2
0
Эх сурвалжийг харах

Merge pull request #740 from sgrenier/next

Misc. changes
Steve Grenier 13 жил өмнө
parent
commit
7f42a25ef6

+ 16 - 12
gameplay/res/shaders/terrain.frag

@@ -24,42 +24,46 @@ vec3 v_normalVector;                            // Normal vector variable (from
 varying vec3 v_normalVector;					// Normal vector from vertex shader
 varying vec3 v_normalVector;					// Normal vector from vertex shader
 #endif
 #endif
 varying vec2 v_texCoord0;
 varying vec2 v_texCoord0;
+#if (LAYER_COUNT > 0)
+varying vec2 v_texCoordLayer0;
+#endif
+#if (LAYER_COUNT > 1)
+varying vec2 v_texCoordLayer1;
+#endif
+#if (LAYER_COUNT > 2)
+varying vec2 v_texCoordLayer2;
+#endif
 
 
 // Lighting
 // Lighting
 #include "lighting.frag"
 #include "lighting.frag"
 #include "lighting-directional.frag"
 #include "lighting-directional.frag"
 
 
 #if (LAYER_COUNT > 1)
 #if (LAYER_COUNT > 1)
-void blendLayer(sampler2D textureMap, vec2 textureRepeat, float alphaBlend)
+void blendLayer(sampler2D textureMap, vec2 texCoord, float alphaBlend)
 {
 {
-    vec2 uv = mod(v_texCoord0 * textureRepeat, vec2(1,1));
-
     // Sample full intensity diffuse color
     // Sample full intensity diffuse color
-    vec3 diffuse = texture2D(textureMap, uv).rgb;
+    vec3 diffuse = texture2D(textureMap,  mod(texCoord, vec2(1,1))).rgb;
 
 
     _baseColor.rgb = _baseColor.rgb * (1.0 - alphaBlend) + diffuse * alphaBlend;
     _baseColor.rgb = _baseColor.rgb * (1.0 - alphaBlend) + diffuse * alphaBlend;
 }
 }
 #endif
 #endif
 
 
