[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47525] branches/soc-2012-swiss_cheese/ source: Adding initial Software Matrix Stack
Alexander Kuznetsov
kuzsasha at gmail.com
Wed Jun 6 18:49:55 CEST 2012
Revision: 47525
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47525
Author: alexk
Date: 2012-06-06 16:49:54 +0000 (Wed, 06 Jun 2012)
Log Message:
-----------
Adding initial Software Matrix Stack
For nuce transition you have to isolate the area on which you working on with:
gpuMatrixLock() and gpuMatrixUnlock()
More functions are comming
Modified Paths:
--------------
branches/soc-2012-swiss_cheese/source/blender/blenlib/BLI_math_matrix.h
branches/soc-2012-swiss_cheese/source/blender/blenlib/intern/math_matrix.c
branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt
branches/soc-2012-swiss_cheese/source/blender/windowmanager/intern/wm_init_exit.c
branches/soc-2012-swiss_cheese/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
Added Paths:
-----------
branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_matrix.h
branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_matrix.c
Modified: branches/soc-2012-swiss_cheese/source/blender/blenlib/BLI_math_matrix.h
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/blenlib/BLI_math_matrix.h 2012-06-06 16:44:47 UTC (rev 47524)
+++ branches/soc-2012-swiss_cheese/source/blender/blenlib/BLI_math_matrix.h 2012-06-06 16:49:54 UTC (rev 47525)
@@ -66,6 +66,7 @@
void sub_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
void sub_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
+void mult_m4_m4m4_q(float m1[4][4], float m3[4][4], float m2[4][4]);
void mul_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
void mul_m4_m3m4(float R[4][4], float A[3][3], float B[4][4]);
@@ -146,6 +147,8 @@
void scale_m3_fl(float R[3][3], float scale);
void scale_m4_fl(float R[4][4], float scale);
+void scale_m4(float m[][4], float x, float y, float z);
+
float mat3_to_scale(float M[3][3]);
float mat4_to_scale(float M[4][4]);
Modified: branches/soc-2012-swiss_cheese/source/blender/blenlib/intern/math_matrix.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/blenlib/intern/math_matrix.c 2012-06-06 16:44:47 UTC (rev 47524)
+++ branches/soc-2012-swiss_cheese/source/blender/blenlib/intern/math_matrix.c 2012-06-06 16:49:54 UTC (rev 47525)
@@ -142,14 +142,8 @@
/******************************** Arithmetic *********************************/
-void mult_m4_m4m4(float m1[][4], float m3_[][4], float m2_[][4])
+void mult_m4_m4m4_q(float m1[][4], float m3[][4], float m2[][4])
{
- float m2[4][4], m3[4][4];
-
- /* copy so it works when m1 is the same pointer as m2 or m3 */
- copy_m4_m4(m2, m2_);
- copy_m4_m4(m3, m3_);
-
/* matrix product: m1[j][k] = m2[j][i].m3[i][k] */
m1[0][0] = m2[0][0] * m3[0][0] + m2[0][1] * m3[1][0] + m2[0][2] * m3[2][0] + m2[0][3] * m3[3][0];
m1[0][1] = m2[0][0] * m3[0][1] + m2[0][1] * m3[1][1] + m2[0][2] * m3[2][1] + m2[0][3] * m3[3][1];
@@ -173,6 +167,19 @@
}
+void mult_m4_m4m4(float m1[][4], float m3_[][4], float m2_[][4])
+{
+ float m2[4][4], m3[4][4];
+
+ /* copy so it works when m1 is the same pointer as m2 or m3 */
+ copy_m4_m4(m2, m2_);
+ copy_m4_m4(m3, m3_);
+
+ /* matrix product: m1[j][k] = m2[j][i].m3[i][k] */
+ mult_m4_m4m4_q(m1, m2, m3);
+
+}
+
void mul_m3_m3m3(float m1[][3], float m3_[][3], float m2_[][3])
{
float m2[3][3], m3[3][3];
@@ -1163,11 +1170,19 @@
m[3][0] = m[3][1] = m[3][2] = 0.0;
}
+void scale_m4(float m[][4], float x, float y, float z)
+{
+ m[0][0]*=x; m[0][1]*=x; m[0][2]*=x; m[0][3]*=x;
+ m[1][0]*=y; m[1][1]*=y; m[1][2]*=y; m[1][3]*=y;
+ m[2][0]*=z; m[2][1]*=z; m[2][2]*=z; m[2][3]*=z;
+}
+
void translate_m4(float mat[][4], float Tx, float Ty, float Tz)
{
mat[3][0] += (Tx * mat[0][0] + Ty * mat[1][0] + Tz * mat[2][0]);
mat[3][1] += (Tx * mat[0][1] + Ty * mat[1][1] + Tz * mat[2][1]);
mat[3][2] += (Tx * mat[0][2] + Ty * mat[1][2] + Tz * mat[2][2]);
+ mat[3][3] += (Tx * mat[0][3] + Ty * mat[1][3] + Tz * mat[2][3]);
}
void rotate_m4(float mat[][4], const char axis, const float angle)
Modified: branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt 2012-06-06 16:44:47 UTC (rev 47524)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt 2012-06-06 16:49:54 UTC (rev 47525)
@@ -54,6 +54,7 @@
intern/gpu_immediate_vbo.c
intern/gpu_lighting.c
intern/gpu_material.c
+ intern/gpu_matrix.c
intern/gpu_primitives.c
shaders/gpu_shader_material.glsl.c
@@ -69,6 +70,7 @@
GPU_extensions.h
GPU_material.h
GPU_utility.h
+ GPU_matrix.h
GPU_lighting.h
GPU_primitives.h
Added: branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_matrix.h
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_matrix.h (rev 0)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_matrix.h 2012-06-06 16:49:54 UTC (rev 47525)
@@ -0,0 +1,33 @@
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define GPU_MODELVIEW 1<<0
+#define GPU_PROJECTION 1<<1
+#define GPU_TEXTURE 1<<2
+
+void GPU_ms_init(void);
+void GPU_ms_exit(void);
+
+void gpuMatrixLock(void);
+void gpuMatrixUnlock(void);
+
+void gpuMatrixCommit(void);
+
+void gpuPushMatrix(void);
+void gpuPopMatrix(void);
+
+void gpuMatrixMode(int mode);
+
+void gpuLoadMatrix(const float * m);
+void gpuGetMatrix(float * m);
+
+void gpuLoadIdentity(void);
+
+void gpuTranslate(float x, float y, float z);
+void gpuScale(float x, float y, float z);
+
+#ifdef __cplusplus
+}
+#endif
Added: branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_matrix.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_matrix.c (rev 0)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_matrix.c 2012-06-06 16:49:54 UTC (rev 47525)
@@ -0,0 +1,291 @@
+#include <assert.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math_matrix.h"
+#include "BLI_math_rotation.h"
+
+
+#include "GPU_matrix.h"
+
+#ifdef GLES
+#include <GLES2/gl2.h>
+#else
+#include <GL/glew.h>
+#endif
+
+typedef float GPU_matrix[4][4];
+
+typedef struct GPU_matrix_stack
+{
+ int size;
+ int pos;
+ int changed;
+ GPU_matrix * dynstack;
+
+
+} GPU_matrix_stack;
+
+GPU_matrix_stack ms_modelview;
+GPU_matrix_stack ms_projection;
+GPU_matrix_stack ms_texture;
+
+GPU_matrix_stack * ms_current;
+
+#define CURMATRIX (ms_current->dynstack[ms_current->pos])
+
+static void ms_init(GPU_matrix_stack * ms, int initsize)
+{
+ if(initsize == 0)
+ initsize = 32;
+ ms->size = initsize;
+ ms->pos = 0;
+ ms->changed = 1;
+ ms->dynstack = MEM_mallocN(ms->size*sizeof(*(ms->dynstack)), "MatrixStack");
+ //gpuLoadIdentity();
+}
+
+static void ms_free(GPU_matrix_stack * ms)
+{
+ ms->size = 0;
+ ms->pos = 0;
+ MEM_freeN(ms->dynstack);
+ ms->dynstack = NULL;
+}
+
+
+static int glstackpos[3] = {0};
+static int glstackmode;
+
+void GPU_ms_init(void)
+{
+ ms_init(&ms_modelview, 32);
+ ms_init(&ms_projection, 16);
+ ms_init(&ms_texture, 16);
+
+ ms_current = &ms_modelview;
+
+ printf("Stack init\n");
+
+
+
+}
+
+void GPU_ms_exit(void)
+{
+ ms_free(&ms_modelview);
+ ms_free(&ms_projection);
+ ms_free(&ms_texture);
+
+ printf("Stack exit\n");
+
+
+
+}
+
+void gpuMatrixLock(void)
+{
+#ifndef GLES
+ GPU_matrix tm;
+ glGetIntegerv(GL_MODELVIEW_STACK_DEPTH, glstackpos);
+ glGetIntegerv(GL_PROJECTION_STACK_DEPTH, glstackpos+1);
+ glGetIntegerv(GL_TEXTURE_STACK_DEPTH, glstackpos+2);
+ glGetIntegerv(GL_MATRIX_MODE, &glstackmode);
+
+ glGetFloatv(GL_MODELVIEW_MATRIX, tm);
+ gpuMatrixMode(GPU_MODELVIEW);
+ gpuLoadMatrix(tm);
+
+ glGetFloatv(GL_PROJECTION_MATRIX, tm);
+ gpuMatrixMode(GPU_PROJECTION);
+ gpuLoadMatrix(tm);
+
+ glGetFloatv(GL_TEXTURE_MATRIX, tm);
+ gpuMatrixMode(GPU_TEXTURE);
+ gpuLoadMatrix(tm);
+
+
+
+
+ glMatrixMode(GL_TEXTURE);
+ glPushMatrix();
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+
+ glMatrixMode(glstackmode);
+ switch(glstackmode)
+ {
+ case GL_MODELVIEW:
+ gpuMatrixMode(GPU_MODELVIEW);
+ break;
+ case GL_TEXTURE:
+ gpuMatrixMode(GPU_TEXTURE);
+ break;
+ case GL_PROJECTION:
+ gpuMatrixMode(GPU_PROJECTION);
+ break;
+
+ }
+
+
+#endif
+
+}
+
+
+void gpuMatrixUnlock(void)
+{
+
+#ifndef GLES
+ int curval;
+
+
+ glMatrixMode(GL_TEXTURE);
+ glPopMatrix();
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+
+ glGetIntegerv(GL_MODELVIEW_STACK_DEPTH, &curval);
+
+
+ glGetIntegerv(GL_PROJECTION_STACK_DEPTH, &curval);
+ glGetIntegerv(GL_TEXTURE_STACK_DEPTH, &curval);
+
+
+
+
+
+
+ glMatrixMode(glstackmode);
+
+#endif
+
+}
+
+void gpuMatrixCommit(void)
+{
+#ifndef GLES
+ if(ms_modelview.changed)
+ {
+ ms_modelview.changed = 0;
+ glMatrixMode(GL_MODELVIEW);
+ glLoadMatrixf(ms_modelview.dynstack[ms_modelview.pos]);
+ }
+ if(ms_projection.changed)
+ {
+ ms_projection.changed = 0;
+ glMatrixMode(GL_PROJECTION);
+ glLoadMatrixf(ms_projection.dynstack[ms_projection.pos]);
+ }
+ if(ms_texture.changed)
+ {
+ ms_texture.changed = 0;
+ glMatrixMode(GL_TEXTURE);
+ glLoadMatrixf(ms_texture.dynstack[ms_texture.pos]);
+ }
+
+#endif
+
+}
+
+
+
+
+void gpuPushMatrix(void)
+{
+ ms_current->pos++;
+
+ if(ms_current->pos >= ms_current->size)
+ {
+ ms_current->size += ((ms_current->size-1)>>1)+1;
+ /* increases size by 50% */
+ ms_current->dynstack = MEM_reallocN(ms_current->dynstack,
+ ms_current->size*sizeof(*(ms_current->dynstack)));
+
+
+ }
+
+ gpuLoadMatrix(ms_current->dynstack[ms_current->pos-1]);
+
+}
+
+void gpuPopMatrix(void)
+{
+ ms_current->pos--;
+ ms_current->changed = 1;
+#ifdef GLU_STACK_DEBUG
+ if(ms_current->pos < 0)
+ assert(0);
+#endif
+}
+
+
+void gpuMatrixMode(int mode)
+{
+
+ switch(mode)
+ {
+ case GPU_MODELVIEW:
+ ms_current = &ms_modelview;
+ break;
+ case GPU_PROJECTION:
+ ms_current = &ms_projection;
+ break;
+ case GPU_TEXTURE:
+ ms_current = & ms_texture;
+ break;
+ #if 1
+ default:
+ assert(0);
+
+ #endif
+
+ }
+
+
+}
+
+
+void gpuLoadMatrix(const float * m)
+{
+ copy_m4_m4(CURMATRIX, m);
+ ms_current->changed = 1;
+}
+
+void gpuGetMatrix(float * m)
+{
+ copy_m4_m4((float (*)[4])m,CURMATRIX);
+ ms_current->changed = 1;
+}
+
+
+void gpuLoadIdentity(void)
+{
+ unit_m4(CURMATRIX);
+ ms_current->changed = 1;
+}
+
+
+
+
+void gpuTranslate(float x, float y, float z)
+{
+
+ translate_m4(CURMATRIX, x, y, z);
+ ms_current->changed = 1;
+
+}
+
+void gpuScale(float x, float y, float z)
+{
+
+ scale_m4(CURMATRIX, x, y, z);
+ ms_current->changed = 1;
+
+}
+
+
Modified: branches/soc-2012-swiss_cheese/source/blender/windowmanager/intern/wm_init_exit.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/windowmanager/intern/wm_init_exit.c 2012-06-06 16:44:47 UTC (rev 47524)
+++ branches/soc-2012-swiss_cheese/source/blender/windowmanager/intern/wm_init_exit.c 2012-06-06 16:49:54 UTC (rev 47525)
@@ -107,6 +107,7 @@
#include "GPU_extensions.h"
#include "GPU_draw.h"
#include "GPU_compatibility.h"
+#include "GPU_matrix.h"
#include "BKE_depsgraph.h"
#include "BKE_sound.h"
@@ -181,6 +182,8 @@
GPU_extensions_init();
GPU_set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
GPU_set_anisotropic(U.anisotropic_filter);
+
+ GPU_ms_init();
immediate = gpuNewImmediate();
gpuImmediateMakeCurrent(immediate);
@@ -421,6 +424,7 @@
GPU_global_buffer_pool_free();
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list