OSDN Git Service

Implement the fixed-function matrix stacks.
authorNicolas Capens <capn@google.com>
Wed, 29 Oct 2014 18:46:44 +0000 (14:46 -0400)
committerNicolas Capens <nicolascapens@google.com>
Thu, 30 Oct 2014 16:34:05 +0000 (16:34 +0000)
BUG=18110152

Change-Id: I0769c446e20eaf52cc84d957de16bfba4254a5f1
Reviewed-on: https://swiftshader-review.googlesource.com/1244
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
src/GLES2/libGLES_CM/Context.cpp
src/GLES2/libGLES_CM/Context.h
src/GLES2/libGLES_CM/MatrixStack.cpp [new file with mode: 0644]
src/GLES2/libGLES_CM/MatrixStack.hpp [new file with mode: 0644]
src/GLES2/libGLES_CM/libGLES_CM.cpp
src/GLES2/libGLES_CM/libGLES_CM.vcxproj
src/GLES2/libGLES_CM/libGLES_CM.vcxproj.filters

index bc432c5..428ba7b 100644 (file)
@@ -38,7 +38,11 @@ namespace es1
 {\r
 Device *Context::device = 0;\r
 \r
-Context::Context(const egl::Config *config, const Context *shareContext) : mConfig(config)\r
+Context::Context(const egl::Config *config, const Context *shareContext)\r
+    : modelViewStack(MAX_MODELVIEW_STACK_DEPTH),\r
+      projectionStack(MAX_PROJECTION_STACK_DEPTH),\r
+         textureStack0(MAX_TEXTURE_STACK_DEPTH),\r
+         textureStack1(MAX_TEXTURE_STACK_DEPTH)\r
 {\r
        device = getDevice();\r
 \r
@@ -161,6 +165,8 @@ Context::Context(const egl::Config *config, const Context *shareContext) : mConf
     mHasBeenCurrent = false;\r
 \r
     markAllStateDirty();\r
+\r
+    matrixMode = GL_MODELVIEW;\r
 }\r
 \r
 Context::~Context()\r
@@ -172,7 +178,7 @@ Context::~Context()
        \r
     for(int type = 0; type < TEXTURE_TYPE_COUNT; type++)\r
     {\r
-        for(int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++)\r
+        for(int sampler = 0; sampler < MAX_TEXTURE_IMAGE_UNITS; sampler++)\r
         {\r
             mState.samplerTexture[type][sampler].set(NULL);\r
         }\r
@@ -943,6 +949,18 @@ bool Context::getFloatv(GLenum pname, GLfloat *params)
          case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:\r
         *params = MAX_TEXTURE_MAX_ANISOTROPY;\r
                break;\r
+         case GL_MODELVIEW_MATRIX:\r
+               for(int i = 0; i < 16; i++)\r
+               {\r
+                       params[i] = modelViewStack.current()[i % 4][i / 4];\r
+               }\r
+               break;\r
+         case GL_PROJECTION_MATRIX:\r
+               for(int i = 0; i < 16; i++)\r
+               {\r
+                       params[i] = projectionStack.current()[i % 4][i / 4];\r
+               }\r
+               break;\r
       default:\r
         return false;\r
     }\r
@@ -1117,7 +1135,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
         break;\r
     case GL_TEXTURE_BINDING_2D:\r
         {\r
-            if(mState.activeSampler < 0 || mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)\r
+            if(mState.activeSampler < 0 || mState.activeSampler > MAX_TEXTURE_IMAGE_UNITS - 1)\r
             {\r
                 error(GL_INVALID_OPERATION);\r
                 return false;\r
@@ -1128,7 +1146,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
         break;\r
     case GL_TEXTURE_BINDING_CUBE_MAP_OES:\r
         {\r
-            if(mState.activeSampler < 0 || mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)\r
+            if(mState.activeSampler < 0 || mState.activeSampler > MAX_TEXTURE_IMAGE_UNITS - 1)\r
             {\r
                 error(GL_INVALID_OPERATION);\r
                 return false;\r
@@ -1139,7 +1157,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
         break;\r
     case GL_TEXTURE_BINDING_EXTERNAL_OES:\r
         {\r
-            if(mState.activeSampler < 0 || mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)\r
+            if(mState.activeSampler < 0 || mState.activeSampler > MAX_TEXTURE_IMAGE_UNITS - 1)\r
             {\r
                 error(GL_INVALID_OPERATION);\r
                 return false;\r
@@ -1148,7 +1166,10 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
             *params = mState.samplerTexture[TEXTURE_EXTERNAL][mState.activeSampler].id();\r
         }\r
         break;\r
-       case GL_MAX_LIGHTS: *params = MAX_LIGHTS; break;\r
+       case GL_MAX_LIGHTS:                 *params = MAX_LIGHTS;                 break;\r
+    case GL_MAX_MODELVIEW_STACK_DEPTH:  *params = MAX_MODELVIEW_STACK_DEPTH;  break;\r
+       case GL_MAX_PROJECTION_STACK_DEPTH: *params = MAX_PROJECTION_STACK_DEPTH; break;\r
+       case GL_MAX_TEXTURE_STACK_DEPTH:    *params = MAX_TEXTURE_STACK_DEPTH;    break;\r
     default:\r
         return false;\r
     }\r
@@ -1211,6 +1232,7 @@ int Context::getQueryParameterNum(GLenum pname)
     case GL_TEXTURE_BINDING_2D:\r
     case GL_TEXTURE_BINDING_CUBE_MAP_OES:\r
     case GL_TEXTURE_BINDING_EXTERNAL_OES:\r
+       case GL_MAX_TEXTURE_UNITS:\r
         return 1;\r
     case GL_MAX_VIEWPORT_DIMS:\r
         return 2;\r
@@ -1245,6 +1267,9 @@ int Context::getQueryParameterNum(GLenum pname)
         return 4;\r
        case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:\r
        case GL_MAX_LIGHTS:\r
+       case GL_MAX_MODELVIEW_STACK_DEPTH:\r
+       case GL_MAX_PROJECTION_STACK_DEPTH:\r
+       case GL_MAX_TEXTURE_STACK_DEPTH:\r
         return 1;\r
        default:\r
                UNREACHABLE();\r
@@ -1311,6 +1336,9 @@ bool Context::isQueryParameterInt(GLenum pname)
     case GL_VIEWPORT:\r
     case GL_SCISSOR_BOX:\r
        case GL_MAX_LIGHTS:\r
+       case GL_MAX_MODELVIEW_STACK_DEPTH:\r
+       case GL_MAX_PROJECTION_STACK_DEPTH:\r
+       case GL_MAX_TEXTURE_STACK_DEPTH:\r
         return true;\r
        default:\r
                ASSERT(isQueryParameterFloat(pname) || isQueryParameterBool(pname));\r
@@ -1626,6 +1654,13 @@ void Context::applyState(GLenum drawMode)
        device->setSpecularMaterialSource(sw::MATERIAL_MATERIAL);\r
        device->setAmbientMaterialSource(sw::MATERIAL_MATERIAL);\r
        device->setEmissiveMaterialSource(sw::MATERIAL_MATERIAL);\r
+\r
+    device->setProjectionMatrix(projectionStack.current());\r
+    device->setModelMatrix(modelViewStack.current());\r
+    device->setTextureMatrix(0, textureStack0.current());\r
+       device->setTextureMatrix(1, textureStack1.current());\r
+       device->setTextureTransform(0, textureStack0.isIdentity() ? 0 : 4, false);\r
+       device->setTextureTransform(1, textureStack1.isIdentity() ? 0 : 4, false);\r
 }\r
 \r
 GLenum Context::applyVertexBuffer(GLint base, GLint first, GLsizei count)\r
@@ -2224,7 +2259,7 @@ void Context::detachTexture(GLuint texture)
 \r
     for(int type = 0; type < TEXTURE_TYPE_COUNT; type++)\r
     {\r
-        for(int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++)\r
+        for(int sampler = 0; sampler < MAX_TEXTURE_IMAGE_UNITS; sampler++)\r
         {\r
             if(mState.samplerTexture[type][sampler].id() == texture)\r
             {\r
@@ -2418,6 +2453,83 @@ Device *Context::getDevice()
        return device;\r
 }\r
 \r
+void Context::setMatrixMode(GLenum mode)\r
+{\r
+    matrixMode = mode;\r
+}\r
+\r
+sw::MatrixStack &Context::currentMatrixStack()\r
+{\r
+       switch(matrixMode)\r
+       {\r
+       case GL_MODELVIEW: \r
+               return modelViewStack;\r
+       case GL_PROJECTION:\r
+               return projectionStack;\r
+       case GL_TEXTURE:\r
+               switch(mState.activeSampler)\r
+               {\r
+               case 0: return textureStack0;\r
+               case 1: return textureStack1;\r
+               }\r
+               break;    \r
+       }\r
+\r
+       UNREACHABLE();\r
+       return textureStack0;\r
+}\r
+\r
+void Context::loadIdentity()\r
+{\r
+       currentMatrixStack().identity();\r
+}\r
+\r
+void Context::load(const GLfloat *m)\r
+{\r
+    currentMatrixStack().load(m);\r
+}\r
+\r
+void Context::pushMatrix()\r
+{\r
+       if(!currentMatrixStack().push())\r
+       {\r
+               return error(GL_STACK_OVERFLOW);\r
+       }\r
+}\r
+\r
+void Context::popMatrix()\r
+{\r
+    if(!currentMatrixStack().pop())\r
+       {\r
+               return error(GL_STACK_OVERFLOW);\r
+       }\r
+}\r
+\r
+void Context::rotate(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)\r
+{\r
+    currentMatrixStack().rotate(angle, x, y, z);\r
+}\r
+\r
+void Context::translate(GLfloat x, GLfloat y, GLfloat z)\r
+{\r
+    currentMatrixStack().translate(x, y, z);  \r
+}\r
+\r
+void Context::scale(GLfloat x, GLfloat y, GLfloat z)\r
+{\r
+    currentMatrixStack().scale(x, y, z);\r
+}\r
+\r
+void Context::multiply(const GLfloat *m)\r
+{\r
+    currentMatrixStack().multiply(m);\r
+}\r
+\r
+void Context::ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)\r
+{\r
+       currentMatrixStack().ortho(left, right, bottom, top, zNear, zFar);\r
+}\r
+\r
 }\r
 \r
 // Exported functions for use by EGL\r
index 3fcd5f5..24b621f 100644 (file)
@@ -21,6 +21,7 @@
 #include "RefCountObject.h"\r
 #include "Image.hpp"\r
 #include "Renderer/Sampler.hpp"\r
+#include "MatrixStack.hpp"\r
 \r
 #define GL_API\r
 #include <GLES/gl.h>\r
@@ -61,16 +62,15 @@ class IndexDataManager;
 enum\r
 {\r
     MAX_VERTEX_ATTRIBS = 16,\r
-       MAX_UNIFORM_VECTORS = 256,   // Device limit\r
-    MAX_VERTEX_UNIFORM_VECTORS = 256 - 3,   // Reserve space for gl_DepthRange\r
     MAX_VARYING_VECTORS = 10,\r
     MAX_TEXTURE_IMAGE_UNITS = 16,\r
-    MAX_VERTEX_TEXTURE_IMAGE_UNITS = 4,\r
-    MAX_COMBINED_TEXTURE_IMAGE_UNITS = MAX_TEXTURE_IMAGE_UNITS + MAX_VERTEX_TEXTURE_IMAGE_UNITS,\r
-    MAX_FRAGMENT_UNIFORM_VECTORS = 224 - 3,    // Reserve space for gl_DepthRange\r
     MAX_DRAW_BUFFERS = 1,\r
        MAX_LIGHTS = 8,\r
 \r
+       MAX_MODELVIEW_STACK_DEPTH = 32,\r
+       MAX_PROJECTION_STACK_DEPTH = 2,\r
+       MAX_TEXTURE_STACK_DEPTH = 2,\r
+\r
     IMPLEMENTATION_COLOR_READ_FORMAT = GL_RGB,\r
     IMPLEMENTATION_COLOR_READ_TYPE = GL_UNSIGNED_SHORT_5_6_5\r
 };\r
@@ -247,7 +247,7 @@ struct State
     BindingPointer<Renderbuffer> renderbuffer;\r
 \r
     VertexAttribute vertexAttribute[MAX_VERTEX_ATTRIBS];\r
-    BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][MAX_COMBINED_TEXTURE_IMAGE_UNITS];\r
+    BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][MAX_TEXTURE_IMAGE_UNITS];\r
 \r
     GLint unpackAlignment;\r
     GLint packAlignment;\r
@@ -418,6 +418,17 @@ public:
 \r
        Device *getDevice();\r
 \r
+    void setMatrixMode(GLenum mode);\r
+    void loadIdentity();\r
+       void load(const GLfloat *m);\r
+    void pushMatrix();\r
+    void popMatrix();\r
+    void rotate(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);\r
+    void translate(GLfloat x, GLfloat y, GLfloat z);\r
+       void scale(GLfloat x, GLfloat y, GLfloat z);\r
+    void multiply(const GLfloat *m);\r
+    void ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);\r
+\r
 private:\r
        virtual ~Context();\r
 \r
@@ -436,8 +447,6 @@ private:
     bool cullSkipsDraw(GLenum drawMode);\r
     bool isTriangleMode(GLenum drawMode);\r
 \r
-    const egl::Config *const mConfig;\r
-\r
     State mState;\r
 \r
     BindingPointer<Texture2D> mTexture2DZero;\r
@@ -478,6 +487,13 @@ private:
     bool mFrontFaceDirty;\r
     bool mDitherStateDirty;\r
 \r
+       sw::MatrixStack &currentMatrixStack();\r
+       GLenum matrixMode;\r
+    sw::MatrixStack modelViewStack;\r
+       sw::MatrixStack projectionStack;\r
+       sw::MatrixStack textureStack0;\r
+       sw::MatrixStack textureStack1;\r
+\r
     ResourceManager *mResourceManager;\r
 \r
        static Device *device;\r
diff --git a/src/GLES2/libGLES_CM/MatrixStack.cpp b/src/GLES2/libGLES_CM/MatrixStack.cpp
new file mode 100644 (file)
index 0000000..c91e152
--- /dev/null
@@ -0,0 +1,198 @@
+#include "MatrixStack.hpp"\r
+\r
+#include "Common/Math.hpp"\r
+\r
+namespace sw\r
+{\r
+       MatrixStack::MatrixStack(int size)\r
+       {\r
+               stack = new Matrix[size];\r
+               stack[0] = 1;\r
+\r
+               top = 0;\r
+               this->size = size;\r
+       }\r
+\r
+       MatrixStack::~MatrixStack()\r
+       {\r
+               delete[] stack;\r
+               stack = 0;\r
+       }\r
+\r
+       void MatrixStack::identity()\r
+       {\r
+               stack[top] = 1;\r
+       }\r
+\r
+       void MatrixStack::load(const float *M)\r
+       {\r
+               stack[top] = Matrix(M[0], M[4], M[8],  M[12],\r
+                                   M[1], M[5], M[9],  M[13],\r
+                                   M[2], M[6], M[10], M[14],\r
+                                   M[3], M[7], M[11], M[15]);\r
+       }\r
+\r
+       void MatrixStack::load(const double *M)\r
+       {\r
+               stack[top] = Matrix((float)M[0], (float)M[4], (float)M[8],  (float)M[12],\r
+                                   (float)M[1], (float)M[5], (float)M[9],  (float)M[13],\r
+                                   (float)M[2], (float)M[6], (float)M[10], (float)M[14],\r
+                                   (float)M[3], (float)M[7], (float)M[11], (float)M[15]);\r
+       }\r
+\r
+       void MatrixStack::translate(float x, float y, float z)\r
+       {\r
+               stack[top] *= Matrix::translate(x, y, z);\r
+       }\r
+\r
+       void MatrixStack::translate(double x, double y, double z)\r
+       {\r
+               translate((float)x, (float)y, (float)z);\r
+       }\r
+\r
+       void MatrixStack::rotate(float angle, float x, float y, float z)\r
+       {\r
+               float n = 1.0f / sqrt(x*x + y*y + z*z);\r
+\r
+               x *= n;\r
+               y *= n;\r
+               z *= n;\r
+\r
+               float theta = angle * 0.0174532925f;   // In radians\r
+               float c = cos(theta);\r
+               float _c = 1 - c;\r
+               float s = sin(theta);\r
+\r
+               // Rodrigues' rotation formula\r
+               sw::Matrix rotate(c+x*x*_c,   x*y*_c-z*s, x*z*_c+y*s,\r
+                                 x*y*_c+z*s, c+y*y*_c,   y*z*_c-x*s,\r
+                                 x*z*_c-y*s, y*z*_c+x*s, c+z*z*_c);\r
+\r
+               stack[top] *= rotate;\r
+       }\r
+\r
+       void MatrixStack::rotate(double angle, double x, double y, double z)\r
+       {\r
+               rotate((float)angle, (float)x, (float)y, (float)z);\r
+       }\r
+\r
+       void MatrixStack::scale(float x, float y, float z)\r
+       {\r
+               stack[top] *= Matrix::scale(x, y, z);\r
+       }\r
+\r
+       void MatrixStack::scale(double x, double y, double z)\r
+       {\r
+               scale((float)x, (float)y, (float)z);\r
+       }\r
+\r
+       void MatrixStack::multiply(const float *M)\r
+       {\r
+               stack[top] *= Matrix(M[0], M[4], M[8],  M[12],\r
+                                    M[1], M[5], M[9],  M[13],\r
+                                    M[2], M[6], M[10], M[14],\r
+                                    M[3], M[7], M[11], M[15]);\r
+       }\r
+\r
+       void MatrixStack::multiply(const double *M)\r
+       {\r
+               stack[top] *= Matrix((float)M[0], (float)M[4], (float)M[8],  (float)M[12],\r
+                                    (float)M[1], (float)M[5], (float)M[9],  (float)M[13],\r
+                                    (float)M[2], (float)M[6], (float)M[10], (float)M[14],\r
+                                    (float)M[3], (float)M[7], (float)M[11], (float)M[15]);\r
+       }\r
+\r
+       void MatrixStack::frustum(float left, float right, float bottom, float top, float zNear, float zFar)\r
+       {\r
+               float l = (float)left;\r
+               float r = (float)right;\r
+               float b = (float)bottom;\r
+               float t = (float)top;\r
+               float n = (float)zNear;\r
+               float f = (float)zFar;\r
+\r
+               float A = (r + l) / (r - l);\r
+               float B = (t + b) / (t - b);\r
+               float C = -(f + n) / (r - n);\r
+               float D = -2 * r * n / (f - n);\r
+\r
+               Matrix frustum(2 * n / (r - l), 0,               A,  0,\r
+                              0,               2 * n / (t - b), B,  0,\r
+                          0,               0,               C,  D,\r
+                          0,               0,               -1, 0);\r
+\r
+               stack[this->top] *= frustum;\r
+       }\r
+\r
+       void MatrixStack::ortho(double left, double right, double bottom, double top, double zNear, double zFar)\r
+       {\r
+               float l = (float)left;\r
+               float r = (float)right;\r
+               float b = (float)bottom;\r
+               float t = (float)top;\r
+               float n = (float)zNear;\r
+               float f = (float)zFar;\r
+\r
+               float tx = -(r + l) / (r - l);\r
+               float ty = -(t + b) / (t - b);\r
+               float tz = -(f + n) / (f - n);\r
+\r
+               Matrix ortho(2 / (r - l), 0,           0,            tx,\r
+                            0,           2 / (t - b), 0,            ty,\r
+                            0,           0,           -2 / (f - n), tz,\r
+                            0,           0,           0,            1);\r
+\r
+               stack[this->top] *= ortho;\r
+       }\r
+\r
+       bool MatrixStack::push()\r
+       {\r
+               if(top >= size - 1) return false;\r
+\r
+               stack[top + 1] = stack[top];\r
+               top++;\r
+\r
+               return true;\r
+       }\r
+\r
+       bool MatrixStack::pop()\r
+       {\r
+               if(top <= 0) return false;\r
+\r
+               top--;\r
+\r
+               return true;\r
+       }\r
+\r
+       const Matrix &MatrixStack::current()\r
+       {\r
+               return stack[top];\r
+       }\r
+\r
+       bool MatrixStack::isIdentity() const\r
+       {\r
+               const Matrix &m = stack[top];\r
+\r
+               if(m.m[0][0] != 1.0f) return false;\r
+               if(m.m[0][1] != 0.0f) return false;\r
+               if(m.m[0][2] != 0.0f) return false;\r
+               if(m.m[0][3] != 0.0f) return false;\r
+\r
+               if(m.m[1][0] != 0.0f) return false;\r
+               if(m.m[1][1] != 1.0f) return false;\r
+               if(m.m[1][2] != 0.0f) return false;\r
+               if(m.m[1][3] != 0.0f) return false;\r
+\r
+               if(m.m[2][0] != 0.0f) return false;\r
+               if(m.m[2][1] != 0.0f) return false;\r
+               if(m.m[2][2] != 1.0f) return false;\r
+               if(m.m[2][3] != 0.0f) return false;\r
+\r
+               if(m.m[3][0] != 0.0f) return false;\r
+               if(m.m[3][1] != 0.0f) return false;\r
+               if(m.m[3][2] != 0.0f) return false;\r
+               if(m.m[3][3] != 1.0f) return false;\r
+\r
+               return true;\r
+       }\r
+}\r
diff --git a/src/GLES2/libGLES_CM/MatrixStack.hpp b/src/GLES2/libGLES_CM/MatrixStack.hpp
new file mode 100644 (file)
index 0000000..56ac43b
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef OpenGL32_MatrixStack_hpp\r
+#define OpenGL32_MatrixStack_hpp\r
+\r
+#include "Renderer/Matrix.hpp"\r
+\r
+namespace sw\r
+{\r
+       class MatrixStack\r
+       {\r
+       public:\r
+               MatrixStack(int size = 2);\r
+\r
+               ~MatrixStack();\r
+\r
+               void identity();\r
+               void load(const float *M);\r
+               void load(const double *M);\r
+\r
+               void translate(float x, float y, float z);\r
+               void translate(double x, double y, double z);\r
+               void rotate(float angle, float x, float y, float z);\r
+               void rotate(double angle, double x, double y, double z);\r
+               void scale(float x, float y, float z);\r
+               void scale(double x, double y, double z);\r
+               void multiply(const float *M);\r
+               void multiply(const double *M);\r
+\r
+               void frustum(float left, float right, float bottom, float top, float zNear, float zFar);\r
+               void ortho(double left, double right, double bottom, double top, double zNear, double zFar);\r
+\r
+               bool push();   // False on overflow\r
+               bool pop();    // False on underflow\r
+\r
+               const Matrix &current();\r
+               bool isIdentity() const;\r
+\r
+       private:\r
+               int top;\r
+               int size;\r
+               Matrix *stack;\r
+       };\r
+}\r
+\r
+#endif   // OpenGL32_MatrixStack_hpp\r
index 49696ab..2b9ffe8 100644 (file)
@@ -351,7 +351,7 @@ void GL_APIENTRY glActiveTexture(GLenum texture)
 \r
         if(context)\r
         {\r
-            if(texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + es1::MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)\r
+            if(texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + es1::MAX_TEXTURE_IMAGE_UNITS - 1)\r
             {\r
                 return error(GL_INVALID_ENUM);\r
             }\r
@@ -3009,12 +3009,40 @@ void GL_APIENTRY glLineWidthx(GLfixed width)
 \r
 void GL_APIENTRY glLoadIdentity(void)\r
 {\r
-       UNIMPLEMENTED();\r
+       TRACE("()");\r
+\r
+    try\r
+    {\r
+        es1::Context *context = es1::getContext();\r
+\r
+        if(context)\r
+        {\r
+            context->loadIdentity();\r
+        }\r
+    }\r
+    catch(std::bad_alloc&)\r
+    {\r
+        return error(GL_OUT_OF_MEMORY);\r
+    }\r
 }\r
 \r
 void GL_APIENTRY glLoadMatrixf(const GLfloat *m)\r
 {\r
-       UNIMPLEMENTED();\r
+       TRACE("(const GLfloat *m)");\r
+\r
+    try\r
+    {\r
+        es1::Context *context = es1::getContext();\r
+\r
+        if(context)\r
+        {\r
+            context->load(m);\r
+        }\r
+    }\r
+    catch(std::bad_alloc&)\r
+    {\r
+        return error(GL_OUT_OF_MEMORY);\r
+    }\r
 }\r
 \r
 void GL_APIENTRY glLoadMatrixx(const GLfixed *m)\r
@@ -3049,12 +3077,40 @@ void GL_APIENTRY glMaterialxv(GLenum face, GLenum pname, const GLfixed *params)
 \r
 void GL_APIENTRY glMatrixMode(GLenum mode)\r
 {\r
-       UNIMPLEMENTED();\r
+       TRACE("(GLenum mode = 0x%X)", mode);\r
+\r
+    try\r
+    {\r
+        es1::Context *context = es1::getContext();\r
+\r
+        if(context)\r
+        {\r
+            context->setMatrixMode(mode);\r
+        }\r
+    }\r
+    catch(std::bad_alloc&)\r
+    {\r
+        return error(GL_OUT_OF_MEMORY);\r
+    }\r
 }\r
 \r
 void GL_APIENTRY glMultMatrixf(const GLfloat *m)\r
 {\r
-       UNIMPLEMENTED();\r
+       TRACE("(const GLfloat *m)");\r
+\r
+    try\r
+    {\r
+        es1::Context *context = es1::getContext();\r
+\r
+        if(context)\r
+        {\r
+            context->multiply(m);\r
+        }\r
+    }\r
+    catch(std::bad_alloc&)\r
+    {\r
+        return error(GL_OUT_OF_MEMORY);\r
+    }\r
 }\r
 \r
 void GL_APIENTRY glMultMatrixx(const GLfixed *m)\r
@@ -3089,7 +3145,21 @@ void GL_APIENTRY glNormalPointer(GLenum type, GLsizei stride, const GLvoid *poin
 \r
 void GL_APIENTRY glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)\r
 {\r
-       UNIMPLEMENTED();\r
+       TRACE("(GLfloat left = %f, GLfloat right = %f, GLfloat bottom = %f, GLfloat top = %f, GLfloat zNear = %f, GLfloat zFar = %f)", left, right, bottom, top, zNear, zFar);\r
+\r
+    try\r
+    {\r
+        es1::Context *context = es1::getContext();\r
+\r
+        if(context)\r
+        {\r
+            context->ortho(left, right, bottom, top, zNear, zFar);\r
+        }\r
+    }\r
+    catch(std::bad_alloc&)\r
+    {\r
+        return error(GL_OUT_OF_MEMORY);\r
+    }\r
 }\r
 \r
 void GL_APIENTRY glOrthox(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar)\r
@@ -3199,12 +3269,40 @@ void GL_APIENTRY glPolygonOffsetx(GLfixed factor, GLfixed units)
 \r
 void GL_APIENTRY glPopMatrix(void)\r
 {\r
-       UNIMPLEMENTED();\r
+       TRACE("()");\r
+    \r
+    try\r
+    {\r
+        es1::Context *context = es1::getContext();\r
+\r
+        if(context)\r
+        {\r
+            context->popMatrix();\r
+        }\r
+    }\r
+    catch(std::bad_alloc&)\r
+    {\r
+        return error(GL_OUT_OF_MEMORY);\r
+    }\r
 }\r
 \r
 void GL_APIENTRY glPushMatrix(void)\r
 {\r
-       UNIMPLEMENTED();\r
+       TRACE("()");\r
+    \r
+    try\r
+    {\r
+        es1::Context *context = es1::getContext();\r
+\r
+        if(context)\r
+        {\r
+            context->pushMatrix();\r
+        }\r
+    }\r
+    catch(std::bad_alloc&)\r
+    {\r
+        return error(GL_OUT_OF_MEMORY);\r
+    }\r
 }\r
 \r
 void GL_APIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels)\r
@@ -3310,7 +3408,21 @@ void GL_APIENTRY glRenderbufferStorageOES(GLenum target, GLenum internalformat,
 \r
 void GL_APIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)\r
 {\r
-       UNIMPLEMENTED();\r
+       TRACE("(GLfloat angle = %f, GLfloat x = %f, GLfloat y = %f, GLfloat z = %f)", angle, x, y, z);\r
+    \r
+    try\r
+    {\r
+        es1::Context *context = es1::getContext();\r
+\r
+        if(context)\r
+        {\r
+            context->rotate(angle, x, y, z);\r
+        }\r
+    }\r
+    catch(std::bad_alloc&)\r
+    {\r
+        return error(GL_OUT_OF_MEMORY);\r
+    }\r
 }\r
 \r
 void GL_APIENTRY glRotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)\r