-
 void main()
 void main()
 {
 {
 #if (LAYER_COUNT > 0)
 #if (LAYER_COUNT > 0)
-    // Set base diffuse color
-    vec2 uvCoord = mod(v_texCoord0 * TEXTURE_REPEAT_0, vec2(1,1));
-	_baseColor.rgb = texture2D(u_samplers[TEXTURE_INDEX_0], uvCoord).rgb;
+    // Sample base texture
+	_baseColor.rgb = texture2D(u_samplers[TEXTURE_INDEX_0], mod(v_texCoordLayer0, vec2(1,1))).rgb;
     _baseColor.a = 1.0;
     _baseColor.a = 1.0;
 #else
 #else
-    // If no layers are defined, simple use a white color
+    // If no layers are defined, simply use a white color
     _baseColor = vec4(1,1,1,1);
     _baseColor = vec4(1,1,1,1);
 #endif
 #endif
 
 
 #if (LAYER_COUNT > 1)
 #if (LAYER_COUNT > 1)
-    blendLayer(u_samplers[TEXTURE_INDEX_1], TEXTURE_REPEAT_1, texture2D(u_samplers[BLEND_INDEX_1], v_texCoord0)[BLEND_CHANNEL_1]);
+    blendLayer(u_samplers[TEXTURE_INDEX_1], v_texCoordLayer1, texture2D(u_samplers[BLEND_INDEX_1], v_texCoord0)[BLEND_CHANNEL_1]);
 #endif
 #endif
-
 #if (LAYER_COUNT > 2)
 #if (LAYER_COUNT > 2)
-    blendLayer(u_samplers[TEXTURE_INDEX_2], TEXTURE_REPEAT_2, texture2D(u_samplers[BLEND_INDEX_2], v_texCoord0)[BLEND_CHANNEL_2]);
+    blendLayer(u_samplers[TEXTURE_INDEX_2], v_texCoordLayer2, texture2D(u_samplers[BLEND_INDEX_2], v_texCoord0)[BLEND_CHANNEL_2]);
 #endif
 #endif
 
 
 #if defined(DEBUG_PATCHES)
 #if defined(DEBUG_PATCHES)

+ 14 - 20
gameplay/res/shaders/terrain.vert

@@ -4,15 +4,6 @@ attribute vec4 a_position;									// Vertex Position							(x, y, z, w)
 attribute vec3 a_normal;									// Vertex Normal							(x, y, z)
 attribute vec3 a_normal;									// Vertex Normal							(x, y, z)
 #endif
 #endif
 attribute vec2 a_texCoord0;
 attribute vec2 a_texCoord0;
-#if LAYER_COUNT > 1
-attribute vec2 a_texCoord1;
-#endif
-#if LAYER_COUNT > 2
-attribute vec2 a_texCoord2;
-#endif
-#if LAYER_COUNT > 3
-attribute vec2 a_texCoord3;
-#endif
 
 
 // Uniforms
 // Uniforms
 uniform mat4 u_worldViewProjectionMatrix;					// World view projection matrix
 uniform mat4 u_worldViewProjectionMatrix;					// World view projection matrix
@@ -26,16 +17,15 @@ uniform vec3 u_lightDirection;								// Direction of light
 varying vec3 v_normalVector;								// Normal vector out
 varying vec3 v_normalVector;								// Normal vector out
 #endif
 #endif
 varying vec2 v_texCoord0;
 varying vec2 v_texCoord0;
+#if LAYER_COUNT > 0
+varying vec2 v_texCoordLayer0;
+#endif
 #if LAYER_COUNT > 1
 #if LAYER_COUNT > 1
-varying vec2 v_texCoord1;
+varying vec2 v_texCoordLayer1;
 #endif
 #endif
 #if LAYER_COUNT > 2
 #if LAYER_COUNT > 2
-varying vec2 v_texCoord2;
+varying vec2 v_texCoordLayer2;
 #endif
 #endif
-#if LAYER_COUNT > 3
-varying vec2 v_texCoord3;
-#endif
-
 
 
 void main()
 void main()
 {
 {
@@ -46,14 +36,18 @@ void main()
     // Pass normal to fragment shader
     // Pass normal to fragment shader
     v_normalVector = (u_normalMatrix * vec4(a_normal.x, a_normal.y, a_normal.z, 0)).xyz;
     v_normalVector = (u_normalMatrix * vec4(a_normal.x, a_normal.y, a_normal.z, 0)).xyz;
 #endif
 #endif
+
+    // Pass base texture coord
     v_texCoord0 = a_texCoord0;
     v_texCoord0 = a_texCoord0;
+
+    // Pass repeated texture coordinates for each layer
+#if LAYER_COUNT > 0
+    v_texCoordLayer0 = a_texCoord0 * TEXTURE_REPEAT_0;
+#endif
 #if LAYER_COUNT > 1
 #if LAYER_COUNT > 1
-    v_texCoord1 = a_texCoord1;
+    v_texCoordLayer1 = a_texCoord0 * TEXTURE_REPEAT_1;
 #endif
 #endif
 #if LAYER_COUNT > 2
 #if LAYER_COUNT > 2
-    v_texCoord2 = a_texCoord2;
-#endif
-#if LAYER_COUNT > 3
-    v_texCoord3 = a_texCoord3;
+    v_texCoordLayer2 = a_texCoord0 * TEXTURE_REPEAT_2;
 #endif
 #endif
 }
 }

+ 0 - 1
gameplay/src/Form.cpp

@@ -26,7 +26,6 @@ Form::Form() : _theme(NULL), _frameBuffer(NULL), _spriteBatch(NULL), _node(NULL)
 
 
 Form::~Form()
 Form::~Form()
 {
 {
-    SAFE_RELEASE(_node);
     SAFE_DELETE(_spriteBatch);
     SAFE_DELETE(_spriteBatch);
     SAFE_RELEASE(_frameBuffer);
     SAFE_RELEASE(_frameBuffer);
     SAFE_RELEASE(_theme);
     SAFE_RELEASE(_theme);

+ 0 - 1
gameplay/src/Node.cpp

@@ -844,7 +844,6 @@ void Node::setForm(Form* form)
     }
     }
 }
 }
 
 
-
 const BoundingSphere& Node::getBoundingSphere() const
 const BoundingSphere& Node::getBoundingSphere() const
 {
 {
     if (_dirtyBits & NODE_DIRTY_BOUNDS)
     if (_dirtyBits & NODE_DIRTY_BOUNDS)

+ 5 - 2
gameplay/src/PlatformBlackBerry.cpp

@@ -1289,7 +1289,10 @@ int Platform::enterMessagePump()
                     break;
                     break;
                 }
                 }
                 case NAVIGATOR_EXIT:
                 case NAVIGATOR_EXIT:
-                    _game->exit();
+                	// Call Game::shutdown directly, instead of Game::exit.
+                	// We need to do this since exit() queues a request to shutdown for the
+                	// next frame, which will never get executed because we are suspended.
+                    _game->shutdown();
                     break;
                     break;
                 }
                 }
             }
             }
