Skip to content

Commit

Permalink
Clean up blend shape support in GLES2 and GLES3.
Browse files Browse the repository at this point in the history
  • Loading branch information
reduz committed Mar 1, 2019
1 parent e47915f commit 3f681b0
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 15 deletions.
20 changes: 20 additions & 0 deletions core/error_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ extern bool _err_error_exists;
_err_error_exists = false; \
}

#define ERR_PRINT_ONCE(m_string) \
{ \
static bool first_print = true; \
if (first_print) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
_err_error_exists = false; \
first_print = false; \
} \
}

/** Print a warning string.
*/

Expand All @@ -325,6 +335,16 @@ extern bool _err_error_exists;
_err_error_exists = false; \
}

#define WARN_PRINT_ONCE(m_string) \
{ \
static bool first_print = true; \
if (first_print) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
_err_error_exists = false; \
first_print = false; \
} \
}

#define WARN_DEPRECATED \
{ \
static volatile bool warning_shown = false; \
Expand Down
36 changes: 21 additions & 15 deletions drivers/gles2/rasterizer_storage_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

#include "rasterizer_storage_gles2.h"

#include "core/engine.h"
#include "core/math/transform.h"
#include "core/project_settings.h"
#include "rasterizer_canvas_gles2.h"
#include "rasterizer_scene_gles2.h"
#include "servers/visual/shader_language.h"

GLuint RasterizerStorageGLES2::system_fbo = 0;

/* TEXTURE API */
Expand Down Expand Up @@ -1308,19 +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) {
static bool show_warning = true; //show warning only once
if (show_warning) {
ERR_PRINT("Using both SCREEN_TEXTURE and DEPTH_TEXTURE is not supported in GLES2");
show_warning = false;
}
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) {
static bool show_warning = true; //show warning only once
if (show_warning) {
ERR_PRINT("Using DEPTH_TEXTURE is not permitted on this hardware, operation will fail.");
show_warning = false;
}
ERR_PRINT_ONCE("Using DEPTH_TEXTURE is not permitted on this hardware, operation will fail.");
}
} break;

Expand Down Expand Up @@ -2266,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;

Expand Down Expand Up @@ -2338,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;
}

Expand Down Expand Up @@ -2429,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;
}

Expand Down Expand Up @@ -2469,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);
Expand Down
1 change: 1 addition & 0 deletions drivers/gles2/rasterizer_storage_gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage {

PoolVector<uint8_t> data;
PoolVector<uint8_t> index_data;
Vector<PoolVector<uint8_t> > blend_shape_data;

int total_data_size;

Expand Down
1 change: 1 addition & 0 deletions drivers/gles3/rasterizer_storage_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3634,6 +3634,7 @@ void RasterizerStorageGLES3::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 RasterizerStorageGLES3::mesh_get_blend_shape_count(RID p_mesh) const {

Expand Down
2 changes: 2 additions & 0 deletions editor/import/editor_scene_importer_gltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,9 +892,11 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
primitive = primitives2[mode];
}

ERR_FAIL_COND_V(!a.has("POSITION"), ERR_PARSE_ERROR);
if (a.has("POSITION")) {
array[Mesh::ARRAY_VERTEX] = _decode_accessor_as_vec3(state, a["POSITION"], true);
}

if (a.has("NORMAL")) {
array[Mesh::ARRAY_NORMAL] = _decode_accessor_as_vec3(state, a["NORMAL"], true);
}
Expand Down
3 changes: 3 additions & 0 deletions servers/visual/visual_server_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ void VisualServerScene::instance_set_base(RID p_instance, RID p_base) {

InstanceGeometryData *geom = memnew(InstanceGeometryData);
instance->base_data = geom;
if (instance->base_type == VS::INSTANCE_MESH) {
instance->blend_values.resize(VSG::storage->mesh_get_blend_shape_count(p_base));
}
} break;
case VS::INSTANCE_REFLECTION_PROBE: {

Expand Down

0 comments on commit 3f681b0

Please sign in to comment.