@@ -3344,7 +3456,21 @@ void GL_APIENTRY glSampleCoveragex(GLclampx value, GLboolean invert)
 \r
 void GL_APIENTRY glScalef(GLfloat x, GLfloat y, GLfloat z)\r
 {\r
-       UNIMPLEMENTED();\r
+       TRACE("(GLfloat x = %f, GLfloat y = %f, GLfloat z = %f)", x, y, z);\r
+    \r
+    try\r
+    {\r
+        es1::Context *context = es1::getContext();\r
+\r
+        if(context)\r
+        {\r
+            context->scale(x, y, z);\r
+        }\r
+    }\r
+    catch(std::bad_alloc&)\r
+    {\r
+        return error(GL_OUT_OF_MEMORY);\r
+    }\r
 }\r
 \r
 void GL_APIENTRY glScalex(GLfixed x, GLfixed y, GLfixed z)\r
@@ -3887,7 +4013,21 @@ void GL_APIENTRY glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLin
 \r
 void GL_APIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z)\r
 {\r
-       UNIMPLEMENTED();\r
+       TRACE("(GLfloat x = %f, GLfloat y = %f, GLfloat z = %f)", x, y, z);\r
+    \r
+    try\r
+    {\r
+        es1::Context *context = es1::getContext();\r
+\r
+        if(context)\r
+        {\r
+            context->translate(x, y, z);\r
+        }\r
+    }\r
+    catch(std::bad_alloc&)\r
+    {\r
+        return error(GL_OUT_OF_MEMORY);\r
+    }\r
 }\r
 \r
 void GL_APIENTRY glTranslatex(GLfixed x, GLfixed y, GLfixed z)\r
