Revision: 16080
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16080
Author:   blendix
Date:     2008-08-13 19:37:37 +0200 (Wed, 13 Aug 2008)

Log Message:
-----------
Apricot Branch
==============

Various cleanups and optimizations in the game engine:
* Remove some duplication in the RAS_RenderTools, and sync the blender
  and game player versions. Also avoid some opengl state changes.
* Don't make separate materials for triangles and quads, this distinction
  was moved to the mesh level. Also don't take some other irrelevant tface
  settings into account to avoid making more materials.
* Refactoring of mesh storage, should fix wrong normals on meshes that are
  reused. It also allows for joining together nearby meshes for speed, though
  that's disabled still because it doesn't work together correct yet with 
  ome features.
* Added a distinction for game objects to be either culled or set invisible,
  previously there was only one flag, which couldn't work correct.
* For parenting to bones, where_is_pose was executed multiple times per
  frame, now should be once per armature.
* Fix uninitialized intertia value in the physics system.
* Various warning fixes.
* Removed some conditionals in GLSL and other minor optimizations in the
  code. Also cache opengl uniform locations, and fix an invalid memory read.
* Avoid doing some math for GLSL lamps if it is not required.

Modified Paths:
--------------
    branches/apricot/intern/moto/include/GEN_Map.h
    branches/apricot/intern/moto/include/MT_Matrix4x4.h
    branches/apricot/intern/moto/include/MT_Matrix4x4.inl
    branches/apricot/source/blender/blenkernel/intern/armature.c
    branches/apricot/source/blender/gpu/GPU_extensions.h
    branches/apricot/source/blender/gpu/intern/gpu_codegen.c
    branches/apricot/source/blender/gpu/intern/gpu_codegen.h
    branches/apricot/source/blender/gpu/intern/gpu_extensions.c
    branches/apricot/source/blender/gpu/intern/gpu_material.c
    branches/apricot/source/blender/gpu/intern/gpu_shader_material.glsl
    branches/apricot/source/blender/gpu/intern/gpu_shader_material.glsl.c
    branches/apricot/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
    branches/apricot/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
    branches/apricot/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h
    branches/apricot/source/gameengine/Converter/BL_ArmatureObject.cpp
    branches/apricot/source/gameengine/Converter/BL_ArmatureObject.h
    branches/apricot/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    branches/apricot/source/gameengine/Converter/BL_MeshDeformer.cpp
    branches/apricot/source/gameengine/Converter/BL_ShapeActionActuator.cpp
    branches/apricot/source/gameengine/Converter/BL_ShapeDeformer.cpp
    branches/apricot/source/gameengine/Converter/BL_SkinDeformer.cpp
    branches/apricot/source/gameengine/Converter/BL_SkinDeformer.h
    branches/apricot/source/gameengine/Converter/BL_SkinMeshObject.cpp
    branches/apricot/source/gameengine/Converter/BL_SkinMeshObject.h
    branches/apricot/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
    branches/apricot/source/gameengine/Converter/KX_ConvertActuators.cpp
    branches/apricot/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
    branches/apricot/source/gameengine/GamePlayer/common/GPC_RenderTools.h
    
branches/apricot/source/gameengine/GamePlayer/common/unix/GPU_PolygonMaterial.h
    branches/apricot/source/gameengine/Ketsji/BL_BlenderShader.cpp
    branches/apricot/source/gameengine/Ketsji/BL_BlenderShader.h
    branches/apricot/source/gameengine/Ketsji/BL_Material.h
    branches/apricot/source/gameengine/Ketsji/BL_Shader.cpp
    branches/apricot/source/gameengine/Ketsji/BL_Shader.h
    branches/apricot/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
    branches/apricot/source/gameengine/Ketsji/KX_BlenderMaterial.h
    branches/apricot/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
    branches/apricot/source/gameengine/Ketsji/KX_GameObject.cpp
    branches/apricot/source/gameengine/Ketsji/KX_GameObject.h
    branches/apricot/source/gameengine/Ketsji/KX_MeshProxy.cpp
    branches/apricot/source/gameengine/Ketsji/KX_PolygonMaterial.cpp
    branches/apricot/source/gameengine/Ketsji/KX_PolygonMaterial.h
    
