[GLES2] fix canvas_item sampler allocation

This commit is contained in:
Thomas Herzog 2018-08-23 16:46:43 +02:00
parent d1497b720e
commit da876907fd
5 changed files with 16 additions and 24 deletions

View File

@ -152,7 +152,7 @@ RasterizerStorageGLES2::Texture *RasterizerCanvasGLES2::_bind_canvas_texture(con
state.current_tex = RID(); state.current_tex = RID();
state.current_tex_ptr = NULL; state.current_tex_ptr = NULL;
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
} else { } else {
@ -167,7 +167,7 @@ RasterizerStorageGLES2::Texture *RasterizerCanvasGLES2::_bind_canvas_texture(con
texture->render_target->used_in_frame = true; texture->render_target->used_in_frame = true;
} }
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
glBindTexture(GL_TEXTURE_2D, texture->tex_id); glBindTexture(GL_TEXTURE_2D, texture->tex_id);
state.current_tex = p_texture; state.current_tex = p_texture;
@ -179,7 +179,7 @@ RasterizerStorageGLES2::Texture *RasterizerCanvasGLES2::_bind_canvas_texture(con
state.current_tex = RID(); state.current_tex = RID();
state.current_tex_ptr = NULL; state.current_tex_ptr = NULL;
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex); glBindTexture(GL_TEXTURE_2D, storage->resources.white_tex);
} }
@ -889,7 +889,7 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons
for (int i = 0; i < tc; i++) { for (int i = 0; i < tc; i++) {
glActiveTexture(GL_TEXTURE2 + i); glActiveTexture(GL_TEXTURE0 + i);
RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(textures[i].second); RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(textures[i].second);
@ -1027,8 +1027,8 @@ void RasterizerCanvasGLES2::reset_canvas() {
// keeping this for now as there's nothing else that uses texture unit 2 // keeping this for now as there's nothing else that uses texture unit 2
// TODO ^ // TODO ^
if (storage->frame.current_rt) { if (storage->frame.current_rt) {
glActiveTexture(GL_TEXTURE0 + 2); // glActiveTexture(GL_TEXTURE0 + 2);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->copy_screen_effect.color); // glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->copy_screen_effect.color);
} }
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);

View File

@ -327,7 +327,7 @@ void RasterizerGLES2::set_boot_image(const Ref<Image> &p_image, const Color &p_c
screenrect.position += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor(); screenrect.position += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor();
RasterizerStorageGLES2::Texture *t = storage->texture_owner.get(texture); RasterizerStorageGLES2::Texture *t = storage->texture_owner.get(texture);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
glBindTexture(GL_TEXTURE_2D, t->tex_id); glBindTexture(GL_TEXTURE_2D, t->tex_id);
canvas->draw_generic_textured_rect(screenrect, Rect2(0, 0, 1, 1)); canvas->draw_generic_textured_rect(screenrect, Rect2(0, 0, 1, 1));
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
@ -354,7 +354,7 @@ void RasterizerGLES2::blit_render_target_to_screen(RID p_render_target, const Re
canvas->canvas_begin(); canvas->canvas_begin();
glDisable(GL_BLEND); glDisable(GL_BLEND);
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES2::system_fbo); glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES2::system_fbo);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
glBindTexture(GL_TEXTURE_2D, rt->color); glBindTexture(GL_TEXTURE_2D, rt->color);
// TODO normals // TODO normals

View File

@ -1303,6 +1303,10 @@ void RasterizerStorageGLES2::shader_get_param_list(RID p_shader, List<PropertyIn
pi.hint = PROPERTY_HINT_RESOURCE_TYPE; pi.hint = PROPERTY_HINT_RESOURCE_TYPE;
pi.hint_string = "CubeMap"; pi.hint_string = "CubeMap";
} break; } break;
default: {
} break;
} }
p_param_list->push_back(pi); p_param_list->push_back(pi);

View File

@ -967,19 +967,7 @@ void ShaderGLES2::use_material(void *p_material) {
value.second.write[15].real = 1; value.second.write[15].real = 1;
} break; } break;
case ShaderLanguage::TYPE_SAMPLER2D: { default: {
} break;
case ShaderLanguage::TYPE_ISAMPLER2D: {
} break;
case ShaderLanguage::TYPE_USAMPLER2D: {
} break;
case ShaderLanguage::TYPE_SAMPLERCUBE: {
} break; } break;
} }

View File

@ -96,9 +96,9 @@ precision mediump float;
precision mediump int; precision mediump int;
#endif #endif
uniform sampler2D color_texture; // texunit:0 uniform sampler2D color_texture; // texunit:-1
uniform highp vec2 color_texpixel_size; uniform highp vec2 color_texpixel_size;
uniform mediump sampler2D normal_texture; // texunit:1 uniform mediump sampler2D normal_texture; // texunit:-2
varying mediump vec2 uv_interp; varying mediump vec2 uv_interp;
varying mediump vec4 color_interp; varying mediump vec4 color_interp;
@ -109,7 +109,7 @@ uniform vec4 final_modulate;
#ifdef SCREEN_TEXTURE_USED #ifdef SCREEN_TEXTURE_USED
uniform sampler2D screen_texture; // texunit:2 uniform sampler2D screen_texture; // texunit:-3
#endif #endif