index b3a4689..d10d323 100644 (file)
@@ -170,6 +170,7 @@ copy "$(OutDir)libGLES_CM.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)\"</Co
     <ClCompile Include="IndexDataManager.cpp" />\r
     <ClCompile Include="libGLES_CM.cpp" />\r
     <ClCompile Include="main.cpp" />\r
+    <ClCompile Include="MatrixStack.cpp" />\r
     <ClCompile Include="RefCountObject.cpp" />\r
     <ClCompile Include="Renderbuffer.cpp" />\r
     <ClCompile Include="ResourceManager.cpp" />\r
@@ -192,6 +193,7 @@ copy "$(OutDir)libGLES_CM.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)\"</Co
     <ClInclude Include="IndexDataManager.h" />\r
     <ClInclude Include="main.h" />\r
     <ClInclude Include="mathutil.h" />\r
+    <ClInclude Include="MatrixStack.hpp" />\r
     <ClInclude Include="RefCountObject.h" />\r
     <ClInclude Include="Renderbuffer.h" />\r
     <ClInclude Include="resource.h" />\r
index b90d7b9..c78e70b 100644 (file)
@@ -59,6 +59,9 @@
     <ClCompile Include="libGLES_CM.cpp">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="MatrixStack.cpp">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="Buffer.h">\r
     <ClInclude Include="..\include\GLES\glplatform.h">\r
       <Filter>Header Files</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="MatrixStack.hpp">\r
+      <Filter>Header Files</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ResourceCompile Include="libGLES_CM.rc" />\r