@@ -1327,7 +1330,7 @@ int Platform::enterMessagePump()
             rc = eglSwapBuffers(__eglDisplay, __eglSurface);
             rc = eglSwapBuffers(__eglDisplay, __eglSurface);
             if (rc != EGL_TRUE)
             if (rc != EGL_TRUE)
             {
             {
-                _game->exit();
+                _game->shutdown();
                 perror("eglSwapBuffers");
                 perror("eglSwapBuffers");
                 break;
                 break;
             }
             }

+ 31 - 30
gameplay/src/Scene.h

@@ -239,6 +239,10 @@ public:
      * The visitMethod parameter must be a pointer to a method that has a bool
      * The visitMethod parameter must be a pointer to a method that has a bool
      * return type and accepts a single parameter of type Node*.
      * return type and accepts a single parameter of type Node*.
      *
      *
+     * A depth-first traversal of the scene continues while the visit method
+     * returns true. Returning false will stop traversing further children for
+     * the given node and the traversal will continue at the next sibling.
+     *
      * @param instance The pointer to an instance of the object that contains visitMethod.
      * @param instance The pointer to an instance of the object that contains visitMethod.
      * @param visitMethod The pointer to the class method to call for each node in the scene.
      * @param visitMethod The pointer to the class method to call for each node in the scene.
      */
      */
@@ -253,8 +257,11 @@ public:
      * 
      * 
      * The visitMethod parameter must be a pointer to a method that has a bool
      * The visitMethod parameter must be a pointer to a method that has a bool
      * return type and accepts two parameters: a Node pointer and a cookie of a
      * return type and accepts two parameters: a Node pointer and a cookie of a
-     * user-specified type. The scene traversal continues while visitMethod return
-     * true. Returning false will cause the traversal to stop.
+     * user-specified type.
+     *
+     * A depth-first traversal of the scene continues while the visit method
+     * returns true. Returning false will stop traversing further children for
+     * the given node and the traversal will continue at the next sibling.
      *
      *
      * @param instance The pointer to an instance of the object that contains visitMethod.
      * @param instance The pointer to an instance of the object that contains visitMethod.
      * @param visitMethod The pointer to the class method to call for each node in the scene.
      * @param visitMethod The pointer to the class method to call for each node in the scene.
@@ -273,6 +280,10 @@ public:
      * valid Lua function that has a boolean return type and accepts a 
      * valid Lua function that has a boolean return type and accepts a 
      * single parameter of type Node*.
      * single parameter of type Node*.
      *
      *
+     * A depth-first traversal of the scene continues while the visit method
+     * returns true. Returning false will stop traversing further children for
+     * the given node and the traversal will continue at the next sibling.
+     *
      * @param visitMethod The name of the Lua function to call for each node in the scene.
      * @param visitMethod The name of the Lua function to call for each node in the scene.
      */
      */
     inline void visit(const char* visitMethod);
     inline void visit(const char* visitMethod);
@@ -311,18 +322,18 @@ private:
      * Visits the given node and all of its children recursively.
      * Visits the given node and all of its children recursively.
      */
      */
     template <class T>
     template <class T>
-    bool visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*));
+    void visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*));
 
 
     /**
     /**
      * Visits the given node and all of its children recursively.
      * Visits the given node and all of its children recursively.
      */
      */
     template <class T, class C>
     template <class T, class C>
-    bool visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*,C), C cookie);
+    void visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*,C), C cookie);
 
 
     /**
     /**
      * Visits the given node and all of its children recursively.
      * Visits the given node and all of its children recursively.
      */
      */
-    inline bool visitNode(Node* node, const char* visitMethod);
+    inline void visitNode(Node* node, const char* visitMethod);
 
 
     std::string _id;
     std::string _id;
     Camera* _activeCamera;
     Camera* _activeCamera;
@@ -341,8 +352,7 @@ void Scene::visit(T* instance, bool (T::*visitMethod)(Node*))
 {
 {
     for (Node* node = getFirstNode(); node != NULL; node = node->getNextSibling())
     for (Node* node = getFirstNode(); node != NULL; node = node->getNextSibling())
     {
     {
-        if (!visitNode(node, instance, visitMethod))
-            return;
+        visitNode(node, instance, visitMethod);
     }
     }
 }
 }
 
 
@@ -352,8 +362,7 @@ void Scene::visit(T* instance, bool (T::*visitMethod)(Node*,C), C cookie)
 {
 {
     for (Node* node = getFirstNode(); node != NULL; node = node->getNextSibling())
     for (Node* node = getFirstNode(); node != NULL; node = node->getNextSibling())
     {
     {
-        if (!visitNode(node, instance, visitMethod, cookie))
-            return;
+        visitNode(node, instance, visitMethod, cookie);
     }
     }
 }
 }
 
 
