You can subscribe to this list here.
| 2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(46) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2006 |
Jan
(185) |
Feb
(242) |
Mar
(237) |
Apr
(180) |
May
(102) |
Jun
(278) |
Jul
(114) |
Aug
(92) |
Sep
(246) |
Oct
(212) |
Nov
(279) |
Dec
(99) |
| 2007 |
Jan
(130) |
Feb
(194) |
Mar
(22) |
Apr
(72) |
May
(40) |
Jun
(111) |
Jul
(114) |
Aug
(154) |
Sep
(114) |
Oct
(2) |
Nov
(1) |
Dec
(5) |
| 2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(6) |
Oct
(51) |
Nov
(34) |
Dec
(130) |
| 2009 |
Jan
(22) |
Feb
(20) |
Mar
(41) |
Apr
(45) |
May
(82) |
Jun
(96) |
Jul
(48) |
Aug
(90) |
Sep
(13) |
Oct
(49) |
Nov
(31) |
Dec
(21) |
| 2010 |
Jan
(25) |
Feb
(9) |
Mar
(7) |
Apr
(28) |
May
(27) |
Jun
(7) |
Jul
(1) |
Aug
|
Sep
(1) |
Oct
(1) |
Nov
(13) |
Dec
(2) |
| 2013 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <cn...@us...> - 2009-03-20 03:38:01
|
Revision: 187
http://hgengine.svn.sourceforge.net/hgengine/?rev=187&view=rev
Author: cnlohr
Date: 2009-03-20 03:37:43 +0000 (Fri, 20 Mar 2009)
Log Message:
-----------
add shaders (not yet working)
Added Paths:
-----------
Mercury2/src/Shader.cpp
Mercury2/src/Shader.h
Added: Mercury2/src/Shader.cpp
===================================================================
--- Mercury2/src/Shader.cpp (rev 0)
+++ Mercury2/src/Shader.cpp 2009-03-20 03:37:43 UTC (rev 187)
@@ -0,0 +1,431 @@
+#include <Shader.h>
+#include <RenderableNode.h>
+#include <MercuryFile.h>
+
+#define GL_GLEXT_PROTOTYPES
+
+#include <GL/gl.h>
+#include <GL/glext.h>
+
+using namespace std;
+
+REGISTER_ASSET_TYPE( Shader );
+
+ShaderAttributesSet SHADERATTRIBUTES;
+Shader * Shader::CurrentShader;
+
+ShaderAttribute * ShaderAttributesSet::GetHandle( const MString & sName )
+{
+ ShaderAttribute * ret = m_AllShaderAttributes[sName];
+ if( !ret )
+ {
+ ret = new ShaderAttribute();
+ m_AllShaderAttributes[sName] = ret;
+ }
+ return ret;
+}
+
+Shader::Shader()
+{
+ iProgramID = (GLhandleARB)NULL;
+ vertexShader = (GLhandleARB)NULL;
+ fragmentShader = (GLhandleARB)NULL;
+ geometryShader = (GLhandleARB)NULL;
+ iTimeCode[0] = 0;
+ iTimeCode[1] = 0;
+ iTimeCode[2] = 0;
+
+}
+
+Shader::~Shader()
+{
+ DestroyShader( );
+}
+
+void Shader::Init(MercuryNode* node)
+{
+ MercuryAsset::Init( node );
+ RenderableNode* rn;
+ if ( (rn=RenderableNode::Cast( node )) )
+ rn->AddPostRender( this );
+}
+
+void Shader::Render(const MercuryNode* node)
+{
+ bool bApply = true;
+
+ //If there's a currnet shader, we may want to abort switching shaders
+ if( CurrentShader )
+ {
+ if( CurrentShader->fPriority > fPriority )
+ bApply = false;
+ }
+ if( bApply )
+ {
+ OriginalShader = CurrentShader;
+ CurrentShader = this;
+ ActivateShader();
+ }
+}
+
+void Shader::PostRender(const MercuryNode* node)
+{
+ CurrentShader = OriginalShader;
+ if( OriginalShader )
+ OriginalShader->ActivateShader();
+ else
+ DeactivateShader();
+}
+
+void Shader::LoadFromXML(const XMLNode& node)
+{
+ sShaderName = node.Attribute("file");
+ fPriority = atof( node.Attribute("priority").c_str() );
+ LoadShader( );
+}
+
+bool Shader::LoadShader( )
+{
+ GetTimeCodes( iTimeCode );
+ MString s1 = sShaderName, s2 = sShaderName, s3 = sShaderName;
+ MercuryFile * f1;
+ MercuryFile * f2;
+ MercuryFile * f3; //geometry
+ char * Buffer;
+ int i;
+
+ s1 += ".frag";
+ s2 += ".vert";
+ s3 += ".geom";
+ f1 = FILEMAN.Open( s1 );
+ f2 = FILEMAN.Open( s2 );
+ f3 = FILEMAN.Open( s3 );
+
+ if( f1 == 0 || f2 == 0 )
+ {
+ if( !f1 )
+ printf( "Could not open %s.\n", (char*)s1.c_str() );
+ if( !f2 )
+ printf( "Could not open %s.\n", (char*)s2.c_str() );
+ return false;
+ }
+ if( f1 )
+ {
+ i = f1->Length();
+ Buffer = (char*)malloc( i+1 );
+ f1->Read( Buffer, i );
+ f1->Close();
+ printf( "Compiling: %s\n", s1.c_str() );
+ Buffer[i] = '\0';
+ if( !LoadShaderFrag( Buffer ) )
+ {
+ free( Buffer );
+ if( f2 )
+ f2->Close();
+ if( f3 )
+ f3->Close();
+ printf( "Reporting failed shaderload. Not linking.\n" );
+ return false;
+ }
+ free( Buffer );
+ }
+ if( f2 )
+ {
+ i = f2->Length();
+ Buffer = (char*)malloc( i+1 );
+ f2->Read( Buffer, i );
+ f2->Close();
+ Buffer[i] = '\0';
+ printf( "Compiling: %s\n", s2.c_str() );
+ if( !LoadShaderVert( Buffer ) )
+ {
+ if( f3 )
+ f3->Close();
+ free( Buffer );
+ printf( "Reporting failed shaderload. Not linking.\n" );
+ return false;
+ }
+ free( Buffer );
+ }
+ if( f3 )
+ {
+ i = f3->Length();
+ Buffer = (char*)malloc( i+1 );
+ f3->Read( Buffer, i );
+ f3->Close();
+ Buffer[i] = '\0';
+ printf( "Compiling: %s\n", s3.c_str() );
+ if( !LoadShaderGeom( Buffer ) )
+ {
+ free( Buffer );
+ printf( "Reporting failed shaderload. Not linking.\n" );
+ return false;
+ }
+ free( Buffer );
+ }
+ return LinkShaders();
+}
+
+bool Shader::LoadShaderFrag( const char * sShaderCode )
+{
+ if( strlen( sShaderCode ) < 5 )
+ return false;
+
+ GLint bFragCompiled;
+ GLint stringLength;
+ fragmentShader = glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB );
+ glShaderSourceARB( fragmentShader, 1, &sShaderCode, NULL );
+ glCompileShaderARB( fragmentShader );
+
+ glGetObjectParameterivARB( fragmentShader, GL_OBJECT_COMPILE_STATUS_ARB, &bFragCompiled );
+ glGetObjectParameterivARB( fragmentShader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &stringLength );
+ if ( stringLength > 1 )
+ {
+ char * tmpstr = (char*)malloc( stringLength + 1 );
+ glGetInfoLogARB( fragmentShader, stringLength, NULL, tmpstr );
+ puts( "Compiling Fragment Shader response follows:" );
+ puts( tmpstr );
+ free( tmpstr );
+ return bFragCompiled!=0;
+ }
+ return true;
+}
+
+bool Shader::LoadShaderVert( const char * sShaderCode )
+{
+ if( strlen( sShaderCode ) < 5 )
+ return false;
+
+ GLint bVertCompiled;
+ GLint stringLength;
+ //Create a new vertex shader
+ vertexShader = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );
+ //Bind the shader to the text, setting that to be its source.
+ glShaderSourceARB( vertexShader, 1, &sShaderCode, NULL );
+ //Compile the shader
+ glCompileShaderARB( vertexShader );
+ //Did the shader compile? Were there any errors?
+ glGetObjectParameterivARB( vertexShader, GL_OBJECT_COMPILE_STATUS_ARB, &bVertCompiled );
+ glGetObjectParameterivARB( vertexShader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &stringLength );
+ if( stringLength > 1 )
+ {
+ char * tmpstr = (char*)malloc( stringLength + 1 );
+ glGetInfoLogARB( vertexShader, stringLength, NULL, tmpstr );
+ puts( "Compiling Vertex Shader response follows:" );
+ puts( tmpstr );
+ free( tmpstr );
+ return bVertCompiled!=0;
+ }
+
+ return true;
+}
+
+bool Shader::LoadShaderGeom( const char * sShaderCode )
+{
+ if( strlen( sShaderCode ) < 5 )
+ return false;
+
+ GLint bGeomCompiled;
+ GLint stringLength;
+ //Create a new geometry shader
+ geometryShader = glCreateShaderObjectARB( GL_GEOMETRY_SHADER_EXT );
+ //Bind the shader to the text, setting that to be its source.
+ glShaderSourceARB( geometryShader, 1, &sShaderCode, NULL );
+ //Compile the shader
+ glCompileShaderARB( geometryShader );
+ //Did the shader compile? Were there any errors?
+ glGetObjectParameterivARB( geometryShader, GL_OBJECT_COMPILE_STATUS_ARB, &bGeomCompiled );
+ glGetObjectParameterivARB( geometryShader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &stringLength );
+ if( bGeomCompiled == 0 )
+ {
+ char * tmpstr = (char*)malloc( stringLength + 1 );
+ glGetInfoLogARB( geometryShader, stringLength, NULL, tmpstr );
+ puts( "Compiling Geometry Shader response follows:" );
+ puts( tmpstr );
+ free( tmpstr );
+ return bGeomCompiled!=0;
+ }
+ return true;
+}
+
+bool Shader::LinkShaders()
+{
+ GLint bLinked;
+ GLint stringLength;
+ //Create the actual shader prgoram
+ iProgramID = glCreateProgramObjectARB();
+ //Attach the fragment/vertex shader to it.
+ if( vertexShader )
+ glAttachObjectARB( iProgramID, vertexShader );
+ if( fragmentShader )
+ glAttachObjectARB( iProgramID, fragmentShader );
+ if( geometryShader )
+ glAttachObjectARB( iProgramID, geometryShader );
+ //Attempt to link the shader
+ glLinkProgramARB( iProgramID );
+
+ //If we're using a geometry shader, we have to do a little extra.
+ if( geometryShader )
+ {
+ glProgramParameteriEXT( iProgramID, GL_GEOMETRY_INPUT_TYPE_EXT, GL_TRIANGLES );
+ glProgramParameteriEXT( iProgramID, GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP );
+
+ int ierror, i;
+ GLint imaxvert;
+ glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT,&imaxvert);
+ if( (ierror = glGetError()) != 0 )
+ {
+ puts( "ERROR: You cannot load a geometry shader when there are still errors left in OpenGL." );
+ puts( "Please track down the error remaining by using glGetError() to cordon off your code." );
+ printf( "The last error received was: %d\n", ierror );
+ }
+ for( i = 1; i < imaxvert; i++ )
+ {
+ glProgramParameteriEXT(iProgramID,GL_GEOMETRY_VERTICES_OUT_EXT,imaxvert/i);
+ if( glGetError() == 0 )
+ break;
+ }
+ printf( "Geometry Shader loaded with a total of %d max verticies. Because there are %d max vertices, and %d preceived components per vert.\n", imaxvert/i, imaxvert, i );
+ }
+
+
+ //See if there were any errors.
+ glGetObjectParameterivARB( iProgramID, GL_OBJECT_LINK_STATUS_ARB, &bLinked );
+ glGetObjectParameterivARB( iProgramID, GL_OBJECT_INFO_LOG_LENGTH_ARB, &stringLength );
+
+ if ( stringLength > 1 || bLinked == 0 )
+ {
+ char * tmpstr = (char*)malloc( stringLength + 1 );
+ glGetInfoLogARB( iProgramID, stringLength, NULL, tmpstr );
+ puts( "Linking shaders. response follows:" );
+ puts( tmpstr );
+ free( tmpstr );
+ return bLinked!=0;
+ }
+
+ //Build the list of uniform tabs.
+ int iNumUniforms;
+ glGetObjectParameterivARB( iProgramID, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &iNumUniforms );
+ m_vShaderTabs.resize( iNumUniforms );
+ for( int i = 0; i < iNumUniforms; ++i )
+ {
+ char buffer[1024];
+ int bufflen;
+ GLint size;
+ GLenum type;
+ glGetActiveUniformARB( iProgramID, i, 1024, &bufflen, &size, &type, buffer );
+ buffer[bufflen] = 0;
+ m_vShaderTabs[i] = SHADERATTRIBUTES.GetHandle( buffer );
+ }
+ return true;
+}
+
+void Shader::DestroyShader()
+{
+ GLhandleARB *objects = NULL;
+ GLint i, count = -1;
+
+ if( !iProgramID )
+ return;
+
+ //If we can't destroy the object, then don't try.
+ glGetObjectParameterivARB(iProgramID, GL_OBJECT_ATTACHED_OBJECTS_ARB, &count);
+
+ //Iterate through all children.
+ if (count > 0)
+ {
+ objects = (GLhandleARB *)malloc(count*sizeof(GLhandleARB));
+ glGetAttachedObjectsARB(iProgramID, count, NULL, objects);
+ }
+ else
+ return;
+
+ for ( i = 0; i < count; ++i)
+ {
+ glDetachObjectARB(iProgramID, objects[i]);
+ }
+
+ glDeleteObjectARB(iProgramID);
+ free( objects );
+ return;
+}
+
+void Shader::CheckForNewer( )
+{
+ unsigned long iCurTimes[3];
+ GetTimeCodes( iCurTimes );
+ if( iCurTimes[0] != iTimeCode[0] || iCurTimes[1] != iTimeCode[1] || iCurTimes[2] != iTimeCode[2] )
+ {
+ DestroyShader( );
+ LoadShader( );
+ }
+}
+
+void Shader::GetTimeCodes( unsigned long * iOut )
+{
+ MercuryFile * f = FILEMAN.Open( sShaderName + ".frag" );
+ iOut[0] = f->GetModTime();
+ f->Close();
+
+ f = FILEMAN.Open( sShaderName + ".vert" );
+ iOut[1] = f->GetModTime();
+ f->Close();
+
+ f = FILEMAN.Open( sShaderName + ".geom" );
+ iOut[2] = f->GetModTime();
+ f->Close();
+}
+
+void Shader::ActivateShader()
+{
+ glUseProgramObjectARB( iProgramID );
+
+ for( unsigned i = 0; i < m_vShaderTabs.size(); ++i )
+ {
+ ShaderAttribute * sa = m_vShaderTabs[i];
+ switch( sa->typ )
+ {
+ case ShaderAttribute::TYPE_INT:
+ case ShaderAttribute::TYPE_SAMPLER:
+ glUniform1iARB( i, sa->sau.iInt );
+ break;
+ case ShaderAttribute::TYPE_FLOAT:
+ case ShaderAttribute::TYPE_FLOATV4:
+ glUniform4fvARB( i, 4, &sa->sau.fFloatV4[0] );
+ };
+ }
+}
+
+void Shader::DeactivateShader()
+{
+ glUseProgramObjectARB( 0 );
+}
+
+
+/*
+ * Copyright (c) 2009 Charles Lohr
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Mercury Engine nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
Added: Mercury2/src/Shader.h
===================================================================
--- Mercury2/src/Shader.h (rev 0)
+++ Mercury2/src/Shader.h 2009-03-20 03:37:43 UTC (rev 187)
@@ -0,0 +1,185 @@
+#ifndef SHADER_H
+#define SHADER_H
+
+#include <MercuryAsset.h>
+#include <map>
+#include <vector>
+
+///Basic Attribute for all shaders
+class ShaderAttribute
+{
+public:
+ ShaderAttribute() : typ( TYPE_INT ) { sau.iInt = 0; }
+
+ ///Type of ShaderAttribute for shader
+ enum ShaderAttributeTyp
+ {
+ TYPE_INT, ///Synonomous to 'int' when passing into a shader
+ TYPE_SAMPLER, ///Synonomous to 'sampler2D' when passing into a shader
+ TYPE_FLOAT, ///Synonomous to 'float' when passing into a shader
+ TYPE_FLOATV4 ///Synonomous to 'vec4' when passing into a shader
+ } typ;
+
+ ///Actual data for value.
+ union ShaderAttributeVal
+ {
+ int iInt; ///Synonomous to 'int'
+ unsigned int iSampler; ///Synonomous to 'sampler2D'
+ float fFloat; ///Synonomous to 'float'
+ float fFloatV4[4]; ///Synonomous to 'vec4'
+ } sau;
+};
+
+///Shader Attribute Retainer
+class ShaderAttributesSet
+{
+public:
+ ShaderAttribute * GetHandle( const MString & sName );
+private:
+ ///All shader attributes
+ /** This contains a list of all attributes that are passed in.
+ If a shader does not have an attribute, it does not insert
+ it here. Note that if shaders change and an element is
+ no longer referenced, it will remain in the map, as to
+ prevent bad pointers. This list is all-enduring.
+ */
+ std::map< MString, ShaderAttribute * > m_AllShaderAttributes;
+};
+
+extern ShaderAttributesSet SHADERATTRIBUTES;
+
+///Basic element for turning shaders on and off
+/** This class helps aide in the loading and use of shaders. It allows loading of files
+ through the LoadShader() function that actively looks for .frag and .vert files. By use
+ of the CheckForNewer() function, the class looks for changes, if any changes are found
+ the shaders will be re-loaded, compiled and linked. Once this node has a shader loaded,
+ the shader can be activated or deactivated using the ActivateShader() and
+ DeactivateShader() functions respectively. Note that shaders do not stack. When you
+ call DeactiveShader(), it does not bring back previously activated shaders. It simply
+ turns all shaders off. */
+class Shader : public MercuryAsset
+{
+public:
+ Shader();
+ virtual ~Shader();
+
+ virtual void Init(MercuryNode* node);
+ virtual void Render(const MercuryNode* node);
+ virtual void PostRender(const MercuryNode* node);
+ static Shader* Generate() { return new Shader; }
+ virtual void LoadFromXML(const XMLNode& node);
+
+ ///Explicitly get the OpenGL ProgramID in the event you need it for advanced techniques
+ unsigned int GetProgramID() { return iProgramID; }
+private:
+ ///Suggested function for loading shaders.
+ /** This function looks for {sShaderName}.vert and {sShaderName}.frag. It will
+ attempt to load, compile and link the files. If any errors are found, they will
+ be announced at STDOUT. When Geometry shader support is added, it will search
+ for .geom files */
+ bool LoadShader( );
+
+ ///Explicitly load a fragment shader
+ /** This function takes on raw code in the sShaderCode string and attemps to compile
+ it. Any errors it runs into will be displayed at STDOUT. Note you are
+ discouraged to use this function, in favor of using LoadShader(). */
+ bool LoadShaderFrag( const char * sShaderCode );
+
+ ///Explicitly load a vertex shader
+ /** This function takes on raw code in the sShaderCode string and attemps to compile
+ it. Any errors it runs into will be displayed at STDOUT. You should use
+ LoadShader() instead of this function. */
+ bool LoadShaderVert( const char * sShaderCode );
+
+ ///Explicitly load a geometry shader
+ /** This function takes on raw code in the sShaderCode string and attemps to compile
+ it. Any errors it runs into will be displayed at STDOUT. You should use
+ LoadShader() instead of this function. */
+ bool LoadShaderGeom( const char * sShaderCode );
+
+ ///Explicitly link all shaders currently loaded
+ /** This takes vertexShader and fragmentShader and converts them into iProgramID.
+ this function is discouraged when using LoadShader(). */
+ bool LinkShaders();
+
+ ///Check for newer version of 'this' shader
+ void CheckForNewer( );
+
+ ///Get the last modified time for sShaderName
+ /* This function takes on iOut as being where to put the last time the shader was modified.
+ this value is system dependent and is necessiarly not linked to anything like seconds. */
+ void GetTimeCodes( unsigned long * iOut );
+
+ ///Activate Shader (apply to current OpenGL state)
+ void ActivateShader();
+
+ ///Turn all shaders off in OpenGL state.
+ void DeactivateShader();
+
+ ///Destroy this shader
+ void DestroyShader();
+
+ ///The last time codes (for vertex and fragment shaders respectively)
+ unsigned long iTimeCode[3];
+
+ ///The OpenGL Program ID (in OpenGL Land, contains all shaders, linked together)
+ unsigned int iProgramID;
+
+ ///The OpenGL Geometry Program ID
+ unsigned int geometryShader;
+
+ ///The OpenGL Vertex Program ID
+ unsigned int vertexShader;
+
+ ///The OpenGL Fragment Program ID
+ unsigned int fragmentShader;
+
+ ///Shader attributes
+ /** This is the system that helps make it possible to blast
+ through all attributes currently set up by dereferencing
+ the pointers in the attributes repository.
+ */
+ std::vector< ShaderAttribute * > m_vShaderTabs;
+
+ ///Name of the shader
+ MString sShaderName;
+
+ ///Priority of THIS shader (if lower than currently active one, it does not become active)
+ float fPriority;
+
+ ///Global static shader (so shaders can recursively activate and deactivate shaders)
+ static Shader * CurrentShader;
+
+ ///Original Shader (to re-enable when leaving)
+ Shader * OriginalShader;
+};
+
+#endif
+
+/*
+ * Copyright (c) 2009 Charles Lohr
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Mercury Engine nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2009-03-20 03:37:29
|
Revision: 186
http://hgengine.svn.sourceforge.net/hgengine/?rev=186&view=rev
Author: cnlohr
Date: 2009-03-20 03:37:22 +0000 (Fri, 20 Mar 2009)
Log Message:
-----------
prepare for shaders
Modified Paths:
--------------
Mercury2/adv_set.c
Mercury2/src/MercuryFile.h
Modified: Mercury2/adv_set.c
===================================================================
--- Mercury2/adv_set.c 2009-03-20 01:55:12 UTC (rev 185)
+++ Mercury2/adv_set.c 2009-03-20 03:37:22 UTC (rev 186)
@@ -10,7 +10,7 @@
src/MercuryVBO.cpp src/MSemaphore.cpp src/UpdateThreader.cpp src/HGMDLMesh.cpp \
src/HGMDLModel.cpp src/MercuryString.cpp src/MercuryCrash.c src/MercuryBacktrace.c \
src/MercuryFile.cpp src/MercuryTimer.cpp src/MercuryMessageManager.cpp src/MercuryVertex.cpp \
- src/MercuryPlane.cpp src/BoundingBox.cpp"
+ src/MercuryPlane.cpp src/BoundingBox.cpp src/Shader.cpp"
SOURCES="$SOURCES src/MercuryFileDriverDirect.cpp src/MercuryFileDriverMem.cpp \
src/MercuryFileDriverPacked.cpp src/MercuryFileDriverZipped.cpp"
Modified: Mercury2/src/MercuryFile.h
===================================================================
--- Mercury2/src/MercuryFile.h 2009-03-20 01:55:12 UTC (rev 185)
+++ Mercury2/src/MercuryFile.h 2009-03-20 03:37:22 UTC (rev 186)
@@ -44,7 +44,12 @@
virtual bool Check() = 0;
///Return true if end of file
virtual bool Eof() = 0;
- ///Return the last time the file was modified, if 0, this means unknown.
+ ///Return the last time the file was modified.
+ /** If the time is unknown, 0 is returned. This time has nothing to
+ do with actual changed time. It is system dependent and should
+ only be used to see if a file has been changed, unless the user
+ wishes to take advantage of something they know about the
+ underlying system. */
virtual unsigned long GetModTime() { return 0; }
const MString& GetName() const { return m_sPath; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-20 01:55:25
|
Revision: 185
http://hgengine.svn.sourceforge.net/hgengine/?rev=185&view=rev
Author: axlecrusher
Date: 2009-03-20 01:55:12 +0000 (Fri, 20 Mar 2009)
Log Message:
-----------
fallback enabled XML attributes
Modified Paths:
--------------
Mercury2/scenegraph.xml
Mercury2/src/XMLParser.cpp
Mercury2/src/XMLParser.h
Modified: Mercury2/scenegraph.xml
===================================================================
--- Mercury2/scenegraph.xml 2009-03-19 22:45:56 UTC (rev 184)
+++ Mercury2/scenegraph.xml 2009-03-20 01:55:12 UTC (rev 185)
@@ -2,18 +2,23 @@
<node type="transformnode" movz="0" roty="0">
<node type="viewport" fov="45" aspect="1.3333" near="0.01" far="100"/>
</node>
- <node type="transformnode" movz="-3">
+ <node type="transformnode" movz="-3" name="fallbackTest">
<node type="renderablenode">
<asset type="texture" file="test.bmp"/>
<asset type="quad"/>
</node>
+ <node type="transformnode" movx="-1" movy="-1" fallback="fallbackTest">
+ <node type="renderablenode">
+ <asset type="quad"/>
+ </node>
+ </node>
</node>
- <node type="transformnode" movz="-3" movx="-1" movy="-1">
+ <node type="transformnode" movx="-1" movy="-1" fallback="fallbackTest">
<node type="renderablenode">
<asset type="quad"/>
</node>
</node>
- <node type="transformnode" movz="-3" movx="1" movy="-1">
+ <node type="transformnode" movx="1" movy="-1" fallback="fallbackTest">
<node type="renderablenode">
<asset type="texture" file="test2.png"/>
<asset type="texture" file="test.bmp"/>
Modified: Mercury2/src/XMLParser.cpp
===================================================================
--- Mercury2/src/XMLParser.cpp 2009-03-19 22:45:56 UTC (rev 184)
+++ Mercury2/src/XMLParser.cpp 2009-03-20 01:55:12 UTC (rev 185)
@@ -23,35 +23,60 @@
XMLNode XMLNode::NextNode() const
{
- for (xmlNode* node = m_node->next; node; node=node->next)
- if (node->type == XML_ELEMENT_NODE)
- return XMLNode(node,m_doc);
+ if ( IsValid() )
+ {
+ for (xmlNode* node = m_node->next; node; node=node->next)
+ if (node->type == XML_ELEMENT_NODE)
+ return XMLNode(node,m_doc);
+
+//falling back here seem like a bad idea, high chance of infinite loops?
+// XMLNode fall = FindFallbackNode();
+// return fall.NextNode();
+ }
return XMLNode();
}
XMLNode XMLNode::PreviousNode() const
{
- for (xmlNode* node = m_node->prev; node; node=node->prev)
- if (node->type == XML_ELEMENT_NODE)
- return XMLNode(node,m_doc);
+ if ( IsValid() )
+ {
+ for (xmlNode* node = m_node->prev; node; node=node->prev)
+ if (node->type == XML_ELEMENT_NODE)
+ return XMLNode(node,m_doc);
+
+//falling back here seem like a bad idea, high chance of infinite loops?
+// XMLNode fall = FindFallbackNode();
+// return fall.PreviousNode();
+ }
return XMLNode();
}
XMLNode XMLNode::Child() const
{
- for (xmlNode* node = m_node->children; node; node=node->next)
- if (node->type == XML_ELEMENT_NODE) return XMLNode(node,m_doc);
+ if ( IsValid() )
+ {
+ for (xmlNode* node = m_node->children; node; node=node->next)
+ if (node->type == XML_ELEMENT_NODE) return XMLNode(node,m_doc);
+
+//falling back here seem like a bad idea, high chance of infinite loops?
+// XMLNode fall = FindFallbackNode();
+// return fall.Child();
+ }
return XMLNode();
}
MString XMLNode::Name() const
{
- return MString((const char*)m_node->name); //XXX fix utf8
+ if ( !IsValid() ) return "";
+ return MString((const char*)m_node->name);
}
MString XMLNode::Content() const
{
MString data;
+
+ if ( !IsValid() ) return data;
+
// xmlChar* d = xmlNodeListGetString(m_doc, m_node->xmlChildrenNode, 1);
xmlChar* d = xmlNodeGetContent(m_node);
@@ -67,6 +92,9 @@
MString XMLNode::Attribute(const MString& tag) const
{
MString data;
+
+ if ( !IsValid() ) return data;
+
xmlChar* d = xmlGetProp(m_node, (const xmlChar*)tag.c_str());
if (d)
@@ -76,43 +104,44 @@
}
else
{
- d = xmlGetProp(m_node, (const xmlChar*)"fallback");
- if (d)
- {
- //start searching at the root
- XMLNode root( xmlDocGetRootElement(m_doc) );
- //prevent infinite recursion on self
- if ( root.m_node != m_node )
- {
- XMLNode fall = root.FindFallbackNode( MString((const char*)d) );
- data = fall.Attribute(tag);
- }
- }
+ XMLNode fall = FindFallbackNode();
+ data = fall.Attribute(tag);
}
- if (d) xmlFree(d);
-
return data;
}
-/*
-MString XMLNode::FindFallbackAttribute(const MString& path)
+
+XMLNode XMLNode::FindFallbackNode() const
{
-
- xmlChar* d = xmlGetProp(m_node, (const xmlChar*)tag.c_str());
+ xmlChar* d = xmlGetProp(m_node, (const xmlChar*)"fallback");
+ XMLNode n;
+
if (d)
{
-
+ //start searching at the root
+ XMLNode root( xmlDocGetRootElement(m_doc) );
+ //prevent infinite recursion on self
+ if ( root.m_node != m_node )
+ {
+ n = root.RecursiveFindFallbackNode( MString((const char*)d) );
+ }
+ xmlFree(d);
}
- MString p = path;
+
+ return n;
}
-*/
-XMLNode XMLNode::FindFallbackNode(const MString& path) const
+
+XMLNode XMLNode::RecursiveFindFallbackNode(const MString& path) const
{
+ if ( !IsValid() ) return XMLNode();
+
if (path.length() > 0)
{
- MString name = path.substr(0, path.find("."));
+ int pos = path.find(".");
+ MString name = pos<=0?path:path.substr(0, pos);
+ MString rpath = pos<=0?"":path.substr(pos);
for (XMLNode n = this->Child(); n.IsValid(); n = n.NextNode())
- if (n.Attribute("name") == name) return n.FindFallbackNode(path);
+ if (n.Attribute("name") == name) return n.RecursiveFindFallbackNode(rpath);
return XMLNode();
}
return *this;
Modified: Mercury2/src/XMLParser.h
===================================================================
--- Mercury2/src/XMLParser.h 2009-03-19 22:45:56 UTC (rev 184)
+++ Mercury2/src/XMLParser.h 2009-03-20 01:55:12 UTC (rev 185)
@@ -30,11 +30,12 @@
MString Attribute(const MString & tag) const;
// MString FindFallbackAttribute();
- XMLNode FindFallbackNode(const MString& path) const;
inline bool IsValid() const { return m_node!=NULL; }
-
+ XMLNode FindFallbackNode() const;
private:
+ XMLNode RecursiveFindFallbackNode(const MString& path) const;
+
xmlNode* m_node;
xmlDoc* m_doc; //parent doc, don't free
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-19 22:46:03
|
Revision: 184
http://hgengine.svn.sourceforge.net/hgengine/?rev=184&view=rev
Author: axlecrusher
Date: 2009-03-19 22:45:56 +0000 (Thu, 19 Mar 2009)
Log Message:
-----------
updates
Modified Paths:
--------------
Mercury2/src/BoundingBox.cpp
Mercury2/src/BoundingBox.h
Mercury2/src/Mercury2.cpp
Mercury2/src/MercuryAsset.h
Mercury2/src/RenderableNode.cpp
Mercury2/src/RenderableNode.h
Mercury2/src/XMLParser.cpp
Mercury2/src/XMLParser.h
Modified: Mercury2/src/BoundingBox.cpp
===================================================================
--- Mercury2/src/BoundingBox.cpp 2009-03-16 00:42:19 UTC (rev 183)
+++ Mercury2/src/BoundingBox.cpp 2009-03-19 22:45:56 UTC (rev 184)
@@ -10,6 +10,18 @@
ComputeNormals();
};
+BoundingBox::BoundingBox(const BoundingBox& bb)
+ :m_center(bb.m_center), m_extend(bb.m_extend)
+{
+ for (uint8_t i = 0; i < 3; ++i)
+ m_normals[i] = bb.m_normals[i];
+}
+
+BoundingVolume* BoundingBox::SpawnClone() const
+{
+ return new BoundingBox(*this);
+}
+
void BoundingBox::LoadFromBinary(char* data)
{
memcpy(m_center, data, sizeof(float)*3);
Modified: Mercury2/src/BoundingBox.h
===================================================================
--- Mercury2/src/BoundingBox.h 2009-03-16 00:42:19 UTC (rev 183)
+++ Mercury2/src/BoundingBox.h 2009-03-19 22:45:56 UTC (rev 184)
@@ -14,6 +14,7 @@
virtual void LoadFromBinary(char* data) = 0;
virtual void Transform( const MercuryMatrix& m ) = 0;
virtual void Render() {};
+ virtual BoundingVolume* SpawnClone() const = 0;
};
class BoundingBox : public BoundingVolume
@@ -21,6 +22,8 @@
public:
BoundingBox() {};
BoundingBox(const MercuryVertex& center, const MercuryVertex& extend);
+ BoundingBox(const BoundingBox& bb);
+
virtual ~BoundingBox() {};
virtual void LoadFromBinary(char* data);
@@ -32,6 +35,7 @@
const MercuryVector& Normal(uint8_t i) const { return m_normals[i]; }
virtual void Render();
+ virtual BoundingVolume* SpawnClone() const;
private:
void ComputeNormals();
Modified: Mercury2/src/Mercury2.cpp
===================================================================
--- Mercury2/src/Mercury2.cpp 2009-03-16 00:42:19 UTC (rev 183)
+++ Mercury2/src/Mercury2.cpp 2009-03-19 22:45:56 UTC (rev 184)
@@ -84,9 +84,9 @@
SAFE_DELETE(root);
SAFE_DELETE(w);
- uint64_t totalWaited = UpdateWaited + RenderWaited;
- printf("Update wait %%%f\n", (UpdateWaited/double(totalWaited))*100.0f);
- printf("Render wait %%%f\n", (RenderWaited/double(totalWaited))*100.0f);
+// uint64_t totalWaited = UpdateWaited + RenderWaited;
+// printf("Update wait %%%f\n", (UpdateWaited/double(totalWaited))*100.0f);
+// printf("Render wait %%%f\n", (RenderWaited/double(totalWaited))*100.0f);
return 0;
}
Modified: Mercury2/src/MercuryAsset.h
===================================================================
--- Mercury2/src/MercuryAsset.h 2009-03-16 00:42:19 UTC (rev 183)
+++ Mercury2/src/MercuryAsset.h 2009-03-19 22:45:56 UTC (rev 184)
@@ -24,6 +24,8 @@
virtual void LoadFromXML(const XMLNode& node) {};
inline void IsInstanced(bool b) { m_isInstanced = b; }
+
+ inline const BoundingVolume* GetBoundingVolume() const { return m_boundingVolume; }
protected:
bool m_isInstanced;
BoundingVolume* m_boundingVolume;
Modified: Mercury2/src/RenderableNode.cpp
===================================================================
--- Mercury2/src/RenderableNode.cpp 2009-03-16 00:42:19 UTC (rev 183)
+++ Mercury2/src/RenderableNode.cpp 2009-03-19 22:45:56 UTC (rev 184)
@@ -7,12 +7,12 @@
using namespace std;
REGISTER_NODE_TYPE(RenderableNode);
-
+/*
uint64_t RenderWaited = 0;
uint64_t UpdateWaited = 0;
MercuryMatrix GLOBALMATRIX;
-
+*/
RenderableNode::RenderableNode()
:m_hidden(false)
{
@@ -43,13 +43,32 @@
UpdateWaited += waited;
}
*/
+
+void RenderableNode::Update(float dTime)
+{
+ MercuryMatrix m = FindGlobalMatrix();
+
+ std::list< MAutoPtr< MercuryAsset > >::iterator i;
+ for (i = m_assets.begin(); i != m_assets.end(); ++i )
+ {
+ const BoundingVolume* v = (*i)->GetBoundingVolume();
+ if (v)
+ {
+ BoundingVolume* nv = v->SpawnClone();
+ nv->Transform(m);
+ SAFE_DELETE(nv);
+ //do some stuff to figure out if this node is culled
+ }
+ }
+}
+
void RenderableNode::Render()
{
list< MercuryAsset* >::iterator i;
+ MercuryMatrix m = FindGlobalMatrix();
if (m_hidden || IsCulled()) return;
- MercuryMatrix m = GLOBALMATRIX = FindGlobalMatrix();
m.Transpose();
glLoadMatrixf( m.Ptr() );
@@ -113,7 +132,7 @@
void RenderableNode::RecursiveRender( MercuryNode* n )
{
- static unsigned long waitTime = 0;
+// static unsigned long waitTime = 0;
RenderableNode* rn;
if ( ( rn = Cast(n) ) )
{
Modified: Mercury2/src/RenderableNode.h
===================================================================
--- Mercury2/src/RenderableNode.h 2009-03-16 00:42:19 UTC (rev 183)
+++ Mercury2/src/RenderableNode.h 2009-03-19 22:45:56 UTC (rev 184)
@@ -10,9 +10,9 @@
#define MCHECKASSETS
-extern uint64_t RenderWaited;
-extern uint64_t UpdateWaited;
-extern MercuryMatrix GLOBALMATRIX;
+//extern uint64_t RenderWaited;
+//extern uint64_t UpdateWaited;
+//extern MercuryMatrix GLOBALMATRIX;
class RenderableNode : public MercuryNode
{
@@ -21,7 +21,7 @@
~RenderableNode();
virtual void Render();
-// virtual void Update(float dTime);
+ virtual void Update(float dTime);
///Returnes true if N is of type RenderableNode
// static bool IsMyType( MercuryNode* n );
Modified: Mercury2/src/XMLParser.cpp
===================================================================
--- Mercury2/src/XMLParser.cpp 2009-03-16 00:42:19 UTC (rev 183)
+++ Mercury2/src/XMLParser.cpp 2009-03-19 22:45:56 UTC (rev 184)
@@ -74,8 +74,49 @@
data = MString((const char*)d);
xmlFree(d);
}
+ else
+ {
+ d = xmlGetProp(m_node, (const xmlChar*)"fallback");
+ if (d)
+ {
+ //start searching at the root
+ XMLNode root( xmlDocGetRootElement(m_doc) );
+ //prevent infinite recursion on self
+ if ( root.m_node != m_node )
+ {
+ XMLNode fall = root.FindFallbackNode( MString((const char*)d) );
+ data = fall.Attribute(tag);
+ }
+ }
+ }
+
+ if (d) xmlFree(d);
+
return data;
}
+/*
+MString XMLNode::FindFallbackAttribute(const MString& path)
+{
+
+ xmlChar* d = xmlGetProp(m_node, (const xmlChar*)tag.c_str());
+ if (d)
+ {
+
+ }
+ MString p = path;
+}
+*/
+XMLNode XMLNode::FindFallbackNode(const MString& path) const
+{
+ if (path.length() > 0)
+ {
+ MString name = path.substr(0, path.find("."));
+ for (XMLNode n = this->Child(); n.IsValid(); n = n.NextNode())
+ if (n.Attribute("name") == name) return n.FindFallbackNode(path);
+ return XMLNode();
+ }
+ return *this;
+}
XMLDocument::XMLDocument()
:m_doc(NULL)
Modified: Mercury2/src/XMLParser.h
===================================================================
--- Mercury2/src/XMLParser.h 2009-03-16 00:42:19 UTC (rev 183)
+++ Mercury2/src/XMLParser.h 2009-03-19 22:45:56 UTC (rev 184)
@@ -28,6 +28,9 @@
MString Name() const;
MString Content() const;
MString Attribute(const MString & tag) const;
+
+// MString FindFallbackAttribute();
+ XMLNode FindFallbackNode(const MString& path) const;
inline bool IsValid() const { return m_node!=NULL; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-16 00:42:28
|
Revision: 183
http://hgengine.svn.sourceforge.net/hgengine/?rev=183&view=rev
Author: axlecrusher
Date: 2009-03-16 00:42:19 +0000 (Mon, 16 Mar 2009)
Log Message:
-----------
make nodes constant in render functions
Modified Paths:
--------------
Mercury2/src/HGMDLModel.cpp
Mercury2/src/HGMDLModel.h
Mercury2/src/MercuryAsset.h
Mercury2/src/MercuryVBO.cpp
Mercury2/src/MercuryVBO.h
Mercury2/src/Texture.cpp
Mercury2/src/Texture.h
Modified: Mercury2/src/HGMDLModel.cpp
===================================================================
--- Mercury2/src/HGMDLModel.cpp 2009-03-16 00:09:00 UTC (rev 182)
+++ Mercury2/src/HGMDLModel.cpp 2009-03-16 00:42:19 UTC (rev 183)
@@ -58,7 +58,7 @@
}
}
-void HGMDLModel::Render(MercuryNode* node)
+void HGMDLModel::Render(const MercuryNode* node)
{
for(uint16_t i = 0; i < m_meshes.size(); ++i)
m_meshes[i]->Render(node);
Modified: Mercury2/src/HGMDLModel.h
===================================================================
--- Mercury2/src/HGMDLModel.h 2009-03-16 00:09:00 UTC (rev 182)
+++ Mercury2/src/HGMDLModel.h 2009-03-16 00:42:19 UTC (rev 183)
@@ -18,7 +18,7 @@
void LoadModel(MercuryFile* hgmdl);
static HGMDLModel* Generate();
- virtual void Render(MercuryNode* node);
+ virtual void Render(const MercuryNode* node);
private:
void LoadHGMDL( const MString& path );
Modified: Mercury2/src/MercuryAsset.h
===================================================================
--- Mercury2/src/MercuryAsset.h 2009-03-16 00:09:00 UTC (rev 182)
+++ Mercury2/src/MercuryAsset.h 2009-03-16 00:42:19 UTC (rev 183)
@@ -16,9 +16,9 @@
virtual void Init(MercuryNode* node);
- virtual void PreRender(MercuryNode* node) {};
- virtual void Render(MercuryNode* node) = 0;
- virtual void PostRender(MercuryNode* node) {};
+ virtual void PreRender(const MercuryNode* node) {};
+ virtual void Render(const MercuryNode* node) = 0;
+ virtual void PostRender(const MercuryNode* node) {};
///Loads an asset from an XMLAsset representing itself
virtual void LoadFromXML(const XMLNode& node) {};
Modified: Mercury2/src/MercuryVBO.cpp
===================================================================
--- Mercury2/src/MercuryVBO.cpp 2009-03-16 00:09:00 UTC (rev 182)
+++ Mercury2/src/MercuryVBO.cpp 2009-03-16 00:42:19 UTC (rev 183)
@@ -21,7 +21,7 @@
m_bufferIDs[0] = m_bufferIDs[1] = 0;
}
-void MercuryVBO::Render(MercuryNode* node)
+void MercuryVBO::Render(const MercuryNode* node)
{
uint8_t numTextures = Texture::NumberActiveTextures();
uint16_t stride = sizeof(float)*8;
Modified: Mercury2/src/MercuryVBO.h
===================================================================
--- Mercury2/src/MercuryVBO.h 2009-03-16 00:09:00 UTC (rev 182)
+++ Mercury2/src/MercuryVBO.h 2009-03-16 00:42:19 UTC (rev 183)
@@ -13,7 +13,7 @@
MercuryVBO();
virtual ~MercuryVBO();
- virtual void Render(MercuryNode* node);
+ virtual void Render(const MercuryNode* node);
void AllocateVertexSpace(unsigned int count);
void AllocateIndexSpace(unsigned int count);
Modified: Mercury2/src/Texture.cpp
===================================================================
--- Mercury2/src/Texture.cpp 2009-03-16 00:09:00 UTC (rev 182)
+++ Mercury2/src/Texture.cpp 2009-03-16 00:42:19 UTC (rev 183)
@@ -82,12 +82,12 @@
};
-void Texture::Render(MercuryNode* node)
+void Texture::Render(const MercuryNode* node)
{
BindTexture();
}
-void Texture::PostRender(MercuryNode* node)
+void Texture::PostRender(const MercuryNode* node)
{
UnbindTexture();
}
Modified: Mercury2/src/Texture.h
===================================================================
--- Mercury2/src/Texture.h 2009-03-16 00:09:00 UTC (rev 182)
+++ Mercury2/src/Texture.h 2009-03-16 00:42:19 UTC (rev 183)
@@ -12,8 +12,8 @@
virtual void Init(MercuryNode* node);
- virtual void Render(MercuryNode* node);
- virtual void PostRender(MercuryNode* node);
+ virtual void Render(const MercuryNode* node);
+ virtual void PostRender(const MercuryNode* node);
virtual void LoadFromXML(const XMLNode& node);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-16 00:09:09
|
Revision: 182
http://hgengine.svn.sourceforge.net/hgengine/?rev=182&view=rev
Author: axlecrusher
Date: 2009-03-16 00:09:00 +0000 (Mon, 16 Mar 2009)
Log Message:
-----------
clean up bounding boxes and rendering
Modified Paths:
--------------
Mercury2/src/BoundingBox.cpp
Mercury2/src/BoundingBox.h
Mercury2/src/HGMDLMesh.cpp
Mercury2/src/MercuryAsset.cpp
Mercury2/src/MercuryAsset.h
Mercury2/src/MercuryVBO.cpp
Mercury2/src/MercuryVBO.h
Mercury2/src/RenderableNode.cpp
Mercury2/src/RenderableNode.h
Modified: Mercury2/src/BoundingBox.cpp
===================================================================
--- Mercury2/src/BoundingBox.cpp 2009-03-15 22:17:56 UTC (rev 181)
+++ Mercury2/src/BoundingBox.cpp 2009-03-16 00:09:00 UTC (rev 182)
@@ -41,22 +41,17 @@
bb.m_normals[1] = (m * m_normals[1]).Normalize();
bb.m_normals[2] = (m * m_normals[2]).Normalize();
*this = bb;
-// return bb;
}
-RenderableBoundingBox::RenderableBoundingBox(const BoundingBox* bb)
- :MercuryAsset(), m_bb(bb)
+void BoundingBox::Render()
{
-}
+// BoundingBox gbb = *this;
-void RenderableBoundingBox::Render(MercuryNode* node)
-{
- BoundingBox gbb = *m_bb;
- gbb.Transform( GetGlobalMatrix() );
- if ( FRUSTUM->Clip( gbb ) ) return;
+// gbb.Transform( ((RenderableNode*)node)->GetGlobalMatrix() );
+// if ( FRUSTUM->Clip( gbb ) ) return;
- const float* center = m_bb->GetCenter();
- const float* extend = m_bb->GetExtend();
+ const float* center = GetCenter();
+ const float* extend = GetExtend();
glPushAttrib( GL_CURRENT_BIT );
glBegin(GL_LINES);
Modified: Mercury2/src/BoundingBox.h
===================================================================
--- Mercury2/src/BoundingBox.h 2009-03-15 22:17:56 UTC (rev 181)
+++ Mercury2/src/BoundingBox.h 2009-03-16 00:09:00 UTC (rev 182)
@@ -1,7 +1,7 @@
#ifndef BOUNDINGBOX_H
#define BOUNDINGBOX_H
-#include <MercuryAsset.h>
+#include <MercuryNode.h>
#include <MercuryVertex.h>
#include <MercuryMatrix.h>
#include <stdint.h>
@@ -9,8 +9,11 @@
class BoundingVolume
{
public:
+ virtual ~BoundingVolume() {};
+
virtual void LoadFromBinary(char* data) = 0;
virtual void Transform( const MercuryMatrix& m ) = 0;
+ virtual void Render() {};
};
class BoundingBox : public BoundingVolume
@@ -18,6 +21,7 @@
public:
BoundingBox() {};
BoundingBox(const MercuryVertex& center, const MercuryVertex& extend);
+ virtual ~BoundingBox() {};
virtual void LoadFromBinary(char* data);
@@ -26,6 +30,8 @@
virtual void Transform( const MercuryMatrix& m );
const MercuryVector& Normal(uint8_t i) const { return m_normals[i]; }
+
+ virtual void Render();
private:
void ComputeNormals();
@@ -35,7 +41,7 @@
MercuryVector m_normals[3];
};
-
+/*
class RenderableBoundingBox : public MercuryAsset
{
public:
@@ -45,7 +51,7 @@
private:
const BoundingBox* m_bb;
};
-
+*/
#endif
/****************************************************************************
Modified: Mercury2/src/HGMDLMesh.cpp
===================================================================
--- Mercury2/src/HGMDLMesh.cpp 2009-03-15 22:17:56 UTC (rev 181)
+++ Mercury2/src/HGMDLMesh.cpp 2009-03-16 00:09:00 UTC (rev 182)
@@ -87,9 +87,9 @@
{
data = new char[length];
hgmdl->Read( data, length );
-
- m_boundingBox = new BoundingBox();
- m_boundingBox->LoadFromBinary( data );
+
+ m_boundingVolume = new BoundingBox();
+ m_boundingVolume->LoadFromBinary( data );
}
SAFE_DELETE_ARRAY(data);
Modified: Mercury2/src/MercuryAsset.cpp
===================================================================
--- Mercury2/src/MercuryAsset.cpp 2009-03-15 22:17:56 UTC (rev 181)
+++ Mercury2/src/MercuryAsset.cpp 2009-03-16 00:09:00 UTC (rev 182)
@@ -2,10 +2,14 @@
#include <RenderableNode.h>
MercuryAsset::MercuryAsset()
- :m_isInstanced(false)
+ :m_isInstanced(false), m_boundingVolume(NULL)
{
}
+MercuryAsset::~MercuryAsset()
+{
+ SAFE_DELETE(m_boundingVolume);
+}
void MercuryAsset::Init(MercuryNode* node)
{
@@ -68,11 +72,6 @@
}
-const MercuryMatrix& MercuryAsset::GetGlobalMatrix() const
-{
- return GLOBALMATRIX;
-}
-
std::map<MString, MercuryAsset*> AssetFactory::m_assetInstances;
/***************************************************************************
Modified: Mercury2/src/MercuryAsset.h
===================================================================
--- Mercury2/src/MercuryAsset.h 2009-03-15 22:17:56 UTC (rev 181)
+++ Mercury2/src/MercuryAsset.h 2009-03-16 00:09:00 UTC (rev 182)
@@ -6,12 +6,13 @@
#include <MessageHandler.h>
#include <map>
#include <MercuryMatrix.h>
+#include <BoundingBox.h>
class MercuryAsset : public RefBase, MessageHandler
{
public:
MercuryAsset();
- virtual ~MercuryAsset() {};
+ virtual ~MercuryAsset();
virtual void Init(MercuryNode* node);
@@ -23,9 +24,9 @@
virtual void LoadFromXML(const XMLNode& node) {};
inline void IsInstanced(bool b) { m_isInstanced = b; }
- const MercuryMatrix& GetGlobalMatrix() const;
protected:
bool m_isInstanced;
+ BoundingVolume* m_boundingVolume;
};
class AssetFactory
Modified: Mercury2/src/MercuryVBO.cpp
===================================================================
--- Mercury2/src/MercuryVBO.cpp 2009-03-15 22:17:56 UTC (rev 181)
+++ Mercury2/src/MercuryVBO.cpp 2009-03-16 00:09:00 UTC (rev 182)
@@ -10,7 +10,7 @@
#define BUFFER_OFFSET(i) ((char*)NULL + (i))
MercuryVBO::MercuryVBO()
- :MercuryAsset(), m_initiated(false), m_boundingBox(NULL)
+ :MercuryAsset(), m_initiated(false)
{
m_bufferIDs[0] = m_bufferIDs[1] = 0;
}
@@ -19,7 +19,6 @@
{
if (m_bufferIDs[0]) glDeleteBuffersARB(2, m_bufferIDs);
m_bufferIDs[0] = m_bufferIDs[1] = 0;
- SAFE_DELETE(m_boundingBox);
}
void MercuryVBO::Render(MercuryNode* node)
@@ -54,11 +53,7 @@
m_lastVBOrendered = this;
- if (m_boundingBox)
- {
- RenderableBoundingBox rbb(m_boundingBox);
- rbb.Render(node);
- }
+ if (m_boundingVolume) m_boundingVolume->Render();
}
void MercuryVBO::InitVBO()
Modified: Mercury2/src/MercuryVBO.h
===================================================================
--- Mercury2/src/MercuryVBO.h 2009-03-15 22:17:56 UTC (rev 181)
+++ Mercury2/src/MercuryVBO.h 2009-03-16 00:09:00 UTC (rev 182)
@@ -31,7 +31,6 @@
protected:
AlignedBuffer<float> m_vertexData;
AlignedBuffer<uint16_t> m_indexData;
- BoundingBox* m_boundingBox;
static MSemaphore m_vboBatches;
};
Modified: Mercury2/src/RenderableNode.cpp
===================================================================
--- Mercury2/src/RenderableNode.cpp 2009-03-15 22:17:56 UTC (rev 181)
+++ Mercury2/src/RenderableNode.cpp 2009-03-16 00:09:00 UTC (rev 182)
@@ -24,7 +24,8 @@
m_render.clear();
m_postrender.clear();
}
-
+/*
+//this function exists for threaded rendering
void RenderableNode::Update(float dTime)
{
static unsigned long waitTime = 0;
@@ -41,7 +42,7 @@
UpdateWaited += waited;
}
-
+*/
void RenderableNode::Render()
{
list< MercuryAsset* >::iterator i;
@@ -116,17 +117,15 @@
RenderableNode* rn;
if ( ( rn = Cast(n) ) )
{
+/*
MSemaphoreDecOnDestroy s( &(rn->m_semaphore) );
-
int unsigned long waited = rn->SpinlockWait(1, waitTime);
- if (waited > 0)
- waitTime = (waitTime<1000000)?waitTime+1000:waitTime;
- else
- waitTime = (waitTime!=0)?waitTime-1000:0;
-
+ if (waited > 0) waitTime = (waitTime<1000000)?waitTime+1000:waitTime;
+ else waitTime = (waitTime!=0)?waitTime-1000:0;
RenderWaited += waited;
-
+*/
// ++RenderWaited += rn->Spinlock(1);
+
rn->Render();
}
@@ -159,7 +158,7 @@
MercuryNode::LoadFromXML( node );
}
-
+/*
unsigned long RenderableNode::Spinlock( unsigned long value )
{
unsigned long waited = 0;
@@ -178,9 +177,9 @@
}
return waited;
}
+*/
-
/***************************************************************************
* Copyright (C) 2008 by Joshua Allen *
* *
Modified: Mercury2/src/RenderableNode.h
===================================================================
--- Mercury2/src/RenderableNode.h 2009-03-15 22:17:56 UTC (rev 181)
+++ Mercury2/src/RenderableNode.h 2009-03-16 00:09:00 UTC (rev 182)
@@ -21,7 +21,7 @@
~RenderableNode();
virtual void Render();
- virtual void Update(float dTime);
+// virtual void Update(float dTime);
///Returnes true if N is of type RenderableNode
// static bool IsMyType( MercuryNode* n );
@@ -44,8 +44,6 @@
bool m_hidden;
private:
bool IsInAssetList(MercuryAsset* asset) const;
- unsigned long Spinlock( unsigned long value );
- unsigned long SpinlockWait( unsigned long value, unsigned long usec );
std::list< MAutoPtr< MercuryAsset > > m_assets; ///serves as a holder for memory
@@ -55,8 +53,11 @@
std::list< MercuryAsset* > m_prerender;
std::list< MercuryAsset* > m_render;
std::list< MercuryAsset* > m_postrender;
-
- MSemaphore m_semaphore;
+
+//Below is stuff for threaded rendering
+// unsigned long Spinlock( unsigned long value );
+// unsigned long SpinlockWait( unsigned long value, unsigned long usec );
+// MSemaphore m_semaphore;
};
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-15 22:18:11
|
Revision: 181
http://hgengine.svn.sourceforge.net/hgengine/?rev=181&view=rev
Author: axlecrusher
Date: 2009-03-15 22:17:56 +0000 (Sun, 15 Mar 2009)
Log Message:
-----------
update to semaphore and count VBO draw commands
Modified Paths:
--------------
Mercury2/src/MSemaphore.cpp
Mercury2/src/MSemaphore.h
Mercury2/src/Mercury2.cpp
Mercury2/src/MercuryVBO.cpp
Mercury2/src/MercuryVBO.h
Mercury2/src/RenderableNode.cpp
Modified: Mercury2/src/MSemaphore.cpp
===================================================================
--- Mercury2/src/MSemaphore.cpp 2009-03-15 20:46:54 UTC (rev 180)
+++ Mercury2/src/MSemaphore.cpp 2009-03-15 22:17:56 UTC (rev 181)
@@ -5,11 +5,16 @@
{
}
-unsigned long MSemaphore::ReadValue()
+unsigned long MSemaphore::Read()
{
return __sync_or_and_fetch(&m_counter, 0);
}
+unsigned long MSemaphore::ReadAndClear()
+{
+ return __sync_fetch_and_and(&m_counter, 0);
+}
+
unsigned long MSemaphore::Decrement()
{
return __sync_sub_and_fetch(&m_counter, 1);
Modified: Mercury2/src/MSemaphore.h
===================================================================
--- Mercury2/src/MSemaphore.h 2009-03-15 20:46:54 UTC (rev 180)
+++ Mercury2/src/MSemaphore.h 2009-03-15 22:17:56 UTC (rev 181)
@@ -6,7 +6,8 @@
public:
MSemaphore();
- unsigned long ReadValue();
+ unsigned long Read();
+ unsigned long ReadAndClear();
unsigned long Decrement();
unsigned long Increment();
Modified: Mercury2/src/Mercury2.cpp
===================================================================
--- Mercury2/src/Mercury2.cpp 2009-03-15 20:46:54 UTC (rev 180)
+++ Mercury2/src/Mercury2.cpp 2009-03-15 22:17:56 UTC (rev 181)
@@ -17,7 +17,7 @@
MSemaphore UpdateLoopGo;
void* UpdateThread(void* node)
{
- while( UpdateLoopGo.ReadValue() < 1 )
+ while( UpdateLoopGo.Read() < 1 )
{
MercuryNode* n = (MercuryNode*)node;
n->RecursiveUpdate(0.01f);
@@ -69,7 +69,8 @@
fpsTimer.Touch(timer);
if (fpsTimer.Age() > 1)
{
- printf("FPS: %f\n", m_count/fpsTimer.Age());
+ float batches = MercuryVBO::ResetBatchCount()/(float)m_count;
+ printf("FPS: %f, VBO batches %f\n", m_count/fpsTimer.Age(), batches);
m_count = 0;
fpsTimer = timer;
}
Modified: Mercury2/src/MercuryVBO.cpp
===================================================================
--- Mercury2/src/MercuryVBO.cpp 2009-03-15 20:46:54 UTC (rev 180)
+++ Mercury2/src/MercuryVBO.cpp 2009-03-15 22:17:56 UTC (rev 181)
@@ -50,6 +50,7 @@
}
glDrawRangeElements(GL_TRIANGLES, 0, m_indexData.Length()-1, m_indexData.Length(), GL_UNSIGNED_SHORT, NULL);
+ m_vboBatches.Increment();
m_lastVBOrendered = this;
@@ -88,6 +89,8 @@
}
void* MercuryVBO::m_lastVBOrendered = NULL;
+MSemaphore MercuryVBO::m_vboBatches;
+
/****************************************************************************
* Copyright (C) 2008 by Joshua Allen *
* *
Modified: Mercury2/src/MercuryVBO.h
===================================================================
--- Mercury2/src/MercuryVBO.h 2009-03-15 20:46:54 UTC (rev 180)
+++ Mercury2/src/MercuryVBO.h 2009-03-15 22:17:56 UTC (rev 181)
@@ -5,6 +5,8 @@
#include <AlignedBuffer.h>
#include <BoundingBox.h>
+#include <MSemaphore.h>
+
class MercuryVBO : public MercuryAsset
{
public:
@@ -15,6 +17,9 @@
void AllocateVertexSpace(unsigned int count);
void AllocateIndexSpace(unsigned int count);
+
+ static uint32_t BatchCount() { return m_vboBatches.Read(); }
+ static uint32_t ResetBatchCount() { return m_vboBatches.ReadAndClear(); }
private:
virtual void InitVBO();
@@ -27,6 +32,8 @@
AlignedBuffer<float> m_vertexData;
AlignedBuffer<uint16_t> m_indexData;
BoundingBox* m_boundingBox;
+
+ static MSemaphore m_vboBatches;
};
#endif
Modified: Mercury2/src/RenderableNode.cpp
===================================================================
--- Mercury2/src/RenderableNode.cpp 2009-03-15 20:46:54 UTC (rev 180)
+++ Mercury2/src/RenderableNode.cpp 2009-03-15 22:17:56 UTC (rev 181)
@@ -163,14 +163,14 @@
unsigned long RenderableNode::Spinlock( unsigned long value )
{
unsigned long waited = 0;
- while (m_semaphore.ReadValue() != value) ++waited;
+ while (m_semaphore.Read() != value) ++waited;
return waited;
}
unsigned long RenderableNode::SpinlockWait( unsigned long value, unsigned long usec )
{
unsigned long waited = 0;
- while (m_semaphore.ReadValue() != value)
+ while (m_semaphore.Read() != value)
{
// waited=true;
++waited;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-15 20:47:06
|
Revision: 180
http://hgengine.svn.sourceforge.net/hgengine/?rev=180&view=rev
Author: axlecrusher
Date: 2009-03-15 20:46:54 +0000 (Sun, 15 Mar 2009)
Log Message:
-----------
replace crossproducts
Modified Paths:
--------------
Mercury2/src/MercuryVertex.cpp
Mercury2/src/MercuryVertex.h
Modified: Mercury2/src/MercuryVertex.cpp
===================================================================
--- Mercury2/src/MercuryVertex.cpp 2009-03-15 20:42:29 UTC (rev 179)
+++ Mercury2/src/MercuryVertex.cpp 2009-03-15 20:46:54 UTC (rev 180)
@@ -85,16 +85,6 @@
MercuryVertex MercuryVertex::CrossProduct(const MercuryVertex& p) const
{
- MercuryVertex ret;
- ret[0] = (*this)[1]*p[2] - (*this)[2]*p[1];
- ret[1] = (*this)[2]*p[0] - (*this)[0]*p[2];
- ret[2] = (*this)[0]*p[1] - (*this)[1]*p[0];
- return ret;
-}
-
-MercuryVertex MercuryVertex::CrossProductSSE(const MercuryVertex& p) const
-{
- //right now this is a hare slower than the C cross product above
MercuryVertex r;
MMCrossProduct( m_xyzw, p.m_xyzw, r.m_xyzw );
return r;
Modified: Mercury2/src/MercuryVertex.h
===================================================================
--- Mercury2/src/MercuryVertex.h 2009-03-15 20:42:29 UTC (rev 179)
+++ Mercury2/src/MercuryVertex.h 2009-03-15 20:46:54 UTC (rev 180)
@@ -69,7 +69,6 @@
///Obtain the cross product (*this) x p
MercuryVertex CrossProduct(const MercuryVertex& p) const;
- MercuryVertex CrossProductSSE(const MercuryVertex& p) const;
float DotProduct(const MercuryVertex& rhs) const;
MercuryVertex DotProduct3(const MercuryVertex& rhs1, const MercuryVertex& rhs2, const MercuryVertex& rhs3) const;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-15 20:42:38
|
Revision: 179
http://hgengine.svn.sourceforge.net/hgengine/?rev=179&view=rev
Author: axlecrusher
Date: 2009-03-15 20:42:29 +0000 (Sun, 15 Mar 2009)
Log Message:
-----------
add C version of cross product
Modified Paths:
--------------
Mercury2/src/MercuryMath.h
Modified: Mercury2/src/MercuryMath.h
===================================================================
--- Mercury2/src/MercuryMath.h 2009-03-15 20:38:32 UTC (rev 178)
+++ Mercury2/src/MercuryMath.h 2009-03-15 20:42:29 UTC (rev 179)
@@ -58,6 +58,7 @@
//void Float2FloatRow(const float* f, FloatRow& r);
//void FloatRow2Float(const FloatRow& fr, float* f);
+#ifdef USE_SSE
inline void MMCrossProduct( const FloatRow& r1, const FloatRow& r2, FloatRow& result)
{
__m128 a,b,c,d,r;//using more registers is faster
@@ -71,6 +72,14 @@
r -= _mm_mul_ps( c, d );
result = r;
}
+#else
+inline void MMCrossProduct( const FloatRow& r1, const FloatRow& r2, FloatRow& result)
+{
+ result[0] = r1[1]*r2[2] - r1[2]*r2[1];
+ result[1] = r1[2]*r2[0] - r1[0]*r2[2];
+ result[2] = r1[0]*r2[1] - r1[1]*r2[0];
+}
+#endif
const FloatRow gfrZero = { 0.f, 0.f, 0.f, 0.f };
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-15 20:38:42
|
Revision: 178
http://hgengine.svn.sourceforge.net/hgengine/?rev=178&view=rev
Author: axlecrusher
Date: 2009-03-15 20:38:32 +0000 (Sun, 15 Mar 2009)
Log Message:
-----------
lots of updates to math and vertex
Modified Paths:
--------------
Mercury2/src/BoundingBox.cpp
Mercury2/src/BoundingBox.h
Mercury2/src/MercuryMath.h
Mercury2/src/MercuryMatrix.cpp
Mercury2/src/MercuryPlane.cpp
Mercury2/src/MercuryVertex.cpp
Mercury2/src/MercuryVertex.h
Mercury2/src/Viewport.h
Modified: Mercury2/src/BoundingBox.cpp
===================================================================
--- Mercury2/src/BoundingBox.cpp 2009-03-08 04:19:56 UTC (rev 177)
+++ Mercury2/src/BoundingBox.cpp 2009-03-15 20:38:32 UTC (rev 178)
@@ -32,7 +32,7 @@
m_normals[2] = (m_center - t).Normalize();
}
-BoundingBox BoundingBox::Transform( const MercuryMatrix& m ) const
+void BoundingBox::Transform( const MercuryMatrix& m )
{
BoundingBox bb;
bb.m_extend = m_center;
@@ -40,7 +40,8 @@
bb.m_normals[0] = (m * m_normals[0]).Normalize();
bb.m_normals[1] = (m * m_normals[1]).Normalize();
bb.m_normals[2] = (m * m_normals[2]).Normalize();
- return bb;
+ *this = bb;
+// return bb;
}
RenderableBoundingBox::RenderableBoundingBox(const BoundingBox* bb)
@@ -50,7 +51,8 @@
void RenderableBoundingBox::Render(MercuryNode* node)
{
- BoundingBox gbb = m_bb->Transform( GetGlobalMatrix() );
+ BoundingBox gbb = *m_bb;
+ gbb.Transform( GetGlobalMatrix() );
if ( FRUSTUM->Clip( gbb ) ) return;
const float* center = m_bb->GetCenter();
Modified: Mercury2/src/BoundingBox.h
===================================================================
--- Mercury2/src/BoundingBox.h 2009-03-08 04:19:56 UTC (rev 177)
+++ Mercury2/src/BoundingBox.h 2009-03-15 20:38:32 UTC (rev 178)
@@ -6,18 +6,25 @@
#include <MercuryMatrix.h>
#include <stdint.h>
-class BoundingBox
+class BoundingVolume
{
public:
+ virtual void LoadFromBinary(char* data) = 0;
+ virtual void Transform( const MercuryMatrix& m ) = 0;
+};
+
+class BoundingBox : public BoundingVolume
+{
+ public:
BoundingBox() {};
BoundingBox(const MercuryVertex& center, const MercuryVertex& extend);
- void LoadFromBinary(char* data);
+ virtual void LoadFromBinary(char* data);
inline const MercuryVertex& GetCenter() const { return m_center; }
inline const MercuryVertex& GetExtend() const { return m_extend; }
- BoundingBox Transform( const MercuryMatrix& m ) const;
+ virtual void Transform( const MercuryMatrix& m );
const MercuryVector& Normal(uint8_t i) const { return m_normals[i]; }
private:
Modified: Mercury2/src/MercuryMath.h
===================================================================
--- Mercury2/src/MercuryMath.h 2009-03-08 04:19:56 UTC (rev 177)
+++ Mercury2/src/MercuryMath.h 2009-03-15 20:38:32 UTC (rev 178)
@@ -55,9 +55,23 @@
void VectorMultiply4f(const FloatRow* matrix, const FloatRow& p, FloatRow& out );
void TransposeMatrix( FloatRow* m );
-void Float2FloatRow(const float* f, FloatRow& r);
-void FloatRow2Float(const FloatRow& fr, float* f);
+//void Float2FloatRow(const float* f, FloatRow& r);
+//void FloatRow2Float(const FloatRow& fr, float* f);
+inline void MMCrossProduct( const FloatRow& r1, const FloatRow& r2, FloatRow& result)
+{
+ __m128 a,b,c,d,r;//using more registers is faster
+
+ a = _mm_shuffle_ps(r1, r1, 0xc9);
+ b = _mm_shuffle_ps(r2, r2, 0xd2);
+ r = _mm_mul_ps( a, b );
+
+ c = _mm_shuffle_ps(r2, r2, 0xc9);
+ d = _mm_shuffle_ps(r1, r1, 0xd2);
+ r -= _mm_mul_ps( c, d );
+ result = r;
+}
+
const FloatRow gfrZero = { 0.f, 0.f, 0.f, 0.f };
#endif
Modified: Mercury2/src/MercuryMatrix.cpp
===================================================================
--- Mercury2/src/MercuryMatrix.cpp 2009-03-08 04:19:56 UTC (rev 177)
+++ Mercury2/src/MercuryMatrix.cpp 2009-03-15 20:38:32 UTC (rev 178)
@@ -197,15 +197,9 @@
MercuryVector MercuryMatrix::operator*(const MercuryVector& v) const
{
- float tmp[4];
- FloatRow r, tvo;
-
- v.ConvertToVector4( tmp, 1 );
- Float2FloatRow( tmp, r );
- VectorMultiply4f( m_matrix, r, tvo);
- FloatRow2Float( tvo, tmp );
-// printf("%f %f %f %f\n", tmp[0], tmp[1], tmp[2], tmp[3]);
- return MercuryVertex(tmp);
+ MercuryVector r;
+ VectorMultiply4f( m_matrix, v.ToFloatRow(), r.ToFloatRow() );
+ return r;
}
Modified: Mercury2/src/MercuryPlane.cpp
===================================================================
--- Mercury2/src/MercuryPlane.cpp 2009-03-08 04:19:56 UTC (rev 177)
+++ Mercury2/src/MercuryPlane.cpp 2009-03-15 20:38:32 UTC (rev 178)
@@ -2,10 +2,14 @@
#include <stdio.h>
#include <MercuryMath.h>
+#define SIGNED_DIST(x) m_normal.DotProduct(x)
+
+// origional algorithim was -x<0
+#define BEHIND_PLANE(x) x>=0
+
bool MercuryPlane::IsBehindPlane(const MercuryVertex& point) const
{
- // origional algorithim was -dotproduct < 0
- return m_normal.DotProduct( point+m_center ) >= 0;
+ return BEHIND_PLANE( SIGNED_DIST( point+m_center ) );
}
bool MercuryPlane::IsBehindPlane(const BoundingBox& bb) const
@@ -14,16 +18,17 @@
const MercuryVertex& extends = bb.GetExtend();
const MercuryVertex &A1(bb.Normal(0)), &A2(bb.Normal(1)), &A3(bb.Normal(2));
-
- float x = ABS( extends.GetX() * m_normal.DotProduct( A1 ) );
- x += ABS( extends.GetY() * m_normal.DotProduct( A2 ) );
- x += ABS( extends.GetZ() * m_normal.DotProduct( A3 ) );
- float d = m_normal.DotProduct( center+m_center );
+ MercuryVertex dp = m_normal.DotProduct3(A1, A2, A3);
+ float x = ABS( extends.GetX() * dp[0] );
+ x += ABS( extends.GetY() * dp[1] );
+ x += ABS( extends.GetZ() * dp[2] );
+
+ float d = SIGNED_DIST( center+m_center );
if ( ABS(d) <= x ) //intersection
return false;
-
- return IsBehindPlane( center ); //if we don't intersect, just see what side we are on
+
+ return BEHIND_PLANE(d); //if we don't intersect, just see what side we are on
}
Modified: Mercury2/src/MercuryVertex.cpp
===================================================================
--- Mercury2/src/MercuryVertex.cpp 2009-03-08 04:19:56 UTC (rev 177)
+++ Mercury2/src/MercuryVertex.cpp 2009-03-15 20:38:32 UTC (rev 178)
@@ -4,33 +4,33 @@
MercuryVertex::MercuryVertex()
{
- m_xyz[0] = m_xyz[1] = m_xyz[2] = 0;
+ (*this)[0] = (*this)[1] = (*this)[2] = 0;
}
MercuryVertex::MercuryVertex( float ix, float iy, float iz )
{
- m_xyz[0] = ix;
- m_xyz[1] = iy;
- m_xyz[2] = iz;
+ (*this)[0] = ix;
+ (*this)[1] = iy;
+ (*this)[2] = iz;
}
MercuryVertex::MercuryVertex( const float * in )
{
for (unsigned int i = 0; i < 3; ++i)
- m_xyz[i] = in[i];
+ (*this)[i] = in[i];
}
MercuryVertex::MercuryVertex( const MercuryVertex& v)
{
for (unsigned int i = 0; i < 3; ++i)
- m_xyz[i] = v.m_xyz[i];
+ (*this)[i] = v[i];
}
void MercuryVertex::NormalizeSelf()
{
float imag = 1.0f/Length();
for (unsigned int i = 0; i < 3; ++i)
- m_xyz[i] *= imag;
+ (*this)[i] *= imag;
}
MercuryVertex MercuryVertex::Normalize() const
@@ -42,64 +42,81 @@
float MercuryVertex::Length() const
{
- float length = m_xyz[0]*m_xyz[0];
- length += m_xyz[1]*m_xyz[1];
- length += m_xyz[2]*m_xyz[2];
+ float length = (*this)[0]*(*this)[0];
+ length += (*this)[1]*(*this)[1];
+ length += (*this)[2]*(*this)[2];
return SQRT(length);
}
float MercuryVertex::GetBiggestElement() const
{
- float tmp = m_xyz[0];
- tmp = max<float>(tmp, m_xyz[1]);
- return max<float>(tmp, m_xyz[2]);
+ float tmp = (*this)[0];
+ tmp = max<float>(tmp, (*this)[1]);
+ return max<float>(tmp, (*this)[2]);
}
const MercuryVertex& MercuryVertex::operator *= (const MercuryVertex& p)
{
for (unsigned int i = 0; i < 3; ++i)
- m_xyz[i] *= p.m_xyz[i];
+ (*this)[i] *= p[i];
return *this;
}
const MercuryVertex& MercuryVertex::operator /= (const MercuryVertex& p)
{
for (unsigned int i = 0; i < 3; ++i)
- m_xyz[i] /= p.m_xyz[i];
+ (*this)[i] /= p[i];
return *this;
}
bool MercuryVertex::operator==(const MercuryVertex& p) const
{
for (unsigned int i = 0; i < 3; ++i)
- if (m_xyz[i] != p.m_xyz[i]) return false;
+ if ((*this)[i] != p[i]) return false;
return true;
}
bool MercuryVertex::operator==(const float f) const
{
for (unsigned int i = 0; i < 3; ++i)
- if (m_xyz[i] != f) return false;
+ if ((*this)[i] != f) return false;
return true;
}
MercuryVertex MercuryVertex::CrossProduct(const MercuryVertex& p) const
{
MercuryVertex ret;
- ret.m_xyz[0] = m_xyz[1]*p.m_xyz[2] - m_xyz[2]*p.m_xyz[1];
- ret.m_xyz[1] = m_xyz[2]*p.m_xyz[0] - m_xyz[0]*p.m_xyz[2];
- ret.m_xyz[2] = m_xyz[0]*p.m_xyz[1] - m_xyz[1]*p.m_xyz[0];
+ ret[0] = (*this)[1]*p[2] - (*this)[2]*p[1];
+ ret[1] = (*this)[2]*p[0] - (*this)[0]*p[2];
+ ret[2] = (*this)[0]*p[1] - (*this)[1]*p[0];
return ret;
}
+MercuryVertex MercuryVertex::CrossProductSSE(const MercuryVertex& p) const
+{
+ //right now this is a hare slower than the C cross product above
+ MercuryVertex r;
+ MMCrossProduct( m_xyzw, p.m_xyzw, r.m_xyzw );
+ return r;
+}
+
float MercuryVertex::DotProduct(const MercuryVertex& rhs) const
{
- return (m_xyz[0]*rhs.m_xyz[0]+m_xyz[1]*rhs.m_xyz[1]+m_xyz[2]*rhs.m_xyz[2]);
+ return ((*this)[0]*rhs[0]+(*this)[1]*rhs[1]+(*this)[2]*rhs[2]);
}
+MercuryVertex MercuryVertex::DotProduct3(const MercuryVertex& rhs1, const MercuryVertex& rhs2, const MercuryVertex& rhs3) const
+{
+ MercuryVertex dp;
+ dp[0] = DotProduct(rhs1);
+ dp[1] = DotProduct(rhs2);
+ dp[2] = DotProduct(rhs3);
+ return dp;
+}
+
void MercuryVertex::Print() const
{
- printf("%f %f %f\n", m_xyz[0], m_xyz[1], m_xyz[2]);
+ printf("%f %f %f\n", (*this)[0], (*this)[1], (*this)[2]);
}
Modified: Mercury2/src/MercuryVertex.h
===================================================================
--- Mercury2/src/MercuryVertex.h 2009-03-08 04:19:56 UTC (rev 177)
+++ Mercury2/src/MercuryVertex.h 2009-03-15 20:38:32 UTC (rev 178)
@@ -1,6 +1,10 @@
#ifndef MERCURYVECTOR_H
#define MERCURYVECTOR_H
+#include <MercuryMath.h>
+
+# define __inline__ __inline__ __attribute__((always_inline))
+
class MercuryVertex
{
public:
@@ -10,18 +14,21 @@
MercuryVertex( const MercuryVertex& v);
///Direct conversion to float*
- operator float* () { return m_xyz; }
+ __inline__ operator float* () { return (float*)&m_xyzw; }
///Direct conversion to const float*
- operator const float* () const { return m_xyz; }
+ __inline__ operator const float* () const { return (float*)&m_xyzw; }
- inline const float GetX() const { return m_xyz[0]; }
- inline const float GetY() const { return m_xyz[1]; }
- inline const float GetZ() const { return m_xyz[2]; }
- inline void SetX(const float ix) { m_xyz[0] = ix; }
- inline void SetY(const float iy) { m_xyz[1] = iy; }
- inline void SetZ(const float iz) { m_xyz[2] = iz; }
+ inline FloatRow& ToFloatRow() { return m_xyzw; }
+ inline const FloatRow& ToFloatRow() const { return m_xyzw; }
+
+ inline const float GetX() const { return (*this)[0]; }
+ inline const float GetY() const { return (*this)[1]; }
+ inline const float GetZ() const { return (*this)[2]; }
+ inline void SetX(const float ix) { (*this)[0] = ix; }
+ inline void SetY(const float iy) { (*this)[1] = iy; }
+ inline void SetZ(const float iz) { (*this)[2] = iz; }
- inline void Zero() { m_xyz[0] = 0; m_xyz[1] = 0; m_xyz[2] = 0; }
+ inline void Zero() { (*this)[0] = 0; (*this)[1] = 0; (*this)[2] = 0; }
///Normalize (make |point| = 1)
void NormalizeSelf();
@@ -33,26 +40,26 @@
float GetBiggestElement() const;
///Write out to be = to this point
- inline void ConvertToVector3( float* out ) const { out[0] = m_xyz[0]; out[1] = m_xyz[1]; out[2] = m_xyz[2]; }
+ inline void ConvertToVector3( float* out ) const { out[0] = (*this)[0]; out[1] = (*this)[1]; out[2] = (*this)[2]; }
///Write out to be = to this point, however the 4th element will be 0
- inline void ConvertToVector4( float* out, float w = 0 ) const { out[0] = m_xyz[0]; out[1] = m_xyz[1]; out[2] = m_xyz[2]; out[3] = w; }
+ inline void ConvertToVector4( float* out, float w = 0 ) const { out[0] = (*this)[0]; out[1] = (*this)[1]; out[2] = (*this)[2]; out[3] = w; }
///Write out to be = - to this point, however the 4th element will be 0
- inline void ConvertToIVector4( float* out, float w = 0 ) const { out[0] = -m_xyz[0]; out[1] = -m_xyz[1]; out[2] = -m_xyz[2]; out[3] = w; }
+ inline void ConvertToIVector4( float* out, float w = 0 ) const { out[0] = -(*this)[0]; out[1] = -(*this)[1]; out[2] = -(*this)[2]; out[3] = w; }
const MercuryVertex& operator *= (const MercuryVertex& p);
const MercuryVertex& operator /= (const MercuryVertex& p);
inline MercuryVertex operator * (const MercuryVertex& p) const { MercuryVertex r(*this); r*=p; return r; }
inline MercuryVertex operator / (const MercuryVertex& p) const { MercuryVertex r(*this); r/=p; return r; }
- inline MercuryVertex& operator += ( const MercuryVertex& other ) { m_xyz[0]+=other.m_xyz[0]; m_xyz[1]+=other.m_xyz[1]; m_xyz[2]+=other.m_xyz[2]; return *this; }
- inline MercuryVertex& operator -= ( const MercuryVertex& other ) { m_xyz[0]-=other.m_xyz[0]; m_xyz[1]-=other.m_xyz[1]; m_xyz[2]-=other.m_xyz[2]; return *this; }
- inline MercuryVertex& operator *= ( float f ) { m_xyz[0]*=f; m_xyz[1]*=f; m_xyz[2]*=f; return *this; }
- inline MercuryVertex& operator /= ( float f ) { m_xyz[0]/=f; m_xyz[1]/=f; m_xyz[2]/=f; return *this; }
+ inline MercuryVertex& operator += ( const MercuryVertex& other ) { (*this)[0]+=other[0]; (*this)[1]+=other[1]; (*this)[2]+=other[2]; return *this; }
+ inline MercuryVertex& operator -= ( const MercuryVertex& other ) { (*this)[0]-=other[0]; (*this)[1]-=other[1]; (*this)[2]-=other[2]; return *this; }
+ inline MercuryVertex& operator *= ( float f ) { (*this)[0]*=f; (*this)[1]*=f; (*this)[2]*=f; return *this; }
+ inline MercuryVertex& operator /= ( float f ) { (*this)[0]/=f; (*this)[1]/=f; (*this)[2]/=f; return *this; }
- inline MercuryVertex operator + ( const MercuryVertex& other ) const { return MercuryVertex( m_xyz[0]+other.m_xyz[0], m_xyz[1]+other.m_xyz[1], m_xyz[2]+other.m_xyz[2] ); }
- inline MercuryVertex operator - ( const MercuryVertex& other ) const { return MercuryVertex( m_xyz[0]-other.m_xyz[0], m_xyz[1]-other.m_xyz[1], m_xyz[2]-other.m_xyz[2] ); }
- inline MercuryVertex operator * ( float f ) const { return MercuryVertex( m_xyz[0]*f, m_xyz[1]*f, m_xyz[2]*f ); }
- inline MercuryVertex operator / ( float f ) const { return MercuryVertex( m_xyz[0]/f, m_xyz[1]/f, m_xyz[2]/f ); }
+ inline MercuryVertex operator + ( const MercuryVertex& other ) const { return MercuryVertex( (*this)[0]+other[0], (*this)[1]+other[1], (*this)[2]+other[2] ); }
+ inline MercuryVertex operator - ( const MercuryVertex& other ) const { return MercuryVertex( (*this)[0]-other[0], (*this)[1]-other[1], (*this)[2]-other[2] ); }
+ inline MercuryVertex operator * ( float f ) const { return MercuryVertex( (*this)[0]*f, (*this)[1]*f, (*this)[2]*f ); }
+ inline MercuryVertex operator / ( float f ) const { return MercuryVertex( (*this)[0]/f, (*this)[1]/f, (*this)[2]/f ); }
bool operator==(const MercuryVertex& p) const;
inline bool operator!=(const MercuryVertex& p) const { return !(*this == p); }
@@ -62,11 +69,15 @@
///Obtain the cross product (*this) x p
MercuryVertex CrossProduct(const MercuryVertex& p) const;
+ MercuryVertex CrossProductSSE(const MercuryVertex& p) const;
float DotProduct(const MercuryVertex& rhs) const;
+ MercuryVertex DotProduct3(const MercuryVertex& rhs1, const MercuryVertex& rhs2, const MercuryVertex& rhs3) const;
+
void Print() const;
- float m_xyz[3];
+// float (*this)[3];
+ FloatRow m_xyzw;
};
typedef MercuryVertex MercuryVector;
Modified: Mercury2/src/Viewport.h
===================================================================
--- Mercury2/src/Viewport.h 2009-03-08 04:19:56 UTC (rev 177)
+++ Mercury2/src/Viewport.h 2009-03-15 20:38:32 UTC (rev 178)
@@ -9,11 +9,11 @@
enum PlanePos
{
PTOP = 0,
- PBOTTOM,
- PLEFT,
- PRIGHT,
- PNEAR,
- PFAR
+ PBOTTOM,
+ PLEFT,
+ PRIGHT,
+ PNEAR,
+ PFAR
};
class Frustum
@@ -23,13 +23,10 @@
void SetPerspective( float fov, float aspect, float znear, float zfar );
const MercuryMatrix& GetMatrix() const { return m_frustum; }
void ComputeFrustum(float left, float right, float bottom, float top, float zNear, float zFar);
-
void LookAt(const MercuryVertex& eye, const MercuryVector& look, const MercuryVector& up);
-
bool Clip(const BoundingBox& bb) const;
-
- MercuryPlane m_planes[6];
private:
+ MercuryPlane m_planes[6];
MercuryMatrix m_frustum;
float m_aspect, m_fov, m_zNear, m_zFar;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-08 04:19:59
|
Revision: 177
http://hgengine.svn.sourceforge.net/hgengine/?rev=177&view=rev
Author: axlecrusher
Date: 2009-03-08 04:19:56 +0000 (Sun, 08 Mar 2009)
Log Message:
-----------
Update to fix compile on ubuntu
Modified Paths:
--------------
Mercury2/mercury2.kdevelop
Mercury2/scenegraph.xml
Mercury2/src/AlignedBuffer.h
Mercury2/src/BMPLoader.cpp
Mercury2/src/BoundingBox.cpp
Mercury2/src/BoundingBox.h
Mercury2/src/MercuryFileDriverDirect.cpp
Mercury2/src/MercuryFileDriverPacked.cpp
Mercury2/src/MercuryFileDriverZipped.cpp
Mercury2/src/MercuryMessageManager.h
Mercury2/src/RenderableNode.cpp
Mercury2/src/RenderableNode.h
Modified: Mercury2/mercury2.kdevelop
===================================================================
--- Mercury2/mercury2.kdevelop 2009-03-04 00:46:51 UTC (rev 176)
+++ Mercury2/mercury2.kdevelop 2009-03-08 04:19:56 UTC (rev 177)
@@ -2,7 +2,7 @@
<kdevelop>
<general>
<author>Joshua Allen</author>
- <email></email>
+ <email/>
<version>2.0</version>
<projectmanagement>KDevAutoProject</projectmanagement>
<primarylanguage>C++</primarylanguage>
@@ -14,8 +14,8 @@
<projectname>Mercury2</projectname>
<projectdirectory>.</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
- <description></description>
- <defaultencoding></defaultencoding>
+ <description/>
+ <defaultencoding/>
<versioncontrol/>
</general>
<kdevautoproject>
@@ -24,10 +24,10 @@
<useconfiguration>debug</useconfiguration>
</general>
<run>
- <mainprogram>/home/josh/Mercury2/debug/src/mercury2</mainprogram>
+ <mainprogram/>
<terminal>false</terminal>
- <programargs></programargs>
- <globaldebugarguments></globaldebugarguments>
+ <programargs/>
+ <globaldebugarguments/>
<globalcwd>/home/josh/Mercury2</globalcwd>
<useglobalprogram>true</useglobalprogram>
<autocompile>false</autocompile>
@@ -59,16 +59,16 @@
<ccompiler>kdevgccoptions</ccompiler>
<cxxcompiler>kdevgppoptions</cxxcompiler>
<f77compiler>kdevg77options</f77compiler>
- <cxxflags>-O0 -g -Wall</cxxflags>
+ <cxxflags>-O2 -g -Wall</cxxflags>
<envvars/>
- <topsourcedir></topsourcedir>
- <cppflags>-Isrc/ -I/usr/include/libxml2/ -DHGENGINE -DRUN_FROM_START_FOLDER</cppflags>
+ <topsourcedir/>
+ <cppflags>-Isrc/ -I/usr/include/libxml2/ -DHGENGINE -DRUN_FROM_START_FOLDER -DUSE_SSE</cppflags>
<ldflags>-lpthread -lX11 -lGL -lxml2 -lpng</ldflags>
- <ccompilerbinary></ccompilerbinary>
- <cxxcompilerbinary></cxxcompilerbinary>
- <f77compilerbinary></f77compilerbinary>
+ <ccompilerbinary/>
+ <cxxcompilerbinary/>
+ <f77compilerbinary/>
<cflags>-O0 -g -Wall</cflags>
- <f77flags></f77flags>
+ <f77flags/>
</debug>
<default>
<envvars/>
@@ -193,8 +193,8 @@
<includestyle>3</includestyle>
<root>/usr/qt/3</root>
<designerintegration>EmbeddedKDevDesigner</designerintegration>
- <qmake>/usr/qt/3/bin/qmake</qmake>
- <designer>/usr/qt/3/bin/designer</designer>
+ <qmake></qmake>
+ <designer></designer>
<designerpluginpaths/>
</qt>
<references/>
@@ -222,7 +222,7 @@
<includePaths>.;</includePaths>
</codecompletion>
<creategettersetter>
- <prefixGet></prefixGet>
+ <prefixGet/>
<prefixSet>set</prefixSet>
<prefixVariable>m_,_</prefixVariable>
<parameterName>theValue</parameterName>
@@ -243,11 +243,11 @@
</cppsupportpart>
<kdevdebugger>
<general>
- <gdbpath></gdbpath>
+ <gdbpath/>
<dbgshell>libtool</dbgshell>
- <configGdbScript></configGdbScript>
- <runShellScript></runShellScript>
- <runGdbScript></runGdbScript>
+ <configGdbScript/>
+ <runShellScript/>
+ <runGdbScript/>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>false</floatingtoolbar>
Modified: Mercury2/scenegraph.xml
===================================================================
--- Mercury2/scenegraph.xml 2009-03-04 00:46:51 UTC (rev 176)
+++ Mercury2/scenegraph.xml 2009-03-08 04:19:56 UTC (rev 177)
@@ -22,8 +22,8 @@
</node>
<node type="rotatornode" movy="0" movz="-2" scalex="0.25" scaley="0.25" scalez="0.25" >
<node type="renderablenode">
- <asset type="texture" file="gunther.png"/>
- <asset type="hgmdlmodel" file="gunther.hgmdl"/>
+ <asset type="texture" file="test.bmp"/>
+ <asset type="hgmdlmodel" file="beerhall.hgmdl"/>
</node>
</node>
</SceneGraph>
Modified: Mercury2/src/AlignedBuffer.h
===================================================================
--- Mercury2/src/AlignedBuffer.h 2009-03-04 00:46:51 UTC (rev 176)
+++ Mercury2/src/AlignedBuffer.h 2009-03-08 04:19:56 UTC (rev 177)
@@ -1,6 +1,8 @@
#ifndef ALIGNEDBUFFER_H
#define ALIGNEDBUFFER_H
+#include <stdint.h>
+
template <typename T>
class AlignedBuffer
{
Modified: Mercury2/src/BMPLoader.cpp
===================================================================
--- Mercury2/src/BMPLoader.cpp 2009-03-04 00:46:51 UTC (rev 176)
+++ Mercury2/src/BMPLoader.cpp 2009-03-08 04:19:56 UTC (rev 177)
@@ -1,6 +1,7 @@
#include <RawImageData.h>
#include <MercuryUtil.h>
#include <ImageLoader.h>
+#include <string.h>
using namespace std;
Modified: Mercury2/src/BoundingBox.cpp
===================================================================
--- Mercury2/src/BoundingBox.cpp 2009-03-04 00:46:51 UTC (rev 176)
+++ Mercury2/src/BoundingBox.cpp 2009-03-08 04:19:56 UTC (rev 177)
@@ -1,7 +1,7 @@
#include <GL/gl.h>
#include <GL/glext.h>
#include <BoundingBox.h>
-
+#include <string.h>
#include <Viewport.h>
BoundingBox::BoundingBox(const MercuryVertex& center, const MercuryVertex& extend)
@@ -50,8 +50,6 @@
void RenderableBoundingBox::Render(MercuryNode* node)
{
- const BoundingBox& bb = *m_bb;
-
BoundingBox gbb = m_bb->Transform( GetGlobalMatrix() );
if ( FRUSTUM->Clip( gbb ) ) return;
Modified: Mercury2/src/BoundingBox.h
===================================================================
--- Mercury2/src/BoundingBox.h 2009-03-04 00:46:51 UTC (rev 176)
+++ Mercury2/src/BoundingBox.h 2009-03-08 04:19:56 UTC (rev 177)
@@ -4,6 +4,7 @@
#include <MercuryAsset.h>
#include <MercuryVertex.h>
#include <MercuryMatrix.h>
+#include <stdint.h>
class BoundingBox
{
Modified: Mercury2/src/MercuryFileDriverDirect.cpp
===================================================================
--- Mercury2/src/MercuryFileDriverDirect.cpp 2009-03-04 00:46:51 UTC (rev 176)
+++ Mercury2/src/MercuryFileDriverDirect.cpp 2009-03-08 04:19:56 UTC (rev 177)
@@ -14,6 +14,8 @@
#define FSHEADER ""
#endif
+#include <string.h>
+
//Core base only.
MercuryFile::MercuryFile()
{
Modified: Mercury2/src/MercuryFileDriverPacked.cpp
===================================================================
--- Mercury2/src/MercuryFileDriverPacked.cpp 2009-03-04 00:46:51 UTC (rev 176)
+++ Mercury2/src/MercuryFileDriverPacked.cpp 2009-03-08 04:19:56 UTC (rev 177)
@@ -1,4 +1,5 @@
#include <MercuryFileDriverPacked.h>
+#include <string.h>
const MString PackagePrefix = "Packages/";
Modified: Mercury2/src/MercuryFileDriverZipped.cpp
===================================================================
--- Mercury2/src/MercuryFileDriverZipped.cpp 2009-03-04 00:46:51 UTC (rev 176)
+++ Mercury2/src/MercuryFileDriverZipped.cpp 2009-03-08 04:19:56 UTC (rev 177)
@@ -3,6 +3,7 @@
//For the store compression on zips
#include <zlib.h>
+#include <string.h>
const MString PackagePrefix = "Packages/";
Modified: Mercury2/src/MercuryMessageManager.h
===================================================================
--- Mercury2/src/MercuryMessageManager.h 2009-03-04 00:46:51 UTC (rev 176)
+++ Mercury2/src/MercuryMessageManager.h 2009-03-08 04:19:56 UTC (rev 177)
@@ -7,6 +7,7 @@
#include <PriorityQueue.h>
#include <MercuryString.h>
#include <MercuryUtil.h>
+#include <stdint.h>
/* This message system uses absolute integer time values to fire off events.
This ensures accuarate firing times while eliminating floating point error.
Modified: Mercury2/src/RenderableNode.cpp
===================================================================
--- Mercury2/src/RenderableNode.cpp 2009-03-04 00:46:51 UTC (rev 176)
+++ Mercury2/src/RenderableNode.cpp 2009-03-08 04:19:56 UTC (rev 177)
@@ -2,6 +2,7 @@
#include <assert.h>
#include <GL/gl.h>
#include <TransformNode.h>
+#include <unistd.h>
using namespace std;
Modified: Mercury2/src/RenderableNode.h
===================================================================
--- Mercury2/src/RenderableNode.h 2009-03-04 00:46:51 UTC (rev 176)
+++ Mercury2/src/RenderableNode.h 2009-03-08 04:19:56 UTC (rev 177)
@@ -6,6 +6,7 @@
#include <MercuryAsset.h>
#include <MercuryMatrix.h>
#include <MSemaphore.h>
+#include <stdint.h>
#define MCHECKASSETS
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-04 00:46:52
|
Revision: 176
http://hgengine.svn.sourceforge.net/hgengine/?rev=176&view=rev
Author: axlecrusher
Date: 2009-03-04 00:46:51 +0000 (Wed, 04 Mar 2009)
Log Message:
-----------
test clipping
Modified Paths:
--------------
Mercury2/src/BoundingBox.cpp
Mercury2/src/Viewport.cpp
Modified: Mercury2/src/BoundingBox.cpp
===================================================================
--- Mercury2/src/BoundingBox.cpp 2009-03-03 22:30:27 UTC (rev 175)
+++ Mercury2/src/BoundingBox.cpp 2009-03-04 00:46:51 UTC (rev 176)
@@ -53,10 +53,8 @@
const BoundingBox& bb = *m_bb;
BoundingBox gbb = m_bb->Transform( GetGlobalMatrix() );
+ if ( FRUSTUM->Clip( gbb ) ) return;
- FRUSTUM->m_planes[PFAR].IsBehindPlane( gbb.GetCenter() );
-// printf("clip %d\n", FRUSTUM->m_planes[PFAR].IsBehindPlane( gbb.GetCenter() ));
-
const float* center = m_bb->GetCenter();
const float* extend = m_bb->GetExtend();
Modified: Mercury2/src/Viewport.cpp
===================================================================
--- Mercury2/src/Viewport.cpp 2009-03-03 22:30:27 UTC (rev 175)
+++ Mercury2/src/Viewport.cpp 2009-03-04 00:46:51 UTC (rev 176)
@@ -127,10 +127,10 @@
bool Frustum::Clip(const BoundingBox& bb) const
{
- bool inView = false;
- for (uint8_t i = 0; (i < 6) && !inView; ++i)
+ bool inView = true;
+ for (uint8_t i = 0; (i < 6) && inView; ++i)
{
- inView = m_planes[i].IsBehindPlane( bb )?inView:true;
+ inView = m_planes[i].IsBehindPlane( bb )?false:inView;
}
return !inView;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-03 22:30:37
|
Revision: 175
http://hgengine.svn.sourceforge.net/hgengine/?rev=175&view=rev
Author: axlecrusher
Date: 2009-03-03 22:30:27 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
fix bounding box check
Modified Paths:
--------------
Mercury2/src/MercuryPlane.cpp
Modified: Mercury2/src/MercuryPlane.cpp
===================================================================
--- Mercury2/src/MercuryPlane.cpp 2009-03-03 21:44:02 UTC (rev 174)
+++ Mercury2/src/MercuryPlane.cpp 2009-03-03 22:30:27 UTC (rev 175)
@@ -19,9 +19,11 @@
x += ABS( extends.GetY() * m_normal.DotProduct( A2 ) );
x += ABS( extends.GetZ() * m_normal.DotProduct( A3 ) );
- float d = m_normal.DotProduct( m_center );
+ float d = m_normal.DotProduct( center+m_center );
+ if ( ABS(d) <= x ) //intersection
+ return false;
- return ABS( d ) > x;
+ return IsBehindPlane( center ); //if we don't intersect, just see what side we are on
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-03 21:44:11
|
Revision: 174
http://hgengine.svn.sourceforge.net/hgengine/?rev=174&view=rev
Author: axlecrusher
Date: 2009-03-03 21:44:02 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
compute box normals
Modified Paths:
--------------
Mercury2/src/BoundingBox.cpp
Mercury2/src/BoundingBox.h
Modified: Mercury2/src/BoundingBox.cpp
===================================================================
--- Mercury2/src/BoundingBox.cpp 2009-03-03 21:41:55 UTC (rev 173)
+++ Mercury2/src/BoundingBox.cpp 2009-03-03 21:44:02 UTC (rev 174)
@@ -4,12 +4,45 @@
#include <Viewport.h>
+BoundingBox::BoundingBox(const MercuryVertex& center, const MercuryVertex& extend)
+ :m_center(center), m_extend(extend)
+{
+ ComputeNormals();
+};
+
void BoundingBox::LoadFromBinary(char* data)
{
memcpy(m_center, data, sizeof(float)*3);
memcpy(m_extend, data+(sizeof(float)*3), sizeof(float)*3);
+ ComputeNormals();
}
+void BoundingBox::ComputeNormals()
+{
+ MercuryVertex t(m_center);
+ t.SetX( t.GetX() + m_extend.GetX() );
+ m_normals[0] = (m_center - t).Normalize();
+
+ t = m_center;
+ t.SetY( t.GetY() + m_extend.GetY() );
+ m_normals[1] = (m_center - t).Normalize();
+
+ t = m_center;
+ t.SetZ( t.GetZ() + m_extend.GetZ() );
+ m_normals[2] = (m_center - t).Normalize();
+}
+
+BoundingBox BoundingBox::Transform( const MercuryMatrix& m ) const
+{
+ BoundingBox bb;
+ bb.m_extend = m_center;
+ bb.m_center = m * m_center;
+ bb.m_normals[0] = (m * m_normals[0]).Normalize();
+ bb.m_normals[1] = (m * m_normals[1]).Normalize();
+ bb.m_normals[2] = (m * m_normals[2]).Normalize();
+ return bb;
+}
+
RenderableBoundingBox::RenderableBoundingBox(const BoundingBox* bb)
:MercuryAsset(), m_bb(bb)
{
@@ -19,11 +52,11 @@
{
const BoundingBox& bb = *m_bb;
- MercuryVertex c = GetGlobalMatrix() * m_bb->GetCenter();
- BoundingBox gbb( c, bb.GetExtend() );
- c.Print();
-// printf("clip %d\n", FRUSTUM->Clip(gbb) );
+ BoundingBox gbb = m_bb->Transform( GetGlobalMatrix() );
+ FRUSTUM->m_planes[PFAR].IsBehindPlane( gbb.GetCenter() );
+// printf("clip %d\n", FRUSTUM->m_planes[PFAR].IsBehindPlane( gbb.GetCenter() ));
+
const float* center = m_bb->GetCenter();
const float* extend = m_bb->GetExtend();
Modified: Mercury2/src/BoundingBox.h
===================================================================
--- Mercury2/src/BoundingBox.h 2009-03-03 21:41:55 UTC (rev 173)
+++ Mercury2/src/BoundingBox.h 2009-03-03 21:44:02 UTC (rev 174)
@@ -3,23 +3,29 @@
#include <MercuryAsset.h>
#include <MercuryVertex.h>
+#include <MercuryMatrix.h>
class BoundingBox
{
public:
BoundingBox() {};
- BoundingBox(const MercuryVertex& center, const MercuryVertex& extend)
- :m_center(center), m_extend(extend)
- {};
+ BoundingBox(const MercuryVertex& center, const MercuryVertex& extend);
void LoadFromBinary(char* data);
inline const MercuryVertex& GetCenter() const { return m_center; }
inline const MercuryVertex& GetExtend() const { return m_extend; }
+ BoundingBox Transform( const MercuryMatrix& m ) const;
+ const MercuryVector& Normal(uint8_t i) const { return m_normals[i]; }
+
private:
+ void ComputeNormals();
+
MercuryVertex m_center;
MercuryVertex m_extend;
+
+ MercuryVector m_normals[3];
};
class RenderableBoundingBox : public MercuryAsset
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-03 21:42:04
|
Revision: 173
http://hgengine.svn.sourceforge.net/hgengine/?rev=173&view=rev
Author: axlecrusher
Date: 2009-03-03 21:41:55 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
fix far and near plane calculations
Modified Paths:
--------------
Mercury2/src/Viewport.cpp
Modified: Mercury2/src/Viewport.cpp
===================================================================
--- Mercury2/src/Viewport.cpp 2009-03-03 21:36:47 UTC (rev 172)
+++ Mercury2/src/Viewport.cpp 2009-03-03 21:41:55 UTC (rev 173)
@@ -92,15 +92,16 @@
MercuryVector X,Y,Z;
Z = (eye - look).Normalize(); //direction behind camera
- X = (up * Z).Normalize(); //X axis
+ X = (up.CrossProduct(Z)).Normalize(); //X axis
Y = Z.CrossProduct( X ); //real up
- m_nc = up - Z * m_zNear;
- m_fc = up - Z * m_zFar;
+ m_nc = (eye - Z) * m_zNear;
+ m_fc = (eye - Z) * m_zFar;
- m_planes[PNEAR].Setup(m_nc, Z*-1);
+ m_planes[PNEAR].Setup(m_nc, Z*(-1));
m_planes[PFAR].Setup(m_fc, Z);
-
+// m_fc.Print();
+// Z.Print();
MercuryVector aux,normal;
aux = (m_nc + Y*m_nh) - eye;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-03 21:36:56
|
Revision: 172
http://hgengine.svn.sourceforge.net/hgengine/?rev=172&view=rev
Author: axlecrusher
Date: 2009-03-03 21:36:47 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
fix point behind plane test
Modified Paths:
--------------
Mercury2/src/MercuryPlane.cpp
Modified: Mercury2/src/MercuryPlane.cpp
===================================================================
--- Mercury2/src/MercuryPlane.cpp 2009-03-03 13:37:30 UTC (rev 171)
+++ Mercury2/src/MercuryPlane.cpp 2009-03-03 21:36:47 UTC (rev 172)
@@ -4,7 +4,8 @@
bool MercuryPlane::IsBehindPlane(const MercuryVertex& point) const
{
- return m_normal.DotProduct( point ) < 0;
+ // origional algorithim was -dotproduct < 0
+ return m_normal.DotProduct( point+m_center ) >= 0;
}
bool MercuryPlane::IsBehindPlane(const BoundingBox& bb) const
@@ -12,15 +13,8 @@
const MercuryVertex& center = bb.GetCenter();
const MercuryVertex& extends = bb.GetExtend();
- MercuryVertex A1, A2, A3, tmp;
-
- tmp = center+MercuryVertex( extends.GetX(), 0, 0 );
- A1 = (center-tmp).Normalize();
- tmp = center+MercuryVertex( 0, extends.GetY(), 0 );
- A2 = (center-tmp).Normalize();
- tmp = center+MercuryVertex( 0, 0, extends.GetZ() );
- A3 = (center-tmp).Normalize();
-
+ const MercuryVertex &A1(bb.Normal(0)), &A2(bb.Normal(1)), &A3(bb.Normal(2));
+
float x = ABS( extends.GetX() * m_normal.DotProduct( A1 ) );
x += ABS( extends.GetY() * m_normal.DotProduct( A2 ) );
x += ABS( extends.GetZ() * m_normal.DotProduct( A3 ) );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-03 13:37:38
|
Revision: 170
http://hgengine.svn.sourceforge.net/hgengine/?rev=170&view=rev
Author: axlecrusher
Date: 2009-03-03 13:33:16 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
take w in conversion functions
Modified Paths:
--------------
Mercury2/src/MercuryVertex.h
Modified: Mercury2/src/MercuryVertex.h
===================================================================
--- Mercury2/src/MercuryVertex.h 2009-03-03 02:06:45 UTC (rev 169)
+++ Mercury2/src/MercuryVertex.h 2009-03-03 13:33:16 UTC (rev 170)
@@ -35,9 +35,9 @@
///Write out to be = to this point
inline void ConvertToVector3( float* out ) const { out[0] = m_xyz[0]; out[1] = m_xyz[1]; out[2] = m_xyz[2]; }
///Write out to be = to this point, however the 4th element will be 0
- inline void ConvertToVector4( float* out ) const { out[0] = m_xyz[0]; out[1] = m_xyz[1]; out[2] = m_xyz[2]; out[3] = 0; }
+ inline void ConvertToVector4( float* out, float w = 0 ) const { out[0] = m_xyz[0]; out[1] = m_xyz[1]; out[2] = m_xyz[2]; out[3] = w; }
///Write out to be = - to this point, however the 4th element will be 0
- inline void ConvertToIVector4( float* out ) const { out[0] = -m_xyz[0]; out[1] = -m_xyz[1]; out[2] = -m_xyz[2]; out[3] = 0; }
+ inline void ConvertToIVector4( float* out, float w = 0 ) const { out[0] = -m_xyz[0]; out[1] = -m_xyz[1]; out[2] = -m_xyz[2]; out[3] = w; }
const MercuryVertex& operator *= (const MercuryVertex& p);
const MercuryVertex& operator /= (const MercuryVertex& p);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-03 13:37:34
|
Revision: 171
http://hgengine.svn.sourceforge.net/hgengine/?rev=171&view=rev
Author: axlecrusher
Date: 2009-03-03 13:37:30 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
Make mercury math a little safer to use
Modified Paths:
--------------
Mercury2/src/MercuryMath.cpp
Mercury2/src/MercuryMath.h
Mercury2/src/MercuryMatrix.cpp
Modified: Mercury2/src/MercuryMath.cpp
===================================================================
--- Mercury2/src/MercuryMath.cpp 2009-03-03 13:33:16 UTC (rev 170)
+++ Mercury2/src/MercuryMath.cpp 2009-03-03 13:37:30 UTC (rev 171)
@@ -1,3 +1,4 @@
+#include <stdint.h>
#include "MercuryMath.h"
//the SSE version of this was really slow, this is quicker
@@ -38,80 +39,46 @@
Copy4f(&r, &gfrZero );
}
-void Mul4f(const FloatRow* first, const FloatRow* second, FloatRow* out)
+void Mul4f(const FloatRow& first, const FloatRow& second, FloatRow& out)
{
- (*out)[0] = (*first)[0] * (*second)[0];
- (*out)[1] = (*first)[1] * (*second)[1];
- (*out)[2] = (*first)[2] * (*second)[2];
- (*out)[3] = (*first)[3] * (*second)[3];
+ for (uint8_t i = 0; i < 4; ++i)
+ out[i] = first[i] * second[i];
}
-void Div4f(const FloatRow* first, const FloatRow* second, FloatRow* out)
+void Div4f(const FloatRow& first, const FloatRow& second, FloatRow& out)
{
- (*out)[0] = (*first)[0] / (*second)[0];
- (*out)[1] = (*first)[1] / (*second)[1];
- (*out)[2] = (*first)[2] / (*second)[2];
- (*out)[3] = (*first)[3] / (*second)[3];
+ for (uint8_t i = 0; i < 4; ++i)
+ out[i] = first[i] / second[i];
}
-void Add4f(const FloatRow* first, const FloatRow* second, FloatRow* out)
+void Add4f(const FloatRow& first, const FloatRow& second, FloatRow& out)
{
- (*out)[0] = (*first)[0] + (*second)[0];
- (*out)[1] = (*first)[1] + (*second)[1];
- (*out)[2] = (*first)[2] + (*second)[2];
- (*out)[3] = (*first)[3] + (*second)[3];
+ for (uint8_t i = 0; i < 4; ++i)
+ out[i] = first[i] + second[i];
}
-void Sub4f(const FloatRow* first, const FloatRow* second, FloatRow* out)
+void Sub4f(const FloatRow& first, const FloatRow& second, FloatRow& out)
{
- (*out)[0] = (*first)[0] - (*second)[0];
- (*out)[1] = (*first)[1] - (*second)[1];
- (*out)[2] = (*first)[2] - (*second)[2];
- (*out)[3] = (*first)[3] - (*second)[3];
+ for (uint8_t i = 0; i < 4; ++i)
+ out[i] = first[i] - second[i];
}
void Copy4f( void * dest, const void * source )
{
- ((float*)dest)[0] = ((float*)source)[0];
- ((float*)dest)[1] = ((float*)source)[1];
- ((float*)dest)[2] = ((float*)source)[2];
- ((float*)dest)[3] = ((float*)source)[3];
+ for (uint8_t i = 0; i < 4; ++i)
+ ((float*)dest)[i] = ((float*)source)[i];
}
void Copy8f( void * dest, const void * source )
{
- ((float*)dest)[0] = ((float*)source)[0];
- ((float*)dest)[1] = ((float*)source)[1];
- ((float*)dest)[2] = ((float*)source)[2];
- ((float*)dest)[3] = ((float*)source)[3];
-
- ((float*)dest)[4] = ((float*)source)[4];
- ((float*)dest)[5] = ((float*)source)[5];
- ((float*)dest)[6] = ((float*)source)[6];
- ((float*)dest)[7] = ((float*)source)[7];
+ for (uint8_t i = 0; i < 8; ++i)
+ ((float*)dest)[i] = ((float*)source)[i];
}
void Copy16f( void * dest, const void * source )
{
- ((float*)dest)[0] = ((float*)source)[0];
- ((float*)dest)[1] = ((float*)source)[1];
- ((float*)dest)[2] = ((float*)source)[2];
- ((float*)dest)[3] = ((float*)source)[3];
-
- ((float*)dest)[4] = ((float*)source)[4];
- ((float*)dest)[5] = ((float*)source)[5];
- ((float*)dest)[6] = ((float*)source)[6];
- ((float*)dest)[7] = ((float*)source)[7];
-
- ((float*)dest)[8] = ((float*)source)[8];
- ((float*)dest)[9] = ((float*)source)[9];
- ((float*)dest)[10] = ((float*)source)[10];
- ((float*)dest)[11] = ((float*)source)[11];
-
- ((float*)dest)[12] = ((float*)source)[12];
- ((float*)dest)[13] = ((float*)source)[13];
- ((float*)dest)[14] = ((float*)source)[14];
- ((float*)dest)[15] = ((float*)source)[15];
+ for (uint8_t i = 0; i < 16; ++i)
+ ((float*)dest)[i] = ((float*)source)[i];
}
void MatrixMultiply4f ( const FloatRow* in1a, const FloatRow* in2a, FloatRow* outa)
@@ -168,21 +135,16 @@
out[3] = p[0] * m[12] + p[1] * m[13] + p[2] * m[14] + p[3] * m[15];
}
-void Float2FloatRow(const float* f, FloatRow* r)
+void Float2FloatRow(const float* f, FloatRow& r)
{
- float* row = *r;
- row[0] = f[0];
- row[1] = f[1];
- row[2] = f[2];
- row[3] = f[3];
+ for (uint8_t i = 0; i < 4; ++i)
+ r[i] = f[i];
}
-void FloatRow2Float( const FloatRow* fr, float* f)
+void FloatRow2Float( const FloatRow& r, float* f)
{
- f[0] = (*fr)[0];
- f[1] = (*fr)[1];
- f[2] = (*fr)[2];
- f[3] = (*fr)[3];
+ for (uint8_t i = 0; i < 4; ++i)
+ f[i] = r[i];
}
#else
@@ -196,24 +158,24 @@
return _mm_add_ps( x, _mm_shuffle_ps(x, x, _MM_SHUFFLE(1,1,1,1)) );
}
-void Mul4f(const FloatRow* first, const FloatRow* second, FloatRow* out)
+void Mul4f(const FloatRow& first, const FloatRow& second, FloatRow& out)
{
- *out = _mm_mul_ps( *first, *second );
+ out = _mm_mul_ps( first, second );
}
-void Div4f(const FloatRow* first, const FloatRow* second, FloatRow* out)
+void Div4f(const FloatRow& first, const FloatRow& second, FloatRow& out)
{
- *out = _mm_div_ps( *first, *second );
+ out = _mm_div_ps( first, second );
}
-void Add4f(const FloatRow* first, const FloatRow* second, FloatRow* out)
+void Add4f(const FloatRow& first, const FloatRow& second, FloatRow& out)
{
- *out = _mm_add_ps( *first, *second );
+ out = _mm_add_ps( first, second );
}
-void Sub4f(const FloatRow* first, const FloatRow* second, FloatRow* out)
+void Sub4f(const FloatRow& first, const FloatRow& second, FloatRow& out)
{
- *out = _mm_sub_ps( *first, *second );
+ out = _mm_sub_ps( first, second );
}
void Copy4f( void * dest, const void * source )
@@ -302,14 +264,14 @@
r = (FloatRow)_mm_setzero_ps();
}
-void Float2FloatRow(const float* f, FloatRow* r)
+void Float2FloatRow(const float* f, FloatRow& r)
{
- *r = _mm_load_ps( f );
+ r = _mm_load_ps( f );
}
-void FloatRow2Float( const FloatRow* fr, float* f)
+void FloatRow2Float( const FloatRow& r, float* f)
{
- _mm_store_ps( f, *fr );
+ _mm_store_ps( f, r );
}
#endif
Modified: Mercury2/src/MercuryMath.h
===================================================================
--- Mercury2/src/MercuryMath.h 2009-03-03 13:33:16 UTC (rev 170)
+++ Mercury2/src/MercuryMath.h 2009-03-03 13:37:30 UTC (rev 171)
@@ -44,10 +44,10 @@
//#define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2])
-void Mul4f(const FloatRow* first, const FloatRow* second, FloatRow* out);
-void Div4f(const FloatRow* first, const FloatRow* second, FloatRow* out);
-void Add4f(const FloatRow* first, const FloatRow* second, FloatRow* out);
-void Sub4f(const FloatRow* first, const FloatRow* second, FloatRow* out);
+void Mul4f(const FloatRow& first, const FloatRow& second, FloatRow& out);
+void Div4f(const FloatRow& first, const FloatRow& second, FloatRow& out);
+void Add4f(const FloatRow& first, const FloatRow& second, FloatRow& out);
+void Sub4f(const FloatRow& first, const FloatRow& second, FloatRow& out);
void Copy4f( void * dest, const void * source );
void Copy8f( void * dest, const void * source );
void Copy16f( void * dest, const void * source );
@@ -55,8 +55,8 @@
void VectorMultiply4f(const FloatRow* matrix, const FloatRow& p, FloatRow& out );
void TransposeMatrix( FloatRow* m );
-void Float2FloatRow(const float* f, FloatRow* r);
-void FloatRow2Float( const FloatRow* fr, float* f);
+void Float2FloatRow(const float* f, FloatRow& r);
+void FloatRow2Float(const FloatRow& fr, float* f);
const FloatRow gfrZero = { 0.f, 0.f, 0.f, 0.f };
Modified: Mercury2/src/MercuryMatrix.cpp
===================================================================
--- Mercury2/src/MercuryMatrix.cpp 2009-03-03 13:33:16 UTC (rev 170)
+++ Mercury2/src/MercuryMatrix.cpp 2009-03-03 13:37:30 UTC (rev 171)
@@ -200,12 +200,11 @@
float tmp[4];
FloatRow r, tvo;
- v.ConvertToVector4( tmp );
- tmp[3] = 1;
- Float2FloatRow( tmp, &r );
+ v.ConvertToVector4( tmp, 1 );
+ Float2FloatRow( tmp, r );
VectorMultiply4f( m_matrix, r, tvo);
- FloatRow2Float( &tvo, tmp );
- printf("%f %f %f %f\n", tmp[0], tmp[1], tmp[2], tmp[3]);
+ FloatRow2Float( tvo, tmp );
+// printf("%f %f %f %f\n", tmp[0], tmp[1], tmp[2], tmp[3]);
return MercuryVertex(tmp);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-03 02:06:54
|
Revision: 169
http://hgengine.svn.sourceforge.net/hgengine/?rev=169&view=rev
Author: axlecrusher
Date: 2009-03-03 02:06:45 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
Fix nonSSE compile
Modified Paths:
--------------
Mercury2/src/MercuryMath.cpp
Modified: Mercury2/src/MercuryMath.cpp
===================================================================
--- Mercury2/src/MercuryMath.cpp 2009-03-03 02:02:34 UTC (rev 168)
+++ Mercury2/src/MercuryMath.cpp 2009-03-03 02:06:45 UTC (rev 169)
@@ -157,11 +157,11 @@
in1[14] * in2[11] + in1[15] * in2[15];
}
-void VectorMultiply4f( const FloatRow* matrix, const FloatRow* pa, FloatRow* outa )
+void VectorMultiply4f( const FloatRow* matrix, const FloatRow& pa, FloatRow& outa )
{
const float *m = *matrix;
- const float *p = *pa;
- float *out = *outa;
+ const float *p = pa;
+ float *out = outa;
out[0] = p[0] * m[0] + p[1] * m[1] + p[2] * m[2] + p[3] * m[3];
out[1] = p[0] * m[4] + p[1] * m[5] + p[2] * m[6] + p[3] * m[7];
out[2] = p[0] * m[8] + p[1] * m[9] + p[2] * m[10] + p[3] * m[11];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-03 02:02:43
|
Revision: 168
http://hgengine.svn.sourceforge.net/hgengine/?rev=168&view=rev
Author: axlecrusher
Date: 2009-03-03 02:02:34 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
Fix broken SSE math, I have to make these math functions safer
Modified Paths:
--------------
Mercury2/src/MercuryMath.cpp
Mercury2/src/MercuryMath.h
Mercury2/src/MercuryMatrix.cpp
Modified: Mercury2/src/MercuryMath.cpp
===================================================================
--- Mercury2/src/MercuryMath.cpp 2009-03-02 21:59:02 UTC (rev 167)
+++ Mercury2/src/MercuryMath.cpp 2009-03-03 02:02:34 UTC (rev 168)
@@ -278,25 +278,23 @@
//This is an SSE matrix vector multiply, see the standard C++ code
//for a clear algorithim. This seems like it works.
-void VectorMultiply4f( const FloatRow* matrix, const FloatRow* p, FloatRow* out )
+void VectorMultiply4f( const FloatRow* matrix, const FloatRow& p, FloatRow& out )
{
- __m128 tmp;
+ __m128 tmp, XY;
- //compute term 1 and term 2 and store them in the low order
- //of outxmm[0]
- out[0] = Hadd4( _mm_mul_ps( matrix[0], *p ) );
- tmp = Hadd4( _mm_mul_ps( matrix[1], *p ) );
- out[0] = _mm_unpacklo_ps(out[0], tmp);
+ //compute term X and term Y and store them in the low order of XY
+ XY = Hadd4( _mm_mul_ps( matrix[0], p ) ); //compute X
+ tmp = Hadd4( _mm_mul_ps( matrix[1], p ) ); //compute Y
+ XY = _mm_unpacklo_ps(XY, tmp);
- //compute term 3 and term 4 and store them in the high order
- //of outxmm[1]
- out[1] = Hadd4( _mm_mul_ps( matrix[2], *p ) );
- tmp = Hadd4( _mm_mul_ps( matrix[3], *p ) );
- out[1] = _mm_unpacklo_ps(out[1], tmp);
+ //compute term Z and term W and store them in the low order of out
+ out = Hadd4( _mm_mul_ps( matrix[2], p ) ); //compute Z
+ tmp = Hadd4( _mm_mul_ps( matrix[3], p ) ); //compute W
+ out = _mm_unpacklo_ps(out, tmp);
- //shuffle the low order of outxmm[0] into the loworder of tmp
- //and shuffle the low order of outxmm[1] into the high order of tmp
- *out = _mm_movelh_ps(out[0], out[1]);
+ //shuffle the low order of XY into the loworder of out
+ //and shuffle the low order of out into the high order of out
+ out = _mm_movelh_ps(XY, out);
}
void ZeroFloatRow(FloatRow& r)
Modified: Mercury2/src/MercuryMath.h
===================================================================
--- Mercury2/src/MercuryMath.h 2009-03-02 21:59:02 UTC (rev 167)
+++ Mercury2/src/MercuryMath.h 2009-03-03 02:02:34 UTC (rev 168)
@@ -52,7 +52,7 @@
void Copy8f( void * dest, const void * source );
void Copy16f( void * dest, const void * source );
void MatrixMultiply4f ( const FloatRow* in1, const FloatRow* in2, FloatRow* out );
-void VectorMultiply4f(const FloatRow* matrix, const FloatRow* p, FloatRow* out );
+void VectorMultiply4f(const FloatRow* matrix, const FloatRow& p, FloatRow& out );
void TransposeMatrix( FloatRow* m );
void Float2FloatRow(const float* f, FloatRow* r);
Modified: Mercury2/src/MercuryMatrix.cpp
===================================================================
--- Mercury2/src/MercuryMatrix.cpp 2009-03-02 21:59:02 UTC (rev 167)
+++ Mercury2/src/MercuryMatrix.cpp 2009-03-03 02:02:34 UTC (rev 168)
@@ -203,9 +203,9 @@
v.ConvertToVector4( tmp );
tmp[3] = 1;
Float2FloatRow( tmp, &r );
- VectorMultiply4f( m_matrix, &r, &tvo);
+ VectorMultiply4f( m_matrix, r, tvo);
FloatRow2Float( &tvo, tmp );
-
+ printf("%f %f %f %f\n", tmp[0], tmp[1], tmp[2], tmp[3]);
return MercuryVertex(tmp);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2009-03-02 21:59:18
|
Revision: 167
http://hgengine.svn.sourceforge.net/hgengine/?rev=167&view=rev
Author: cnlohr
Date: 2009-03-02 21:59:02 +0000 (Mon, 02 Mar 2009)
Log Message:
-----------
add extra files to build system
Modified Paths:
--------------
Mercury2/adv_set.c
Mercury2/base_set.sh
Modified: Mercury2/adv_set.c
===================================================================
--- Mercury2/adv_set.c 2009-03-02 21:07:12 UTC (rev 166)
+++ Mercury2/adv_set.c 2009-03-02 21:59:02 UTC (rev 167)
@@ -9,9 +9,9 @@
src/Texture.cpp src/RawImageData.cpp src/BMPLoader.cpp src/PNGLoader.cpp src/ImageLoader.cpp \
src/MercuryVBO.cpp src/MSemaphore.cpp src/UpdateThreader.cpp src/HGMDLMesh.cpp \
src/HGMDLModel.cpp src/MercuryString.cpp src/MercuryCrash.c src/MercuryBacktrace.c \
- src/MercuryFile.cpp src/MercuryTimer.cpp src/MercuryMessageManager.cpp"
+ src/MercuryFile.cpp src/MercuryTimer.cpp src/MercuryMessageManager.cpp src/MercuryVertex.cpp \
+ src/MercuryPlane.cpp src/BoundingBox.cpp"
-
SOURCES="$SOURCES src/MercuryFileDriverDirect.cpp src/MercuryFileDriverMem.cpp \
src/MercuryFileDriverPacked.cpp src/MercuryFileDriverZipped.cpp"
Modified: Mercury2/base_set.sh
===================================================================
--- Mercury2/base_set.sh 2009-03-02 21:07:12 UTC (rev 166)
+++ Mercury2/base_set.sh 2009-03-02 21:59:02 UTC (rev 167)
@@ -8,13 +8,14 @@
ISMAC=1; fi
-OPTIONS="X11 libxml OGL"
+OPTIONS="X11 libxml OGL sse"
OPT_X11=1
OPT_OGL=1
OPT_libxml=1
+OPT_sse=1
DEFINES="WAS_CONFIGURED USE_MSTRING"
-CC_BASE="-O2 -g0 -Wall -DUSE_SSE"
+CC_BASE="-O2 -g0 -Wall"
for i in $*; do
if test $i = "--help"; then
@@ -65,7 +66,7 @@
NEED_L="$NEED_L GL"
fi
-if test $OPT_sse = 1; then
+if test $OPT_ss = 1; then
DEFINES="$DEFINES USE_SSE"
fi
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-02 21:07:22
|
Revision: 166
http://hgengine.svn.sourceforge.net/hgengine/?rev=166&view=rev
Author: axlecrusher
Date: 2009-03-02 21:07:12 +0000 (Mon, 02 Mar 2009)
Log Message:
-----------
fix broken SSE vector multiply
Modified Paths:
--------------
Mercury2/src/MercuryMath.cpp
Modified: Mercury2/src/MercuryMath.cpp
===================================================================
--- Mercury2/src/MercuryMath.cpp 2009-03-02 20:36:05 UTC (rev 165)
+++ Mercury2/src/MercuryMath.cpp 2009-03-02 21:07:12 UTC (rev 166)
@@ -4,7 +4,7 @@
void TransposeMatrix( FloatRow* m )
{
float tmp;
- float *_m = *m;
+ float *_m = (float*)m;
tmp = _m[1];
_m[1] = _m[4];
@@ -284,14 +284,14 @@
//compute term 1 and term 2 and store them in the low order
//of outxmm[0]
- out[0] = Hadd4( _mm_mul_ps( matrix[1], *p ) );
- tmp = Hadd4( _mm_mul_ps( matrix[2], *p ) );
+ out[0] = Hadd4( _mm_mul_ps( matrix[0], *p ) );
+ tmp = Hadd4( _mm_mul_ps( matrix[1], *p ) );
out[0] = _mm_unpacklo_ps(out[0], tmp);
//compute term 3 and term 4 and store them in the high order
//of outxmm[1]
- out[1] = Hadd4( _mm_mul_ps( matrix[3], *p ) );
- tmp = Hadd4( _mm_mul_ps( matrix[4], *p ) );
+ out[1] = Hadd4( _mm_mul_ps( matrix[2], *p ) );
+ tmp = Hadd4( _mm_mul_ps( matrix[3], *p ) );
out[1] = _mm_unpacklo_ps(out[1], tmp);
//shuffle the low order of outxmm[0] into the loworder of tmp
@@ -304,9 +304,9 @@
r = (FloatRow)_mm_setzero_ps();
}
-FloatRow Float2FloatRow(const float* f, , FloatRow* r)
+void Float2FloatRow(const float* f, FloatRow* r)
{
- r = _mm_load_ps( f );
+ *r = _mm_load_ps( f );
}
void FloatRow2Float( const FloatRow* fr, float* f)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-02 20:36:10
|
Revision: 165
http://hgengine.svn.sourceforge.net/hgengine/?rev=165&view=rev
Author: axlecrusher
Date: 2009-03-02 20:36:05 +0000 (Mon, 02 Mar 2009)
Log Message:
-----------
fix matrix vector multiply
Modified Paths:
--------------
Mercury2/src/BoundingBox.cpp
Mercury2/src/MercuryMatrix.cpp
Modified: Mercury2/src/BoundingBox.cpp
===================================================================
--- Mercury2/src/BoundingBox.cpp 2009-03-02 20:19:52 UTC (rev 164)
+++ Mercury2/src/BoundingBox.cpp 2009-03-02 20:36:05 UTC (rev 165)
@@ -20,12 +20,8 @@
const BoundingBox& bb = *m_bb;
MercuryVertex c = GetGlobalMatrix() * m_bb->GetCenter();
-
-// GetGlobalMatrix().Print();
- c.Print();
-
BoundingBox gbb( c, bb.GetExtend() );
-
+ c.Print();
// printf("clip %d\n", FRUSTUM->Clip(gbb) );
const float* center = m_bb->GetCenter();
Modified: Mercury2/src/MercuryMatrix.cpp
===================================================================
--- Mercury2/src/MercuryMatrix.cpp 2009-03-02 20:19:52 UTC (rev 164)
+++ Mercury2/src/MercuryMatrix.cpp 2009-03-02 20:36:05 UTC (rev 165)
@@ -201,6 +201,7 @@
FloatRow r, tvo;
v.ConvertToVector4( tmp );
+ tmp[3] = 1;
Float2FloatRow( tmp, &r );
VectorMultiply4f( m_matrix, &r, &tvo);
FloatRow2Float( &tvo, tmp );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-02 20:19:56
|
Revision: 164
http://hgengine.svn.sourceforge.net/hgengine/?rev=164&view=rev
Author: axlecrusher
Date: 2009-03-02 20:19:52 +0000 (Mon, 02 Mar 2009)
Log Message:
-----------
dereference not cast
Modified Paths:
--------------
Mercury2/src/MercuryMath.cpp
Modified: Mercury2/src/MercuryMath.cpp
===================================================================
--- Mercury2/src/MercuryMath.cpp 2009-03-02 20:07:37 UTC (rev 163)
+++ Mercury2/src/MercuryMath.cpp 2009-03-02 20:19:52 UTC (rev 164)
@@ -4,7 +4,7 @@
void TransposeMatrix( FloatRow* m )
{
float tmp;
- float *_m = (float*)m;
+ float *_m = *m;
tmp = _m[1];
_m[1] = _m[4];
@@ -40,34 +40,34 @@
void Mul4f(const FloatRow* first, const FloatRow* second, FloatRow* out)
{
- ((float*)out)[0] = ((float*)first)[0] * ((float*)second)[0];
- ((float*)out)[1] = ((float*)first)[1] * ((float*)second)[1];
- ((float*)out)[2] = ((float*)first)[2] * ((float*)second)[2];
- ((float*)out)[3] = ((float*)first)[3] * ((float*)second)[3];
+ (*out)[0] = (*first)[0] * (*second)[0];
+ (*out)[1] = (*first)[1] * (*second)[1];
+ (*out)[2] = (*first)[2] * (*second)[2];
+ (*out)[3] = (*first)[3] * (*second)[3];
}
void Div4f(const FloatRow* first, const FloatRow* second, FloatRow* out)
{
- ((float*)out)[0] = ((float*)first)[0] / ((float*)second)[0];
- ((float*)out)[1] = ((float*)first)[1] / ((float*)second)[1];
- ((float*)out)[2] = ((float*)first)[2] / ((float*)second)[2];
- ((float*)out)[3] = ((float*)first)[3] / ((float*)second)[3];
+ (*out)[0] = (*first)[0] / (*second)[0];
+ (*out)[1] = (*first)[1] / (*second)[1];
+ (*out)[2] = (*first)[2] / (*second)[2];
+ (*out)[3] = (*first)[3] / (*second)[3];
}
void Add4f(const FloatRow* first, const FloatRow* second, FloatRow* out)
{
- ((float*)out)[0] = ((float*)first)[0] + ((float*)second)[0];
- ((float*)out)[1] = ((float*)first)[1] + ((float*)second)[1];
- ((float*)out)[2] = ((float*)first)[2] + ((float*)second)[2];
- ((float*)out)[3] = ((float*)first)[3] + ((float*)second)[3];
+ (*out)[0] = (*first)[0] + (*second)[0];
+ (*out)[1] = (*first)[1] + (*second)[1];
+ (*out)[2] = (*first)[2] + (*second)[2];
+ (*out)[3] = (*first)[3] + (*second)[3];
}
void Sub4f(const FloatRow* first, const FloatRow* second, FloatRow* out)
{
- ((float*)out)[0] = ((float*)first)[0] - ((float*)second)[0];
- ((float*)out)[1] = ((float*)first)[1] - ((float*)second)[1];
- ((float*)out)[2] = ((float*)first)[2] - ((float*)second)[2];
- ((float*)out)[3] = ((float*)first)[3] - ((float*)second)[3];
+ (*out)[0] = (*first)[0] - (*second)[0];
+ (*out)[1] = (*first)[1] - (*second)[1];
+ (*out)[2] = (*first)[2] - (*second)[2];
+ (*out)[3] = (*first)[3] - (*second)[3];
}
void Copy4f( void * dest, const void * source )
@@ -116,12 +116,10 @@
void MatrixMultiply4f ( const FloatRow* in1a, const FloatRow* in2a, FloatRow* outa)
{
- float *in1, *in2, *out;
+ const float *in1 = *in1a;
+ const float *in2 = *in2a;
+ float *out = *outa;
- in1 = (float*)in1a;
- in2 = (float*)in2a;
- out = (float*)outa;
-
out[0] = in1[0] * in2[0] + in1[1] * in2[4] +
in1[2] * in2[8] + in1[3] * in2[12];
out[1] = in1[0] * in2[1] + in1[1] * in2[5] +
@@ -161,9 +159,9 @@
void VectorMultiply4f( const FloatRow* matrix, const FloatRow* pa, FloatRow* outa )
{
- float *m = (float*)matrix;
- float *p = (float*)pa;
- float *out = (float*)outa;
+ const float *m = *matrix;
+ const float *p = *pa;
+ float *out = *outa;
out[0] = p[0] * m[0] + p[1] * m[1] + p[2] * m[2] + p[3] * m[3];
out[1] = p[0] * m[4] + p[1] * m[5] + p[2] * m[6] + p[3] * m[7];
out[2] = p[0] * m[8] + p[1] * m[9] + p[2] * m[10] + p[3] * m[11];
@@ -172,7 +170,7 @@
void Float2FloatRow(const float* f, FloatRow* r)
{
- float* row = (float*)r;
+ float* row = *r;
row[0] = f[0];
row[1] = f[1];
row[2] = f[2];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-02 20:07:39
|
Revision: 163
http://hgengine.svn.sourceforge.net/hgengine/?rev=163&view=rev
Author: axlecrusher
Date: 2009-03-02 20:07:37 +0000 (Mon, 02 Mar 2009)
Log Message:
-----------
update
Modified Paths:
--------------
Mercury2/scenegraph.xml
Mercury2/src/MercuryMatrix.cpp
Modified: Mercury2/scenegraph.xml
===================================================================
--- Mercury2/scenegraph.xml 2009-03-02 20:00:18 UTC (rev 162)
+++ Mercury2/scenegraph.xml 2009-03-02 20:07:37 UTC (rev 163)
@@ -20,7 +20,7 @@
<asset type="quad"/>
</node>
</node>
- <node type="rotatornode" movy="0" movz="-20" scalex="0.25" scaley="0.25" scalez="0.25" >
+ <node type="rotatornode" movy="0" movz="-2" scalex="0.25" scaley="0.25" scalez="0.25" >
<node type="renderablenode">
<asset type="texture" file="gunther.png"/>
<asset type="hgmdlmodel" file="gunther.hgmdl"/>
Modified: Mercury2/src/MercuryMatrix.cpp
===================================================================
--- Mercury2/src/MercuryMatrix.cpp 2009-03-02 20:00:18 UTC (rev 162)
+++ Mercury2/src/MercuryMatrix.cpp 2009-03-02 20:07:37 UTC (rev 163)
@@ -198,11 +198,13 @@
MercuryVector MercuryMatrix::operator*(const MercuryVector& v) const
{
float tmp[4];
+ FloatRow r, tvo;
+
v.ConvertToVector4( tmp );
- FloatRow r, tvo;
Float2FloatRow( tmp, &r );
VectorMultiply4f( m_matrix, &r, &tvo);
FloatRow2Float( &tvo, tmp );
+
return MercuryVertex(tmp);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|