summaryrefslogtreecommitdiffstats
path: root/scene/resources
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-11-24 20:46:55 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-11-24 20:46:55 -0300
commita732708b9dad4ebc118a0ce854f950c6becb984c (patch)
tree4e740d30a2449e065462bc408e23536d5270ca0e /scene/resources
parent69c30709ec6908e0960707501cc7fea58eb64f01 (diff)
downloadredot-engine-a732708b9dad4ebc118a0ce854f950c6becb984c.tar.gz
Blend shapes using transform feedback (GPU)
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/mesh.cpp6
-rw-r--r--scene/resources/mesh.h18
-rw-r--r--scene/resources/surface_tool.cpp38
3 files changed, 47 insertions, 15 deletions
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index e737c5c37e..ec33bb53d9 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -316,14 +316,14 @@ void Mesh::add_surface(uint32_t p_format,PrimitiveType p_primitive,const DVector
}
-void Mesh::add_surface_from_arrays(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes) {
+void Mesh::add_surface_from_arrays(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes,uint32_t p_flags) {
ERR_FAIL_COND(p_arrays.size()!=ARRAY_MAX);
Surface s;
- VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh,(VisualServer::PrimitiveType)p_primitive, p_arrays,p_blend_shapes);
+ VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh,(VisualServer::PrimitiveType)p_primitive, p_arrays,p_blend_shapes,p_flags);
surfaces.push_back(s);
@@ -1024,7 +1024,7 @@ void Mesh::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_morph_target_mode","mode"),&Mesh::set_morph_target_mode);
ObjectTypeDB::bind_method(_MD("get_morph_target_mode"),&Mesh::get_morph_target_mode);
- ObjectTypeDB::bind_method(_MD("add_surface_from_arrays","primitive","arrays","blend_shapes"),&Mesh::add_surface_from_arrays,DEFVAL(Array()));
+ ObjectTypeDB::bind_method(_MD("add_surface_from_arrays","primitive","arrays","blend_shapes","compress_flags"),&Mesh::add_surface_from_arrays,DEFVAL(Array()),DEFVAL(ARRAY_COMPRESS_DEFAULT));
ObjectTypeDB::bind_method(_MD("get_surface_count"),&Mesh::get_surface_count);
ObjectTypeDB::bind_method(_MD("surface_remove","surf_idx"),&Mesh::surface_remove);
ObjectTypeDB::bind_method(_MD("surface_get_array_len","surf_idx"),&Mesh::surface_get_array_len);
diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h
index 2b28f1187e..b671d8c3b3 100644
--- a/scene/resources/mesh.h
+++ b/scene/resources/mesh.h
@@ -77,6 +77,22 @@ public:
ARRAY_FORMAT_WEIGHTS=1<<ARRAY_WEIGHTS,
ARRAY_FORMAT_INDEX=1<<ARRAY_INDEX,
+ ARRAY_COMPRESS_BASE=(ARRAY_INDEX+1),
+ ARRAY_COMPRESS_VERTEX=1<<(ARRAY_VERTEX+ARRAY_COMPRESS_BASE), // mandatory
+ ARRAY_COMPRESS_NORMAL=1<<(ARRAY_NORMAL+ARRAY_COMPRESS_BASE),
+ ARRAY_COMPRESS_TANGENT=1<<(ARRAY_TANGENT+ARRAY_COMPRESS_BASE),
+ ARRAY_COMPRESS_COLOR=1<<(ARRAY_COLOR+ARRAY_COMPRESS_BASE),
+ ARRAY_COMPRESS_TEX_UV=1<<(ARRAY_TEX_UV+ARRAY_COMPRESS_BASE),
+ ARRAY_COMPRESS_TEX_UV2=1<<(ARRAY_TEX_UV2+ARRAY_COMPRESS_BASE),
+ ARRAY_COMPRESS_BONES=1<<(ARRAY_BONES+ARRAY_COMPRESS_BASE),
+ ARRAY_COMPRESS_WEIGHTS=1<<(ARRAY_WEIGHTS+ARRAY_COMPRESS_BASE),
+ ARRAY_COMPRESS_INDEX=1<<(ARRAY_INDEX+ARRAY_COMPRESS_BASE),
+
+ ARRAY_FLAG_USE_2D_VERTICES=ARRAY_COMPRESS_INDEX<<1,
+ ARRAY_FLAG_USE_16_BIT_BONES=ARRAY_COMPRESS_INDEX<<2,
+
+ ARRAY_COMPRESS_DEFAULT=ARRAY_COMPRESS_VERTEX|ARRAY_COMPRESS_NORMAL|ARRAY_COMPRESS_TANGENT|ARRAY_COMPRESS_COLOR|ARRAY_COMPRESS_TEX_UV|ARRAY_COMPRESS_TEX_UV2|ARRAY_COMPRESS_WEIGHTS
+
};
enum PrimitiveType {
@@ -122,7 +138,7 @@ protected:
public:
- void add_surface_from_arrays(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array());
+ void add_surface_from_arrays(PrimitiveType p_primitive, const Array& p_arrays, const Array& p_blend_shapes=Array(), uint32_t p_flags=ARRAY_COMPRESS_DEFAULT);
void add_surface(uint32_t p_format,PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const AABB& p_aabb,const Vector<DVector<uint8_t> >& p_blend_shapes=Vector<DVector<uint8_t> >(),const Vector<AABB>& p_bone_aabbs=Vector<AABB>());
Array surface_get_arrays(int p_surface) const;
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index 6f08d69221..8e6175fa5b 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -355,7 +355,30 @@ Ref<Mesh> SurfaceTool::commit(const Ref<Mesh>& p_existing) {
w=DVector<Color>::Write();
a[i]=array;
} break;
- case Mesh::ARRAY_FORMAT_BONES:
+ case Mesh::ARRAY_FORMAT_BONES: {
+
+
+ DVector<int> array;
+ array.resize(varr_len*4);
+ DVector<int>::Write w = array.write();
+
+ int idx=0;
+ for(List< Vertex >::Element *E=vertex_array.front();E;E=E->next(),idx+=4) {
+
+ const Vertex &v=E->get();
+
+ ERR_CONTINUE( v.bones.size()!=4 );
+
+ for(int j=0;j<4;j++) {
+ w[idx+j]=v.bones[j];
+ }
+
+ }
+
+ w=DVector<int>::Write();
+ a[i]=array;
+
+ } break;
case Mesh::ARRAY_FORMAT_WEIGHTS: {
@@ -367,18 +390,11 @@ Ref<Mesh> SurfaceTool::commit(const Ref<Mesh>& p_existing) {
for(List< Vertex >::Element *E=vertex_array.front();E;E=E->next(),idx+=4) {
const Vertex &v=E->get();
+ ERR_CONTINUE( v.weights.size()!=4 );
for(int j=0;j<4;j++) {
- switch(i) {
- case Mesh::ARRAY_WEIGHTS: {
- ERR_CONTINUE( v.weights.size()!=4 );
- w[idx+j]=v.weights[j];
- } break;
- case Mesh::ARRAY_BONES: {
- ERR_CONTINUE( v.bones.size()!=4 );
- w[idx+j]=v.bones[j];
- } break;
- }
+
+ w[idx+j]=v.weights[j];
}
}