[core] GL types for buckets, textures, buffers

This commit is contained in:
Bruno de Oliveira Abinader
2015-09-10 17:59:58 +03:00
committed by Konstantin Käfer
parent 05d01194b7
commit c33a6bddc6
15 changed files with 56 additions and 53 deletions

View File

@@ -14,9 +14,9 @@
namespace mbgl {
template <
size_t item_size,
int bufferType = GL_ARRAY_BUFFER,
size_t defaultLength = 8192,
GLsizei item_size,
GLenum bufferType = GL_ARRAY_BUFFER,
GLsizei defaultLength = 8192,
bool retainAfterUpload = false
>
class Buffer : private util::noncopyable {
@@ -31,8 +31,8 @@ public:
// Returns the number of elements in this buffer. This is not the number of
// bytes, but rather the number of coordinates with associated information.
inline size_t index() const {
return pos / itemSize;
inline GLsizei index() const {
return static_cast<GLsizei>(pos / itemSize);
}
inline bool empty() const {

View File

@@ -10,16 +10,16 @@
namespace mbgl {
template <int count>
template <GLsizei count>
struct ElementGroup : public util::noncopyable {
std::array<VertexArrayObject, count> array;
uint32_t vertex_length;
uint32_t elements_length;
GLsizei vertex_length;
GLsizei elements_length;
ElementGroup() : vertex_length(0), elements_length(0) {}
ElementGroup(uint32_t vertex_length_, uint32_t elements_length_)
: vertex_length(vertex_length_),
elements_length(elements_length_) {
ElementGroup(GLsizei vertex_length_ = 0, GLsizei elements_length_ = 0)
: vertex_length(vertex_length_)
, elements_length(elements_length_)
{
}
};

View File

@@ -4,6 +4,7 @@
#include <mbgl/geometry/binpack.hpp>
#include <mbgl/text/glyph_store.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/platform/gl.hpp>
#include <string>
#include <set>
@@ -51,7 +52,7 @@ private:
std::map<std::string, std::map<uint32_t, GlyphValue>> index;
const std::unique_ptr<uint8_t[]> data;
std::atomic<bool> dirty;
uint32_t texture = 0;
GLuint texture = 0;
};
};

View File

@@ -12,10 +12,10 @@
using namespace mbgl;
LineAtlas::LineAtlas(uint16_t w, uint16_t h)
LineAtlas::LineAtlas(GLsizei w, GLsizei h)
: width(w),
height(h),
data(std::make_unique<uint8_t[]>(w * h)),
data(std::make_unique<GLbyte[]>(w * h)),
dirty(true) {
}

View File

@@ -1,6 +1,8 @@
#ifndef MBGL_GEOMETRY_LINE_ATLAS
#define MBGL_GEOMETRY_LINE_ATLAS
#include <mbgl/platform/gl.hpp>
#include <vector>
#include <map>
#include <memory>
@@ -15,7 +17,7 @@ typedef struct {
class LineAtlas {
public:
LineAtlas(uint16_t width, uint16_t height);
LineAtlas(GLsizei width, GLsizei height);
~LineAtlas();
// Binds the atlas texture to the GPU, and uploads data if it is out of date.
@@ -28,13 +30,13 @@ public:
LinePatternPos getDashPosition(const std::vector<float>&, bool);
LinePatternPos addDash(const std::vector<float> &dasharray, bool round);
const int width;
const int height;
const GLsizei width;
const GLsizei height;
private:
const std::unique_ptr<uint8_t[]> data;
const std::unique_ptr<GLbyte[]> data;
bool dirty;
uint32_t texture = 0;
GLuint texture = 0;
int nextRow = 0;
std::map<size_t, LinePatternPos> positions;
};

View File

@@ -2,7 +2,7 @@
#define MBGL_GEOMETRY_SPRITE_ATLAS
#include <mbgl/geometry/binpack.hpp>
#include <mbgl/platform/gl.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/ptr.hpp>
@@ -93,7 +93,7 @@ private:
const std::unique_ptr<uint32_t[]> data;
std::atomic<bool> dirty;
bool fullUploadRequired = true;
uint32_t texture = 0;
GLuint texture = 0;
uint32_t filter = 0;
static const int buffer = 1;
};

View File

@@ -107,7 +107,7 @@ void FillBucket::tessellate() {
assert(lineGroups.back());
LineGroup& lineGroup = *lineGroups.back();
uint32_t lineIndex = lineGroup.vertex_length;
GLsizei lineIndex = lineGroup.vertex_length;
for (const auto& polygon : polygons) {
const size_t group_count = polygon.size();
@@ -156,7 +156,7 @@ void FillBucket::tessellate() {
// coordinate in this polygon.
assert(triangleGroups.back());
TriangleGroup& triangleGroup = *triangleGroups.back();
uint32_t triangleIndex = triangleGroup.vertex_length;
GLsizei triangleIndex = triangleGroup.vertex_length;
for (int i = 0; i < triangle_count; ++i) {
const TESSindex *element_group = &elements[i * vertices_per_group];

View File

@@ -75,7 +75,7 @@ void LineBucket::addGeometry(const std::vector<Coordinate>& vertices) {
nextNormal = util::perp(util::unit(vec2<double>(firstVertex - currentVertex)));
}
const int32_t startVertex = (int32_t)vertexBuffer.index();
const GLint startVertex = vertexBuffer.index();
std::vector<TriangleElement> triangleStore;
for (size_t i = 0; i < len; ++i) {
@@ -333,16 +333,15 @@ void LineBucket::addCurrentVertex(const Coordinate& currentVertex,
float endLeft,
float endRight,
bool round,
int32_t startVertex,
GLint startVertex,
std::vector<TriangleElement>& triangleStore) {
int8_t tx = round ? 1 : 0;
vec2<double> extrude = normal * flip;
if (endLeft)
extrude = extrude - (util::perp(normal) * endLeft);
e3 = (int32_t)vertexBuffer.add(currentVertex.x, currentVertex.y, extrude.x, extrude.y, tx, 0,
distance) -
startVertex;
e3 = vertexBuffer.add(currentVertex.x, currentVertex.y, extrude.x, extrude.y, tx, 0, distance)
- startVertex;
if (e1 >= 0 && e2 >= 0) {
triangleStore.emplace_back(e1, e2, e3);
}
@@ -352,9 +351,8 @@ void LineBucket::addCurrentVertex(const Coordinate& currentVertex,
extrude = normal * (-flip);
if (endRight)
extrude = extrude - (util::perp(normal) * endRight);
e3 = (int32_t)vertexBuffer.add(currentVertex.x, currentVertex.y, extrude.x, extrude.y, tx, 1,
distance) -
startVertex;
e3 = vertexBuffer.add(currentVertex.x, currentVertex.y, extrude.x, extrude.y, tx, 1, distance)
- startVertex;
if (e1 >= 0 && e2 >= 0) {
triangleStore.emplace_back(e1, e2, e3);
}
@@ -367,13 +365,13 @@ void LineBucket::addPieSliceVertex(const Coordinate& currentVertex,
double distance,
const vec2<double>& extrude,
bool lineTurnsLeft,
int32_t startVertex,
GLint startVertex,
std::vector<TriangleElement>& triangleStore) {
int8_t ty = lineTurnsLeft;
auto flippedExtrude = extrude * (flip * (lineTurnsLeft ? -1 : 1));
e3 = (int32_t)vertexBuffer.add(currentVertex.x, currentVertex.y, flippedExtrude.x, flippedExtrude.y, 0, ty,
distance) - startVertex;
e3 = vertexBuffer.add(currentVertex.x, currentVertex.y, flippedExtrude.x, flippedExtrude.y, 0, ty, distance)
- startVertex;
if (e1 >= 0 && e2 >= 0) {
triangleStore.emplace_back(e1, e2, e3);
}

View File

@@ -46,9 +46,9 @@ private:
};
void addCurrentVertex(const Coordinate& currentVertex, float flip, double distance,
const vec2<double>& normal, float endLeft, float endRight, bool round,
int32_t startVertex, std::vector<LineBucket::TriangleElement>& triangleStore);
GLint startVertex, std::vector<LineBucket::TriangleElement>& triangleStore);
void addPieSliceVertex(const Coordinate& currentVertex, float flip, double distance,
const vec2<double>& extrude, bool lineTurnsLeft, int32_t startVertex,
const vec2<double>& extrude, bool lineTurnsLeft, GLint startVertex,
std::vector<TriangleElement>& triangleStore);
public:
@@ -61,9 +61,9 @@ private:
const size_t vertex_start;
const size_t triangle_elements_start;
int32_t e1;
int32_t e2;
int32_t e3;
GLint e1;
GLint e2;
GLint e3;
std::vector<std::unique_ptr<TriangleGroup>> triangleGroups;
};

View File

@@ -117,14 +117,14 @@ void Painter::setDebug(bool enabled) {
debug = enabled;
}
void Painter::useProgram(uint32_t program) {
void Painter::useProgram(GLuint program) {
if (gl_program != program) {
MBGL_CHECK_ERROR(glUseProgram(program));
gl_program = program;
}
}
void Painter::lineWidth(float line_width) {
void Painter::lineWidth(GLfloat line_width) {
if (gl_lineWidth != line_width) {
MBGL_CHECK_ERROR(glLineWidth(line_width));
gl_lineWidth = line_width;

View File

@@ -161,8 +161,8 @@ private:
void setDepthSublayer(int n);
public:
void useProgram(uint32_t program);
void lineWidth(float lineWidth);
void useProgram(GLuint program);
void lineWidth(GLfloat lineWidth);
public:
mat4 projMatrix;
@@ -194,8 +194,8 @@ private:
gl::Config config;
uint32_t gl_program = 0;
float gl_lineWidth = 0;
GLuint gl_program = 0;
GLfloat gl_lineWidth = 0;
std::array<uint16_t, 2> gl_viewport = {{ 0, 0 }};
RenderPass pass = RenderPass::Opaque;
Color background = {{ 0, 0, 0, 0 }};

View File

@@ -488,7 +488,7 @@ void SymbolBucket::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float
// coordinate in this polygon.
assert(buffer.groups.back());
auto &triangleGroup = *buffer.groups.back();
uint32_t triangleIndex = triangleGroup.vertex_length;
GLsizei triangleIndex = triangleGroup.vertex_length;
// coordinates (2 triangles)
buffer.vertices.add(anchorPoint.x, anchorPoint.y, tl.x, tl.y, tex.x, tex.y, minZoom,

View File

@@ -50,7 +50,7 @@ void Raster::bind(bool linear) {
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture));
}
GLuint new_filter = linear ? GL_LINEAR : GL_NEAREST;
GLint new_filter = linear ? GL_LINEAR : GL_NEAREST;
if (new_filter != this->filter) {
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, new_filter));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, new_filter));

View File

@@ -1,6 +1,7 @@
#ifndef MBGL_UTIL_RASTER
#define MBGL_UTIL_RASTER
#include <mbgl/platform/gl.hpp>
#include <mbgl/util/texture_pool.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/ptr.hpp>
@@ -32,13 +33,14 @@ public:
public:
// loaded image dimensions
uint32_t width = 0, height = 0;
GLsizei width = 0;
GLsizei height = 0;
// has been uploaded to texture
bool textured = false;
// the uploaded texture
uint32_t texture = 0;
GLuint texture = 0;
// texture opacity
double opacity = 0;
@@ -53,7 +55,7 @@ private:
TexturePool& texturePool;
// min/mag filter
uint32_t filter = 0;
GLint filter = 0;
// the raw pixels
std::unique_ptr<util::Image> img;

View File

@@ -5,7 +5,7 @@
#include <vector>
const int TextureMax = 64;
const GLsizei TextureMax = 64;
using namespace mbgl;
@@ -13,7 +13,7 @@ GLuint TexturePool::getTextureID() {
if (texture_ids.empty()) {
GLuint new_texture_ids[TextureMax];
MBGL_CHECK_ERROR(glGenTextures(TextureMax, new_texture_ids));
for (uint32_t id = 0; id < TextureMax; id++) {
for (GLuint id = 0; id < TextureMax; id++) {
texture_ids.insert(new_texture_ids[id]);
}
}