summaryrefslogtreecommitdiff
path: root/drivers/gles2
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gles2')
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.cpp89
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.h2
-rw-r--r--drivers/gles2/rasterizer_storage_gles2.cpp142
-rw-r--r--drivers/gles2/rasterizer_storage_gles2.h8
-rw-r--r--drivers/gles2/shader_gles2.cpp535
-rw-r--r--drivers/gles2/shader_gles2.h275
6 files changed, 400 insertions, 651 deletions
diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp
index 0fd36cfb9c..e6f46776c0 100644
--- a/drivers/gles2/rasterizer_scene_gles2.cpp
+++ b/drivers/gles2/rasterizer_scene_gles2.cpp
@@ -83,7 +83,11 @@ void RasterizerSceneGLES2::shadow_atlas_set_size(RID p_atlas, int p_size) {
// erase the old atlast
if (shadow_atlas->fbo) {
- glDeleteTextures(1, &shadow_atlas->depth);
+ if (storage->config.use_rgba_3d_shadows) {
+ glDeleteRenderbuffers(1, &shadow_atlas->depth);
+ } else {
+ glDeleteTextures(1, &shadow_atlas->depth);
+ }
glDeleteFramebuffers(1, &shadow_atlas->fbo);
if (shadow_atlas->color) {
glDeleteTextures(1, &shadow_atlas->color);
@@ -111,18 +115,15 @@ void RasterizerSceneGLES2::shadow_atlas_set_size(RID p_atlas, int p_size) {
// create a depth texture
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, 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);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ if (storage->config.use_rgba_3d_shadows) {
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadow_atlas->depth, 0);
+ //maximum compatibility, renderbuffer and RGBA shadow
+ glGenRenderbuffers(1, &shadow_atlas->depth);
+ glBindRenderbuffer(GL_RENDERBUFFER, directional_shadow.depth);
+ glRenderbufferStorage(GL_RENDERBUFFER, storage->config.depth_internalformat, shadow_atlas->size, shadow_atlas->size);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, shadow_atlas->depth);
- if (storage->config.use_rgba_3d_shadows) {
glGenTextures(1, &shadow_atlas->color);
glBindTexture(GL_TEXTURE_2D, shadow_atlas->color);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, shadow_atlas->size, shadow_atlas->size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
@@ -131,6 +132,18 @@ void RasterizerSceneGLES2::shadow_atlas_set_size(RID p_atlas, int p_size) {
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, shadow_atlas->color, 0);
+ } else {
+ //just depth texture
+ glGenTextures(1, &shadow_atlas->depth);
+ glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth);
+ glTexImage2D(GL_TEXTURE_2D, 0, storage->config.depth_internalformat, shadow_atlas->size, shadow_atlas->size, 0, GL_DEPTH_COMPONENT, storage->config.depth_type, 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);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadow_atlas->depth, 0);
}
glViewport(0, 0, shadow_atlas->size, shadow_atlas->size);
@@ -475,7 +488,8 @@ RID RasterizerSceneGLES2::reflection_probe_instance_create(RID p_probe) {
glGenTextures(1, &rpi->color[i]);
}
- glGenTextures(1, &rpi->depth);
+ glGenRenderbuffers(1, &rpi->depth);
+
rpi->cubemap = 0;
//glGenTextures(1, &rpi->cubemap);
@@ -524,8 +538,8 @@ bool RasterizerSceneGLES2::reflection_probe_instance_begin_render(RID p_instance
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, rpi->depth);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, size, size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
+ glBindRenderbuffer(GL_RENDERBUFFER, rpi->depth);
+ glRenderbufferStorage(GL_RENDERBUFFER, storage->config.depth_internalformat, size, size);
if (rpi->cubemap != 0) {
glDeleteTextures(1, &rpi->cubemap);
@@ -547,7 +561,7 @@ bool RasterizerSceneGLES2::reflection_probe_instance_begin_render(RID p_instance
glBindTexture(GL_TEXTURE_2D, rpi->color[i]);
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, size, size, 0, format, type, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rpi->color[i], 0);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, rpi->depth, 0);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rpi->depth);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE);
}
@@ -566,8 +580,6 @@ bool RasterizerSceneGLES2::reflection_probe_instance_begin_render(RID p_instance
//adjust framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, rpi->fbo[i]);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _cube_side_enum[i], rpi->cubemap, 0);
- glBindRenderbuffer(GL_RENDERBUFFER, rpi->depth);
- glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, size, size); // Note: used to be _DEPTH_COMPONENT24_OES. GL_DEPTH_COMPONENT untested.
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rpi->depth);
#ifdef DEBUG_ENABLED
@@ -1265,9 +1277,9 @@ bool RasterizerSceneGLES2::_setup_material(RasterizerStorageGLES2::Material *p_m
}
int tc = p_material->textures.size();
- Pair<StringName, RID> *textures = p_material->textures.ptrw();
+ const Pair<StringName, RID> *textures = p_material->textures.ptr();
- ShaderLanguage::ShaderNode::Uniform::Hint *texture_hints = p_material->shader->texture_hints.ptrw();
+ const ShaderLanguage::ShaderNode::Uniform::Hint *texture_hints = p_material->shader->texture_hints.ptr();
state.scene_shader.set_uniform(SceneShaderGLES2::SKELETON_TEXTURE_SIZE, p_skeleton_tex_size);
@@ -2977,7 +2989,7 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_
if (light->type == VS::LIGHT_OMNI) {
// cubemap only
- if (light->omni_shadow_mode == VS::LIGHT_OMNI_SHADOW_CUBE && storage->config.support_write_depth) {
+ if (light->omni_shadow_mode == VS::LIGHT_OMNI_SHADOW_CUBE && storage->config.support_shadow_cubemaps) {
int cubemap_index = shadow_cubemaps.size() - 1;
// find an appropriate cubemap to render to
@@ -3075,7 +3087,7 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_
state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH_DUAL_PARABOLOID, false);
// convert cubemap to dual paraboloid if needed
- if (light->type == VS::LIGHT_OMNI && (light->omni_shadow_mode == VS::LIGHT_OMNI_SHADOW_CUBE && storage->config.support_write_depth) && p_pass == 5) {
+ if (light->type == VS::LIGHT_OMNI && (light->omni_shadow_mode == VS::LIGHT_OMNI_SHADOW_CUBE && storage->config.support_shadow_cubemaps) && p_pass == 5) {
ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas);
glBindFramebuffer(GL_FRAMEBUFFER, shadow_atlas->fbo);
@@ -3172,7 +3184,7 @@ bool RasterizerSceneGLES2::free(RID p_rid) {
if (reflection_instance->cubemap != 0) {
glDeleteTextures(1, &reflection_instance->cubemap);
}
- glDeleteTextures(1, &reflection_instance->depth);
+ glDeleteRenderbuffers(1, &reflection_instance->depth);
reflection_probe_release_atlas_index(p_rid);
reflection_probe_instance_owner.free(p_rid);
@@ -3253,7 +3265,7 @@ void RasterizerSceneGLES2::initialize() {
}
// cubemaps for shadows
- if (storage->config.support_write_depth) { //not going to be used
+ if (storage->config.support_shadow_cubemaps) { //not going to be used
int max_shadow_cubemap_sampler_size = 512;
int cube_size = max_shadow_cubemap_sampler_size;
@@ -3271,7 +3283,7 @@ void RasterizerSceneGLES2::initialize() {
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, storage->config.depth_internalformat, cube_size, cube_size, 0, GL_DEPTH_COMPONENT, storage->config.depth_type, NULL);
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -3302,19 +3314,13 @@ void RasterizerSceneGLES2::initialize() {
glGenFramebuffers(1, &directional_shadow.fbo);
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);
-
- 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);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, directional_shadow.depth, 0);
-
if (storage->config.use_rgba_3d_shadows) {
+ //maximum compatibility, renderbuffer and RGBA shadow
+ glGenRenderbuffers(1, &directional_shadow.depth);
+ glBindRenderbuffer(GL_RENDERBUFFER, directional_shadow.depth);
+ glRenderbufferStorage(GL_RENDERBUFFER, storage->config.depth_internalformat, directional_shadow.size, directional_shadow.size);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, directional_shadow.depth);
+
glGenTextures(1, &directional_shadow.color);
glBindTexture(GL_TEXTURE_2D, directional_shadow.color);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, directional_shadow.size, directional_shadow.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
@@ -3323,6 +3329,19 @@ void RasterizerSceneGLES2::initialize() {
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, directional_shadow.color, 0);
+ } else {
+ //just a depth buffer
+ glGenTextures(1, &directional_shadow.depth);
+ glBindTexture(GL_TEXTURE_2D, directional_shadow.depth);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, storage->config.depth_internalformat, directional_shadow.size, directional_shadow.size, 0, GL_DEPTH_COMPONENT, storage->config.depth_type, 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);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, directional_shadow.depth, 0);
}
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
diff --git a/drivers/gles2/rasterizer_scene_gles2.h b/drivers/gles2/rasterizer_scene_gles2.h
index fbb8b7e9e5..f23e45b52f 100644
--- a/drivers/gles2/rasterizer_scene_gles2.h
+++ b/drivers/gles2/rasterizer_scene_gles2.h
@@ -475,7 +475,7 @@ public:
virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform);
virtual void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale = 1.0);
virtual void light_instance_mark_visible(RID p_light_instance);
- virtual bool light_instances_can_render_shadow_cube() const { return storage->config.support_write_depth; }
+ virtual bool light_instances_can_render_shadow_cube() const { return storage->config.support_shadow_cubemaps; }
LightInstance **render_light_instances;
int render_directional_lights;
diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp
index 9d2e609e5e..c106712526 100644
--- a/drivers/gles2/rasterizer_storage_gles2.cpp
+++ b/drivers/gles2/rasterizer_storage_gles2.cpp
@@ -56,6 +56,8 @@ GLuint RasterizerStorageGLES2::system_fbo = 0;
#define _RED_OES 0x1903
+#define _DEPTH_COMPONENT24_OES 0x81A6
+
void RasterizerStorageGLES2::bind_quad_array() const {
glBindBuffer(GL_ARRAY_BUFFER, resources.quadie);
glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0);
@@ -1306,7 +1308,11 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const {
actions->uniforms = &p_shader->uniforms;
if (p_shader->spatial.uses_screen_texture && p_shader->spatial.uses_depth_texture) {
- WARN_PRINT("Using both SCREEN_TEXTURE and DEPTH_TEXTURE is not supported in GLES2");
+ ERR_PRINT_ONCE("Using both SCREEN_TEXTURE and DEPTH_TEXTURE is not supported in GLES2");
+ }
+
+ if (p_shader->spatial.uses_depth_texture && !config.support_depth_texture) {
+ ERR_PRINT_ONCE("Using DEPTH_TEXTURE is not permitted on this hardware, operation will fail.");
}
} break;
@@ -2252,9 +2258,14 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS:
surface->aabb = p_aabb;
surface->max_bone = p_bone_aabbs.size();
-
+#ifdef TOOLS_ENABLED
+ surface->blend_shape_data = p_blend_shapes;
+ if (surface->blend_shape_data.size()) {
+ ERR_PRINT_ONCE("Blend shapes are not supported in OpenGL ES 2.0");
+ }
surface->data = array;
surface->index_data = p_index_array;
+#endif
surface->total_data_size += surface->array_byte_size + surface->index_array_byte_size;
@@ -2324,12 +2335,12 @@ void RasterizerStorageGLES2::mesh_set_blend_shape_count(RID p_mesh, int p_amount
ERR_FAIL_COND(p_amount < 0);
mesh->blend_shape_count = p_amount;
+ mesh->instance_change_notify(true, false);
}
int RasterizerStorageGLES2::mesh_get_blend_shape_count(RID p_mesh) const {
const Mesh *mesh = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND_V(!mesh, 0);
-
return mesh->blend_shape_count;
}
@@ -2415,7 +2426,9 @@ PoolVector<uint8_t> RasterizerStorageGLES2::mesh_surface_get_array(RID p_mesh, i
ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), PoolVector<uint8_t>());
Surface *surface = mesh->surfaces[p_surface];
-
+#ifndef TOOLS_ENABLED
+ ERR_PRINT("OpenGL ES 2.0 does not allow retrieving mesh array data");
+#endif
return surface->data;
}
@@ -2455,7 +2468,14 @@ AABB RasterizerStorageGLES2::mesh_surface_get_aabb(RID p_mesh, int p_surface) co
}
Vector<PoolVector<uint8_t> > RasterizerStorageGLES2::mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const {
- return Vector<PoolVector<uint8_t> >();
+ const Mesh *mesh = mesh_owner.getornull(p_mesh);
+ ERR_FAIL_COND_V(!mesh, Vector<PoolVector<uint8_t> >());
+ ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Vector<PoolVector<uint8_t> >());
+#ifndef TOOLS_ENABLED
+ ERR_PRINT("OpenGL ES 2.0 does not allow retrieving mesh array data");
+#endif
+
+ return mesh->surfaces[p_surface]->blend_shape_data;
}
Vector<AABB> RasterizerStorageGLES2::mesh_surface_get_skeleton_aabb(RID p_mesh, int p_surface) const {
const Mesh *mesh = mesh_owner.getornull(p_mesh);
@@ -4304,24 +4324,36 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) {
// depth
- glGenTextures(1, &rt->depth);
- glBindTexture(GL_TEXTURE_2D, rt->depth);
+ if (config.support_depth_texture) {
+ glGenTextures(1, &rt->depth);
+ glBindTexture(GL_TEXTURE_2D, rt->depth);
+ glTexImage2D(GL_TEXTURE_2D, 0, config.depth_internalformat, rt->width, rt->height, 0, GL_DEPTH_COMPONENT, config.depth_type, 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);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, rt->width, rt->height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, rt->depth, 0);
+ } else {
+ glGenRenderbuffers(1, &rt->depth);
+ glBindRenderbuffer(GL_RENDERBUFFER, rt->depth);
- 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);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glRenderbufferStorage(GL_RENDERBUFFER, config.depth_internalformat, rt->width, rt->height);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, rt->depth, 0);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth);
+ }
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
glDeleteFramebuffers(1, &rt->fbo);
- glDeleteTextures(1, &rt->depth);
+ if (config.support_depth_texture) {
+ glDeleteTextures(1, &rt->depth);
+ } else {
+ glDeleteRenderbuffers(1, &rt->depth);
+ }
glDeleteTextures(1, &rt->color);
rt->fbo = 0;
rt->width = 0;
@@ -4393,7 +4425,12 @@ void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) {
}
if (rt->depth) {
- glDeleteTextures(1, &rt->depth);
+ if (config.support_depth_texture) {
+ glDeleteTextures(1, &rt->depth);
+ } else {
+ glDeleteRenderbuffers(1, &rt->depth);
+ }
+
rt->depth = 0;
}
@@ -4531,17 +4568,10 @@ RID RasterizerStorageGLES2::canvas_light_shadow_buffer_create(int p_width) {
glGenFramebuffers(1, &cls->fbo);
glBindFramebuffer(GL_FRAMEBUFFER, cls->fbo);
- glGenTextures(1, &cls->depth);
- glBindTexture(GL_TEXTURE_2D, cls->depth);
-
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, cls->size, cls->height, 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);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, cls->depth, 0);
+ glGenRenderbuffers(1, &cls->depth);
+ glBindRenderbuffer(GL_RENDERBUFFER, cls->depth);
+ glRenderbufferStorage(GL_RENDERBUFFER, config.depth_internalformat, cls->size, cls->height);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, cls->depth);
glGenTextures(1, &cls->distance);
glBindTexture(GL_TEXTURE_2D, cls->distance);
@@ -4906,7 +4936,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) {
CanvasLightShadow *cls = canvas_light_shadow_owner.get(p_rid);
glDeleteFramebuffers(1, &cls->fbo);
- glDeleteTextures(1, &cls->depth);
+ glDeleteRenderbuffers(1, &cls->depth);
glDeleteTextures(1, &cls->distance);
canvas_light_shadow_owner.free(p_rid);
memdelete(cls);
@@ -4974,6 +5004,9 @@ void RasterizerStorageGLES2::initialize() {
config.pvrtc_supported = false;
config.etc1_supported = false;
config.support_npot_repeat_mipmap = true;
+ config.depth_internalformat = GL_DEPTH_COMPONENT;
+ config.depth_type = GL_UNSIGNED_INT;
+
#else
config.float_texture_supported = config.extensions.has("GL_ARB_texture_float") || config.extensions.has("GL_OES_texture_float");
config.s3tc_supported = config.extensions.has("GL_EXT_texture_compression_s3tc") || config.extensions.has("WEBGL_compressed_texture_s3tc");
@@ -4984,10 +5017,14 @@ void RasterizerStorageGLES2::initialize() {
#endif
#ifdef GLES_OVER_GL
config.use_rgba_2d_shadows = false;
+ config.support_depth_texture = true;
config.use_rgba_3d_shadows = false;
+ config.support_depth_cubemaps = true;
#else
config.use_rgba_2d_shadows = !(config.float_texture_supported && config.extensions.has("GL_EXT_texture_rg"));
- config.use_rgba_3d_shadows = config.extensions.has("GL_OES_depth_texture");
+ config.support_depth_texture = config.extensions.has("GL_OES_depth_texture");
+ config.use_rgba_3d_shadows = !config.support_depth_texture;
+ config.support_depth_cubemaps = config.extensions.has("GL_OES_depth_texture_cube_map");
#endif
#ifdef GLES_OVER_GL
@@ -5011,6 +5048,55 @@ void RasterizerStorageGLES2::initialize() {
config.support_half_float_vertices = true;
#endif
+ //determine formats for depth textures (or renderbuffers)
+ if (config.support_depth_texture) {
+ // Will use texture for depth
+ // have to manually see if we can create a valid framebuffer texture using UNSIGNED_INT,
+ // as there is no extension to test for this.
+ GLuint fbo;
+ glGenFramebuffers(1, &fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ GLuint depth;
+ glGenTextures(1, &depth);
+ glBindTexture(GL_TEXTURE_2D, depth);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 32, 32, 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);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth, 0);
+
+ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+
+ if (status == GL_FRAMEBUFFER_COMPLETE) {
+ config.depth_internalformat = GL_DEPTH_COMPONENT;
+ config.depth_type = GL_UNSIGNED_INT;
+ } else {
+ config.depth_internalformat = GL_DEPTH_COMPONENT16;
+ config.depth_type = GL_UNSIGNED_SHORT;
+ }
+
+ glBindFramebuffer(GL_FRAMEBUFFER, system_fbo);
+ glDeleteFramebuffers(1, &fbo);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ glDeleteTextures(1, &depth);
+
+ } else {
+ // Will use renderbuffer for depth
+ if (config.extensions.has("GL_OES_depth24")) {
+ config.depth_internalformat = _DEPTH_COMPONENT24_OES;
+ config.depth_type = GL_UNSIGNED_INT;
+ } else {
+ config.depth_internalformat = GL_DEPTH_COMPONENT16;
+ config.depth_type = GL_UNSIGNED_SHORT;
+ }
+ }
+
+ //picky requirements for these
+ config.support_shadow_cubemaps = config.support_depth_texture && config.support_write_depth && config.support_depth_cubemaps;
+
frame.count = 0;
frame.delta = 0;
frame.current_rt = NULL;
diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h
index f6c8faa497..cad3af200e 100644
--- a/drivers/gles2/rasterizer_storage_gles2.h
+++ b/drivers/gles2/rasterizer_storage_gles2.h
@@ -85,6 +85,13 @@ public:
bool support_write_depth;
bool support_half_float_vertices;
bool support_npot_repeat_mipmap;
+ bool support_depth_texture;
+ bool support_depth_cubemaps;
+
+ bool support_shadow_cubemaps;
+
+ GLuint depth_internalformat;
+ GLuint depth_type;
} config;
struct Resources {
@@ -628,6 +635,7 @@ public:
PoolVector<uint8_t> data;
PoolVector<uint8_t> index_data;
+ Vector<PoolVector<uint8_t> > blend_shape_data;
int total_data_size;
diff --git a/drivers/gles2/shader_gles2.cpp b/drivers/gles2/shader_gles2.cpp
index 012d1538b6..6856035470 100644
--- a/drivers/gles2/shader_gles2.cpp
+++ b/drivers/gles2/shader_gles2.cpp
@@ -69,51 +69,6 @@ ShaderGLES2 *ShaderGLES2::active = NULL;
#endif
-void ShaderGLES2::bind_uniforms() {
- if (!uniforms_dirty)
- return;
-
- // regular uniforms
-
- const Map<uint32_t, Variant>::Element *E = uniform_defaults.front();
-
- while (E) {
- int idx = E->key();
- int location = version->uniform_location[idx];
-
- if (location < 0) {
- E = E->next();
- continue;
- }
-
- Variant v;
-
- v = E->value();
-
- _set_uniform_variant(location, v);
- E = E->next();
- }
-
- // camera uniforms
-
- const Map<uint32_t, CameraMatrix>::Element *C = uniform_cameras.front();
-
- while (C) {
- int idx = C->key();
- int location = version->uniform_location[idx];
-
- if (location < 0) {
- C = C->next();
- continue;
- }
-
- glUniformMatrix4fv(location, 1, GL_FALSE, &(C->get().matrix[0][0]));
- C = C->next();
- }
-
- uniforms_dirty = false;
-}
-
GLint ShaderGLES2::get_uniform_location(int p_index) const {
ERR_FAIL_COND_V(!version, -1);
@@ -139,28 +94,6 @@ bool ShaderGLES2::bind() {
glUseProgram(version->id);
- // find out uniform names and locations
-
- int count;
- glGetProgramiv(version->id, GL_ACTIVE_UNIFORMS, &count);
- version->uniform_names.resize(count);
-
- for (int i = 0; i < count; i++) {
- GLchar uniform_name[1024];
- int len = 0;
- GLint size = 0;
- GLenum type;
-
- glGetActiveUniform(version->id, i, 1024, &len, &size, &type, uniform_name);
-
- uniform_name[len] = '\0';
- String name = String((const char *)uniform_name);
-
- version->uniform_names.write[i] = name;
- }
-
- bind_uniforms();
-
DEBUG_TEST_ERROR("use program");
active = this;
@@ -513,6 +446,7 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() {
String native_uniform_name = _mkid(cc->texture_uniforms[i]);
GLint location = glGetUniformLocation(v.id, (native_uniform_name).ascii().get_data());
v.custom_uniform_locations[cc->texture_uniforms[i]] = location;
+ glUniform1i(location, i);
}
}
@@ -732,342 +666,317 @@ void ShaderGLES2::use_material(void *p_material) {
if (E->get().texture_order >= 0)
continue; // this is a texture, doesn't go here
- Map<StringName, Variant>::Element *V = material->params.find(E->key());
+ Map<StringName, GLint>::Element *L = v->custom_uniform_locations.find(E->key());
+ if (!L || L->get() < 0)
+ continue; //uniform not valid
- Pair<ShaderLanguage::DataType, Vector<ShaderLanguage::ConstantNode::Value> > value;
+ GLuint location = L->get();
- value.first = E->get().type;
- value.second = E->get().default_value;
+ Map<StringName, Variant>::Element *V = material->params.find(E->key());
if (V) {
- value.second = Vector<ShaderLanguage::ConstantNode::Value>();
- value.second.resize(E->get().default_value.size());
switch (E->get().type) {
case ShaderLanguage::TYPE_BOOL: {
- if (value.second.size() < 1)
- value.second.resize(1);
- value.second.write[0].boolean = V->get();
+
+ bool boolean = V->get();
+ glUniform1i(location, boolean ? 1 : 0);
} break;
case ShaderLanguage::TYPE_BVEC2: {
- if (value.second.size() < 2)
- value.second.resize(2);
int flags = V->get();
- value.second.write[0].boolean = flags & 1;
- value.second.write[1].boolean = flags & 2;
+ glUniform2i(location, (flags & 1) ? 1 : 0, (flags & 2) ? 1 : 0);
} break;
case ShaderLanguage::TYPE_BVEC3: {
- if (value.second.size() < 3)
- value.second.resize(3);
+
int flags = V->get();
- value.second.write[0].boolean = flags & 1;
- value.second.write[1].boolean = flags & 2;
- value.second.write[2].boolean = flags & 4;
+ glUniform3i(location, (flags & 1) ? 1 : 0, (flags & 2) ? 1 : 0, (flags & 4) ? 1 : 0);
} break;
case ShaderLanguage::TYPE_BVEC4: {
- if (value.second.size() < 4)
- value.second.resize(4);
int flags = V->get();
- value.second.write[0].boolean = flags & 1;
- value.second.write[1].boolean = flags & 2;
- value.second.write[2].boolean = flags & 4;
- value.second.write[3].boolean = flags & 8;
+ glUniform4i(location, (flags & 1) ? 1 : 0, (flags & 2) ? 1 : 0, (flags & 4) ? 1 : 0, (flags & 8) ? 1 : 0);
} break;
- case ShaderLanguage::TYPE_INT: {
- if (value.second.size() < 1)
- value.second.resize(1);
- int val = V->get();
- value.second.write[0].sint = val;
+ case ShaderLanguage::TYPE_INT:
+ case ShaderLanguage::TYPE_UINT: {
+ int value = V->get();
+ glUniform1i(location, value);
} break;
- case ShaderLanguage::TYPE_IVEC2: {
- if (value.second.size() < 2)
- value.second.resize(2);
- PoolIntArray val = V->get();
- for (int i = 0; i < val.size(); i++) {
- value.second.write[i].sint = val[i];
+ case ShaderLanguage::TYPE_IVEC2:
+ case ShaderLanguage::TYPE_UVEC2: {
+
+ Array r = V->get();
+ const int count = 2;
+ if (r.size() == count) {
+ int values[count];
+ for (int i = 0; i < count; i++) {
+ values[i] = r[i];
+ }
+ glUniform2i(location, values[0], values[1]);
}
+
} break;
- case ShaderLanguage::TYPE_IVEC3: {
- if (value.second.size() < 3)
- value.second.resize(3);
- PoolIntArray val = V->get();
- for (int i = 0; i < val.size(); i++) {
- value.second.write[i].sint = val[i];
+ case ShaderLanguage::TYPE_IVEC3:
+ case ShaderLanguage::TYPE_UVEC3: {
+ Array r = V->get();
+ const int count = 3;
+ if (r.size() == count) {
+ int values[count];
+ for (int i = 0; i < count; i++) {
+ values[i] = r[i];
+ }
+ glUniform3i(location, values[0], values[1], values[2]);
}
} break;
- case ShaderLanguage::TYPE_IVEC4: {
- if (value.second.size() < 4)
- value.second.resize(4);
- PoolIntArray val = V->get();
- for (int i = 0; i < val.size(); i++) {
- value.second.write[i].sint = val[i];
+ case ShaderLanguage::TYPE_IVEC4:
+ case ShaderLanguage::TYPE_UVEC4: {
+ Array r = V->get();
+ const int count = 4;
+ if (r.size() == count) {
+ int values[count];
+ for (int i = 0; i < count; i++) {
+ values[i] = r[i];
+ }
+ glUniform4i(location, values[0], values[1], values[2], values[3]);
}
} break;
- case ShaderLanguage::TYPE_UINT: {
- if (value.second.size() < 1)
- value.second.resize(1);
- uint32_t val = V->get();
- value.second.write[0].uint = val;
+ case ShaderLanguage::TYPE_FLOAT: {
+ float value = V->get();
+ glUniform1f(location, value);
+
} break;
- case ShaderLanguage::TYPE_UVEC2: {
- if (value.second.size() < 2)
- value.second.resize(2);
- PoolIntArray val = V->get();
- for (int i = 0; i < val.size(); i++) {
- value.second.write[i].uint = val[i];
- }
+ case ShaderLanguage::TYPE_VEC2: {
+ Vector2 value = V->get();
+ glUniform2f(location, value.x, value.y);
+ } break;
+ case ShaderLanguage::TYPE_VEC3: {
+ Vector3 value = V->get();
+ glUniform3f(location, value.x, value.y, value.z);
} break;
- case ShaderLanguage::TYPE_UVEC3: {
- if (value.second.size() < 3)
- value.second.resize(3);
- PoolIntArray val = V->get();
- for (int i = 0; i < val.size(); i++) {
- value.second.write[i].uint = val[i];
+ case ShaderLanguage::TYPE_VEC4: {
+ if (V->get().get_type() == Variant::COLOR) {
+ Color value = V->get();
+ glUniform4f(location, value.r, value.g, value.b, value.a);
+ } else if (V->get().get_type() == Variant::QUAT) {
+ Quat value = V->get();
+ glUniform4f(location, value.x, value.y, value.z, value.w);
+ } else {
+ Plane value = V->get();
+ glUniform4f(location, value.normal.x, value.normal.y, value.normal.z, value.d);
}
} break;
- case ShaderLanguage::TYPE_UVEC4: {
- if (value.second.size() < 4)
- value.second.resize(4);
- PoolIntArray val = V->get();
- for (int i = 0; i < val.size(); i++) {
- value.second.write[i].uint = val[i];
- }
+ case ShaderLanguage::TYPE_MAT2: {
+
+ Transform2D tr = V->get();
+ GLfloat matrix[4] = {
+ /* build a 16x16 matrix */
+ tr.elements[0][0],
+ tr.elements[0][1],
+ tr.elements[1][0],
+ tr.elements[1][1],
+ };
+ glUniformMatrix2fv(location, 1, GL_FALSE, matrix);
} break;
- case ShaderLanguage::TYPE_FLOAT: {
- if (value.second.size() < 1)
- value.second.resize(1);
- value.second.write[0].real = V->get();
+ case ShaderLanguage::TYPE_MAT3: {
+ Basis val = V->get();
+
+ GLfloat mat[9] = {
+ val.elements[0][0],
+ val.elements[1][0],
+ val.elements[2][0],
+ val.elements[0][1],
+ val.elements[1][1],
+ val.elements[2][1],
+ val.elements[0][2],
+ val.elements[1][2],
+ val.elements[2][2],
+ };
+
+ glUniformMatrix3fv(location, 1, GL_FALSE, mat);
+
+ } break;
+
+ case ShaderLanguage::TYPE_MAT4: {
+
+ Transform2D tr = V->get();
+ GLfloat matrix[16] = { /* build a 16x16 matrix */
+ tr.elements[0][0],
+ tr.elements[0][1],
+ 0,
+ 0,
+ tr.elements[1][0],
+ tr.elements[1][1],
+ 0,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ tr.elements[2][0],
+ tr.elements[2][1],
+ 0,
+ 1
+ };
+
+ glUniformMatrix4fv(location, 1, GL_FALSE, matrix);
+
+ } break;
+
+ default: {
+ ERR_PRINT("type missing, bug?");
+ } break;
+ }
+ } else if (E->get().default_value.size()) {
+ const Vector<ShaderLanguage::ConstantNode::Value> &values = E->get().default_value;
+ switch (E->get().type) {
+ case ShaderLanguage::TYPE_BOOL: {
+ glUniform1i(location, values[0].boolean);
+ } break;
+
+ case ShaderLanguage::TYPE_BVEC2: {
+ glUniform2i(location, values[0].boolean, values[1].boolean);
+ } break;
+
+ case ShaderLanguage::TYPE_BVEC3: {
+ glUniform3i(location, values[0].boolean, values[1].boolean, values[2].boolean);
+ } break;
+
+ case ShaderLanguage::TYPE_BVEC4: {
+ glUniform4i(location, values[0].boolean, values[1].boolean, values[2].boolean, values[3].boolean);
+ } break;
+
+ case ShaderLanguage::TYPE_INT: {
+ glUniform1i(location, values[0].sint);
+ } break;
+
+ case ShaderLanguage::TYPE_IVEC2: {
+ glUniform2i(location, values[0].sint, values[1].sint);
+ } break;
+
+ case ShaderLanguage::TYPE_IVEC3: {
+ glUniform3i(location, values[0].sint, values[1].sint, values[2].sint);
+ } break;
+
+ case ShaderLanguage::TYPE_IVEC4: {
+ glUniform4i(location, values[0].sint, values[1].sint, values[2].sint, values[3].sint);
+ } break;
+
+ case ShaderLanguage::TYPE_UINT: {
+ glUniform1i(location, values[0].uint);
+ } break;
+
+ case ShaderLanguage::TYPE_UVEC2: {
+ glUniform2i(location, values[0].uint, values[1].uint);
+ } break;
+ case ShaderLanguage::TYPE_UVEC3: {
+ glUniform3i(location, values[0].uint, values[1].uint, values[2].uint);
+ } break;
+
+ case ShaderLanguage::TYPE_UVEC4: {
+ glUniform4i(location, values[0].uint, values[1].uint, values[2].uint, values[3].uint);
+ } break;
+
+ case ShaderLanguage::TYPE_FLOAT: {
+ glUniform1f(location, values[0].real);
} break;
case ShaderLanguage::TYPE_VEC2: {
- if (value.second.size() < 2)
- value.second.resize(2);
- Vector2 val = V->get();
- value.second.write[0].real = val.x;
- value.second.write[1].real = val.y;
+ glUniform2f(location, values[0].real, values[1].real);
} break;
case ShaderLanguage::TYPE_VEC3: {
- if (value.second.size() < 3)
- value.second.resize(3);
- Vector3 val = V->get();
- value.second.write[0].real = val.x;
- value.second.write[1].real = val.y;
- value.second.write[2].real = val.z;
+ glUniform3f(location, values[0].real, values[1].real, values[2].real);
} break;
case ShaderLanguage::TYPE_VEC4: {
- if (value.second.size() < 4)
- value.second.resize(4);
- if (V->get().get_type() == Variant::PLANE) {
- Plane val = V->get();
- value.second.write[0].real = val.normal.x;
- value.second.write[1].real = val.normal.y;
- value.second.write[2].real = val.normal.z;
- value.second.write[3].real = val.d;
- } else {
- Color val = V->get();
- value.second.write[0].real = val.r;
- value.second.write[1].real = val.g;
- value.second.write[2].real = val.b;
- value.second.write[3].real = val.a;
- }
-
+ glUniform4f(location, values[0].real, values[1].real, values[2].real, values[3].real);
} break;
case ShaderLanguage::TYPE_MAT2: {
- Transform2D val = V->get();
+ GLfloat mat[4];
- if (value.second.size() < 4) {
- value.second.resize(4);
+ for (int i = 0; i < 4; i++) {
+ mat[i] = values[i].real;
}
- 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];
-
+ glUniformMatrix2fv(location, 1, GL_FALSE, mat);
} break;
case ShaderLanguage::TYPE_MAT3: {
- Basis val = V->get();
+ GLfloat mat[9];
- if (value.second.size() < 9) {
- value.second.resize(9);
+ for (int i = 0; i < 9; i++) {
+ mat[i] = values[i].real;
}
- 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];
+ glUniformMatrix3fv(location, 1, GL_FALSE, mat);
+
} break;
case ShaderLanguage::TYPE_MAT4: {
- Transform val = V->get();
+ GLfloat mat[16];
- if (value.second.size() < 16) {
- value.second.resize(16);
+ for (int i = 0; i < 16; i++) {
+ mat[i] = values[i].real;
}
- 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;
+ glUniformMatrix4fv(location, 1, GL_FALSE, mat);
+
} break;
- default: {
+ case ShaderLanguage::TYPE_SAMPLER2D: {
} break;
- }
- } else {
- if (value.second.size() == 0) {
- // No default value set... weird, let's just use zero for everything
- size_t default_arg_size = 1;
- bool is_float = false;
- switch (E->get().type) {
- case ShaderLanguage::TYPE_BOOL:
- case ShaderLanguage::TYPE_INT:
- case ShaderLanguage::TYPE_UINT: {
- default_arg_size = 1;
- } break;
-
- case ShaderLanguage::TYPE_FLOAT: {
- default_arg_size = 1;
- is_float = true;
- } break;
-
- case ShaderLanguage::TYPE_BVEC2:
- case ShaderLanguage::TYPE_IVEC2:
- case ShaderLanguage::TYPE_UVEC2: {
- default_arg_size = 2;
- } break;
-
- case ShaderLanguage::TYPE_VEC2: {
- default_arg_size = 2;
- is_float = true;
- } break;
-
- case ShaderLanguage::TYPE_BVEC3:
- case ShaderLanguage::TYPE_IVEC3:
- case ShaderLanguage::TYPE_UVEC3: {
- default_arg_size = 3;
- } break;
-
- case ShaderLanguage::TYPE_VEC3: {
- default_arg_size = 3;
- is_float = true;
- } break;
-
- case ShaderLanguage::TYPE_BVEC4:
- case ShaderLanguage::TYPE_IVEC4:
- case ShaderLanguage::TYPE_UVEC4: {
- default_arg_size = 4;
- } break;
-
- case ShaderLanguage::TYPE_VEC4: {
- default_arg_size = 4;
- is_float = true;
- } break;
-
- default: {
- // TODO matricies and all that stuff
- default_arg_size = 1;
- } break;
- }
-
- value.second.resize(default_arg_size);
-
- for (size_t i = 0; i < default_arg_size; i++) {
- if (is_float) {
- value.second.write[i].real = 0.0;
- } else {
- value.second.write[i].uint = 0;
- }
- }
- }
- }
- GLint location;
- if (v->custom_uniform_locations.has(E->key())) {
- location = v->custom_uniform_locations[E->key()];
- } else {
- int idx = v->uniform_names.find(E->key()); // TODO maybe put those in a Map?
- if (idx < 0) {
- location = -1;
- } else {
- location = v->uniform_location[idx];
- }
- }
+ case ShaderLanguage::TYPE_ISAMPLER2D: {
- _set_uniform_value(location, value);
- }
+ } break;
- // bind textures
- int tc = material->textures.size();
- Pair<StringName, RID> *textures = material->textures.ptrw();
+ case ShaderLanguage::TYPE_USAMPLER2D: {
- for (int i = 0; i < tc; i++) {
+ } break;
- Pair<ShaderLanguage::DataType, Vector<ShaderLanguage::ConstantNode::Value> > value;
- value.first = ShaderLanguage::TYPE_INT;
- value.second.resize(1);
- value.second.write[0].sint = i;
+ case ShaderLanguage::TYPE_SAMPLERCUBE: {
- // GLint location = get_uniform_location(textures[i].first);
+ } break;
- // if (location < 0) {
- // location = material->shader->uniform_locations[textures[i].first];
- // }
- GLint location = -1;
- if (v->custom_uniform_locations.has(textures[i].first)) {
- location = v->custom_uniform_locations[textures[i].first];
- } else {
- location = get_uniform_location(textures[i].first);
- }
+ case ShaderLanguage::TYPE_SAMPLER2DARRAY:
+ case ShaderLanguage::TYPE_ISAMPLER2DARRAY:
+ case ShaderLanguage::TYPE_USAMPLER2DARRAY:
+ case ShaderLanguage::TYPE_SAMPLER3D:
+ case ShaderLanguage::TYPE_ISAMPLER3D:
+ case ShaderLanguage::TYPE_USAMPLER3D: {
+ // Not implemented in GLES2
+ } break;
- _set_uniform_value(location, value);
+ case ShaderLanguage::TYPE_VOID: {
+ // Nothing to do?
+ } break;
+ default: {
+ ERR_PRINT("type missing, bug?");
+ } break;
+ }
+ }
}
}
-void ShaderGLES2::set_base_material_tex_index(int p_idx) {
-}
-
ShaderGLES2::ShaderGLES2() {
version = NULL;
last_custom_code = 1;
diff --git a/drivers/gles2/shader_gles2.h b/drivers/gles2/shader_gles2.h
index d493880d0b..ebea40e10e 100644
--- a/drivers/gles2/shader_gles2.h
+++ b/drivers/gles2/shader_gles2.h
@@ -1,4 +1,4 @@
-/*************************************************************************/
+/*************************************************************************/
/* shader_gles2.h */
/*************************************************************************/
/* This file is part of: */
@@ -112,7 +112,6 @@ private:
GLuint id;
GLuint vert_id;
GLuint frag_id;
- Vector<StringName> uniform_names;
GLint *uniform_location;
Vector<GLint> texture_uniform_locations;
Map<StringName, GLint> custom_uniform_locations;
@@ -177,9 +176,6 @@ private:
int max_image_units;
- Map<uint32_t, Variant> uniform_defaults;
- Map<uint32_t, CameraMatrix> uniform_cameras;
-
Map<StringName, Pair<ShaderLanguage::DataType, Vector<ShaderLanguage::ConstantNode::Value> > > uniform_values;
protected:
@@ -212,246 +208,11 @@ public:
static _FORCE_INLINE_ ShaderGLES2 *get_active() { return active; }
bool bind();
void unbind();
- void bind_uniforms();
inline GLuint get_program() const { return version ? version->id : 0; }
void clear_caches();
- _FORCE_INLINE_ void _set_uniform_value(GLint p_uniform, const Pair<ShaderLanguage::DataType, Vector<ShaderLanguage::ConstantNode::Value> > &value) {
- if (p_uniform < 0)
- return;
-
- const Vector<ShaderLanguage::ConstantNode::Value> &values = value.second;
-
- switch (value.first) {
- case ShaderLanguage::TYPE_BOOL: {
- glUniform1i(p_uniform, values[0].boolean);
- } break;
-
- case ShaderLanguage::TYPE_BVEC2: {
- glUniform2i(p_uniform, values[0].boolean, values[1].boolean);
- } break;
-
- case ShaderLanguage::TYPE_BVEC3: {
- glUniform3i(p_uniform, values[0].boolean, values[1].boolean, values[2].boolean);
- } break;
-
- case ShaderLanguage::TYPE_BVEC4: {
- glUniform4i(p_uniform, values[0].boolean, values[1].boolean, values[2].boolean, values[3].boolean);
- } break;
-
- case ShaderLanguage::TYPE_INT: {
- glUniform1i(p_uniform, values[0].sint);
- } break;
-
- case ShaderLanguage::TYPE_IVEC2: {
- glUniform2i(p_uniform, values[0].sint, values[1].sint);
- } break;
-
- case ShaderLanguage::TYPE_IVEC3: {
- glUniform3i(p_uniform, values[0].sint, values[1].sint, values[2].sint);
- } break;
-
- case ShaderLanguage::TYPE_IVEC4: {
- glUniform4i(p_uniform, values[0].sint, values[1].sint, values[2].sint, values[3].sint);
- } break;
-
- case ShaderLanguage::TYPE_UINT: {
- glUniform1i(p_uniform, values[0].uint);
- } break;
-
- case ShaderLanguage::TYPE_UVEC2: {
- glUniform2i(p_uniform, values[0].uint, values[1].uint);
- } break;
-
- case ShaderLanguage::TYPE_UVEC3: {
- glUniform3i(p_uniform, values[0].uint, values[1].uint, values[2].uint);
- } break;
-
- case ShaderLanguage::TYPE_UVEC4: {
- glUniform4i(p_uniform, values[0].uint, values[1].uint, values[2].uint, values[3].uint);
- } break;
-
- case ShaderLanguage::TYPE_FLOAT: {
- glUniform1f(p_uniform, values[0].real);
- } break;
-
- case ShaderLanguage::TYPE_VEC2: {
- glUniform2f(p_uniform, values[0].real, values[1].real);
- } break;
-
- case ShaderLanguage::TYPE_VEC3: {
- glUniform3f(p_uniform, values[0].real, values[1].real, values[2].real);
- } break;
-
- case ShaderLanguage::TYPE_VEC4: {
- glUniform4f(p_uniform, values[0].real, values[1].real, values[2].real, values[3].real);
- } break;
-
- case ShaderLanguage::TYPE_MAT2: {
- GLfloat mat[4];
-
- for (int i = 0; i < 4; i++) {
- mat[i] = values[i].real;
- }
-
- glUniformMatrix2fv(p_uniform, 1, GL_FALSE, mat);
- } break;
-
- case ShaderLanguage::TYPE_MAT3: {
- GLfloat mat[9];
-
- for (int i = 0; i < 9; i++) {
- mat[i] = values[i].real;
- }
-
- glUniformMatrix3fv(p_uniform, 1, GL_FALSE, mat);
-
- } break;
-
- case ShaderLanguage::TYPE_MAT4: {
- GLfloat mat[16];
-
- for (int i = 0; i < 16; i++) {
- mat[i] = values[i].real;
- }
-
- glUniformMatrix4fv(p_uniform, 1, GL_FALSE, mat);
-
- } break;
-
- case ShaderLanguage::TYPE_SAMPLER2D: {
-
- } break;
-
- case ShaderLanguage::TYPE_ISAMPLER2D: {
-
- } break;
-
- case ShaderLanguage::TYPE_USAMPLER2D: {
-
- } break;
-
- case ShaderLanguage::TYPE_SAMPLERCUBE: {
-
- } break;
-
- case ShaderLanguage::TYPE_SAMPLER2DARRAY:
- case ShaderLanguage::TYPE_ISAMPLER2DARRAY:
- case ShaderLanguage::TYPE_USAMPLER2DARRAY:
- case ShaderLanguage::TYPE_SAMPLER3D:
- case ShaderLanguage::TYPE_ISAMPLER3D:
- case ShaderLanguage::TYPE_USAMPLER3D: {
- // Not implemented in GLES2
- } break;
-
- case ShaderLanguage::TYPE_VOID: {
- // Nothing to do?
- } break;
- }
- }
-
- _FORCE_INLINE_ void _set_uniform_variant(GLint p_uniform, const Variant &p_value) {
-
- if (p_uniform < 0)
- return; // do none
- switch (p_value.get_type()) {
-
- case Variant::BOOL:
- case Variant::INT: {
-
- int val = p_value;
- glUniform1i(p_uniform, val);
- } break;
- case Variant::REAL: {
-
- real_t val = p_value;
- glUniform1f(p_uniform, val);
- } break;
- case Variant::COLOR: {
-
- Color val = p_value;
- glUniform4f(p_uniform, val.r, val.g, val.b, val.a);
- } break;
- case Variant::VECTOR2: {
-
- Vector2 val = p_value;
- glUniform2f(p_uniform, val.x, val.y);
- } break;
- case Variant::VECTOR3: {
-
- Vector3 val = p_value;
- glUniform3f(p_uniform, val.x, val.y, val.z);
- } break;
- case Variant::PLANE: {
-
- Plane val = p_value;
- glUniform4f(p_uniform, val.normal.x, val.normal.y, val.normal.z, val.d);
- } break;
- case Variant::QUAT: {
-
- Quat val = p_value;
- glUniform4f(p_uniform, val.x, val.y, val.z, val.w);
- } break;
-
- case Variant::TRANSFORM2D: {
-
- Transform2D tr = p_value;
- GLfloat matrix[16] = { /* build a 16x16 matrix */
- tr.elements[0][0],
- tr.elements[0][1],
- 0,
- 0,
- tr.elements[1][0],
- tr.elements[1][1],
- 0,
- 0,
- 0,
- 0,
- 1,
- 0,
- tr.elements[2][0],
- tr.elements[2][1],
- 0,
- 1
- };
-
- glUniformMatrix4fv(p_uniform, 1, false, matrix);
-
- } break;
- case Variant::BASIS:
- case Variant::TRANSFORM: {
-
- Transform tr = p_value;
- GLfloat matrix[16] = { /* build a 16x16 matrix */
- tr.basis.elements[0][0],
- tr.basis.elements[1][0],
- tr.basis.elements[2][0],
- 0,
- tr.basis.elements[0][1],
- tr.basis.elements[1][1],
- tr.basis.elements[2][1],
- 0,
- tr.basis.elements[0][2],
- tr.basis.elements[1][2],
- tr.basis.elements[2][2],
- 0,
- tr.origin.x,
- tr.origin.y,
- tr.origin.z,
- 1
- };
-
- glUniformMatrix4fv(p_uniform, 1, false, matrix);
- } break;
- case Variant::OBJECT: {
-
- } break;
- default: { ERR_FAIL(); } // do nothing
- }
- }
-
uint32_t create_custom_shader();
void set_custom_shader_code(uint32_t p_code_id,
const String &p_vertex,
@@ -468,18 +229,6 @@ public:
uint32_t get_version_key() const { return conditional_version.version; }
- void set_uniform_default(int p_idx, const Variant &p_value) {
-
- if (p_value.get_type() == Variant::NIL) {
-
- uniform_defaults.erase(p_idx);
- } else {
-
- uniform_defaults[p_idx] = p_value;
- }
- uniforms_dirty = true;
- }
-
// this void* is actually a RasterizerStorageGLES2::Material, but C++ doesn't
// like forward declared nested classes.
void use_material(void *p_material);
@@ -487,31 +236,9 @@ public:
_FORCE_INLINE_ uint32_t get_version() const { return new_conditional_version.version; }
_FORCE_INLINE_ bool is_version_valid() const { return version && version->ok; }
- void set_uniform_camera(int p_idx, const CameraMatrix &p_mat) {
-
- uniform_cameras[p_idx] = p_mat;
- uniforms_dirty = true;
- }
-
- _FORCE_INLINE_ void set_texture_uniform(int p_idx, const Variant &p_value) {
-
- ERR_FAIL_COND(!version);
- ERR_FAIL_INDEX(p_idx, version->texture_uniform_locations.size());
- _set_uniform_variant(version->texture_uniform_locations[p_idx], p_value);
- }
-
- _FORCE_INLINE_ GLint get_texture_uniform_location(int p_idx) {
-
- ERR_FAIL_COND_V(!version, -1);
- ERR_FAIL_INDEX_V(p_idx, version->texture_uniform_locations.size(), -1);
- return version->texture_uniform_locations[p_idx];
- }
-
virtual void init() = 0;
void finish();
- void set_base_material_tex_index(int p_idx);
-
void add_custom_define(const String &p_define) {
custom_defines.push_back(p_define.utf8());
}