Fix some strict GL ES 2 conformance issues.

This commit fixes two issues that cause issues in WebGL:
  * Non-power-of-two textures must wrap as GL_CLAMP_TO_EDGE.
    This breaks non-power-of-two textures.
  * Render calls with zero primitives should not be issued.
    This just causes warning spam.
pull/339/head
whitequark 2018-07-18 19:40:14 +00:00
parent 02ec64ee66
commit 738ac02cbf
2 changed files with 26 additions and 9 deletions

View File

@ -272,6 +272,8 @@ void MeshRenderer::Remove(const MeshRenderer::Handle &handle) {
void MeshRenderer::Draw(const MeshRenderer::Handle &handle,
bool useColors, RgbaColor overrideColor) {
if(handle.size == 0) return;
selectedShader->Enable();
glBindBuffer(GL_ARRAY_BUFFER, handle.vertexBuffer);
@ -575,6 +577,8 @@ void EdgeRenderer::Remove(const EdgeRenderer::Handle &handle) {
}
void EdgeRenderer::Draw(const EdgeRenderer::Handle &handle) {
if(handle.size == 0) return;
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, atlas->GetTexture(pattern));
shader.SetUniformTextureUnit("pattern", 1);
@ -774,6 +778,8 @@ void OutlineRenderer::Remove(const OutlineRenderer::Handle &handle) {
}
void OutlineRenderer::Draw(const OutlineRenderer::Handle &handle, Canvas::DrawOutlinesAs mode) {
if(handle.size == 0) return;
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, atlas->GetTexture(pattern));
shader.SetUniformTextureUnit("pattern", 1);
@ -980,15 +986,17 @@ IndexedMeshRenderer::Handle IndexedMeshRenderer::Add(const SIndexedMesh &m, bool
return handle;
}
void IndexedMeshRenderer::Remove(const IndexedMeshRenderer::Handle &m) {
glDeleteBuffers(1, &m.vertexBuffer);
glDeleteBuffers(1, &m.indexBuffer);
void IndexedMeshRenderer::Remove(const IndexedMeshRenderer::Handle &handle) {
glDeleteBuffers(1, &handle.vertexBuffer);
glDeleteBuffers(1, &handle.indexBuffer);
}
void IndexedMeshRenderer::Draw(const IndexedMeshRenderer::Handle &m) {
void IndexedMeshRenderer::Draw(const IndexedMeshRenderer::Handle &handle) {
if(handle.size == 0) return;
selectedShader->Enable();
glBindBuffer(GL_ARRAY_BUFFER, m.vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, handle.vertexBuffer);
glEnableVertexAttribArray(ATTRIB_POS);
glVertexAttribPointer(ATTRIB_POS, 3, GL_FLOAT, GL_FALSE, sizeof(SIndexedMesh::Vertex),
(void *)offsetof(SIndexedMesh::Vertex, pos));
@ -998,8 +1006,8 @@ void IndexedMeshRenderer::Draw(const IndexedMeshRenderer::Handle &m) {
(void *)offsetof(SIndexedMesh::Vertex, tex));
}
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m.indexBuffer);
glDrawElements(GL_TRIANGLES, m.size, GL_UNSIGNED_INT, NULL);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, handle.indexBuffer);
glDrawElements(GL_TRIANGLES, handle.size, GL_UNSIGNED_INT, NULL);
glDisableVertexAttribArray(ATTRIB_POS);
if(NeedsTexture()) glDisableVertexAttribArray(ATTRIB_TEX);

View File

@ -259,14 +259,23 @@ Canvas::Fill *OpenGl2Renderer::SelectFill(hFill hcf) {
return fill;
}
static bool IsPowerOfTwo(size_t n) {
return (n & (n - 1)) == 0;
}
void OpenGl2Renderer::InvalidatePixmap(std::shared_ptr<const Pixmap> pm) {
GLuint id;
pixmapCache.Lookup(pm, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
if(IsPowerOfTwo(pm->width) && IsPowerOfTwo(pm->height)) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
} else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
GLenum format;
switch(pm->format) {