diff options
Diffstat (limited to 'drivers/gles2/shader_gles2.cpp')
-rw-r--r-- | drivers/gles2/shader_gles2.cpp | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/drivers/gles2/shader_gles2.cpp b/drivers/gles2/shader_gles2.cpp index 146575973f..e9b58cb272 100644 --- a/drivers/gles2/shader_gles2.cpp +++ b/drivers/gles2/shader_gles2.cpp @@ -527,8 +527,13 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() { for (int i = 0; i < texunit_pair_count; i++) { GLint loc = glGetUniformLocation(v.id, texunit_pairs[i].name); - if (loc >= 0) - glUniform1i(loc, texunit_pairs[i].index); + if (loc >= 0) { + if (texunit_pairs[i].index < 0) { + glUniform1i(loc, max_image_units + texunit_pairs[i].index); + } else { + glUniform1i(loc, texunit_pairs[i].index); + } + } } if (cc) { @@ -643,6 +648,8 @@ void ShaderGLES2::setup( } } } + + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_image_units); } void ShaderGLES2::finish() { @@ -717,7 +724,7 @@ void ShaderGLES2::free_custom_shader(uint32_t p_code_id) { custom_code_map.erase(p_code_id); } -void ShaderGLES2::use_material(void *p_material, int p_num_predef_textures) { +void ShaderGLES2::use_material(void *p_material) { RasterizerStorageGLES2::Material *material = (RasterizerStorageGLES2::Material *)p_material; if (!material) { @@ -906,20 +913,58 @@ void ShaderGLES2::use_material(void *p_material, int p_num_predef_textures) { case ShaderLanguage::TYPE_MAT2: { Transform2D val = V->get(); - // TODO + if (value.second.size() < 4) { + value.second.resize(4); + } + + value.second.write[0].real = val.elements[0][0]; + value.second.write[1].real = val.elements[0][1]; + value.second.write[2].real = val.elements[1][0]; + value.second.write[3].real = val.elements[1][1]; } break; case ShaderLanguage::TYPE_MAT3: { Basis val = V->get(); - // TODO + if (value.second.size() < 9) { + value.second.resize(9); + } + + value.second.write[0].real = val.elements[0][0]; + value.second.write[1].real = val.elements[0][1]; + value.second.write[2].real = val.elements[0][2]; + value.second.write[3].real = val.elements[1][0]; + value.second.write[4].real = val.elements[1][1]; + value.second.write[5].real = val.elements[1][2]; + value.second.write[6].real = val.elements[2][0]; + value.second.write[7].real = val.elements[2][1]; + value.second.write[8].real = val.elements[2][2]; } break; case ShaderLanguage::TYPE_MAT4: { Transform val = V->get(); - // TODO + if (value.second.size() < 16) { + value.second.resize(16); + } + + value.second.write[0].real = val.basis.elements[0][0]; + value.second.write[1].real = val.basis.elements[0][1]; + value.second.write[2].real = val.basis.elements[0][2]; + value.second.write[3].real = 0; + value.second.write[4].real = val.basis.elements[1][0]; + value.second.write[5].real = val.basis.elements[1][1]; + value.second.write[6].real = val.basis.elements[1][2]; + value.second.write[7].real = 0; + value.second.write[8].real = val.basis.elements[2][0]; + value.second.write[9].real = val.basis.elements[2][1]; + value.second.write[10].real = val.basis.elements[2][2]; + value.second.write[11].real = 0; + value.second.write[12].real = val.origin[0]; + value.second.write[13].real = val.origin[1]; + value.second.write[14].real = val.origin[2]; + value.second.write[15].real = 1; } break; case ShaderLanguage::TYPE_SAMPLER2D: { @@ -1034,7 +1079,7 @@ void ShaderGLES2::use_material(void *p_material, int p_num_predef_textures) { Pair<ShaderLanguage::DataType, Vector<ShaderLanguage::ConstantNode::Value> > value; value.first = ShaderLanguage::TYPE_INT; value.second.resize(1); - value.second.write[0].sint = p_num_predef_textures + i; + value.second.write[0].sint = i; // GLint location = get_uniform_location(textures[i].first); |