diff options
Diffstat (limited to 'drivers/gles2')
-rw-r--r-- | drivers/gles2/rasterizer_canvas_gles2.cpp | 16 | ||||
-rw-r--r-- | drivers/gles2/rasterizer_scene_gles2.cpp | 13 | ||||
-rw-r--r-- | drivers/gles2/rasterizer_storage_gles2.cpp | 26 | ||||
-rw-r--r-- | drivers/gles2/rasterizer_storage_gles2.h | 7 | ||||
-rw-r--r-- | drivers/gles2/shaders/scene.glsl | 13 |
5 files changed, 56 insertions, 19 deletions
diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp index bf0da5feb1..3671679b49 100644 --- a/drivers/gles2/rasterizer_canvas_gles2.cpp +++ b/drivers/gles2/rasterizer_canvas_gles2.cpp @@ -202,12 +202,12 @@ RasterizerStorageGLES2::Texture *RasterizerCanvasGLES2::_bind_canvas_texture(con } else { - texture = texture->get_ptr(); - if (texture->redraw_if_visible) { VisualServerRaster::redraw_request(); } + texture = texture->get_ptr(); + if (texture->render_target) { texture->render_target->used_in_frame = true; } @@ -244,12 +244,12 @@ RasterizerStorageGLES2::Texture *RasterizerCanvasGLES2::_bind_canvas_texture(con } else { - normal_map = normal_map->get_ptr(); - if (normal_map->redraw_if_visible) { //check before proxy, because this is usually used with proxies VisualServerRaster::redraw_request(); } + normal_map = normal_map->get_ptr(); + glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2); glBindTexture(GL_TEXTURE_2D, normal_map->tex_id); state.current_normal = p_normal_map; @@ -1412,6 +1412,10 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons continue; } + if (t->redraw_if_visible) { + VisualServerRaster::redraw_request(); + } + t = t->get_ptr(); #ifdef TOOLS_ENABLED @@ -1422,10 +1426,6 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons if (t->render_target) t->render_target->used_in_frame = true; - if (t->redraw_if_visible) { - VisualServerRaster::redraw_request(); - } - glBindTexture(t->target, t->tex_id); } diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp index e0eec74700..5e006b7527 100644 --- a/drivers/gles2/rasterizer_scene_gles2.cpp +++ b/drivers/gles2/rasterizer_scene_gles2.cpp @@ -1312,12 +1312,12 @@ bool RasterizerSceneGLES2::_setup_material(RasterizerStorageGLES2::Material *p_m continue; } - t = t->get_ptr(); - if (t->redraw_if_visible) { //must check before proxy because this is often used with proxies VisualServerRaster::redraw_request(); } + t = t->get_ptr(); + #ifdef TOOLS_ENABLED if (t->detect_3d) { t->detect_3d(t->detect_3d_ud); @@ -1671,11 +1671,10 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) { if (c.texture.is_valid() && storage->texture_owner.owns(c.texture)) { RasterizerStorageGLES2::Texture *t = storage->texture_owner.get(c.texture); - t = t->get_ptr(); - if (t->redraw_if_visible) { VisualServerRaster::redraw_request(); } + t = t->get_ptr(); #ifdef TOOLS_ENABLED if (t->detect_3d) { @@ -2487,6 +2486,12 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, state.scene_shader.set_uniform(SceneShaderGLES2::WORLD_TRANSFORM, e->instance->transform); + if (skeleton) { + state.scene_shader.set_uniform(SceneShaderGLES2::SKELETON_IN_WORLD_COORDS, skeleton->use_world_transform); + state.scene_shader.set_uniform(SceneShaderGLES2::SKELETON_TRANSFORM, skeleton->world_transform); + state.scene_shader.set_uniform(SceneShaderGLES2::SKELETON_TRANSFORM_INVERSE, skeleton->world_transform_inverse); + } + if (use_lightmap_capture) { //this is per instance, must be set always if present glUniform4fv(state.scene_shader.get_uniform_location(SceneShaderGLES2::LIGHTMAP_CAPTURES), 12, (const GLfloat *)e->instance->lightmap_capture_data.ptr()); state.scene_shader.set_uniform(SceneShaderGLES2::LIGHTMAP_CAPTURE_SKY, false); diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index d5965bba4f..11ab8438df 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -429,7 +429,6 @@ Ref<Image> RasterizerStorageGLES2::_get_gl_image_and_format(const Ref<Image> &p_ if (!image.is_null()) { image = image->duplicate(); - print_line("decompressing..."); image->decompress(); ERR_FAIL_COND_V(image->is_compressed(), image); switch (image->get_format()) { @@ -2380,7 +2379,7 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS: surface->total_data_size += surface->array_byte_size + surface->index_array_byte_size; for (int i = 0; i < surface->skeleton_bone_used.size(); i++) { - surface->skeleton_bone_used.write[i] = surface->skeleton_bone_aabb[i].size.x < 0 || surface->skeleton_bone_aabb[i].size.y < 0 || surface->skeleton_bone_aabb[i].size.z < 0; + surface->skeleton_bone_used.write[i] = !(surface->skeleton_bone_aabb[i].size.x < 0 || surface->skeleton_bone_aabb[i].size.y < 0 || surface->skeleton_bone_aabb[i].size.z < 0); } for (int i = 0; i < VS::ARRAY_MAX; i++) { @@ -2688,7 +2687,7 @@ AABB RasterizerStorageGLES2::mesh_get_aabb(RID p_mesh, RID p_skeleton) const { mtx.basis[0].x = texture[base_ofs + 0]; mtx.basis[0].y = texture[base_ofs + 1]; mtx.origin.x = texture[base_ofs + 3]; - base_ofs += 256 * 4; + base_ofs += 4; mtx.basis[1].x = texture[base_ofs + 0]; mtx.basis[1].y = texture[base_ofs + 1]; mtx.origin.y = texture[base_ofs + 3]; @@ -2716,12 +2715,12 @@ AABB RasterizerStorageGLES2::mesh_get_aabb(RID p_mesh, RID p_skeleton) const { mtx.basis[0].y = texture[base_ofs + 1]; mtx.basis[0].z = texture[base_ofs + 2]; mtx.origin.x = texture[base_ofs + 3]; - base_ofs += 256 * 4; + base_ofs += 4; mtx.basis[1].x = texture[base_ofs + 0]; mtx.basis[1].y = texture[base_ofs + 1]; mtx.basis[1].z = texture[base_ofs + 2]; mtx.origin.y = texture[base_ofs + 3]; - base_ofs += 256 * 4; + base_ofs += 4; mtx.basis[2].x = texture[base_ofs + 0]; mtx.basis[2].y = texture[base_ofs + 1]; mtx.basis[2].z = texture[base_ofs + 2]; @@ -3599,6 +3598,23 @@ void RasterizerStorageGLES2::skeleton_set_base_transform_2d(RID p_skeleton, cons skeleton->base_transform_2d = p_base_transform; } +void RasterizerStorageGLES2::skeleton_set_world_transform(RID p_skeleton, bool p_enable, const Transform &p_world_transform) { + + Skeleton *skeleton = skeleton_owner.getornull(p_skeleton); + + ERR_FAIL_COND(skeleton->use_2d); + + skeleton->world_transform = p_world_transform; + skeleton->use_world_transform = p_enable; + if (p_enable) { + skeleton->world_transform_inverse = skeleton->world_transform.affine_inverse(); + } + + if (!skeleton->update_list.in_list()) { + skeleton_update_list.add(&skeleton->update_list); + } +} + void RasterizerStorageGLES2::_update_skeleton_transform_buffer(const PoolVector<float> &p_data, size_t p_size) { glBindBuffer(GL_ARRAY_BUFFER, resources.skeleton_transform_buffer); diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h index e6c23716a5..8f5565c96f 100644 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ b/drivers/gles2/rasterizer_storage_gles2.h @@ -864,12 +864,16 @@ public: Set<RasterizerScene::InstanceBase *> instances; Transform2D base_transform_2d; + Transform world_transform; + Transform world_transform_inverse; + bool use_world_transform; Skeleton() : use_2d(false), size(0), tex_id(0), - update_list(this) { + update_list(this), + use_world_transform(false) { } }; @@ -887,6 +891,7 @@ public: virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform); virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const; virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform); + virtual void skeleton_set_world_transform(RID p_skeleton, bool p_enable, const Transform &p_world_transform); void _update_skeleton_transform_buffer(const PoolVector<float> &p_data, size_t p_size); diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/gles2/shaders/scene.glsl index 371ea8498a..e3c6966e21 100644 --- a/drivers/gles2/shaders/scene.glsl +++ b/drivers/gles2/shaders/scene.glsl @@ -59,6 +59,10 @@ uniform ivec2 skeleton_texture_size; #endif +uniform highp mat4 skeleton_transform; +uniform highp mat4 skeleton_transform_inverse; +uniform bool skeleton_in_world_coords; + #endif #ifdef USE_INSTANCING @@ -404,7 +408,14 @@ void main() { #endif - world_matrix = bone_transform * world_matrix; + if (skeleton_in_world_coords) { + bone_transform = skeleton_transform * (bone_transform * skeleton_transform_inverse); + world_matrix = bone_transform * world_matrix; + } else { + world_matrix = world_matrix * bone_transform; + } + + #endif #ifdef USE_INSTANCING |