Revert "coalesce texture uploads at the beginning of a frame"

This reverts commit 8c2c7f769f.

See #454

Conflicts:
	src/geometry/glyph_atlas.cpp
	src/geometry/sprite_atlas.cpp
This commit is contained in:
John Firebaugh
2014-09-02 15:18:52 -07:00
parent bb9a466adb
commit c1280f0b38
5 changed files with 16 additions and 56 deletions

View File

@@ -33,7 +33,6 @@ public:
const SDFGlyph& glyph);
void removeGlyphs(uint64_t tile_id);
void bind();
void upload();
public:
const uint16_t width = 0;

View File

@@ -42,12 +42,10 @@ public:
// NEVER CALL THIS FUNCTION FROM THE RENDER THREAD! it is blocking.
Rect<dimension> waitForImage(const std::string &name, const Sprite &sprite);
// Binds the image buffer of this sprite atlas to the GPU.
// Binds the image buffer of this sprite atlas to the GPU, and uploads data if it is out
// of date.
void bind(bool linear = false);
// Uploads the image buffer to the GPU if it is out of date.
void upload();
inline float getWidth() const { return width; }
inline float getHeight() const { return height; }
inline float getTextureWidth() const { return width * pixelRatio; }

View File

@@ -120,46 +120,6 @@ void GlyphAtlas::removeGlyphs(uint64_t tile_id) {
}
}
void GlyphAtlas::upload() {
if (dirty) {
const bool exists = texture;
bind();
std::lock_guard<std::mutex> lock(mtx);
if (!exists) {
glTexImage2D(
GL_TEXTURE_2D, // GLenum target
0, // GLint level
GL_ALPHA, // GLint internalformat
width, // GLsizei width
height, // GLsizei height
0, // GLint border
GL_ALPHA, // GLenum format
GL_UNSIGNED_BYTE, // GLenum type
data // const GLvoid * data
);
} else {
glTexSubImage2D(
GL_TEXTURE_2D, // GLenum target
0, // GLint level
0, // GLint xoffset
0, // GLint yoffset
width, // GLsizei width
height, // GLsizei height
GL_ALPHA, // GLenum format
GL_UNSIGNED_BYTE, // GLenum type
data // const GLvoid *pixels
);
}
dirty = false;
#if defined(DEBUG)
// platform::show_debug_image("Glyph Atlas", data, width, height);
#endif
}
}
void GlyphAtlas::bind() {
if (!texture) {
glGenTextures(1, &texture);
@@ -171,4 +131,14 @@ void GlyphAtlas::bind() {
} else {
glBindTexture(GL_TEXTURE_2D, texture);
}
if (dirty) {
std::lock_guard<std::mutex> lock(mtx);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data);
dirty = false;
#if defined(DEBUG)
// platform::show_debug_image("Glyph Atlas", data, width, height);
#endif
}
};

View File

@@ -196,11 +196,13 @@ void SpriteAtlas::update(const Sprite &sprite) {
}
void SpriteAtlas::bind(bool linear) {
bool first = false;
if (!texture) {
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
first = true;
} else {
glBindTexture(GL_TEXTURE_2D, texture);
}
@@ -211,17 +213,12 @@ void SpriteAtlas::bind(bool linear) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_val);
filter = filter_val;
}
}
void SpriteAtlas::upload() {
if (dirty) {
const bool exists = texture;
bind(filter); // Make sure we don't change the filter value.
std::lock_guard<std::mutex> lock(mtx);
allocate();
if (!exists) {
if (first) {
glTexImage2D(
GL_TEXTURE_2D, // GLenum target
0, // GLint level
@@ -252,7 +249,7 @@ void SpriteAtlas::upload() {
#endif
dirty = false;
}
}
};
SpriteAtlas::~SpriteAtlas() {
std::lock_guard<std::mutex> lock(mtx);

View File

@@ -545,10 +545,6 @@ void Map::render() {
#if defined(DEBUG)
std::vector<std::string> debug;
#endif
glyphAtlas->upload();
spriteAtlas->upload();
painter.clear();
painter.resize();