diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-02-22 19:14:21 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-02-22 19:14:21 -0300 |
commit | ffcd9542114cc984f5ecacf82990b9be6e4b1725 (patch) | |
tree | e6e8e26fbc9a0e478c1af3e29f43905f35ba4981 /drivers/gles3 | |
parent | 2c88f4d4b54dd106a2a4611109ebe8896c44aa43 (diff) |
Fixes to webgl/opengl es 3.0 for compatibility with webgl2.0, still does not work though
Diffstat (limited to 'drivers/gles3')
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.cpp | 17 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.cpp | 37 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.h | 2 | ||||
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 4 | ||||
-rw-r--r-- | drivers/gles3/shaders/ssao.glsl | 18 | ||||
-rw-r--r-- | drivers/gles3/shaders/ssao_minify.glsl | 2 |
6 files changed, 51 insertions, 29 deletions
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index ceb6bc336d..87a70d2750 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -133,7 +133,7 @@ void RasterizerSceneGLES3::shadow_atlas_set_size(RID p_atlas,int p_size){ glActiveTexture(GL_TEXTURE0); glGenTextures(1, &shadow_atlas->depth); glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadow_atlas->size, shadow_atlas->size, 0, + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, shadow_atlas->size, shadow_atlas->size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -2662,19 +2662,19 @@ void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result,int p_light_cu glBindBuffer(GL_UNIFORM_BUFFER, state.omni_array_ubo); glBufferSubData(GL_UNIFORM_BUFFER, 0, state.omni_light_count*state.ubo_light_size, state.omni_array_tmp); glBindBuffer(GL_UNIFORM_BUFFER, 0); - - glBindBufferBase(GL_UNIFORM_BUFFER,4,state.omni_array_ubo); } + glBindBufferBase(GL_UNIFORM_BUFFER,4,state.omni_array_ubo); + if (state.spot_light_count) { glBindBuffer(GL_UNIFORM_BUFFER, state.spot_array_ubo); glBufferSubData(GL_UNIFORM_BUFFER, 0, state.spot_light_count*state.ubo_light_size, state.spot_array_tmp); glBindBuffer(GL_UNIFORM_BUFFER, 0); - glBindBufferBase(GL_UNIFORM_BUFFER,5,state.spot_array_ubo); } + glBindBufferBase(GL_UNIFORM_BUFFER,5,state.spot_array_ubo); } @@ -2770,9 +2770,10 @@ void RasterizerSceneGLES3::_setup_reflections(RID *p_reflection_probe_cull_resul glBufferSubData(GL_UNIFORM_BUFFER, 0, state.reflection_probe_count*sizeof(ReflectionProbeDataUBO), state.reflection_array_tmp); glBindBuffer(GL_UNIFORM_BUFFER, 0); - glBindBufferBase(GL_UNIFORM_BUFFER,6,state.reflection_array_ubo); } + glBindBufferBase(GL_UNIFORM_BUFFER,6,state.reflection_array_ubo); + } @@ -4804,7 +4805,7 @@ void RasterizerSceneGLES3::initialize() { //gen cubemap first for(int i=0;i<6;i++) { - glTexImage2D(_cube_side_enum[i], 0, GL_DEPTH_COMPONENT, cube.size, cube.size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL); + glTexImage2D(_cube_side_enum[i], 0, GL_DEPTH_COMPONENT24, cube.size, cube.size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL); } glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -4838,7 +4839,7 @@ void RasterizerSceneGLES3::initialize() { glBindFramebuffer(GL_FRAMEBUFFER,directional_shadow.fbo); glGenTextures(1,&directional_shadow.depth); glBindTexture(GL_TEXTURE_2D,directional_shadow.depth); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, directional_shadow.size, directional_shadow.size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, directional_shadow.size, directional_shadow.size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -4928,7 +4929,7 @@ void RasterizerSceneGLES3::initialize() { glGenTextures(1,&cube.depth); glBindTexture(GL_TEXTURE_2D,cube.depth); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, cube.size, cube.size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, cube.size, cube.size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index ac8bf8c262..cec41aa251 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -93,16 +93,26 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima switch(p_format) { case Image::FORMAT_L8: { +#ifdef GLES_OVER_GL r_gl_internal_format=GL_R8; r_gl_format=GL_RED; r_gl_type=GL_UNSIGNED_BYTE; - +#else + r_gl_internal_format=GL_LUMINANCE; + r_gl_format=GL_LUMINANCE; + r_gl_type=GL_UNSIGNED_BYTE; +#endif } break; case Image::FORMAT_LA8: { - +#ifdef GLES_OVER_GL r_gl_internal_format=GL_RG8; r_gl_format=GL_RG; r_gl_type=GL_UNSIGNED_BYTE; +#else + r_gl_internal_format=GL_LUMINANCE_ALPHA; + r_gl_format=GL_LUMINANCE_ALPHA; + r_gl_type=GL_UNSIGNED_BYTE; +#endif } break; case Image::FORMAT_R8: { @@ -734,6 +744,7 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture,const Image& p_image } //set swizle for older format compatibility +#ifdef GLES_OVER_GL switch(texture->format) { case Image::FORMAT_L8: { @@ -759,6 +770,7 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture,const Image& p_image } break; } +#endif if (config.use_anisotropic_filter) { if (texture->flags&VS::TEXTURE_FLAG_ANISOTROPIC_FILTER) { @@ -1096,7 +1108,7 @@ RID RasterizerStorageGLES3::texture_create_radiance_cubemap(RID p_source,int p_r ERR_FAIL_COND_V(!texture,RID()); ERR_FAIL_COND_V(!(texture->flags&VS::TEXTURE_FLAG_CUBEMAP),RID()); - bool use_float=true; + bool use_float=config.hdr_supported; if (p_resolution<0) { p_resolution=texture->width; @@ -1316,7 +1328,7 @@ void RasterizerStorageGLES3::skybox_set_texture(RID p_skybox, RID p_cube_map, in int mm_level=mipmaps; - bool use_float=true; + bool use_float=config.hdr_supported; GLenum internal_format = use_float?GL_RGBA16F:GL_RGB10_A2; GLenum format = GL_RGBA; @@ -5570,9 +5582,10 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ GLuint color_type; Image::Format image_format; + bool hdr = rt->flags[RENDER_TARGET_HDR] && config.hdr_supported; + hdr=false; - - if (!rt->flags[RENDER_TARGET_HDR] || rt->flags[RENDER_TARGET_NO_3D]) { + if (!hdr || rt->flags[RENDER_TARGET_NO_3D]) { color_internal_format=GL_RGBA8; color_format=GL_RGBA; @@ -5597,7 +5610,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ glGenTextures(1, &rt->depth); glBindTexture(GL_TEXTURE_2D, rt->depth); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, rt->width, rt->height, 0, + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, rt->width, rt->height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -5621,6 +5634,10 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); + if (status != GL_FRAMEBUFFER_COMPLETE) { + printf("framebuffer fail, status: %x\n",status); + } + ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE ); Texture *tex = texture_owner.get(rt->texture); @@ -5668,7 +5685,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ if (msaa==0) glRenderbufferStorage(GL_RENDERBUFFER,color_internal_format,rt->width,rt->height); else - glRenderbufferStorageMultisample(GL_RENDERBUFFER,msaa,GL_RGBA16F,rt->width,rt->height); + glRenderbufferStorageMultisample(GL_RENDERBUFFER,msaa,color_internal_format,rt->width,rt->height); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_RENDERBUFFER,rt->buffers.diffuse); @@ -5676,7 +5693,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.specular); if (msaa==0) - glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA16F,rt->width,rt->height); + glRenderbufferStorage(GL_RENDERBUFFER,color_internal_format,rt->width,rt->height); else glRenderbufferStorageMultisample(GL_RENDERBUFFER,msaa,color_internal_format,rt->width,rt->height); @@ -6460,9 +6477,11 @@ void RasterizerStorageGLES3::initialize() { config.latc_supported=config.extensions.has("GL_EXT_texture_compression_latc"); config.bptc_supported=config.extensions.has("GL_ARB_texture_compression_bptc"); #ifdef GLES_OVER_GL + config.hdr_supported=true; config.etc2_supported=false; #else config.etc2_supported=true; + config.hdr_supported=false; #endif config.pvrtc_supported=config.extensions.has("GL_IMG_texture_compression_pvrtc"); config.srgb_decode_supported=config.extensions.has("GL_EXT_texture_sRGB_decode"); diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index e8cff3711c..ab5e5612c6 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -46,6 +46,8 @@ public: bool etc2_supported; bool pvrtc_supported; + bool hdr_supported; + bool srgb_decode_supported; bool use_rgba_2d_shadows; diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 3d81cc5a50..a0bf6cd58b 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -533,8 +533,8 @@ float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) { float ratio_incr = 1.0/steps; do { - source += incr*2; - bias+=incr*2; + source += incr*2.0; + bias+=incr*2.0; vec3 uv_depth = (source.xyz / source.w) * 0.5 + 0.5; float depth = texture(depth_buffer,uv_depth.xy).r; diff --git a/drivers/gles3/shaders/ssao.glsl b/drivers/gles3/shaders/ssao.glsl index 75f49ef37a..ba29ec52c7 100644 --- a/drivers/gles3/shaders/ssao.glsl +++ b/drivers/gles3/shaders/ssao.glsl @@ -29,7 +29,7 @@ void main() { uniform sampler2D source_depth; //texunit:0 -uniform usampler2D source_depth_mipmaps; //texunit:1 +uniform highp usampler2D source_depth_mipmaps; //texunit:1 uniform sampler2D source_normal; //texunit:2 uniform ivec2 screen_size; @@ -78,8 +78,8 @@ vec3 reconstructCSFaceNormal(vec3 C) { /** Returns a unit vector and a screen-space radius for the tap on a unit disk (the caller should scale by the actual disk radius) */ vec2 tapLocation(int sampleNumber, float spinAngle, out float ssR){ // Radius relative to ssR - float alpha = float(sampleNumber + 0.5) * (1.0 / NUM_SAMPLES); - float angle = alpha * (NUM_SPIRAL_TURNS * 6.28) + spinAngle; + float alpha = (float(sampleNumber) + 0.5) * (1.0 / float(NUM_SAMPLES)); + float angle = alpha * (float(NUM_SPIRAL_TURNS) * 6.28) + spinAngle; ssR = alpha; return vec2(cos(angle), sin(angle)); @@ -193,7 +193,7 @@ void main() { // Hash function used in the HPG12 AlchemyAO paper - float randomPatternRotationAngle = (3 * ssC.x ^ ssC.y + ssC.x * ssC.y) * 10; + float randomPatternRotationAngle = float((3 * ssC.x ^ ssC.y + ssC.x * ssC.y) * 10); // Reconstruct normals from positions. These will lead to 1-pixel black lines // at depth discontinuities, however the blur will wipe those out so they are not visible @@ -208,12 +208,12 @@ void main() { sum += sampleAO(ssC, C, n_C, ssDiskRadius, radius,i, randomPatternRotationAngle); } - float A = max(0.0, 1.0 - sum * intensity_div_r6 * (5.0 / NUM_SAMPLES)); + float A = max(0.0, 1.0 - sum * intensity_div_r6 * (5.0 / float(NUM_SAMPLES))); #ifdef ENABLE_RADIUS2 //go again for radius2 - randomPatternRotationAngle = (5 * ssC.x ^ ssC.y + ssC.x * ssC.y) * 11; + randomPatternRotationAngle = float((5 * ssC.x ^ ssC.y + ssC.x * ssC.y) * 11); // Reconstruct normals from positions. These will lead to 1-pixel black lines // at depth discontinuities, however the blur will wipe those out so they are not visible @@ -228,15 +228,15 @@ void main() { sum += sampleAO(ssC, C, n_C, ssDiskRadius,radius2, i, randomPatternRotationAngle); } - A= min(A,max(0.0, 1.0 - sum * intensity_div_r62 * (5.0 / NUM_SAMPLES))); + A= min(A,max(0.0, 1.0 - sum * intensity_div_r62 * (5.0 / float(NUM_SAMPLES)))); #endif // Bilateral box-filter over a quad for free, respecting depth edges // (the difference that this makes is subtle) if (abs(dFdx(C.z)) < 0.02) { - A -= dFdx(A) * ((ssC.x & 1) - 0.5); + A -= dFdx(A) * (float(ssC.x & 1) - 0.5); } if (abs(dFdy(C.z)) < 0.02) { - A -= dFdy(A) * ((ssC.y & 1) - 0.5); + A -= dFdy(A) * (float(ssC.y & 1) - 0.5); } visibility = A; diff --git a/drivers/gles3/shaders/ssao_minify.glsl b/drivers/gles3/shaders/ssao_minify.glsl index df9045c28a..6e46a1842c 100644 --- a/drivers/gles3/shaders/ssao_minify.glsl +++ b/drivers/gles3/shaders/ssao_minify.glsl @@ -43,7 +43,7 @@ void main() { fdepth = fdepth * 2.0 - 1.0; fdepth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - fdepth * (camera_z_far - camera_z_near)); fdepth /= camera_z_far; - depth = uint(clamp(fdepth*65535,0.0,65535.0)); + depth = uint(clamp(fdepth*65535.0,0.0,65535.0)); #else depth = texelFetch(source_depth, clamp(ssP * 2 + ivec2(ssP.y & 1, ssP.x & 1), ivec2(0), from_size - ivec2(1)), source_mipmap).r; |