@@ -361,59 +370,51 @@ inline void Scene::visit(const char* visitMethod)
 {
 {
     for (Node* node = getFirstNode(); node != NULL; node = node->getNextSibling())
     for (Node* node = getFirstNode(); node != NULL; node = node->getNextSibling())
     {
     {
-        if (!visitNode(node, visitMethod))
-            return;
+        visitNode(node, visitMethod);
     }
     }
 }
 }
 
 
 template <class T>
 template <class T>
-bool Scene::visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*))
+void Scene::visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*))
 {
 {
     // Invoke the visit method for this node.
     // Invoke the visit method for this node.
     if (!(instance->*visitMethod)(node))
     if (!(instance->*visitMethod)(node))
-        return false;
+        return;
 
 
     // Recurse for all children.
     // Recurse for all children.
     for (Node* child = node->getFirstChild(); child != NULL; child = child->getNextSibling())
     for (Node* child = node->getFirstChild(); child != NULL; child = child->getNextSibling())
     {
     {
-        if (!visitNode(child, instance, visitMethod))
-            return false;
+        visitNode(child, instance, visitMethod);
     }
     }
-
-    return true;
 }
 }
 
 
 template <class T, class C>
 template <class T, class C>
-bool Scene::visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*,C), C cookie)
+void Scene::visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*,C), C cookie)
 {
 {
     // Invoke the visit method for this node.
     // Invoke the visit method for this node.
     if (!(instance->*visitMethod)(node, cookie))
     if (!(instance->*visitMethod)(node, cookie))
-        return false;
+        return;
 
 
     // Recurse for all children.
     // Recurse for all children.
     for (Node* child = node->getFirstChild(); child != NULL; child = child->getNextSibling())
     for (Node* child = node->getFirstChild(); child != NULL; child = child->getNextSibling())
     {
     {
-        if (!visitNode(child, instance, visitMethod, cookie))
-            return false;
+        visitNode(child, instance, visitMethod, cookie);
     }
     }
-
-    return true;
 }
 }
 
 
-inline bool Scene::visitNode(Node* node, const char* visitMethod)
+inline void Scene::visitNode(Node* node, const char* visitMethod)
 {
 {
+    ScriptController* sc = Game::getInstance()->getScriptController();
+
     // Invoke the visit method for this node.
     // Invoke the visit method for this node.
-    if (!Game::getInstance()->getScriptController()->executeFunction<bool>(visitMethod, "<Node>", node))
-        return false;
+    if (!sc->executeFunction<bool>(visitMethod, "<Node>", node))
+        return;
 
 
     // Recurse for all children.
     // Recurse for all children.
     for (Node* child = node->getFirstChild(); child != NULL; child = child->getNextSibling())
     for (Node* child = node->getFirstChild(); child != NULL; child = child->getNextSibling())
     {
     {
-        if (!Game::getInstance()->getScriptController()->executeFunction<bool>(visitMethod, "<Node>", child))
-            return false;
+        visitNode(child, visitMethod);
     }
     }
-
-    return true;
 }
 }
 
 
 }
 }

+ 12 - 0
gameplay/src/Terrain.cpp

@@ -554,6 +554,18 @@ const Matrix& Terrain::getNormalMatrix() const
     return _normalMatrix;
     return _normalMatrix;
 }
 }
 
 
+const Matrix& Terrain::getWorldViewMatrix() const
+{
+    static Matrix worldView;
+
+    if (_node)
+        Matrix::multiply(_node->getViewMatrix(), getWorldMatrix(), &worldView);
+    else
+        worldView = getWorldMatrix(); // no node, so nothing to get view from
+
+    return worldView;
+}
+
 const Matrix& Terrain::getWorldViewProjectionMatrix() const
 const Matrix& Terrain::getWorldViewProjectionMatrix() const
 {
 {
     static Matrix worldViewProj;
     static Matrix worldViewProj;

+ 6 - 0
gameplay/src/Terrain.h

@@ -12,6 +12,7 @@ namespace gameplay
 {
 {
 
 
 class Node;
 class Node;
+class TerrainPatch;
 
 
 /**
 /**
  * Defines a Terrain that is capable of rendering large landscapes from 2D heightmap images.
  * Defines a Terrain that is capable of rendering large landscapes from 2D heightmap images.
@@ -351,6 +352,11 @@ private:
      */
      */
     const Matrix& getNormalMatrix() const;
     const Matrix& getNormalMatrix() const;
 
 
+    /**
+     * Returns the world view matrix for the terrain, factoring in terrain local scaling.
+     */
+    const Matrix& getWorldViewMatrix() const;
+
     /**
     /**
      * Returns the world view projection matrix for the terrain, factoring in terrain local scaling.
      * Returns the world view projection matrix for the terrain, factoring in terrain local scaling.
      */
      */