55#include < glad/glad.h>
66#include < KHR/khrplatform.h>
77// TODO/Good to have:
8- // -Message:GL_INVALID_OPERATION in glBlitFramebuffer(source and destination color buffer cannot be the same), this may not be easy to handle
98// -IMGUI crashes on windows + opengl es
10- // -limited color attachments to 4 in not a good way
11- // -GL_PROXY_TEXTURE_2D and GL_TEXTURE_COMPRESSED_IMAGE_SIZE
9+ // -Deferred is broken
10+ // -MSAA causes ASSERTION: "GL_state.ValidForFlip()" at gropengl.cpp:141
11+ // -The entire MSAA path is broken in ES on multiple places
12+ // -GL_PROXY_TEXTURE_2D and GL_TEXTURE_COMPRESSED_IMAGE_SIZE solution
1213// -glGetTexImage()
1314
1415// Stubs Enums, this does not exist on GLES and need to be handled
@@ -134,7 +135,30 @@ static inline void convert_BGR_to_RGBA(const uint8_t* src, uint8_t* dst, size_t
134135 }
135136}
136137
138+ // BGRA1555_REV -> RGB888
139+ static inline void convert_BGRA1555_REV_to_RGB888 (const uint16_t * src, uint8_t * dstRGB8, size_t npx)
140+ {
141+ for (size_t i = 0 ; i < npx; ++i) {
142+ uint16_t s = src[i];
143+ uint8_t R5 = (s >> 10 ) & 0x1F ;
144+ uint8_t G5 = (s >> 5 ) & 0x1F ;
145+ uint8_t B5 = s & 0x1F ;
146+
147+ // expand 5 to 8 bits
148+ uint8_t R = (R5 << 3 ) | (R5 >> 2 );
149+ uint8_t G = (G5 << 3 ) | (G5 >> 2 );
150+ uint8_t B = (B5 << 3 ) | (B5 >> 2 );
151+
152+ size_t o = 3 * i;
153+ dstRGB8[o + 0 ] = R;
154+ dstRGB8[o + 1 ] = G;
155+ dstRGB8[o + 2 ] = B;
156+ }
157+ }
137158
159+ #ifdef glTexSubImage3D
160+ #undef glTexSubImage3D
161+ #endif
138162static inline void glTexSubImage3D (GLenum target, GLint level, GLint xoff, GLint yoff, GLint zoff, GLsizei w, GLsizei h, GLsizei d, GLenum format, GLenum type, const void * data)
139163{
140164 const size_t npx = size_t (w) * size_t (h) * size_t (d);
@@ -150,9 +174,20 @@ static inline void glTexSubImage3D(GLenum target, GLint level, GLint xoff, GLint
150174 std::vector<uint8_t > scratch (npx * 4 ); // RGBA8888 = 4 BPP
151175 convert_BGRA1555_REV_to_RGBA8888 (reinterpret_cast <const uint16_t *>(data), scratch.data (), npx);
152176 glPixelStorei (GL_UNPACK_ALIGNMENT, 1 );
153- glTexSubImage3D_glad (target, level, xoff, yoff, zoff, w, h, d, format, type, scratch.data ());
177+ glad_glTexSubImage3D (target, level, xoff, yoff, zoff, w, h, d, format, type, scratch.data ());
154178 return ;
155179 }
180+ } else if (internalFormat == GL_RGB8) {
181+ format = GL_RGB;
182+ type = GL_UNSIGNED_BYTE;
183+ if (data != nullptr )
184+ {
185+ std::vector<uint8_t > scratch (npx * 3 ); // RGB888 = 3 BPP
186+ convert_BGRA1555_REV_to_RGB888 (reinterpret_cast <const uint16_t *>(data), scratch.data (), npx);
187+ glPixelStorei (GL_UNPACK_ALIGNMENT, 1 );
188+ glad_glTexSubImage3D (target, level, xoff, yoff, zoff, w, h, d, format, type, scratch.data ());
189+ return ;
190+ }
156191 } else {
157192 format = GL_RGBA;
158193 type = GL_UNSIGNED_SHORT_5_5_5_1;
@@ -162,7 +197,7 @@ static inline void glTexSubImage3D(GLenum target, GLint level, GLint xoff, GLint
162197 reinterpret_cast <uint16_t *>(scratch.data ()),
163198 npx);
164199 glPixelStorei (GL_UNPACK_ALIGNMENT, 1 );
165- glTexSubImage3D_glad (target, level, xoff, yoff, zoff, w, h, d, format, type, scratch.data ());
200+ glad_glTexSubImage3D (target, level, xoff, yoff, zoff, w, h, d, format, type, scratch.data ());
166201 return ;
167202 }
168203 }
@@ -177,7 +212,7 @@ static inline void glTexSubImage3D(GLenum target, GLint level, GLint xoff, GLint
177212 std::vector<uint8_t > scratch (npx * 4 ); // RGBA8888 = 4 BPP
178213 convert_BGR_to_RGBA (static_cast <const uint8_t *>(data), scratch.data (), npx);
179214 glPixelStorei (GL_UNPACK_ALIGNMENT, 1 );
180- glTexSubImage3D_glad (target, level, xoff, yoff, zoff, w, h, d, format, type, scratch.data ());
215+ glad_glTexSubImage3D (target, level, xoff, yoff, zoff, w, h, d, format, type, scratch.data ());
181216 return ;
182217 }
183218 }
@@ -188,7 +223,7 @@ static inline void glTexSubImage3D(GLenum target, GLint level, GLint xoff, GLint
188223 std::vector<uint8_t > scratch (npx * 3 ); // RGB888 = 3 BPP
189224 convert_BGR_to_RGB (static_cast <const uint8_t *>(data), scratch.data (), npx);
190225 glPixelStorei (GL_UNPACK_ALIGNMENT, 1 );
191- glTexSubImage3D_glad (target, level, xoff, yoff, zoff, w, h, d, format, type, scratch.data ());
226+ glad_glTexSubImage3D (target, level, xoff, yoff, zoff, w, h, d, format, type, scratch.data ());
192227 return ;
193228 }
194229 }
@@ -201,31 +236,62 @@ static inline void glTexSubImage3D(GLenum target, GLint level, GLint xoff, GLint
201236 std::vector<uint8_t > scratch (npx * 4 );
202237 convert_BGRA8888_to_RGBA8888 (reinterpret_cast <const uint8_t *>(data), scratch.data (), npx);
203238 glPixelStorei (GL_UNPACK_ALIGNMENT, 1 );
204- glTexSubImage3D_glad (target, level, xoff, yoff, zoff, w, h, d, GL_RGBA, type, scratch.data ());
239+ glad_glTexSubImage3D (target, level, xoff, yoff, zoff, w, h, d, GL_RGBA, type, scratch.data ());
205240 return ;
206241 }
207242 }
208243
209- glTexSubImage3D_glad (target, level, xoff, yoff, zoff, w, h, d, format, type, data);
244+ glad_glTexSubImage3D (target, level, xoff, yoff, zoff, w, h, d, format, type, data);
210245}
211246
247+ #ifdef glTexImage2D
248+ #undef glTexImage2D
249+ #endif
212250static inline void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void * data)
213251{
214252 if (internalformat == GL_RGBA16F) {
215- glTexImage2D_glad (target, level, internalformat, width, height, border, GL_RGBA, GL_HALF_FLOAT, data);
253+ glad_glTexImage2D (target, level, internalformat, width, height, border, GL_RGBA, GL_HALF_FLOAT, data);
216254 } else if (internalformat == GL_RGBA8) {
217- glTexImage2D_glad (target, level, internalformat, width, height, border, GL_RGBA, GL_UNSIGNED_BYTE, data);
255+ glad_glTexImage2D (target, level, internalformat, width, height, border, GL_RGBA, GL_UNSIGNED_BYTE, data);
218256 } else if (internalformat == GL_DEPTH_COMPONENT24) {
219- glTexImage2D_glad (target, level, internalformat, width, height, border, format, GL_UNSIGNED_INT, data);
257+ glad_glTexImage2D (target, level, internalformat, width, height, border, format, GL_UNSIGNED_INT, data);
258+ } else {
259+ glad_glTexImage2D (target, level, internalformat, width, height, border, format, type, data);
260+ }
261+ }
262+
263+ #ifdef glTexImage3D
264+ #undef glTexImage3D
265+ #endif
266+ static inline void glTexImage3D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *data)
267+ {
268+ if (internalformat == GL_DEPTH_COMPONENT24) {
269+ glad_glTexImage3D (target, level, internalformat, width, height, depth, border, format, GL_UNSIGNED_INT, data);
270+ } else if (type == GL_UNSIGNED_INT_8_8_8_8_REV) {
271+ if (internalformat == GL_RGBA16F) {
272+ glad_glTexImage3D (target, level, internalformat, width, height, depth, border, format, GL_HALF_FLOAT, data);
273+ } if (internalformat == GL_RGBA32F) {
274+ glad_glTexImage3D (target, level, internalformat, width, height, depth, border, format, GL_FLOAT, data);
275+ } else {
276+ glad_glTexImage3D (target, level, internalformat, width, height, depth, border, format, GL_UNSIGNED_BYTE, data);
277+ }
220278 } else {
221- glTexImage2D_glad (target, level, internalformat, width, height, border, format, type, data);
279+ glad_glTexImage3D (target, level, internalformat, width, height, depth , border, format, type, data);
222280 }
223281}
224282
283+ #ifdef glReadPixels
284+ #undef glReadPixels
285+ #endif
286+ static inline void glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void * data)
287+ {
288+ if (type == GL_UNSIGNED_INT_8_8_8_8_REV)
289+ type = GL_UNSIGNED_BYTE;
290+ glad_glReadPixels (x, y, width, height, format, type, data);
291+ }
292+
225293inline void glDrawBuffer (GLenum data)
226294{
227- if (data >= GL_COLOR_ATTACHMENT4)
228- return ; // limit color attachments to 4
229295 const GLenum buffer[] = { data };
230296 glDrawBuffers (1 , buffer);
231297}
0 commit comments