From 9d635f06298f84a59160e8e8cce0187cde6cf74e Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 22 Nov 2016 20:51:56 -0300 Subject: Migrated from GLES to GLAD, fixes many issues. --- drivers/gles3/rasterizer_canvas_gles3.cpp | 134 ++++++++++++++++------------- drivers/gles3/rasterizer_canvas_gles3.h | 3 + drivers/gles3/rasterizer_gles3.cpp | 77 +++++++++++++---- drivers/gles3/rasterizer_scene_gles3.cpp | 21 +++-- drivers/gles3/rasterizer_storage_gles3.cpp | 93 ++++++++++++++------ drivers/gles3/shader_gles3.cpp | 6 +- 6 files changed, 220 insertions(+), 114 deletions(-) (limited to 'drivers/gles3') diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index 10a8912561..1f23387516 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -274,17 +274,7 @@ void RasterizerCanvasGLES3::_draw_polygon(int p_vertex_count, const int* p_indic } if (p_indices) { -#ifdef GLEW_ENABLED glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_INT, p_indices ); -#else - static const int _max_draw_poly_indices = 16*1024; // change this size if needed!!! - ERR_FAIL_COND(p_vertex_count > _max_draw_poly_indices); - static uint16_t _draw_poly_indices[_max_draw_poly_indices]; - for (int i=0; iframe.canvas_draw_commands++; } @@ -471,14 +443,14 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item,Item *curr Vector2(line->to.x,line->to.y) }; -#ifdef GLEW_ENABLED +#ifdef GLES_OVER_GL if (line->antialiased) glEnable(GL_LINE_SMOOTH); #endif - glLineWidth(line->width); + //glLineWidth(line->width); _draw_gui_primitive(2,verts,NULL,NULL); -#ifdef GLEW_ENABLED +#ifdef GLES_OVER_GL if (line->antialiased) glDisable(GL_LINE_SMOOTH); #endif @@ -1395,7 +1367,7 @@ void RasterizerCanvasGLES3::reset_canvas() { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } //glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); - glLineWidth(1.0); + //glLineWidth(1.0); glBindBuffer(GL_ARRAY_BUFFER,0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); for(int i=0;iis_stdout_verbose()) { @@ -91,9 +124,17 @@ void RasterizerGLES3::initialize() { } #endif - glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); +#ifdef GLAD_ENABLED + + if(!gladLoadGL()) { + ERR_PRINT("Error initializing GLAD"); + } + + glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB); glDebugMessageCallbackARB(_gl_debug_print, NULL); - glEnable(GL_DEBUG_OUTPUT); + glEnable(_EXT_DEBUG_OUTPUT); + +#endif /* glDebugMessageControlARB(GL_DEBUG_SOURCE_API_ARB,GL_DEBUG_TYPE_ERROR_ARB,GL_DEBUG_SEVERITY_HIGH_ARB,0,NULL,GL_TRUE); diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 54dc3b914b..f42eea45d4 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -934,7 +934,7 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material* p_m } if (state.current_line_width!=p_material->line_width) { - glLineWidth(p_material->line_width); + //glLineWidth(MAX(p_material->line_width,1.0)); state.current_line_width=p_material->line_width; } @@ -1109,17 +1109,17 @@ void RasterizerSceneGLES3::_setup_geometry(RenderList::Element *e) { int stride = (multi_mesh->xform_floats+multi_mesh->color_floats)*4; glEnableVertexAttribArray(8); glVertexAttribPointer(8,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)NULL)+0); - glVertexAttribDivisorARB(8,1); + glVertexAttribDivisor(8,1); glEnableVertexAttribArray(9); glVertexAttribPointer(9,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)NULL)+4*4); - glVertexAttribDivisorARB(9,1); + glVertexAttribDivisor(9,1); int color_ofs; if (multi_mesh->transform_format==VS::MULTIMESH_TRANSFORM_3D) { glEnableVertexAttribArray(10); glVertexAttribPointer(10,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)NULL)+8*4); - glVertexAttribDivisorARB(10,1); + glVertexAttribDivisor(10,1); color_ofs=12*4; } else { glDisableVertexAttribArray(10); @@ -1136,13 +1136,13 @@ void RasterizerSceneGLES3::_setup_geometry(RenderList::Element *e) { case VS::MULTIMESH_COLOR_8BIT: { glEnableVertexAttribArray(11); glVertexAttribPointer(11,4,GL_UNSIGNED_BYTE,GL_TRUE,stride,((uint8_t*)NULL)+color_ofs); - glVertexAttribDivisorARB(11,1); + glVertexAttribDivisor(11,1); } break; case VS::MULTIMESH_COLOR_FLOAT: { glEnableVertexAttribArray(11); glVertexAttribPointer(11,4,GL_FLOAT,GL_FALSE,stride,((uint8_t*)NULL)+color_ofs); - glVertexAttribDivisorARB(11,1); + glVertexAttribDivisor(11,1); } break; } @@ -1191,11 +1191,11 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { if (s->index_array_len>0) { - glDrawElementsInstancedARB(gl_primitive[s->primitive],s->index_array_len, (s->array_len>=(1<<16))?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT,0,amount); + glDrawElementsInstanced(gl_primitive[s->primitive],s->index_array_len, (s->array_len>=(1<<16))?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT,0,amount); } else { - glDrawArraysInstancedARB(gl_primitive[s->primitive],0,s->array_len,amount); + glDrawArraysInstanced(gl_primitive[s->primitive],0,s->array_len,amount); } @@ -3648,10 +3648,9 @@ void RasterizerSceneGLES3::initialize() { } -#ifdef GLEW_ENABLED +#ifdef GLES_OVER_GL //"desktop" opengl needs this. - glEnable(GL_POINT_SPRITE); - glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); + glEnable(GL_PROGRAM_POINT_SIZE); #endif } diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index e5a0cded8e..60cbbc9023 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -62,7 +62,21 @@ #define _GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE #define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF - +#define _EXT_COMPRESSED_R11_EAC 0x9270 +#define _EXT_COMPRESSED_SIGNED_R11_EAC 0x9271 +#define _EXT_COMPRESSED_RG11_EAC 0x9272 +#define _EXT_COMPRESSED_SIGNED_RG11_EAC 0x9273 +#define _EXT_COMPRESSED_RGB8_ETC2 0x9274 +#define _EXT_COMPRESSED_SRGB8_ETC2 0x9275 +#define _EXT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276 +#define _EXT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277 +#define _EXT_COMPRESSED_RGBA8_ETC2_EAC 0x9278 +#define _EXT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279 + +#define _EXT_COMPRESSED_RGBA_BPTC_UNORM 0x8E8C +#define _EXT_COMPRESSED_SRGB_ALPHA_BPTC_UNORM 0x8E8D +#define _EXT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT 0x8E8E +#define _EXT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT 0x8E8F Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Image::Format p_format, uint32_t p_flags,GLenum& r_gl_format,GLenum& r_gl_internal_format,GLenum &r_gl_type,bool &r_compressed,bool &srgb) { @@ -77,17 +91,16 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima switch(p_format) { case Image::FORMAT_L8: { - r_gl_internal_format=GL_LUMINANCE; - r_gl_format=GL_LUMINANCE; + r_gl_internal_format=GL_R8; + r_gl_format=GL_RED; r_gl_type=GL_UNSIGNED_BYTE; } break; case Image::FORMAT_LA8: { - r_gl_internal_format=GL_LUMINANCE_ALPHA; - r_gl_format=GL_LUMINANCE_ALPHA; + r_gl_internal_format=GL_RG8; + r_gl_format=GL_RG; r_gl_type=GL_UNSIGNED_BYTE; - } break; case Image::FORMAT_R8: { @@ -120,8 +133,9 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima } break; case Image::FORMAT_RGB565: { - - r_gl_internal_format=GL_RGB565; +#warning TODO: Convert tod 555 if 565 is not supported (GLES3.3-) + r_gl_internal_format=GL_RGB5; + //r_gl_internal_format=GL_RGB565; r_gl_format=GL_RGB; r_gl_type=GL_UNSIGNED_SHORT_5_6_5; @@ -287,7 +301,7 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima if (config.bptc_supported) { - r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:GL_COMPRESSED_RGBA_BPTC_UNORM; + r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:_EXT_COMPRESSED_RGBA_BPTC_UNORM; r_gl_format=GL_RGBA; r_gl_type=GL_UNSIGNED_BYTE; r_compressed=true; @@ -303,7 +317,7 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima if (config.bptc_supported) { - r_gl_internal_format=GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT; + r_gl_internal_format=_EXT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT; r_gl_format=GL_RGB; r_gl_type=GL_FLOAT; r_compressed=true; @@ -316,7 +330,7 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima if (config.bptc_supported) { - r_gl_internal_format=GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT; + r_gl_internal_format=_EXT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT; r_gl_format=GL_RGB; r_gl_type=GL_FLOAT; r_compressed=true; @@ -413,7 +427,7 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima if (config.etc2_supported) { - r_gl_internal_format=GL_COMPRESSED_R11_EAC; + r_gl_internal_format=_EXT_COMPRESSED_R11_EAC; r_gl_format=GL_RED; r_gl_type=GL_UNSIGNED_BYTE; r_compressed=true; @@ -427,7 +441,7 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima if (config.etc2_supported) { - r_gl_internal_format=GL_COMPRESSED_SIGNED_R11_EAC; + r_gl_internal_format=_EXT_COMPRESSED_SIGNED_R11_EAC; r_gl_format=GL_RED; r_gl_type=GL_UNSIGNED_BYTE; r_compressed=true; @@ -441,7 +455,7 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima if (config.etc2_supported) { - r_gl_internal_format=GL_COMPRESSED_RG11_EAC; + r_gl_internal_format=_EXT_COMPRESSED_RG11_EAC; r_gl_format=GL_RG; r_gl_type=GL_UNSIGNED_BYTE; r_compressed=true; @@ -454,7 +468,7 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima case Image::FORMAT_ETC2_RG11S: { if (config.etc2_supported) { - r_gl_internal_format=GL_COMPRESSED_SIGNED_RG11_EAC; + r_gl_internal_format=_EXT_COMPRESSED_SIGNED_RG11_EAC; r_gl_format=GL_RG; r_gl_type=GL_UNSIGNED_BYTE; r_compressed=true; @@ -467,7 +481,7 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima if (config.etc2_supported) { - r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?GL_COMPRESSED_SRGB8_ETC2:GL_COMPRESSED_RGB8_ETC2; + r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB8_ETC2:_EXT_COMPRESSED_RGB8_ETC2; r_gl_format=GL_RGB; r_gl_type=GL_UNSIGNED_BYTE; r_compressed=true; @@ -483,7 +497,7 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima if (config.etc2_supported) { - r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:GL_COMPRESSED_RGBA8_ETC2_EAC; + r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:_EXT_COMPRESSED_RGBA8_ETC2_EAC; r_gl_format=GL_RGBA; r_gl_type=GL_UNSIGNED_BYTE; r_compressed=true; @@ -499,7 +513,7 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima if (config.etc2_supported) { - r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; + r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:_EXT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; r_gl_format=GL_RGBA; r_gl_type=GL_UNSIGNED_BYTE; r_compressed=true; @@ -709,6 +723,32 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture,const Image& p_image glTexParameterf( texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); } + //set swizle for older format compatibility + switch(texture->format) { + + case Image::FORMAT_L8: { + glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_R,GL_RED); + glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_G,GL_RED); + glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_B,GL_RED); + glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_A,GL_ONE); + + } break; + case Image::FORMAT_LA8: { + + glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_R,GL_RED); + glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_G,GL_RED); + glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_B,GL_RED); + glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_A,GL_GREEN); + } break; + default: { + glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_R,GL_RED); + glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_G,GL_GREEN); + glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_B,GL_BLUE); + glTexParameteri(texture->target,GL_TEXTURE_SWIZZLE_A,GL_ALPHA); + + } break; + + } if (config.use_anisotropic_filter) { if (texture->flags&VS::TEXTURE_FLAG_ANISOTROPIC_FILTER) { @@ -782,7 +822,7 @@ Image RasterizerStorageGLES3::texture_get_data(RID p_texture,VS::CubeMapSide p_c ERR_FAIL_COND_V(texture->data_size==0,Image()); ERR_FAIL_COND_V(texture->render_target,Image()); -#ifdef GLEW_ENABLED +#ifdef GLES_OVER_GL DVector data; @@ -5068,9 +5108,14 @@ void RasterizerStorageGLES3::initialize() { /// { - Vector ext= String((const char*)glGetString( GL_EXTENSIONS )).split(" ",false); - for(int i=0;i strings; -#ifdef GLEW_ENABLED +#ifdef GLES_OVER_GL //strings.push_back("#version 330\n"); strings.push_back("#version 300 es\n"); #else @@ -709,6 +709,8 @@ void ShaderGLES3::setup(const char** p_conditional_defines, int p_conditional_co } } + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,&max_image_units); + } void ShaderGLES3::finish() { @@ -804,7 +806,7 @@ ShaderGLES3::ShaderGLES3() { last_custom_code=1; uniforms_dirty = true; base_material_tex_index=0; - glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,&max_image_units); + } -- cgit v1.2.3