Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp20
-rw-r--r--source/gameengine/BlenderRoutines/CMakeLists.txt1
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderGL.cpp75
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderGL.h3
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp251
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h67
-rw-r--r--source/gameengine/BlenderRoutines/Makefile5
-rw-r--r--source/gameengine/BlenderRoutines/SConscript5
-rw-r--r--source/gameengine/Converter/BL_ArmatureObject.cpp74
-rw-r--r--source/gameengine/Converter/BL_ArmatureObject.h8
-rw-r--r--source/gameengine/Converter/BL_BlenderDataConversion.cpp140
-rw-r--r--source/gameengine/Converter/BL_DeformableGameObject.cpp8
-rw-r--r--source/gameengine/Converter/BL_MeshDeformer.cpp89
-rw-r--r--source/gameengine/Converter/BL_MeshDeformer.h3
-rw-r--r--source/gameengine/Converter/BL_ShapeActionActuator.cpp1
-rw-r--r--source/gameengine/Converter/BL_ShapeDeformer.cpp3
-rw-r--r--source/gameengine/Converter/BL_ShapeDeformer.h11
-rw-r--r--source/gameengine/Converter/BL_SkinDeformer.cpp47
-rw-r--r--source/gameengine/Converter/BL_SkinDeformer.h16
-rw-r--r--source/gameengine/Converter/BL_SkinMeshObject.cpp74
-rw-r--r--source/gameengine/Converter/BL_SkinMeshObject.h45
-rw-r--r--source/gameengine/Converter/CMakeLists.txt1
-rw-r--r--source/gameengine/Converter/KX_BlenderSceneConverter.cpp25
-rw-r--r--source/gameengine/Converter/KX_BlenderSceneConverter.h2
-rw-r--r--source/gameengine/Converter/KX_ConvertActuators.cpp2
-rw-r--r--source/gameengine/Converter/Makefile1
-rw-r--r--source/gameengine/Converter/SConscript2
-rw-r--r--source/gameengine/GamePlayer/common/CMakeLists.txt2
-rw-r--r--source/gameengine/GamePlayer/common/GPC_RenderTools.cpp537
-rw-r--r--source/gameengine/GamePlayer/common/GPC_RenderTools.h163
-rw-r--r--source/gameengine/GamePlayer/common/Makefile5
-rw-r--r--source/gameengine/GamePlayer/common/SConscript2
-rw-r--r--source/gameengine/GamePlayer/common/unix/GPU_PolygonMaterial.h4
-rw-r--r--source/gameengine/GamePlayer/ghost/CMakeLists.txt1
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Application.cpp34
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Application.h6
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_ghost.cpp16
-rw-r--r--source/gameengine/GamePlayer/ghost/Makefile5
-rw-r--r--source/gameengine/GamePlayer/ghost/SConscript4
-rw-r--r--source/gameengine/Ketsji/BL_BlenderShader.cpp124
-rw-r--r--source/gameengine/Ketsji/BL_BlenderShader.h10
-rw-r--r--source/gameengine/Ketsji/BL_Material.h6
-rw-r--r--source/gameengine/Ketsji/BL_Shader.cpp12
-rw-r--r--source/gameengine/Ketsji/BL_Shader.h2
-rw-r--r--source/gameengine/Ketsji/CMakeLists.txt1
-rw-r--r--source/gameengine/Ketsji/KX_BlenderMaterial.cpp126
-rw-r--r--source/gameengine/Ketsji/KX_BlenderMaterial.h3
-rw-r--r--source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp136
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.cpp98
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.h77
-rw-r--r--source/gameengine/Ketsji/KX_ISceneConverter.h4
-rw-r--r--source/gameengine/Ketsji/KX_KetsjiEngine.cpp32
-rw-r--r--source/gameengine/Ketsji/KX_KetsjiEngine.h7
-rw-r--r--source/gameengine/Ketsji/KX_Light.cpp57
-rw-r--r--source/gameengine/Ketsji/KX_Light.h11
-rw-r--r--source/gameengine/Ketsji/KX_MeshProxy.cpp13
-rw-r--r--source/gameengine/Ketsji/KX_PolyProxy.cpp18
-rw-r--r--source/gameengine/Ketsji/KX_PolygonMaterial.cpp50
-rw-r--r--source/gameengine/Ketsji/KX_PolygonMaterial.h2
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp89
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.h2
-rw-r--r--source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_Scene.cpp31
-rw-r--r--source/gameengine/Ketsji/KX_Scene.h10
-rw-r--r--source/gameengine/Ketsji/KX_VertexProxy.cpp14
-rw-r--r--source/gameengine/Ketsji/KX_VisibilityActuator.cpp2
-rw-r--r--source/gameengine/Ketsji/Makefile6
-rw-r--r--source/gameengine/Ketsji/SConscript5
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.cpp34
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.h3
-rw-r--r--source/gameengine/PyDoc/GameLogic.py9
-rw-r--r--source/gameengine/PyDoc/Rasterizer.py17
-rw-r--r--source/gameengine/Rasterizer/Makefile4
-rw-r--r--source/gameengine/Rasterizer/RAS_BucketManager.cpp257
-rw-r--r--source/gameengine/Rasterizer/RAS_BucketManager.h21
-rw-r--r--source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp25
-rw-r--r--source/gameengine/Rasterizer/RAS_IPolygonMaterial.h9
-rw-r--r--source/gameengine/Rasterizer/RAS_IRasterizer.h44
-rw-r--r--source/gameengine/Rasterizer/RAS_IRenderTools.cpp24
-rw-r--r--source/gameengine/Rasterizer/RAS_IRenderTools.h39
-rw-r--r--source/gameengine/Rasterizer/RAS_MaterialBucket.cpp554
-rw-r--r--source/gameengine/Rasterizer/RAS_MaterialBucket.h213
-rw-r--r--source/gameengine/Rasterizer/RAS_MeshObject.cpp723
-rw-r--r--source/gameengine/Rasterizer/RAS_MeshObject.h240
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt1
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/Makefile5
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp84
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h24
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp748
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h46
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.cpp216
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h18
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/SConscript5
-rw-r--r--source/gameengine/Rasterizer/RAS_Polygon.cpp83
-rw-r--r--source/gameengine/Rasterizer/RAS_Polygon.h56
-rw-r--r--source/gameengine/Rasterizer/RAS_TexVert.cpp30
-rw-r--r--source/gameengine/Rasterizer/RAS_TexVert.h28
-rw-r--r--source/gameengine/Rasterizer/SConscript5
98 files changed, 2731 insertions, 3542 deletions
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
index 16f8ae0095a..1f66335c749 100644
--- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
+++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
@@ -79,6 +79,8 @@
#include "DNA_scene_types.h"
/***/
+#include "GPU_extensions.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -138,6 +140,9 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
if(GLEW_ARB_multitexture && GLEW_VERSION_1_1)
usemat = (SYS_GetCommandLineInt(syshandle, "blender_material", 0) != 0);
+ if(GPU_extensions_minimum_support())
+ useglslmat = (SYS_GetCommandLineInt(syshandle, "blender_glsl_material", 0) != 0);
+
// create the canvas, rasterizer and rendertools
RAS_ICanvas* canvas = new KX_BlenderCanvas(area);
canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
@@ -304,13 +309,14 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
mousedevice,
networkdevice,
audiodevice,
- startscenename);
+ startscenename,
+ blscene);
// some python things
PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest);
ketsjiengine->SetPythonDictionary(dictionaryobject);
initRasterizer(rasterizer, canvas);
- PyObject *gameLogic = initGameLogic(startscene);
+ PyObject *gameLogic = initGameLogic(ketsjiengine, startscene);
PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module.
PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
initGameKeys();
@@ -526,8 +532,6 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
// create the ketsjiengine
KX_KetsjiEngine* ketsjiengine = new KX_KetsjiEngine(kxsystem);
- int i;
-
Scene *blscene = NULL;
if (!bfd)
{
@@ -543,7 +547,7 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
} else {
blscene = bfd->curscene;
}
- int cframe,startFrame;
+ int cframe = 1, startFrame;
if (blscene)
{
cframe=blscene->r.cfra;
@@ -574,12 +578,14 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
mousedevice,
networkdevice,
audiodevice,
- startscenename);
+ startscenename,
+ blscene);
+
// some python things
PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest);
ketsjiengine->SetPythonDictionary(dictionaryobject);
initRasterizer(rasterizer, canvas);
- PyObject *gameLogic = initGameLogic(startscene);
+ PyObject *gameLogic = initGameLogic(ketsjiengine, startscene);
PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module
initGameKeys();
initPythonConstraintBinding();
diff --git a/source/gameengine/BlenderRoutines/CMakeLists.txt b/source/gameengine/BlenderRoutines/CMakeLists.txt
index 1d72fb9cde1..340a1ae310b 100644
--- a/source/gameengine/BlenderRoutines/CMakeLists.txt
+++ b/source/gameengine/BlenderRoutines/CMakeLists.txt
@@ -31,6 +31,7 @@ SET(INC
../../../intern/SoundSystem
../../../source/blender/misc
../../../source/blender/blenloader
+ ../../../source/blender/gpu
../../../extern/bullet2/src
../../../extern/solid
../../../extern/glew/include
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
index da52be56d1b..669e7bd1b3f 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
+++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
@@ -26,7 +26,6 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#include "GL/glew.h"
#include "KX_BlenderGL.h"
#ifdef HAVE_CONFIG_H
@@ -93,80 +92,6 @@ void BL_SwapBuffers()
myswapbuffers();
}
-void BL_RenderText(int mode,const char* textstr,int textlen,struct MTFace* tface,
- unsigned int *col,float v1[3],float v2[3],float v3[3],float v4[3])
-{
- Image* ima;
-
- if(mode & TF_BMFONT) {
- //char string[MAX_PROPSTRING];
- int characters, index, character;
- float centerx, centery, sizex, sizey, transx, transy, movex, movey, advance;
-
-// bProperty *prop;
-
- // string = "Frank van Beek";
-
- characters = textlen;
-
- ima = (struct Image*) tface->tpage;
- if (ima == NULL) {
- characters = 0;
- }
-
- /* When OBCOL flag is on the color is set in IndexPrimitives_3DText */
- if (tface->mode & TF_OBCOL) { /* Color has been set */
- col= NULL;
- } else {
- if(!col) glColor3f(1.0f, 1.0f, 1.0f);
- }
-
- glPushMatrix();
- for (index = 0; index < characters; index++) {
- // lets calculate offset stuff
- character = textstr[index];
-
- // space starts at offset 1
- // character = character - ' ' + 1;
-
- matrixGlyph((ImBuf *)ima->ibufs.first, character, & centerx, &centery, &sizex, &sizey, &transx, &transy, &movex, &movey, &advance);
-
- glBegin(GL_POLYGON);
- // printf(" %c %f %f %f %f\n", character, tface->uv[0][0], tface->uv[0][1], );
- // glTexCoord2f((tface->uv[0][0] - centerx) * sizex + transx, (tface->uv[0][1] - centery) * sizey + transy);
- glTexCoord2f((tface->uv[0][0] - centerx) * sizex + transx, (tface->uv[0][1] - centery) * sizey + transy);
-
- if(col) spack(col[0]);
- // glVertex3fv(v1);
- glVertex3f(sizex * v1[0] + movex, sizey * v1[1] + movey, v1[2]);
-
- glTexCoord2f((tface->uv[1][0] - centerx) * sizex + transx, (tface->uv[1][1] - centery) * sizey + transy);
- if(col) spack(col[1]);
- // glVertex3fv(v2);
- glVertex3f(sizex * v2[0] + movex, sizey * v2[1] + movey, v2[2]);
-
- glTexCoord2f((tface->uv[2][0] - centerx) * sizex + transx, (tface->uv[2][1] - centery) * sizey + transy);
- if(col) spack(col[2]);
- // glVertex3fv(v3);
- glVertex3f(sizex * v3[0] + movex, sizey * v3[1] + movey, v3[2]);
-
- if(v4) {
- // glTexCoord2f((tface->uv[3][0] - centerx) * sizex + transx, 1.0 - (1.0 - tface->uv[3][1]) * sizey - transy);
- glTexCoord2f((tface->uv[3][0] - centerx) * sizex + transx, (tface->uv[3][1] - centery) * sizey + transy);
- if(col) spack(col[3]);
- // glVertex3fv(v4);
- glVertex3f(sizex * v4[0] + movex, sizey * v4[1] + movey, v4[2]);
- }
- glEnd();
-
- glTranslatef(advance, 0.0, 0.0);
- }
- glPopMatrix();
-
- }
-}
-
-
void DisableForText()
{
if(glIsEnabled(GL_BLEND)) glDisable(GL_BLEND);
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.h b/source/gameengine/BlenderRoutines/KX_BlenderGL.h
index c8e0d47afb6..b891a7343c2 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderGL.h
+++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.h
@@ -46,9 +46,6 @@ void BL_HideMouse();
void BL_NormalMouse();
void BL_WaitMouse();
-void BL_RenderText(int mode,const char* textstr,int textlen,struct MTFace* tface,
- unsigned int *col,float v1[3],float v2[3],float v3[3],float v4[3]);
-
void BL_print_gamedebug_line(char* text, int xco, int yco, int width, int height);
void BL_print_gamedebug_line_padded(char* text, int xco, int yco, int width, int height);
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
index dafc2599850..1797d6c1a0f 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
+++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
@@ -26,8 +26,6 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#include "KX_BlenderRenderTools.h"
-
#include "GL/glew.h"
#include "RAS_IRenderTools.h"
@@ -36,23 +34,22 @@
#include "RAS_ICanvas.h"
#include "RAS_GLExtensionManager.h"
-// next two includes/dependencies come from the shadow feature
-// it needs the gameobject and the sumo physics scene for a raycast
#include "KX_GameObject.h"
-
#include "KX_PolygonMaterial.h"
#include "KX_BlenderMaterial.h"
+#include "KX_RayCast.h"
+#include "KX_IPhysicsController.h"
-#include "Value.h"
+#include "PHY_IPhysicsEnvironment.h"
-#include "KX_BlenderGL.h" // for text printing
#include "STR_String.h"
-#include "RAS_BucketManager.h" // for polymaterial (needed for textprinting)
-#include "KX_RayCast.h"
-#include "KX_IPhysicsController.h"
-#include "PHY_IPhysicsEnvironment.h"
-#include "KX_Scene.h"
+#include "GPU_draw.h"
+
+#include "KX_BlenderGL.h" // for text printing
+#include "KX_BlenderRenderTools.h"
+
+unsigned int KX_BlenderRenderTools::m_numgllights;
KX_BlenderRenderTools::KX_BlenderRenderTools()
{
@@ -61,73 +58,90 @@ KX_BlenderRenderTools::KX_BlenderRenderTools()
m_numgllights = 8;
}
-/**
-ProcessLighting performs lighting on objects. the layer is a bitfield that contains layer information.
-There are 20 'official' layers in blender.
-A light is applied on an object only when they are in the same layer.
-OpenGL has a maximum of 8 lights (simultaneous), so 20 * 8 lights are possible in a scene.
-*/
+KX_BlenderRenderTools::~KX_BlenderRenderTools()
+{
+}
-int KX_BlenderRenderTools::ProcessLighting(int layer)
+void KX_BlenderRenderTools::BeginFrame(RAS_IRasterizer* rasty)
{
-
- int result = false;
+ m_clientobject = NULL;
+ m_lastlightlayer = -1;
+ m_lastlighting = false;
+ DisableOpenGLLights();
+}
- if (layer < 0)
- {
- DisableOpenGLLights();
- result = false;
- } else
+void KX_BlenderRenderTools::EndFrame(RAS_IRasterizer* rasty)
+{
+}
+
+/* ProcessLighting performs lighting on objects. the layer is a bitfield that
+ * contains layer information. There are 20 'official' layers in blender. A
+ * light is applied on an object only when they are in the same layer. OpenGL
+ * has a maximum of 8 lights (simultaneous), so 20 * 8 lights are possible in
+ * a scene. */
+
+void KX_BlenderRenderTools::ProcessLighting(int layer, const MT_Transform& viewmat)
+{
+ if(m_lastlightlayer == layer)
+ return;
+
+ m_lastlightlayer = layer;
+
+ bool enable = false;
+
+ if (layer >= 0)
{
if (m_clientobject)
{
if (layer == RAS_LIGHT_OBJECT_LAYER)
- {
layer = static_cast<KX_GameObject*>(m_clientobject)->GetLayer();
- }
- if (applyLights(layer))
- {
- EnableOpenGLLights();
- result = true;
- } else
- {
- DisableOpenGLLights();
- result = false;
- }
+
+ enable = applyLights(layer, viewmat);
}
}
- return result;
-
-
+
+ if(enable)
+ EnableOpenGLLights();
+ else
+ DisableOpenGLLights();
}
+void KX_BlenderRenderTools::EnableOpenGLLights()
+{
+ if(m_lastlighting == true)
+ return;
-void KX_BlenderRenderTools::BeginFrame(RAS_IRasterizer* rasty)
+ glEnable(GL_LIGHTING);
+ glEnable(GL_COLOR_MATERIAL);
+
+ glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, true);
+ if (GLEW_EXT_separate_specular_color || GLEW_VERSION_1_2)
+ glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
+
+ m_lastlighting = true;
+}
+
+void KX_BlenderRenderTools::DisableOpenGLLights()
{
- m_clientobject = NULL;
- m_lastblenderobject = NULL;
- m_lastblenderlights = false;
- m_lastlayer = -1;
- m_lastlighting = false;
- m_modified = true;
- DisableOpenGLLights();
+ if(m_lastlighting == false)
+ return;
+ glDisable(GL_LIGHTING);
+ glDisable(GL_COLOR_MATERIAL);
+ m_lastlighting = false;
}
-void KX_BlenderRenderTools::SetClientObject(void* obj)
+
+void KX_BlenderRenderTools::SetClientObject(RAS_IRasterizer *rasty, void* obj)
{
if (m_clientobject != obj)
{
- if (obj == NULL || !((KX_GameObject*)obj)->IsNegativeScaling())
- {
- glFrontFace(GL_CCW);
- } else
- {
- glFrontFace(GL_CW);
- }
+ bool ccw = (obj == NULL || !((KX_GameObject*)obj)->IsNegativeScaling());
+ rasty->SetFrontFace(ccw);
+
m_clientobject = obj;
- m_modified = true;
}
}
@@ -182,7 +196,7 @@ void KX_BlenderRenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmat
MT_Vector3 dir = (campos - objpos).safe_normalized();
MT_Vector3 up(0,0,1.0);
- KX_GameObject* gameobj = (KX_GameObject*) this->m_clientobject;
+ KX_GameObject* gameobj = (KX_GameObject*)m_clientobject;
// get scaling of halo object
MT_Vector3 size = gameobj->GetSGNode()->GetLocalScale();
@@ -218,7 +232,7 @@ void KX_BlenderRenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmat
{
// shadow must be cast to the ground, physics system needed here!
MT_Point3 frompoint(oglmatrix[12],oglmatrix[13],oglmatrix[14]);
- KX_GameObject *gameobj = (KX_GameObject*) this->m_clientobject;
+ KX_GameObject *gameobj = (KX_GameObject*)m_clientobject;
MT_Vector3 direction = MT_Vector3(0,0,-1);
direction.normalize();
@@ -252,13 +266,29 @@ void KX_BlenderRenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmat
}
-/**
-Render Text renders text into a (series of) polygon, using a texture font,
-Each character consists of one polygon (one quad or two triangles)
-*/
-void KX_BlenderRenderTools::RenderText(int mode,RAS_IPolyMaterial* polymat,float v1[3],float v2[3],float v3[3],float v4[3])
+void KX_BlenderRenderTools::RenderText2D(RAS_TEXT_RENDER_MODE mode,
+ const char* text,
+ int xco,
+ int yco,
+ int width,
+ int height)
+{
+ STR_String tmpstr(text);
+
+ if(mode == RAS_IRenderTools::RAS_TEXT_PADDED)
+ BL_print_gamedebug_line_padded(tmpstr.Ptr(), xco, yco, width, height);
+ else
+ BL_print_gamedebug_line(tmpstr.Ptr(), xco, yco, width, height);
+}
+
+/* Render Text renders text into a (series of) polygon, using a texture font,
+ * Each character consists of one polygon (one quad or two triangles) */
+
+void KX_BlenderRenderTools::RenderText(
+ int mode,
+ RAS_IPolyMaterial* polymat,
+ float v1[3], float v2[3], float v3[3], float v4[3], int glattrib)
{
-
STR_String mytext = ((CValue*)m_clientobject)->GetPropertyText("Text");
const unsigned int flag = polymat->GetFlag();
@@ -275,67 +305,9 @@ void KX_BlenderRenderTools::RenderText(int mode,RAS_IPolyMaterial* polymat,float
col = blenderpoly->GetMCol();
}
- BL_RenderText( mode,mytext,mytext.Length(),tface,col,v1,v2,v3,v4);
-
-}
-
-
-
-KX_BlenderRenderTools::~KX_BlenderRenderTools()
-{
-};
-
-
-void KX_BlenderRenderTools::EndFrame(RAS_IRasterizer* rasty)
-{
+ GPU_render_text(tface, mode, mytext, mytext.Length(), col, v1, v2, v3, v4, glattrib);
}
-
-
-void KX_BlenderRenderTools::DisableOpenGLLights()
-{
- glDisable(GL_LIGHTING);
- glDisable(GL_COLOR_MATERIAL);
-}
-
-
-void KX_BlenderRenderTools::EnableOpenGLLights()
-{
- glEnable(GL_LIGHTING);
-
- glEnable(GL_COLOR_MATERIAL);
- glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, true);
- if (GLEW_EXT_separate_specular_color || GLEW_VERSION_1_2)
- glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
-
-}
-
-
-/**
- * Rendering text using 2D bitmap functionality.
- */
-void KX_BlenderRenderTools::RenderText2D(RAS_TEXT_RENDER_MODE mode,
- const char* text,
- int xco,
- int yco,
- int width,
- int height)
-{
- switch (mode) {
- case RAS_IRenderTools::RAS_TEXT_PADDED: {
- STR_String tmpstr(text);
- BL_print_gamedebug_line_padded(tmpstr.Ptr(),xco,yco,width,height);
- break;
- }
- default: {
- STR_String tmpstr(text);
- BL_print_gamedebug_line(tmpstr.Ptr(),xco,yco,width,height);
- }
- }
-}
-
-
void KX_BlenderRenderTools::PushMatrix()
{
@@ -348,14 +320,13 @@ void KX_BlenderRenderTools::PopMatrix()
}
-
-int KX_BlenderRenderTools::applyLights(int objectlayer)
+int KX_BlenderRenderTools::applyLights(int objectlayer, const MT_Transform& viewmat)
{
-// taken from blender source, incompatibility between Blender Object / GameObject
-
+ // taken from blender source, incompatibility between Blender Object / GameObject
+ float glviewmat[16];
unsigned int count;
float vec[4];
-
+
vec[3]= 1.0;
for(count=0; count<m_numgllights; count++)
@@ -363,9 +334,11 @@ int KX_BlenderRenderTools::applyLights(int objectlayer)
//std::vector<struct RAS_LightObject*> m_lights;
std::vector<struct RAS_LightObject*>::iterator lit = m_lights.begin();
+
+ viewmat.getValue(glviewmat);
glPushMatrix();
- glLoadMatrixf(m_viewmat);
+ glLoadMatrixf(glviewmat);
for (lit = m_lights.begin(), count = 0; !(lit==m_lights.end()) && count < m_numgllights; ++lit)
{
RAS_LightObject* lightdata = (*lit);
@@ -433,7 +406,6 @@ int KX_BlenderRenderTools::applyLights(int objectlayer)
glEnable((GLenum)(GL_LIGHT0+count));
count++;
-
}
}
glPopMatrix();
@@ -442,22 +414,6 @@ int KX_BlenderRenderTools::applyLights(int objectlayer)
}
-
-
-RAS_IPolyMaterial* KX_BlenderRenderTools::CreateBlenderPolyMaterial(
- const STR_String &texname,
- bool ba,const STR_String& matname,int tile,int tilexrep,int tileyrep,int mode,bool transparant,bool zsort, int lightlayer
- ,bool bIsTriangle,void* clientobject,void* tface)
-{
- assert(!"Deprecated");
-/* return new KX_BlenderPolyMaterial(
-
- texname,
- ba,matname,tile,tilexrep,tileyrep,mode,transparant,zsort, lightlayer
- ,bIsTriangle,clientobject,(struct MTFace*)tface);*/
- return NULL;
-}
-
void KX_BlenderRenderTools::MotionBlur(RAS_IRasterizer* rasterizer)
{
int state = rasterizer->GetMotionBlurState();
@@ -491,4 +447,3 @@ void KX_BlenderRenderTools::Render2DFilters(RAS_ICanvas* canvas)
m_filtermanager.RenderFilters(canvas);
}
-unsigned int KX_BlenderRenderTools::m_numgllights;
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h
index 8027136aa52..a7618462c9b 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h
+++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h
@@ -26,6 +26,7 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
+
#ifndef __KX_BLENDERRENDERTOOLS
#define __KX_BLENDERRENDERTOOLS
@@ -39,65 +40,50 @@
struct KX_ClientObjectInfo;
class KX_RayCast;
-/**
-BlenderRenderTools are a set of tools to apply 2D/3D graphics effects, which are not
-part of the (polygon) Rasterizer.
-Effects like 2D text, 3D (polygon) text, lighting.
-*/
+/* BlenderRenderTools are a set of tools to apply 2D/3D graphics effects, which
+ * are not part of the (polygon) Rasterizer. Effects like 2D text, 3D (polygon)
+ * text, lighting.
+ *
+ * Most of this code is duplicated in GPC_RenderTools, so this should be
+ * moved to some common location to avoid duplication. */
class KX_BlenderRenderTools : public RAS_IRenderTools
{
- bool m_lastblenderlights;
- void* m_lastblenderobject;
- int m_lastlayer;
+ int m_lastlightlayer;
bool m_lastlighting;
static unsigned int m_numgllights;
-
-
+
public:
-
KX_BlenderRenderTools();
virtual ~KX_BlenderRenderTools();
- virtual void EndFrame(class RAS_IRasterizer* rasty);
- virtual void BeginFrame(class RAS_IRasterizer* rasty);
- void DisableOpenGLLights();
+ void EndFrame(RAS_IRasterizer* rasty);
+ void BeginFrame(RAS_IRasterizer* rasty);
+
void EnableOpenGLLights();
- int ProcessLighting(int layer);
+ void DisableOpenGLLights();
+ void ProcessLighting(int layer, const MT_Transform& viewmat);
- virtual void RenderText2D(RAS_TEXT_RENDER_MODE mode,
+ void RenderText2D(RAS_TEXT_RENDER_MODE mode,
const char* text,
int xco,
int yco,
int width,
int height);
- virtual void RenderText(int mode,
+ void RenderText(int mode,
class RAS_IPolyMaterial* polymat,
float v1[3],
float v2[3],
float v3[3],
- float v4[3]);
- void applyTransform(class RAS_IRasterizer* rasty,
- double* oglmatrix,
- int objectdrawmode );
- int applyLights(int objectlayer);
- virtual void PushMatrix();
- virtual void PopMatrix();
-
- virtual class RAS_IPolyMaterial* CreateBlenderPolyMaterial(const STR_String &texname,
- bool ba,
- const STR_String& matname,
- int tile,
- int tilexrep,
- int tileyrep,
- int mode,
- bool transparant,
- bool zsort,
- int lightlayer,
- bool bIsTriangle,
- void* clientobject,
- void* tface);
-
+ float v4[3],
+ int glattrib);
+
+ void applyTransform(RAS_IRasterizer* rasty, double* oglmatrix, int objectdrawmode);
+ int applyLights(int objectlayer, const MT_Transform& viewmat);
+
+ void PushMatrix();
+ void PopMatrix();
+
bool RayHit(KX_ClientObjectInfo* client, class KX_RayCast* result, void * const data);
bool NeedRayCast(KX_ClientObjectInfo*) { return true; }
@@ -107,8 +93,7 @@ public:
virtual void Render2DFilters(RAS_ICanvas* canvas);
- virtual void SetClientObject(void* obj);
-
+ virtual void SetClientObject(RAS_IRasterizer *rasty, void* obj);
};
#endif //__KX_BLENDERRENDERTOOLS
diff --git a/source/gameengine/BlenderRoutines/Makefile b/source/gameengine/BlenderRoutines/Makefile
index a7394158a20..4b9a2a3af17 100644
--- a/source/gameengine/BlenderRoutines/Makefile
+++ b/source/gameengine/BlenderRoutines/Makefile
@@ -54,6 +54,7 @@ CPPFLAGS += -I../../blender/blenkernel
CPPFLAGS += -I../../blender/render/extern/include
CPPFLAGS += -I../../blender/blenloader
CPPFLAGS += -I../../blender/blenkernel
+CPPFLAGS += -I../../blender/gpu
CPPFLAGS += -I../Converter
CPPFLAGS += -I../Expressions
CPPFLAGS += -I../GameLogic
@@ -72,9 +73,5 @@ ifeq ($(OS),windows)
CPPFLAGS += -I../../blender
endif
-ifeq ($(WITH_BF_GLEXT),true)
- CPPFLAGS += -DWITH_GLEXT
-endif
-
CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION)
diff --git a/source/gameengine/BlenderRoutines/SConscript b/source/gameengine/BlenderRoutines/SConscript
index 327f4798e04..78adbc83d9b 100644
--- a/source/gameengine/BlenderRoutines/SConscript
+++ b/source/gameengine/BlenderRoutines/SConscript
@@ -15,7 +15,7 @@ incs += ' #source/gameengine/SceneGraph #source/gameengine/Physics/common'
incs += ' #source/gameengine/Physics/Bullet #source/gameengine/Physics/Sumo'
incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork'
incs += ' #intern/SoundSystem #source/blender/misc #source/blender/blenloader'
-incs += ' #extern/glew/include'
+incs += ' #extern/glew/include #source/blender/gpu'
incs += ' ' + env['BF_PYTHON_INC']
incs += ' ' + env['BF_SOLID_INC']
@@ -26,7 +26,4 @@ cxxflags = []
if env['OURPLATFORM']=='win32-vc':
cxxflags.append ('/GR')
-if env['WITH_BF_GLEXT'] == 1:
- env['CPPFLAGS'].append('-DWITH_GLEXT')
-
env.BlenderLib ( 'bf_bloutines', sources, Split(incs), [], libtype=['game', 'game2', 'player'], priority=[0, 0, 55] , compileflags=cxxflags)
diff --git a/source/gameengine/Converter/BL_ArmatureObject.cpp b/source/gameengine/Converter/BL_ArmatureObject.cpp
index cdfce321713..bf774bf7568 100644
--- a/source/gameengine/Converter/BL_ArmatureObject.cpp
+++ b/source/gameengine/Converter/BL_ArmatureObject.cpp
@@ -53,16 +53,20 @@ BL_ArmatureObject::BL_ArmatureObject(
: KX_GameObject(sgReplicationInfo,callbacks),
m_objArma(armature),
- m_mrdPose(NULL),
m_framePose(NULL),
- m_lastframe(0.),
+ m_lastframe(0.0),
m_activeAct(NULL),
- m_activePriority(999)
+ m_activePriority(999),
+ m_lastapplyframe(0.0)
{
m_armature = get_armature(m_objArma);
- m_pose = m_objArma->pose;
-}
+ /* we make a copy of blender object's pose, and then always swap it with
+ * the original pose before calling into blender functions, to deal with
+ * replica's or other objects using the same blender object */
+ m_pose = NULL;
+ copy_pose(&m_pose, m_objArma->pose, 1 /* copy_constraint_channels_hack */);
+}
CValue* BL_ArmatureObject::GetReplica()
{
@@ -79,34 +83,39 @@ void BL_ArmatureObject::ProcessReplica(BL_ArmatureObject *replica)
{
KX_GameObject::ProcessReplica(replica);
+ replica->m_pose = NULL;
+ copy_pose(&replica->m_pose, m_pose, 1 /* copy_constraint_channels_hack */);
}
BL_ArmatureObject::~BL_ArmatureObject()
{
- if (m_mrdPose)
- free_pose(m_mrdPose);
+ if (m_pose)
+ free_pose(m_pose);
}
-/* note, you can only call this for exisiting Armature objects, and not mix it with other Armatures */
-/* there is only 1 unique Pose per Armature */
-void BL_ArmatureObject::ApplyPose()
+bool BL_ArmatureObject::VerifyPose()
{
- if (m_pose) {
- // copy to armature object
- if (m_objArma->pose != m_pose)/* This should never happen but it does - Campbell */
- extract_pose_from_pose(m_objArma->pose, m_pose);
-
- // is this needed anymore?
- //if (!m_mrdPose)
- // copy_pose (&m_mrdPose, m_pose, 0);
- //else
- // extract_pose_from_pose(m_mrdPose, m_pose);
+ if(m_lastapplyframe != m_lastframe) {
+ extract_pose_from_pose(m_objArma->pose, m_pose);
+ where_is_pose(m_objArma);
+ m_lastapplyframe = m_lastframe;
+ extract_pose_from_pose(m_pose, m_objArma->pose);
+ return false;
}
+ else
+ return true;
+}
+
+void BL_ArmatureObject::ApplyPose()
+{
+ if(VerifyPose())
+ extract_pose_from_pose(m_objArma->pose, m_pose);
}
void BL_ArmatureObject::SetPose(bPose *pose)
{
- m_pose = pose;
+ extract_pose_from_pose(m_pose, pose);
+ m_lastapplyframe = -1.0;
}
bool BL_ArmatureObject::SetActiveAction(BL_ActionActuator *act, short priority, double curtime)
@@ -162,6 +171,7 @@ void BL_ArmatureObject::GetPose(bPose **pose)
if (*pose == m_pose)
// no need to copy if the pointers are the same
return;
+
extract_pose_from_pose(*pose, m_pose);
}
}
@@ -171,20 +181,16 @@ void BL_ArmatureObject::GetMRDPose(bPose **pose)
/* If the caller supplies a null pose, create a new one. */
/* Otherwise, copy the armature's pose channels into the caller-supplied pose */
- // is this needed anymore?
- //if (!m_mrdPose){
- // copy_pose (&m_mrdPose, m_pose, 0);
- //}
-
if (!*pose) {
// must duplicate the constraints too otherwise we have corruption in free_pose_channels()
// because it will free the blender constraints.
// Ideally, blender should rememeber that the constraints were not copied so that
// free_pose_channels() would not free them.
- copy_pose(pose, m_objArma->pose, 1);
+ copy_pose(pose, m_pose, 1);
+ }
+ else {
+ extract_pose_from_pose(*pose, m_pose);
}
- else
- extract_pose_from_pose(*pose, m_objArma->pose);
}
@@ -198,16 +204,18 @@ double BL_ArmatureObject::GetLastFrame()
return m_lastframe;
}
-bool BL_ArmatureObject::GetBoneMatrix(Bone* bone, MT_Matrix4x4& matrix) const
+bool BL_ArmatureObject::GetBoneMatrix(Bone* bone, MT_Matrix4x4& matrix)
{
- Object* par_arma = m_objArma;
- where_is_pose(par_arma);
- bPoseChannel *pchan= get_pose_channel(par_arma->pose, bone->name);
+ bPoseChannel *pchan;
+
+ ApplyPose();
+ pchan = get_pose_channel(m_objArma->pose, bone->name);
if(pchan) {
matrix.setValue(&pchan->pose_mat[0][0]);
return true;
}
+
return false;
}
diff --git a/source/gameengine/Converter/BL_ArmatureObject.h b/source/gameengine/Converter/BL_ArmatureObject.h
index a612ca77ec0..6f2c0d2f4c9 100644
--- a/source/gameengine/Converter/BL_ArmatureObject.h
+++ b/source/gameengine/Converter/BL_ArmatureObject.h
@@ -59,7 +59,10 @@ public:
void GetMRDPose(struct bPose **pose);
void GetPose(struct bPose **pose);
void SetPose (struct bPose *pose);
+
void ApplyPose();
+ bool VerifyPose();
+
bool SetActiveAction(class BL_ActionActuator *act, short priority, double curtime);
struct bArmature * GetArmature() { return m_armature; }
@@ -69,7 +72,7 @@ public:
/// Retrieve the pose matrix for the specified bone.
/// Returns true on success.
- bool GetBoneMatrix(Bone* bone, MT_Matrix4x4& matrix) const;
+ bool GetBoneMatrix(Bone* bone, MT_Matrix4x4& matrix);
/// Returns the bone length. The end of the bone is in the local y direction.
float GetBoneLength(Bone* bone) const;
@@ -79,11 +82,12 @@ protected:
Object *m_objArma;
struct bArmature *m_armature;
struct bPose *m_pose;
- struct bPose *m_mrdPose;
struct bPose *m_framePose;
double m_lastframe;
class BL_ActionActuator *m_activeAct;
short m_activePriority;
+
+ double m_lastapplyframe;
};
#endif
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
index edc14dabc70..def4938b053 100644
--- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp
+++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
@@ -601,7 +601,6 @@ BL_Material* ConvertMaterial(
(tface->mode & TF_INVISIBLE)
)?POLY_VIS:0;
- material->ras_mode |= ( (tface->mode & TF_DYNAMIC)!= 0 )?COLLIDER:0;
material->transp = tface->transp;
material->tile = tface->tile;
material->mode = tface->mode;
@@ -617,7 +616,7 @@ BL_Material* ConvertMaterial(
}
else {
// nothing at all
- material->ras_mode |= (COLLIDER|POLY_VIS| (validmat?0:USE_LIGHT));
+ material->ras_mode |= (POLY_VIS| (validmat?0:USE_LIGHT));
material->mode = default_face_mode;
material->transp = TF_SOLID;
material->tile = 0;
@@ -627,13 +626,19 @@ BL_Material* ConvertMaterial(
if(validmat && (mat->mode & MA_ZTRA) && (material->transp == TF_SOLID))
material->transp = TF_ALPHA;
- // always zsort alpha + add
- if((material->transp == TF_ALPHA || material->transp == TF_ADD || texalpha)
- && (material->transp != TF_CLIP)) {
+ // always zsort alpha + add
+ if((material->transp == TF_ALPHA || texalpha) && (material->transp != TF_CLIP)) {
material->ras_mode |= ALPHA;
material->ras_mode |= (material->mode & TF_ALPHASORT)? ZSORT: 0;
}
+ // collider or not?
+ material->ras_mode |= (material->mode & TF_DYNAMIC)? COLLIDER: 0;
+
+ // these flags are irrelevant at this point, remove so they
+ // don't hurt material bucketing
+ material->mode &= ~(TF_DYNAMIC|TF_ALPHASORT|TF_TEX);
+
// get uv sets
if(validmat)
{
@@ -644,6 +649,7 @@ BL_Material* ConvertMaterial(
for (int vind = 0; vind<material->num_enabled; vind++)
{
BL_Mapping &map = material->mapping[vind];
+
if (map.uvCoName.IsEmpty())
isFirstSet = false;
else
@@ -673,7 +679,7 @@ BL_Material* ConvertMaterial(
isFirstSet = false;
uvName = layer.name;
}
- else
+ else if(strcmp(layer.name, uvName) != 0)
{
uv2[0] = uvSet[0]; uv2[1] = uvSet[1];
uv2[2] = uvSet[2]; uv2[3] = uvSet[3];
@@ -702,7 +708,6 @@ BL_Material* ConvertMaterial(
material->SetConversionUV(uvName, uv);
material->SetConversionUV2(uv2Name, uv2);
- material->ras_mode |= (mface->v4==0)?TRIANGLE:0;
if(validmat)
material->matname =(mat->id.name);
@@ -767,7 +772,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
}
meshobj->SetName(mesh->id.name);
- meshobj->m_xyz_index_to_vertex_index_mapping.resize(totvert);
+ meshobj->m_sharedvertex_map.resize(totvert);
for (int f=0;f<totface;f++,mface++)
{
@@ -830,7 +835,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
ma = give_current_material(blenderobj, mface->mat_nr+1);
{
- bool polyvisible = true;
+ bool visible = true;
RAS_IPolyMaterial* polymat = NULL;
BL_Material *bl_mat = NULL;
@@ -845,7 +850,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
bl_mat->material_index = (int)mface->mat_nr;
- polyvisible = ((bl_mat->ras_mode & POLY_VIS)!=0);
+ visible = ((bl_mat->ras_mode & POLY_VIS)!=0);
collider = ((bl_mat->ras_mode & COLLIDER)!=0);
/* vertex colors and uv's were stored in bl_mat temporarily */
@@ -862,7 +867,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
uv22 = uv[2]; uv23 = uv[3];
/* then the KX_BlenderMaterial */
- polymat = new KX_BlenderMaterial(scene, bl_mat, skinMesh, lightlayer, blenderobj );
+ polymat = new KX_BlenderMaterial(scene, bl_mat, skinMesh, lightlayer);
}
else {
/* do Texture Face materials */
@@ -886,7 +891,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
tile = tface->tile;
mode = tface->mode;
- polyvisible = !((mface->flag & ME_HIDE)||(tface->mode & TF_INVISIBLE));
+ visible = !((mface->flag & ME_HIDE)||(tface->mode & TF_INVISIBLE));
uv0 = MT_Point2(tface->uv[0]);
uv1 = MT_Point2(tface->uv[1]);
@@ -940,15 +945,13 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
rgb3 = KX_rgbaint2uint_new(color);
}
- bool istriangle = (mface->v4==0);
-
// only zsort alpha + add
bool alpha = (transp == TF_ALPHA || transp == TF_ADD);
bool zsort = (mode & TF_ALPHASORT)? alpha: 0;
polymat = new KX_PolygonMaterial(imastr, ma,
tile, tilexrep, tileyrep,
- mode, transp, alpha, zsort, lightlayer, istriangle, blenderobj, tface, (unsigned int*)mcol);
+ mode, transp, alpha, zsort, lightlayer, tface, (unsigned int*)mcol);
if (ma) {
polymat->m_specular = MT_Vector3(ma->specr, ma->specg, ma->specb)*ma->spec;
@@ -961,6 +964,9 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
}
}
+ /* mark face as flat, so vertices are split */
+ bool flat = (mface->flag & ME_SMOOTH) == 0;
+
// see if a bucket was reused or a new one was created
// this way only one KX_BlenderMaterial object has to exist per bucket
bool bucketCreated;
@@ -981,49 +987,19 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
polymat = bucket->GetPolyMaterial();
}
- int nverts = mface->v4?4:3;
- int vtxarray = meshobj->FindVertexArray(nverts,polymat);
- RAS_Polygon* poly = new RAS_Polygon(bucket,polyvisible,nverts,vtxarray);
-
- bool flat;
-
- if (skinMesh) {
- /* If the face is set to solid, all fnors are the same */
- if (mface->flag & ME_SMOOTH)
- flat = false;
- else
- flat = true;
- }
- else
- flat = false;
+ int nverts = (mface->v4)? 4: 3;
+ RAS_Polygon *poly = meshobj->AddPolygon(bucket, nverts);
- poly->SetVertex(0,meshobj->FindOrAddVertex(vtxarray,pt0,uv0,uv20,tan0,rgb0,no0,flat,polymat,mface->v1));
- poly->SetVertex(1,meshobj->FindOrAddVertex(vtxarray,pt1,uv1,uv21,tan1,rgb1,no1,flat,polymat,mface->v2));
- poly->SetVertex(2,meshobj->FindOrAddVertex(vtxarray,pt2,uv2,uv22,tan2,rgb2,no2,flat,polymat,mface->v3));
- if (nverts==4)
- poly->SetVertex(3,meshobj->FindOrAddVertex(vtxarray,pt3,uv3,uv23,tan3,rgb3,no3,flat,polymat,mface->v4));
-
- meshobj->AddPolygon(poly);
- if (poly->IsCollider())
- {
- RAS_TriangleIndex idx;
- idx.m_index[0] = mface->v1;
- idx.m_index[1] = mface->v2;
- idx.m_index[2] = mface->v3;
- idx.m_collider = collider;
- meshobj->m_triangle_indices.push_back(idx);
- if (nverts==4)
- {
- idx.m_index[0] = mface->v1;
- idx.m_index[1] = mface->v3;
- idx.m_index[2] = mface->v4;
- idx.m_collider = collider;
- meshobj->m_triangle_indices.push_back(idx);
- }
- }
-
-// poly->SetVisibleWireframeEdges(mface->edcode);
+ poly->SetVisible(visible);
poly->SetCollider(collider);
+ //poly->SetEdgeCode(mface->edcode);
+
+ meshobj->AddVertex(poly,0,pt0,uv0,uv20,tan0,rgb0,no0,flat,mface->v1);
+ meshobj->AddVertex(poly,1,pt1,uv1,uv21,tan1,rgb1,no1,flat,mface->v2);
+ meshobj->AddVertex(poly,2,pt2,uv2,uv22,tan2,rgb2,no2,flat,mface->v3);
+
+ if (nverts==4)
+ meshobj->AddVertex(poly,3,pt3,uv3,uv23,tan3,rgb3,no3,flat,mface->v4);
}
if (tface)
@@ -1039,13 +1015,12 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
layer.face++;
}
}
- meshobj->m_xyz_index_to_vertex_index_mapping.clear();
- meshobj->UpdateMaterialList();
+ meshobj->m_sharedvertex_map.clear();
// pre calculate texture generation
- for(RAS_MaterialBucket::Set::iterator mit = meshobj->GetFirstMaterial();
+ for(list<RAS_MeshMaterial>::iterator mit = meshobj->GetFirstMaterial();
mit != meshobj->GetLastMaterial(); ++ mit) {
- (*mit)->GetPolyMaterial()->OnConstruction();
+ mit->m_bucket->GetPolyMaterial()->OnConstruction();
}
if (layers)
@@ -1490,14 +1465,9 @@ static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int l
lightobj.m_type = RAS_LightObject::LIGHT_NORMAL;
}
-#ifdef BLENDER_GLSL
- if(converter->GetGLSLMaterials())
- GPU_lamp_from_blender(ob, la);
-
- gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rendertools, lightobj, ob->gpulamp);
-#else
- gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rendertools, lightobj, NULL);
-#endif
+ gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rendertools,
+ lightobj, converter->GetGLSLMaterials());
+
BL_ConvertLampIpos(la, gamelight, converter);
return gamelight;
@@ -1534,7 +1504,7 @@ static KX_GameObject *gameobject_from_blenderobject(
gamelight->AddRef();
kxscene->GetLightList()->Add(gamelight);
-
+
break;
}
@@ -1643,20 +1613,6 @@ struct parentChildLink {
SG_Node* m_gamechildnode;
};
- /**
- * Find the specified scene by name, or the first
- * scene if nothing matches (shouldn't happen).
- */
-static struct Scene *GetSceneForName(struct Main *maggie, const STR_String& scenename) {
- Scene *sce;
-
- for (sce= (Scene*) maggie->scene.first; sce; sce= (Scene*) sce->id.next)
- if (scenename == (sce->id.name+2))
- return sce;
-
- return (Scene*) maggie->scene.first;
-}
-
#include "DNA_constraint_types.h"
#include "BIF_editconstraint.h"
@@ -1755,7 +1711,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
)
{
- Scene *blenderscene = GetSceneForName(maggie, scenename);
+ Scene *blenderscene = converter->GetBlenderSceneForName(scenename);
// for SETLOOPER
Scene *sce;
Base *base;
@@ -1990,7 +1946,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
//tf.Add(gameobj->GetSGNode());
gameobj->NodeUpdateGS(0,true);
- gameobj->Bucketize();
+ gameobj->AddMeshUser();
}
else
@@ -2187,7 +2143,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
//tf.Add(gameobj->GetSGNode());
gameobj->NodeUpdateGS(0,true);
- gameobj->Bucketize();
+ gameobj->AddMeshUser();
}
else
@@ -2273,8 +2229,11 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
{
// parent this to a bone
Bone *parent_bone = get_named_bone(get_armature(blenderchild->parent), blenderchild->parsubstr);
- KX_BoneParentRelation *bone_parent_relation = KX_BoneParentRelation::New(parent_bone);
- pcit->m_gamechildnode->SetParentRelation(bone_parent_relation);
+
+ if(parent_bone) {
+ KX_BoneParentRelation *bone_parent_relation = KX_BoneParentRelation::New(parent_bone);
+ pcit->m_gamechildnode->SetParentRelation(bone_parent_relation);
+ }
break;
}
@@ -2511,5 +2470,10 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
kxscene->DupliGroupRecurse(gameobj, 0);
}
}
+
+ KX_Camera *activecam = kxscene->GetActiveCamera();
+ MT_Scalar distance = (activecam)? activecam->GetCameraFar() - activecam->GetCameraNear(): 100.0f;
+ RAS_BucketManager *bucketmanager = kxscene->GetBucketManager();
+ bucketmanager->OptimizeBuckets(distance);
}
diff --git a/source/gameengine/Converter/BL_DeformableGameObject.cpp b/source/gameengine/Converter/BL_DeformableGameObject.cpp
index d23274324ee..1d62a41cce9 100644
--- a/source/gameengine/Converter/BL_DeformableGameObject.cpp
+++ b/source/gameengine/Converter/BL_DeformableGameObject.cpp
@@ -41,12 +41,14 @@ BL_DeformableGameObject::~BL_DeformableGameObject()
delete m_pDeformer; // __NLA : Temporary until we decide where to put this
}
-void BL_DeformableGameObject::ProcessReplica(KX_GameObject* replica)
+void BL_DeformableGameObject::ProcessReplica(KX_GameObject* replica)
{
+ BL_MeshDeformer *deformer;
KX_GameObject::ProcessReplica(replica);
- if (m_pDeformer){
- ((BL_DeformableGameObject*)replica)->m_pDeformer = m_pDeformer->GetReplica();
+ if (m_pDeformer) {
+ deformer = (BL_MeshDeformer*)m_pDeformer->GetReplica();
+ ((BL_DeformableGameObject*)replica)->m_pDeformer = deformer;
}
}
diff --git a/source/gameengine/Converter/BL_MeshDeformer.cpp b/source/gameengine/Converter/BL_MeshDeformer.cpp
index 39d66a90e92..fa3b8185fe2 100644
--- a/source/gameengine/Converter/BL_MeshDeformer.cpp
+++ b/source/gameengine/Converter/BL_MeshDeformer.cpp
@@ -50,26 +50,26 @@
bool BL_MeshDeformer::Apply(RAS_IPolyMaterial*)
{
- size_t i, j;
+ size_t i;
float *co;
// only apply once per frame if the mesh is actually modified
if(m_pMeshObject->MeshModified() &&
m_lastDeformUpdate != m_gameobj->GetLastFrame()) {
// For each material
- for(RAS_MaterialBucket::Set::iterator mit = m_pMeshObject->GetFirstMaterial();
+ for(list<RAS_MeshMaterial>::iterator mit= m_pMeshObject->GetFirstMaterial();
mit != m_pMeshObject->GetLastMaterial(); ++ mit) {
- RAS_IPolyMaterial *mat = (*mit)->GetPolyMaterial();
+ if(!mit->m_slots[(void*)m_gameobj])
+ continue;
- vecVertexArray& vertexarrays = m_pMeshObject->GetVertexCache(mat);
-
- // For each array
- for (i=0; i<vertexarrays.size(); i++){
- KX_VertexArray& vertexarray = (*vertexarrays[i]);
+ RAS_MeshSlot *slot = *mit->m_slots[(void*)m_gameobj];
+ RAS_MeshSlot::iterator it;
+ // for each array
+ for(slot->begin(it); !slot->end(it); slot->next(it)) {
// For each vertex
- for (j=0; j<vertexarray.size(); j++){
- RAS_TexVert& v = vertexarray[j];
+ for(i=it.startvertex; i<it.endvertex; i++) {
+ RAS_TexVert& v = it.vertex[i];
co = m_bmesh->mvert[v.getOrigIndex()].co;
v.SetXYZ(MT_Point3(co));
}
@@ -90,7 +90,17 @@ BL_MeshDeformer::~BL_MeshDeformer()
delete [] m_transverts;
if (m_transnors)
delete [] m_transnors;
-};
+}
+
+void BL_MeshDeformer::Relink(GEN_Map<class GEN_HashedPtr, void*>*map)
+{
+ void **h_obj = (*map)[m_gameobj];
+
+ if (h_obj)
+ m_gameobj = (BL_DeformableGameObject*)(*h_obj);
+ else
+ m_gameobj = NULL;
+}
/**
* @warning This function is expensive!
@@ -101,41 +111,41 @@ void BL_MeshDeformer::RecalcNormals()
* gives area-weight normals which often look better anyway, and use
* GL_NORMALIZE so we don't have to do per vertex normalization either
* since the GPU can do it faster */
- size_t i, j;
+ list<RAS_MeshMaterial>::iterator mit;
+ RAS_MeshSlot::iterator it;
+ size_t i;
/* set vertex normals to zero */
memset(m_transnors, 0, sizeof(float)*3*m_bmesh->totvert);
/* add face normals to vertices. */
- for(RAS_MaterialBucket::Set::iterator mit = m_pMeshObject->GetFirstMaterial();
+ for(mit = m_pMeshObject->GetFirstMaterial();
mit != m_pMeshObject->GetLastMaterial(); ++ mit) {
- RAS_IPolyMaterial *mat = (*mit)->GetPolyMaterial();
+ if(!mit->m_slots[(void*)m_gameobj])
+ continue;
- const vecIndexArrays& indexarrays = m_pMeshObject->GetIndexCache(mat);
- vecVertexArray& vertexarrays = m_pMeshObject->GetVertexCache(mat);
+ RAS_MeshSlot *slot = *mit->m_slots[(void*)m_gameobj];
- for (i=0; i<indexarrays.size(); i++) {
- KX_VertexArray& vertexarray = (*vertexarrays[i]);
- const KX_IndexArray& indexarray = (*indexarrays[i]);
- int nvert = mat->UsesTriangles()? 3: 4;
+ for(slot->begin(it); !slot->end(it); slot->next(it)) {
+ int nvert = (int)it.array->m_type;
- for(j=0; j<indexarray.size(); j+=nvert) {
- RAS_TexVert& v1 = vertexarray[indexarray[j]];
- RAS_TexVert& v2 = vertexarray[indexarray[j+1]];
- RAS_TexVert& v3 = vertexarray[indexarray[j+2]];
+ for(i=0; i<it.totindex; i+=nvert) {
+ RAS_TexVert& v1 = it.vertex[it.index[i]];
+ RAS_TexVert& v2 = it.vertex[it.index[i+1]];
+ RAS_TexVert& v3 = it.vertex[it.index[i+2]];
RAS_TexVert *v4 = NULL;
- const float *co1 = v1.getLocalXYZ();
- const float *co2 = v2.getLocalXYZ();
- const float *co3 = v3.getLocalXYZ();
+ const float *co1 = v1.getXYZ();
+ const float *co2 = v2.getXYZ();
+ const float *co3 = v3.getXYZ();
const float *co4 = NULL;
/* compute face normal */
float fnor[3], n1[3], n2[3];
if(nvert == 4) {
- v4 = &vertexarray[indexarray[j+3]];
- co4 = v4->getLocalXYZ();
+ v4 = &it.vertex[it.index[i+3]];
+ co4 = v4->getXYZ();
n1[0]= co1[0]-co3[0];
n1[1]= co1[1]-co3[1];
@@ -174,7 +184,7 @@ void BL_MeshDeformer::RecalcNormals()
}
/* in case of flat - just assign, the vertices are split */
- if(v1.getFlag() & TV_CALCFACENORMAL) {
+ if(v1.getFlag() & RAS_TexVert::FLAT) {
v1.SetNormal(fnor);
v2.SetNormal(fnor);
v3.SetNormal(fnor);
@@ -186,19 +196,18 @@ void BL_MeshDeformer::RecalcNormals()
}
/* assign smooth vertex normals */
- for(RAS_MaterialBucket::Set::iterator mit = m_pMeshObject->GetFirstMaterial();
+ for(mit = m_pMeshObject->GetFirstMaterial();
mit != m_pMeshObject->GetLastMaterial(); ++ mit) {
- RAS_IPolyMaterial *mat = (*mit)->GetPolyMaterial();
+ if(!mit->m_slots[(void*)m_gameobj])
+ continue;
- vecVertexArray& vertexarrays = m_pMeshObject->GetVertexCache(mat);
+ RAS_MeshSlot *slot = *mit->m_slots[(void*)m_gameobj];
- for (i=0; i<vertexarrays.size(); i++) {
- KX_VertexArray& vertexarray = (*vertexarrays[i]);
-
- for(j=0; j<vertexarray.size(); j++) {
- RAS_TexVert& v = vertexarray[j];
+ for(slot->begin(it); !slot->end(it); slot->next(it)) {
+ for(i=it.startvertex; i<it.endvertex; i++) {
+ RAS_TexVert& v = it.vertex[i];
- if(!(v.getFlag() & TV_CALCFACENORMAL))
+ if(!(v.getFlag() & RAS_TexVert::FLAT))
v.SetNormal(m_transnors[v.getOrigIndex()]); //.safe_normalized()
}
}
@@ -219,4 +228,4 @@ void BL_MeshDeformer::VerifyStorage()
m_tvtot = m_bmesh->totvert;
}
}
-
+
diff --git a/source/gameengine/Converter/BL_MeshDeformer.h b/source/gameengine/Converter/BL_MeshDeformer.h
index e9f7f0b192f..9d3d2e78123 100644
--- a/source/gameengine/Converter/BL_MeshDeformer.h
+++ b/source/gameengine/Converter/BL_MeshDeformer.h
@@ -47,7 +47,7 @@ class BL_MeshDeformer : public RAS_Deformer
public:
void VerifyStorage();
void RecalcNormals();
- virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*map){};
+ virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*map);
BL_MeshDeformer(BL_DeformableGameObject *gameobj,
struct Object* obj,
class BL_SkinMeshObject *meshobj ):
@@ -67,6 +67,7 @@ public:
virtual RAS_Deformer* GetReplica(){return NULL;};
struct Mesh* GetMesh() { return m_bmesh; };
// virtual void InitDeform(double time){};
+
protected:
class BL_SkinMeshObject* m_pMeshObject;
struct Mesh* m_bmesh;
diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp
index 942e3b502e0..799b6b74b66 100644
--- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp
+++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp
@@ -134,7 +134,6 @@ void BL_ShapeActionActuator::BlendShape(Key* key, float srcweight)
{
vector<float>::const_iterator it;
float dstweight;
- int i;
KeyBlock *kb;
dstweight = 1.0F - srcweight;
diff --git a/source/gameengine/Converter/BL_ShapeDeformer.cpp b/source/gameengine/Converter/BL_ShapeDeformer.cpp
index b2e54539b19..236cd1a6667 100644
--- a/source/gameengine/Converter/BL_ShapeDeformer.cpp
+++ b/source/gameengine/Converter/BL_ShapeDeformer.cpp
@@ -111,10 +111,7 @@ bool BL_ShapeDeformer::ExecuteShapeDrivers(void)
int type;
// the shape drivers use the bone matrix as input. Must
// update the matrix now
- Object* par_arma = m_armobj->GetArmatureObject();
m_armobj->ApplyPose();
- where_is_pose( par_arma );
- PoseApplied(true);
for (it=m_shapeDrivers.begin(); it!=m_shapeDrivers.end(); it++) {
// no need to set a specific time: this curve has a driver
diff --git a/source/gameengine/Converter/BL_ShapeDeformer.h b/source/gameengine/Converter/BL_ShapeDeformer.h
index 5f0188e3a42..1465bb01e22 100644
--- a/source/gameengine/Converter/BL_ShapeDeformer.h
+++ b/source/gameengine/Converter/BL_ShapeDeformer.h
@@ -43,17 +43,6 @@ struct IpoCurve;
class BL_ShapeDeformer : public BL_SkinDeformer
{
public:
- virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*map)
- {
- void **h_obj = (*map)[m_gameobj];
- if (h_obj){
- m_gameobj = (BL_DeformableGameObject*)(*h_obj);
- }
- else
- m_gameobj=NULL;
- // relink the underlying skin deformer
- BL_SkinDeformer::Relink(map);
- };
BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
Object *bmeshobj,
BL_SkinMeshObject *mesh)
diff --git a/source/gameengine/Converter/BL_SkinDeformer.cpp b/source/gameengine/Converter/BL_SkinDeformer.cpp
index f96c40c098f..d8e7a9cdadf 100644
--- a/source/gameengine/Converter/BL_SkinDeformer.cpp
+++ b/source/gameengine/Converter/BL_SkinDeformer.cpp
@@ -99,9 +99,26 @@ BL_SkinDeformer::~BL_SkinDeformer()
m_armobj->Release();
}
+void BL_SkinDeformer::Relink(GEN_Map<class GEN_HashedPtr, void*>*map)
+{
+ if (m_armobj) {
+ void **h_obj = (*map)[m_armobj];
+
+ if (h_obj)
+ SetArmature( (BL_ArmatureObject*)(*h_obj) );
+ else
+ m_armobj=NULL;
+ }
+
+ BL_MeshDeformer::Relink(map);
+}
+
bool BL_SkinDeformer::Apply(RAS_IPolyMaterial *mat)
{
- size_t i, j;
+ RAS_MeshSlot::iterator it;
+ RAS_MeshMaterial *mmat;
+ RAS_MeshSlot *slot;
+ size_t i;
// update the vertex in m_transverts
Update();
@@ -110,16 +127,18 @@ bool BL_SkinDeformer::Apply(RAS_IPolyMaterial *mat)
// Duplicated objects with more than one ploymaterial (=multiple mesh slot per object)
// share the same mesh (=the same cache). As the rendering is done per polymaterial
// cycling through the objects, the entire mesh cache cannot be updated in one shot.
- vecVertexArray& vertexarrays = m_pMeshObject->GetVertexCache(mat);
+ mmat = m_pMeshObject->GetMeshMaterial(mat);
+ if(!mmat->m_slots[(void*)m_gameobj])
+ return true;
- // For each array
- for (i=0; i<vertexarrays.size(); i++) {
- KX_VertexArray& vertexarray = (*vertexarrays[i]);
+ slot = *mmat->m_slots[(void*)m_gameobj];
- // For each vertex
+ // for each array
+ for(slot->begin(it); !slot->end(it); slot->next(it)) {
+ // for each vertex
// copy the untransformed data from the original mvert
- for (j=0; j<vertexarray.size(); j++) {
- RAS_TexVert& v = vertexarray[j];
+ for(i=it.startvertex; i<it.endvertex; i++) {
+ RAS_TexVert& v = it.vertex[i];
v.SetXYZ(m_transverts[v.getOrigIndex()]);
}
}
@@ -147,14 +166,10 @@ bool BL_SkinDeformer::Update(void)
/* See if the armature has been updated for this frame */
if (PoseUpdated()){
float obmat[4][4]; // the original object matrice
-
+
/* XXX note: where_is_pose() (from BKE_armature.h) calculates all matrices needed to start deforming */
/* but it requires the blender object pointer... */
Object* par_arma = m_armobj->GetArmatureObject();
- if (!PoseApplied()){
- m_armobj->ApplyPose();
- where_is_pose( par_arma );
- }
/* store verts locally */
VerifyStorage();
@@ -163,6 +178,8 @@ bool BL_SkinDeformer::Update(void)
for (int v =0; v<m_bmesh->totvert; v++)
VECCOPY(m_transverts[v], m_bmesh->mvert[v].co);
+ m_armobj->ApplyPose();
+
// save matrix first
Mat4CpyMat4(obmat, m_objMesh->obmat);
// set reference matrix
@@ -179,11 +196,11 @@ bool BL_SkinDeformer::Update(void)
/* Update the current frame */
m_lastArmaUpdate=m_armobj->GetLastFrame();
- /* reset for next frame */
- PoseApplied(false);
+
/* indicate that the m_transverts and normals are up to date */
return true;
}
+
return false;
}
diff --git a/source/gameengine/Converter/BL_SkinDeformer.h b/source/gameengine/Converter/BL_SkinDeformer.h
index d3fc5ae2a81..e08de8c478a 100644
--- a/source/gameengine/Converter/BL_SkinDeformer.h
+++ b/source/gameengine/Converter/BL_SkinDeformer.h
@@ -50,17 +50,7 @@ class BL_SkinDeformer : public BL_MeshDeformer
{
public:
// void SetArmatureController (BL_ArmatureController *cont);
- virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*map)
- {
- if (m_armobj){
- void **h_obj = (*map)[m_armobj];
- if (h_obj){
- SetArmature( (BL_ArmatureObject*)(*h_obj) );
- }
- else
- m_armobj=NULL;
- }
- }
+ virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*map);
void SetArmature (class BL_ArmatureObject *armobj);
BL_SkinDeformer(BL_DeformableGameObject *gameobj,
@@ -81,10 +71,6 @@ public:
virtual ~BL_SkinDeformer();
bool Update (void);
bool Apply (class RAS_IPolyMaterial *polymat);
- bool PoseApplied()
- { return m_poseApplied; }
- void PoseApplied(bool applied)
- { m_poseApplied = applied; }
bool PoseUpdated(void)
{
if (m_armobj && m_lastArmaUpdate!=m_armobj->GetLastFrame()) {
diff --git a/source/gameengine/Converter/BL_SkinMeshObject.cpp b/source/gameengine/Converter/BL_SkinMeshObject.cpp
index fa215df1e1c..4f9f1a434b5 100644
--- a/source/gameengine/Converter/BL_SkinMeshObject.cpp
+++ b/source/gameengine/Converter/BL_SkinMeshObject.cpp
@@ -28,42 +28,69 @@
* Deformer that supports armature skinning
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#ifdef WIN32
#pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning
#endif //WIN32
-#include "RAS_IPolygonMaterial.h"
-#include "BL_SkinMeshObject.h"
-#include "BL_DeformableGameObject.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_key_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
-#include "KX_GameObject.h"
+
#include "RAS_BucketManager.h"
+#include "RAS_IPolygonMaterial.h"
-//void BL_SkinMeshObject::Bucketize(double* oglmatrix,void* clientobj,bool useObjectColor,const MT_Vector4& rgbavec,RAS_BucketManager* bucketmgr)
-void BL_SkinMeshObject::Bucketize(double* oglmatrix,void* clientobj,bool useObjectColor,const MT_Vector4& rgbavec)
-{
+#include "KX_GameObject.h"
+
+#include "BL_SkinMeshObject.h"
+#include "BL_DeformableGameObject.h"
- KX_MeshSlot ms;
- ms.m_clientObj = clientobj;
- ms.m_mesh = this;
- ms.m_OpenGLMatrix = oglmatrix;
- ms.m_bObjectColor = useObjectColor;
- ms.m_RGBAcolor = rgbavec;
- ms.m_pDeformer = ((BL_DeformableGameObject*)clientobj)->m_pDeformer;
-
- for (RAS_MaterialBucket::Set::iterator it = m_materials.begin();it!=m_materials.end();it++)
+BL_SkinMeshObject::BL_SkinMeshObject(Mesh* mesh, int lightlayer)
+ : RAS_MeshObject (mesh, lightlayer)
+{
+ m_bDeformed = true;
+
+ if (m_mesh && m_mesh->key)
{
+ KeyBlock *kb;
+ int count=0;
+ // initialize weight cache for shape objects
+ // count how many keys in this mesh
+ for(kb= (KeyBlock*)m_mesh->key->block.first; kb; kb= (KeyBlock*)kb->next)
+ count++;
+ m_cacheWeightIndex.resize(count,-1);
+ }
+}
- RAS_MaterialBucket* materialbucket = (*it);
+BL_SkinMeshObject::~BL_SkinMeshObject()
+{
+ if (m_mesh && m_mesh->key)
+ {
+ KeyBlock *kb;
+ // remove the weight cache to avoid memory leak
+ for(kb= (KeyBlock*)m_mesh->key->block.first; kb; kb= (KeyBlock*)kb->next) {
+ if(kb->weights)
+ MEM_freeN(kb->weights);
+ kb->weights= NULL;
+ }
+ }
+}
+
+void BL_SkinMeshObject::UpdateBuckets(void* clientobj,double* oglmatrix,bool useObjectColor,const MT_Vector4& rgbavec, bool visible, bool culled)
+{
+ list<RAS_MeshMaterial>::iterator it;
+ list<RAS_MeshSlot*>::iterator sit;
+
+ for(it = m_materials.begin();it!=m_materials.end();++it) {
+ if(!it->m_slots[clientobj])
+ continue;
-// KX_ArrayOptimizer* oa = GetArrayOptimizer(materialbucket->GetPolyMaterial());
- materialbucket->SetMeshSlot(ms);
+ RAS_MeshSlot *slot = *it->m_slots[clientobj];
+ slot->m_pDeformer = ((BL_DeformableGameObject*)clientobj)->m_pDeformer;
}
+ RAS_MeshObject::UpdateBuckets(clientobj, oglmatrix, useObjectColor, rgbavec, visible, culled);
}
static int get_def_index(Object* ob, const char* vgroup)
@@ -74,6 +101,7 @@ static int get_def_index(Object* ob, const char* vgroup)
for (curdef = (bDeformGroup*)ob->defbase.first; curdef; curdef=(bDeformGroup*)curdef->next, index++)
if (!strcmp(curdef->name, vgroup))
return index;
+
return -1;
}
diff --git a/source/gameengine/Converter/BL_SkinMeshObject.h b/source/gameengine/Converter/BL_SkinMeshObject.h
index c21fb64204b..8544a2b958c 100644
--- a/source/gameengine/Converter/BL_SkinMeshObject.h
+++ b/source/gameengine/Converter/BL_SkinMeshObject.h
@@ -33,62 +33,27 @@
#ifdef WIN32
#pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning
#endif //WIN32
-#include "MEM_guardedalloc.h"
+
#include "RAS_MeshObject.h"
#include "RAS_Deformer.h"
#include "RAS_IPolygonMaterial.h"
#include "BL_MeshDeformer.h"
-#include "DNA_mesh_types.h"
-#include "DNA_key_types.h"
-#include "DNA_meshdata_types.h"
-
class BL_SkinMeshObject : public RAS_MeshObject
{
-
-// enum { BUCKET_MAX_INDICES = 16384};//2048};//8192};
-// enum { BUCKET_MAX_TRIANGLES = 4096};
-
protected:
vector<int> m_cacheWeightIndex;
public:
- void Bucketize(double* oglmatrix,void* clientobj,bool useObjectColor,const MT_Vector4& rgbavec);
-// void Bucketize(double* oglmatrix,void* clientobj,bool useObjectColor,const MT_Vector4& rgbavec,class RAS_BucketManager* bucketmgr);
-
- BL_SkinMeshObject(Mesh* mesh, int lightlayer) : RAS_MeshObject (mesh, lightlayer)
- {
- m_class = 1;
- if (m_mesh && m_mesh->key)
- {
- KeyBlock *kb;
- int count=0;
- // initialize weight cache for shape objects
- // count how many keys in this mesh
- for(kb= (KeyBlock*)m_mesh->key->block.first; kb; kb= (KeyBlock*)kb->next)
- count++;
- m_cacheWeightIndex.resize(count,-1);
- }
- };
+ BL_SkinMeshObject(Mesh* mesh, int lightlayer);
+ ~BL_SkinMeshObject();
- virtual ~BL_SkinMeshObject()
- {
- if (m_mesh && m_mesh->key)
- {
- KeyBlock *kb;
- // remove the weight cache to avoid memory leak
- for(kb= (KeyBlock*)m_mesh->key->block.first; kb; kb= (KeyBlock*)kb->next) {
- if(kb->weights)
- MEM_freeN(kb->weights);
- kb->weights= NULL;
- }
- }
- };
+ void UpdateBuckets(void* clientobj, double* oglmatrix,
+ bool useObjectColor, const MT_Vector4& rgbavec, bool visible, bool culled);
// for shape keys,
void CheckWeightCache(struct Object* obj);
-
};
#endif
diff --git a/source/gameengine/Converter/CMakeLists.txt b/source/gameengine/Converter/CMakeLists.txt
index adb7304b10e..217bdb30907 100644
--- a/source/gameengine/Converter/CMakeLists.txt
+++ b/source/gameengine/Converter/CMakeLists.txt
@@ -64,6 +64,7 @@ SET(INC
../../../source/gameengine/Network/LoopBackNetwork
../../../source/blender/misc
../../../source/blender/blenloader
+ ../../../source/blender/gpu
../../../extern/bullet2/src
../../../extern/solid
${PYTHON_INC}
diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
index de91bce2ab1..1f5b578d441 100644
--- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
+++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
@@ -184,20 +184,21 @@ bool KX_BlenderSceneConverter::TryAndLoadNewFile()
return result;
}
-
+Scene *KX_BlenderSceneConverter::GetBlenderSceneForName(const STR_String& name)
+{
+ Scene *sce;
/**
* Find the specified scene by name, or the first
* scene if nothing matches (shouldn't happen).
*/
-static struct Scene *GetSceneForName2(struct Main *maggie, const STR_String& scenename) {
- Scene *sce;
- for (sce= (Scene*) maggie->scene.first; sce; sce= (Scene*) sce->id.next)
- if (scenename == (sce->id.name+2))
+ for (sce= (Scene*) m_maggie->scene.first; sce; sce= (Scene*) sce->id.next)
+ if (name == (sce->id.name+2))
return sce;
- return (Scene*) maggie->scene.first;
+ return (Scene*)m_maggie->scene.first;
+
}
#include "KX_PythonInit.h"
@@ -258,7 +259,7 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename,
class RAS_ICanvas* canvas)
{
//find out which physics engine
- Scene *blenderscene = GetSceneForName2(m_maggie, scenename);
+ Scene *blenderscene = GetBlenderSceneForName(scenename);
e_PhysicsEngine physics_engine = UseBullet;
// hook for registration function during conversion.
@@ -818,7 +819,7 @@ void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber)
KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g);
if (gameObj->IsDynamic())
{
- KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController();
+ //KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController();
Object* blenderObject = FindBlenderObject(gameObj);
if (blenderObject)
@@ -846,7 +847,7 @@ void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber)
- const MT_Vector3& scale = gameObj->NodeGetWorldScaling();
+ //const MT_Vector3& scale = gameObj->NodeGetWorldScaling();
const MT_Point3& position = gameObj->NodeGetWorldPosition();
Ipo* ipo = blenderObject->ipo;
@@ -974,7 +975,7 @@ void KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo()
KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g);
if (gameObj->IsDynamic())
{
- KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController();
+ //KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController();
Object* blenderObject = FindBlenderObject(gameObj);
if (blenderObject)
@@ -1002,8 +1003,8 @@ void KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo()
- const MT_Vector3& scale = gameObj->NodeGetWorldScaling();
- const MT_Point3& position = gameObj->NodeGetWorldPosition();
+ //const MT_Vector3& scale = gameObj->NodeGetWorldScaling();
+ //const MT_Point3& position = gameObj->NodeGetWorldPosition();
Ipo* ipo = blenderObject->ipo;
if (ipo)
diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.h b/source/gameengine/Converter/KX_BlenderSceneConverter.h
index e5d6ccc5caf..2317e952a0a 100644
--- a/source/gameengine/Converter/KX_BlenderSceneConverter.h
+++ b/source/gameengine/Converter/KX_BlenderSceneConverter.h
@@ -45,6 +45,7 @@ class BL_Material;
struct IpoCurve;
struct Main;
struct SpaceIpo;
+struct Scene;
class KX_BlenderSceneConverter : public KX_ISceneConverter
{
@@ -151,6 +152,7 @@ public:
virtual void SetGLSLMaterials(bool val);
virtual bool GetGLSLMaterials();
+ struct Scene* GetBlenderSceneForName(const STR_String& name);
};
#endif //__KX_BLENDERSCENECONVERTER_H
diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp
index 7e976beaf44..321fc325bb8 100644
--- a/source/gameengine/Converter/KX_ConvertActuators.cpp
+++ b/source/gameengine/Converter/KX_ConvertActuators.cpp
@@ -1064,7 +1064,7 @@ void BL_ConvertActuators(char* maggiename,
{
bParentActuator *parAct = (bParentActuator *) bact->data;
int mode = KX_ParentActuator::KX_PARENT_NODEF;
- KX_GameObject *tmpgob;
+ KX_GameObject *tmpgob = NULL;
switch(parAct->type)
{
diff --git a/source/gameengine/Converter/Makefile b/source/gameengine/Converter/Makefile
index f312fc13221..4dd63e428bd 100644
--- a/source/gameengine/Converter/Makefile
+++ b/source/gameengine/Converter/Makefile
@@ -51,6 +51,7 @@ CPPFLAGS += -I../../blender/include
CPPFLAGS += -I../../blender/blenlib
CPPFLAGS += -I../../blender/blenkernel
CPPFLAGS += -I../../blender/render/extern/include
+CPPFLAGS += -I../../blender/gpu
CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
CPPFLAGS += -I../Expressions -I../Rasterizer -I../GameLogic
CPPFLAGS += -I../Ketsji -I../BlenderRoutines -I../SceneGraph
diff --git a/source/gameengine/Converter/SConscript b/source/gameengine/Converter/SConscript
index f5e382b471e..3be352c568b 100644
--- a/source/gameengine/Converter/SConscript
+++ b/source/gameengine/Converter/SConscript
@@ -16,7 +16,7 @@ incs += ' #source/gameengine/Expressions #source/gameengine/Network #source/game
incs += ' #source/gameengine/Physics/common #source/gameengine/Physics/Bullet #source/gameengine/Physics/BlOde'
incs += ' #source/gameengine/Physics/Dummy #source/gameengine/Physics/Sumo'
incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork'
-incs += ' #source/blender/misc #source/blender/blenloader'
+incs += ' #source/blender/misc #source/blender/blenloader #source/blender/gpu'
incs += ' ' + env['BF_PYTHON_INC']
incs += ' ' + env['BF_SOLID_INC']
diff --git a/source/gameengine/GamePlayer/common/CMakeLists.txt b/source/gameengine/GamePlayer/common/CMakeLists.txt
index e26f8b9d69a..0c6c4179e2d 100644
--- a/source/gameengine/GamePlayer/common/CMakeLists.txt
+++ b/source/gameengine/GamePlayer/common/CMakeLists.txt
@@ -30,7 +30,6 @@ SET(SRC
GPC_Engine.cpp
GPC_KeyboardDevice.cpp
GPC_MouseDevice.cpp
- GPC_PolygonMaterial.cpp
GPC_RawImage.cpp
GPC_RawLoadDotBlendArray.cpp
GPC_RawLogoArrays.cpp
@@ -69,6 +68,7 @@ SET(INC
../../../../source/gameengine/GamePlayer/ghost
../../../../source/blender/misc
../../../../source/blender/blenloader
+ ../../../../source/blender/gpu
../../../../extern/glew/include
${PYTHON_INC}
${SOLID_INC}
diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
index a64c85f6c17..78d8eaf2aa3 100644
--- a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
+++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
@@ -27,141 +27,256 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#include <assert.h>
-
-#ifdef WIN32
-#pragma warning (disable : 4786)
-#include <windows.h>
-#endif
-
#include "GL/glew.h"
-#include <iostream>
-
-#include "GPC_RenderTools.h"
-
#include "RAS_IRenderTools.h"
#include "RAS_IRasterizer.h"
#include "RAS_LightObject.h"
#include "RAS_ICanvas.h"
#include "RAS_GLExtensionManager.h"
-// next two includes/dependencies come from the shadow feature
-// it needs the gameobject and the sumo physics scene for a raycast
#include "KX_GameObject.h"
-
-#include "GPC_PolygonMaterial.h"
#include "KX_PolygonMaterial.h"
-#include "Value.h"
+#include "KX_BlenderMaterial.h"
+#include "KX_RayCast.h"
+#include "KX_IPhysicsController.h"
+
+#include "PHY_IPhysicsEnvironment.h"
-//#include "KX_BlenderGL.h" // for text printing
-//#include "KX_BlenderClientObject.h"
#include "STR_String.h"
-#include "RAS_BucketManager.h" // for polymaterial (needed for textprinting)
-
-
-// Blender includes
-/* This list includes only data type definitions */
-#include "DNA_object_types.h"
-#include "DNA_material_types.h"
-#include "DNA_image_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_group_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_camera_types.h"
-#include "DNA_property_types.h"
-#include "DNA_text_types.h"
-#include "DNA_sensor_types.h"
-#include "DNA_controller_types.h"
-#include "DNA_actuator_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_world_types.h"
-
-#include "BKE_global.h"
-#include "BKE_image.h"
-#include "BKE_bmfont.h"
+
+#include "GPU_draw.h"
+
+#include "BKE_bmfont.h" // for text printing
#include "BKE_bmfont_types.h"
-#include "BKE_main.h"
-#include "IMB_imbuf_types.h"
-// End of Blender includes
+#include "GPC_RenderTools.h"
-#include "KX_Scene.h"
-#include "KX_RayCast.h"
-#include "KX_IPhysicsController.h"
-#include "PHY_IPhysicsEnvironment.h"
-#include "KX_BlenderMaterial.h"
+unsigned int GPC_RenderTools::m_numgllights;
GPC_RenderTools::GPC_RenderTools()
{
m_font = BMF_GetFont(BMF_kHelvetica10);
+
glGetIntegerv(GL_MAX_LIGHTS, (GLint*) &m_numgllights);
if (m_numgllights < 8)
m_numgllights = 8;
}
-
GPC_RenderTools::~GPC_RenderTools()
{
}
+void GPC_RenderTools::BeginFrame(RAS_IRasterizer* rasty)
+{
+ m_clientobject = NULL;
+ m_lastlightlayer = -1;
+ m_lastlighting = false;
+ DisableOpenGLLights();
+}
void GPC_RenderTools::EndFrame(RAS_IRasterizer* rasty)
{
}
+/* ProcessLighting performs lighting on objects. the layer is a bitfield that
+ * contains layer information. There are 20 'official' layers in blender. A
+ * light is applied on an object only when they are in the same layer. OpenGL
+ * has a maximum of 8 lights (simultaneous), so 20 * 8 lights are possible in
+ * a scene. */
-void GPC_RenderTools::BeginFrame(RAS_IRasterizer* rasty)
+void GPC_RenderTools::ProcessLighting(int layer, const MT_Transform& viewmat)
{
- m_clientobject=NULL;
- m_modified=true;
- DisableOpenGLLights();
+ if(m_lastlightlayer == layer)
+ return;
-}
+ m_lastlightlayer = layer;
-int GPC_RenderTools::ProcessLighting(int layer)
-{
- int result = false;
+ bool enable = false;
- if (layer < 0)
- {
- DisableOpenGLLights();
- result = false;
- } else
+ if (layer >= 0)
{
if (m_clientobject)
- {
- if (applyLights(layer))
- {
- EnableOpenGLLights();
- result = true;
- } else
- {
- DisableOpenGLLights();
- result = false;
- }
+ {
+ if (layer == RAS_LIGHT_OBJECT_LAYER)
+ layer = static_cast<KX_GameObject*>(m_clientobject)->GetLayer();
+
+ enable = applyLights(layer, viewmat);
}
}
- return result;
+
+ if(enable)
+ EnableOpenGLLights();
+ else
+ DisableOpenGLLights();
}
void GPC_RenderTools::EnableOpenGLLights()
{
+ if(m_lastlighting == true)
+ return;
+
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
- glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
+
+ glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, true);
if (GLEW_EXT_separate_specular_color || GLEW_VERSION_1_2)
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
+
+ m_lastlighting = true;
}
-void GPC_RenderTools::RenderText2D(RAS_TEXT_RENDER_MODE mode,
- const char* text,
- int xco,
- int yco,
- int width,
- int height)
+void GPC_RenderTools::DisableOpenGLLights()
+{
+ if(m_lastlighting == false)
+ return;
+
+ glDisable(GL_LIGHTING);
+ glDisable(GL_COLOR_MATERIAL);
+
+ m_lastlighting = false;
+}
+
+
+void GPC_RenderTools::SetClientObject(RAS_IRasterizer *rasty, void* obj)
+{
+ if (m_clientobject != obj)
+ {
+ bool ccw = (obj == NULL || !((KX_GameObject*)obj)->IsNegativeScaling());
+ rasty->SetFrontFace(ccw);
+
+ m_clientobject = obj;
+ }
+}
+
+bool GPC_RenderTools::RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data)
+{
+ double* const oglmatrix = (double* const) data;
+ MT_Point3 resultpoint(result->m_hitPoint);
+ MT_Vector3 resultnormal(result->m_hitNormal);
+ MT_Vector3 left(oglmatrix[0],oglmatrix[1],oglmatrix[2]);
+ MT_Vector3 dir = -(left.cross(resultnormal)).safe_normalized();
+ left = (dir.cross(resultnormal)).safe_normalized();
+ // for the up vector, we take the 'resultnormal' returned by the physics
+
+ double maat[16]={
+ left[0], left[1], left[2], 0,
+ dir[0], dir[1], dir[2], 0,
+ resultnormal[0],resultnormal[1],resultnormal[2], 0,
+ 0, 0, 0, 1};
+ glTranslated(resultpoint[0],resultpoint[1],resultpoint[2]);
+ //glMultMatrixd(oglmatrix);
+ glMultMatrixd(maat);
+ return true;
+}
+
+void GPC_RenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmatrix,int objectdrawmode )
+{
+ /* FIXME:
+ blender: intern/moto/include/MT_Vector3.inl:42: MT_Vector3 operator/(const
+ MT_Vector3&, double): Assertion `!MT_fuzzyZero(s)' failed.
+
+ Program received signal SIGABRT, Aborted.
+ [Switching to Thread 16384 (LWP 1519)]
+ 0x40477571 in kill () from /lib/libc.so.6
+ (gdb) bt
+ #7 0x08334368 in MT_Vector3::normalized() const ()
+ #8 0x0833e6ec in GPC_RenderTools::applyTransform(RAS_IRasterizer*, double*, int) ()
+ */
+
+ if (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED ||
+ objectdrawmode & RAS_IPolyMaterial::BILLBOARD_AXISALIGNED)
+ {
+ // rotate the billboard/halo
+ //page 360/361 3D Game Engine Design, David Eberly for a discussion
+ // on screen aligned and axis aligned billboards
+ // assumed is that the preprocessor transformed all billboard polygons
+ // so that their normal points into the positive x direction (1.0 , 0.0 , 0.0)
+ // when new parenting for objects is done, this rotation
+ // will be moved into the object
+
+ MT_Point3 objpos (oglmatrix[12],oglmatrix[13],oglmatrix[14]);
+ MT_Point3 campos = rasty->GetCameraPosition();
+ MT_Vector3 dir = (campos - objpos).safe_normalized();
+ MT_Vector3 up(0,0,1.0);
+
+ KX_GameObject* gameobj = (KX_GameObject*) this->m_clientobject;
+ // get scaling of halo object
+ MT_Vector3 size = gameobj->GetSGNode()->GetLocalScale();
+
+ bool screenaligned = (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED)!=0;//false; //either screen or axisaligned
+ if (screenaligned)
+ {
+ up = (up - up.dot(dir) * dir).safe_normalized();
+ } else
+ {
+ dir = (dir - up.dot(dir)*up).safe_normalized();
+ }
+
+ MT_Vector3 left = dir.normalized();
+ dir = (left.cross(up)).normalized();
+
+ // we have calculated the row vectors, now we keep
+ // local scaling into account:
+
+ left *= size[0];
+ dir *= size[1];
+ up *= size[2];
+ double maat[16]={
+ left[0], left[1],left[2], 0,
+ dir[0], dir[1],dir[2],0,
+ up[0],up[1],up[2],0,
+ 0,0,0,1};
+ glTranslated(objpos[0],objpos[1],objpos[2]);
+ glMultMatrixd(maat);
+
+ } else
+ {
+ if (objectdrawmode & RAS_IPolyMaterial::SHADOW)
+ {
+ // shadow must be cast to the ground, physics system needed here!
+ MT_Point3 frompoint(oglmatrix[12],oglmatrix[13],oglmatrix[14]);
+ KX_GameObject *gameobj = (KX_GameObject*) this->m_clientobject;
+ MT_Vector3 direction = MT_Vector3(0,0,-1);
+
+ direction.normalize();
+ direction *= 100000;
+
+ MT_Point3 topoint = frompoint + direction;
+
+ KX_Scene* kxscene = (KX_Scene*) m_auxilaryClientInfo;
+ PHY_IPhysicsEnvironment* physics_environment = kxscene->GetPhysicsEnvironment();
+ KX_IPhysicsController* physics_controller = gameobj->GetPhysicsController();
+
+ KX_GameObject *parent = gameobj->GetParent();
+ if (!physics_controller && parent)
+ physics_controller = parent->GetPhysicsController();
+ if (parent)
+ parent->Release();
+
+ KX_RayCast::Callback<GPC_RenderTools> callback(this, physics_controller, oglmatrix);
+ if (!KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback))
+ {
+ // couldn't find something to cast the shadow on...
+ glMultMatrixd(oglmatrix);
+ }
+ } else
+ {
+
+ // 'normal' object
+ glMultMatrixd(oglmatrix);
+ }
+ }
+}
+
+
+void GPC_RenderTools::RenderText2D(RAS_TEXT_RENDER_MODE mode,
+ const char* text,
+ int xco,
+ int yco,
+ int width,
+ int height)
{
STR_String tmpstr(text);
int lines;
@@ -234,21 +349,19 @@ void GPC_RenderTools::RenderText2D(RAS_TEXT_RENDER_MODE mode,
glDisable(GL_LIGHTING);
}
-/**
- * Copied from KX_BlenderRenderTools.cpp in KX_blenderhook
- * Renders text into a (series of) polygon(s), using a texture font,
- * Each character consists of one polygon (one quad or two triangles)
- */
+/* Render Text renders text into a (series of) polygon, using a texture font,
+ * Each character consists of one polygon (one quad or two triangles) */
+
void GPC_RenderTools::RenderText(
int mode,
RAS_IPolyMaterial* polymat,
- float v1[3], float v2[3], float v3[3], float v4[3])
+ float v1[3], float v2[3], float v3[3], float v4[3], int glattrib)
{
STR_String mytext = ((CValue*)m_clientobject)->GetPropertyText("Text");
const unsigned int flag = polymat->GetFlag();
struct MTFace* tface = 0;
- unsigned int* col = 0;
+ unsigned int *col = 0;
if(flag & RAS_BLENDERMAT) {
KX_BlenderMaterial *bl_mat = static_cast<KX_BlenderMaterial*>(polymat);
@@ -259,110 +372,29 @@ void GPC_RenderTools::RenderText(
tface = blenderpoly->GetMTFace();
col = blenderpoly->GetMCol();
}
-
- BL_RenderText(mode, mytext, mytext.Length(), tface, col, v1, v2, v3, v4);
+
+ GPU_render_text(tface, mode, mytext, mytext.Length(), col, v1, v2, v3, v4, glattrib);
}
-
-/**
- * Copied from KX_BlenderGL.cpp in KX_blenderhook
- */
-void GPC_RenderTools::BL_RenderText(
- int mode,
- const char* textstr,
- int textlen,
- struct MTFace* tface,
- unsigned int* col,
- float v1[3],float v2[3],float v3[3],float v4[3])
+void GPC_RenderTools::PushMatrix()
{
- struct Image* ima;
-
- if (mode & TF_BMFONT) {
- //char string[MAX_PROPSTRING];
-// float tmat[4][4];
- int characters, index, character;
- float centerx, centery, sizex, sizey, transx, transy, movex, movey, advance;
-
-// bProperty *prop;
-
- // string = "Frank van Beek";
-
- characters = textlen;
-
- ima = (struct Image*) tface->tpage;
- if (ima == NULL) {
- characters = 0;
- }
-
- if(!col) glColor3f(1.0f, 1.0f, 1.0f);
-
- glPushMatrix();
- for (index = 0; index < characters; index++) {
- // lets calculate offset stuff
- character = textstr[index];
-
- // space starts at offset 1
- // character = character - ' ' + 1;
-
- matrixGlyph((ImBuf *)ima->ibufs.first, character, & centerx, &centery, &sizex, &sizey, &transx, &transy, &movex, &movey, &advance);
-
- glBegin(GL_POLYGON);
- // printf(" %c %f %f %f %f\n", character, tface->uv[0][0], tface->uv[0][1], );
- // glTexCoord2f((tface->uv[0][0] - centerx) * sizex + transx, (tface->uv[0][1] - centery) * sizey + transy);
- glTexCoord2f((tface->uv[0][0] - centerx) * sizex + transx, (tface->uv[0][1] - centery) * sizey + transy);
-
- if(col) BL_spack(col[0]);
- // glVertex3fv(v1);
- glVertex3f(sizex * v1[0] + movex, sizey * v1[1] + movey, v1[2]);
-
- glTexCoord2f((tface->uv[1][0] - centerx) * sizex + transx, (tface->uv[1][1] - centery) * sizey + transy);
- if(col) BL_spack(col[1]);
- // glVertex3fv(v2);
- glVertex3f(sizex * v2[0] + movex, sizey * v2[1] + movey, v2[2]);
-
- glTexCoord2f((tface->uv[2][0] - centerx) * sizex + transx, (tface->uv[2][1] - centery) * sizey + transy);
- if(col) BL_spack(col[2]);
- // glVertex3fv(v3);
- glVertex3f(sizex * v3[0] + movex, sizey * v3[1] + movey, v3[2]);
-
- if(v4) {
- // glTexCoord2f((tface->uv[3][0] - centerx) * sizex + transx, 1.0 - (1.0 - tface->uv[3][1]) * sizey - transy);
- glTexCoord2f((tface->uv[3][0] - centerx) * sizex + transx, (tface->uv[3][1] - centery) * sizey + transy);
- if(col) BL_spack(col[3]);
- // glVertex3fv(v4);
- glVertex3f(sizex * v4[0] + movex, sizey * v4[1] + movey, v4[2]);
- }
- glEnd();
-
- glTranslatef(advance, 0.0, 0.0);
- }
- glPopMatrix();
-
- }
+ glPushMatrix();
}
-
-RAS_IPolyMaterial* GPC_RenderTools::CreateBlenderPolyMaterial(
- const STR_String &texname,
- bool ba,const STR_String& matname,int tile,int tilexrep,int tileyrep,int mode,bool transparant, bool zsort,
- int lightlayer,bool bIsTriangle,void* clientobject,void* tface)
+void GPC_RenderTools::PopMatrix()
{
- assert(!"Deprecated");
-/* return new GPC_PolygonMaterial(texname, ba,matname,tile,tilexrep,tileyrep,
- mode,transparant,zsort,lightlayer,bIsTriangle,clientobject,tface);
- */
- return NULL;
+ glPopMatrix();
}
-int GPC_RenderTools::applyLights(int objectlayer)
+int GPC_RenderTools::applyLights(int objectlayer, const MT_Transform& viewmat)
{
-// taken from blender source, incompatibility between Blender Object / GameObject
-
- int count;
+ // taken from blender source, incompatibility between Blender Object / GameObject
+ float glviewmat[16];
+ unsigned int count;
float vec[4];
-
+
vec[3]= 1.0;
for(count=0; count<m_numgllights; count++)
@@ -371,23 +403,20 @@ int GPC_RenderTools::applyLights(int objectlayer)
//std::vector<struct RAS_LightObject*> m_lights;
std::vector<struct RAS_LightObject*>::iterator lit = m_lights.begin();
+ viewmat.getValue(glviewmat);
+ glPushMatrix();
+ glLoadMatrixf(glviewmat);
for (lit = m_lights.begin(), count = 0; !(lit==m_lights.end()) && count < m_numgllights; ++lit)
{
RAS_LightObject* lightdata = (*lit);
if (lightdata->m_layer & objectlayer)
{
-
- glPushMatrix();
- glLoadMatrixf(m_viewmat);
-
-
vec[0] = (*(lightdata->m_worldmatrix))(0,3);
vec[1] = (*(lightdata->m_worldmatrix))(1,3);
vec[2] = (*(lightdata->m_worldmatrix))(2,3);
vec[3] = 1;
-
if(lightdata->m_type==RAS_LightObject::LIGHT_SUN) {
vec[0] = (*(lightdata->m_worldmatrix))(0,2);
@@ -443,141 +472,16 @@ int GPC_RenderTools::applyLights(int objectlayer)
}
glLightfv((GLenum)(GL_LIGHT0+count), GL_SPECULAR, vec);
glEnable((GLenum)(GL_LIGHT0+count));
-
- count++;
- glPopMatrix();
+ count++;
}
}
+ glPopMatrix();
return count;
}
-void GPC_RenderTools::SetClientObject(void* obj)
-{
- if (m_clientobject != obj)
- {
- if (obj == NULL || !((KX_GameObject*)obj)->IsNegativeScaling())
- {
- glFrontFace(GL_CCW);
- } else
- {
- glFrontFace(GL_CW);
- }
- m_clientobject = obj;
- m_modified = true;
- }
-}
-
-bool GPC_RenderTools::RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data)
-{
- double* const oglmatrix = (double* const) data;
- MT_Point3 resultpoint(result->m_hitPoint);
- MT_Vector3 resultnormal(result->m_hitNormal);
- MT_Vector3 left(oglmatrix[0],oglmatrix[1],oglmatrix[2]);
- MT_Vector3 dir = -(left.cross(resultnormal)).safe_normalized();
- left = (dir.cross(resultnormal)).safe_normalized();
- // for the up vector, we take the 'resultnormal' returned by the physics
-
- double maat[16]={
- left[0], left[1], left[2], 0,
- dir[0], dir[1], dir[2], 0,
- resultnormal[0],resultnormal[1],resultnormal[2], 0,
- 0, 0, 0, 1};
- glTranslated(resultpoint[0],resultpoint[1],resultpoint[2]);
- //glMultMatrixd(oglmatrix);
- glMultMatrixd(maat);
- return true;
-}
-
-void GPC_RenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmatrix,int objectdrawmode )
-{
- if (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED ||
- objectdrawmode & RAS_IPolyMaterial::BILLBOARD_AXISALIGNED)
- {
- // rotate the billboard/halo
- //page 360/361 3D Game Engine Design, David Eberly for a discussion
- // on screen aligned and axis aligned billboards
- // assumed is that the preprocessor transformed all billboard polygons
- // so that their normal points into the positive x direction (1.0 , 0.0 , 0.0)
- // when new parenting for objects is done, this rotation
- // will be moved into the object
-
- MT_Point3 objpos (oglmatrix[12],oglmatrix[13],oglmatrix[14]);
- MT_Point3 campos = rasty->GetCameraPosition();
- MT_Vector3 dir = (campos - objpos).safe_normalized();
- MT_Vector3 up(0,0,1.0);
-
- KX_GameObject* gameobj = (KX_GameObject*) this->m_clientobject;
- // get scaling of halo object
- MT_Vector3 size = gameobj->GetSGNode()->GetLocalScale();
-
- bool screenaligned = (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED)!=0;//false; //either screen or axisaligned
- if (screenaligned)
- {
- up = (up - up.dot(dir) * dir).safe_normalized();
- } else
- {
- dir = (dir - up.dot(dir)*up).safe_normalized();
- }
-
- MT_Vector3 left = dir.normalized();
- dir = (left.cross(up)).normalized();
-
- // we have calculated the row vectors, now we keep
- // local scaling into account:
-
- left *= size[0];
- dir *= size[1];
- up *= size[2];
- double maat[16]={
- left[0], left[1],left[2], 0,
- dir[0], dir[1],dir[2],0,
- up[0],up[1],up[2],0,
- 0,0,0,1};
- glTranslated(objpos[0],objpos[1],objpos[2]);
- glMultMatrixd(maat);
-
- } else
- {
- if (objectdrawmode & RAS_IPolyMaterial::SHADOW)
- {
- // shadow must be cast to the ground, physics system needed here!
- MT_Point3 frompoint(oglmatrix[12],oglmatrix[13],oglmatrix[14]);
- KX_GameObject *gameobj = (KX_GameObject*) this->m_clientobject;
- MT_Vector3 direction = MT_Vector3(0,0,-1);
-
- direction.normalize();
- direction *= 100000;
-
- MT_Point3 topoint = frompoint + direction;
-
- KX_Scene* kxscene = (KX_Scene*) m_auxilaryClientInfo;
- PHY_IPhysicsEnvironment* physics_environment = kxscene->GetPhysicsEnvironment();
- KX_IPhysicsController* physics_controller = gameobj->GetPhysicsController();
-
- KX_GameObject *parent = gameobj->GetParent();
- if (!physics_controller && parent)
- physics_controller = parent->GetPhysicsController();
- if (parent)
- parent->Release();
-
- KX_RayCast::Callback<GPC_RenderTools> callback(this, physics_controller, oglmatrix);
- if (!KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback))
- {
- // couldn't find something to cast the shadow on...
- glMultMatrixd(oglmatrix);
- }
- } else
- {
-
- // 'normal' object
- glMultMatrixd(oglmatrix);
- }
- }
-}
-
void GPC_RenderTools::MotionBlur(RAS_IRasterizer* rasterizer)
{
int state = rasterizer->GetMotionBlurState();
@@ -608,7 +512,6 @@ void GPC_RenderTools::Update2DFilter(vector<STR_String>& propNames, void* gameOb
void GPC_RenderTools::Render2DFilters(RAS_ICanvas* canvas)
{
- m_filtermanager.RenderFilters( canvas);
+ m_filtermanager.RenderFilters(canvas);
}
-unsigned int GPC_RenderTools::m_numgllights;
diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.h b/source/gameengine/GamePlayer/common/GPC_RenderTools.h
index 9f70f67caf2..382956e73ea 100644
--- a/source/gameengine/GamePlayer/common/GPC_RenderTools.h
+++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.h
@@ -31,11 +31,11 @@
#define __GPC_RENDERTOOLS_H
#ifdef WIN32
- #include <windows.h>
+// don't show stl-warnings
+#pragma warning (disable:4786)
+#include <windows.h>
#endif // WIN32
-#include "GL/glew.h"
-
#include "RAS_IRenderTools.h"
#include "BMF_Api.h"
@@ -43,100 +43,52 @@
struct KX_ClientObjectInfo;
class KX_RayCast;
+/* BlenderRenderTools are a set of tools to apply 2D/3D graphics effects, which
+ * are not part of the (polygon) Rasterizer. Effects like 2D text, 3D (polygon)
+ * text, lighting.
+ *
+ * Most of this code is duplicated in KX_BlenderRenderTools, so this should be
+ * moved to some common location to avoid duplication. */
+
class GPC_RenderTools : public RAS_IRenderTools
{
+ int m_lastlightlayer;
+ bool m_lastlighting;
+ static unsigned int m_numgllights;
+
+ BMF_Font* m_font;
+
public:
- GPC_RenderTools();
- virtual ~GPC_RenderTools();
-
- virtual void EndFrame(RAS_IRasterizer* rasty);
- virtual void BeginFrame(RAS_IRasterizer* rasty);
-
- void DisableOpenGLLights()
- {
- glDisable(GL_LIGHTING);
- glDisable(GL_COLOR_MATERIAL);
- }
-
- void EnableOpenGLLights();
-
- int ProcessLighting(int layer);
-
- void Perspective(int a, int width, int height, float mat[4][4], float viewmat[4][4])
- {
- if(a== 0)
- {
- glMatrixMode(GL_PROJECTION);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- else
- {
- if(a== 1)
- {
- glMatrixMode(GL_PROJECTION);
- glMatrixMode(GL_MODELVIEW);
- }
- }
- }
-
- /**
- * @attention mode is ignored here
- */
- virtual void RenderText2D(
- RAS_TEXT_RENDER_MODE mode,
- const char* text,
- int xco,
- int yco,
- int width,
- int height);
-
- /**
- * Renders text into a (series of) polygon(s), using a texture font,
- * Each character consists of one polygon (one quad or two triangles)
- */
- virtual void RenderText(
- int mode,
- RAS_IPolyMaterial* polymat,
- float v1[3],
- float v2[3],
- float v3[3],
- float v4[3]);
-
- void Render(RAS_IRasterizer* rasty,double* oglmatrix,int objectdrawmode)
- {
- glPopMatrix();
- glPushMatrix();
- glMultMatrixd(oglmatrix);
- }
-
- void applyTransform(RAS_IRasterizer* rasty, double* oglmatrix, int objectdrawmode);
-
- virtual void PushMatrix()
- {
- glPushMatrix();
- }
-
- virtual void PopMatrix()
- {
- glPopMatrix();
- }
-
- virtual class RAS_IPolyMaterial* CreateBlenderPolyMaterial(
- const STR_String &texname,
- bool ba,
- const STR_String& matname,
- int tile,
- int tilexrep,int tileyrep,
- int mode,
- bool transparant,
- bool zsort,
- int lightlayer,
- bool bIsTriangle,
- void* clientobject,
- void* tface);
-
- int applyLights(int objectlayer);
+ GPC_RenderTools();
+ virtual ~GPC_RenderTools();
+
+ void EndFrame(RAS_IRasterizer* rasty);
+ void BeginFrame(RAS_IRasterizer* rasty);
+
+ void EnableOpenGLLights();
+ void DisableOpenGLLights();
+ void ProcessLighting(int layer, const MT_Transform& viewmat);
+
+ /* @attention mode is ignored here */
+ void RenderText2D(RAS_TEXT_RENDER_MODE mode,
+ const char* text,
+ int xco,
+ int yco,
+ int width,
+ int height);
+ void RenderText(int mode,
+ class RAS_IPolyMaterial* polymat,
+ float v1[3],
+ float v2[3],
+ float v3[3],
+ float v4[3],
+ int glattrib);
+
+ void applyTransform(RAS_IRasterizer* rasty, double* oglmatrix, int objectdrawmode);
+ int applyLights(int objectlayer, const MT_Transform& viewmat);
+
+ void PushMatrix();
+ void PopMatrix();
bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data);
bool NeedRayCast(KX_ClientObjectInfo* client) { return true; }
@@ -147,28 +99,7 @@ public:
virtual void Render2DFilters(RAS_ICanvas* canvas);
- virtual void SetClientObject(void* obj);
-
-protected:
- /**
- * Copied from KX_BlenderGL.cpp in KX_blenderhook
- */
- void BL_RenderText(
- int mode,
- const char* textstr,
- int textlen,
- struct MTFace* tface,
- unsigned int* col,
- float v1[3],float v2[3],float v3[3],float v4[3]);
- void BL_spack(unsigned int ucol)
- {
- char *cp = (char *)&ucol;
- glColor3ub(cp[3], cp[2], cp[1]);
- }
-
-
- BMF_Font* m_font;
- static unsigned int m_numgllights;
+ virtual void SetClientObject(RAS_IRasterizer *rasty, void* obj);
};
#endif // __GPC_RENDERTOOLS_H
diff --git a/source/gameengine/GamePlayer/common/Makefile b/source/gameengine/GamePlayer/common/Makefile
index 19d792ddbdb..6a12e659be6 100644
--- a/source/gameengine/GamePlayer/common/Makefile
+++ b/source/gameengine/GamePlayer/common/Makefile
@@ -43,6 +43,7 @@ CPPFLAGS += -I../../../blender/blenloader
CPPFLAGS += -I../../../blender/blenlib
CPPFLAGS += -I../../../blender/imbuf
CPPFLAGS += -I../../../blender/makesdna
+CPPFLAGS += -I../../../blender/gpu
CPPFLAGS += -I../../../kernel/gen_system
CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
@@ -72,10 +73,6 @@ CPPFLAGS += -I../../../gameengine/Rasterizer/RAS_OpenGLRasterizer
CPPFLAGS += -I../../../gameengine/Physics/Sumo
CPPFLAGS += -I../../../gameengine/Physics/common
-ifeq ($(WITH_BF_GLEXT),true)
- CPPFLAGS += -DWITH_GLEXT
-endif
-
###############################
SOURCEDIR = source/gameengine/GamePlayer/common
diff --git a/source/gameengine/GamePlayer/common/SConscript b/source/gameengine/GamePlayer/common/SConscript
index 3b2367d2592..30f20a670d3 100644
--- a/source/gameengine/GamePlayer/common/SConscript
+++ b/source/gameengine/GamePlayer/common/SConscript
@@ -8,7 +8,6 @@ source_files = ['bmfont.cpp',
'GPC_Engine.cpp',
'GPC_KeyboardDevice.cpp',
'GPC_MouseDevice.cpp',
- 'GPC_PolygonMaterial.cpp',
'GPC_RawImage.cpp',
'GPC_RawLoadDotBlendArray.cpp',
'GPC_RawLogoArrays.cpp',
@@ -46,6 +45,7 @@ incs = ['.',
'#source/gameengine/GamePlayer/ghost',
'#source/blender/misc',
'#source/blender/blenloader',
+ '#source/blender/gpu',
'#extern/glew/include']
#This is all plugin stuff!
diff --git a/source/gameengine/GamePlayer/common/unix/GPU_PolygonMaterial.h b/source/gameengine/GamePlayer/common/unix/GPU_PolygonMaterial.h
index fee729a84ac..e5ed7f39811 100644
--- a/source/gameengine/GamePlayer/common/unix/GPU_PolygonMaterial.h
+++ b/source/gameengine/GamePlayer/common/unix/GPU_PolygonMaterial.h
@@ -37,9 +37,9 @@ class GPU_PolygonMaterial : public BP_PolygonMaterial
public:
GPUPolygonMaterial(const STR_String& texname, bool ba,const STR_String& matname,
int tile, int tileXrep, int tileYrep, int mode, int transparant,
- int lightlayer,bool bIsTriangle,void* clientobject,void* tpage) :
+ int lightlayer,,void* tpage) :
BP_PolygonMaterial(texname, ba,matname, tile, tileXrep, tileYrep,
- mode, transparant, lightlayer, bIsTriangle, clientobject),
+ mode, transparant, lightlayer),
m_tface(tpage)
{
}
diff --git a/source/gameengine/GamePlayer/ghost/CMakeLists.txt b/source/gameengine/GamePlayer/ghost/CMakeLists.txt
index d9f0675001f..5e0ca93ac06 100644
--- a/source/gameengine/GamePlayer/ghost/CMakeLists.txt
+++ b/source/gameengine/GamePlayer/ghost/CMakeLists.txt
@@ -64,6 +64,7 @@ SET(INC
../../../../source/gameengine/GamePlayer/common
../../../../source/blender/misc
../../../../source/blender/blenloader
+ ../../../../source/blender/gpu
../../../../extern/solid
../../../../extern/glew/include
${PYTHON_INC}
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
index c56a6d0da23..a690beb9f38 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
@@ -38,6 +38,7 @@
#endif
#include "GL/glew.h"
+#include "GPU_extensions.h"
#include "GPG_Application.h"
@@ -104,9 +105,10 @@ static void frameTimerProc(GHOST_ITimerTask* task, GHOST_TUns64 time);
static GHOST_ISystem* fSystem = 0;
static const int kTimerFreq = 10;
-GPG_Application::GPG_Application(GHOST_ISystem* system, struct Main* maggie, STR_String startSceneName)
- : m_startSceneName(startSceneName),
- m_maggie(maggie),
+GPG_Application::GPG_Application(GHOST_ISystem* system)
+ : m_startSceneName(""),
+ m_startScene(0),
+ m_maggie(0),
m_exitRequested(0),
m_system(system),
m_mainWindow(0),
@@ -142,15 +144,16 @@ GPG_Application::~GPG_Application(void)
-bool GPG_Application::SetGameEngineData(struct Main* maggie, STR_String startSceneName)
+bool GPG_Application::SetGameEngineData(struct Main* maggie, Scene *scene)
{
bool result = false;
- if (maggie != NULL && startSceneName != "")
+ if (maggie != NULL && scene != NULL)
{
- G.scene = (Scene*)maggie->scene.first;
+ G.scene = scene;
m_maggie = maggie;
- m_startSceneName = startSceneName;
+ m_startSceneName = scene->id.name+2;
+ m_startScene = scene;
result = true;
}
@@ -480,7 +483,7 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
{
if (!m_engineInitialized)
{
- glewInit();
+ GPU_extensions_init();
bgl::InitExtensions(true);
// get and set the preferences
@@ -499,12 +502,18 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
bool fixed_framerate= (SYS_GetCommandLineInt(syshandle, "fixed_framerate", fixedFr) != 0);
bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
- bool useLists = (SYS_GetCommandLineInt(syshandle, "displaylists", G.fileflags & G_FILE_DIAPLAY_LISTS) != 0);
+ bool useLists = (SYS_GetCommandLineInt(syshandle, "displaylists", G.fileflags & G_FILE_DISPLAY_LISTS) != 0);
if(GLEW_ARB_multitexture && GLEW_VERSION_1_1) {
int gameflag =(G.fileflags & G_FILE_GAME_MAT);
m_blendermat = (SYS_GetCommandLineInt(syshandle, "blender_material", gameflag) != 0);
}
+
+ if(GPU_extensions_minimum_support()) {
+ int gameflag = (G.fileflags & G_FILE_GAME_MAT_GLSL);
+
+ m_blenderglslmat = (SYS_GetCommandLineInt(syshandle, "blender_glsl_material", gameflag) != 0);
+ }
// create the canvas, rasterizer and rendertools
m_canvas = new GPG_Canvas(window);
@@ -640,14 +649,15 @@ bool GPG_Application::startEngine(void)
m_mouse,
m_networkdevice,
m_audiodevice,
- startscenename);
+ startscenename,
+ m_startScene);
// some python things
PyObject* dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest);
m_ketsjiengine->SetPythonDictionary(dictionaryobject);
initRasterizer(m_rasterizer, m_canvas);
- PyObject *gameLogic = initGameLogic(startscene);
+ PyObject *gameLogic = initGameLogic(m_ketsjiengine, startscene);
PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module
initGameKeys();
initPythonConstraintBinding();
@@ -745,6 +755,8 @@ void GPG_Application::stopEngine()
void GPG_Application::exitEngine()
{
+ GPU_extensions_exit();
+
if (m_ketsjiengine)
{
stopEngine();
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.h b/source/gameengine/GamePlayer/ghost/GPG_Application.h
index 31f5eb75e52..5242a419808 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_Application.h
+++ b/source/gameengine/GamePlayer/ghost/GPG_Application.h
@@ -50,14 +50,15 @@ class GPG_Canvas;
class GPG_KeyboardDevice;
class GPG_System;
struct Main;
+struct Scene;
class GPG_Application : public GHOST_IEventConsumer
{
public:
- GPG_Application(GHOST_ISystem* system, struct Main* maggie, STR_String startSceneName);
+ GPG_Application(GHOST_ISystem* system);
~GPG_Application(void);
- bool SetGameEngineData(struct Main* maggie,STR_String startSceneName);
+ bool SetGameEngineData(struct Main* maggie, struct Scene* scene);
bool startWindow(STR_String& title, int windowLeft, int windowTop, int windowWidth, int windowHeight,
const bool stereoVisual, const int stereoMode);
bool startFullScreen(int width, int height, int bpp, int frequency, const bool stereoVisual, const int stereoMode);
@@ -123,6 +124,7 @@ protected:
/* The game data */
STR_String m_startSceneName;
+ struct Scene* m_startScene;
struct Main* m_maggie;
/* Exit state. */
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
index 26a85128025..cc781a38bbb 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
@@ -64,13 +64,15 @@ extern "C"
#ifdef __cplusplus
}
#endif // __cplusplus
+
+#include "GPU_draw.h"
+
/**********************************
* End Blender include block
**********************************/
#include "SYS_System.h"
#include "GPG_Application.h"
-#include "GPC_PolygonMaterial.h"
#include "GHOST_ISystem.h"
#include "RAS_IRasterizer.h"
@@ -282,7 +284,7 @@ int main(int argc, char** argv)
bool fullScreenParFound = false;
bool windowParFound = false;
bool closeConsole = true;
- RAS_IRasterizer::StereoMode stereomode;
+ RAS_IRasterizer::StereoMode stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
bool stereoWindow = false;
bool stereoParFound = false;
int windowLeft = 100;
@@ -525,8 +527,6 @@ int main(int argc, char** argv)
return 0;
}
- if (!stereoParFound) stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
-
#ifdef WIN32
if (scr_saver_mode != SCREEN_SAVER_MODE_CONFIGURATION)
#endif
@@ -539,7 +539,7 @@ int main(int argc, char** argv)
if (SYS_GetCommandLineInt(syshandle, "nomipmap", 0))
{
- GPC_PolygonMaterial::SetMipMappingEnabled(0);
+ GPU_set_mipmap(0);
}
// Create the system
@@ -561,7 +561,7 @@ int main(int argc, char** argv)
{
int exitcode = KX_EXIT_REQUEST_NO_REQUEST;
STR_String exitstring = "";
- GPG_Application app(system, NULL, exitstring);
+ GPG_Application app(system);
bool firstTimeRunning = true;
char *filename = get_filename(argc, argv);
char *titlename;
@@ -619,7 +619,7 @@ int main(int argc, char** argv)
#endif // WIN32
Main *maggie = bfd->main;
Scene *scene = bfd->curscene;
- char *startscenename = scene->id.name + 2;
+ G.main = maggie;
G.fileflags = bfd->fileflags;
//Seg Fault; icon.c gIcons == 0
@@ -661,7 +661,7 @@ int main(int argc, char** argv)
}
// GPG_Application app (system, maggie, startscenename);
- app.SetGameEngineData(maggie, startscenename);
+ app.SetGameEngineData(maggie, scene);
if (firstTimeRunning)
{
diff --git a/source/gameengine/GamePlayer/ghost/Makefile b/source/gameengine/GamePlayer/ghost/Makefile
index 13940ac3fc8..0b187791734 100644
--- a/source/gameengine/GamePlayer/ghost/Makefile
+++ b/source/gameengine/GamePlayer/ghost/Makefile
@@ -69,6 +69,7 @@ CPPFLAGS += -I../../../blender/blenloader
CPPFLAGS += -I../../../blender/imbuf
CPPFLAGS += -I../../../blender/makesdna
CPPFLAGS += -I../../../blender/readblenfile
+CPPFLAGS += -I../../../blender/gpu
CPPFLAGS += -I../../../gameengine/BlenderRoutines
@@ -80,7 +81,3 @@ CPPFLAGS += -I$(NAN_STRING)/include
CPPFLAGS += -I$(NAN_GHOST)/include
CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION)
-ifeq ($(WITH_BF_GLEXT),true)
- CPPFLAGS += -DWITH_GLEXT
-endif
-
diff --git a/source/gameengine/GamePlayer/ghost/SConscript b/source/gameengine/GamePlayer/ghost/SConscript
index f3cce6c7443..33cf07b6211 100644
--- a/source/gameengine/GamePlayer/ghost/SConscript
+++ b/source/gameengine/GamePlayer/ghost/SConscript
@@ -40,6 +40,7 @@ incs = ['.',
'#source/gameengine/GamePlayer/common',
'#source/blender/misc',
'#source/blender/blenloader',
+ '#source/blender/gpu',
'#extern/glew/include']
incs += Split(env['BF_PYTHON_INC'])
@@ -48,8 +49,5 @@ cflags = []
if env['OURPLATFORM']=='win32-vc':
cflags = ['/GR']
-if env['WITH_BF_GLEXT'] == 1:
- env['CPPFLAGS'].append('-DWITH_GLEXT')
-
env.BlenderLib (libname='gp_ghost', sources=source_files, includes = incs, defines = [], libtype='player',priority=0, compileflags=cflags)
diff --git a/source/gameengine/Ketsji/BL_BlenderShader.cpp b/source/gameengine/Ketsji/BL_BlenderShader.cpp
index a9a0771936c..13b8235687b 100644
--- a/source/gameengine/Ketsji/BL_BlenderShader.cpp
+++ b/source/gameengine/Ketsji/BL_BlenderShader.cpp
@@ -9,108 +9,64 @@
#include "BL_BlenderShader.h"
#include "BL_Material.h"
-#ifdef BLENDER_GLSL
#include "GPU_extensions.h"
#include "GPU_material.h"
-#endif
#include "RAS_BucketManager.h"
#include "RAS_MeshObject.h"
#include "RAS_IRasterizer.h"
- /* this is evil, but we need the scene to create materials with
- * lights from the correct scene .. */
-static struct Scene *GetSceneForName(const STR_String& scenename)
-{
- Scene *sce;
-
- for (sce= (Scene*)G.main->scene.first; sce; sce= (Scene*)sce->id.next)
- if (scenename == (sce->id.name+2))
- return sce;
-
- return (Scene*)G.main->scene.first;
-}
-
-bool BL_BlenderShader::Ok()
-{
-#ifdef BLENDER_GLSL
- VerifyShader();
-
- return (mMat && mMat->gpumaterial);
-#else
- return 0;
-#endif
-}
-
BL_BlenderShader::BL_BlenderShader(KX_Scene *scene, struct Material *ma, int lightlayer)
:
-#ifdef BLENDER_GLSL
mScene(scene),
mMat(ma),
- mGPUMat(NULL),
-#endif
- mBound(false),
mLightLayer(lightlayer)
{
-#ifdef BLENDER_GLSL
- mBlenderScene = GetSceneForName(scene->GetName());
+ mBlenderScene = scene->GetBlenderScene(); //GetSceneForName(scene->GetName());
mBlendMode = GPU_BLEND_SOLID;
- if(mMat) {
+ if(mMat)
GPU_material_from_blender(mBlenderScene, mMat);
- mGPUMat = mMat->gpumaterial;
- }
-#endif
}
BL_BlenderShader::~BL_BlenderShader()
{
-#ifdef BLENDER_GLSL
- if(mMat && mMat->gpumaterial)
- GPU_material_unbind(mMat->gpumaterial);
-#endif
+ if(mMat && GPU_material_from_blender(mBlenderScene, mMat))
+ GPU_material_unbind(GPU_material_from_blender(mBlenderScene, mMat));
}
-bool BL_BlenderShader::VerifyShader()
+bool BL_BlenderShader::Ok()
{
-#ifdef BLENDER_GLSL
- if(mMat && !mMat->gpumaterial)
- GPU_material_from_blender(mBlenderScene, mMat);
+ return VerifyShader();
+}
- mGPUMat = mMat->gpumaterial;
-
- return (mMat && mGPUMat);
-#else
- return false;
-#endif
+bool BL_BlenderShader::VerifyShader()
+{
+ if(mMat)
+ return (GPU_material_from_blender(mBlenderScene, mMat) != 0);
+ else
+ return false;
}
-void BL_BlenderShader::SetProg(bool enable)
+void BL_BlenderShader::SetProg(bool enable, double time)
{
-#ifdef BLENDER_GLSL
if(VerifyShader()) {
- if(enable) {
- GPU_material_bind(mGPUMat, mLightLayer);
- mBound = true;
- }
- else {
- GPU_material_unbind(mGPUMat);
- mBound = false;
- }
+ if(enable)
+ GPU_material_bind(GPU_material_from_blender(mBlenderScene, mMat), mLightLayer, time);
+ else
+ GPU_material_unbind(GPU_material_from_blender(mBlenderScene, mMat));
}
-#endif
}
int BL_BlenderShader::GetAttribNum()
{
-#ifdef BLENDER_GLSL
GPUVertexAttribs attribs;
int i, enabled = 0;
if(!VerifyShader())
return enabled;
- GPU_material_vertex_attributes(mGPUMat, &attribs);
+ GPU_material_vertex_attributes(GPU_material_from_blender(mBlenderScene, mMat), &attribs);
for(i = 0; i < attribs.totlayer; i++)
if(attribs.layer[i].glindex+1 > enabled)
@@ -120,24 +76,23 @@ int BL_BlenderShader::GetAttribNum()
enabled = BL_MAX_ATTRIB;
return enabled;
-#else
- return 0;
-#endif
}
void BL_BlenderShader::SetAttribs(RAS_IRasterizer* ras, const BL_Material *mat)
{
-#ifdef BLENDER_GLSL
GPUVertexAttribs attribs;
+ GPUMaterial *gpumat;
int i, attrib_num;
ras->SetAttribNum(0);
if(!VerifyShader())
return;
+
+ gpumat = GPU_material_from_blender(mBlenderScene, mMat);
if(ras->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED) {
- GPU_material_vertex_attributes(mGPUMat, &attribs);
+ GPU_material_vertex_attributes(gpumat, &attribs);
attrib_num = GetAttribNum();
ras->SetTexCoordNum(0);
@@ -168,44 +123,37 @@ void BL_BlenderShader::SetAttribs(RAS_IRasterizer* ras, const BL_Material *mat)
else
ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_DISABLE, attribs.layer[i].glindex);
}
-
- ras->EnableTextures(true);
}
- else
- ras->EnableTextures(false);
-#endif
}
-void BL_BlenderShader::Update( const KX_MeshSlot & ms, RAS_IRasterizer* rasty )
+void BL_BlenderShader::Update(const RAS_MeshSlot & ms, RAS_IRasterizer* rasty )
{
-#ifdef BLENDER_GLSL
float obmat[4][4], viewmat[4][4], viewinvmat[4][4], obcol[4];
+ GPUMaterial *gpumat;
- VerifyShader();
+ gpumat = GPU_material_from_blender(mBlenderScene, mMat);
- if(!mGPUMat) // || !mBound)
+ if(!gpumat || !GPU_material_bound(gpumat))
return;
MT_Matrix4x4 model;
model.setValue(ms.m_OpenGLMatrix);
- MT_Matrix4x4 view;
- rasty->GetViewMatrix(view);
+ const MT_Matrix4x4& view = rasty->GetViewMatrix();
+ const MT_Matrix4x4& viewinv = rasty->GetViewInvMatrix();
+ // note: getValue gives back column major as needed by OpenGL
model.getValue((float*)obmat);
view.getValue((float*)viewmat);
-
- view.invert();
- view.getValue((float*)viewinvmat);
+ viewinv.getValue((float*)viewinvmat);
if(ms.m_bObjectColor)
ms.m_RGBAcolor.getValue((float*)obcol);
else
obcol[0]= obcol[1]= obcol[2]= obcol[3]= 1.0f;
- GPU_material_bind_uniforms(mGPUMat, obmat, viewmat, viewinvmat, obcol);
+ GPU_material_bind_uniforms(gpumat, obmat, viewmat, viewinvmat, obcol);
- mBlendMode = GPU_material_blend_mode(mGPUMat, obcol);
-#endif
+ mBlendMode = GPU_material_blend_mode(gpumat, obcol);
}
int BL_BlenderShader::GetBlendMode()
@@ -215,12 +163,8 @@ int BL_BlenderShader::GetBlendMode()
bool BL_BlenderShader::Equals(BL_BlenderShader *blshader)
{
-#ifdef BLENDER_GLSL
/* to avoid unneeded state switches */
- return (blshader && mGPUMat == blshader->mGPUMat && mLightLayer == blshader->mLightLayer);
-#else
- return true;
-#endif
+ return (blshader && mMat == blshader->mMat && mLightLayer == blshader->mLightLayer);
}
// eof
diff --git a/source/gameengine/Ketsji/BL_BlenderShader.h b/source/gameengine/Ketsji/BL_BlenderShader.h
index da9765dafa4..5c1f59f94ad 100644
--- a/source/gameengine/Ketsji/BL_BlenderShader.h
+++ b/source/gameengine/Ketsji/BL_BlenderShader.h
@@ -2,9 +2,7 @@
#ifndef __BL_GPUSHADER_H__
#define __BL_GPUSHADER_H__
-#ifdef BLENDER_GLSL
#include "GPU_material.h"
-#endif
#include "MT_Matrix4x4.h"
#include "MT_Matrix3x3.h"
@@ -29,13 +27,9 @@ class BL_Material;
class BL_BlenderShader
{
private:
-#ifdef BLENDER_GLSL
KX_Scene *mScene;
struct Scene *mBlenderScene;
struct Material *mMat;
- GPUMaterial *mGPUMat;
-#endif
- bool mBound;
int mLightLayer;
int mBlendMode;
@@ -46,11 +40,11 @@ public:
virtual ~BL_BlenderShader();
bool Ok();
- void SetProg(bool enable);
+ void SetProg(bool enable, double time=0.0);
int GetAttribNum();
void SetAttribs(class RAS_IRasterizer* ras, const BL_Material *mat);
- void Update(const class KX_MeshSlot & ms, class RAS_IRasterizer* rasty);
+ void Update(const class RAS_MeshSlot & ms, class RAS_IRasterizer* rasty);
int GetBlendMode();
bool Equals(BL_BlenderShader *blshader);
diff --git a/source/gameengine/Ketsji/BL_Material.h b/source/gameengine/Ketsji/BL_Material.h
index dcb66ea2579..0eaa234566c 100644
--- a/source/gameengine/Ketsji/BL_Material.h
+++ b/source/gameengine/Ketsji/BL_Material.h
@@ -18,9 +18,9 @@ struct EnvMap;
this will default to users available units
to build with more available, just increment this value
although the more you add the slower the search time will be.
- we will go for three, which should be enough
+ we will go for eight, which should be enough
*/
-#define MAXTEX 3 //match in RAS_TexVert & RAS_OpenGLRasterizer
+#define MAXTEX 8 //match in RAS_TexVert & RAS_OpenGLRasterizer
// different mapping modes
class BL_Mapping
@@ -139,7 +139,7 @@ enum BL_ras_mode
COLLIDER=2,
ZSORT=4,
ALPHA=8,
- TRIANGLE=16,
+ // TRIANGLE=16,
USE_LIGHT=32,
WIRE=64
};
diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp
index 57d0fe4140f..f28d3fa2912 100644
--- a/source/gameengine/Ketsji/BL_Shader.cpp
+++ b/source/gameengine/Ketsji/BL_Shader.cpp
@@ -433,7 +433,7 @@ void BL_Shader::SetProg(bool enable)
}
}
-void BL_Shader::Update( const KX_MeshSlot & ms, RAS_IRasterizer* rasty )
+void BL_Shader::Update( const RAS_MeshSlot & ms, RAS_IRasterizer* rasty )
{
if(!Ok() || !mPreDef.size())
return;
@@ -445,8 +445,7 @@ void BL_Shader::Update( const KX_MeshSlot & ms, RAS_IRasterizer* rasty )
{
MT_Matrix4x4 model;
model.setValue(ms.m_OpenGLMatrix);
- MT_Matrix4x4 view;
- rasty->GetViewMatrix(view);
+ const MT_Matrix4x4& view = rasty->GetViewMatrix();
if(mAttr==SHD_TANGENT)
ms.m_mesh->SetMeshModified(true);
@@ -525,13 +524,15 @@ void BL_Shader::Update( const KX_MeshSlot & ms, RAS_IRasterizer* rasty )
}
case VIEWMATRIX_INVERSE:
{
- view.invert();
+ MT_Matrix4x4 viewinv = view;
+ viewinv.invert();
SetUniform(uni->mLoc, view);
break;
}
case VIEWMATRIX_INVERSETRANSPOSE:
{
- view.invert();
+ MT_Matrix4x4 viewinv = view;
+ viewinv.invert();
SetUniform(uni->mLoc, view, true);
break;
}
@@ -670,6 +671,7 @@ void BL_Shader::SetUniform(int uniform, const MT_Matrix4x4& vec, bool transpose)
)
{
float value[16];
+ // note: getValue gives back column major as needed by OpenGL
vec.getValue(value);
glUniformMatrix4fvARB(uniform, 1, transpose?GL_TRUE:GL_FALSE, value);
}
diff --git a/source/gameengine/Ketsji/BL_Shader.h b/source/gameengine/Ketsji/BL_Shader.h
index 8f303454087..c7fae31ba03 100644
--- a/source/gameengine/Ketsji/BL_Shader.h
+++ b/source/gameengine/Ketsji/BL_Shader.h
@@ -177,7 +177,7 @@ public:
void UnloadShader();
// Update predefined uniforms each render call
- void Update(const class KX_MeshSlot & ms, class RAS_IRasterizer* rasty);
+ void Update(const class RAS_MeshSlot & ms, class RAS_IRasterizer* rasty);
//// Set sampler units (copied)
//void InitializeSampler(int unit, BL_Texture* texture );
diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt
index be009d94701..58411f6d25e 100644
--- a/source/gameengine/Ketsji/CMakeLists.txt
+++ b/source/gameengine/Ketsji/CMakeLists.txt
@@ -69,6 +69,7 @@ SET(INC
../../../intern/SoundSystem
../../../source/blender/misc
../../../source/blender/blenloader
+ ../../../source/blender/gpu
../../../extern/bullet2/src
../../../extern/solid
../../../extern/glew/include
diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
index a67e5b26667..f92200780d5 100644
--- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
+++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
@@ -19,13 +19,12 @@
#include "MT_Vector4.h"
#include "MT_Matrix4x4.h"
+#include "RAS_BucketManager.h"
#include "RAS_MeshObject.h"
#include "RAS_IRasterizer.h"
#include "RAS_OpenGLRasterizer/RAS_GLExtensionManager.h"
-extern "C" {
-#include "BDR_drawmesh.h"
-}
+#include "GPU_draw.h"
#include "STR_HashedString.h"
@@ -48,7 +47,6 @@ KX_BlenderMaterial::KX_BlenderMaterial(
BL_Material *data,
bool skin,
int lightlayer,
- void *clientobject,
PyTypeObject *T
)
: PyObjectPlus(T),
@@ -62,9 +60,7 @@ KX_BlenderMaterial::KX_BlenderMaterial(
data->transp,
((data->ras_mode &ALPHA)!=0),
((data->ras_mode &ZSORT)!=0),
- lightlayer,
- ((data->ras_mode &TRIANGLE)!=0),
- clientobject
+ lightlayer
),
mMaterial(data),
mShader(0),
@@ -78,9 +74,10 @@ KX_BlenderMaterial::KX_BlenderMaterial(
{
// --------------------------------
// RAS_IPolyMaterial variables...
- m_flag |=RAS_BLENDERMAT;
- m_flag |=(mMaterial->IdMode>=ONETEX)?RAS_MULTITEX:0;
- m_flag |=(mMaterial->ras_mode & USE_LIGHT)!=0?RAS_MULTILIGHT:0;
+ m_flag |= RAS_BLENDERMAT;
+ m_flag |= (mMaterial->IdMode>=ONETEX)? RAS_MULTITEX: 0;
+ m_flag |= ((mMaterial->ras_mode & USE_LIGHT)!=0)? RAS_MULTILIGHT: 0;
+ m_flag |= (mMaterial->glslmat)? RAS_BLENDERGLSL: 0;
// figure max
int enabled = mMaterial->num_enabled;
@@ -97,7 +94,7 @@ KX_BlenderMaterial::KX_BlenderMaterial(
mMaterial->blend_mode[i]
);
}
- m_multimode += mMaterial->IdMode+mMaterial->ras_mode;
+ m_multimode += mMaterial->IdMode+ (mMaterial->ras_mode & ~(COLLIDER|USE_LIGHT));
}
@@ -204,7 +201,7 @@ void KX_BlenderMaterial::OnExit()
}
if( mMaterial->tface )
- set_tpage(mMaterial->tface);
+ GPU_set_tpage(mMaterial->tface);
}
@@ -256,25 +253,28 @@ void KX_BlenderMaterial::setShaderData( bool enable, RAS_IRasterizer *ras)
void KX_BlenderMaterial::setBlenderShaderData( bool enable, RAS_IRasterizer *ras)
{
if( !enable || !mBlenderShader->Ok() ) {
+ ras->SetBlendingMode(TF_SOLID);
+
// frame cleanup.
if(mLastBlenderShader) {
mLastBlenderShader->SetProg(false);
mLastBlenderShader= NULL;
}
+ else
+ BL_Texture::DisableAllTextures();
- ras->SetBlendingMode(TF_SOLID);
- BL_Texture::DisableAllTextures();
return;
}
if(!mBlenderShader->Equals(mLastBlenderShader)) {
ras->SetBlendingMode(mMaterial->transp);
- BL_Texture::DisableAllTextures();
if(mLastBlenderShader)
mLastBlenderShader->SetProg(false);
+ else
+ BL_Texture::DisableAllTextures();
- mBlenderShader->SetProg(true);
+ mBlenderShader->SetProg(true, ras->GetTime());
mLastBlenderShader= mBlenderShader;
}
}
@@ -354,21 +354,22 @@ KX_BlenderMaterial::ActivatShaders(
if (GetCachingInfo() != cachingInfo) {
if (!cachingInfo)
- tmp->setShaderData( false, rasty);
+ tmp->setShaderData(false, rasty);
cachingInfo = GetCachingInfo();
if(rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED)
- tmp->setShaderData( true, rasty);
+ tmp->setShaderData(true, rasty);
else
- tmp->setShaderData( false, rasty);
+ tmp->setShaderData(false, rasty);
if(mMaterial->mode & RAS_IRasterizer::KX_TWOSIDE)
rasty->SetCullFace(false);
else
rasty->SetCullFace(true);
- if (((mMaterial->ras_mode &WIRE)!=0) || mMaterial->mode & RAS_IRasterizer::KX_LINES)
+ if (((mMaterial->ras_mode &WIRE)!=0) || (mMaterial->mode & RAS_IRasterizer::KX_LINES) ||
+ (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME))
{
if((mMaterial->ras_mode &WIRE)!=0)
rasty->SetCullFace(false);
@@ -394,31 +395,24 @@ KX_BlenderMaterial::ActivateBlenderShaders(
mLastShader= NULL;
}
- // reset...
- if(tmp->mMaterial->IsShared())
- cachingInfo =0;
-
if (GetCachingInfo() != cachingInfo) {
if (!cachingInfo)
tmp->setBlenderShaderData(false, rasty);
cachingInfo = GetCachingInfo();
- if(rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED) {
+ if(rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED)
tmp->setBlenderShaderData(true, rasty);
- rasty->EnableTextures(true);
- }
- else {
+ else
tmp->setBlenderShaderData(false, rasty);
- rasty->EnableTextures(false);
- }
if(mMaterial->mode & RAS_IRasterizer::KX_TWOSIDE)
rasty->SetCullFace(false);
else
rasty->SetCullFace(true);
- if (((mMaterial->ras_mode &WIRE)!=0) || mMaterial->mode & RAS_IRasterizer::KX_LINES)
+ if (((mMaterial->ras_mode & WIRE)!=0) || (mMaterial->mode & RAS_IRasterizer::KX_LINES) ||
+ (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME))
{
if((mMaterial->ras_mode &WIRE)!=0)
rasty->SetCullFace(false);
@@ -426,10 +420,10 @@ KX_BlenderMaterial::ActivateBlenderShaders(
}
else
rasty->SetLines(false);
- }
- ActivatGLMaterials(rasty);
- mBlenderShader->SetAttribs(rasty, mMaterial);
+ ActivatGLMaterials(rasty);
+ mBlenderShader->SetAttribs(rasty, mMaterial);
+ }
}
void
@@ -466,7 +460,8 @@ KX_BlenderMaterial::ActivateMat(
else
rasty->SetCullFace(true);
- if (((mMaterial->ras_mode &WIRE)!=0) || mMaterial->mode & RAS_IRasterizer::KX_LINES)
+ if (((mMaterial->ras_mode &WIRE)!=0) || (mMaterial->mode & RAS_IRasterizer::KX_LINES) ||
+ (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME))
{
if((mMaterial->ras_mode &WIRE)!=0)
rasty->SetCullFace(false);
@@ -486,12 +481,10 @@ KX_BlenderMaterial::Activate(
TCachingInfo& cachingInfo
)const
{
- bool dopass = false;
- if( GLEW_ARB_shader_objects && ( mShader && mShader->Ok() ) ) {
- if( (mPass++) < mShader->getNumPass() ) {
+ if(GLEW_ARB_shader_objects && (mShader && mShader->Ok())) {
+ if((mPass++) < mShader->getNumPass() ) {
ActivatShaders(rasty, cachingInfo);
- dopass = true;
- return dopass;
+ return true;
}
else {
if(mShader == mLastShader) {
@@ -499,36 +492,29 @@ KX_BlenderMaterial::Activate(
mLastShader = NULL;
}
mPass = 0;
- dopass = false;
- return dopass;
+ return false;
}
}
- else if( GLEW_ARB_shader_objects && ( mBlenderShader && mBlenderShader->Ok() ) ) {
- if( (mPass++) == 0 ) {
+ else if( GLEW_ARB_shader_objects && (mBlenderShader && mBlenderShader->Ok() ) ) {
+ if(mPass++ == 0) {
ActivateBlenderShaders(rasty, cachingInfo);
- dopass = true;
- return dopass;
+ return true;
}
else {
mPass = 0;
- dopass = false;
- return dopass;
+ return false;
}
}
else {
- switch (mPass++)
- {
- case 0:
- ActivateMat(rasty, cachingInfo);
- dopass = true;
- break;
- default:
- mPass = 0;
- dopass = false;
- break;
+ if(mPass++ == 0) {
+ ActivateMat(rasty, cachingInfo);
+ return true;
+ }
+ else {
+ mPass = 0;
+ return false;
}
}
- return dopass;
}
bool KX_BlenderMaterial::UsesLighting(RAS_IRasterizer *rasty) const
@@ -536,14 +522,15 @@ bool KX_BlenderMaterial::UsesLighting(RAS_IRasterizer *rasty) const
if(!RAS_IPolyMaterial::UsesLighting(rasty))
return false;
- if(mShader && mShader->Ok());
+ if(mShader && mShader->Ok())
+ return true;
else if(mBlenderShader && mBlenderShader->Ok())
return false;
-
- return true;
+ else
+ return true;
}
-void KX_BlenderMaterial::ActivateMeshSlot(const KX_MeshSlot & ms, RAS_IRasterizer* rasty) const
+void KX_BlenderMaterial::ActivateMeshSlot(const RAS_MeshSlot & ms, RAS_IRasterizer* rasty) const
{
if(mShader && GLEW_ARB_shader_objects) {
mShader->Update(ms, rasty);
@@ -554,7 +541,7 @@ void KX_BlenderMaterial::ActivateMeshSlot(const KX_MeshSlot & ms, RAS_IRasterize
mBlenderShader->Update(ms, rasty);
/* we do blend modes here, because they can change per object
- * with the same material due to obcolor */
+ * with the same material due to obcolor/obalpha */
blendmode = mBlenderShader->GetBlendMode();
if((blendmode == TF_SOLID || blendmode == TF_ALPHA) && mMaterial->transp != TF_SOLID)
blendmode = mMaterial->transp;
@@ -633,11 +620,7 @@ void KX_BlenderMaterial::ActivateTexGen(RAS_IRasterizer *ras) const
else
ras->SetTexCoord(RAS_IRasterizer::RAS_TEXCO_DISABLE, i);
}
-
- ras->EnableTextures(true);
}
- else
- ras->EnableTextures(false);
}
void KX_BlenderMaterial::setTexMatrixData(int i)
@@ -712,8 +695,7 @@ void KX_BlenderMaterial::setObjectMatrixData(int i, RAS_IRasterizer *ras)
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
- MT_Matrix4x4 mvmat;
- ras->GetViewMatrix(mvmat);
+ const MT_Matrix4x4& mvmat = ras->GetViewMatrix();
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
@@ -835,7 +817,9 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()")
}
if(mShader && !mShader->GetError()) {
+ m_flag &= ~RAS_BLENDERGLSL;
mMaterial->SetSharedMaterial(true);
+ mScene->GetBucketManager()->ReleaseDisplayLists(this);
Py_INCREF(mShader);
return mShader;
}else
@@ -870,8 +854,6 @@ void KX_BlenderMaterial::SetBlenderGLSLShader(void)
delete mBlenderShader;
mBlenderShader = 0;
}
- else
- m_flag |= RAS_BLENDERGLSL;
}
KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getMaterialIndex, "getMaterialIndex()")
diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.h b/source/gameengine/Ketsji/KX_BlenderMaterial.h
index 0d7657b8cdb..4ddf5a924df 100644
--- a/source/gameengine/Ketsji/KX_BlenderMaterial.h
+++ b/source/gameengine/Ketsji/KX_BlenderMaterial.h
@@ -28,7 +28,6 @@ public:
BL_Material* mat,
bool skin,
int lightlayer,
- void* clientobject,
PyTypeObject* T=&Type
);
@@ -47,7 +46,7 @@ public:
virtual
void ActivateMeshSlot(
- const KX_MeshSlot & ms,
+ const RAS_MeshSlot & ms,
RAS_IRasterizer* rasty
) const;
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
index d6997ee29a8..9607489497d 100644
--- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
+++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
@@ -76,16 +76,16 @@
struct KX_PhysicsInstance
{
DT_VertexBaseHandle m_vertexbase;
- int m_vtxarray;
+ RAS_DisplayArray* m_darray;
RAS_IPolyMaterial* m_material;
-
- KX_PhysicsInstance(DT_VertexBaseHandle vertex_base, int vtxarray, RAS_IPolyMaterial* mat)
+
+ KX_PhysicsInstance(DT_VertexBaseHandle vertex_base, RAS_DisplayArray *darray, RAS_IPolyMaterial* mat)
: m_vertexbase(vertex_base),
- m_vtxarray(vtxarray),
- m_material(mat)
+ m_darray(darray),
+ m_material(mat)
{
}
-
+
~KX_PhysicsInstance()
{
DT_DeleteVertexBase(m_vertexbase);
@@ -100,11 +100,11 @@ static void BL_RegisterSumoObject(KX_GameObject* gameobj,class SM_Scene* sumoSce
static DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj, bool polytope);
void KX_ConvertSumoObject( KX_GameObject* gameobj,
- RAS_MeshObject* meshobj,
- KX_Scene* kxscene,
- PHY_ShapeProps* kxshapeprops,
- PHY_MaterialProps* kxmaterial,
- struct KX_ObjectProperties* objprop)
+ RAS_MeshObject* meshobj,
+ KX_Scene* kxscene,
+ PHY_ShapeProps* kxshapeprops,
+ PHY_MaterialProps* kxmaterial,
+ struct KX_ObjectProperties* objprop)
{
@@ -150,23 +150,23 @@ void KX_ConvertSumoObject( KX_GameObject* gameobj,
objprop->m_boundobject.box.m_extends[1],
objprop->m_boundobject.box.m_extends[2]);
smprop->m_inertia.scale(objprop->m_boundobject.box.m_extends[0]*objprop->m_boundobject.box.m_extends[0],
- objprop->m_boundobject.box.m_extends[1]*objprop->m_boundobject.box.m_extends[1],
- objprop->m_boundobject.box.m_extends[2]*objprop->m_boundobject.box.m_extends[2]);
+ objprop->m_boundobject.box.m_extends[1]*objprop->m_boundobject.box.m_extends[1],
+ objprop->m_boundobject.box.m_extends[2]*objprop->m_boundobject.box.m_extends[2]);
smprop->m_inertia *= smprop->m_mass/MT_Vector3(objprop->m_boundobject.box.m_extends).length();
break;
case KX_BOUNDCYLINDER:
shape = DT_NewCylinder(smprop->m_radius, objprop->m_boundobject.c.m_height);
smprop->m_inertia.scale(smprop->m_mass*smprop->m_radius*smprop->m_radius,
- smprop->m_mass*smprop->m_radius*smprop->m_radius,
- smprop->m_mass*objprop->m_boundobject.c.m_height*objprop->m_boundobject.c.m_height);
+ smprop->m_mass*smprop->m_radius*smprop->m_radius,
+ smprop->m_mass*objprop->m_boundobject.c.m_height*objprop->m_boundobject.c.m_height);
break;
case KX_BOUNDCONE:
shape = DT_NewCone(objprop->m_radius, objprop->m_boundobject.c.m_height);
smprop->m_inertia.scale(smprop->m_mass*smprop->m_radius*smprop->m_radius,
- smprop->m_mass*smprop->m_radius*smprop->m_radius,
- smprop->m_mass*objprop->m_boundobject.c.m_height*objprop->m_boundobject.c.m_height);
+ smprop->m_mass*smprop->m_radius*smprop->m_radius,
+ smprop->m_mass*objprop->m_boundobject.c.m_height*objprop->m_boundobject.c.m_height);
break;
- /* Dynamic mesh objects. WARNING! slow. */
+ /* Dynamic mesh objects. WARNING! slow. */
case KX_BOUNDPOLYTOPE:
polytope = true;
// fall through
@@ -186,15 +186,15 @@ void KX_ConvertSumoObject( KX_GameObject* gameobj,
shape = DT_NewSphere(objprop->m_radius);
smprop->m_inertia *= smprop->m_mass*smprop->m_radius*smprop->m_radius;
break;
-
+
}
-
+
sumoObj = new SM_Object(shape, !objprop->m_ghost?smmaterial:NULL,smprop,NULL);
-
+
sumoObj->setRigidBody(objprop->m_angular_rigidbody?true:false);
-
+
BL_RegisterSumoObject(gameobj,sceneptr,sumoObj,"",true, true);
-
+
}
else {
// non physics object
@@ -320,12 +320,11 @@ static void BL_RegisterSumoObject(
physicscontroller->SetObject(gameobj->GetSGNode());
}
-static DT_ShapeHandle InstancePhysicsComplex(RAS_MeshObject* meshobj, int vtxarray, RAS_IPolyMaterial *mat)
+static DT_ShapeHandle InstancePhysicsComplex(RAS_MeshObject* meshobj, RAS_DisplayArray *darray, RAS_IPolyMaterial *mat)
{
// instance a mesh from a single vertex array & material
- const RAS_TexVert *vertex_array = &((*meshobj->GetVertexCache(mat)[vtxarray])[0]);
- //const KX_IndexArray &index_array = *meshobj->GetIndexCache(mat)[vtxarray];
- DT_VertexBaseHandle vertex_base = DT_NewVertexBase(vertex_array[0].getLocalXYZ(), sizeof(RAS_TexVert));
+ const RAS_TexVert *vertex_array = &darray->m_vertex[0];
+ DT_VertexBaseHandle vertex_base = DT_NewVertexBase(vertex_array[0].getXYZ(), sizeof(RAS_TexVert));
DT_ShapeHandle shape = DT_NewComplexShape(vertex_base);
@@ -337,15 +336,19 @@ static DT_ShapeHandle InstancePhysicsComplex(RAS_MeshObject* meshobj, int vtxarr
// only add polygons that have the collisionflag set
if (poly->IsCollider())
{
- DT_VertexIndices(3, poly->GetVertexIndexBase().m_indexarray);
+ DT_Begin();
+ DT_VertexIndex(poly->GetVertexOffset(0));
+ DT_VertexIndex(poly->GetVertexOffset(1));
+ DT_VertexIndex(poly->GetVertexOffset(2));
+ DT_End();
// tesselate
if (poly->VertexCount() == 4)
{
DT_Begin();
- DT_VertexIndex(poly->GetVertexIndexBase().m_indexarray[0]);
- DT_VertexIndex(poly->GetVertexIndexBase().m_indexarray[2]);
- DT_VertexIndex(poly->GetVertexIndexBase().m_indexarray[3]);
+ DT_VertexIndex(poly->GetVertexOffset(0));
+ DT_VertexIndex(poly->GetVertexOffset(2));
+ DT_VertexIndex(poly->GetVertexOffset(3));
DT_End();
}
}
@@ -354,16 +357,15 @@ static DT_ShapeHandle InstancePhysicsComplex(RAS_MeshObject* meshobj, int vtxarr
//DT_VertexIndices(indices.size(), &indices[0]);
DT_EndComplexShape();
- map_gamemesh_to_instance.insert(GEN_HashedPtr(meshobj), new KX_PhysicsInstance(vertex_base, vtxarray, mat));
+ map_gamemesh_to_instance.insert(GEN_HashedPtr(meshobj), new KX_PhysicsInstance(vertex_base, darray, mat));
return shape;
}
-static DT_ShapeHandle InstancePhysicsPolytope(RAS_MeshObject* meshobj, int vtxarray, RAS_IPolyMaterial *mat)
+static DT_ShapeHandle InstancePhysicsPolytope(RAS_MeshObject* meshobj, RAS_DisplayArray *darray, RAS_IPolyMaterial *mat)
{
// instance a mesh from a single vertex array & material
- const RAS_TexVert *vertex_array = &((*meshobj->GetVertexCache(mat)[vtxarray])[0]);
- //const KX_IndexArray &index_array = *meshobj->GetIndexCache(mat)[vtxarray];
- DT_VertexBaseHandle vertex_base = DT_NewVertexBase(vertex_array[0].getLocalXYZ(), sizeof(RAS_TexVert));
+ const RAS_TexVert *vertex_array = &darray->m_vertex[0];
+ DT_VertexBaseHandle vertex_base = DT_NewVertexBase(vertex_array[0].getXYZ(), sizeof(RAS_TexVert));
std::vector<DT_Index> indices;
for (int p = 0; p < meshobj->NumPolygons(); p++)
@@ -373,12 +375,12 @@ static DT_ShapeHandle InstancePhysicsPolytope(RAS_MeshObject* meshobj, int vtxar
// only add polygons that have the collisionflag set
if (poly->IsCollider())
{
- indices.push_back(poly->GetVertexIndexBase().m_indexarray[0]);
- indices.push_back(poly->GetVertexIndexBase().m_indexarray[1]);
- indices.push_back(poly->GetVertexIndexBase().m_indexarray[2]);
+ indices.push_back(poly->GetVertexOffset(0));
+ indices.push_back(poly->GetVertexOffset(1));
+ indices.push_back(poly->GetVertexOffset(2));
if (poly->VertexCount() == 4)
- indices.push_back(poly->GetVertexIndexBase().m_indexarray[3]);
+ indices.push_back(poly->GetVertexOffset(3));
}
}
@@ -386,7 +388,7 @@ static DT_ShapeHandle InstancePhysicsPolytope(RAS_MeshObject* meshobj, int vtxar
DT_VertexIndices(indices.size(), &indices[0]);
DT_EndPolytope();
- map_gamemesh_to_instance.insert(GEN_HashedPtr(meshobj), new KX_PhysicsInstance(vertex_base, vtxarray, mat));
+ map_gamemesh_to_instance.insert(GEN_HashedPtr(meshobj), new KX_PhysicsInstance(vertex_base, darray, mat));
return shape;
}
@@ -398,8 +400,8 @@ bool KX_ReInstanceShapeFromMesh(RAS_MeshObject* meshobj)
KX_PhysicsInstance *instance = *map_gamemesh_to_instance[GEN_HashedPtr(meshobj)];
if (instance)
{
- const RAS_TexVert *vertex_array = &((*meshobj->GetVertexCache(instance->m_material)[instance->m_vtxarray])[0]);
- DT_ChangeVertexBase(instance->m_vertexbase, vertex_array[0].getLocalXYZ());
+ const RAS_TexVert *vertex_array = &instance->m_darray->m_vertex[0];
+ DT_ChangeVertexBase(instance->m_vertexbase, vertex_array[0].getXYZ());
return true;
}
return false;
@@ -425,7 +427,7 @@ static DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj, bool polytope
// Count the number of collision polygons and check they all come from the same
// vertex array
int numvalidpolys = 0;
- int vtxarray = -1;
+ RAS_DisplayArray *darray = NULL;
RAS_IPolyMaterial *poly_material = NULL;
bool reinstance = true;
@@ -437,14 +439,14 @@ static DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj, bool polytope
if (poly->IsCollider())
{
// check polygon is from the same vertex array
- if (poly->GetVertexIndexBase().m_vtxarray != vtxarray)
+ if (poly->GetDisplayArray() != darray)
{
- if (vtxarray < 0)
- vtxarray = poly->GetVertexIndexBase().m_vtxarray;
+ if (darray == NULL)
+ darray = poly->GetDisplayArray();
else
{
reinstance = false;
- vtxarray = -1;
+ darray = NULL;
}
}
@@ -478,9 +480,9 @@ static DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj, bool polytope
if (reinstance)
{
if (polytope)
- shape = InstancePhysicsPolytope(meshobj, vtxarray, poly_material);
+ shape = InstancePhysicsPolytope(meshobj, darray, poly_material);
else
- shape = InstancePhysicsComplex(meshobj, vtxarray, poly_material);
+ shape = InstancePhysicsComplex(meshobj, darray, poly_material);
}
else
{
@@ -489,7 +491,7 @@ static DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj, bool polytope
std::cout << "CreateShapeFromMesh: " << meshobj->GetName() << " is not suitable for polytope." << std::endl;
if (!poly_material)
std::cout << " Check mesh materials." << std::endl;
- if (vtxarray < 0)
+ if (darray == NULL)
std::cout << " Check number of vertices." << std::endl;
}
@@ -505,18 +507,10 @@ static DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj, bool polytope
if (poly->IsCollider())
{ /* We have to tesselate here because SOLID can only raycast triangles */
DT_Begin();
- /* V1 */
- DT_Vertex(meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray,
- poly->GetVertexIndexBase().m_indexarray[2],
- poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ());
- /* V2 */
- DT_Vertex(meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray,
- poly->GetVertexIndexBase().m_indexarray[1],
- poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ());
- /* V3 */
- DT_Vertex(meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray,
- poly->GetVertexIndexBase().m_indexarray[0],
- poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ());
+ /* V1, V2, V3 */
+ DT_Vertex(poly->GetVertex(2)->getXYZ());
+ DT_Vertex(poly->GetVertex(1)->getXYZ());
+ DT_Vertex(poly->GetVertex(0)->getXYZ());
numvalidpolys++;
DT_End();
@@ -524,18 +518,10 @@ static DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj, bool polytope
if (poly->VertexCount() == 4)
{
DT_Begin();
- /* V1 */
- DT_Vertex(meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray,
- poly->GetVertexIndexBase().m_indexarray[3],
- poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ());
- /* V3 */
- DT_Vertex(meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray,
- poly->GetVertexIndexBase().m_indexarray[2],
- poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ());
- /* V4 */
- DT_Vertex(meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray,
- poly->GetVertexIndexBase().m_indexarray[0],
- poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ());
+ /* V1, V3, V4 */
+ DT_Vertex(poly->GetVertex(3)->getXYZ());
+ DT_Vertex(poly->GetVertex(2)->getXYZ());
+ DT_Vertex(poly->GetVertex(0)->getXYZ());
numvalidpolys++;
DT_End();
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index cc2956813c1..bec5d188f06 100644
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ b/source/gameengine/Ketsji/KX_GameObject.cpp
@@ -79,10 +79,12 @@ KX_GameObject::KX_GameObject(
m_bDyna(false),
m_layer(0),
m_pBlenderObject(NULL),
+ m_pBlenderGroupObject(NULL),
m_bSuspendDynamics(false),
m_bUseObjectColor(false),
m_bIsNegativeScaling(false),
m_bVisible(true),
+ m_bCulled(true),
m_pPhysicsController1(NULL),
m_pPhysicsEnvironment(NULL),
m_xray(false),
@@ -101,8 +103,11 @@ KX_GameObject::KX_GameObject(
};
+
KX_GameObject::~KX_GameObject()
{
+ RemoveMeshes();
+
// is this delete somewhere ?
//if (m_sumoObj)
// delete m_sumoObj;
@@ -164,7 +169,6 @@ STR_String KX_GameObject::GetName()
void KX_GameObject::SetName(STR_String name)
{
m_name = name;
-
}; // Set the name of the value
@@ -285,11 +289,11 @@ void KX_GameObject::ProcessReplica(KX_GameObject* replica)
CValue* KX_GameObject::GetReplica()
{
KX_GameObject* replica = new KX_GameObject(*this);
-
+
// this will copy properties and so on...
CValue::AddDataToReplica(replica);
ProcessReplica(replica);
-
+
return replica;
}
@@ -355,24 +359,26 @@ double* KX_GameObject::GetOpenGLMatrix()
return fl;
}
+void KX_GameObject::AddMeshUser()
+{
+ for (size_t i=0;i<m_meshes.size();i++)
+ m_meshes[i]->AddMeshUser(this);
+
+ UpdateBuckets();
+}
-
-void KX_GameObject::Bucketize()
+void KX_GameObject::UpdateBuckets()
{
double* fl = GetOpenGLMatrix();
for (size_t i=0;i<m_meshes.size();i++)
- m_meshes[i]->Bucketize(fl, this, m_bUseObjectColor, m_objectColor);
+ m_meshes[i]->UpdateBuckets(this, fl, m_bUseObjectColor, m_objectColor, m_bVisible, m_bCulled);
}
-
-
void KX_GameObject::RemoveMeshes()
{
- double* fl = GetOpenGLMatrix();
-
for (size_t i=0;i<m_meshes.size();i++)
- m_meshes[i]->RemoveFromBuckets(fl, this);
+ m_meshes[i]->RemoveFromBuckets(this);
//note: meshes can be shared, and are deleted by KX_BlenderSceneConverter
@@ -455,13 +461,14 @@ KX_GameObject::UpdateMaterialData(
)
{
int mesh = 0;
-
if (((unsigned int)mesh < m_meshes.size()) && mesh >= 0) {
- RAS_MaterialBucket::Set::iterator mit = m_meshes[mesh]->GetFirstMaterial();
+ list<RAS_MeshMaterial>::iterator mit = m_meshes[mesh]->GetFirstMaterial();
+
for(; mit != m_meshes[mesh]->GetLastMaterial(); ++mit)
{
- RAS_IPolyMaterial* poly = (*mit)->GetPolyMaterial();
- if(poly->GetFlag() & RAS_BLENDERMAT)
+ RAS_IPolyMaterial* poly = mit->m_bucket->GetPolyMaterial();
+
+ if(poly->GetFlag() & RAS_BLENDERMAT )
{
KX_BlenderMaterial *m = static_cast<KX_BlenderMaterial*>(poly);
@@ -469,8 +476,7 @@ KX_GameObject::UpdateMaterialData(
{
m->UpdateIPO(rgba, specrgb,hard,spec,ref,emit, alpha);
// if mesh has only one material attached to it then use original hack with no need to edit vertices (better performance)
- if(!(poly->GetFlag() & RAS_BLENDERGLSL))
- SetObjectColor(rgba);
+ SetObjectColor(rgba);
}
else
{
@@ -504,60 +510,39 @@ KX_GameObject::SetVisible(
m_bVisible = v;
}
-void
-KX_GameObject::SetLayer(
- int l
+bool
+KX_GameObject::GetCulled(
+ void
)
{
- m_layer = l;
+ return m_bCulled;
}
-int
-KX_GameObject::GetLayer(
- void
+void
+KX_GameObject::SetCulled(
+ bool c
)
{
- return m_layer;
+ m_bCulled = c;
}
-// used by Python, and the actuatorshould _not_ be misused by the
-// scene!
-void
-KX_GameObject::MarkVisible(
- bool visible
+
+void
+KX_GameObject::SetLayer(
+ int l
)
{
- /* If explicit visibility settings are used, this is
- * determined on this level. Maybe change this to mesh level
- * later on? */
-
- double* fl = GetOpenGLMatrixPtr()->getPointer();
- for (size_t i=0;i<m_meshes.size();i++)
- {
- m_meshes[i]->MarkVisible(fl,this,visible,m_bUseObjectColor,m_objectColor);
- }
+ m_layer = l;
}
-
-// Always use the flag?
-void
-KX_GameObject::MarkVisible(
+int
+KX_GameObject::GetLayer(
void
)
{
- double* fl = GetOpenGLMatrixPtr()->getPointer();
- for (size_t i=0;i<m_meshes.size();i++)
- {
- m_meshes[i]->MarkVisible(fl,
- this,
- m_bVisible,
- m_bUseObjectColor,
- m_objectColor
- );
- }
+ return m_layer;
}
-
void KX_GameObject::addLinearVelocity(const MT_Vector3& lin_vel,bool local)
{
if (m_pPhysicsController1)
@@ -1052,6 +1037,7 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr
if (attr == "visible")
{
SetVisible(val != 0);
+ UpdateBuckets();
return 0;
}
}
@@ -1221,8 +1207,8 @@ PyObject* KX_GameObject::PySetVisible(PyObject* self, PyObject* value)
return NULL;
}
- MarkVisible(visible!=0);
- m_bVisible = (visible!=0);
+ SetVisible(visible != 0);
+ UpdateBuckets();
Py_RETURN_NONE;
}
diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h
index 508bc7cdfd0..9dcf6526448 100644
--- a/source/gameengine/Ketsji/KX_GameObject.h
+++ b/source/gameengine/Ketsji/KX_GameObject.h
@@ -75,15 +75,17 @@ protected:
int m_layer;
std::vector<RAS_MeshObject*> m_meshes;
struct Object* m_pBlenderObject;
+ struct Object* m_pBlenderGroupObject;
bool m_bSuspendDynamics;
bool m_bUseObjectColor;
bool m_bIsNegativeScaling;
MT_Vector4 m_objectColor;
- // Is this object set to be visible? Only useful for the
- // visibility subsystem right now.
- bool m_bVisible;
+ // visible = user setting
+ // culled = while rendering, depending on camera
+ bool m_bVisible;
+ bool m_bCulled;
KX_IPhysicsController* m_pPhysicsController1;
// used for ray casting
@@ -395,6 +397,16 @@ public:
{
m_pBlenderObject = obj;
}
+
+ struct Object* GetBlenderGroupObject( )
+ {
+ return m_pBlenderGroupObject;
+ }
+
+ void SetBlenderGroupObject( struct Object* obj)
+ {
+ m_pBlenderGroupObject = obj;
+ }
bool IsDupliGroup()
{
@@ -538,18 +550,22 @@ public:
/**
* @section Mesh accessor functions.
*/
+
+ /**
+ * Update buckets to indicate that there is a new
+ * user of this object's meshes.
+ */
+ void
+ AddMeshUser(
+ );
/**
- * Run through the meshes associated with this
- * object and bucketize them. See RAS_Mesh for
- * more details on this function. Interesting to
- * note that polygon bucketizing seems to happen on a per
- * object basis. Which may explain why there is such
- * a big performance gain when all static objects
- * are joined into 1.
+ * Update buckets with data about the mesh after
+ * creating or duplicating the object, changing
+ * visibility, object color, .. .
*/
void
- Bucketize(
+ UpdateBuckets(
);
/**
@@ -610,38 +626,37 @@ public:
ResetDebugColor(
);
- /**
- * Set the visibility of the meshes associated with this
- * object.
+ /**
+ * Was this object marked visible? (only for the explicit
+ * visibility system).
*/
- void
- MarkVisible(
- bool visible
+ bool
+ GetVisible(
+ void
);
- /**
- * Set the visibility according to the visibility flag.
+ /**
+ * Set visibility flag of this object
*/
- void
- MarkVisible(
void
+ SetVisible(
+ bool b
);
/**
- * Was this object marked visible? (only for the ewxplicit
- * visibility system).
+ * Was this object culled?
*/
bool
- GetVisible(
+ GetCulled(
void
);
/**
- * Set visibility flag of this object
+ * Set culled flag of this object
*/
void
- SetVisible(
- bool b
+ SetCulled(
+ bool c
);
/**
@@ -670,6 +685,14 @@ public:
) { return m_bIsNegativeScaling; }
/**
+ * Is this a light?
+ */
+ virtual bool
+ IsLight(
+ void
+ ) { return false; }
+
+ /**
* @section Logic bubbling methods.
*/
diff --git a/source/gameengine/Ketsji/KX_ISceneConverter.h b/source/gameengine/Ketsji/KX_ISceneConverter.h
index f069048cd3d..3709fa8c784 100644
--- a/source/gameengine/Ketsji/KX_ISceneConverter.h
+++ b/source/gameengine/Ketsji/KX_ISceneConverter.h
@@ -32,6 +32,8 @@
#include "STR_String.h"
#include "KX_Python.h"
+struct Scene;
+
class KX_ISceneConverter
{
@@ -77,6 +79,8 @@ public:
// use blender glsl materials
virtual void SetGLSLMaterials(bool val) =0;
virtual bool GetGLSLMaterials()=0;
+
+ virtual struct Scene* GetBlenderSceneForName(const STR_String& name)=0;
};
#endif //__KX_ISCENECONVERTER_H
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
index 1d6cc975ab5..cf98bb72601 100644
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
+++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
@@ -96,6 +96,7 @@ double KX_KetsjiEngine::m_ticrate = DEFAULT_LOGIC_TIC_RATE;
double KX_KetsjiEngine::m_anim_framerate = 25.0;
double KX_KetsjiEngine::m_suspendedtime = 0.0;
double KX_KetsjiEngine::m_suspendeddelta = 0.0;
+double KX_KetsjiEngine::m_average_framerate = 0.0;
/**
@@ -310,6 +311,12 @@ void KX_KetsjiEngine::EndFrame()
{
RenderDebugProperties();
}
+
+ m_average_framerate = m_logger->GetAverage();
+ if (m_average_framerate < 1e-6)
+ m_average_framerate = 1e-6;
+ m_average_framerate = 1.0/m_average_framerate;
+
// Go to next profiling measurement, time spend after this call is shown in the next frame.
m_logger->NextMeasurement(m_kxsystem->GetTimeInSeconds());
@@ -321,8 +328,6 @@ void KX_KetsjiEngine::EndFrame()
m_canvas->EndDraw();
-
-
}
//#include "PIL_time.h"
@@ -897,11 +902,18 @@ void KX_KetsjiEngine::SetupRenderFrame(KX_Scene *scene, KX_Camera* cam)
void KX_KetsjiEngine::RenderShadowBuffers(KX_Scene *scene)
{
- CListValue *lightlist = scene->GetLightList();
+ CListValue *objectlist = scene->GetObjectList();
int i, drawmode;
- for(i=0; i<lightlist->GetCount(); i++) {
- KX_LightObject *light = (KX_LightObject*)lightlist->GetValue(i);
+ m_rendertools->SetAuxilaryClientInfo(scene);
+
+ for(i=0; i<objectlist->GetCount(); i++) {
+ KX_GameObject *gameobj = (KX_GameObject*)objectlist->GetValue(i);
+
+ if(!gameobj->IsLight())
+ continue;
+
+ KX_LightObject *light = (KX_LightObject*)gameobj;
light->Update();
@@ -1281,12 +1293,13 @@ void KX_KetsjiEngine::RemoveScheduledScenes()
KX_Scene* KX_KetsjiEngine::CreateScene(const STR_String& scenename)
{
-
+ Scene *scene = m_sceneconverter->GetBlenderSceneForName(scenename);
KX_Scene* tmpscene = new KX_Scene(m_keyboarddevice,
m_mousedevice,
m_networkdevice,
m_audiodevice,
- scenename);
+ scenename,
+ scene);
m_sceneconverter->ConvertScene(scenename,
tmpscene,
@@ -1442,6 +1455,11 @@ void KX_KetsjiEngine::SetAnimFrameRate(double framerate)
m_anim_framerate = framerate;
}
+double KX_KetsjiEngine::GetAverageFrameRate()
+{
+ return m_average_framerate;
+}
+
void KX_KetsjiEngine::SetTimingDisplay(bool frameRate, bool profile, bool properties)
{
m_show_framerate = frameRate;
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h
index 77b69ec2d9e..97458362f0f 100644
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.h
+++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h
@@ -149,6 +149,8 @@ private:
/** Labels for profiling display. */
static const char m_profileLabels[tc_numCategories][15];
+ /** Last estimated framerate */
+ static double m_average_framerate;
/** Show the framerate on the game display? */
bool m_show_framerate;
/** Show profiling info on the game display? */
@@ -272,6 +274,11 @@ public:
static void SetAnimFrameRate(double framerate);
/**
+ * Gets the last estimated average framerate
+ */
+ static double GetAverageFrameRate();
+
+ /**
* Activates or deactivates timing information display.
* @param frameRate Display for frame rate on or off.
* @param profile Display for individual components on or off.
diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp
index 4e3d6180d22..6cfe5610863 100644
--- a/source/gameengine/Ketsji/KX_Light.cpp
+++ b/source/gameengine/Ketsji/KX_Light.cpp
@@ -42,14 +42,13 @@
#include "KX_PyMath.h"
-#ifdef BLENDER_GLSL
+#include "DNA_object_types.h"
#include "GPU_material.h"
-#endif
KX_LightObject::KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,
class RAS_IRenderTools* rendertools,
const RAS_LightObject& lightobj,
- struct GPULamp *gpulamp,
+ bool glsl,
PyTypeObject* T
)
:
@@ -59,7 +58,8 @@ KX_LightObject::KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,
m_lightobj = lightobj;
m_lightobj.m_worldmatrix = GetOpenGLMatrixPtr();
m_rendertools->AddLight(&m_lightobj);
- m_gpulamp = gpulamp;
+ m_glsl = glsl;
+ m_blenderscene = ((KX_Scene*)sgReplicationInfo)->GetBlenderScene();
};
@@ -73,7 +73,7 @@ CValue* KX_LightObject::GetReplica()
{
KX_LightObject* replica = new KX_LightObject(*this);
-
+
// this will copy properties and so on...
CValue::AddDataToReplica(replica);
@@ -81,13 +81,23 @@ CValue* KX_LightObject::GetReplica()
replica->m_lightobj.m_worldmatrix = replica->GetOpenGLMatrixPtr();
m_rendertools->AddLight(&replica->m_lightobj);
+
return replica;
}
+GPULamp *KX_LightObject::GetGPULamp()
+{
+ if(m_glsl)
+ return GPU_lamp_from_blender(m_blenderscene, GetBlenderObject(), GetBlenderGroupObject());
+ else
+ return false;
+}
+
void KX_LightObject::Update()
{
-#ifdef BLENDER_GLSL
- if(m_gpulamp) {
+ GPULamp *lamp;
+
+ if((lamp = GetGPULamp())) {
float obmat[4][4];
double *dobmat = GetOpenGLMatrixPtr()->getPointer();
@@ -95,38 +105,39 @@ void KX_LightObject::Update()
for(int j=0; j<4; j++, dobmat++)
obmat[i][j] = (float)*dobmat;
- GPU_lamp_update(m_gpulamp, obmat);
+ GPU_lamp_update(lamp, obmat);
}
-#endif
}
bool KX_LightObject::HasShadowBuffer()
{
-#ifdef BLENDER_GLSL
- return (m_gpulamp && GPU_lamp_has_shadow_buffer(m_gpulamp));
-#else
- return false;
-#endif
+ GPULamp *lamp;
+
+ if((lamp = GetGPULamp()))
+ return GPU_lamp_has_shadow_buffer(lamp);
+ else
+ return false;
}
int KX_LightObject::GetShadowLayer()
{
-#ifdef BLENDER_GLSL
- if(m_gpulamp)
- return GPU_lamp_shadow_layer(m_gpulamp);
+ GPULamp *lamp;
+
+ if((lamp = GetGPULamp()))
+ return GPU_lamp_shadow_layer(lamp);
else
-#endif
return 0;
}
void KX_LightObject::BindShadowBuffer(RAS_IRasterizer *ras, KX_Camera *cam, MT_Transform& camtrans)
{
-#ifdef BLENDER_GLSL
+ GPULamp *lamp;
float viewmat[4][4], winmat[4][4];
int winsize;
/* bind framebuffer */
- GPU_lamp_shadow_buffer_bind(m_gpulamp, viewmat, &winsize, winmat);
+ lamp = GetGPULamp();
+ GPU_lamp_shadow_buffer_bind(lamp, viewmat, &winsize, winmat);
/* setup camera transformation */
MT_Matrix4x4 modelviewmat((float*)viewmat);
@@ -146,14 +157,12 @@ void KX_LightObject::BindShadowBuffer(RAS_IRasterizer *ras, KX_Camera *cam, MT_T
ras->SetProjectionMatrix(projectionmat);
ras->SetViewMatrix(modelviewmat, cam->NodeGetWorldPosition(),
cam->GetCameraLocation(), cam->GetCameraOrientation());
-#endif
}
void KX_LightObject::UnbindShadowBuffer(RAS_IRasterizer *ras)
{
-#ifdef BLENDER_GLSL
- GPU_lamp_shadow_buffer_unbind(m_gpulamp);
-#endif
+ GPULamp *lamp = GetGPULamp();
+ GPU_lamp_shadow_buffer_unbind(lamp);
}
PyObject* KX_LightObject::_getattr(const STR_String& attr)
diff --git a/source/gameengine/Ketsji/KX_Light.h b/source/gameengine/Ketsji/KX_Light.h
index 62eb26c61a8..e5dbf0b7f4a 100644
--- a/source/gameengine/Ketsji/KX_Light.h
+++ b/source/gameengine/Ketsji/KX_Light.h
@@ -33,6 +33,7 @@
#include "KX_GameObject.h"
struct GPULamp;
+struct Scene;
class KX_Camera;
class RAS_IRasterizer;
class RAS_IRenderTools;
@@ -44,16 +45,18 @@ class KX_LightObject : public KX_GameObject
protected:
RAS_LightObject m_lightobj;
class RAS_IRenderTools* m_rendertools; //needed for registering and replication of lightobj
- struct GPULamp *m_gpulamp;
- static char doc[];
+ bool m_glsl;
+ Scene* m_blenderscene;
+ static char doc[];
public:
- KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,class RAS_IRenderTools* rendertools,const struct RAS_LightObject& lightobj, struct GPULamp *gpulamp, PyTypeObject *T = &Type);
+ KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,class RAS_IRenderTools* rendertools,const struct RAS_LightObject& lightobj, bool glsl, PyTypeObject *T = &Type);
virtual ~KX_LightObject();
virtual CValue* GetReplica();
RAS_LightObject* GetLightData() { return &m_lightobj;}
/* GLSL shadow */
+ struct GPULamp *GetGPULamp();
bool HasShadowBuffer();
int GetShadowLayer();
void BindShadowBuffer(class RAS_IRasterizer *ras, class KX_Camera *cam, class MT_Transform& camtrans);
@@ -62,6 +65,8 @@ public:
virtual PyObject* _getattr(const STR_String& attr); /* lens, near, far, projection_matrix */
virtual int _setattr(const STR_String& attr, PyObject *pyvalue);
+
+ virtual bool IsLight(void) { return true; }
};
#endif //__KX_LIGHT
diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp
index 29842af7fb6..5bfe8c70cba 100644
--- a/source/gameengine/Ketsji/KX_MeshProxy.cpp
+++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp
@@ -96,10 +96,11 @@ KX_MeshProxy::_getattr(const STR_String& attr)
if (attr == "materials")
{
PyObject *materials = PyList_New(0);
- RAS_MaterialBucket::Set::iterator mit = m_meshobj->GetFirstMaterial();
+ list<RAS_MeshMaterial>::iterator mit = m_meshobj->GetFirstMaterial();
for(; mit != m_meshobj->GetLastMaterial(); ++mit)
{
- RAS_IPolyMaterial *polymat = (*mit)->GetPolyMaterial();
+ RAS_IPolyMaterial *polymat = mit->m_bucket->GetPolyMaterial();
+
if(polymat->GetFlag() & RAS_BLENDERMAT)
{
KX_BlenderMaterial *mat = static_cast<KX_BlenderMaterial*>(polymat);
@@ -204,11 +205,11 @@ PyObject* KX_MeshProxy::PyGetVertexArrayLength(PyObject* self,
if (PyArg_ParseTuple(args,"i",&matid))
{
- RAS_IPolyMaterial* mat = m_meshobj->GetMaterialBucket(matid)->GetPolyMaterial();
+ RAS_MeshMaterial *mmat = m_meshobj->GetMeshMaterial(matid);
+ RAS_IPolyMaterial* mat = mmat->m_bucket->GetPolyMaterial();
+
if (mat)
- {
- length = m_meshobj->GetVertexArrayLength(mat);
- }
+ length = m_meshobj->NumVertices(mat);
}
else {
return NULL;
diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp
index 658c8a98e4f..c6f6bc2db01 100644
--- a/source/gameengine/Ketsji/KX_PolyProxy.cpp
+++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp
@@ -112,8 +112,8 @@ KX_PolyProxy::_getattr(const STR_String& attr)
unsigned int matid;
for (matid=0; matid<m_mesh->NumMaterials(); matid++)
{
- RAS_MaterialBucket* meshBucket = m_mesh->GetMaterialBucket(matid);
- if (meshBucket == polyBucket)
+ RAS_MeshMaterial* meshMat = m_mesh->GetMeshMaterial(matid);
+ if (meshMat->m_bucket == polyBucket)
// found it
break;
}
@@ -121,19 +121,19 @@ KX_PolyProxy::_getattr(const STR_String& attr)
}
if (attr == "v1")
{
- return PyInt_FromLong(m_polygon->GetVertexIndexBase().m_indexarray[0]);
+ return PyInt_FromLong(m_polygon->GetVertexOffset(0));
}
if (attr == "v2")
{
- return PyInt_FromLong(m_polygon->GetVertexIndexBase().m_indexarray[1]);
+ return PyInt_FromLong(m_polygon->GetVertexOffset(1));
}
if (attr == "v3")
{
- return PyInt_FromLong(m_polygon->GetVertexIndexBase().m_indexarray[2]);
+ return PyInt_FromLong(m_polygon->GetVertexOffset(2));
}
if (attr == "v4")
{
- return PyInt_FromLong(((m_polygon->VertexCount()>3)?m_polygon->GetVertexIndexBase().m_indexarray[3]:0));
+ return PyInt_FromLong(((m_polygon->VertexCount()>3)?m_polygon->GetVertexOffset(3):0));
}
if (attr == "visible")
{
@@ -178,8 +178,8 @@ KX_PYMETHODDEF_DOC_NOARG(KX_PolyProxy, getMaterialIndex,
unsigned int matid;
for (matid=0; matid<m_mesh->NumMaterials(); matid++)
{
- RAS_MaterialBucket* meshBucket = m_mesh->GetMaterialBucket(matid);
- if (meshBucket == polyBucket)
+ RAS_MeshMaterial* meshMat = m_mesh->GetMeshMaterial(matid);
+ if (meshMat->m_bucket == polyBucket)
// found it
break;
}
@@ -234,7 +234,7 @@ KX_PYMETHODDEF_DOC(KX_PolyProxy, getVertexIndex,
}
if (index < m_polygon->VertexCount())
{
- return PyInt_FromLong(m_polygon->GetVertexIndexBase().m_indexarray[index]);
+ return PyInt_FromLong(m_polygon->GetVertexOffset(index));
}
return PyInt_FromLong(0);
}
diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp
index 144f74a1a4c..c9180bf3a80 100644
--- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp
+++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp
@@ -35,10 +35,6 @@
#include "BKE_global.h"
#include "BKE_image.h"
-extern "C" {
-#include "BDR_drawmesh.h"
-}
-
#include "DNA_material_types.h"
#include "DNA_texture_types.h"
#include "DNA_image_types.h"
@@ -46,6 +42,8 @@ extern "C" {
#include "IMB_imbuf_types.h"
+#include "GPU_draw.h"
+
#include "MEM_guardedalloc.h"
#include "RAS_LightObject.h"
@@ -63,8 +61,6 @@ KX_PolygonMaterial::KX_PolygonMaterial(const STR_String &texname,
bool alpha,
bool zsort,
int lightlayer,
- bool bIsTriangle,
- void* clientobject,
struct MTFace* tface,
unsigned int* mcol,
PyTypeObject *T)
@@ -78,9 +74,7 @@ KX_PolygonMaterial::KX_PolygonMaterial(const STR_String &texname,
transp,
alpha,
zsort,
- lightlayer,
- bIsTriangle,
- clientobject),
+ lightlayer),
m_tface(tface),
m_mcol(mcol),
m_material(material),
@@ -140,38 +134,29 @@ void KX_PolygonMaterial::DefaultActivate(RAS_IRasterizer* rasty, TCachingInfo& c
if (GetCachingInfo() != cachingInfo)
{
if (!cachingInfo)
- {
- set_tpage(NULL);
- }
+ GPU_set_tpage(NULL);
+
cachingInfo = GetCachingInfo();
if ((m_drawingmode & 4)&& (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED))
{
- update_realtime_texture((struct MTFace*) m_tface, rasty->GetTime());
- set_tpage(m_tface);
- rasty->EnableTextures(true);
+ Image *ima = (Image*)m_tface->tpage;
+ GPU_update_image_time(ima, rasty->GetTime());
+ GPU_set_tpage(m_tface);
}
else
- {
- set_tpage(NULL);
- rasty->EnableTextures(false);
- }
+ GPU_set_tpage(NULL);
if(m_drawingmode & RAS_IRasterizer::KX_TWOSIDE)
- {
rasty->SetCullFace(false);
- }
else
- {
rasty->SetCullFace(true);
- }
- if (m_drawingmode & RAS_IRasterizer::KX_LINES) {
+ if ((m_drawingmode & RAS_IRasterizer::KX_LINES) ||
+ (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME))
rasty->SetLines(true);
- }
- else {
+ else
rasty->SetLines(false);
- }
}
rasty->SetSpecularity(m_specular[0],m_specular[1],m_specular[2],m_specularity);
@@ -253,7 +238,8 @@ PyObject* KX_PolygonMaterial::_getattr(const STR_String& attr)
if (attr == "lightlayer")
return PyInt_FromLong(m_lightlayer);
if (attr == "triangle")
- return PyInt_FromLong(m_bIsTriangle);
+ // deprecated, triangle/quads shouldn't have been a material property
+ return 0;
if (attr == "diffuse")
return PyObjectFrom(m_diffuse);
@@ -333,7 +319,7 @@ int KX_PolygonMaterial::_setattr(const STR_String &attr, PyObject *pyvalue)
// This probably won't work...
if (attr == "triangle")
{
- m_bIsTriangle = value;
+ // deprecated, triangle/quads shouldn't have been a material property
return 0;
}
}
@@ -386,7 +372,9 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, updateTexture, "updateTexture(tface, rast
{
MTFace *tface = (MTFace*) PyCObject_AsVoidPtr(pytface);
RAS_IRasterizer *rasty = (RAS_IRasterizer*) PyCObject_AsVoidPtr(pyrasty);
- update_realtime_texture(tface, rasty->GetTime());
+ Image *ima = (Image*)tface->tpage;
+ GPU_update_image_time(ima, rasty->GetTime());
+
Py_Return;
}
@@ -399,7 +387,7 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setTexture, "setTexture(tface)")
if (PyArg_ParseTuple(args, "O!", &PyCObject_Type, &pytface))
{
MTFace *tface = (MTFace*) PyCObject_AsVoidPtr(pytface);
- set_tpage(tface);
+ GPU_set_tpage(tface);
Py_Return;
}
diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.h b/source/gameengine/Ketsji/KX_PolygonMaterial.h
index 11c8baa8b1f..fe116f757db 100644
--- a/source/gameengine/Ketsji/KX_PolygonMaterial.h
+++ b/source/gameengine/Ketsji/KX_PolygonMaterial.h
@@ -68,8 +68,6 @@ public:
bool alpha,
bool zsort,
int lightlayer,
- bool bIsTriangle,
- void* clientobject,
struct MTFace* tface,
unsigned int* mcol,
PyTypeObject *T = &Type);
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index 4b6a38f18c0..120311fb967 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -57,13 +57,13 @@
#include "BL_ActionActuator.h"
#include "RAS_IRasterizer.h"
#include "RAS_ICanvas.h"
+#include "RAS_BucketManager.h"
#include "MT_Vector3.h"
#include "MT_Point3.h"
#include "ListValue.h"
#include "KX_Scene.h"
#include "SND_DeviceManager.h"
-#include "RAS_OpenGLRasterizer/RAS_GLExtensionManager.h"
#include "BL_Shader.h"
#include "KX_PyMath.h"
@@ -83,6 +83,7 @@ extern "C" {
#include "BKE_utildefines.h"
#include "BKE_global.h"
#include "BLI_blenlib.h"
+#include "GPU_material.h"
static void setSandbox(TPythonSecurityLevel level);
@@ -90,6 +91,7 @@ static void setSandbox(TPythonSecurityLevel level);
// 'local' copy of canvas ptr, for window height/width python scripts
static RAS_ICanvas* gp_Canvas = NULL;
static KX_Scene* gp_KetsjiScene = NULL;
+static KX_KetsjiEngine* gp_KetsjiEngine = NULL;
static RAS_IRasterizer* gp_Rasterizer = NULL;
void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)
@@ -270,6 +272,11 @@ static PyObject* gPyGetPhysicsTicRate(PyObject*)
return PyFloat_FromDouble(PHY_GetActiveEnvironment()->getFixedTimeStep());
}
+static PyObject* gPyGetAverageFrameRate(PyObject*)
+{
+ return PyFloat_FromDouble(KX_KetsjiEngine::GetAverageFrameRate());
+}
+
static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args)
{
char cpath[sizeof(G.sce)];
@@ -409,6 +416,7 @@ static struct PyMethodDef game_methods[] = {
{"setLogicTicRate", (PyCFunction) gPySetLogicTicRate, METH_VARARGS, "Sets the logic tic rate"},
{"getPhysicsTicRate", (PyCFunction) gPyGetPhysicsTicRate, METH_NOARGS, "Gets the physics tic rate"},
{"setPhysicsTicRate", (PyCFunction) gPySetPhysicsTicRate, METH_VARARGS, "Sets the physics tic rate"},
+ {"getAverageFrameRate", (PyCFunction) gPyGetAverageFrameRate, METH_NOARGS, "Gets the estimated average frame rate"},
{"getBlendFileList", (PyCFunction)gPyGetBlendFileList, METH_VARARGS, "Gets a list of blend files in the same directory as the current blend file"},
{"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, "Prints GL Extension Info"},
{NULL, (PyCFunction) NULL, 0, NULL }
@@ -670,6 +678,76 @@ static PyObject* gPyDisableMotionBlur(PyObject*, PyObject* args)
Py_Return;
}
+int getGLSLSettingFlag(char *setting)
+{
+ if(strcmp(setting, "lights") == 0)
+ return G_FILE_GLSL_NO_LIGHTS;
+ else if(strcmp(setting, "shaders") == 0)
+ return G_FILE_GLSL_NO_SHADERS;
+ else if(strcmp(setting, "shadows") == 0)
+ return G_FILE_GLSL_NO_SHADOWS;
+ else if(strcmp(setting, "ramps") == 0)
+ return G_FILE_GLSL_NO_RAMPS;
+ else if(strcmp(setting, "nodes") == 0)
+ return G_FILE_GLSL_NO_NODES;
+ else if(strcmp(setting, "extra_textures") == 0)
+ return G_FILE_GLSL_NO_EXTRA_TEX;
+ else
+ return -1;
+}
+
+static PyObject* gPySetGLSLMaterialSetting(PyObject*,
+ PyObject* args,
+ PyObject*)
+{
+ char *setting;
+ int enable, flag;
+
+ if (PyArg_ParseTuple(args,"si",&setting,&enable))
+ {
+ flag = getGLSLSettingFlag(setting);
+
+ if(flag != -1) {
+ if (enable)
+ G.fileflags &= ~flag;
+ else
+ G.fileflags |= flag;
+
+ /* display lists and GLSL materials need to be remade */
+ if(gp_KetsjiEngine) {
+ KX_SceneList *scenes = gp_KetsjiEngine->CurrentScenes();
+ KX_SceneList::iterator it;
+
+ for(it=scenes->begin(); it!=scenes->end(); it++)
+ if((*it)->GetBucketManager())
+ (*it)->GetBucketManager()->ReleaseDisplayLists();
+ }
+
+ GPU_materials_free();
+ }
+ }
+
+ Py_Return;
+}
+
+static PyObject* gPyGetGLSLMaterialSetting(PyObject*,
+ PyObject* args,
+ PyObject*)
+{
+ char *setting;
+ int enabled = 0, flag;
+
+ if (PyArg_ParseTuple(args,"s",&setting))
+ {
+ flag = getGLSLSettingFlag(setting);
+
+ if(flag != -1)
+ enabled = ((G.fileflags & flag) != 0);
+ }
+
+ return PyInt_FromLong(enabled);
+}
+
STR_String gPyGetWindowHeight__doc__="getWindowHeight doc";
STR_String gPyGetWindowWidth__doc__="getWindowWidth doc";
STR_String gPyEnableVisibility__doc__="enableVisibility doc";
@@ -703,11 +781,13 @@ static struct PyMethodDef rasterizer_methods[] = {
{"getEyeSeparation", (PyCFunction) gPyGetEyeSeparation, METH_VARARGS, "get the eye separation for stereo mode"},
{"setFocalLength", (PyCFunction) gPySetFocalLength, METH_VARARGS, "set the focal length for stereo mode"},
{"getFocalLength", (PyCFunction) gPyGetFocalLength, METH_VARARGS, "get the focal length for stereo mode"},
+ {"setGLSLMaterialSetting",(PyCFunction) gPySetGLSLMaterialSetting,
+ METH_VARARGS, "set the state of a GLSL material setting"},
+ {"getGLSLMaterialSetting",(PyCFunction) gPyGetGLSLMaterialSetting,
+ METH_VARARGS, "get the state of a GLSL material setting"},
{ NULL, (PyCFunction) NULL, 0, NULL }
};
-
-
// Initialization function for the module (*must* be called initGameLogic)
static char GameLogic_module_documentation[] =
@@ -720,11 +800,12 @@ static char Rasterizer_module_documentation[] =
-PyObject* initGameLogic(KX_Scene* scene) // quick hack to get gravity hook
+PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack to get gravity hook
{
PyObject* m;
PyObject* d;
+ gp_KetsjiEngine = engine;
gp_KetsjiScene = scene;
gUseVisibilityTemp=false;
diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h
index f094a1ca575..388d073c6db 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.h
+++ b/source/gameengine/Ketsji/KX_PythonInit.h
@@ -40,7 +40,7 @@ typedef enum {
extern bool gUseVisibilityTemp;
-PyObject* initGameLogic(class KX_Scene* ketsjiscene);
+PyObject* initGameLogic(class KX_KetsjiEngine *engine, class KX_Scene* ketsjiscene);
PyObject* initGameKeys();
PyObject* initRasterizer(class RAS_IRasterizer* rasty,class RAS_ICanvas* canvas);
PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level);
diff --git a/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp b/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp
index f085ff435dc..d651373869a 100644
--- a/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp
+++ b/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp
@@ -78,7 +78,7 @@ UpdateChildCoordinates(
if (parent)
{
- const BL_ArmatureObject *armature = (const BL_ArmatureObject*)(parent->GetSGClientObject());
+ BL_ArmatureObject *armature = (BL_ArmatureObject*)(parent->GetSGClientObject());
if (armature)
{
MT_Matrix4x4 parent_matrix;
diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp
index 1c37fcea77e..2ad0412f1bf 100644
--- a/source/gameengine/Ketsji/KX_Scene.cpp
+++ b/source/gameengine/Ketsji/KX_Scene.cpp
@@ -68,6 +68,7 @@
#include "SG_IObject.h"
#include "SG_Tree.h"
#include "DNA_group_types.h"
+#include "DNA_scene_types.h"
#include "BKE_anim.h"
#include "KX_SG_NodeRelationships.h"
@@ -116,7 +117,8 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice,
class SCA_IInputDevice* mousedevice,
class NG_NetworkDeviceInterface *ndi,
class SND_IAudioDevice* adi,
- const STR_String& sceneName):
+ const STR_String& sceneName,
+ Scene *scene):
PyObjectPlus(&KX_Scene::Type),
m_keyboardmgr(NULL),
m_mousemgr(NULL),
@@ -126,7 +128,8 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice,
m_adi(adi),
m_networkDeviceInterface(ndi),
m_active_camera(NULL),
- m_ueberExecutionPriority(0)
+ m_ueberExecutionPriority(0),
+ m_blenderScene(scene)
{
m_suspendedtime = 0.0;
m_suspendeddelta = 0.0;
@@ -453,7 +456,7 @@ KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CVal
// this is the list of object that are send to the graphics pipeline
m_objectlist->Add(newobj->AddRef());
- newobj->Bucketize();
+ newobj->AddMeshUser();
// logic cannot be replicated, until the whole hierarchy is replicated.
m_logicHierarchicalGameObjects.push_back(newobj);
@@ -623,6 +626,7 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level)
if (blgroupobj == blenderobj)
// this check is also in group_duplilist()
continue;
+
gameobj = (KX_GameObject*)m_logicmgr->FindGameObjByBlendObj(blenderobj);
if (gameobj == NULL)
{
@@ -630,6 +634,9 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level)
// Should not happen as dupli group are created automatically
continue;
}
+
+ gameobj->SetBlenderGroupObject(blgroupobj);
+
if ((blenderobj->lay & group->layer)==0)
{
// object is not visible in the 3D view, will not be instantiated
@@ -999,7 +1006,7 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj)
newobj->m_pDeformer = NULL;
}
- if (mesh->m_class == 1)
+ if (mesh->IsDeformed())
{
// we must create a new deformer but which one?
KX_GameObject* parentobj = newobj->GetParent();
@@ -1073,7 +1080,8 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj)
parentobj->Release();
}
}
- gameobj->Bucketize();
+
+ gameobj->AddMeshUser();
}
@@ -1225,7 +1233,9 @@ void KX_Scene::MarkSubTreeVisible(SG_Tree *node, RAS_IRasterizer* rasty, bool vi
for (int m=0;m<nummeshes;m++)
(gameobj->GetMesh(m))->SchedulePolygons(rasty->GetDrawingMode());
}
- gameobj->MarkVisible(visible);
+
+ gameobj->SetCulled(!visible);
+ gameobj->UpdateBuckets();
}
}
if (node->Left())
@@ -1242,7 +1252,8 @@ void KX_Scene::MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj,KX_Cam
// Shadow lamp layers
if(layer && !(gameobj->GetLayer() & layer)) {
- gameobj->MarkVisible(false);
+ gameobj->SetCulled(true);
+ gameobj->UpdateBuckets();
return;
}
@@ -1288,9 +1299,11 @@ void KX_Scene::MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj,KX_Cam
}
// Visibility/ non-visibility are marked
// elsewhere now.
- gameobj->MarkVisible();
+ gameobj->SetCulled(false);
+ gameobj->UpdateBuckets();
} else {
- gameobj->MarkVisible(false);
+ gameobj->SetCulled(true);
+ gameobj->UpdateBuckets();
}
}
diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h
index 1c56dd1ee55..5f7e1167e27 100644
--- a/source/gameengine/Ketsji/KX_Scene.h
+++ b/source/gameengine/Ketsji/KX_Scene.h
@@ -54,6 +54,7 @@
*/
struct SM_MaterialProps;
struct SM_ShapeProps;
+struct Scene;
class GEN_HashedPtr;
class CListValue;
@@ -277,12 +278,15 @@ protected:
*/
PyObject* m_attrlist;
+ struct Scene* m_blenderScene;
+
public:
KX_Scene(class SCA_IInputDevice* keyboarddevice,
class SCA_IInputDevice* mousedevice,
class NG_NetworkDeviceInterface* ndi,
class SND_IAudioDevice* adi,
- const STR_String& scenename );
+ const STR_String& scenename,
+ struct Scene* scene);
virtual
~KX_Scene();
@@ -582,6 +586,10 @@ public:
* was running and not suspended) and the "curtime"
*/
double getSuspendedDelta();
+ /**
+ * Returns the Blender scene this was made from
+ */
+ struct Scene *GetBlenderScene() { return m_blenderScene; }
};
typedef std::vector<KX_Scene*> KX_SceneList;
diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp
index 5cec65dff1c..25205714308 100644
--- a/source/gameengine/Ketsji/KX_VertexProxy.cpp
+++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp
@@ -82,7 +82,7 @@ PyObject*
KX_VertexProxy::_getattr(const STR_String& attr)
{
if (attr == "XYZ")
- return PyObjectFrom(MT_Vector3(m_vertex->getLocalXYZ()));
+ return PyObjectFrom(MT_Vector3(m_vertex->getXYZ()));
if (attr == "UV")
return PyObjectFrom(MT_Point2(m_vertex->getUV1()));
@@ -102,11 +102,11 @@ KX_VertexProxy::_getattr(const STR_String& attr)
// pos
if (attr == "x")
- return PyFloat_FromDouble(m_vertex->getLocalXYZ()[0]);
+ return PyFloat_FromDouble(m_vertex->getXYZ()[0]);
if (attr == "y")
- return PyFloat_FromDouble(m_vertex->getLocalXYZ()[1]);
+ return PyFloat_FromDouble(m_vertex->getXYZ()[1]);
if (attr == "z")
- return PyFloat_FromDouble(m_vertex->getLocalXYZ()[2]);
+ return PyFloat_FromDouble(m_vertex->getXYZ()[2]);
// Col
if (attr == "r")
@@ -184,7 +184,7 @@ int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue)
{
float val = PyFloat_AsDouble(pyvalue);
// pos
- MT_Point3 pos(m_vertex->getLocalXYZ());
+ MT_Point3 pos(m_vertex->getXYZ());
if (attr == "x")
{
pos.x() = val;
@@ -312,7 +312,7 @@ PyObject* KX_VertexProxy::PyGetXYZ(PyObject*,
PyObject*,
PyObject*)
{
- return PyObjectFrom(MT_Point3(m_vertex->getLocalXYZ()));
+ return PyObjectFrom(MT_Point3(m_vertex->getXYZ()));
}
PyObject* KX_VertexProxy::PySetXYZ(PyObject*,
@@ -426,7 +426,7 @@ PyObject* KX_VertexProxy::PySetUV2(PyObject*,
{
if (PyVecTo(list, vec))
{
- m_vertex->SetFlag((m_vertex->getFlag()|TV_2NDUV));
+ m_vertex->SetFlag((m_vertex->getFlag()|RAS_TexVert::SECOND_UV));
m_vertex->SetUnit(unit);
m_vertex->SetUV2(vec);
m_mesh->SetMeshModified(true);
diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp
index b4693a7a7db..5a0cadcbcfe 100644
--- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp
+++ b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp
@@ -76,7 +76,7 @@ KX_VisibilityActuator::Update()
KX_GameObject *obj = (KX_GameObject*) GetParent();
obj->SetVisible(m_visible);
- obj->MarkVisible();
+ obj->UpdateBuckets();
return true;
}
diff --git a/source/gameengine/Ketsji/Makefile b/source/gameengine/Ketsji/Makefile
index 995237adf2c..0b48ad8b8c3 100644
--- a/source/gameengine/Ketsji/Makefile
+++ b/source/gameengine/Ketsji/Makefile
@@ -64,13 +64,9 @@ CPPFLAGS += -I../../blender/blenlib
CPPFLAGS += -I../../blender/include
CPPFLAGS += -I../../blender/makesdna
CPPFLAGS += -I../../blender/imbuf
+CPPFLAGS += -I../../blender/gpu
CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
-ifeq ($(WITH_BF_GLEXT),true)
- CPPFLAGS += -DWITH_GLEXT
-endif
-
-
###########################
SOURCEDIR = source/gameengine/Ketsji
diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript
index f6f744b199a..02e7aed82a5 100644
--- a/source/gameengine/Ketsji/SConscript
+++ b/source/gameengine/Ketsji/SConscript
@@ -32,16 +32,13 @@ incs += ' #source/gameengine/SceneGraph #source/gameengine/Physics/common #sourc
incs += ' #source/gameengine/Physics/BlOde #source/gameengine/Physics/Dummy'
incs += ' #source/gameengine/Physics/Sumo #source/gameengine/Physics/Sumo/include'
incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork'
-incs += ' #source/blender/misc #source/blender/blenloader #extern/glew/include'
+incs += ' #source/blender/misc #source/blender/blenloader #extern/glew/include #source/blender/gpu'
cflags = []
if env['OURPLATFORM'] == 'win32-vc':
cflags.append('/GR')
cflags.append('/Ox')
-if env['WITH_BF_GLEXT'] == 1:
- env['CPPFLAGS'].append('-DWITH_GLEXT')
-
incs += ' ' + env['BF_SOLID_INC']
incs += ' ' + env['BF_PYTHON_INC']
incs += ' ' + env['BF_SDL_INC']
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
index 2ec96c75a68..8fd89295b03 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
@@ -815,9 +815,7 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope)
{
for (int i=0;i<poly->VertexCount();i++)
{
- const float* vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray,
- poly->GetVertexIndexBase().m_indexarray[i],
- poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
+ const float* vtx = poly->GetVertex(i)->getXYZ();
btPoint3 point(vtx[0],vtx[1],vtx[2]);
m_vertexArray.push_back(point);
numvalidpolys++;
@@ -825,18 +823,15 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope)
} else
{
{
- const float* vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray,
- poly->GetVertexIndexBase().m_indexarray[2],
- poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
+ const float* vtx = poly->GetVertex(2)->getXYZ();
btPoint3 vertex0(vtx[0],vtx[1],vtx[2]);
- vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray,
- poly->GetVertexIndexBase().m_indexarray[1],
- poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
+
+ vtx = poly->GetVertex(1)->getXYZ();
btPoint3 vertex1(vtx[0],vtx[1],vtx[2]);
- vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray,
- poly->GetVertexIndexBase().m_indexarray[0],
- poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
+
+ vtx = poly->GetVertex(0)->getXYZ();
btPoint3 vertex2(vtx[0],vtx[1],vtx[2]);
+
m_vertexArray.push_back(vertex0);
m_vertexArray.push_back(vertex1);
m_vertexArray.push_back(vertex2);
@@ -845,18 +840,15 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope)
}
if (poly->VertexCount() == 4)
{
- const float* vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray,
- poly->GetVertexIndexBase().m_indexarray[3],
- poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
+ const float* vtx = poly->GetVertex(3)->getXYZ();
btPoint3 vertex0(vtx[0],vtx[1],vtx[2]);
- vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray,
- poly->GetVertexIndexBase().m_indexarray[2],
- poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
+
+ vtx = poly->GetVertex(2)->getXYZ();
btPoint3 vertex1(vtx[0],vtx[1],vtx[2]);
- vtx = meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray,
- poly->GetVertexIndexBase().m_indexarray[0],
- poly->GetMaterial()->GetPolyMaterial())->getLocalXYZ();
+
+ vtx = poly->GetVertex(0)->getXYZ();
btPoint3 vertex2(vtx[0],vtx[1],vtx[2]);
+
m_vertexArray.push_back(vertex0);
m_vertexArray.push_back(vertex1);
m_vertexArray.push_back(vertex2);
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
index 8a7f1062f53..a3fbb502c08 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
@@ -128,7 +128,8 @@ struct CcdConstructionInfo
CcdConstructionInfo()
- : m_gravity(0,0,0),
+ : m_localInertiaTensor(1.f, 1.f, 1.f),
+ m_gravity(0,0,0),
m_scaling(1.f,1.f,1.f),
m_mass(0.f),
m_restitution(0.1f),
diff --git a/source/gameengine/PyDoc/GameLogic.py b/source/gameengine/PyDoc/GameLogic.py
index b65bc0f3ce8..af3d2810553 100644
--- a/source/gameengine/PyDoc/GameLogic.py
+++ b/source/gameengine/PyDoc/GameLogic.py
@@ -220,6 +220,13 @@ def setPhysicsTicRate(ticrate):
@param ticrate: The new update frequency (in Hz).
@type ticrate: float
"""
+def getAverageFrameRate():
+ """
+ Gets the estimated average framerate
+
+ @return: The estimed average framerate in frames per second
+ @rtype: float
+ """
def expandPath(path):
"""
@@ -245,4 +252,4 @@ def getBlendFileList(path = "//"):
@type path: string
@return: A list of filenames, with no directory prefix
@rtype: list
- """ \ No newline at end of file
+ """
diff --git a/source/gameengine/PyDoc/Rasterizer.py b/source/gameengine/PyDoc/Rasterizer.py
index 3711ac63b3e..7afdcf07f2e 100644
--- a/source/gameengine/PyDoc/Rasterizer.py
+++ b/source/gameengine/PyDoc/Rasterizer.py
@@ -146,3 +146,20 @@ def getFocalLength():
@rtype: float
"""
+
+def setGLSLMaterialSetting(setting, enable):
+ """
+ Enables or disables a GLSL material setting.
+
+ @type setting: string (lights, shaders, shadows, ramps, nodes, extra_textures)
+ @type enable: boolean
+ """
+
+def getGLSLMaterialSetting(setting, enable):
+ """
+ Get the state of a GLSL material setting.
+
+ @type setting: string (lights, shaders, shadows, ramps, nodes, extra_textures)
+ @rtype: boolean
+ """
+
diff --git a/source/gameengine/Rasterizer/Makefile b/source/gameengine/Rasterizer/Makefile
index e3b1f274ee5..917f70c7108 100644
--- a/source/gameengine/Rasterizer/Makefile
+++ b/source/gameengine/Rasterizer/Makefile
@@ -49,10 +49,6 @@ ifeq ($(OS),darwin)
CPPFLAGS += -fpascal-strings
endif
-ifeq ($(WITH_BF_GLEXT),true)
- CPPFLAGS += -DWITH_GLEXT
-endif
-
###############
SOURCEDIR = source/gameengine/Rasterizer
diff --git a/source/gameengine/Rasterizer/RAS_BucketManager.cpp b/source/gameengine/Rasterizer/RAS_BucketManager.cpp
index 82bdce44519..9fb21a3c17b 100644
--- a/source/gameengine/Rasterizer/RAS_BucketManager.cpp
+++ b/source/gameengine/Rasterizer/RAS_BucketManager.cpp
@@ -26,10 +26,6 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#ifdef WIN32
// don't show these anoying STL warnings
#pragma warning (disable:4786)
@@ -39,168 +35,243 @@
#include "RAS_MaterialBucket.h"
#include "STR_HashedString.h"
#include "RAS_MeshObject.h"
-#define KX_NUM_MATERIALBUCKETS 100
#include "RAS_IRasterizer.h"
#include "RAS_IRenderTools.h"
#include "RAS_BucketManager.h"
+#include <algorithm>
#include <set>
-RAS_BucketManager::RAS_BucketManager()
+/* sorting */
+
+struct RAS_BucketManager::sortedmeshslot
{
+public:
+ MT_Scalar m_z; /* depth */
+ RAS_MeshSlot *m_ms; /* mesh slot */
+ RAS_MaterialBucket *m_bucket; /* buck mesh slot came from */
-}
+ sortedmeshslot() {}
-RAS_BucketManager::~RAS_BucketManager()
-{
- RAS_BucketManagerClearAll();
-}
+ void set(RAS_MeshSlot *ms, RAS_MaterialBucket *bucket, const MT_Vector3& pnorm)
+ {
+ // would be good to use the actual bounding box center instead
+ MT_Point3 pos(ms->m_OpenGLMatrix[12], ms->m_OpenGLMatrix[13], ms->m_OpenGLMatrix[14]);
-/**
- * struct alphamesh holds a mesh, (m_ms) it's depth, (m_z) and the bucket it came from (m_bucket.)
- */
-struct RAS_BucketManager::alphamesh
-{
-public:
- MT_Scalar m_z;
- RAS_MaterialBucket::T_MeshSlotList::iterator m_ms;
- RAS_MaterialBucket *m_bucket;
- alphamesh(MT_Scalar z, RAS_MaterialBucket::T_MeshSlotList::iterator &ms, RAS_MaterialBucket *bucket) :
- m_z(z),
- m_ms(ms),
- m_bucket(bucket)
- {}
+ m_z = MT_dot(pnorm, pos);
+ m_ms = ms;
+ m_bucket = bucket;
+ }
};
struct RAS_BucketManager::backtofront
{
- bool operator()(const alphamesh &a, const alphamesh &b)
+ bool operator()(const sortedmeshslot &a, const sortedmeshslot &b)
{
- return a.m_z < b.m_z;
+ return (a.m_z < b.m_z) || (a.m_z == b.m_z && a.m_ms < b.m_ms);
}
};
+
+struct RAS_BucketManager::fronttoback
+{
+ bool operator()(const sortedmeshslot &a, const sortedmeshslot &b)
+ {
+ return (a.m_z > b.m_z) || (a.m_z == b.m_z && a.m_ms > b.m_ms);
+ }
+};
+
+/* bucket manager */
+
+RAS_BucketManager::RAS_BucketManager()
+{
+
+}
+
+RAS_BucketManager::~RAS_BucketManager()
+{
+ BucketList::iterator it;
+
+ for (it = m_SolidBuckets.begin(); it != m_SolidBuckets.end(); it++)
+ delete (*it);
+
+ for (it = m_AlphaBuckets.begin(); it != m_AlphaBuckets.end(); it++)
+ delete(*it);
+ m_SolidBuckets.clear();
+ m_AlphaBuckets.clear();
+}
+
+void RAS_BucketManager::OrderBuckets(const MT_Transform& cameratrans, BucketList& buckets, vector<sortedmeshslot>& slots, bool alpha)
+{
+ BucketList::iterator bit;
+ list<RAS_MeshSlot>::iterator mit;
+ size_t size = 0, i = 0;
+
+ /* Camera's near plane equation: pnorm.dot(point) + pval,
+ * but we leave out pval since it's constant anyway */
+ const MT_Vector3 pnorm(cameratrans.getBasis()[2]);
+
+ for (bit = buckets.begin(); bit != buckets.end(); ++bit)
+ for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit)
+ if (!mit->IsCulled())
+ size++;
+
+ slots.resize(size);
+
+ for (bit = buckets.begin(); bit != buckets.end(); ++bit)
+ for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit)
+ if (!mit->IsCulled())
+ slots[i++].set(&*mit, *bit, pnorm);
+
+ if(alpha)
+ sort(slots.begin(), slots.end(), backtofront());
+ else
+ sort(slots.begin(), slots.end(), fronttoback());
+}
+
+//static int TOTASLOT = 0;
+//static int TOTSLOT = 0;
void RAS_BucketManager::RenderAlphaBuckets(
const MT_Transform& cameratrans, RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools)
{
- BucketList::iterator bit;
- std::multiset<alphamesh, backtofront> alphameshset;
- RAS_MaterialBucket::T_MeshSlotList::iterator mit;
+ vector<sortedmeshslot> slots;
+ vector<sortedmeshslot>::iterator sit;
+
+ // Having depth masks disabled/enabled gives different artifacts in
+ // case no sorting is done or is done inexact. For compatibility, we
+ // disable it.
+ rasty->SetDepthMask(RAS_IRasterizer::KX_DEPTHMASK_DISABLED);
+
+ OrderBuckets(cameratrans, m_AlphaBuckets, slots, true);
- /* Camera's near plane equation: cam_norm.dot(point) + cam_origin */
- const MT_Vector3 cam_norm(cameratrans.getBasis()[2]);
- const MT_Scalar cam_origin = cameratrans.getOrigin()[2];
- for (bit = m_AlphaBuckets.begin(); bit != m_AlphaBuckets.end(); ++bit)
- {
- for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit)
- {
- if ((*mit).m_bVisible)
- {
- MT_Point3 pos((*mit).m_OpenGLMatrix[12], (*mit).m_OpenGLMatrix[13], (*mit).m_OpenGLMatrix[14]);
- alphameshset.insert(alphamesh(MT_dot(cam_norm, pos) + cam_origin, mit, *bit));
+ for(sit=slots.begin(); sit!=slots.end(); ++sit) {
+ rendertools->SetClientObject(rasty, sit->m_ms->m_clientObj);
+
+ while(sit->m_bucket->ActivateMaterial(cameratrans, rasty, rendertools)) {
+ sit->m_bucket->RenderMeshSlot(cameratrans, rasty, rendertools, *(sit->m_ms));
+ //TOTASLOT++;
+ }
+ }
+
+ rasty->SetDepthMask(RAS_IRasterizer::KX_DEPTHMASK_ENABLED);
+}
+
+void RAS_BucketManager::RenderSolidBuckets(
+ const MT_Transform& cameratrans, RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools)
+{
+ BucketList::iterator bit;
+ list<RAS_MeshSlot>::iterator mit;
+
+ rasty->SetDepthMask(RAS_IRasterizer::KX_DEPTHMASK_ENABLED);
+
+ for (bit = m_SolidBuckets.begin(); bit != m_SolidBuckets.end(); ++bit) {
+ for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit) {
+ if (mit->IsCulled())
+ continue;
+
+ rendertools->SetClientObject(rasty, mit->m_clientObj);
+
+ while ((*bit)->ActivateMaterial(cameratrans, rasty, rendertools)) {
+ (*bit)->RenderMeshSlot(cameratrans, rasty, rendertools, *mit);
+ //TOTSLOT++;
}
}
}
- // It shouldn't be strictly necessary to disable depth writes; but
- // it is needed for compatibility.
- rasty->SetDepthMask(RAS_IRasterizer::KX_DEPTHMASK_DISABLED);
+#if 0
+ vector<sortedmeshslot> slots;
+ vector<sortedmeshslot>::iterator sit;
- RAS_IRasterizer::DrawMode drawingmode;
- std::multiset< alphamesh, backtofront>::iterator msit = alphameshset.begin();
- for (; msit != alphameshset.end(); ++msit)
- {
- rendertools->SetClientObject((*(*msit).m_ms).m_clientObj);
- while ((*msit).m_bucket->ActivateMaterial(cameratrans, rasty, rendertools, drawingmode))
- (*msit).m_bucket->RenderMeshSlot(cameratrans, rasty, rendertools, *(*msit).m_ms, drawingmode);
+ OrderBuckets(cameratrans, m_SolidBuckets, slots, false);
+
+ for(sit=slots.begin(); sit!=slots.end(); ++sit) {
+ rendertools->SetClientObject(rasty, sit->m_ms->m_clientObj);
+
+ while(sit->m_bucket->ActivateMaterial(cameratrans, rasty, rendertools))
+ sit->m_bucket->RenderMeshSlot(cameratrans, rasty, rendertools, *(sit->m_ms));
}
-
- rasty->SetDepthMask(RAS_IRasterizer::KX_DEPTHMASK_ENABLED);
+#endif
}
void RAS_BucketManager::Renderbuckets(
const MT_Transform& cameratrans, RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools)
{
- BucketList::iterator bucket;
-
- rasty->EnableTextures(false);
- rasty->SetDepthMask(RAS_IRasterizer::KX_DEPTHMASK_ENABLED);
-
// beginning each frame, clear (texture/material) caching information
rasty->ClearCachingInfo();
- RAS_MaterialBucket::StartFrame();
-
- for (bucket = m_MaterialBuckets.begin(); bucket != m_MaterialBuckets.end(); ++bucket)
- (*bucket)->Render(cameratrans,rasty,rendertools);
+ //TOTASLOT = 0;
+ //TOTSLOT = 0;
+ RenderSolidBuckets(cameratrans, rasty, rendertools);
RenderAlphaBuckets(cameratrans, rasty, rendertools);
- RAS_MaterialBucket::EndFrame();
+
+ //printf("total slots = %d = %d + %d\n", TOTSLOT + TOTASLOT, TOTSLOT, TOTASLOT);
+
+ rendertools->SetClientObject(rasty, NULL);
}
RAS_MaterialBucket* RAS_BucketManager::FindBucket(RAS_IPolyMaterial * material, bool &bucketCreated)
{
- bucketCreated = false;
BucketList::iterator it;
- for (it = m_MaterialBuckets.begin(); it != m_MaterialBuckets.end(); it++)
- {
+
+ bucketCreated = false;
+
+ for (it = m_SolidBuckets.begin(); it != m_SolidBuckets.end(); it++)
if (*(*it)->GetPolyMaterial() == *material)
return *it;
- }
for (it = m_AlphaBuckets.begin(); it != m_AlphaBuckets.end(); it++)
- {
if (*(*it)->GetPolyMaterial() == *material)
return *it;
- }
RAS_MaterialBucket *bucket = new RAS_MaterialBucket(material);
bucketCreated = true;
+
if (bucket->IsAlpha())
m_AlphaBuckets.push_back(bucket);
else
- m_MaterialBuckets.push_back(bucket);
+ m_SolidBuckets.push_back(bucket);
return bucket;
}
-void RAS_BucketManager::RAS_BucketManagerClearAll()
+void RAS_BucketManager::OptimizeBuckets(MT_Scalar distance)
{
- BucketList::iterator it;
- for (it = m_MaterialBuckets.begin(); it != m_MaterialBuckets.end(); it++)
- {
- delete (*it);
- }
- for (it = m_AlphaBuckets.begin(); it != m_AlphaBuckets.end(); it++)
- {
- delete(*it);
- }
+ BucketList::iterator bit;
- m_MaterialBuckets.clear();
- m_AlphaBuckets.clear();
+ distance = 10.0;
+
+ for (bit = m_SolidBuckets.begin(); bit != m_SolidBuckets.end(); ++bit)
+ (*bit)->Optimize(distance);
+ for (bit = m_AlphaBuckets.begin(); bit != m_AlphaBuckets.end(); ++bit)
+ (*bit)->Optimize(distance);
}
-void RAS_BucketManager::ReleaseDisplayLists()
+void RAS_BucketManager::ReleaseDisplayLists(RAS_IPolyMaterial *mat)
{
BucketList::iterator bit;
- RAS_MaterialBucket::T_MeshSlotList::iterator mit;
+ list<RAS_MeshSlot>::iterator mit;
- for (bit = m_MaterialBuckets.begin(); bit != m_MaterialBuckets.end(); ++bit) {
- for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit) {
- if(mit->m_DisplayList) {
- mit->m_DisplayList->Release();
- mit->m_DisplayList = NULL;
+ for (bit = m_SolidBuckets.begin(); bit != m_SolidBuckets.end(); ++bit) {
+ if (mat == NULL || (mat == (*bit)->GetPolyMaterial())) {
+ for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit) {
+ if(mit->m_DisplayList) {
+ mit->m_DisplayList->Release();
+ mit->m_DisplayList = NULL;
+ }
}
}
}
for (bit = m_AlphaBuckets.begin(); bit != m_AlphaBuckets.end(); ++bit) {
- for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit) {
- if(mit->m_DisplayList) {
- mit->m_DisplayList->Release();
- mit->m_DisplayList = NULL;
+ if (mat == NULL || (mat == (*bit)->GetPolyMaterial())) {
+ for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit) {
+ if(mit->m_DisplayList) {
+ mit->m_DisplayList->Release();
+ mit->m_DisplayList = NULL;
+ }
}
}
}
diff --git a/source/gameengine/Rasterizer/RAS_BucketManager.h b/source/gameengine/Rasterizer/RAS_BucketManager.h
index 08b67ed022f..74526f365a0 100644
--- a/source/gameengine/Rasterizer/RAS_BucketManager.h
+++ b/source/gameengine/Rasterizer/RAS_BucketManager.h
@@ -39,32 +39,33 @@
class RAS_BucketManager
{
- //GEN_Map<class RAS_IPolyMaterial,class RAS_MaterialBucket*> m_MaterialBuckets;
-
typedef std::vector<class RAS_MaterialBucket*> BucketList;
- BucketList m_MaterialBuckets;
+ BucketList m_SolidBuckets;
BucketList m_AlphaBuckets;
- struct alphamesh;
+ struct sortedmeshslot;
struct backtofront;
+ struct fronttoback;
public:
RAS_BucketManager();
virtual ~RAS_BucketManager();
- void RenderAlphaBuckets(const MT_Transform& cameratrans,
- RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools);
void Renderbuckets(const MT_Transform & cameratrans,
- RAS_IRasterizer* rasty,
- class RAS_IRenderTools* rendertools);
+ RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools);
RAS_MaterialBucket* FindBucket(RAS_IPolyMaterial * material, bool &bucketCreated);
+ void OptimizeBuckets(MT_Scalar distance);
- void ReleaseDisplayLists();
+ void ReleaseDisplayLists(RAS_IPolyMaterial * material = NULL);
private:
- void RAS_BucketManagerClearAll();
+ void OrderBuckets(const MT_Transform& cameratrans, BucketList& buckets, vector<sortedmeshslot>& slots, bool alpha);
+ void RenderSolidBuckets(const MT_Transform& cameratrans,
+ RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools);
+ void RenderAlphaBuckets(const MT_Transform& cameratrans,
+ RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools);
};
#endif //__RAS_BUCKETMANAGER
diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp
index 4ee06d96603..fb3607f89f4 100644
--- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp
+++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp
@@ -42,11 +42,8 @@ RAS_IPolyMaterial::RAS_IPolyMaterial(const STR_String& texname,
int transp,
bool alpha,
bool zsort,
- int lightlayer,
- bool bIsTriangle,
- void* clientobject=NULL) :
-
- m_texturename(texname),
+ int lightlayer)
+ : m_texturename(texname),
m_materialname(matname),
m_tile(tile),
m_tilexrep(tilexrep),
@@ -56,7 +53,6 @@ RAS_IPolyMaterial::RAS_IPolyMaterial(const STR_String& texname,
m_alpha(alpha),
m_zsort(zsort),
m_lightlayer(lightlayer),
- m_bIsTriangle(bIsTriangle),
m_polymatid(m_newpolymatid++),
m_flag(0),
m_multimode(0)
@@ -72,15 +68,16 @@ bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const
{
if(m_flag &RAS_BLENDERMAT)
{
- return (
+ bool test = (
this->m_multimode == lhs.m_multimode &&
this->m_flag == lhs.m_flag &&
this->m_drawingmode == lhs.m_drawingmode &&
this->m_transp == lhs.m_transp &&
- this->m_lightlayer == lhs.m_lightlayer &&
this->m_texturename.hash() == lhs.m_texturename.hash() &&
this->m_materialname.hash() == lhs.m_materialname.hash()
);
+
+ return test;
}
else
{
@@ -92,8 +89,6 @@ bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const
this->m_alpha == lhs.m_alpha &&
this->m_zsort == lhs.m_zsort &&
this->m_drawingmode == lhs.m_drawingmode &&
- this->m_bIsTriangle == lhs.m_bIsTriangle &&
- this->m_lightlayer == lhs.m_lightlayer &&
this->m_texturename.hash() == lhs.m_texturename.hash() &&
this->m_materialname.hash() == lhs.m_materialname.hash()
);
@@ -123,11 +118,6 @@ bool RAS_IPolyMaterial::IsZSort() const
return m_zsort;
}
-bool RAS_IPolyMaterial::UsesTriangles() const
-{
- return m_bIsTriangle;
-}
-
unsigned int RAS_IPolyMaterial::hash() const
{
return m_texturename.hash();
@@ -172,5 +162,10 @@ bool RAS_IPolyMaterial::UsesLighting(RAS_IRasterizer *rasty) const
return dolights;
}
+bool RAS_IPolyMaterial::UsesObjectColor() const
+{
+ return !(m_flag & RAS_BLENDERGLSL);
+}
+
unsigned int RAS_IPolyMaterial::m_newpolymatid = 0;
diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h
index 8fc53e6b038..218dd91cb30 100644
--- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h
+++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h
@@ -71,7 +71,6 @@ protected:
bool m_alpha;
bool m_zsort;
int m_lightlayer;
- bool m_bIsTriangle;
unsigned int m_polymatid;
static unsigned int m_newpolymatid;
@@ -106,9 +105,7 @@ public:
int transp,
bool alpha,
bool zsort,
- int lightlayer,
- bool bIsTriangle,
- void* clientobject);
+ int lightlayer);
virtual ~RAS_IPolyMaterial() {};
/**
@@ -129,14 +126,13 @@ public:
{
return false;
}
- virtual void ActivateMeshSlot(const class KX_MeshSlot & ms, RAS_IRasterizer* rasty) const {}
+ virtual void ActivateMeshSlot(const class RAS_MeshSlot & ms, RAS_IRasterizer* rasty) const {}
virtual bool Equals(const RAS_IPolyMaterial& lhs) const;
bool Less(const RAS_IPolyMaterial& rhs) const;
int GetLightLayer() const;
bool IsAlpha() const;
bool IsZSort() const;
- bool UsesTriangles() const;
unsigned int hash() const;
int GetDrawingMode() const;
const STR_String& GetMaterialName() const;
@@ -145,6 +141,7 @@ public:
const unsigned int GetFlag() const;
virtual bool UsesLighting(RAS_IRasterizer *rasty) const;
+ virtual bool UsesObjectColor() const;
/*
* PreCalculate texture gen
diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h
index 9e03212283e..1d18d02a583 100644
--- a/source/gameengine/Rasterizer/RAS_IRasterizer.h
+++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h
@@ -217,39 +217,18 @@ public:
// Drawing Functions
/**
- * IndexPrimitives: Renders primitives.
- * @param vertexarrays is an array of vertex arrays
- * @param indexarrays is an array of index arrays
- * @param mode determines the type of primitive stored in the vertex/index arrays
- * @param useObjectColor will render the object using @param rgbacolor instead of
- * vertex colors.
- */
- virtual void IndexPrimitives( const vecVertexArray& vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
- bool useObjectColor,
- const MT_Vector4& rgbacolor,
- class KX_ListSlot** slot)=0;
-
- virtual void IndexPrimitivesMulti(
- const vecVertexArray& vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
- bool useObjectColor,
- const MT_Vector4& rgbacolor,
- class KX_ListSlot** slot)=0;
+ * IndexPrimitives: Renders primitives from mesh slot.
+ */
+ virtual void IndexPrimitives(class RAS_MeshSlot& ms)=0;
+ virtual void IndexPrimitivesMulti(class RAS_MeshSlot& ms)=0;
/**
* IndexPrimitives_3DText will render text into the polygons.
* The text to be rendered is from @param rendertools client object's text property.
*/
- virtual void IndexPrimitives_3DText( const vecVertexArray& vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
+ virtual void IndexPrimitives_3DText(class RAS_MeshSlot& ms,
class RAS_IPolyMaterial* polymat,
- class RAS_IRenderTools* rendertools,
- bool useObjectColor,
- const MT_Vector4& rgbacolor)=0;
+ class RAS_IRenderTools* rendertools)=0;
virtual void SetProjectionMatrix(MT_CmMatrix4x4 & mat)=0;
/* This one should become our final version, methinks. */
@@ -271,9 +250,6 @@ public:
virtual const MT_Point3& GetCameraPosition()=0;
/**
*/
- virtual void LoadViewMatrix()=0;
- /**
- */
virtual void SetFog(float start,
float dist,
float r,
@@ -309,9 +285,6 @@ public:
*/
virtual int GetDrawingMode()=0;
/**
- */
- virtual void EnableTextures(bool enable)=0;
- /**
* Sets face culling
*/
virtual void SetCullFace(bool enable)=0;
@@ -385,7 +358,9 @@ public:
virtual void SetAttribNum(int num) = 0;
virtual void SetTexCoord(TexCoGen coords, int unit) = 0;
virtual void SetAttrib(TexCoGen coords, int unit) = 0;
- virtual void GetViewMatrix(MT_Matrix4x4 &mat) const = 0;
+
+ virtual const MT_Matrix4x4& GetViewMatrix() const = 0;
+ virtual const MT_Matrix4x4& GetViewInvMatrix() const = 0;
virtual bool QueryLists(){return false;}
virtual bool QueryArrays(){return false;}
@@ -398,6 +373,7 @@ public:
virtual void SetMotionBlurState(int newstate)=0;
virtual void SetBlendingMode(int blendmode)=0;
+ virtual void SetFrontFace(bool ccw)=0;
};
#endif //__RAS_IRASTERIZER
diff --git a/source/gameengine/Rasterizer/RAS_IRenderTools.cpp b/source/gameengine/Rasterizer/RAS_IRenderTools.cpp
index 2be9bb75ebf..555a3520bb4 100644
--- a/source/gameengine/Rasterizer/RAS_IRenderTools.cpp
+++ b/source/gameengine/Rasterizer/RAS_IRenderTools.cpp
@@ -28,42 +28,22 @@
#include "RAS_IRenderTools.h"
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-void RAS_IRenderTools::SetViewMat(const MT_Transform& trans)
-{
- trans.getValue(m_viewmat);
-}
-
-
-
-void RAS_IRenderTools::SetClientObject(void* obj)
+void RAS_IRenderTools::SetClientObject(RAS_IRasterizer* rasty, void *obj)
{
if (m_clientobject != obj)
- {
m_clientobject = obj;
- m_modified = true;
- }
}
-
-
void RAS_IRenderTools::SetAuxilaryClientInfo(void* inf)
{
m_auxilaryClientInfo = inf;
}
-
-
void RAS_IRenderTools::AddLight(struct RAS_LightObject* lightobject)
{
m_lights.push_back(lightobject);
}
-
-
void RAS_IRenderTools::RemoveLight(struct RAS_LightObject* lightobject)
{
std::vector<struct RAS_LightObject*>::iterator lit =
@@ -71,5 +51,5 @@ void RAS_IRenderTools::RemoveLight(struct RAS_LightObject* lightobject)
if (!(lit==m_lights.end()))
m_lights.erase(lit);
-
}
+
diff --git a/source/gameengine/Rasterizer/RAS_IRenderTools.h b/source/gameengine/Rasterizer/RAS_IRenderTools.h
index 54a663ba111..57f331e64cb 100644
--- a/source/gameengine/Rasterizer/RAS_IRenderTools.h
+++ b/source/gameengine/Rasterizer/RAS_IRenderTools.h
@@ -44,12 +44,9 @@ class RAS_IRenderTools
{
protected:
- float m_viewmat[16];
void* m_clientobject;
void* m_auxilaryClientInfo;
- bool m_modified;
-
std::vector<struct RAS_LightObject*> m_lights;
RAS_2DFilterManager m_filtermanager;
@@ -68,8 +65,7 @@ public:
RAS_IRenderTools(
) :
- m_clientobject(NULL),
- m_modified(true)
+ m_clientobject(NULL)
{
};
@@ -131,24 +127,21 @@ public:
float v1[3],
float v2[3],
float v3[3],
- float v4[3]
+ float v4[3],
+ int glattrib
)=0;
virtual
- void
- SetViewMat(
- const MT_Transform& trans
- );
-
- virtual
- int
+ void
ProcessLighting(
- int layer
+ int layer,
+ const MT_Transform& trans
)=0;
virtual
void
SetClientObject(
+ RAS_IRasterizer* rasty,
void* obj
);
@@ -190,24 +183,6 @@ public:
virtual
void
Render2DFilters(RAS_ICanvas* canvas)=0;
-
- virtual
- class RAS_IPolyMaterial*
- CreateBlenderPolyMaterial(
- const STR_String &texname,
- bool ba,
- const STR_String& matname,
- int tile,
- int tilexrep,
- int tileyrep,
- int mode,
- bool transparant,
- bool zsort,
- int lightlayer,
- bool bIsTriangle,
- void* clientobject,
- void* tface
- )=0;
};
#endif //__RAS_IRENDERTOOLS
diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
index 0015b6a251f..e003cdc9368 100644
--- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
+++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
@@ -28,10 +28,6 @@
#include "RAS_MaterialBucket.h"
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#ifdef WIN32
#pragma warning (disable:4786)
#include <windows.h>
@@ -44,79 +40,408 @@
#include "RAS_MeshObject.h"
#include "RAS_Deformer.h" // __NLA
+/* mesh slot */
+
+RAS_MeshSlot::RAS_MeshSlot()
+{
+ m_clientObj = NULL;
+ m_pDeformer = NULL;
+ m_OpenGLMatrix = NULL;
+ m_mesh = NULL;
+ m_bucket = NULL;
+ m_bVisible = false;
+ m_bCulled = true;
+ m_bObjectColor = false;
+ m_RGBAcolor = MT_Vector4(0.0, 0.0, 0.0, 0.0);
+ m_DisplayList = NULL;
+ m_bDisplayList = true;
+ m_joinSlot = NULL;
+}
+
+RAS_MeshSlot::~RAS_MeshSlot()
+{
+ vector<RAS_DisplayArray*>::iterator it;
+
+ Split(true);
+
+ while(m_joinedSlots.size())
+ m_joinedSlots.front()->Split(true);
+ for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
+ (*it)->m_users--;
+ if((*it)->m_users == 0)
+ delete *it;
+ }
+
+ if (m_DisplayList) {
+ m_DisplayList->Release();
+ m_DisplayList = NULL;
+ }
+}
-KX_VertexIndex::KX_VertexIndex(int size)
+RAS_MeshSlot::RAS_MeshSlot(const RAS_MeshSlot& slot)
{
- m_size = size;
+ vector<RAS_DisplayArray*>::iterator it;
+
+ m_clientObj = NULL;
+ m_pDeformer = NULL;
+ m_OpenGLMatrix = NULL;
+ m_mesh = slot.m_mesh;
+ m_bucket = slot.m_bucket;
+ m_bVisible = slot.m_bVisible;
+ m_bCulled = slot.m_bCulled;
+ m_bObjectColor = slot.m_bObjectColor;
+ m_RGBAcolor = slot.m_RGBAcolor;
+ m_DisplayList = NULL;
+ m_bDisplayList = slot.m_bDisplayList;
+ m_joinSlot = NULL;
+ m_currentArray = slot.m_currentArray;
+ m_displayArrays = slot.m_displayArrays;
+ m_joinedSlots = slot.m_joinedSlots;
+
+ m_startarray = slot.m_startarray;
+ m_startvertex = slot.m_startvertex;
+ m_startindex = slot.m_startindex;
+ m_endarray = slot.m_endarray;
+ m_endvertex = slot.m_endvertex;
+ m_endindex = slot.m_endindex;
+
+ for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
+ *it = new RAS_DisplayArray(**it);
+ (*it)->m_users = 1;
+ }
}
+void RAS_MeshSlot::init(RAS_MaterialBucket *bucket, int numverts)
+{
+ m_bucket = bucket;
+
+ SetDisplayArray(numverts);
+ m_startarray = 0;
+ m_startvertex = 0;
+ m_startindex = 0;
+ m_endarray = 0;
+ m_endvertex = 0;
+ m_endindex = 0;
+}
-void KX_VertexIndex::SetIndex(short loc,unsigned int index)
+void RAS_MeshSlot::begin(RAS_MeshSlot::iterator& it)
{
- m_indexarray[loc]=index;
+ int startvertex, endvertex;
+ int startindex, endindex;
+
+ it.array = m_displayArrays[m_startarray];
+
+ startvertex = m_startvertex;
+ endvertex = (m_startarray == m_endarray)? m_endvertex: it.array->m_vertex.size();
+ startindex = m_startindex;
+ endindex = (m_startarray == m_endarray)? m_endindex: it.array->m_index.size();
+
+ it.vertex = &it.array->m_vertex[0];
+ it.index = &it.array->m_index[startindex];
+ it.startvertex = startvertex;
+ it.endvertex = endvertex;
+ it.totindex = endindex-startindex;
+ it.arraynum = m_startarray;
}
-bool KX_MeshSlot::Less(const KX_MeshSlot& lhs) const
+void RAS_MeshSlot::next(RAS_MeshSlot::iterator& it)
{
- bool result = ((m_mesh < lhs.m_mesh ) ||
- ((m_mesh == lhs.m_mesh)&&(m_OpenGLMatrix < lhs.m_OpenGLMatrix)));
-
- return result;
+ int startvertex, endvertex;
+ int startindex, endindex;
+
+ if(it.arraynum == (size_t)m_endarray) {
+ it.array = NULL;
+ it.vertex = NULL;
+ it.index = NULL;
+ it.startvertex = 0;
+ it.endvertex = 0;
+ it.totindex = 0;
+ }
+ else {
+ it.arraynum++;
+ it.array = m_displayArrays[it.arraynum];
+
+ startindex = 0;
+ endindex = (it.arraynum == (size_t)m_endarray)? m_endindex: it.array->m_index.size();
+ startvertex = 0;
+ endvertex = (it.arraynum == (size_t)m_endarray)? m_endvertex: it.array->m_vertex.size();
+
+ it.vertex = &it.array->m_vertex[0];
+ it.index = &it.array->m_index[startindex];
+ it.startvertex = startvertex;
+ it.endvertex = endvertex;
+ it.totindex = endindex-startindex;
+ }
}
-KX_MeshSlot::~KX_MeshSlot()
+bool RAS_MeshSlot::end(RAS_MeshSlot::iterator& it)
{
- if (m_DisplayList)
- m_DisplayList->Release();
+ return (it.array == NULL);
}
+RAS_DisplayArray *RAS_MeshSlot::CurrentDisplayArray()
+{
+ return m_currentArray;
+}
-RAS_MaterialBucket::RAS_MaterialBucket(RAS_IPolyMaterial* mat)
- :m_bModified(true)
+void RAS_MeshSlot::SetDisplayArray(int numverts)
{
- m_material = mat;
+ vector<RAS_DisplayArray*>::iterator it;
+ RAS_DisplayArray *darray = NULL;
+
+ for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
+ darray = *it;
+
+ if(darray->m_type == numverts) {
+ if(darray->m_index.size()+numverts >= RAS_DisplayArray::BUCKET_MAX_INDEX)
+ darray = NULL;
+ else if(darray->m_vertex.size()+numverts >= RAS_DisplayArray::BUCKET_MAX_VERTEX)
+ darray = NULL;
+ else
+ break;
+ }
+ else
+ darray = NULL;
+ }
+
+ if(!darray) {
+ darray = new RAS_DisplayArray();
+ darray->m_users = 1;
+
+ if(numverts == 2) darray->m_type = RAS_DisplayArray::LINE;
+ else if(numverts == 3) darray->m_type = RAS_DisplayArray::TRIANGLE;
+ else darray->m_type = RAS_DisplayArray::QUAD;
+
+ m_displayArrays.push_back(darray);
+
+ if(numverts == 2)
+ darray->m_type = RAS_DisplayArray::LINE;
+ else if(numverts == 3)
+ darray->m_type = RAS_DisplayArray::TRIANGLE;
+ else if(numverts == 4)
+ darray->m_type = RAS_DisplayArray::QUAD;
+
+ m_endarray = m_displayArrays.size()-1;
+ m_endvertex = 0;
+ m_endindex = 0;
+ }
+
+ m_currentArray = darray;
}
+void RAS_MeshSlot::AddPolygon(int numverts)
+{
+ SetDisplayArray(numverts);
+}
+int RAS_MeshSlot::AddVertex(const RAS_TexVert& tv)
+{
+ RAS_DisplayArray *darray;
+ int offset;
+
+ darray = m_currentArray;
+ darray->m_vertex.push_back(tv);
+ offset = darray->m_vertex.size()-1;
-RAS_IPolyMaterial* RAS_MaterialBucket::GetPolyMaterial() const
-{
- return m_material;
+ if(darray == m_displayArrays[m_endarray])
+ m_endvertex++;
+
+ return offset;
}
+void RAS_MeshSlot::AddPolygonVertex(int offset)
+{
+ RAS_DisplayArray *darray;
+
+ darray = m_currentArray;
+ darray->m_index.push_back(offset);
+
+ if(darray == m_displayArrays[m_endarray])
+ m_endindex++;
+}
+bool RAS_MeshSlot::Equals(RAS_MeshSlot *target)
+{
+ if(!m_OpenGLMatrix || !target->m_OpenGLMatrix)
+ return false;
+ if(m_pDeformer || target->m_pDeformer)
+ return false;
+ if(m_bVisible != target->m_bVisible)
+ return false;
+ if(m_bObjectColor != target->m_bObjectColor)
+ return false;
+ if(m_bObjectColor && !(m_RGBAcolor == target->m_RGBAcolor))
+ return false;
-void RAS_MaterialBucket::SetMeshSlot(KX_MeshSlot& ms)
+ return true;
+}
+
+bool RAS_MeshSlot::Join(RAS_MeshSlot *target, MT_Scalar distance)
{
- m_meshSlots.insert(ms);
+ vector<RAS_DisplayArray*>::iterator it;
+ iterator mit;
+ size_t i;
+
+ // verify if we can join
+ if(m_joinSlot || m_joinedSlots.size() || target->m_joinSlot)
+ return false;
+
+ if(!Equals(target))
+ return false;
+
+ MT_Vector3 co(&m_OpenGLMatrix[12]);
+ MT_Vector3 targetco(&target->m_OpenGLMatrix[12]);
+
+ if((co - targetco).length() > distance)
+ return false;
+
+ MT_Matrix4x4 mat(m_OpenGLMatrix);
+ MT_Matrix4x4 targetmat(target->m_OpenGLMatrix);
+ targetmat.invert();
+
+ MT_Matrix4x4 transform = targetmat*mat;
+
+ // m_mesh, clientobj
+ m_joinSlot = target;
+ m_joinInvTransform = transform;
+ m_joinInvTransform.invert();
+ target->m_joinedSlots.push_back(this);
+
+ MT_Matrix4x4 ntransform = m_joinInvTransform.transposed();
+ ntransform[0][3]= ntransform[1][3]= ntransform[2][3]= 0.0f;
+
+ for(begin(mit); !end(mit); next(mit))
+ for(i=mit.startvertex; i<mit.endvertex; i++)
+ mit.vertex[i].Transform(transform, ntransform);
+
+ for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
+ target->m_displayArrays.push_back(*it);
+ target->m_endarray++;
+ target->m_endvertex = target->m_displayArrays.back()->m_vertex.size();
+ target->m_endindex = target->m_displayArrays.back()->m_index.size();
+ }
+
+ if (m_DisplayList) {
+ m_DisplayList->Release();
+ m_DisplayList = NULL;
+ }
+ if (target->m_DisplayList) {
+ target->m_DisplayList->Release();
+ target->m_DisplayList = NULL;
+ }
+
+ return true;
+#if 0
+ return false;
+#endif
}
+bool RAS_MeshSlot::Split(bool force)
+{
+ list<RAS_MeshSlot*>::iterator jit;
+ RAS_MeshSlot *target = m_joinSlot;
+ vector<RAS_DisplayArray*>::iterator it, jt;
+ iterator mit;
+ size_t i, found0 = 0, found1 = 0;
+
+ if(target && (force || !Equals(target))) {
+ m_joinSlot = NULL;
+
+ for(jit=target->m_joinedSlots.begin(); jit!=target->m_joinedSlots.end(); jit++) {
+ if(*jit == this) {
+ target->m_joinedSlots.erase(jit);
+ found0 = 1;
+ break;
+ }
+ }
+
+ if(!found0)
+ abort();
+
+ for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
+ found1 = 0;
+ for(jt=target->m_displayArrays.begin(); jt!=target->m_displayArrays.end(); jt++) {
+ if(*jt == *it) {
+ target->m_displayArrays.erase(jt);
+ target->m_endarray--;
+ found1 = 1;
+ break;
+ }
+ }
+
+ if(!found1)
+ abort();
+ }
+
+ if(target->m_displayArrays.size()) {
+ target->m_endvertex = target->m_displayArrays.back()->m_vertex.size();
+ target->m_endindex = target->m_displayArrays.back()->m_index.size();
+ }
+ else {
+ target->m_endvertex = 0;
+ target->m_endindex = 0;
+ }
+
+ MT_Matrix4x4 ntransform = m_joinInvTransform.inverse().transposed();
+ ntransform[0][3]= ntransform[1][3]= ntransform[2][3]= 0.0f;
+ for(begin(mit); !end(mit); next(mit))
+ for(i=mit.startvertex; i<mit.endvertex; i++)
+ mit.vertex[i].Transform(m_joinInvTransform, ntransform);
+
+ if (target->m_DisplayList) {
+ target->m_DisplayList->Release();
+ target->m_DisplayList = NULL;
+ }
+
+ return true;
+ }
-void RAS_MaterialBucket::RemoveMeshSlot(KX_MeshSlot& ms)
+ return false;
+}
+
+bool RAS_MeshSlot::IsCulled()
{
- T_MeshSlotList::iterator it = m_meshSlots.find(ms);
+ list<RAS_MeshSlot*>::iterator it;
- if (!(it == m_meshSlots.end()))
- m_meshSlots.erase(it);
-
+ if(m_joinSlot)
+ return true;
+ if(!m_bCulled)
+ return false;
+
+ for(it=m_joinedSlots.begin(); it!=m_joinedSlots.end(); it++)
+ if(!(*it)->m_bCulled)
+ return false;
+
+ return true;
}
+/* material bucket sorting */
+
+struct RAS_MaterialBucket::less
+{
+ bool operator()(const RAS_MaterialBucket* x, const RAS_MaterialBucket* y) const
+ {
+ return *x->GetPolyMaterial() < *y->GetPolyMaterial();
+ }
+};
+/* material bucket */
-void RAS_MaterialBucket::MarkVisibleMeshSlot(KX_MeshSlot& ms,
- bool visible,
- bool color,
- const MT_Vector4& rgbavec)
+RAS_MaterialBucket::RAS_MaterialBucket(RAS_IPolyMaterial* mat)
+{
+ m_material = mat;
+}
+
+RAS_MaterialBucket::~RAS_MaterialBucket()
{
- T_MeshSlotList::iterator it = m_meshSlots.find(ms);
-
- assert (!(it == m_meshSlots.end()));
- (*it).m_bVisible = visible;
- (*it).m_bObjectColor = color;
- (*it).m_RGBAcolor= rgbavec;
+}
+
+RAS_IPolyMaterial* RAS_MaterialBucket::GetPolyMaterial() const
+{
+ return m_material;
}
bool RAS_MaterialBucket::IsAlpha() const
@@ -129,162 +454,129 @@ bool RAS_MaterialBucket::IsZSort() const
return (m_material->IsZSort());
}
-
-
-void RAS_MaterialBucket::StartFrame()
+RAS_MeshSlot* RAS_MaterialBucket::AddMesh(int numverts)
{
-}
+ RAS_MeshSlot *ms;
+ m_meshSlots.push_back(RAS_MeshSlot());
+
+ ms = &m_meshSlots.back();
+ ms->init(this, numverts);
+ return ms;
+}
-void RAS_MaterialBucket::EndFrame()
+RAS_MeshSlot* RAS_MaterialBucket::CopyMesh(RAS_MeshSlot *ms)
{
+ m_meshSlots.push_back(RAS_MeshSlot(*ms));
+
+ return &m_meshSlots.back();
}
-unsigned int RAS_MaterialBucket::NumMeshSlots()
+void RAS_MaterialBucket::RemoveMesh(RAS_MeshSlot* ms)
{
- return m_meshSlots.size();
+ list<RAS_MeshSlot>::iterator it;
+
+ for(it=m_meshSlots.begin(); it!=m_meshSlots.end(); it++) {
+ if(&*it == ms) {
+ m_meshSlots.erase(it);
+ return;
+ }
+ }
}
-RAS_MaterialBucket::T_MeshSlotList::iterator RAS_MaterialBucket::msBegin()
+list<RAS_MeshSlot>::iterator RAS_MaterialBucket::msBegin()
{
return m_meshSlots.begin();
}
-RAS_MaterialBucket::T_MeshSlotList::iterator RAS_MaterialBucket::msEnd()
+list<RAS_MeshSlot>::iterator RAS_MaterialBucket::msEnd()
{
return m_meshSlots.end();
}
bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_IRasterizer* rasty,
- RAS_IRenderTools *rendertools, RAS_IRasterizer::DrawMode &drawmode)
+ RAS_IRenderTools *rendertools)
{
- rendertools->SetViewMat(cameratrans);
-
if (!rasty->SetMaterial(*m_material))
return false;
if (m_material->UsesLighting(rasty))
- rendertools->ProcessLighting(RAS_IRenderTools::RAS_LIGHT_OBJECT_LAYER/*m_material->GetLightLayer()*/);
- else
- rendertools->ProcessLighting(-1);
-
- if(rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID)
- drawmode = RAS_IRasterizer::KX_MODE_LINES;
- else if(m_material->UsesTriangles())
- drawmode = RAS_IRasterizer::KX_MODE_TRIANGLES;
+ rendertools->ProcessLighting(RAS_IRenderTools::RAS_LIGHT_OBJECT_LAYER, cameratrans);
else
- drawmode = RAS_IRasterizer::KX_MODE_QUADS;
+ rendertools->ProcessLighting(-1, cameratrans);
return true;
}
void RAS_MaterialBucket::RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRasterizer* rasty,
- RAS_IRenderTools* rendertools, const KX_MeshSlot &ms, RAS_IRasterizer::DrawMode drawmode)
+ RAS_IRenderTools* rendertools, RAS_MeshSlot &ms)
{
- if (!ms.m_bVisible)
- return;
-
m_material->ActivateMeshSlot(ms, rasty);
- /* __NLA Do the deformation */
if (ms.m_pDeformer)
{
ms.m_pDeformer->Apply(m_material);
// KX_ReInstanceShapeFromMesh(ms.m_mesh); // Recompute the physics mesh. (Can't call KX_* from RAS_)
}
- /* End __NLA */
- if (rasty->GetDrawingMode() >= RAS_IRasterizer::KX_SOLID)
- ms.m_mesh->SortPolygons(cameratrans*MT_Transform(ms.m_OpenGLMatrix));
+ if(IsZSort() && rasty->GetDrawingMode() >= RAS_IRasterizer::KX_SOLID)
+ ms.m_mesh->SortPolygons(ms, cameratrans*MT_Transform(ms.m_OpenGLMatrix));
rendertools->PushMatrix();
rendertools->applyTransform(rasty,ms.m_OpenGLMatrix,m_material->GetDrawingMode());
if(rasty->QueryLists())
- {
if(ms.m_DisplayList)
ms.m_DisplayList->SetModified(ms.m_mesh->MeshModified());
- }
// verify if we can use display list, not for deformed object, and
// also don't create a new display list when drawing shadow buffers,
- // then it won't have texture coordinates for actual drawing
- KX_ListSlot **displaylist;
+ // then it won't have texture coordinates for actual drawing. also
+ // for zsort we can't make a display list, since the polygon order
+ // changes all the time.
if(ms.m_pDeformer)
- displaylist = 0;
+ ms.m_bDisplayList = false;
else if(!ms.m_DisplayList && rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW)
- displaylist = 0;
+ ms.m_bDisplayList = false;
+ else if (IsZSort())
+ ms.m_bDisplayList = false;
+ else if(m_material->UsesObjectColor() && ms.m_bObjectColor)
+ ms.m_bDisplayList = false;
else
- displaylist = &ms.m_DisplayList;
+ ms.m_bDisplayList = true;
- // Use the text-specific IndexPrimitives for text faces
+ // for text drawing using faces
if (m_material->GetDrawingMode() & RAS_IRasterizer::RAS_RENDER_3DPOLYGON_TEXT)
- {
- rasty->IndexPrimitives_3DText(
- ms.m_mesh->GetVertexCache(m_material),
- ms.m_mesh->GetIndexCache(m_material),
- drawmode,
- m_material,
- rendertools, // needed for textprinting on polys
- ms.m_bObjectColor,
- ms.m_RGBAcolor);
- }
-
- // for using glMultiTexCoord
+ rasty->IndexPrimitives_3DText(ms, m_material, rendertools);
+ // for multitexturing
else if((m_material->GetFlag() & RAS_MULTITEX))
- {
- rasty->IndexPrimitivesMulti(
- ms.m_mesh->GetVertexCache(m_material),
- ms.m_mesh->GetIndexCache(m_material),
- drawmode,
- ms.m_bObjectColor,
- ms.m_RGBAcolor,
- displaylist);
- }
-
- // Use the normal IndexPrimitives
+ rasty->IndexPrimitivesMulti(ms);
+ // use normal IndexPrimitives
else
- {
- rasty->IndexPrimitives(
- ms.m_mesh->GetVertexCache(m_material),
- ms.m_mesh->GetIndexCache(m_material),
- drawmode,
- ms.m_bObjectColor,
- ms.m_RGBAcolor,
- displaylist);
- }
+ rasty->IndexPrimitives(ms);
- if(rasty->QueryLists()) {
+ if(rasty->QueryLists())
if(ms.m_DisplayList)
ms.m_mesh->SetMeshModified(false);
- }
rendertools->PopMatrix();
}
-void RAS_MaterialBucket::Render(const MT_Transform& cameratrans,
- RAS_IRasterizer* rasty,
- RAS_IRenderTools* rendertools)
+void RAS_MaterialBucket::Optimize(MT_Scalar distance)
{
- if (m_meshSlots.begin()== m_meshSlots.end())
- return;
-
- //rendertools->SetViewMat(cameratrans);
-
- //rasty->SetMaterial(*m_material);
+ /* TODO: still have to check before this works correct:
+ * - lightlayer, frontface, text, billboard
+ * - make it work with physics */
- RAS_IRasterizer::DrawMode drawmode;
- for (T_MeshSlotList::const_iterator it = m_meshSlots.begin();
- ! (it == m_meshSlots.end()); ++it)
- {
- rendertools->SetClientObject((*it).m_clientObj);
- while (ActivateMaterial(cameratrans, rasty, rendertools, drawmode)) {
- RenderMeshSlot(cameratrans, rasty, rendertools, *it, drawmode);
- }
- }
- // to reset the eventual GL_CW mode
- rendertools->SetClientObject(NULL);
+#if 0
+ list<RAS_MeshSlot>::iterator it;
+ list<RAS_MeshSlot>::iterator jt;
+
+ // greed joining on all following buckets
+ for(it=m_meshSlots.begin(); it!=m_meshSlots.end(); it++)
+ for(jt=it, jt++; jt!=m_meshSlots.end(); jt++)
+ jt->Join(&*it, distance);
+#endif
}
-
diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.h b/source/gameengine/Rasterizer/RAS_MaterialBucket.h
index 4eef889c533..475f01d549a 100644
--- a/source/gameengine/Rasterizer/RAS_MaterialBucket.h
+++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.h
@@ -36,30 +36,15 @@
#include "MT_Transform.h"
#include "RAS_IPolygonMaterial.h"
#include "RAS_IRasterizer.h"
-#include "RAS_Deformer.h" // __NLA
+#include "RAS_Deformer.h"
+
#include <vector>
-#include <map>
#include <set>
+#include <list>
using namespace std;
-/**
- * KX_VertexIndex
- */
-struct KX_VertexIndex {
-public:
- KX_VertexIndex(int size);
- void SetIndex(short loc,unsigned int index);
-
- // The vertex array
- short m_vtxarray;
- // An index into the vertex array for up to 4 verticies
- unsigned short m_indexarray[4];
- short m_size;
-};
+/* Display List Slot */
-/**
- * KX_ListSlot.
- */
class KX_ListSlot
{
protected:
@@ -80,91 +65,149 @@ public:
virtual void SetModified(bool mod)=0;
};
-/**
- * KX_MeshSlot.
- */
-class KX_MeshSlot
+class RAS_DisplayArray;
+class RAS_MeshSlot;
+class RAS_MeshMaterial;
+class RAS_MaterialBucket;
+
+/* An array with data used for OpenGL drawing */
+
+class RAS_DisplayArray
{
public:
- void* m_clientObj;
- RAS_Deformer* m_pDeformer; // __NLA
- double* m_OpenGLMatrix;
- class RAS_MeshObject* m_mesh;
- mutable bool m_bVisible; // for visibility
- mutable bool m_bObjectColor;
- mutable MT_Vector4 m_RGBAcolor;
- mutable KX_ListSlot* m_DisplayList; // for lists
- KX_MeshSlot() :
- m_pDeformer(NULL),
- m_bVisible(true),
- m_DisplayList(0)
- {
- }
- ~KX_MeshSlot();
- bool Less(const KX_MeshSlot& lhs) const;
+ vector<RAS_TexVert> m_vertex;
+ vector<unsigned short> m_index;
+ enum { LINE = 2, TRIANGLE = 3, QUAD = 4 } m_type;
+ //RAS_MeshSlot *m_origSlot;
+ int m_users;
+
+ enum { BUCKET_MAX_INDEX = 65535 };
+ enum { BUCKET_MAX_VERTEX = 65535 };
};
+/* Entry of a RAS_MeshObject into RAS_MaterialBucket */
-inline bool operator <( const KX_MeshSlot& rhs,const KX_MeshSlot& lhs)
+class RAS_MeshSlot
{
- return ( rhs.Less(lhs));
-}
+private:
+ // indices into display arrays
+ int m_startarray;
+ int m_endarray;
+ int m_startindex;
+ int m_endindex;
+ int m_startvertex;
+ int m_endvertex;
+ vector<RAS_DisplayArray*> m_displayArrays;
+
+ // for construction only
+ RAS_DisplayArray* m_currentArray;
+
+public:
+ // for rendering
+ RAS_MaterialBucket* m_bucket;
+ RAS_MeshObject* m_mesh;
+ void* m_clientObj;
+ RAS_Deformer* m_pDeformer;
+ double* m_OpenGLMatrix;
+ // visibility
+ bool m_bVisible;
+ bool m_bCulled;
+ // object color
+ bool m_bObjectColor;
+ MT_Vector4 m_RGBAcolor;
+ // display lists
+ KX_ListSlot* m_DisplayList;
+ bool m_bDisplayList;
+ // joined mesh slots
+ RAS_MeshSlot* m_joinSlot;
+ MT_Matrix4x4 m_joinInvTransform;
+ list<RAS_MeshSlot*> m_joinedSlots;
+
+ RAS_MeshSlot();
+ RAS_MeshSlot(const RAS_MeshSlot& slot);
+ virtual ~RAS_MeshSlot();
+
+ void init(RAS_MaterialBucket *bucket, int numverts);
+
+ struct iterator {
+ RAS_DisplayArray *array;
+ RAS_TexVert *vertex;
+ unsigned short *index;
+ size_t startvertex;
+ size_t endvertex;
+ size_t totindex;
+ size_t arraynum;
+ };
+
+ void begin(iterator& it);
+ void next(iterator& it);
+ bool end(iterator& it);
+
+ /* used during construction */
+ void SetDisplayArray(int numverts);
+ RAS_DisplayArray *CurrentDisplayArray();
+
+ void AddPolygon(int numverts);
+ int AddVertex(const RAS_TexVert& tv);
+ void AddPolygonVertex(int offset);
+
+ /* optimization */
+ bool Split(bool force=false);
+ bool Join(RAS_MeshSlot *target, MT_Scalar distance);
+ bool Equals(RAS_MeshSlot *target);
+ bool IsCulled();
+};
+
+/* Used by RAS_MeshObject, to point to it's slots in a bucket */
+
+class RAS_MeshMaterial
+{
+public:
+ RAS_MeshSlot *m_baseslot;
+ class RAS_MaterialBucket *m_bucket;
+
+ GEN_Map<GEN_HashedPtr,RAS_MeshSlot*> m_slots;
+};
+
+/* Contains a list of display arrays with the same material,
+ * and a mesh slot for each mesh that uses display arrays in
+ * this bucket */
-/**
- * Contains a list of meshs with the same material properties.
- */
class RAS_MaterialBucket
{
public:
- typedef std::set<KX_MeshSlot> T_MeshSlotList;
-
RAS_MaterialBucket(RAS_IPolyMaterial* mat);
- virtual ~RAS_MaterialBucket() {}
-
- void Render(const MT_Transform& cameratrans,
- class RAS_IRasterizer* rasty,
- class RAS_IRenderTools* rendertools);
+ virtual ~RAS_MaterialBucket();
+ /* Bucket Sorting */
+ struct less;
+ typedef set<RAS_MaterialBucket*, less> Set;
+
+ /* Material Properties */
RAS_IPolyMaterial* GetPolyMaterial() const;
- bool IsAlpha() const;
- bool IsZSort() const;
+ bool IsAlpha() const;
+ bool IsZSort() const;
- static void StartFrame();
- static void EndFrame();
-
- void SetMeshSlot(KX_MeshSlot& ms);
- void RemoveMeshSlot(KX_MeshSlot& ms);
- void MarkVisibleMeshSlot(KX_MeshSlot& ms,
- bool visible,
- bool color,
- const MT_Vector4& rgbavec);
-
- void RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRasterizer* rasty,
- RAS_IRenderTools* rendertools, const KX_MeshSlot &ms, RAS_IRasterizer::DrawMode drawmode);
+ /* Rendering */
bool ActivateMaterial(const MT_Transform& cameratrans, RAS_IRasterizer* rasty,
- RAS_IRenderTools *rendertools, RAS_IRasterizer::DrawMode& drawmode);
-
- unsigned int NumMeshSlots();
- T_MeshSlotList::iterator msBegin();
- T_MeshSlotList::iterator msEnd();
-
- struct less
- {
- bool operator()(const RAS_MaterialBucket* x, const RAS_MaterialBucket* y) const
- {
- return *x->GetPolyMaterial() < *y->GetPolyMaterial();
- }
- };
+ RAS_IRenderTools *rendertools);
+ void RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRasterizer* rasty,
+ RAS_IRenderTools* rendertools, RAS_MeshSlot &ms);
- typedef set<RAS_MaterialBucket*, less> Set;
+ /* Mesh Slot Access */
+ list<RAS_MeshSlot>::iterator msBegin();
+ list<RAS_MeshSlot>::iterator msEnd();
+
+ class RAS_MeshSlot* AddMesh(int numverts);
+ class RAS_MeshSlot* CopyMesh(class RAS_MeshSlot *ms);
+ void RemoveMesh(class RAS_MeshSlot* ms);
+ void Optimize(MT_Scalar distance);
+
private:
-
- T_MeshSlotList m_meshSlots;
- bool m_bModified;
+ list<RAS_MeshSlot> m_meshSlots;
RAS_IPolyMaterial* m_material;
- double* m_pOGLMatrix;
};
-#endif //__KX_BUCKET
+#endif //__RAS_MATERIAL_BUCKET
diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.cpp b/source/gameengine/Rasterizer/RAS_MeshObject.cpp
index a4f7f3f01dd..a907994bf57 100644
--- a/source/gameengine/Rasterizer/RAS_MeshObject.cpp
+++ b/source/gameengine/Rasterizer/RAS_MeshObject.cpp
@@ -26,10 +26,6 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#include "RAS_MeshObject.h"
#include "RAS_IRasterizer.h"
#include "MT_MinMax.h"
@@ -37,62 +33,84 @@
#include <algorithm>
+/* polygon sorting */
-STR_String RAS_MeshObject::s_emptyname = "";
+struct RAS_MeshObject::polygonSlot
+{
+ float m_z;
+ int m_index[4];
+
+ polygonSlot() {}
+ /* pnorm is the normal from the plane equation that the distance from is
+ * used to sort again. */
+ void get(const RAS_TexVert *vertexarray, const unsigned short *indexarray,
+ int offset, int nvert, const MT_Vector3& pnorm)
+ {
+ MT_Vector3 center(0, 0, 0);
+ int i;
+ for(i=0; i<nvert; i++) {
+ m_index[i] = indexarray[offset+i];
+ center += vertexarray[m_index[i]].getXYZ();
+ }
-KX_ArrayOptimizer::~KX_ArrayOptimizer()
-{
- for (vector<KX_VertexArray*>::iterator itv = m_VertexArrayCache1.begin();
- !(itv == m_VertexArrayCache1.end());++itv)
- {
- delete (*itv);
+ /* note we don't divide center by the number of vertices, since all
+ * polygons have the same number of vertices, and that we leave out
+ * the 4-th component of the plane equation since it is constant. */
+ m_z = MT_dot(pnorm, center);
}
- for (vector<KX_IndexArray*>::iterator iti = m_IndexArrayCache1.begin();
- !(iti == m_IndexArrayCache1.end());++iti)
+ void set(unsigned short *indexarray, int offset, int nvert)
{
- delete (*iti);
+ int i;
+
+ for(i=0; i<nvert; i++)
+ indexarray[offset+i] = m_index[i];
}
+};
- m_TriangleArrayCount.clear();
- m_VertexArrayCache1.clear();
- m_IndexArrayCache1.clear();
-
+struct RAS_MeshObject::backtofront
+{
+ bool operator()(const polygonSlot &a, const polygonSlot &b) const
+ {
+ return a.m_z < b.m_z;
+ }
+};
-}
+struct RAS_MeshObject::fronttoback
+{
+ bool operator()(const polygonSlot &a, const polygonSlot &b) const
+ {
+ return a.m_z > b.m_z;
+ }
+};
+/* mesh object */
+STR_String RAS_MeshObject::s_emptyname = "";
RAS_MeshObject::RAS_MeshObject(Mesh* mesh, int lightlayer)
- : m_bModified(true),
- m_lightlayer(lightlayer),
- m_zsort(false),
- m_MeshMod(true),
+ : m_lightlayer(lightlayer),
+ m_bModified(true),
+ m_bMeshModified(true),
m_mesh(mesh),
- m_class(0)
+ m_bDeformed(false)
{
}
-
-bool RAS_MeshObject::MeshModified()
-{
- return m_MeshMod;
-}
-
-
RAS_MeshObject::~RAS_MeshObject()
{
- for (vector<RAS_Polygon*>::iterator it=m_Polygons.begin();!(it==m_Polygons.end());it++)
- {
- delete (*it);
- }
+ vector<RAS_Polygon*>::iterator it;
- ClearArrayData();
+ for(it=m_Polygons.begin(); it!=m_Polygons.end(); it++)
+ delete (*it);
}
-
+bool RAS_MeshObject::MeshModified()
+{
+ return m_bMeshModified;
+}
unsigned int RAS_MeshObject::GetLightLayer()
{
@@ -108,18 +126,21 @@ int RAS_MeshObject::NumMaterials()
const STR_String& RAS_MeshObject::GetMaterialName(unsigned int matid)
{
- RAS_MaterialBucket* bucket = GetMaterialBucket(matid);
+ RAS_MeshMaterial* mmat = GetMeshMaterial(matid);
+
+ if(mmat)
+ return mmat->m_bucket->GetPolyMaterial()->GetMaterialName();
- return bucket?bucket->GetPolyMaterial()->GetMaterialName():s_emptyname;
+ return s_emptyname;
}
-RAS_MaterialBucket* RAS_MeshObject::GetMaterialBucket(unsigned int matid)
+RAS_MeshMaterial* RAS_MeshObject::GetMeshMaterial(unsigned int matid)
{
if (m_materials.size() > 0 && (matid < m_materials.size()))
{
- RAS_MaterialBucket::Set::const_iterator it = m_materials.begin();
+ list<RAS_MeshMaterial>::iterator it = m_materials.begin();
while (matid--) ++it;
- return *it;
+ return &*it;
}
return NULL;
@@ -141,14 +162,17 @@ RAS_Polygon* RAS_MeshObject::GetPolygon(int num) const
-RAS_MaterialBucket::Set::iterator RAS_MeshObject::GetFirstMaterial()
+
+ list<RAS_MeshMaterial>::iterator GetFirstMaterial();
+ list<RAS_MeshMaterial>::iterator GetLastMaterial();
+list<RAS_MeshMaterial>::iterator RAS_MeshObject::GetFirstMaterial()
{
return m_materials.begin();
}
-RAS_MaterialBucket::Set::iterator RAS_MeshObject::GetLastMaterial()
+list<RAS_MeshMaterial>::iterator RAS_MeshObject::GetLastMaterial()
{
return m_materials.end();
}
@@ -171,377 +195,238 @@ const STR_String& RAS_MeshObject::GetName()
const STR_String& RAS_MeshObject::GetTextureName(unsigned int matid)
{
- RAS_MaterialBucket* bucket = GetMaterialBucket(matid);
+ RAS_MeshMaterial* mmat = GetMeshMaterial(matid);
- return bucket?bucket->GetPolyMaterial()->GetTextureName():s_emptyname;
+ if(mmat)
+ return mmat->m_bucket->GetPolyMaterial()->GetTextureName();
+
+ return s_emptyname;
}
+RAS_MeshMaterial *RAS_MeshObject::GetMeshMaterial(RAS_IPolyMaterial *mat)
+{
+ list<RAS_MeshMaterial>::iterator mit;
+ /* find a mesh material */
+ for(mit = m_materials.begin(); mit != m_materials.end(); mit++)
+ if(mit->m_bucket->GetPolyMaterial() == mat)
+ return &*mit;
-void RAS_MeshObject::AddPolygon(RAS_Polygon* poly)
-{
- m_Polygons.push_back(poly);
+ return NULL;
}
+RAS_Polygon* RAS_MeshObject::AddPolygon(RAS_MaterialBucket *bucket, int numverts)
+{
+ RAS_MeshMaterial *mmat;
+ RAS_Polygon *poly;
+ RAS_MeshSlot *slot;
+ /* find a mesh material */
+ mmat = GetMeshMaterial(bucket->GetPolyMaterial());
+
+ /* none found, create a new one */
+ if(!mmat) {
+ RAS_MeshMaterial meshmat;
+ meshmat.m_bucket = bucket;
+ meshmat.m_baseslot = meshmat.m_bucket->AddMesh(numverts);
+ m_materials.push_back(meshmat);
+ mmat = &m_materials.back();
+ }
+
+ /* add it to the bucket, this also adds new display arrays */
+ slot = mmat->m_baseslot;
+ slot->AddPolygon(numverts);
+
+ /* create a new polygon */
+ RAS_DisplayArray *darray = slot->CurrentDisplayArray();
+ poly = new RAS_Polygon(bucket, darray, numverts);
+ m_Polygons.push_back(poly);
+
+ return poly;
+}
void RAS_MeshObject::DebugColor(unsigned int abgr)
{
-/*
- int numpolys = NumPolygons();
- for (int i=0;i<numpolys;i++)
- {
+ /*int numpolys = NumPolygons();
+
+ for (int i=0;i<numpolys;i++) {
RAS_Polygon* poly = m_polygons[i];
for (int v=0;v<poly->VertexCount();v++)
- {
- RAS_TexVert* vtx = poly->GetVertex(v);
- vtx->setDebugRGBA(abgr);
- }
+ RAS_TexVert* vtx = poly->GetVertex(v)->setDebugRGBA(abgr);
}
*/
- m_debugcolor = abgr;
+ /* m_debugcolor = abgr; */
}
void RAS_MeshObject::SetVertexColor(RAS_IPolyMaterial* mat,MT_Vector4 rgba)
{
- const vecVertexArray & vertexvec = GetVertexCache(mat);
-
- for (vector<KX_VertexArray*>::const_iterator it = vertexvec.begin(); it != vertexvec.end(); ++it)
- {
- KX_VertexArray::iterator vit;
- for (vit=(*it)->begin(); vit != (*it)->end(); vit++)
- {
- vit->SetRGBA(rgba);
- }
- }
-}
-
-void RAS_MeshObject::SchedulePoly(const KX_VertexIndex& idx,
- int numverts,
- RAS_IPolyMaterial* mat)
-{
- KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);
-
- ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(idx.m_indexarray[0]);
- ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(idx.m_indexarray[1]);
- ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(idx.m_indexarray[2]);
-
- if (!mat->UsesTriangles())
- ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(idx.m_indexarray[3]);
-}
+ RAS_MeshMaterial *mmat = GetMeshMaterial(mat);
+ RAS_MeshSlot *slot = mmat->m_baseslot;
+ RAS_MeshSlot::iterator it;
+ size_t i;
+
+ for(slot->begin(it); !slot->end(it); slot->next(it))
+ for(i=it.startvertex; i<it.endvertex; i++)
+ it.vertex[i].SetRGBA(rgba);
+}
+
+void RAS_MeshObject::AddVertex(RAS_Polygon *poly, int i,
+ const MT_Point3& xyz,
+ const MT_Point2& uv,
+ const MT_Point2& uv2,
+ const MT_Vector4& tangent,
+ const unsigned int rgba,
+ const MT_Vector3& normal,
+ bool flat,
+ int origindex)
+{
+ RAS_TexVert texvert(xyz, uv, uv2, tangent, rgba, normal, flat, origindex);
+ RAS_MeshMaterial *mmat;
+ RAS_DisplayArray *darray;
+ RAS_MeshSlot *slot;
+ int offset;
+
+ mmat = GetMeshMaterial(poly->GetMaterial()->GetPolyMaterial());
+ slot = mmat->m_baseslot;
+ darray = slot->CurrentDisplayArray();
+ if(!flat) {
+ /* find vertices shared between faces, with the restriction
+ * that they exist in the same display array, and have the
+ * same uv coordinate etc */
+ vector<SharedVertex>& sharedmap = m_sharedvertex_map[origindex];
+ vector<SharedVertex>::iterator it;
-void RAS_MeshObject::ScheduleWireframePoly(const KX_VertexIndex& idx,
- int numverts,
- int edgecode,
- RAS_IPolyMaterial* mat)
-{
- //int indexpos = m_IndexArrayCount[idx.m_vtxarray];
- int edgetrace = 1<<(numverts-1);
- bool drawedge = (edgecode & edgetrace)!=0;
- edgetrace = 1;
- int prevvert = idx.m_indexarray[numverts-1];
- KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);
-
- for (int v = 0; v < numverts; v++)
- {
- unsigned int curvert = idx.m_indexarray[v];
- if (drawedge)
+ for(it = sharedmap.begin(); it != sharedmap.end(); it++)
{
- ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(prevvert);
- ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(curvert);
+ if(it->m_darray != darray)
+ continue;
+ if(!it->m_darray->m_vertex[it->m_offset].closeTo(&texvert))
+ continue;
+
+ /* found one, add it and we're done */
+ if(poly->IsVisible())
+ slot->AddPolygonVertex(it->m_offset);
+ poly->SetVertexOffset(i, it->m_offset);
+ return;
}
- prevvert = curvert;
- drawedge = (edgecode & edgetrace)!=0;
- edgetrace*=2;
}
- //m_IndexArrayCount[idx.m_vtxarray] = indexpos;
-}
-int RAS_MeshObject::FindOrAddVertex(int vtxarray,
- const MT_Point3& xyz,
- const MT_Point2& uv,
- const MT_Point2& uv2,
- const MT_Vector4& tangent,
- const unsigned int rgbacolor,
- const MT_Vector3& normal,
- bool flat,
- RAS_IPolyMaterial* mat,
- int origindex)
-{
- KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);
-
- int numverts = ao->m_VertexArrayCache1[vtxarray]->size();//m_VertexArrayCount[vtxarray];
- RAS_TexVert newvert(xyz,uv,uv2,tangent,rgbacolor,normal, flat? TV_CALCFACENORMAL: 0,origindex);
+ /* no shared vertex found, add a new one */
+ offset = slot->AddVertex(texvert);
+ if(poly->IsVisible())
+ slot->AddPolygonVertex(offset);
+ poly->SetVertexOffset(i, offset);
-#define KX_FIND_SHARED_VERTICES
-#ifdef KX_FIND_SHARED_VERTICES
if(!flat) {
- for (std::vector<RAS_MatArrayIndex>::iterator it = m_xyz_index_to_vertex_index_mapping[origindex].begin();
- it != m_xyz_index_to_vertex_index_mapping[origindex].end();
- it++)
- {
- if ((*it).m_arrayindex1 == ao->m_index1 &&
- (*it).m_array == vtxarray &&
- *(*it).m_matid == *mat &&
- (*ao->m_VertexArrayCache1[vtxarray])[(*it).m_index].closeTo(&newvert)
- )
- {
- return (*it).m_index;
- }
- }
+ SharedVertex shared;
+ shared.m_darray = darray;
+ shared.m_offset = offset;
+ m_sharedvertex_map[origindex].push_back(shared);
}
-#endif // KX_FIND_SHARED_VERTICES
-
- // no vertex found, add one
- ao->m_VertexArrayCache1[vtxarray]->push_back(newvert);
- // printf("(%f,%f,%f) ",xyz[0],xyz[1],xyz[2]);
- RAS_MatArrayIndex idx;
- idx.m_arrayindex1 = ao->m_index1;
- idx.m_array = vtxarray;
- idx.m_index = numverts;
- idx.m_matid = mat;
- m_xyz_index_to_vertex_index_mapping[origindex].push_back(idx);
-
- return numverts;
}
-vecVertexArray& RAS_MeshObject::GetVertexCache (RAS_IPolyMaterial* mat)
+int RAS_MeshObject::NumVertices(RAS_IPolyMaterial* mat)
{
- KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);
-
- return ao->m_VertexArrayCache1;
-}
+ RAS_MeshMaterial *mmat;
+ RAS_MeshSlot *slot;
+ RAS_MeshSlot::iterator it;
+ size_t len = 0;
-int RAS_MeshObject::GetVertexArrayLength(RAS_IPolyMaterial* mat)
-{
- int len = 0;
-
- const vecVertexArray & vertexvec = GetVertexCache(mat);
- vector<KX_VertexArray*>::const_iterator it = vertexvec.begin();
+ mmat = GetMeshMaterial(mat);
+ slot = mmat->m_baseslot;
+ for(slot->begin(it); !slot->end(it); slot->next(it))
+ len += it.endvertex - it.startvertex;
- for (; it != vertexvec.end(); ++it)
- {
- len += (*it)->size();
- }
-
return len;
}
-
RAS_TexVert* RAS_MeshObject::GetVertex(unsigned int matid,
unsigned int index)
{
- RAS_TexVert* vertex = NULL;
-
- RAS_MaterialBucket* bucket = GetMaterialBucket(matid);
- if (bucket)
- {
- RAS_IPolyMaterial* mat = bucket->GetPolyMaterial();
- if (mat)
- {
- const vecVertexArray & vertexvec = GetVertexCache(mat);
- vector<KX_VertexArray*>::const_iterator it = vertexvec.begin();
-
- for (unsigned int len = 0; it != vertexvec.end(); ++it)
- {
- if (index < len + (*it)->size())
- {
- vertex = &(*(*it))[index-len];
- break;
- }
- else
- {
- len += (*it)->size();
- }
- }
- }
- }
-
- return vertex;
-}
-
-
+ RAS_MeshMaterial *mmat;
+ RAS_MeshSlot *slot;
+ RAS_MeshSlot::iterator it;
+ size_t len;
-const vecIndexArrays& RAS_MeshObject::GetIndexCache (RAS_IPolyMaterial* mat)
-{
- KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);
-
- return ao->m_IndexArrayCache1;
-}
+ mmat = GetMeshMaterial(matid);
-
-
-KX_ArrayOptimizer* RAS_MeshObject::GetArrayOptimizer(RAS_IPolyMaterial* polymat)
-{
- KX_ArrayOptimizer** aop = m_matVertexArrayS[polymat];
-
- if(aop)
- return *aop;
+ if(!mmat)
+ return NULL;
- // didn't find array, but an array might already exist
- // for a material equal to this one
- for(int i=0;i<m_matVertexArrayS.size();i++) {
- RAS_IPolyMaterial *mat = (RAS_IPolyMaterial*)(m_matVertexArrayS.getKey(i)->getValue());
- if(*mat == *polymat) {
- m_matVertexArrayS.insert(polymat, *m_matVertexArrayS.at(i));
- return *m_matVertexArrayS.at(i);
- }
+ slot = mmat->m_baseslot;
+ len = 0;
+ for(slot->begin(it); !slot->end(it); slot->next(it)) {
+ if(index >= len + it.endvertex - it.startvertex)
+ len += it.endvertex - it.startvertex;
+ else
+ return &it.vertex[index - len];
}
-
- // create new array
- int numelements = m_matVertexArrayS.size();
- m_sortedMaterials.push_back(polymat);
-
- KX_ArrayOptimizer* ao = new KX_ArrayOptimizer(numelements);
- m_matVertexArrayS.insert(polymat, ao);
- return ao;
+ return NULL;
}
-
-
-void RAS_MeshObject::Bucketize(double* oglmatrix,
- void* clientobj,
- bool useObjectColor,
- const MT_Vector4& rgbavec)
+void RAS_MeshObject::AddMeshUser(void *clientobj)
{
- KX_MeshSlot ms;
- ms.m_clientObj = clientobj;
- ms.m_mesh = this;
- ms.m_OpenGLMatrix = oglmatrix;
- ms.m_bObjectColor = useObjectColor;
- ms.m_RGBAcolor = rgbavec;
-
- for (RAS_MaterialBucket::Set::iterator it = m_materials.begin();it!=m_materials.end();++it)
- {
- RAS_MaterialBucket* bucket = *it;
-// KX_ArrayOptimizer* oa = GetArrayOptimizer(bucket->GetPolyMaterial());
- bucket->SetMeshSlot(ms);
- }
+ list<RAS_MeshMaterial>::iterator it;
-}
-
-
-
-void RAS_MeshObject::MarkVisible(double* oglmatrix,
- void* clientobj,
- bool visible,
- bool useObjectColor,
- const MT_Vector4& rgbavec)
-{
- KX_MeshSlot ms;
- ms.m_clientObj = clientobj;
- ms.m_mesh = this;
- ms.m_OpenGLMatrix = oglmatrix;
- ms.m_RGBAcolor = rgbavec;
- ms.m_bObjectColor= useObjectColor;
-
- for (RAS_MaterialBucket::Set::iterator it = m_materials.begin();it!=m_materials.end();++it)
- {
- RAS_MaterialBucket* bucket = *it;
-// KX_ArrayOptimizer* oa = GetArrayOptimizer(bucket->GetPolyMaterial());
- bucket->MarkVisibleMeshSlot(ms,visible,useObjectColor,rgbavec);
+ for(it = m_materials.begin();it!=m_materials.end();++it) {
+ /* always copy from the base slot, which is never removed
+ * since new objects can be created with the same mesh data */
+ RAS_MeshSlot *ms = it->m_bucket->CopyMesh(it->m_baseslot);
+ ms->m_clientObj = clientobj;
+ it->m_slots.insert(clientobj, ms);
}
}
-
-void RAS_MeshObject::RemoveFromBuckets(double* oglmatrix,
- void* clientobj)
+void RAS_MeshObject::UpdateBuckets(void* clientobj,
+ double* oglmatrix,
+ bool useObjectColor,
+ const MT_Vector4& rgbavec,
+ bool visible,
+ bool culled)
{
- KX_MeshSlot ms;
- ms.m_clientObj = clientobj;
- ms.m_mesh = this;
- ms.m_OpenGLMatrix = oglmatrix;
-
- for (RAS_MaterialBucket::Set::iterator it = m_materials.begin();it!=m_materials.end();++it)
- {
- RAS_MaterialBucket* bucket = *it;
-// RAS_IPolyMaterial* polymat = bucket->GetPolyMaterial();
- //KX_ArrayOptimizer* oa = GetArrayOptimizer(polymat);
- bucket->RemoveMeshSlot(ms);
- }
-
-}
-
-
+ list<RAS_MeshMaterial>::iterator it;
-/*
- * RAS_MeshObject::GetVertex returns the vertex located somewhere in the vertexpool
- * it is the clients responsibility to make sure the array and index are valid
- */
-RAS_TexVert* RAS_MeshObject::GetVertex(short array,
- unsigned int index,
- RAS_IPolyMaterial* polymat)
-{
- KX_ArrayOptimizer* ao = GetArrayOptimizer(polymat);
- return &((*(ao->m_VertexArrayCache1)[array])[index]);
-}
+ for(it = m_materials.begin();it!=m_materials.end();++it) {
+ RAS_MeshSlot **msp = it->m_slots[clientobj];
+ if(!msp)
+ continue;
+ RAS_MeshSlot *ms = *msp;
-void RAS_MeshObject::ClearArrayData()
-{
- for (int i=0;i<m_matVertexArrayS.size();i++) {
- KX_ArrayOptimizer** ao = m_matVertexArrayS.at(i);
-
- // we have duplicate entries, only free once
- for(int j=i+1;j<m_matVertexArrayS.size();j++) {
- if(ao == m_matVertexArrayS.at(j)) {
- ao = NULL;
- break;
- }
- }
+ ms->m_mesh = this;
+ ms->m_OpenGLMatrix = oglmatrix;
+ ms->m_bObjectColor = useObjectColor;
+ ms->m_RGBAcolor = rgbavec;
+ ms->m_bVisible = visible;
+ ms->m_bCulled = culled || !visible;
- if (ao)
- delete *ao;
+ /* split if necessary */
+ ms->Split();
}
}
-
-
-/**
- * RAS_MeshObject::CreateNewVertices creates vertices within sorted pools of vertices that share same material
-*/
-int RAS_MeshObject::FindVertexArray(int numverts,
- RAS_IPolyMaterial* polymat)
+void RAS_MeshObject::RemoveFromBuckets(void *clientobj)
{
-// bool found=false;
- int array=-1;
+ list<RAS_MeshMaterial>::iterator it;
- KX_ArrayOptimizer* ao = GetArrayOptimizer(polymat);
+ for(it = m_materials.begin();it!=m_materials.end();++it) {
+ RAS_MeshSlot **msp = it->m_slots[clientobj];
- for (unsigned int i=0;i<ao->m_VertexArrayCache1.size();i++)
- {
- if ( (ao->m_TriangleArrayCount[i] + (numverts-2)) < BUCKET_MAX_TRIANGLES)
- {
- if((ao->m_VertexArrayCache1[i]->size()+numverts < BUCKET_MAX_INDICES))
- {
- array = i;
- ao->m_TriangleArrayCount[array]+=numverts-2;
- break;
- }
- }
- }
+ if(!msp)
+ continue;
- if (array == -1)
- {
- array = ao->m_VertexArrayCache1.size();
- vector<RAS_TexVert>* va = new vector<RAS_TexVert>;
- ao->m_VertexArrayCache1.push_back(va);
- KX_IndexArray *ia = new KX_IndexArray();
- ao->m_IndexArrayCache1.push_back(ia);
- ao->m_TriangleArrayCount.push_back(numverts-2);
- }
+ RAS_MeshSlot *ms = *msp;
- return array;
+ it->m_bucket->RemoveMesh(ms);
+ it->m_slots.remove(clientobj);
+ }
}
-
-
-
//void RAS_MeshObject::Transform(const MT_Transform& trans)
//{
//m_trans.translate(MT_Vector3(0,0,1));//.operator *=(trans);
@@ -563,71 +448,7 @@ void RAS_MeshObject::RelativeTransform(const MT_Vector3& vec)
}
*/
-
-
-void RAS_MeshObject::UpdateMaterialList()
-{
- m_materials.clear();
- unsigned int numpolys = m_Polygons.size();
- // for all polygons, find out which material they use, and add it to the set of materials
- for (unsigned int i=0;i<numpolys;i++)
- {
- m_materials.insert(m_Polygons[i]->GetMaterial());
- }
-}
-
-struct RAS_MeshObject::polygonSlot
-{
- float m_z;
- int m_index[4];
-
- polygonSlot() {}
-
- /* pnorm is the normal from the plane equation that the distance from is
- * used to sort again. */
- void get(const KX_VertexArray& vertexarray, const KX_IndexArray& indexarray,
- int offset, int nvert, const MT_Vector3& pnorm)
- {
- MT_Vector3 center(0, 0, 0);
- int i;
-
- for(i=0; i<nvert; i++) {
- m_index[i] = indexarray[offset+i];
- center += vertexarray[m_index[i]].getLocalXYZ();
- }
-
- /* note we don't divide center by the number of vertices, since all
- * polygons have the same number of vertices, and that we leave out
- * the 4-th component of the plane equation since it is constant. */
- m_z = MT_dot(pnorm, center);
- }
-
- void set(KX_IndexArray& indexarray, int offset, int nvert)
- {
- int i;
-
- for(i=0; i<nvert; i++)
- indexarray[offset+i] = m_index[i];
- }
-};
-
-struct RAS_MeshObject::backtofront
-{
- bool operator()(const polygonSlot &a, const polygonSlot &b) const
- {
- return a.m_z < b.m_z;
- }
-};
-
-struct RAS_MeshObject::fronttoback
-{
- bool operator()(const polygonSlot &a, const polygonSlot &b) const
- {
- return a.m_z > b.m_z;
- }
-};
-
-void RAS_MeshObject::SortPolygons(const MT_Transform &transform)
+void RAS_MeshObject::SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transform)
{
// Limitations: sorting is quite simple, and handles many
// cases wrong, partially due to polygons being sorted per
@@ -645,43 +466,34 @@ void RAS_MeshObject::SortPolygons(const MT_Transform &transform)
// to avoid excessive state changes while drawing. e) would
// require splitting polygons.
- if (!m_zsort)
- return;
+ RAS_MeshSlot::iterator it;
+ size_t j;
- // Extract camera Z plane...
- const MT_Vector3 pnorm(transform.getBasis()[2]);
- // unneeded: const MT_Scalar pval = transform.getOrigin()[2];
+ for(ms.begin(it); !ms.end(it); ms.next(it)) {
+ unsigned int nvert = (int)it.array->m_type;
+ unsigned int totpoly = it.totindex/nvert;
- for (RAS_MaterialBucket::Set::iterator it = m_materials.begin();it!=m_materials.end();++it)
- {
- if(!(*it)->IsZSort())
+ if(totpoly <= 1)
+ continue;
+ if(it.array->m_type == RAS_DisplayArray::LINE)
continue;
- RAS_IPolyMaterial *mat = (*it)->GetPolyMaterial();
- KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);
-
- vecIndexArrays& indexarrays = ao->m_IndexArrayCache1;
- vecVertexArray& vertexarrays = ao->m_VertexArrayCache1;
- unsigned int i, j, nvert = (mat->UsesTriangles())? 3: 4;
-
- for(i=0; i<indexarrays.size(); i++) {
- KX_IndexArray& indexarray = *indexarrays[i];
- KX_VertexArray& vertexarray = *vertexarrays[i];
+ // Extract camera Z plane...
+ const MT_Vector3 pnorm(transform.getBasis()[2]);
+ // unneeded: const MT_Scalar pval = transform.getOrigin()[2];
- unsigned int totpoly = indexarray.size()/nvert;
- vector<polygonSlot> slots(totpoly);
+ vector<polygonSlot> slots(totpoly);
- /* get indices and z into temporary array */
- for(j=0; j<totpoly; j++)
- slots[j].get(vertexarray, indexarray, j*nvert, nvert, pnorm);
+ /* get indices and z into temporary array */
+ for(j=0; j<totpoly; j++)
+ slots[j].get(it.vertex, it.index, j*nvert, nvert, pnorm);
- /* sort (stable_sort might be better, if flickering happens?) */
- std::sort(slots.begin(), slots.end(), backtofront());
+ /* sort (stable_sort might be better, if flickering happens?) */
+ std::sort(slots.begin(), slots.end(), backtofront());
- /* get indices from temporary array again */
- for(j=0; j<totpoly; j++)
- slots[j].set(indexarray, j*nvert, nvert);
- }
+ /* get indices from temporary array again */
+ for(j=0; j<totpoly; j++)
+ slots[j].set(it.index, j*nvert, nvert);
}
}
@@ -690,37 +502,8 @@ void RAS_MeshObject::SchedulePolygons(int drawingmode)
{
if (m_bModified)
{
- int i, numpolys = m_Polygons.size();
-
- for (RAS_MaterialBucket::Set::iterator it = m_materials.begin();it!=m_materials.end();++it)
- if ((*it)->IsZSort())
- m_zsort = true;
-
- if (drawingmode == RAS_IRasterizer::KX_WIREFRAME)
- {
- for (i=0;i<numpolys;i++)
- {
- RAS_Polygon* poly = m_Polygons[i];
- if (poly->IsVisible())
- ScheduleWireframePoly(poly->GetVertexIndexBase(),poly->VertexCount(),poly->GetEdgeCode(),
- poly->GetMaterial()->GetPolyMaterial());
-
- }
- m_zsort = false;
- }
- else
- {
- for (i=0;i<numpolys;i++)
- {
- RAS_Polygon* poly = m_Polygons[i];
- if (poly->IsVisible())
- SchedulePoly(poly->GetVertexIndexBase(),poly->VertexCount(),
- poly->GetMaterial()->GetPolyMaterial());
- }
- }
-
m_bModified = false;
- m_MeshMod = true;
+ m_bMeshModified = true;
}
}
diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.h b/source/gameengine/Rasterizer/RAS_MeshObject.h
index 9a46d89c393..0d35a2f402b 100644
--- a/source/gameengine/Rasterizer/RAS_MeshObject.h
+++ b/source/gameengine/Rasterizer/RAS_MeshObject.h
@@ -36,6 +36,7 @@
#include <vector>
#include <set>
+#include <list>
#include "RAS_Polygon.h"
#include "RAS_MaterialBucket.h"
@@ -44,194 +45,71 @@
#include "GEN_HashedPtr.h"
struct Mesh;
-/**
- * This class holds an array of vertices and indicies.
- */
-class KX_ArrayOptimizer
-{
-public:
- KX_ArrayOptimizer(int index)
- : m_index1(index)
- {};
- virtual ~KX_ArrayOptimizer();
-
- vector<KX_VertexArray*> m_VertexArrayCache1;
- vector<int> m_TriangleArrayCount;
- vector<KX_IndexArray*> m_IndexArrayCache1;
- /**
- order in which they are stored into the mesh
- */
- int m_index1;
-};
+/* RAS_MeshObject is a mesh used for rendering. It stores polygons,
+ * but the actual vertices and index arrays are stored in material
+ * buckets, referenced by the list of RAS_MeshMaterials. */
-/**
- * This struct holds a triangle.
- */
-struct RAS_TriangleIndex
-{
-public:
- int m_index[3];
- int m_array;
- RAS_IPolyMaterial* m_matid;
- bool m_collider;
-};
-
-/**
- * This class looks horribly broken. Only m_matid is used, and
- * m_matid is a (int) RAS_IPolyMaterial*.
- * --> m_matid == lhs.m_matid should be *m_matid == *lhs.m_matid
- */
-class RAS_MatArrayIndex
-{
-public:
-
- int m_arrayindex1;
- RAS_IPolyMaterial* m_matid;
- int m_array;
- int m_index;
-
-/*
- inline bool Less(const RAS_MatArrayIndex& lhs) const {
- bool result =
- ( (m_matid < lhs.m_matid) ||
- ((m_matid == lhs.m_matid)&&(m_array < lhs.m_array)) ||
- ((m_matid == lhs.m_matid) && (m_array == lhs.m_array) &&
- (m_index < lhs.m_index))
-
- );
- return result;
-
- }
-*/
-
-};
-/*
-inline bool operator <( const RAS_MatArrayIndex& rhs,const RAS_MatArrayIndex& lhs)
-{
- return ( rhs.Less(lhs));
-}*/
-
-/**
- * RAS_MeshObject stores mesh data for the renderer.
- */
class RAS_MeshObject
{
-
- // GEN_Map<class RAS_IPolyMaterial,KX_ArrayOptimizer*> m_matVertexArrayS;
- //vector<class RAS_IPolyMaterial*,KX_ArrayOptimizer> m_vertexArrays;
- virtual KX_ArrayOptimizer* GetArrayOptimizer(RAS_IPolyMaterial* polymat);
- //vector<RAS_Polygon*> m_polygons;
-
+private:
unsigned int m_debugcolor;
- bool m_bModified;
int m_lightlayer;
-
- vector<class RAS_Polygon*> m_Polygons;
+
+ bool m_bModified;
+ bool m_bMeshModified;
+
STR_String m_name;
static STR_String s_emptyname;
- bool m_zsort;
- bool m_MeshMod;
+ vector<class RAS_Polygon*> m_Polygons;
+
+ /* polygon sorting */
struct polygonSlot;
struct backtofront;
struct fronttoback;
- void SchedulePoly(
- const KX_VertexIndex& idx,
- int numverts,
- RAS_IPolyMaterial* mat
- );
-
- void ScheduleWireframePoly(
- const KX_VertexIndex& idx,
- int numverts,
- int edgecode,
- RAS_IPolyMaterial* mat
- );
-
protected:
- enum { BUCKET_MAX_INDICES = 65535 };//2048};//8192};
- enum { BUCKET_MAX_TRIANGLES = 65535 };
-
- GEN_Map<GEN_HashedPtr,KX_ArrayOptimizer*> m_matVertexArrayS;
-
- RAS_MaterialBucket::Set m_materials;
+ list<RAS_MeshMaterial> m_materials;
Mesh* m_mesh;
+ bool m_bDeformed;
+
public:
// for now, meshes need to be in a certain layer (to avoid sorting on lights in realtime)
RAS_MeshObject(Mesh* mesh, int lightlayer);
virtual ~RAS_MeshObject();
- vector<RAS_IPolyMaterial*> m_sortedMaterials;
- vector<vector<RAS_MatArrayIndex> > m_xyz_index_to_vertex_index_mapping;
- vector<RAS_TriangleIndex > m_triangle_indices;
-
- int m_class;
- unsigned int GetLightLayer();
+ bool IsDeformed() { return m_bDeformed; }
+
+ /* materials */
int NumMaterials();
const STR_String& GetMaterialName(unsigned int matid);
- RAS_MaterialBucket* GetMaterialBucket(unsigned int matid);
const STR_String& GetTextureName(unsigned int matid);
- virtual void AddPolygon(RAS_Polygon* poly);
- void UpdateMaterialList();
-
- int NumPolygons();
- RAS_Polygon* GetPolygon(int num) const;
-
- virtual void Bucketize(
- double* oglmatrix,
- void* clientobj,
- bool useObjectColor,
- const MT_Vector4& rgbavec
- );
- void RemoveFromBuckets(
- double* oglmatrix,
- void* clientobj
- );
+ RAS_MeshMaterial* GetMeshMaterial(unsigned int matid);
+ RAS_MeshMaterial* GetMeshMaterial(RAS_IPolyMaterial *mat);
- void MarkVisible(
- double* oglmatrix,
- void* clientobj,
- bool visible,
- bool useObjectColor,
- const MT_Vector4& rgbavec
- );
+ list<RAS_MeshMaterial>::iterator GetFirstMaterial();
+ list<RAS_MeshMaterial>::iterator GetLastMaterial();
- void DebugColor(unsigned int abgr);
- void SetVertexColor(RAS_IPolyMaterial* mat,MT_Vector4 rgba);
-
- /**
- * Sorts the polygons by their transformed z values.
- */
- void SortPolygons(const MT_Transform &transform);
+ unsigned int GetLightLayer();
- void SchedulePolygons(int drawingmode);
+ /* name */
+ void SetName(STR_String name);
+ const STR_String& GetName();
- void ClearArrayData();
-
- RAS_MaterialBucket::Set::iterator GetFirstMaterial();
- RAS_MaterialBucket::Set::iterator GetLastMaterial();
-
- virtual RAS_TexVert* GetVertex(
- short array,
- unsigned int index,
- RAS_IPolyMaterial* polymat
- );
-
- virtual int FindVertexArray(
- int numverts,
- RAS_IPolyMaterial* polymat
- );
+ /* modification state */
+ bool MeshModified();
+ void SetMeshModified(bool v){m_bMeshModified = v;}
+ /* original blender mesh */
+ Mesh* GetMesh() { return m_mesh; }
+
+ /* mesh construction */
- // find (and share) or add vertices
- // for some speedup, only the last 20 added vertices are searched for equality
-
- virtual int FindOrAddVertex(
- int vtxarray,
+ virtual RAS_Polygon* AddPolygon(RAS_MaterialBucket *bucket, int numverts);
+ virtual void AddVertex(RAS_Polygon *poly, int i,
const MT_Point3& xyz,
const MT_Point2& uv,
const MT_Point2& uv2,
@@ -239,27 +117,43 @@ public:
const unsigned int rgbacolor,
const MT_Vector3& normal,
bool flat,
- RAS_IPolyMaterial* mat,
- int origindex
- );
-
- vecVertexArray& GetVertexCache (RAS_IPolyMaterial* mat);
+ int origindex);
+
+ void SchedulePolygons(int drawingmode);
+
+ /* vertex and polygon acces */
+ int NumVertices(RAS_IPolyMaterial* mat);
+ RAS_TexVert* GetVertex(unsigned int matid, unsigned int index);
+
+ int NumPolygons();
+ RAS_Polygon* GetPolygon(int num) const;
- int GetVertexArrayLength(RAS_IPolyMaterial* mat);
+ /* buckets */
+ virtual void AddMeshUser(void *clientobj);
+ virtual void UpdateBuckets(
+ void* clientobj,
+ double* oglmatrix,
+ bool useObjectColor,
+ const MT_Vector4& rgbavec,
+ bool visible,
+ bool culled);
- RAS_TexVert* GetVertex(
- unsigned int matid,
- unsigned int index
- );
+ void RemoveFromBuckets(void *clientobj);
- const vecIndexArrays& GetIndexCache (RAS_IPolyMaterial* mat);
- void SetName(STR_String name);
- const STR_String& GetName();
+ /* colors */
+ void DebugColor(unsigned int abgr);
+ void SetVertexColor(RAS_IPolyMaterial* mat,MT_Vector4 rgba);
+
+ /* polygon sorting by Z for alpha */
+ void SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transform);
- bool MeshModified();
- void SetMeshModified(bool v){m_MeshMod = v;}
- Mesh* GetMesh() { return m_mesh; }
+ /* for construction to find shared vertices */
+ struct SharedVertex {
+ RAS_DisplayArray *m_darray;
+ int m_offset;
+ };
+ vector<vector<SharedVertex> > m_sharedvertex_map;
};
#endif //__RAS_MESHOBJECT
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt
index 2a6d64ecc73..e4403ace69f 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt
@@ -32,6 +32,7 @@ SET(INC
../../../../intern/moto/include
../../../../source/gameengine/Rasterizer
../../../../extern/glew/include
+ ../../../../source/blender/gpu
)
BLENDERLIB(bf_oglrasterizer "${SRC}" "${INC}")
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/Makefile b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/Makefile
index f01978b8eb1..aee485a22be 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/Makefile
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/Makefile
@@ -41,12 +41,11 @@ CPPFLAGS += -I$(OPENGL_HEADERS)
CPPFLAGS += -I$(NAN_STRING)/include
CPPFLAGS += -I$(NAN_MOTO)/include
CPPFLAGS += -I../../../kernel/gen_system
+CPPFLAGS += -I../../../blender/gpu
CPPFLAGS += -I../../BlenderRoutines
CPPFLAGS += -I..
+
ifeq ($(OS),darwin)
CPPFLAGS += -fpascal-strings
endif
-ifeq ($(WITH_BF_GLEXT),true)
- CPPFLAGS += -DWITH_GLEXT
-endif
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp
index c2687319717..2c4b55ff964 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp
@@ -9,6 +9,7 @@
#include "GL/glew.h"
+#include "RAS_MaterialBucket.h"
#include "RAS_TexVert.h"
#include "MT_assert.h"
@@ -125,20 +126,20 @@ void RAS_ListRasterizer::RemoveListSlot(RAS_ListSlot* list)
}
}
-RAS_ListSlot* RAS_ListRasterizer::FindOrAdd(const vecVertexArray& vertexarrays, KX_ListSlot** slot)
+RAS_ListSlot* RAS_ListRasterizer::FindOrAdd(RAS_MeshSlot& ms)
{
/*
Keep a copy of constant lists submitted for rendering,
this guards against (replicated)new...delete every frame,
and we can reuse lists!
- :: sorted by vertex array
+ :: sorted by mesh slot
*/
- RAS_ListSlot* localSlot = (RAS_ListSlot*)*slot;
+ RAS_ListSlot* localSlot = (RAS_ListSlot*)ms.m_DisplayList;
if(!localSlot) {
- RAS_Lists::iterator it = mLists.find(vertexarrays);
+ RAS_Lists::iterator it = mLists.find(&ms);
if(it == mLists.end()) {
localSlot = new RAS_ListSlot(this);
- mLists.insert(std::pair<vecVertexArray, RAS_ListSlot*>(vertexarrays, localSlot));
+ mLists.insert(std::pair<RAS_MeshSlot*, RAS_ListSlot*>(&ms, localSlot));
} else {
localSlot = static_cast<RAS_ListSlot*>(it->second->AddRef());
}
@@ -157,69 +158,45 @@ void RAS_ListRasterizer::ReleaseAlloc()
mLists.clear();
}
-
-void RAS_ListRasterizer::IndexPrimitives(
- const vecVertexArray & vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
- bool useObjectColor,
- const MT_Vector4& rgbacolor,
- class KX_ListSlot** slot)
+void RAS_ListRasterizer::IndexPrimitives(RAS_MeshSlot& ms)
{
RAS_ListSlot* localSlot =0;
- // useObjectColor(are we updating every frame?)
- if(!useObjectColor && slot) {
- localSlot = FindOrAdd(vertexarrays, slot);
+ if(ms.m_bDisplayList) {
+ localSlot = FindOrAdd(ms);
localSlot->DrawList();
if(localSlot->End()) {
// save slot here too, needed for replicas and object using same mesh
// => they have the same vertexarray but different mesh slot
- *slot = localSlot;
+ ms.m_DisplayList = localSlot;
return;
}
}
- if (mUseVertexArrays) {
- RAS_VAOpenGLRasterizer::IndexPrimitives(
- vertexarrays, indexarrays,
- mode, useObjectColor,
- rgbacolor,slot
- );
- } else {
- RAS_OpenGLRasterizer::IndexPrimitives(
- vertexarrays, indexarrays,
- mode, useObjectColor,
- rgbacolor,slot
- );
- }
+ if (mUseVertexArrays)
+ RAS_VAOpenGLRasterizer::IndexPrimitives(ms);
+ else
+ RAS_OpenGLRasterizer::IndexPrimitives(ms);
- if(!useObjectColor && slot) {
+ if(ms.m_bDisplayList) {
localSlot->EndList();
- *slot = localSlot;
+ ms.m_DisplayList = localSlot;
}
}
-void RAS_ListRasterizer::IndexPrimitivesMulti(
- const vecVertexArray& vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
- bool useObjectColor,
- const MT_Vector4& rgbacolor,
- class KX_ListSlot** slot)
+void RAS_ListRasterizer::IndexPrimitivesMulti(RAS_MeshSlot& ms)
{
RAS_ListSlot* localSlot =0;
- // useObjectColor(are we updating every frame?)
- if(!useObjectColor && slot) {
- localSlot = FindOrAdd(vertexarrays, slot);
+ if(ms.m_bDisplayList) {
+ localSlot = FindOrAdd(ms);
localSlot->DrawList();
if(localSlot->End()) {
// save slot here too, needed for replicas and object using same mesh
// => they have the same vertexarray but different mesh slot
- *slot = localSlot;
+ ms.m_DisplayList = localSlot;
return;
}
}
@@ -227,23 +204,14 @@ void RAS_ListRasterizer::IndexPrimitivesMulti(
// workaround: note how we do not use vertex arrays for making display
// lists, since glVertexAttribPointerARB doesn't seem to work correct
// in display lists on ATI? either a bug in the driver or in Blender ..
- if (mUseVertexArrays && !localSlot) {
- RAS_VAOpenGLRasterizer::IndexPrimitivesMulti(
- vertexarrays, indexarrays,
- mode, useObjectColor,
- rgbacolor,slot
- );
- } else {
- RAS_OpenGLRasterizer::IndexPrimitivesMulti(
- vertexarrays, indexarrays,
- mode, useObjectColor,
- rgbacolor,slot
- );
- }
+ if (mUseVertexArrays && !localSlot)
+ RAS_VAOpenGLRasterizer::IndexPrimitivesMulti(ms);
+ else
+ RAS_OpenGLRasterizer::IndexPrimitivesMulti(ms);
- if(!useObjectColor && slot) {
+ if(ms.m_bDisplayList) {
localSlot->EndList();
- *slot = localSlot;
+ ms.m_DisplayList = localSlot;
}
}
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h
index b1b19144c12..96d6d2a995d 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h
@@ -4,6 +4,7 @@
#include "RAS_MaterialBucket.h"
#include "RAS_VAOpenGLRasterizer.h"
#include <vector>
+#include <map>
class RAS_ListRasterizer;
class RAS_ListSlot : public KX_ListSlot
@@ -34,14 +35,14 @@ enum RAS_ListSlotFlags {
LIST_REGEN =64
};
-typedef std::map<const vecVertexArray, RAS_ListSlot*> RAS_Lists;
+typedef std::map<class RAS_MeshSlot*, RAS_ListSlot*> RAS_Lists;
class RAS_ListRasterizer : public RAS_VAOpenGLRasterizer
{
bool mUseVertexArrays;
RAS_Lists mLists;
- RAS_ListSlot* FindOrAdd(const vecVertexArray& vertexarrays, KX_ListSlot** slot);
+ RAS_ListSlot* FindOrAdd(class RAS_MeshSlot& ms);
void ReleaseAlloc();
public:
@@ -49,23 +50,8 @@ public:
RAS_ListRasterizer(RAS_ICanvas* canvas, bool useVertexArrays=false, bool lock=false);
virtual ~RAS_ListRasterizer();
- virtual void IndexPrimitives(
- const vecVertexArray& vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
- bool useObjectColor,
- const MT_Vector4& rgbacolor,
- class KX_ListSlot** slot
- );
-
- virtual void IndexPrimitivesMulti(
- const vecVertexArray& vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
- bool useObjectColor,
- const MT_Vector4& rgbacolor,
- class KX_ListSlot** slot
- );
+ virtual void IndexPrimitives(class RAS_MeshSlot& ms);
+ virtual void IndexPrimitivesMulti(class RAS_MeshSlot& ms);
virtual bool Init();
virtual void Exit();
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
index 1dcc6e70934..62ee2edb731 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
@@ -38,6 +38,9 @@
#include "MT_CmMatrix4x4.h"
#include "RAS_IRenderTools.h" // rendering text
+#include "GPU_draw.h"
+#include "GPU_material.h"
+
/**
* 32x32 bit masks for vinterlace stereo mode
*/
@@ -67,10 +70,12 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas)
m_motionblurvalue(-1.0),
m_texco_num(0),
m_attrib_num(0),
- m_last_blendmode(0),
+ m_last_blendmode(GPU_BLEND_SOLID),
+ m_last_frontface(true),
m_materialCachingInfo(0)
{
- m_viewmatrix.Identity();
+ m_viewmatrix.setIdentity();
+ m_viewinvmatrix.setIdentity();
for (int i = 0; i < 32; i++)
{
@@ -87,81 +92,9 @@ RAS_OpenGLRasterizer::~RAS_OpenGLRasterizer()
{
}
-
-
-static void Myinit_gl_stuff(void)
-{
- float mat_specular[] = { 0.5, 0.5, 0.5, 1.0 };
- float mat_shininess[] = { 35.0 };
-/* float one= 1.0; */
- int a, x, y;
- GLubyte pat[32*32];
- const GLubyte *patc= pat;
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_specular);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
-
-
-#if defined(__FreeBSD) || defined(__linux__)
- glDisable(GL_DITHER); /* op sgi/sun hardware && 12 bits */
-#endif
-
- /* no local viewer, looks ugly in ortho mode */
- /* glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, &one); */
-
- glDepthFunc(GL_LEQUAL);
- /* scaling matrices */
- glEnable(GL_NORMALIZE);
-
- glShadeModel(GL_FLAT);
-
- glDisable(GL_ALPHA_TEST);
- glDisable(GL_BLEND);
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_FOG);
- glDisable(GL_LIGHTING);
- glDisable(GL_LOGIC_OP);
- glDisable(GL_STENCIL_TEST);
- glDisable(GL_TEXTURE_1D);
- glDisable(GL_TEXTURE_2D);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
-
- glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
- glPixelTransferi(GL_RED_SCALE, 1);
- glPixelTransferi(GL_RED_BIAS, 0);
- glPixelTransferi(GL_GREEN_SCALE, 1);
- glPixelTransferi(GL_GREEN_BIAS, 0);
- glPixelTransferi(GL_BLUE_SCALE, 1);
- glPixelTransferi(GL_BLUE_BIAS, 0);
- glPixelTransferi(GL_ALPHA_SCALE, 1);
- glPixelTransferi(GL_ALPHA_BIAS, 0);
-
- a = 0;
- for(x=0; x<32; x++)
- {
- for(y=0; y<4; y++)
- {
- if( (x) & 1) pat[a++]= 0x88;
- else pat[a++]= 0x22;
- }
- }
-
- glPolygonStipple(patc);
-
- glFrontFace(GL_CCW);
- glCullFace(GL_BACK);
- glEnable(GL_CULL_FACE);
-}
-
-
-
bool RAS_OpenGLRasterizer::Init()
{
-
- Myinit_gl_stuff();
+ GPU_state_init();
m_redback = 0.4375;
m_greenback = 0.4375;
@@ -172,7 +105,8 @@ bool RAS_OpenGLRasterizer::Init()
m_ambg = 0.0f;
m_ambb = 0.0f;
- SetBlendingMode(0);
+ SetBlendingMode(GPU_BLEND_SOLID);
+ SetFrontFace(true);
glClearColor(m_redback,m_greenback,m_blueback,m_alphaback);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
@@ -344,7 +278,8 @@ bool RAS_OpenGLRasterizer::BeginFrame(int drawingmode, double time)
glEnable (GL_CULL_FACE);
}
- SetBlendingMode(0);
+ SetBlendingMode(GPU_BLEND_SOLID);
+ SetFrontFace(true);
glShadeModel(GL_SMOOTH);
@@ -359,28 +294,16 @@ void RAS_OpenGLRasterizer::SetDrawingMode(int drawingmode)
{
m_drawingmode = drawingmode;
- switch (m_drawingmode)
- {
- case KX_WIREFRAME:
- {
- glDisable (GL_CULL_FACE);
- break;
- }
- default:
- {
- }
- }
+ if(m_drawingmode == KX_WIREFRAME)
+ glDisable(GL_CULL_FACE);
}
-
-
int RAS_OpenGLRasterizer::GetDrawingMode()
{
return m_drawingmode;
}
-
void RAS_OpenGLRasterizer::SetDepthMask(DepthMask depthmask)
{
glDepthMask(depthmask == KX_DEPTHMASK_DISABLED ? GL_FALSE : GL_TRUE);
@@ -573,294 +496,84 @@ void RAS_OpenGLRasterizer::SwapBuffers()
-void RAS_OpenGLRasterizer::GetViewMatrix(MT_Matrix4x4 &mat) const
+const MT_Matrix4x4& RAS_OpenGLRasterizer::GetViewMatrix() const
{
- float viewmat[16];
- glGetFloatv(GL_MODELVIEW_MATRIX, viewmat);
- mat.setValue(viewmat);
+ return m_viewmatrix;
}
-
-
-void RAS_OpenGLRasterizer::IndexPrimitives(const vecVertexArray & vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
- bool useObjectColor,
- const MT_Vector4& rgbacolor,
- class KX_ListSlot** slot
- )
-{
- const RAS_TexVert* vertexarray;
- unsigned int numindices, vt;
-
- for (vt=0;vt<vertexarrays.size();vt++)
- {
- vertexarray = &((*vertexarrays[vt]) [0]);
- const KX_IndexArray & indexarray = (*indexarrays[vt]);
- numindices = indexarray.size();
-
- if (!numindices)
- break;
-
- int vindex=0;
- switch (mode)
- {
- case KX_MODE_LINES:
- {
- glBegin(GL_LINES);
- vindex=0;
- for (unsigned int i=0;i<numindices;i+=2)
- {
- glVertex3fv(vertexarray[(indexarray[vindex++])].getLocalXYZ());
- glVertex3fv(vertexarray[(indexarray[vindex++])].getLocalXYZ());
- }
- glEnd();
- }
- break;
- case KX_MODE_QUADS:
- {
- glBegin(GL_QUADS);
- vindex=0;
- if (useObjectColor)
- {
- for (unsigned int i=0;i<numindices;i+=4)
- {
-
- glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
-
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
- }
- }
- else
- {
- for (unsigned int i=0;i<numindices;i+=4)
- {
- // This looks curiously endian unsafe to me.
- // However it depends on the way the colors are packed into
- // the m_rgba field of RAS_TexVert
-
- glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
- }
- }
- glEnd();
- break;
- }
- case KX_MODE_TRIANGLES:
- {
- glBegin(GL_TRIANGLES);
- vindex=0;
- if (useObjectColor)
- {
- for (unsigned int i=0;i<numindices;i+=3)
- {
-
- glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
-
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
- }
- }
- else
- {
- for (unsigned int i=0;i<numindices;i+=3)
- {
-
- glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
- }
- }
- glEnd();
- break;
- }
- default:
- {
- }
-
- } // switch
- } // for each vertexarray
-
+const MT_Matrix4x4& RAS_OpenGLRasterizer::GetViewInvMatrix() const
+{
+ return m_viewinvmatrix;
}
-void RAS_OpenGLRasterizer::IndexPrimitives_3DText(const vecVertexArray & vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
+void RAS_OpenGLRasterizer::IndexPrimitives_3DText(RAS_MeshSlot& ms,
class RAS_IPolyMaterial* polymat,
- class RAS_IRenderTools* rendertools,
- bool useObjectColor,
- const MT_Vector4& rgbacolor
- )
+ class RAS_IRenderTools* rendertools)
{
- const RAS_TexVert* vertexarray;
- unsigned int numindices, vt;
-
- if (useObjectColor)
- {
+ bool obcolor = ms.m_bObjectColor;
+ MT_Vector4& rgba = ms.m_RGBAcolor;
+ RAS_MeshSlot::iterator it;
+
+ // handle object color
+ if (obcolor) {
glDisableClientState(GL_COLOR_ARRAY);
- glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
+ glColor4d(rgba[0], rgba[1], rgba[2], rgba[3]);
}
else
- {
glEnableClientState(GL_COLOR_ARRAY);
- }
-
- for (vt=0;vt<vertexarrays.size();vt++)
- {
- vertexarray = &((*vertexarrays[vt]) [0]);
- const KX_IndexArray & indexarray = (*indexarrays[vt]);
- numindices = indexarray.size();
-
- if (!numindices)
- break;
+
+ for(ms.begin(it); !ms.end(it); ms.next(it)) {
+ RAS_TexVert *vertex;
+ size_t i, j, numvert;
- int vindex=0;
- switch (mode)
- {
- case KX_MODE_LINES:
- {
- glBegin(GL_LINES);
- vindex=0;
- for (unsigned int i=0;i<numindices;i+=2)
- {
- glVertex3fv(vertexarray[(indexarray[vindex++])].getLocalXYZ());
- glVertex3fv(vertexarray[(indexarray[vindex++])].getLocalXYZ());
- }
- glEnd();
- }
- break;
- case KX_MODE_QUADS:
+ numvert = it.array->m_type;
+
+ if(it.array->m_type == RAS_DisplayArray::LINE) {
+ // line drawing, no text
+ glBegin(GL_LINES);
+
+ for(i=0; i<it.totindex; i+=2)
{
- vindex=0;
- for (unsigned int i=0;i<numindices;i+=4)
- {
- float v1[3],v2[3],v3[3],v4[3];
-
- v1[0] = vertexarray[(indexarray[vindex])].getLocalXYZ()[0];
- v1[1] = vertexarray[(indexarray[vindex])].getLocalXYZ()[1];
- v1[2] = vertexarray[(indexarray[vindex])].getLocalXYZ()[2];
- vindex++;
-
- v2[0] = vertexarray[(indexarray[vindex])].getLocalXYZ()[0];
- v2[1] = vertexarray[(indexarray[vindex])].getLocalXYZ()[1];
- v2[2] = vertexarray[(indexarray[vindex])].getLocalXYZ()[2];
- vindex++;
-
- v3[0] = vertexarray[(indexarray[vindex])].getLocalXYZ()[0];
- v3[1] = vertexarray[(indexarray[vindex])].getLocalXYZ()[1];
- v3[2] = vertexarray[(indexarray[vindex])].getLocalXYZ()[2];
- vindex++;
-
- v4[0] = vertexarray[(indexarray[vindex])].getLocalXYZ()[0];
- v4[1] = vertexarray[(indexarray[vindex])].getLocalXYZ()[1];
- v4[2] = vertexarray[(indexarray[vindex])].getLocalXYZ()[2];
-
- vindex++;
-
- rendertools->RenderText(polymat->GetDrawingMode(),polymat,v1,v2,v3,v4);
- ClearCachingInfo();
- }
- break;
+ vertex = &it.vertex[it.index[i]];
+ glVertex3fv(vertex->getXYZ());
+
+ vertex = &it.vertex[it.index[i+1]];
+ glVertex3fv(vertex->getXYZ());
}
- case KX_MODE_TRIANGLES:
+
+ glEnd();
+ }
+ else {
+ // triangle and quad text drawing
+ for(i=0; i<it.totindex; i+=numvert)
{
- glBegin(GL_TRIANGLES);
- vindex=0;
- for (unsigned int i=0;i<numindices;i+=3)
- {
- float v1[3],v2[3],v3[3];
-
- v1[0] = vertexarray[(indexarray[vindex])].getLocalXYZ()[0];
- v1[1] = vertexarray[(indexarray[vindex])].getLocalXYZ()[1];
- v1[2] = vertexarray[(indexarray[vindex])].getLocalXYZ()[2];
- vindex++;
-
- v2[0] = vertexarray[(indexarray[vindex])].getLocalXYZ()[0];
- v2[1] = vertexarray[(indexarray[vindex])].getLocalXYZ()[1];
- v2[2] = vertexarray[(indexarray[vindex])].getLocalXYZ()[2];
- vindex++;
-
- v3[0] = vertexarray[(indexarray[vindex])].getLocalXYZ()[0];
- v3[1] = vertexarray[(indexarray[vindex])].getLocalXYZ()[1];
- v3[2] = vertexarray[(indexarray[vindex])].getLocalXYZ()[2];
- vindex++;
-
- rendertools->RenderText(polymat->GetDrawingMode(),polymat,v1,v2,v3,NULL);
- ClearCachingInfo();
+ float v[4][3];
+ int glattrib, unit;
+
+ for(j=0; j<numvert; j++) {
+ vertex = &it.vertex[it.index[i+j]];
+
+ v[j][0] = vertex->getXYZ()[0];
+ v[j][1] = vertex->getXYZ()[1];
+ v[j][2] = vertex->getXYZ()[2];
}
- glEnd();
- break;
- }
- default:
- {
+
+ // find the right opengl attribute
+ glattrib = -1;
+ if(GLEW_ARB_vertex_program)
+ for(unit=0; unit<m_attrib_num; unit++)
+ if(m_attrib[unit] == RAS_TEXCO_UV1)
+ glattrib = unit;
+
+ rendertools->RenderText(polymat->GetDrawingMode(), polymat,
+ v[0], v[1], v[2], (numvert == 4)? v[3]: NULL, glattrib);
+
+ ClearCachingInfo();
}
- } //switch
- } //for each vertexarray
+ }
+ }
+
+ glDisableClientState(GL_COLOR_ARRAY);
}
void RAS_OpenGLRasterizer::SetTexCoordNum(int num)
@@ -897,14 +610,14 @@ void RAS_OpenGLRasterizer::TexCoord(const RAS_TexVert &tv)
if(GLEW_ARB_multitexture) {
for(unit=0; unit<m_texco_num; unit++) {
- if(tv.getFlag() & TV_2NDUV && (int)tv.getUnit() == unit) {
+ if(tv.getFlag() & RAS_TexVert::SECOND_UV && (int)tv.getUnit() == unit) {
glMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, tv.getUV2());
continue;
}
switch(m_texco[unit]) {
case RAS_TEXCO_ORCO:
case RAS_TEXCO_GLOB:
- glMultiTexCoord3fvARB(GL_TEXTURE0_ARB+unit, tv.getLocalXYZ());
+ glMultiTexCoord3fvARB(GL_TEXTURE0_ARB+unit, tv.getXYZ());
break;
case RAS_TEXCO_UV1:
glMultiTexCoord2fvARB(GL_TEXTURE0_ARB+unit, tv.getUV1());
@@ -929,7 +642,7 @@ void RAS_OpenGLRasterizer::TexCoord(const RAS_TexVert &tv)
switch(m_attrib[unit]) {
case RAS_TEXCO_ORCO:
case RAS_TEXCO_GLOB:
- glVertexAttrib3fvARB(unit, tv.getLocalXYZ());
+ glVertexAttrib3fvARB(unit, tv.getXYZ());
break;
case RAS_TEXCO_UV1:
glVertexAttrib2fvARB(unit, tv.getUV1());
@@ -953,211 +666,80 @@ void RAS_OpenGLRasterizer::TexCoord(const RAS_TexVert &tv)
}
}
-void RAS_OpenGLRasterizer::Tangent( const RAS_TexVert& v1,
- const RAS_TexVert& v2,
- const RAS_TexVert& v3,
- const MT_Vector3 &no)
+
+void RAS_OpenGLRasterizer::IndexPrimitives(RAS_MeshSlot& ms)
{
- // TODO: set for deformer...
- MT_Vector3 x1(v1.getLocalXYZ()), x2(v2.getLocalXYZ()), x3(v3.getLocalXYZ());
- MT_Vector2 uv1(v1.getUV1()), uv2(v2.getUV1()), uv3(v3.getUV1());
- MT_Vector3 dx1(x2 - x1), dx2(x3 - x1);
- MT_Vector2 duv1(uv2 - uv1), duv2(uv3 - uv1);
-
- MT_Scalar r = 1.0 / (duv1.x() * duv2.y() - duv2.x() * duv1.y());
- duv1 *= r;
- duv2 *= r;
- MT_Vector3 sdir(duv2.y() * dx1 - duv1.y() * dx2);
- MT_Vector3 tdir(duv1.x() * dx2 - duv2.x() * dx1);
-
- // Gram-Schmidt orthogonalize
- MT_Vector3 t(sdir - no.cross(no.cross(sdir)));
- if (!MT_fuzzyZero(t)) t /= t.length();
-
- float tangent[4];
- t.getValue(tangent);
- // Calculate handedness
- tangent[3] = no.dot(sdir.cross(tdir)) < 0.0 ? -1.0 : 1.0;
+ IndexPrimitivesInternal(ms, false);
}
+void RAS_OpenGLRasterizer::IndexPrimitivesMulti(RAS_MeshSlot& ms)
+{
+ IndexPrimitivesInternal(ms, true);
+}
-void RAS_OpenGLRasterizer::IndexPrimitivesMulti(
- const vecVertexArray& vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
- bool useObjectColor,
- const MT_Vector4& rgbacolor,
- class KX_ListSlot** slot
- )
+void RAS_OpenGLRasterizer::IndexPrimitivesInternal(RAS_MeshSlot& ms, bool multi)
{
+ bool obcolor = ms.m_bObjectColor;
+ bool wireframe = m_drawingmode <= KX_WIREFRAME;
+ MT_Vector4& rgba = ms.m_RGBAcolor;
+ RAS_MeshSlot::iterator it;
+
+ // iterate over display arrays, each containing an index + vertex array
+ for(ms.begin(it); !ms.end(it); ms.next(it)) {
+ RAS_TexVert *vertex;
+ size_t i, j, numvert;
+
+ numvert = it.array->m_type;
- const RAS_TexVert* vertexarray;
- unsigned int numindices,vt;
-
- for (vt=0;vt<vertexarrays.size();vt++)
- {
- vertexarray = &((*vertexarrays[vt]) [0]);
- const KX_IndexArray & indexarray = (*indexarrays[vt]);
- numindices = indexarray.size();
-
- if (!numindices)
- break;
+ if(it.array->m_type == RAS_DisplayArray::LINE) {
+ // line drawing
+ glBegin(GL_LINES);
- int vindex=0;
- switch (mode)
- {
- case KX_MODE_LINES:
+ for(i=0; i<it.totindex; i+=2)
{
- glBegin(GL_LINES);
- vindex=0;
- for (unsigned int i=0;i<numindices;i+=2)
- {
- glVertex3fv(vertexarray[(indexarray[vindex++])].getLocalXYZ());
- glVertex3fv(vertexarray[(indexarray[vindex++])].getLocalXYZ());
- }
- glEnd();
+ vertex = &it.vertex[it.index[i]];
+ glVertex3fv(vertex->getXYZ());
+
+ vertex = &it.vertex[it.index[i+1]];
+ glVertex3fv(vertex->getXYZ());
}
- break;
- case KX_MODE_QUADS:
- {
+
+ glEnd();
+ }
+ else {
+ // triangle and quad drawing
+ if(it.array->m_type == RAS_DisplayArray::TRIANGLE)
+ glBegin(GL_TRIANGLES);
+ else
glBegin(GL_QUADS);
- vindex=0;
- if (useObjectColor)
- {
- for (unsigned int i=0;i<numindices;i+=4)
- {
-
- glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
-
- //
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- TexCoord(vertexarray[(indexarray[vindex])]);
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- //
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- TexCoord(vertexarray[(indexarray[vindex])]);
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- //
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- TexCoord(vertexarray[(indexarray[vindex])]);
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- //
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- TexCoord(vertexarray[(indexarray[vindex])]);
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
- }
- }
- else
- {
- for (unsigned int i=0;i<numindices;i+=4)
- {
- // This looks curiously endian unsafe to me.
- // However it depends on the way the colors are packed into
- // the m_rgba field of RAS_TexVert
-
- //
- glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
-
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- TexCoord(vertexarray[(indexarray[vindex])]);
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- //
- glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- TexCoord(vertexarray[(indexarray[vindex])]);
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- //
- glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- TexCoord(vertexarray[(indexarray[vindex])]);
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- //
- glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- TexCoord(vertexarray[(indexarray[vindex])]);
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
- }
- }
- glEnd();
- break;
- }
- case KX_MODE_TRIANGLES:
+
+ for(i=0; i<it.totindex; i+=numvert)
{
- glBegin(GL_TRIANGLES);
- vindex=0;
- if (useObjectColor)
- {
- for (unsigned int i=0;i<numindices;i+=3)
- {
-
- glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
- //
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- TexCoord(vertexarray[(indexarray[vindex])]);
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- //
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- TexCoord(vertexarray[(indexarray[vindex])]);
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- //
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- TexCoord(vertexarray[(indexarray[vindex])]);
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
- }
- }
- else
- {
- for (unsigned int i=0;i<numindices;i+=3)
- {
- //
- glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- TexCoord(vertexarray[(indexarray[vindex])]);
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- //
- glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- TexCoord(vertexarray[(indexarray[vindex])]);
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
-
- //
- glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
- glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
- TexCoord(vertexarray[(indexarray[vindex])]);
- glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
- vindex++;
+ if(obcolor)
+ glColor4d(rgba[0], rgba[1], rgba[2], rgba[3]);
+
+ for(j=0; j<numvert; j++) {
+ vertex = &it.vertex[it.index[i+j]];
+
+ if(!wireframe) {
+ if(!obcolor)
+ glColor4ubv((const GLubyte *)(vertex->getRGBA()));
+
+ glNormal3fv(vertex->getNormal());
+
+ if(multi)
+ TexCoord(*vertex);
+ else
+ glTexCoord2fv(vertex->getUV1());
}
+
+ glVertex3fv(vertex->getXYZ());
}
- glEnd();
- break;
- }
- default:
- {
}
- } // switch
- } // for each vertexarray
+
+ glEnd();
+ }
+ }
}
void RAS_OpenGLRasterizer::SetProjectionMatrix(MT_CmMatrix4x4 &mat)
@@ -1232,7 +814,7 @@ MT_Matrix4x4 RAS_OpenGLRasterizer::GetFrustumMatrix(
void RAS_OpenGLRasterizer::SetViewMatrix(const MT_Matrix4x4 &mat, const MT_Vector3& campos,
const MT_Point3 &, const MT_Quaternion &camOrientQuat)
{
- MT_Matrix4x4 viewMat = mat;
+ m_viewmatrix = mat;
// correction for stereo
if(m_stereomode != RAS_STEREO_NOSTEREO)
@@ -1259,7 +841,7 @@ void RAS_OpenGLRasterizer::SetViewMatrix(const MT_Matrix4x4 &mat, const MT_Vecto
MT_Transform transform;
transform.setIdentity();
transform.translate(-(eyeline * m_eyeseparation / 2.0));
- viewMat *= transform;
+ m_viewmatrix *= transform;
}
break;
case RAS_STEREO_RIGHTEYE:
@@ -1268,20 +850,21 @@ void RAS_OpenGLRasterizer::SetViewMatrix(const MT_Matrix4x4 &mat, const MT_Vecto
MT_Transform transform;
transform.setIdentity();
transform.translate(eyeline * m_eyeseparation / 2.0);
- viewMat *= transform;
+ m_viewmatrix *= transform;
}
break;
}
}
- // convert row major matrix 'viewMat' to column major for OpenGL
- MT_Scalar cammat[16];
- viewMat.getValue(cammat);
- MT_CmMatrix4x4 viewCmmat = cammat;
+ m_viewinvmatrix = m_viewmatrix;
+ m_viewinvmatrix.invert();
+
+ // note: getValue gives back column major as needed by OpenGL
+ MT_Scalar glviewmat[16];
+ m_viewmatrix.getValue(glviewmat);
glMatrixMode(GL_MODELVIEW);
- m_viewmatrix = viewCmmat;
- glLoadMatrixd(&m_viewmatrix(0,0));
+ glLoadMatrixd(glviewmat);
m_campos = campos;
}
@@ -1292,20 +875,6 @@ const MT_Point3& RAS_OpenGLRasterizer::GetCameraPosition()
}
-
-void RAS_OpenGLRasterizer::LoadViewMatrix()
-{
- glLoadMatrixd(&m_viewmatrix(0,0));
-}
-
-
-
-void RAS_OpenGLRasterizer::EnableTextures(bool enable)
-{
-}
-
-
-
void RAS_OpenGLRasterizer::SetCullFace(bool enable)
{
if (enable)
@@ -1388,23 +957,23 @@ void RAS_OpenGLRasterizer::SetBlendingMode(int blendmode)
if(blendmode == m_last_blendmode)
return;
- if(blendmode == 0) {
+ if(blendmode == GPU_BLEND_SOLID) {
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
- else if(blendmode == 1) {
+ else if(blendmode == GPU_BLEND_ADD) {
glBlendFunc(GL_ONE, GL_ONE);
glEnable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
}
- else if(blendmode == 2) {
+ else if(blendmode == GPU_BLEND_ALPHA) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);
}
- else if(blendmode == 4) {
+ else if(blendmode == GPU_BLEND_CLIP) {
glDisable(GL_BLEND);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.5f);
@@ -1413,3 +982,16 @@ void RAS_OpenGLRasterizer::SetBlendingMode(int blendmode)
m_last_blendmode = blendmode;
}
+void RAS_OpenGLRasterizer::SetFrontFace(bool ccw)
+{
+ if(m_last_frontface == ccw)
+ return;
+
+ if(ccw)
+ glFrontFace(GL_CCW);
+ else
+ glFrontFace(GL_CW);
+
+ m_last_frontface = ccw;
+}
+
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
index 02056cce446..368bd4312ac 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
@@ -41,7 +41,7 @@ using namespace std;
#include "RAS_MaterialBucket.h"
#include "RAS_ICanvas.h"
-#define RAS_MAX_TEXCO 3 // match in BL_Material
+#define RAS_MAX_TEXCO 8 // match in BL_Material
#define RAS_MAX_ATTRIB 16 // match in BL_BlenderShader
struct OglDebugLine
@@ -77,7 +77,8 @@ class RAS_OpenGLRasterizer : public RAS_IRasterizer
float m_ambb;
double m_time;
- MT_CmMatrix4x4 m_viewmatrix;
+ MT_Matrix4x4 m_viewmatrix;
+ MT_Matrix4x4 m_viewinvmatrix;
MT_Point3 m_campos;
StereoMode m_stereomode;
@@ -100,6 +101,7 @@ protected:
int m_texco_num;
int m_attrib_num;
int m_last_blendmode;
+ bool m_last_frontface;
/** Stores the caching information for the last material activated. */
RAS_IPolyMaterial::TCachingInfo m_materialCachingInfo;
@@ -144,33 +146,15 @@ public:
virtual float GetFocalLength();
virtual void SwapBuffers();
- virtual void IndexPrimitives(
- const vecVertexArray& vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
- bool useObjectColor,
- const MT_Vector4& rgbacolor,
- class KX_ListSlot** slot
- );
+ virtual void IndexPrimitives(class RAS_MeshSlot& ms);
+ virtual void IndexPrimitivesMulti(class RAS_MeshSlot& ms);
virtual void IndexPrimitives_3DText(
- const vecVertexArray& vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
+ class RAS_MeshSlot& ms,
class RAS_IPolyMaterial* polymat,
- class RAS_IRenderTools* rendertools,
- bool useObjectColor,
- const MT_Vector4& rgbacolor
- );
-
- virtual void IndexPrimitivesMulti(
- const vecVertexArray& vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
- bool useObjectColor,
- const MT_Vector4& rgbacolor,
- class KX_ListSlot** slot);
+ class RAS_IRenderTools* rendertools);
+ void IndexPrimitivesInternal(RAS_MeshSlot& ms, bool multi);
virtual void SetProjectionMatrix(MT_CmMatrix4x4 & mat);
virtual void SetProjectionMatrix(const MT_Matrix4x4 & mat);
@@ -182,7 +166,6 @@ public:
);
virtual const MT_Point3& GetCameraPosition();
- virtual void LoadViewMatrix();
virtual void SetFog(
float start,
@@ -214,7 +197,6 @@ public:
virtual void SetDrawingMode(int drawingmode);
virtual int GetDrawingMode();
- virtual void EnableTextures(bool enable);
virtual void SetCullFace(bool enable);
virtual void SetLines(bool enable);
@@ -270,13 +252,10 @@ public:
virtual void SetTexCoord(TexCoGen coords, int unit);
virtual void SetAttrib(TexCoGen coords, int unit);
- void TexCoord(const RAS_TexVert &tv);
- virtual void GetViewMatrix(MT_Matrix4x4 &mat) const;
+ void TexCoord(const RAS_TexVert &tv);
- void Tangent(const RAS_TexVert& v1,
- const RAS_TexVert& v2,
- const RAS_TexVert& v3,
- const MT_Vector3 &no);
+ const MT_Matrix4x4& GetViewMatrix() const;
+ const MT_Matrix4x4& GetViewInvMatrix() const;
virtual void EnableMotionBlur(float motionblurvalue);
virtual void DisableMotionBlur();
@@ -293,6 +272,7 @@ public:
};
virtual void SetBlendingMode(int blendmode);
+ virtual void SetFrontFace(bool ccw);
};
#endif //__RAS_OPENGLRASTERIZER
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.cpp
index c78a97ad7be..2cb3b52adfb 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.cpp
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.cpp
@@ -33,6 +33,7 @@
#include <stdlib.h>
#include "GL/glew.h"
+#include "GPU_extensions.h"
#include "STR_String.h"
#include "RAS_TexVert.h"
@@ -77,16 +78,16 @@ void RAS_VAOpenGLRasterizer::SetDrawingMode(int drawingmode)
{
case KX_BOUNDINGBOX:
case KX_WIREFRAME:
- glDisableClientState(GL_COLOR_ARRAY);
- glDisable(GL_CULL_FACE);
+ //glDisableClientState(GL_COLOR_ARRAY);
+ //glDisable(GL_CULL_FACE);
break;
case KX_SOLID:
- glDisableClientState(GL_COLOR_ARRAY);
+ //glDisableClientState(GL_COLOR_ARRAY);
break;
case KX_TEXTURED:
case KX_SHADED:
case KX_SHADOW:
- glEnableClientState(GL_COLOR_ARRAY);
+ //glEnableClientState(GL_COLOR_ARRAY);
default:
break;
}
@@ -98,141 +99,121 @@ void RAS_VAOpenGLRasterizer::Exit()
glEnableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
- EnableTextures(false);
RAS_OpenGLRasterizer::Exit();
}
-void RAS_VAOpenGLRasterizer::IndexPrimitives( const vecVertexArray& vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
- bool useObjectColor,
- const MT_Vector4& rgbacolor,
- class KX_ListSlot** slot)
+void RAS_VAOpenGLRasterizer::IndexPrimitives(RAS_MeshSlot& ms)
{
- static const GLsizei vtxstride = sizeof(RAS_TexVert);
+ static const GLsizei stride = sizeof(RAS_TexVert);
+ bool wireframe = m_drawingmode <= KX_WIREFRAME;
+ RAS_MeshSlot::iterator it;
GLenum drawmode;
- if(mode == KX_MODE_TRIANGLES)
- drawmode = GL_TRIANGLES;
- else if(mode == KX_MODE_QUADS)
- drawmode = GL_QUADS;
- else
- drawmode = GL_LINES;
- const RAS_TexVert* vertexarray;
- unsigned int numindices, vt;
-
- if (drawmode != GL_LINES)
- {
- if (useObjectColor)
- {
- glDisableClientState(GL_COLOR_ARRAY);
- glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
- } else
- {
- glColor4d(0,0,0,1.0);
- glEnableClientState(GL_COLOR_ARRAY);
- }
- }
- else
- {
- glColor3d(0,0,0);
- }
-
- EnableTextures(false);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ if(!wireframe)
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// use glDrawElements to draw each vertexarray
- for (vt=0;vt<vertexarrays.size();vt++)
- {
- vertexarray = &((*vertexarrays[vt]) [0]);
- const KX_IndexArray & indexarray = (*indexarrays[vt]);
- numindices = indexarray.size();
-
- if (!numindices)
+ for(ms.begin(it); !ms.end(it); ms.next(it)) {
+ if(it.totindex == 0)
continue;
-
- glVertexPointer(3,GL_FLOAT,vtxstride,vertexarray->getLocalXYZ());
- glNormalPointer(GL_FLOAT,vtxstride,vertexarray->getNormal());
- glTexCoordPointer(2,GL_FLOAT,vtxstride,vertexarray->getUV1());
- if(glIsEnabled(GL_COLOR_ARRAY))
- glColorPointer(4,GL_UNSIGNED_BYTE,vtxstride,vertexarray->getRGBA());
- //if(m_Lock)
- // local->Begin(vertexarrays[vt]->size());
+ // drawing mode
+ if(it.array->m_type == RAS_DisplayArray::TRIANGLE)
+ drawmode = GL_TRIANGLES;
+ else if(it.array->m_type == RAS_DisplayArray::QUAD)
+ drawmode = GL_QUADS;
+ else
+ drawmode = GL_LINES;
+
+ // colors
+ if (drawmode != GL_LINES && !wireframe) {
+ if (ms.m_bObjectColor) {
+ const MT_Vector4& rgba = ms.m_RGBAcolor;
- // here the actual drawing takes places
- glDrawElements(drawmode,numindices,GL_UNSIGNED_SHORT,&(indexarray[0]));
+ glDisableClientState(GL_COLOR_ARRAY);
+ glColor4d(rgba[0], rgba[1], rgba[2], rgba[3]);
+ }
+ else {
+ glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
+ glEnableClientState(GL_COLOR_ARRAY);
+ }
+ }
+ else
+ glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
+
+ glVertexPointer(3, GL_FLOAT, stride, it.vertex->getXYZ());
+ glNormalPointer(GL_FLOAT, stride, it.vertex->getNormal());
+ if(!wireframe) {
+ glTexCoordPointer(2, GL_FLOAT, stride, it.vertex->getUV1());
+ if(glIsEnabled(GL_COLOR_ARRAY))
+ glColorPointer(4, GL_UNSIGNED_BYTE, stride, it.vertex->getRGBA());
+ }
- //if(m_Lock)
- // local->End();
+ // here the actual drawing takes places
+ glDrawElements(drawmode, it.totindex, GL_UNSIGNED_SHORT, it.index);
}
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ if(!wireframe) {
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ }
}
-void RAS_VAOpenGLRasterizer::IndexPrimitivesMulti( const vecVertexArray& vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
- bool useObjectColor,
- const MT_Vector4& rgbacolor,
- class KX_ListSlot** slot)
+void RAS_VAOpenGLRasterizer::IndexPrimitivesMulti(RAS_MeshSlot& ms)
{
- static const GLsizei vtxstride = sizeof(RAS_TexVert);
-
+ static const GLsizei stride = sizeof(RAS_TexVert);
+ bool wireframe = m_drawingmode <= KX_WIREFRAME;
+ RAS_MeshSlot::iterator it;
GLenum drawmode;
- if(mode == KX_MODE_TRIANGLES)
- drawmode = GL_TRIANGLES;
- else if(mode == KX_MODE_QUADS)
- drawmode = GL_QUADS;
- else
- drawmode = GL_LINES;
- const RAS_TexVert* vertexarray;
- unsigned int numindices, vt;
-
- if (drawmode != GL_LINES)
- {
- if (useObjectColor)
- {
- glDisableClientState(GL_COLOR_ARRAY);
- glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
- }
- else
- {
- glColor4d(0,0,0,1.0);
- glEnableClientState(GL_COLOR_ARRAY);
- }
- }
- else
- {
- glColor3d(0,0,0);
- }
+ if(!wireframe)
+ EnableTextures(true);
// use glDrawElements to draw each vertexarray
- for (vt=0;vt<vertexarrays.size();vt++)
- {
- vertexarray = &((*vertexarrays[vt]) [0]);
- const KX_IndexArray & indexarray = (*indexarrays[vt]);
- numindices = indexarray.size();
-
- if (!numindices)
+ for(ms.begin(it); !ms.end(it); ms.next(it)) {
+ if(it.totindex == 0)
continue;
- glVertexPointer(3,GL_FLOAT,vtxstride,vertexarray->getLocalXYZ());
- glNormalPointer(GL_FLOAT,vtxstride,vertexarray->getNormal());
- TexCoordPtr(vertexarray);
- if(glIsEnabled(GL_COLOR_ARRAY))
- glColorPointer(4,GL_UNSIGNED_BYTE,vtxstride,vertexarray->getRGBA());
+ // drawing mode
+ if(it.array->m_type == RAS_DisplayArray::TRIANGLE)
+ drawmode = GL_TRIANGLES;
+ else if(it.array->m_type == RAS_DisplayArray::QUAD)
+ drawmode = GL_QUADS;
+ else
+ drawmode = GL_LINES;
+
+ // colors
+ if (drawmode != GL_LINES && !wireframe) {
+ if (ms.m_bObjectColor) {
+ const MT_Vector4& rgba = ms.m_RGBAcolor;
- //if(m_Lock)
- // local->Begin(vertexarrays[vt]->size());
+ glDisableClientState(GL_COLOR_ARRAY);
+ glColor4d(rgba[0], rgba[1], rgba[2], rgba[3]);
+ }
+ else {
+ glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
+ glEnableClientState(GL_COLOR_ARRAY);
+ }
+ }
+ else
+ glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
+
+ glVertexPointer(3, GL_FLOAT, stride, it.vertex->getXYZ());
+ glNormalPointer(GL_FLOAT, stride, it.vertex->getNormal());
+ if(!wireframe) {
+ TexCoordPtr(it.vertex);
+ if(glIsEnabled(GL_COLOR_ARRAY))
+ glColorPointer(4, GL_UNSIGNED_BYTE, stride, it.vertex->getRGBA());
+ }
// here the actual drawing takes places
- glDrawElements(drawmode,numindices,GL_UNSIGNED_SHORT,&(indexarray[0]));
-
- //if(m_Lock)
- // local->End();
+ glDrawElements(drawmode, it.totindex, GL_UNSIGNED_SHORT, it.index);
+ }
+
+ if(!wireframe) {
+ glDisableClientState(GL_COLOR_ARRAY);
+ EnableTextures(false);
}
}
@@ -248,7 +229,7 @@ void RAS_VAOpenGLRasterizer::TexCoordPtr(const RAS_TexVert *tv)
for(unit=0; unit<m_texco_num; unit++)
{
glClientActiveTextureARB(GL_TEXTURE0_ARB+unit);
- if(tv->getFlag() & TV_2NDUV && (int)tv->getUnit() == unit) {
+ if(tv->getFlag() & RAS_TexVert::SECOND_UV && (int)tv->getUnit() == unit) {
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(RAS_TexVert), tv->getUV2());
continue;
@@ -257,7 +238,7 @@ void RAS_VAOpenGLRasterizer::TexCoordPtr(const RAS_TexVert *tv)
{
case RAS_TEXCO_ORCO:
case RAS_TEXCO_GLOB:
- glTexCoordPointer(3, GL_FLOAT, sizeof(RAS_TexVert),tv->getLocalXYZ());
+ glTexCoordPointer(3, GL_FLOAT, sizeof(RAS_TexVert),tv->getXYZ());
break;
case RAS_TEXCO_UV1:
glTexCoordPointer(2, GL_FLOAT, sizeof(RAS_TexVert),tv->getUV1());
@@ -284,7 +265,7 @@ void RAS_VAOpenGLRasterizer::TexCoordPtr(const RAS_TexVert *tv)
switch(m_attrib[unit]) {
case RAS_TEXCO_ORCO:
case RAS_TEXCO_GLOB:
- glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getLocalXYZ());
+ glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getXYZ());
break;
case RAS_TEXCO_UV1:
glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getUV1());
@@ -313,11 +294,6 @@ void RAS_VAOpenGLRasterizer::EnableTextures(bool enable)
TexCoGen *texco, *attrib;
int unit, texco_num, attrib_num;
- /* disable previously enabled texture coordinates and attributes. ideally
- * this shouldn't be necessary .. */
- if(enable)
- EnableTextures(false);
-
/* we cache last texcoords and attribs to ensure we disable the ones that
* were actually last set */
if(enable) {
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h
index e4cc4ace0e8..766bbfbed0e 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h
@@ -50,22 +50,10 @@ public:
virtual void SetDrawingMode(int drawingmode);
- virtual void IndexPrimitives( const vecVertexArray& vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
- bool useObjectColor,
- const MT_Vector4& rgbacolor,
- class KX_ListSlot** slot);
-
- virtual void IndexPrimitivesMulti(
- const vecVertexArray& vertexarrays,
- const vecIndexArrays & indexarrays,
- DrawMode mode,
- bool useObjectColor,
- const MT_Vector4& rgbacolor,
- class KX_ListSlot** slot);
-
+ virtual void IndexPrimitives(class RAS_MeshSlot& ms);
+ virtual void IndexPrimitivesMulti(class RAS_MeshSlot& ms);
+private:
virtual void EnableTextures(bool enable);
//virtual bool QueryArrays(){return true;}
//virtual bool QueryLists(){return m_Lock;}
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/SConscript b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/SConscript
index 0cf9c326370..8d46528f7f0 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/SConscript
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/SConscript
@@ -1,12 +1,9 @@
#!/usr/bin/python
Import ('env')
-if env['WITH_BF_GLEXT'] == 1:
- env['CPPFLAGS'].append('-DWITH_GLEXT')
-
sources = env.Glob('*.cpp')
incs = '. #source/kernel/gen_system #intern/string #intern/moto/include #source/gameengine/Rasterizer #source/gameengine/BlenderRoutines '
-incs += ' #extern/glew/include ' + env['BF_OPENGL_INC']
+incs += ' #source/blender/gpu #extern/glew/include ' + env['BF_OPENGL_INC']
env.BlenderLib ( 'bf_oglrasterizer', Split(sources), Split(incs), [], libtype=['game','player'], priority=[40, 120] )
diff --git a/source/gameengine/Rasterizer/RAS_Polygon.cpp b/source/gameengine/Rasterizer/RAS_Polygon.cpp
index b74cb9cfcac..50331d7a664 100644
--- a/source/gameengine/Rasterizer/RAS_Polygon.cpp
+++ b/source/gameengine/Rasterizer/RAS_Polygon.cpp
@@ -26,99 +26,82 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#ifdef WIN32
-
#pragma warning (disable:4786)
#endif
#include "RAS_Polygon.h"
-RAS_Polygon::RAS_Polygon(RAS_MaterialBucket* bucket,
- bool visible,
- int numverts,
- int vtxarrayindex)
- :m_bucket(bucket),
- m_vertexindexbase(numverts),
- m_numverts(numverts),
- m_edgecode(65535)
+RAS_Polygon::RAS_Polygon(RAS_MaterialBucket* bucket, RAS_DisplayArray *darray, int numvert)
{
- m_vertexindexbase.m_vtxarray = vtxarrayindex ;//m_bucket->FindVertexArray(numverts);
- m_polyFlags.Visible = visible;
-}
-
+ m_bucket = bucket;
+ m_darray = darray;
+ m_offset[0]= m_offset[1]= m_offset[2]= m_offset[3]= 0;
+ m_numvert = numvert;
+ m_edgecode = 255;
+ m_polyflags = 0;
+}
int RAS_Polygon::VertexCount()
{
- return m_numverts;
+ return m_numvert;
}
-
-
-void RAS_Polygon::SetVertex(int i,
- unsigned int vertexindex ) //const MT_Point3& xyz,const MT_Point2& uv,const unsigned int rgbacolor,const MT_Vector3& normal)
+void RAS_Polygon::SetVertexOffset(int i, unsigned short offset)
{
- m_vertexindexbase.SetIndex(i,vertexindex); //m_bucket->FindOrAddVertex(m_vertexindexbase.m_vtxarray,
- //xyz,uv,rgbacolor,normal));
+ m_offset[i] = offset;
}
-
-
-const KX_VertexIndex& RAS_Polygon::GetIndexBase()
+RAS_TexVert *RAS_Polygon::GetVertex(int i)
{
- return m_vertexindexbase;
+ return &m_darray->m_vertex[m_offset[i]];
}
-
-
-void RAS_Polygon::SetVisibleWireframeEdges(int edgecode)
+int RAS_Polygon::GetVertexOffset(int i)
{
- m_edgecode = edgecode;
+ return m_offset[i];
}
-
-
-// each bit is for a visible edge, starting with bit 1 for the first edge, bit 2 for second etc.
int RAS_Polygon::GetEdgeCode()
{
return m_edgecode;
}
+void RAS_Polygon::SetEdgeCode(int edgecode)
+{
+ m_edgecode = edgecode;
+}
bool RAS_Polygon::IsVisible()
{
- return m_polyFlags.Visible;
+ return (m_polyflags & VISIBLE) != 0;
}
-
+void RAS_Polygon::SetVisible(bool visible)
+{
+ if(visible) m_polyflags |= VISIBLE;
+ else m_polyflags &= ~VISIBLE;
+}
bool RAS_Polygon::IsCollider()
{
- return m_polyFlags.Collider;
+ return (m_polyflags & COLLIDER) != 0;
}
-
-
-void RAS_Polygon::SetCollider(bool col)
+void RAS_Polygon::SetCollider(bool visible)
{
- m_polyFlags.Collider = col;
+ if(visible) m_polyflags |= COLLIDER;
+ else m_polyflags &= ~COLLIDER;
}
-
-
-KX_VertexIndex& RAS_Polygon::GetVertexIndexBase()
+RAS_MaterialBucket* RAS_Polygon::GetMaterial()
{
- return m_vertexindexbase;
+ return m_bucket;
}
-
-
-RAS_MaterialBucket* RAS_Polygon::GetMaterial()
+RAS_DisplayArray* RAS_Polygon::GetDisplayArray()
{
- return m_bucket;
+ return m_darray;
}
diff --git a/source/gameengine/Rasterizer/RAS_Polygon.h b/source/gameengine/Rasterizer/RAS_Polygon.h
index 7ce7926a816..18526ba45f7 100644
--- a/source/gameengine/Rasterizer/RAS_Polygon.h
+++ b/source/gameengine/Rasterizer/RAS_Polygon.h
@@ -35,55 +35,47 @@
#include <vector>
using namespace std;
-
-//
-// Bitfield that stores the flags for each CValue derived class
-//
-struct PolygonFlags {
- PolygonFlags() :
- Visible(true),
- Collider(true)
- {
- }
- unsigned char Visible : 1;
- unsigned char Collider : 1;
- //int Visible : 1;
- //int Collider : 1;
-};
+/* polygon flags */
class RAS_Polygon
{
+ /* location */
RAS_MaterialBucket* m_bucket;
- KX_VertexIndex m_vertexindexbase;
- int m_numverts;
- int m_edgecode;
- PolygonFlags m_polyFlags;
-
+ RAS_DisplayArray* m_darray;
+ unsigned short m_offset[4];
+ unsigned short m_numvert;
+
+ /* flags */
+ unsigned char m_edgecode;
+ unsigned char m_polyflags;
public:
- RAS_Polygon(RAS_MaterialBucket* bucket,
- bool visible,
- int numverts,
- int vtxarrayindex) ;
+ enum {
+ VISIBLE = 1,
+ COLLIDER = 2
+ };
+
+ RAS_Polygon(RAS_MaterialBucket* bucket, RAS_DisplayArray* darray, int numvert);
virtual ~RAS_Polygon() {};
-// RAS_TexVert* GetVertex(int index);
int VertexCount();
- void SetVertex(int i, unsigned int vertexindex); //const MT_Point3& xyz,const MT_Point2& uv,const unsigned int rgbacolor,const MT_Vector3& normal)
-
- const KX_VertexIndex& GetIndexBase();
+ RAS_TexVert* GetVertex(int i);
- void SetVisibleWireframeEdges(int edgecode);
+ void SetVertexOffset(int i, unsigned short offset);
+ int GetVertexOffset(int i);
+
// each bit is for a visible edge, starting with bit 1 for the first edge, bit 2 for second etc.
int GetEdgeCode();
+ void SetEdgeCode(int edgecode);
bool IsVisible();
+ void SetVisible(bool visible);
+
bool IsCollider();
- void SetCollider(bool col);
+ void SetCollider(bool collider);
- KX_VertexIndex& GetVertexIndexBase();
RAS_MaterialBucket* GetMaterial();
-
+ RAS_DisplayArray* GetDisplayArray();
};
#endif
diff --git a/source/gameengine/Rasterizer/RAS_TexVert.cpp b/source/gameengine/Rasterizer/RAS_TexVert.cpp
index 935633dc636..d6f1fe912be 100644
--- a/source/gameengine/Rasterizer/RAS_TexVert.cpp
+++ b/source/gameengine/Rasterizer/RAS_TexVert.cpp
@@ -27,12 +27,7 @@
*/
#include "RAS_TexVert.h"
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#define SHORT(x) short(x*32767.0)
+#include "MT_Matrix4x4.h"
RAS_TexVert::RAS_TexVert(const MT_Point3& xyz,
const MT_Point2& uv,
@@ -40,7 +35,7 @@ RAS_TexVert::RAS_TexVert(const MT_Point3& xyz,
const MT_Vector4& tangent,
const unsigned int rgba,
const MT_Vector3& normal,
- const short flag,
+ const bool flat,
const unsigned int origindex)
{
xyz.getValue(m_localxyz);
@@ -49,7 +44,7 @@ RAS_TexVert::RAS_TexVert(const MT_Point3& xyz,
SetRGBA(rgba);
SetNormal(normal);
tangent.getValue(m_tangent);
- m_flag = flag;
+ m_flag = (flat)? FLAT: 0;
m_origindex = origindex;
m_unit = 2;
}
@@ -101,7 +96,7 @@ void RAS_TexVert::SetFlag(const short flag)
void RAS_TexVert::SetUnit(const unsigned int u)
{
- m_unit = u<=TV_MAX?u:TV_MAX;
+ m_unit = u<=MAX_UNIT?u:MAX_UNIT;
}
void RAS_TexVert::SetNormal(const MT_Vector3& normal)
@@ -109,12 +104,18 @@ void RAS_TexVert::SetNormal(const MT_Vector3& normal)
normal.getValue(m_normal);
}
+void RAS_TexVert::SetTangent(const MT_Vector3& tangent)
+{
+ tangent.getValue(m_tangent);
+}
+
// compare two vertices, and return TRUE if both are almost identical (they can be shared)
bool RAS_TexVert::closeTo(const RAS_TexVert* other)
{
return (m_flag == other->m_flag &&
m_rgba == other->m_rgba &&
MT_fuzzyEqual(MT_Vector3(m_normal), MT_Vector3(other->m_normal)) &&
+ MT_fuzzyEqual(MT_Vector3(m_tangent), MT_Vector3(other->m_tangent)) &&
MT_fuzzyEqual(MT_Vector2(m_uv1), MT_Vector2(other->m_uv1)) &&
MT_fuzzyEqual(MT_Vector2(m_uv2), MT_Vector2(other->m_uv2)) && // p --
MT_fuzzyEqual(MT_Vector3(m_localxyz), MT_Vector3(other->m_localxyz))) ;
@@ -131,11 +132,10 @@ unsigned int RAS_TexVert::getUnit() const
return m_unit;
}
-
-void RAS_TexVert::getOffsets(void* &xyz, void* &uv1, void* &rgba, void* &normal) const
+void RAS_TexVert::Transform(const MT_Matrix4x4& mat, const MT_Matrix4x4& nmat)
{
- xyz = (void *) m_localxyz;
- uv1 = (void *) m_uv1;
- rgba = (void *) &m_rgba;
- normal = (void *) m_normal;
+ SetXYZ((mat*MT_Vector4(m_localxyz[0], m_localxyz[1], m_localxyz[2], 1.0)).getValue());
+ SetNormal((nmat*MT_Vector4(m_normal[0], m_normal[1], m_normal[2], 1.0)).getValue());
+ SetTangent((nmat*MT_Vector4(m_tangent[0], m_tangent[1], m_tangent[2], 1.0)).getValue());
}
+
diff --git a/source/gameengine/Rasterizer/RAS_TexVert.h b/source/gameengine/Rasterizer/RAS_TexVert.h
index bf092b4b230..4ec4db19e53 100644
--- a/source/gameengine/Rasterizer/RAS_TexVert.h
+++ b/source/gameengine/Rasterizer/RAS_TexVert.h
@@ -37,11 +37,6 @@
static MT_Point3 g_pt3;
static MT_Point2 g_pt2;
-#define TV_CALCFACENORMAL 0x0001
-#define TV_2NDUV 0x0002
-
-#define TV_MAX 3//match Def in BL_Material.h
-
class RAS_TexVert
{
@@ -59,6 +54,12 @@ class RAS_TexVert
// 32 bytes total size, fits nice = 56 = not fit nice.
// We'll go for 64 bytes total size - 24 bytes left.
public:
+ enum {
+ FLAT = 1,
+ SECOND_UV = 2,
+ MAX_UNIT = 8
+ };
+
short getFlag() const;
unsigned int getUnit() const;
@@ -70,7 +71,7 @@ public:
const MT_Vector4& tangent,
const unsigned int rgba,
const MT_Vector3& normal,
- const short flag,
+ const bool flat,
const unsigned int origindex);
~RAS_TexVert() {};
@@ -82,7 +83,7 @@ public:
return m_uv2;
};
- const float* getLocalXYZ() const {
+ const float* getXYZ() const {
return m_localxyz;
};
@@ -108,20 +109,19 @@ public:
void SetRGBA(const unsigned int rgba);
void SetNormal(const MT_Vector3& normal);
+ void SetTangent(const MT_Vector3& tangent);
void SetFlag(const short flag);
void SetUnit(const unsigned u);
void SetRGBA(const MT_Vector4& rgba);
const MT_Point3& xyz();
- // compare two vertices, and return TRUE if both are almost identical (they can be shared)
- bool closeTo(const RAS_TexVert* other);
+ void Transform(const class MT_Matrix4x4& mat,
+ const class MT_Matrix4x4& nmat);
- bool closeTo(const MT_Point3& otherxyz,
- const MT_Point2& otheruv,
- const unsigned int otherrgba,
- short othernormal[3]) const;
- void getOffsets(void*&xyz, void *&uv1, void *&rgba, void *&normal) const;
+ // compare two vertices, to test if they can be shared, used for
+ // splitting up based on uv's, colors, etc
+ bool closeTo(const RAS_TexVert* other);
};
#endif //__RAS_TEXVERT
diff --git a/source/gameengine/Rasterizer/SConscript b/source/gameengine/Rasterizer/SConscript
index e6bc657ed6d..a024f7e0ee6 100644
--- a/source/gameengine/Rasterizer/SConscript
+++ b/source/gameengine/Rasterizer/SConscript
@@ -3,11 +3,8 @@ Import ('env')
sources = env.Glob('*.cpp')
-if env['WITH_BF_GLEXT'] == 1:
- env['CPPFLAGS'].append('-DWITH_GLEXT')
-
-incs = '. #source/kernel/gen_system #intern/string #intern/moto/include #source/gameengine/BlenderRoutines #extern/glew/include #source/gameengine/Expressions'
+incs = '. #source/kernel/gen_system #intern/string #intern/moto/include #source/gameengine/BlenderRoutines #extern/glew/include #source/gameengine/Expressions #source/blender/blenkernel #source/blender/makesdna'
incs += ' ' + env['BF_PYTHON_INC']
if env['OURPLATFORM']=='win32-vc':