branches/apricot/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp
    branches/apricot/source/gameengine/Ketsji/KX_Scene.cpp
    branches/apricot/source/gameengine/Ketsji/KX_VertexProxy.cpp
    branches/apricot/source/gameengine/Ketsji/KX_VisibilityActuator.cpp
    branches/apricot/source/gameengine/Physics/Bullet/CcdPhysicsController.h
    branches/apricot/source/gameengine/Rasterizer/RAS_BucketManager.cpp
    branches/apricot/source/gameengine/Rasterizer/RAS_BucketManager.h
    branches/apricot/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp
    branches/apricot/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h
    branches/apricot/source/gameengine/Rasterizer/RAS_IRasterizer.h
    branches/apricot/source/gameengine/Rasterizer/RAS_IRenderTools.cpp
    branches/apricot/source/gameengine/Rasterizer/RAS_IRenderTools.h
    branches/apricot/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
    branches/apricot/source/gameengine/Rasterizer/RAS_MaterialBucket.h
    branches/apricot/source/gameengine/Rasterizer/RAS_MeshObject.cpp
    branches/apricot/source/gameengine/Rasterizer/RAS_MeshObject.h
    
branches/apricot/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp
    
branches/apricot/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h
    
branches/apricot/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
    
branches/apricot/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
    
branches/apricot/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.cpp
    
branches/apricot/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h
    branches/apricot/source/gameengine/Rasterizer/RAS_Polygon.cpp
    branches/apricot/source/gameengine/Rasterizer/RAS_Polygon.h
    branches/apricot/source/gameengine/Rasterizer/RAS_TexVert.cpp
    branches/apricot/source/gameengine/Rasterizer/RAS_TexVert.h
    branches/apricot/source/gameengine/Rasterizer/SConscript
    branches/apricot/source/kernel/gen_system/GEN_Map.h

Modified: branches/apricot/intern/moto/include/GEN_Map.h
===================================================================
--- branches/apricot/intern/moto/include/GEN_Map.h      2008-08-13 17:34:09 UTC 
(rev 16079)
+++ branches/apricot/intern/moto/include/GEN_Map.h      2008-08-13 17:37:37 UTC 
(rev 16080)
@@ -50,6 +50,19 @@
             m_buckets[i] = 0;
         }
     }
+
+       GEN_Map(const GEN_Map& map)
+       {
+               m_num_buckets = map.m_num_buckets;
+               m_buckets = new Entry *[m_num_buckets];
+
+               for (int i = 0; i < m_num_buckets; ++i) {
+                       m_buckets[i] = 0;
+
+                       for(Entry *entry = map.m_buckets[i]; entry; 
entry=entry->m_next)
+                               insert(entry->m_key, entry->m_value);
+               }
+       }
     
     int size() { 
         int count=0;

Modified: branches/apricot/intern/moto/include/MT_Matrix4x4.h
===================================================================
--- branches/apricot/intern/moto/include/MT_Matrix4x4.h 2008-08-13 17:34:09 UTC 
(rev 16079)
+++ branches/apricot/intern/moto/include/MT_Matrix4x4.h 2008-08-13 17:37:37 UTC 
(rev 16080)
@@ -212,6 +212,7 @@
        MT_Matrix4x4 transposed() const; 
        void         transpose();
 
+       MT_Matrix4x4 inverse() const;
        void         invert();
   
 protected:

Modified: branches/apricot/intern/moto/include/MT_Matrix4x4.inl
===================================================================
--- branches/apricot/intern/moto/include/MT_Matrix4x4.inl       2008-08-13 
17:34:09 UTC (rev 16079)
+++ branches/apricot/intern/moto/include/MT_Matrix4x4.inl       2008-08-13 
17:37:37 UTC (rev 16080)
@@ -52,15 +52,15 @@
                }
 }
 
