Browse Source

Merge pull request #28 from blackberry-gaming/next-setaylor

Added Support for MacOSX using XCode 4.0
Sean Paul Taylor 14 years ago
parent
commit
9a3f5610fa
4 changed files with 56 additions and 50 deletions
  1. 1 1
      gameplay/src/Base.h
  2. 9 9
      gameplay/src/Effect.cpp
  3. 22 19
      gameplay/src/Font.cpp
  4. 24 21
      gameplay/src/SpriteBatch.cpp

+ 1 - 1
gameplay/src/Base.h

@@ -142,7 +142,7 @@ extern void printError(const char* format, ...);
     extern PFNGLGENVERTEXARRAYSOESPROC glGenVertexArrays;
     extern PFNGLISVERTEXARRAYOESPROC glIsVertexArray;
     #define glClearDepth glClearDepthf
-   #define GL_ES
+   #define OPENGL_ES
 #elif WIN32
     #define WIN32_LEAN_AND_MEAN
     #include <GL/glew.h>

+ 9 - 9
gameplay/src/Effect.cpp

@@ -6,7 +6,7 @@
 #include "Effect.h"
 #include "FileSystem.h"
 
-#define GL_ES_DEFINE  "#define OPENGL_ES"
+#define OPENGL_ES_DEFINE  "#define OPENGL_ES"
 
 namespace gameplay
 {
@@ -111,13 +111,12 @@ Effect* Effect::createFromSource(const char* vshPath, const char* vshSource, con
     GLint length;
     GLint success;
 
-    std::string definesStr = (defines == NULL) ? "" : defines;
-
     // Compile vertex shader.
-#ifdef GL_ES
-    if (defines)
+    std::string definesStr = (defines == NULL) ? "" : defines;
+#ifdef OPENGL_ES
+    if (defines && strlen(defines) != 0)
         definesStr += "\n";
-    definesStr+= GL_ES_DEFINE;
+    definesStr+= OPENGL_ES_DEFINE;
 #endif
     shaderSource[0] = definesStr.c_str();
     shaderSource[1] = "\n";
@@ -145,10 +144,11 @@ Effect* Effect::createFromSource(const char* vshPath, const char* vshSource, con
     }
 
     // Compile the fragment shader.
-#ifdef GL_ES
-    if (defines)
+    definesStr = (defines == NULL) ? "" : defines;
+#ifdef OPENGL_ES
+    if (defines && strlen(defines) != 0)
         definesStr += "\n";
-    definesStr+= GL_ES_DEFINE;
+    definesStr+= OPENGL_ES_DEFINE;
 #endif
     shaderSource[0] = definesStr.c_str();
     shaderSource[1] = "\n";

+ 22 - 19
gameplay/src/Font.cpp

@@ -10,28 +10,31 @@
 
 // Default font vertex shader
 #define FONT_VSH \
-    "uniform mat4 sb_projection_matrix;" \
-    "attribute vec3 a_position;" \
-    "attribute vec2 a_texcoord;" \
-    "attribute vec4 a_color;" \
-    "varying vec2 vtexcoord;" \
-    "varying vec4 vcolor;" \
-    "void main()" \
-    "{" \
-        "gl_Position = sb_projection_matrix * vec4(a_position, 1);" \
-        "vtexcoord = a_texcoord;" \
-        "vcolor = a_color;" \
-    "}"
+    "uniform mat4 u_projectionMatrix;\n" \
+    "attribute vec3 a_position;\n" \
+    "attribute vec2 a_texcoord;\n" \
+    "attribute vec4 a_color;\n" \
+    "varying vec2 v_texcoord;\n" \
+    "varying vec4 v_color;\n" \
+    "void main()\n" \
+    "{\n" \
+        "gl_Position = u_projectionMatrix * vec4(a_position, 1);\n" \
+        "v_texcoord = a_texcoord;\n" \
+        "v_color = a_color;\n" \
+    "}\n"
 
 // Default font fragment shader
 #define FONT_FSH \
-    "varying vec2 vtexcoord;" \
-    "varying vec4 vcolor;" \
-    "uniform sampler2D texture;" \
-    "void main()" \
-    "{" \
-        "gl_FragColor = vcolor;" \
-        "gl_FragColor.a = texture2D(texture, vtexcoord).a;" \
+    "#ifdef OPENGL_ES\n" \
+    "precision highp float;\n" \
+    "#endif\n" \
+    "varying vec2 v_texcoord;\n" \
+    "varying vec4 v_color;\n" \
+    "uniform sampler2D u_texture;\n" \
+    "void main()\n" \
+    "{\n" \
+        "gl_FragColor = v_color;\n" \
+        "gl_FragColor.a = texture2D(u_texture, v_texcoord).a;\n" \
     "}"
 
 namespace gameplay

+ 24 - 21
gameplay/src/SpriteBatch.cpp

@@ -19,28 +19,31 @@
 
 // Default sprite vertex shader
 #define SPRITE_VSH \
-    "uniform mat4 sb_projection_matrix;" \
-    "attribute vec3 a_position;" \
-    "attribute vec2 a_texcoord;" \
-    "attribute vec4 a_color;" \
-    "varying vec2 vtexcoord;" \
-    "varying vec4 vcolor;" \
-    "void main()" \
-    "{" \
-        "gl_Position = sb_projection_matrix * vec4(a_position, 1);" \
-        "vtexcoord = a_texcoord;" \
-        "vcolor = a_color;" \
-    "}"
+    "uniform mat4 u_projectionMatrix;\n" \
+    "attribute vec3 a_position;\n" \
+    "attribute vec2 a_texcoord;\n" \
+    "attribute vec4 a_color;\n" \
+    "varying vec2 v_texcoord;\n" \
+    "varying vec4 v_color;\n" \
+    "void main()\n" \
+    "{\n" \
+        "gl_Position = u_projectionMatrix * vec4(a_position, 1);\n" \
+        "v_texcoord = a_texcoord;\n" \
+        "v_color = a_color;\n" \
+    "}\n"
 
 // Default sprite fragment shader
 #define SPRITE_FSH \
-    "varying vec2 vtexcoord;" \
-    "varying vec4 vcolor;" \
-    "uniform sampler2D texture;" \
-    "void main()" \
-    "{" \
-        "gl_FragColor = vcolor * texture2D(texture, vtexcoord);" \
-    "}"
+    "#ifdef OPENGL_ES\n" \
+    "precision highp float;\n" \
+    "#endif\n" \
+    "varying vec2 v_texcoord;\n" \
+    "varying vec4 v_color;\n" \
+    "uniform sampler2D u_texture;\n" \
+    "void main()\n" \
+    "{\n" \
+        "gl_FragColor = v_color * texture2D(u_texture, v_texcoord);\n" \
+    "}\n"
 
 namespace gameplay
 {
@@ -146,8 +149,8 @@ SpriteBatch* SpriteBatch::create(Texture* texture, Effect* effect, unsigned int
     batch->_textureHeightRatio = 1.0f / (float)texture->getHeight();
     batch->resizeBatch(initialCapacity > 0 ? initialCapacity : SPRITE_BATCH_DEFAULT_SIZE);
 
-    // If there is a uniform named 'sb_projection_matrix', store it so that we can set our projection matrix to it
-    batch->_projectionUniform = effect->getUniform("sb_projection_matrix");
+    // If there is a uniform named 'u_projectionMatrix', store it so that we can set our projection matrix to it
+    batch->_projectionUniform = effect->getUniform("u_projectionMatrix");
     if (batch->_projectionUniform)
     {
         batch->_projectionMatrix = new Matrix();