From 073ab4b3ad9554da63745716e384babc08c52e9f Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 13 Mar 2017 04:03:26 +0100 Subject: [PATCH 1/2] Fixing OGL multiple vertex streams. --- src/renderer_gl.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 87f699694..d2e0eb799 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -7165,18 +7165,10 @@ namespace bgfx { namespace gl streamMask >>= ntz; idx += ntz; - uint16_t handle = draw.m_stream[idx].m_handle.idx; - if (invalidHandle != handle) - { - VertexBufferGL& vb = m_vertexBuffers[handle]; - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) ); - bindAttribs = true; - } - else - { - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) ); - } + currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle; } + + bindAttribs = true; } if (currentState.m_indexBuffer.idx != draw.m_indexBuffer.idx) @@ -7224,8 +7216,11 @@ namespace bgfx { namespace gl streamMask >>= ntz; idx += ntz; + currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex; + const VertexBufferGL& vb = m_vertexBuffers[draw.m_stream[idx].m_handle.idx]; uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[idx].m_decl.idx : vb.m_decl.idx; + GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) ); program.bindAttributes(m_vertexDecls[decl], draw.m_stream[idx].m_startVertex); } program.bindAttributesEnd(); From 35323725e9e0a0eb4b122a320d1283ef8776d67d Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 14 Mar 2017 14:26:11 +0100 Subject: [PATCH 2/2] Don't force stb image loader to use RGBA8. --- examples/common/image.cpp | 23 ++++++++++++++++++++--- src/renderer_gl.cpp | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/examples/common/image.cpp b/examples/common/image.cpp index fe8ce8a7d..8868cb137 100644 --- a/examples/common/image.cpp +++ b/examples/common/image.cpp @@ -33,7 +33,9 @@ BX_PRAGMA_DIAGNOSTIC_POP() #include typedef unsigned char stbi_uc; +extern "C" int stbi_is_hdr_from_memory(stbi_uc const* _buffer, int _len); extern "C" stbi_uc* stbi_load_from_memory(stbi_uc const* _buffer, int _len, int* _x, int* _y, int* _comp, int _req_comp); +extern "C" float* stbi_loadf_from_memory(stbi_uc const* _buffer, int _len, int* _x, int* _y, int* _comp, int _req_comp); extern "C" void stbi_image_free(void* _ptr); extern void lodepng_free(void* _ptr); @@ -336,18 +338,33 @@ namespace bgfx static ImageContainer* imageParseStbImage(bx::AllocatorI* _allocator, const void* _data, uint32_t _size) { - TextureFormat::Enum format = TextureFormat::RGBA8; + const int isHdr = stbi_is_hdr_from_memory((const uint8_t*)_data, (int)_size); + + void* data; uint32_t width = 0; uint32_t height = 0; - int comp = 0; - void* data = stbi_load_from_memory( (uint8_t*)_data, _size, (int*)&width, (int*)&height, &comp, 4); + if (isHdr) { data = stbi_loadf_from_memory((const uint8_t*)_data, (int)_size, (int*)&width, (int*)&height, &comp, 4); } + else { data = stbi_load_from_memory ((const uint8_t*)_data, (int)_size, (int*)&width, (int*)&height, &comp, 0); } if (NULL == data) { return NULL; } + bgfx::TextureFormat::Enum format; + if (isHdr) + { + format = bgfx::TextureFormat::RGBA32F; + } + else + { + if (1 == comp) { format = bgfx::TextureFormat::R8; } + else if (2 == comp) { format = bgfx::TextureFormat::RG8; } + else if (3 == comp) { format = bgfx::TextureFormat::RGB8; } + else/*if (4 == comp)*/ { format = bgfx::TextureFormat::RGBA8; } + } + ImageContainer* output = imageAlloc(_allocator , format , uint16_t(width) diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index d2e0eb799..39cf59c3c 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -4684,6 +4684,7 @@ namespace bgfx { namespace gl GL_CHECK(glGenTextures(1, &m_id) ); BX_CHECK(0 != m_id, "Failed to generate texture id."); GL_CHECK(glBindTexture(_target, m_id) ); + GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1) ); const TextureFormatInfo& tfi = s_textureFormat[m_textureFormat]; m_fmt = tfi.m_fmt;