-/* We do things slightly different here, because the invert() modifies
- * the buffer itself. This makes it impossible to make this op right
- * away. Like other, still missing facilities, I will repair this
- * later. */
-/* GEN_INLINE T_Matrix4x4 MT_Matrix4x4::inverse() const */
-/*  { */
-/*  } */
+GEN_INLINE MT_Matrix4x4 MT_Matrix4x4::inverse() const
+{
+       MT_Matrix4x4 invmat = *this;
 
+       invmat.invert();
 
+       return invmat;
+}
+
 GEN_INLINE MT_Matrix4x4& MT_Matrix4x4::operator*=(const MT_Matrix4x4& m)
 {
        setValue(m.tdot(0, m_el[0]), m.tdot(1, m_el[0]), m.tdot(2, m_el[0]), 
m.tdot(3, m_el[0]),

Modified: branches/apricot/source/blender/blenkernel/intern/armature.c
===================================================================
--- branches/apricot/source/blender/blenkernel/intern/armature.c        
2008-08-13 17:34:09 UTC (rev 16079)
+++ branches/apricot/source/blender/blenkernel/intern/armature.c        
2008-08-13 17:37:37 UTC (rev 16080)
@@ -2295,8 +2295,9 @@
                                        
                                        /* 4. walk over the tree for regular 
solving */
                                        for(a=0; a<tree->totchannel; a++) {
-                                               if(!(tree->pchan[a]->flag & 
POSE_DONE)) // successive trees can set the flag
+                                               if(!(tree->pchan[a]->flag & 
POSE_DONE)) {// successive trees can set the flag
                                                        where_is_pose_bone(ob, 
tree->pchan[a], ctime);
+                                               }
                                        }
                                        /* 5. execute the IK solver */
                                        execute_posetree(ob, tree);

Modified: branches/apricot/source/blender/gpu/GPU_extensions.h
===================================================================
--- branches/apricot/source/blender/gpu/GPU_extensions.h        2008-08-13 
17:34:09 UTC (rev 16079)
+++ branches/apricot/source/blender/gpu/GPU_extensions.h        2008-08-13 
17:37:37 UTC (rev 16080)
@@ -120,9 +120,10 @@
 void GPU_shader_bind(GPUShader *shader);
 void GPU_shader_unbind();
 
-void GPU_shader_uniform_vector(GPUShader *shader, char *name, int length,
+int GPU_shader_get_uniform(GPUShader *shader, char *name);
+void GPU_shader_uniform_vector(GPUShader *shader, int location, int length,
        int arraysize, float *value);
-void GPU_shader_uniform_texture(GPUShader *shader, char *name, GPUTexture 
*tex);
+void GPU_shader_uniform_texture(GPUShader *shader, int location, GPUTexture 
*tex);
 
 int GPU_shader_get_attribute(GPUShader *shader, char *name);
 

Modified: branches/apricot/source/blender/gpu/intern/gpu_codegen.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_codegen.c    2008-08-13 
17:34:09 UTC (rev 16079)
+++ branches/apricot/source/blender/gpu/intern/gpu_codegen.c    2008-08-13 
17:37:37 UTC (rev 16080)
@@ -144,6 +144,7 @@
        struct ImageUser *iuser;/* image user */
        float *dynamicvec;              /* vector data in case it is dynamic */
        GPUTexture *tex;                /* input texture, only set at runtime */
+       int shaderloc;                  /* id from opengl */
        char shadername[32];    /* name in shader */
 
        float vec[16];                  /* vector data */
@@ -683,7 +684,7 @@
        BLI_dynstr_append(ds, ";\n");
 }
 
-static char *code_generate_fragment(ListBase *nodes, GPUOutput *output)
+static char *code_generate_fragment(ListBase *nodes, GPUOutput *output, const 
char *name)
 {
        DynStr *ds = BLI_dynstr_new();
        char *code;
@@ -693,6 +694,9 @@
        codegen_set_unique_ids(nodes);
        codegen_print_uniforms_functions(ds, nodes);
 
+       //if(G.f & G_DEBUG)
+       //      BLI_dynstr_printf(ds, "/* %s */\n", name);
+
        BLI_dynstr_append(ds, "void main(void)\n");
        BLI_dynstr_append(ds, "{\n");
 
@@ -705,7 +709,7 @@
        code = BLI_dynstr_get_cstring(ds);
        BLI_dynstr_free(ds);
 
-       if(G.f & G_DEBUG) printf("%s\n", code);
+       //if(G.f & G_DEBUG) printf("%s\n", code);
 
        return code;
 }
@@ -766,7 +770,7 @@
        GPUNode *node;
        GPUInput *next, *input;
        ListBase *inputs = &pass->inputs;
-       int extract;
+       int extract, z;
 
        memset(inputs, 0, sizeof(*inputs));
 
@@ -776,7 +780,8 @@
        GPU_shader_bind(shader);
 
        for (node=nodes->first; node; node=node->next) {
-               for (input=node->inputs.first; input; input=next) {
+               z = 0;
+               for (input=node->inputs.first; input; input=next, z++) {
                        next = input->next;
 
                        /* attributes don't need to be bound, they already have
@@ -800,6 +805,9 @@
                        else if(input->dynamicvec)
                                extract = 1;
 
+                       if(extract)
+                               input->shaderloc = 
GPU_shader_get_uniform(shader, input->shadername);
+
                        /* extract nodes */
                        if(extract) {
                                BLI_remlink(&node->inputs, input);
@@ -830,7 +838,7 @@
                if(input->ima || input->tex) {
                        if(input->tex) {
                                GPU_texture_bind(input->tex, input->texid);
-                               GPU_shader_uniform_texture(shader, 
input->shadername, input->tex);
+                               GPU_shader_uniform_texture(shader, 
input->shaderloc, input->tex);
                        }
                }
        }
@@ -848,7 +856,7 @@
        /* pass dynamic inputs to opengl, others were removed */
        for (input=inputs->first; input; input=input->next)
                if(!(input->ima || input->tex))
-                       GPU_shader_uniform_vector(shader, input->shadername, 
input->type, 1,
+                       GPU_shader_uniform_vector(shader, input->shaderloc, 
input->type, 1,
                                input->dynamicvec);
 }
 
@@ -926,6 +934,8 @@
                if(strcmp(name, "set_value")==0 || strcmp(name, "set_rgb")==0) {
                        input = MEM_dupallocN(outnode->inputs.first);
                        input->type = type;
+                       if(input->link)
+                               input->link->users++;
                        BLI_addtail(&node->inputs, input);
                        return;
                }
@@ -1049,9 +1059,8 @@
        GPUInput *input;
 
        for(input=inputs->first; input; input=input->next) {
-               if(input->link) {
+               if(input->link)
                        GPU_node_link_free(input->link);
-               }
                else if(input->tex && !input->dynamictex)
                        GPU_texture_free(input->tex);
        }
@@ -1379,7 +1388,7 @@
        }
 }
 
-GPUPass *GPU_generate_pass(ListBase *nodes, GPUNodeLink *outlink, 
GPUVertexAttribs *attribs, int *builtins)
+GPUPass *GPU_generate_pass(ListBase *nodes, GPUNodeLink *outlink, 
GPUVertexAttribs *attribs, int *builtins, const char *name)
 {
        GPUShader *shader;
        GPUPass *pass;
@@ -1397,7 +1406,7 @@
        gpu_nodes_get_builtin_flag(nodes, builtins);
 
        /* generate code and compile with opengl */
-       fragmentcode = code_generate_fragment(nodes, outlink->output);
+       fragmentcode = code_generate_fragment(nodes, outlink->output, name);
        vertexcode = code_generate_vertex(nodes);
        shader = GPU_shader_create(vertexcode, fragmentcode, FUNCTION_LIB);
        MEM_freeN(fragmentcode);

Modified: branches/apricot/source/blender/gpu/intern/gpu_codegen.h
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_codegen.h    2008-08-13 
17:34:09 UTC (rev 16079)
+++ branches/apricot/source/blender/gpu/intern/gpu_codegen.h    2008-08-13 
17:37:37 UTC (rev 16080)
@@ -67,7 +67,7 @@
 typedef struct GPUPass GPUPass;
 
 GPUPass *GPU_generate_pass(ListBase *nodes, struct GPUNodeLink *outlink,
-       struct GPUVertexAttribs *attribs, int *builtin);
+       struct GPUVertexAttribs *attribs, int *builtin, const char *name);
 
 struct GPUShader *GPU_pass_shader(GPUPass *pass);
 

Modified: branches/apricot/source/blender/gpu/intern/gpu_extensions.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_extensions.c 2008-08-13 
17:34:09 UTC (rev 16079)
+++ branches/apricot/source/blender/gpu/intern/gpu_extensions.c 2008-08-13 
17:37:37 UTC (rev 16080)
@@ -955,7 +955,6 @@
        return shader;
 }
 
-
 void GPU_shader_bind(GPUShader *shader)
 {
        GPU_print_error("Pre Shader Bind");
@@ -983,22 +982,24 @@
        MEM_freeN(shader);
 }
 
+int GPU_shader_get_uniform(GPUShader *shader, char *name)
+{
+       return glGetUniformLocationARB(shader->object, name);
+}
 
-void GPU_shader_uniform_vector(GPUShader *shader, char *name, int length, int 
arraysize, float *value)
+void GPU_shader_uniform_vector(GPUShader *shader, int location, int length, 
int arraysize, float *value)
 {
-       GLint location = glGetUniformLocationARB(shader->object, name);
-
        if(location == -1)
                return;
 
        GPU_print_error("Pre Uniform Vector");
 
-       /*if (length == 1) printf("%s %f\n", name, value[0]);
-       else if (length == 2) printf("%s %f %f\n", name, value[0], value[1]);
-       else if (length == 3) { printf("%s ", name); printvecf("", value); }
-       else if (length == 4) { printf("%s ", name); printquat("", value); }
-       else if (length == 9) { printf("%s ", name); printmatrix3("", 
(float(*)[3])value); }
-       else if (length == 16) { printf("%s ", name); printmatrix4("", 
(float(*)[4])value); }*/
+       /*if (length == 1) fprintf(stderr, "%d %s %f\n", location, name, 
value[0]);
+       else if (length == 2) fprintf(stderr, "%d %s %f %f\n", location, name, 
value[0], value[1]);
+       else if (length == 3) { fprintf(stderr, "%d %s ", location, name); 
printvecf("", value); }
+       else if (length == 4) { fprintf(stderr, "%d %s ", location, name); 
printquat("", value); }
+       else if (length == 9) { fprintf(stderr, "%d %s ", location, name); 
printmatrix3("", (float(*)[3])value); }
+       else if (length == 16) { fprintf(stderr, "%d %s ", location, name); 
printmatrix4("", (float(*)[4])value); }*/
 
        if (length == 1) glUniform1fvARB(location, arraysize, value);

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to