Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[WIP] Prototype modern C++ bindings for OpenGL
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Oct 5, 2016
1 parent 13ca45f commit c0b3c9f
Show file tree
Hide file tree
Showing 65 changed files with 1,567 additions and 1,446 deletions.
16 changes: 13 additions & 3 deletions cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,31 @@ set(MBGL_CORE_FILES
# gl
include/mbgl/gl/gl.hpp
src/mbgl/gl/attribute.hpp
src/mbgl/gl/color.hpp
src/mbgl/gl/context.cpp
src/mbgl/gl/context.hpp
src/mbgl/gl/debugging.cpp
src/mbgl/gl/debugging.hpp
src/mbgl/gl/depth.hpp
src/mbgl/gl/drawable.hpp
src/mbgl/gl/extension.cpp
src/mbgl/gl/extension.hpp
src/mbgl/gl/gl.cpp
src/mbgl/gl/index_buffer.hpp
src/mbgl/gl/mode.hpp
src/mbgl/gl/object.cpp
src/mbgl/gl/object.hpp
src/mbgl/gl/segment.hpp
src/mbgl/gl/shader.cpp
src/mbgl/gl/shader.hpp
src/mbgl/gl/state.hpp
src/mbgl/gl/stencil.hpp
src/mbgl/gl/texture.hpp
src/mbgl/gl/types.hpp
src/mbgl/gl/uniform.cpp
src/mbgl/gl/uniform.hpp
src/mbgl/gl/value.cpp
src/mbgl/gl/value.hpp
src/mbgl/gl/vao.cpp
src/mbgl/gl/vao.hpp
src/mbgl/gl/vertex_array.cpp
src/mbgl/gl/vertex_array.hpp
src/mbgl/gl/vertex_buffer.hpp
Expand Down Expand Up @@ -142,7 +146,6 @@ set(MBGL_CORE_FILES
src/mbgl/renderer/circle_bucket.hpp
src/mbgl/renderer/debug_bucket.cpp
src/mbgl/renderer/debug_bucket.hpp
src/mbgl/renderer/element_group.hpp
src/mbgl/renderer/fill_bucket.cpp
src/mbgl/renderer/fill_bucket.hpp
src/mbgl/renderer/frame_history.cpp
Expand Down Expand Up @@ -172,10 +175,12 @@ set(MBGL_CORE_FILES
# shader
src/mbgl/shader/circle_shader.cpp
src/mbgl/shader/circle_shader.hpp
src/mbgl/shader/circle_uniforms.hpp
src/mbgl/shader/circle_vertex.cpp
src/mbgl/shader/circle_vertex.hpp
src/mbgl/shader/collision_box_shader.cpp
src/mbgl/shader/collision_box_shader.hpp
src/mbgl/shader/collision_box_uniforms.hpp
src/mbgl/shader/collision_box_vertex.cpp
src/mbgl/shader/collision_box_vertex.hpp
src/mbgl/shader/fill_outline_pattern_shader.cpp
Expand All @@ -186,6 +191,8 @@ set(MBGL_CORE_FILES
src/mbgl/shader/fill_pattern_shader.hpp
src/mbgl/shader/fill_shader.cpp
src/mbgl/shader/fill_shader.hpp
src/mbgl/shader/fill_uniforms.cpp
src/mbgl/shader/fill_uniforms.hpp
src/mbgl/shader/fill_vertex.cpp
src/mbgl/shader/fill_vertex.hpp
src/mbgl/shader/line_pattern_shader.cpp
Expand All @@ -194,17 +201,20 @@ set(MBGL_CORE_FILES
src/mbgl/shader/line_sdf_shader.hpp
src/mbgl/shader/line_shader.cpp
src/mbgl/shader/line_shader.hpp
src/mbgl/shader/line_uniforms.hpp
src/mbgl/shader/line_vertex.cpp
src/mbgl/shader/line_vertex.hpp
src/mbgl/shader/raster_shader.cpp
src/mbgl/shader/raster_shader.hpp
src/mbgl/shader/raster_uniforms.hpp
src/mbgl/shader/raster_vertex.cpp
src/mbgl/shader/raster_vertex.hpp
src/mbgl/shader/shaders.hpp
src/mbgl/shader/symbol_icon_shader.cpp
src/mbgl/shader/symbol_icon_shader.hpp
src/mbgl/shader/symbol_sdf_shader.cpp
src/mbgl/shader/symbol_sdf_shader.hpp
src/mbgl/shader/symbol_uniforms.hpp
src/mbgl/shader/symbol_vertex.cpp
src/mbgl/shader/symbol_vertex.hpp

Expand Down
4 changes: 4 additions & 0 deletions include/mbgl/util/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Color {
static constexpr Color black() { return { 0.0f, 0.0f, 0.0f, 1.0f }; };
static constexpr Color white() { return { 1.0f, 1.0f, 1.0f, 1.0f }; };

static constexpr Color red() { return { 1.0f, 0.0f, 0.0f, 1.0f }; };
static constexpr Color green() { return { 0.0f, 1.0f, 0.0f, 1.0f }; };
static constexpr Color blue() { return { 0.0f, 0.0f, 1.0f, 1.0f }; };

static optional<Color> parse(const std::string&);
};

Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/util/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace mbgl {
template <class T>
class Range {
public:
Range(const T& min_, const T& max_)
constexpr Range(const T& min_, const T& max_)
: min(min_), max(max_) {}

T min;
Expand Down
6 changes: 0 additions & 6 deletions src/mbgl/gl/attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
#include <mbgl/gl/types.hpp>
#include <mbgl/gl/shader.hpp>

#include <cstddef>
#include <limits>
#include <vector>

namespace mbgl {
namespace gl {

Expand All @@ -27,10 +23,8 @@ class AttributeBinding {
type(DataTypeOf<T>::value),
count(N),
offset(O) {
static_assert(std::is_standard_layout<Vertex>::value, "vertex type must use standard layout");
static_assert(O % 4 == 0, "vertex attribute must be optimally aligned");
static_assert(1 <= N && N <= 4, "count must be 1, 2, 3, or 4");
static_assert(sizeof(Vertex) <= std::numeric_limits<int32_t>::max(), "vertex type is too big");
}

AttributeLocation location;
Expand Down
80 changes: 80 additions & 0 deletions src/mbgl/gl/color.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#pragma once

#include <mbgl/util/variant.hpp>
#include <mbgl/util/color.hpp>

namespace mbgl {
namespace gl {

class Color {
public:
enum BlendFactor {
Zero = 0x0000,
One = 0x0001,
SrcColor = 0x0300,
OneMinusSrcColor = 0x0301,
SrcAlpha = 0x0302,
OneMinusSrcAlpha = 0x0303,
DstAlpha = 0x0304,
OneMinusDstAlpha = 0x0305,
DstColor = 0x0306,
OneMinusDstColor = 0x0307,
SrcAlphaSaturate = 0x0308,
ConstantColor = 0x8001,
OneMinusConstantColor = 0x8002,
ConstantAlpha = 0x8003,
OneMinusConstantAlpha = 0x8004
};

template <uint32_t>
struct ConstantBlend {
};

template <uint32_t>
struct LinearBlend {
BlendFactor srcFactor;
BlendFactor dstFactor;
};

struct Replace {};
using Min = ConstantBlend<0x8007>;
using Max = ConstantBlend<0x8008>;
using Add = LinearBlend<0x8006>;
using Subtract = LinearBlend<0x800A>;
using ReverseSubtract = LinearBlend<0x800B>;

using BlendFunction = variant<
Replace,
Min,
Max,
Add,
Subtract,
ReverseSubtract>;

BlendFunction blendFunction;
mbgl::Color blendColor;

struct Mask {
bool r;
bool g;
bool b;
bool a;
};

Mask mask;

static Color disabled() {
return Color { Replace(), {}, { false, false, false, false } };
}

static Color unblended() {
return Color { Replace(), {}, { true, true, true, true } };
}

static Color alphaBlended() {
return Color { Add { One, OneMinusSrcAlpha }, {}, { true, true, true, true } };
}
};

} // namespace gl
} // namespace mbgl
Loading

0 comments on commit c0b3c9f

Please sign in to comment.