From: <cn...@us...> - 2009-07-16 05:05:15
|
Revision: 429 http://hgengine.svn.sourceforge.net/hgengine/?rev=429&view=rev Author: cnlohr Date: 2009-07-16 05:05:11 +0000 (Thu, 16 Jul 2009) Log Message: ----------- add ability for nodes to find a parent by name Modified Paths: -------------- Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-07-15 14:33:24 UTC (rev 428) +++ Mercury2/src/MercuryNode.cpp 2009-07-16 05:05:11 UTC (rev 429) @@ -120,7 +120,15 @@ return NULL; } +MercuryNode* MercuryNode::FindParent( const MString & sNameOfNode, int depth ) +{ + MercuryNode * ret = this; + while( ret && ret->GetName() != sNameOfNode ) + ret = ret->Parent(); + return ret; +} + void MercuryNode::RecursiveUpdate(float dTime) { Update(dTime); Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-07-15 14:33:24 UTC (rev 428) +++ Mercury2/src/MercuryNode.h 2009-07-16 05:05:11 UTC (rev 429) @@ -48,6 +48,10 @@ /** The search order is breadth-first, however this may change without notice! */ MercuryNode* FindChild( const MString & sNameOfNode, int depth = MAXINT ); + ///Find a parent node that has the name matching sNameOfNode. + /** Traversal is from the closest parent on upward */ + MercuryNode* FindParent( const MString & sNameOfNode, int depth = MAXINT ); + virtual void Update(float dTime) {}; virtual void RecursiveUpdate(float dTime); void ThreadedUpdate(float dTime); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-07-21 01:52:42
|
Revision: 432 http://hgengine.svn.sourceforge.net/hgengine/?rev=432&view=rev Author: axlecrusher Date: 2009-07-21 01:52:34 +0000 (Tue, 21 Jul 2009) Log Message: ----------- update Modified Paths: -------------- Mercury2/src/Frustum.cpp Mercury2/src/Frustum.h Mercury2/src/MercuryVBO.cpp Mercury2/src/Viewport.h Added Paths: ----------- Mercury2/src/Orthographic.cpp Mercury2/src/Orthographic.h Modified: Mercury2/src/Frustum.cpp =================================================================== --- Mercury2/src/Frustum.cpp 2009-07-21 00:48:39 UTC (rev 431) +++ Mercury2/src/Frustum.cpp 2009-07-21 01:52:34 UTC (rev 432) @@ -91,6 +91,32 @@ m_planes[PRIGHT].Setup(m_nc+X*m_nw,normal); } +void Frustum::Ortho(float left, float right, float bottom, float top, float near, float far) +{ + float rml = right - left; + float tmb = top - bottom; + float fmn = far - near; + + m_frustum = MercuryMatrix::Identity(); + m_frustum[0][0] = 2.0f/rml; + m_frustum[1][1] = 2.0f/tmb; + m_frustum[2][2] = 2.0f/fmn; + + m_frustum[0][3] = -(right+left)/rml; + m_frustum[1][3] = -(top+bottom)/tmb; + m_frustum[2][3] = -(far+near)/fmn; + + m_planes[PTOP].Setup(MercuryVertex(rml/2.0f, top, fmn/2.0f), MercuryVector(0,-1,0)); + m_planes[PBOTTOM].Setup(MercuryVertex(rml/2.0f, bottom, fmn/2.0f), MercuryVector(0,1,0)); + + m_planes[PLEFT].Setup(MercuryVertex(left, tmb/2.0f, fmn/2.0f), MercuryVector(1,0,0)); + m_planes[PRIGHT].Setup(MercuryVertex(right, tmb/2.0f, fmn/2.0f), MercuryVector(-1,0,0)); + + m_planes[PNEAR].Setup(MercuryVertex(rml/2.0f, tmb/2.0f, near), MercuryVector(0,0,-1)); + m_planes[PFAR].Setup(MercuryVertex(rml/2.0f, tmb/2.0f, far), MercuryVector(0,0,1)); +} + + /* void Frustum::LookAt() { Modified: Mercury2/src/Frustum.h =================================================================== --- Mercury2/src/Frustum.h 2009-07-21 00:48:39 UTC (rev 431) +++ Mercury2/src/Frustum.h 2009-07-21 01:52:34 UTC (rev 432) @@ -22,6 +22,7 @@ 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); + void Ortho(float left, float right, float bottom, float top, float near, float far); inline const MercuryPlane& GetPlane(int i) const { return m_planes[i]; } private: @@ -35,6 +36,11 @@ MercuryVector m_nc, m_fc; }; +extern const Frustum* FRUSTUM; +extern MercuryMatrix VIEWMATRIX; +extern MercuryVertex EYE; +extern MercuryVector LOOKAT; + #endif /**************************************************************************** Modified: Mercury2/src/MercuryVBO.cpp =================================================================== --- Mercury2/src/MercuryVBO.cpp 2009-07-21 00:48:39 UTC (rev 431) +++ Mercury2/src/MercuryVBO.cpp 2009-07-21 01:52:34 UTC (rev 432) @@ -28,8 +28,8 @@ uint8_t numTextures = Texture::NumberActiveTextures(); uint16_t stride = sizeof(float)*8; - if ( !m_initiated ) - InitVBO(); + if ( !m_initiated ) InitVBO(); +glDisable(GL_CULL_FACE); if ( this != m_lastVBOrendered ) { Added: Mercury2/src/Orthographic.cpp =================================================================== --- Mercury2/src/Orthographic.cpp (rev 0) +++ Mercury2/src/Orthographic.cpp 2009-07-21 01:52:34 UTC (rev 432) @@ -0,0 +1,90 @@ +#include <Orthographic.h> +#include <GLHeaders.h> +#include <MercuryWindow.h> + +REGISTER_NODE_TYPE(Orthographic); + +Orthographic::Orthographic() +{ +} + +void Orthographic::PreRender(const MercuryMatrix& matrix) +{ + FRUSTUM = &m_frustum; + + MercuryWindow* w = MercuryWindow::GetCurrentWindow(); + + //Load the frustum into the projection + //"eye" position does not go into projection + glMatrixMode(GL_PROJECTION); + glLoadMatrix( m_frustum.GetMatrix() ); + m_frustum.GetMatrix().Print(); + glMatrixMode(GL_MODELVIEW); + + //compute the position of the eye +// EYE = MercuryVertex(0,0,0,1); //wrong +// EYE = matrix * EYE; + + VIEWMATRIX = matrix; + + //the camera sets this (the calculation here is wrong) +// MercuryVector z(0,0,-1); //look down Z by default +// LOOKAT = (matrix * z).Normalize(); + +// matrix.Print(); +// EYE.Print("Eye"); +// LOOKAT.Print("Lookat"); +// printf("******\n"); +// LOOKAT = (matrix * l).Normalize(); +// LOOKAT. +// LOOKAT.Print(); + + //Sets up the clipping frustum +// m_frustum.LookAt(EYE, LOOKAT, MercuryVertex(0,1,0)); +} + +void Orthographic::LoadFromXML(const XMLNode& node) +{ + MercuryWindow* w = MercuryWindow::GetCurrentWindow(); + + m_frustum.Ortho( StrToFloat(node.Attribute("left")), + StrToFloat(node.Attribute("right")), + StrToFloat(node.Attribute("bottom")), + StrToFloat(node.Attribute("top")), + StrToFloat(node.Attribute("near")), + StrToFloat(node.Attribute("far")) ); + + MercuryNode::LoadFromXML(node); +} + +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen * + * * + * * + * 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/Orthographic.h =================================================================== --- Mercury2/src/Orthographic.h (rev 0) +++ Mercury2/src/Orthographic.h 2009-07-21 01:52:34 UTC (rev 432) @@ -0,0 +1,56 @@ +#ifndef ORTHOGRAPHIC_H +#define ORTHOGRAPHIC_H + +#include <MercuryNode.h> +#include <MercuryMatrix.h> +#include <MercuryVertex.h> +#include <MercuryPlane.h> +#include <Frustum.h> + +class Orthographic : public MercuryNode +{ + public: + Orthographic(); + virtual void PreRender(const MercuryMatrix& matrix); + + virtual void LoadFromXML(const XMLNode& node); + + GENRTTI(Orthographic); + private: + Frustum m_frustum; +// float m_xFactor, m_yFactor; +// int m_minx, m_miny; +}; + +#endif +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen * + * * + * * + * 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. * + ***************************************************************************/ Modified: Mercury2/src/Viewport.h =================================================================== --- Mercury2/src/Viewport.h 2009-07-21 00:48:39 UTC (rev 431) +++ Mercury2/src/Viewport.h 2009-07-21 01:52:34 UTC (rev 432) @@ -7,11 +7,6 @@ #include <MercuryPlane.h> #include <Frustum.h> -extern const Frustum* FRUSTUM; -extern MercuryMatrix VIEWMATRIX; -extern MercuryVertex EYE; -extern MercuryVector LOOKAT; - class Viewport : public MercuryNode { public: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-07-25 18:32:03
|
Revision: 434 http://hgengine.svn.sourceforge.net/hgengine/?rev=434&view=rev Author: axlecrusher Date: 2009-07-25 18:31:55 +0000 (Sat, 25 Jul 2009) Log Message: ----------- fix ripple taint down Modified Paths: -------------- Mercury2/src/TransformNode.cpp Mercury2/src/TransformNode.h Modified: Mercury2/src/TransformNode.cpp =================================================================== --- Mercury2/src/TransformNode.cpp 2009-07-23 03:50:09 UTC (rev 433) +++ Mercury2/src/TransformNode.cpp 2009-07-25 18:31:55 UTC (rev 434) @@ -44,7 +44,7 @@ void TransformNode::SetTaint(bool taint) { m_tainted = taint; - RippleTaintDown(); + RippleTaintDown(this); } void TransformNode::ComputeMatrix() @@ -81,19 +81,18 @@ return MercuryMatrix::Identity(); } -void TransformNode::RippleTaintDown() +void TransformNode::RippleTaintDown(MercuryNode* node) { - if (m_tainted == true) + TransformNode* tn; + + for (MercuryNode* n = node->FirstChild(); n != NULL; n = node->NextChild(n)) { - TransformNode* tn; - std::list< MercuryNode* >::iterator i; - - for (i = m_children.begin(); i != m_children.end(); ++i ) - { - tn = TransformNode::Cast(*i); - if ( tn ) - tn->SetTaint( true ); - } + tn = TransformNode::Cast(n); + if (tn) + //stop this recursion here on this branch SetTaint will start a new taint recursion + tn->SetTaint(true); + else + RippleTaintDown( n ); } } @@ -147,7 +146,7 @@ tn = TransformNode::Cast( n ); if ( tn ) { - tn->RippleTaintDown(); + RippleTaintDown(tn); return; } n = n->Parent(); Modified: Mercury2/src/TransformNode.h =================================================================== --- Mercury2/src/TransformNode.h 2009-07-23 03:50:09 UTC (rev 433) +++ Mercury2/src/TransformNode.h 2009-07-25 18:31:55 UTC (rev 434) @@ -38,7 +38,7 @@ GENRTTI(TransformNode); private: - void RippleTaintDown(); + static void RippleTaintDown(MercuryNode* n); //use of accessor required MercuryVertex m_scale; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-07-25 18:58:50
|
Revision: 436 http://hgengine.svn.sourceforge.net/hgengine/?rev=436&view=rev Author: axlecrusher Date: 2009-07-25 18:58:42 +0000 (Sat, 25 Jul 2009) Log Message: ----------- camera and frustum go into viewmatrix Modified Paths: -------------- Mercury2/src/Camera.cpp Mercury2/src/Viewport.cpp Modified: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp 2009-07-25 18:33:03 UTC (rev 435) +++ Mercury2/src/Camera.cpp 2009-07-25 18:58:42 UTC (rev 436) @@ -32,7 +32,8 @@ r.toMatrix4( local ); local.Translate( GetPosition()*-1 ); - m_globalMatrix = local * parent; //fold in any parent transform in reverse (correct rotation) +// m_globalMatrix = local * parent; //fold in any parent transform in reverse (correct rotation) + VIEWMATRIX = local * parent; //compute camera position in world space (broken if camera is in transform node) local = MercuryMatrix::Identity(); Modified: Mercury2/src/Viewport.cpp =================================================================== --- Mercury2/src/Viewport.cpp 2009-07-25 18:33:03 UTC (rev 435) +++ Mercury2/src/Viewport.cpp 2009-07-25 18:58:42 UTC (rev 436) @@ -31,7 +31,7 @@ // EYE = MercuryVertex(0,0,0,1); //wrong // EYE = matrix * EYE; - VIEWMATRIX = matrix; +// VIEWMATRIX = matrix; //the camera sets this (the calculation here is wrong) // MercuryVector z(0,0,-1); //look down Z by default This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-07-31 00:59:21
|
Revision: 443 http://hgengine.svn.sourceforge.net/hgengine/?rev=443&view=rev Author: axlecrusher Date: 2009-07-31 00:59:08 +0000 (Fri, 31 Jul 2009) Log Message: ----------- allow other color types besides RGBA Modified Paths: -------------- Mercury2/src/GLHelpers.cpp Mercury2/src/GLHelpers.h Mercury2/src/MercuryFBO.cpp Mercury2/src/Orthographic.cpp Mercury2/src/RawImageData.h Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/src/GLHelpers.cpp =================================================================== --- Mercury2/src/GLHelpers.cpp 2009-07-31 00:55:58 UTC (rev 442) +++ Mercury2/src/GLHelpers.cpp 2009-07-31 00:59:08 UTC (rev 443) @@ -78,6 +78,30 @@ return MercuryVertex( (float)mouseX, (float)mouseY, (float)mouseZ ); } +GLenum ToGLColorType(ColorByteType cbt) +{ + switch (cbt) + { + case WHITE: + return GL_LUMINANCE; + case WHITE_ALPHA: + return GL_LUMINANCE_ALPHA; + case RGB: + return GL_RGB; + case RGBA: + return GL_RGBA; + case RGB16: + return GL_RGBA16; + case RGBA16: + return GL_RGBA16; + break; + default: + printf( "Unsupported color byte type (%d)\n", cbt ); + return GL_RGB; + } + +} + /**************************************************************************** * Copyright (C) 2009 by Joshua Allen * * * Modified: Mercury2/src/GLHelpers.h =================================================================== --- Mercury2/src/GLHelpers.h 2009-07-31 00:55:58 UTC (rev 442) +++ Mercury2/src/GLHelpers.h 2009-07-31 00:59:08 UTC (rev 443) @@ -3,10 +3,13 @@ #include <MercuryMatrix.h> #include <MercuryVertex.h> +#include <RawImageData.h> + MString GlError2String(uint32_t e); void glLoadMatrix(const MercuryMatrix& m); MercuryMatrix glGetMatrix(int m); MercuryVertex pointFromScreenLoc(int screen_x, int screen_y); +GLenum ToGLColorType(ColorByteType cbt); /**************************************************************************** * Copyright (C) 2009 by Joshua Allen * Modified: Mercury2/src/MercuryFBO.cpp =================================================================== --- Mercury2/src/MercuryFBO.cpp 2009-07-31 00:55:58 UTC (rev 442) +++ Mercury2/src/MercuryFBO.cpp 2009-07-31 00:59:08 UTC (rev 443) @@ -46,7 +46,7 @@ { MString n = ssprintf("%s_%d", m_name.c_str(), i); m_textures[i] = Texture::LoadDynamicTexture(n); - m_textures[i]->MakeDynamic(m_width, m_height,n); + m_textures[i]->MakeDynamic(m_width, m_height, RGBA, n); } } @@ -90,7 +90,7 @@ for (uint8_t i = 0; i < m_numTextures; ++i) { MString n = ssprintf("%s_%d", m_name.c_str(), i); - m_textures[i]->MakeDynamic(m_width, m_height,n); + m_textures[i]->MakeDynamic(m_width, m_height, RGBA, n); } } Bind(); Modified: Mercury2/src/Orthographic.cpp =================================================================== --- Mercury2/src/Orthographic.cpp 2009-07-31 00:55:58 UTC (rev 442) +++ Mercury2/src/Orthographic.cpp 2009-07-31 00:59:08 UTC (rev 443) @@ -36,8 +36,6 @@ void Orthographic::LoadFromXML(const XMLNode& node) { - MercuryWindow* w = MercuryWindow::GetCurrentWindow(); - m_frustum.Ortho( StrToFloat(node.Attribute("left")), StrToFloat(node.Attribute("right")), StrToFloat(node.Attribute("bottom")), Modified: Mercury2/src/RawImageData.h =================================================================== --- Mercury2/src/RawImageData.h 2009-07-31 00:55:58 UTC (rev 442) +++ Mercury2/src/RawImageData.h 2009-07-31 00:59:08 UTC (rev 443) @@ -6,7 +6,9 @@ WHITE, WHITE_ALPHA, RGB, - RGBA + RGBA, + RGB16, + RGBA16, }; class RawImageData Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-07-31 00:55:58 UTC (rev 442) +++ Mercury2/src/Texture.cpp 2009-07-31 00:59:08 UTC (rev 443) @@ -49,28 +49,8 @@ if ( !m_textureID ) glGenTextures(1, &m_textureID); // m_raw = raw; - int ByteType; + GLenum byteType = ToGLColorType( m_raw->m_ColorByteType ); - switch (m_raw->m_ColorByteType) - { - case WHITE: - ByteType = GL_LUMINANCE; - break; - case WHITE_ALPHA: - ByteType = GL_LUMINANCE_ALPHA; - break; - case RGB: - ByteType = GL_RGB; - break; - case RGBA: - ByteType = GL_RGBA; - break; - default: - printf( "Unsupported byte type (%d) in Texture::LoadFromRaw\n", m_raw->m_ColorByteType ); - ByteType = GL_RGB; - break; - } - glBindTexture(GL_TEXTURE_2D, m_textureID); /* glTexImage2D(GL_TEXTURE_2D, @@ -83,7 +63,7 @@ GL_UNSIGNED_BYTE, m_raw->m_data); */ - gluBuild2DMipmaps( GL_TEXTURE_2D, ByteType, m_raw->m_width, m_raw->m_height, ByteType, GL_UNSIGNED_BYTE, m_raw->m_data ); + gluBuild2DMipmaps( GL_TEXTURE_2D, byteType, m_raw->m_width, m_raw->m_height, byteType, GL_UNSIGNED_BYTE, m_raw->m_data ); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); @@ -94,7 +74,7 @@ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); // gluBuild2DMipmaps( GL_TEXTURE_2D, 3, m_raw->m_width, m_raw->m_height, ByteType, GL_UNSIGNED_BYTE, m_raw->m_data ); - + SAFE_DELETE(m_raw); }; void Texture::Render(const MercuryNode* node) @@ -121,7 +101,7 @@ MString file = node.Attribute("file"); if ( dynamic ) - MakeDynamic( 0, 0, file ); + MakeDynamic( 0, 0, RGBA, file ); else LoadImagePath( file ); } @@ -188,7 +168,7 @@ m_raw = raw; } -void Texture::MakeDynamic(uint16_t width, uint16_t height, const MString& name) +void Texture::MakeDynamic(uint16_t width, uint16_t height, ColorByteType cbt, const MString& name) { // Clean(); @@ -200,7 +180,7 @@ if (m_textureID == 0) glGenTextures( 1, &m_textureID ); glBindTexture( GL_TEXTURE_2D, m_textureID ); - glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, width, height, 0 ); + glCopyTexImage2D( GL_TEXTURE_2D, 0, ToGLColorType(cbt), 0, 0, width, height, 0 ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glBindTexture( GL_TEXTURE_2D, 0 ); Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2009-07-31 00:55:58 UTC (rev 442) +++ Mercury2/src/Texture.h 2009-07-31 00:59:08 UTC (rev 443) @@ -25,9 +25,8 @@ inline static uint32_t ReadAndResetBindCount() { uint32_t t = m_textureBinds; m_textureBinds = 0; return t; } inline uint32_t TextureID() const { return m_textureID; } - void MakeDynamic(uint16_t width, uint16_t height, const MString& name); + void MakeDynamic(uint16_t width, uint16_t height, ColorByteType cbt, const MString& name); - static Texture* Generate(); static MAutoPtr< Texture > LoadFromFile(const MString& path); static MAutoPtr< Texture > LoadDynamicTexture(const MString& name); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-08-01 02:44:42
|
Revision: 445 http://hgengine.svn.sourceforge.net/hgengine/?rev=445&view=rev Author: axlecrusher Date: 2009-08-01 02:44:35 +0000 (Sat, 01 Aug 2009) Log Message: ----------- int4 (ivec4) Modified Paths: -------------- Mercury2/src/Shader.cpp Mercury2/src/Shader.h Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-08-01 02:43:14 UTC (rev 444) +++ Mercury2/src/Shader.cpp 2009-08-01 02:44:35 UTC (rev 445) @@ -485,10 +485,14 @@ break; case ShaderAttribute::TYPE_FLOAT: case ShaderAttribute::TYPE_FLOATV4: - glUniform4fvARB( location, 4, &x.value.fFloatV4[0] ); + glUniform4fvARB( location, 1, &x.value.fFloatV4[0] ); break; case ShaderAttribute::TYPE_MATRIX: glUniformMatrix4fvARB(location, 1, 1, x.value.matrix); //transpase too + break; + case ShaderAttribute::TYPE_INT4: + glUniform4ivARB( location, 1, x.value.iInts ); + break; }; GLERRORCHECK; } Modified: Mercury2/src/Shader.h =================================================================== --- Mercury2/src/Shader.h 2009-08-01 02:43:14 UTC (rev 444) +++ Mercury2/src/Shader.h 2009-08-01 02:44:35 UTC (rev 445) @@ -17,6 +17,7 @@ enum ShaderAttributeTyp { TYPE_INT, ///Synonomous to 'int' when passing into a shader + TYPE_INT4, ///Synonomous to 'ivec4' 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 @@ -31,6 +32,7 @@ float fFloat; ///Synonomous to 'float' float fFloatV4[4]; ///Synonomous to 'vec4' const float* matrix; ///Synonomous to 'mat4' + int iInts[4]; ///Synonomous to 'int4' } value; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-08-01 02:45:31
|
Revision: 446 http://hgengine.svn.sourceforge.net/hgengine/?rev=446&view=rev Author: axlecrusher Date: 2009-08-01 02:45:23 +0000 (Sat, 01 Aug 2009) Log Message: ----------- string to color byte type Modified Paths: -------------- Mercury2/src/RawImageData.cpp Mercury2/src/RawImageData.h Modified: Mercury2/src/RawImageData.cpp =================================================================== --- Mercury2/src/RawImageData.cpp 2009-08-01 02:44:35 UTC (rev 445) +++ Mercury2/src/RawImageData.cpp 2009-08-01 02:45:23 UTC (rev 446) @@ -11,6 +11,20 @@ SAFE_DELETE_ARRAY(m_data); } +ColorByteType ToColorByteType(const MString& s) +{ + if (s == "RGB") + return RGB; + else if (s == "RGBA") + return RGBA; + else if (s == "RGB16") + return RGB16; + else if (s == "RGBA16") + return RGBA16; + + return RGB; +} + /**************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/RawImageData.h =================================================================== --- Mercury2/src/RawImageData.h 2009-08-01 02:44:35 UTC (rev 445) +++ Mercury2/src/RawImageData.h 2009-08-01 02:45:23 UTC (rev 446) @@ -1,6 +1,8 @@ #ifndef RAWIMAGEDATA_H #define RAWIMAGEDATA_H +#include <MercuryUtil.h> + enum ColorByteType { WHITE, @@ -11,6 +13,8 @@ RGBA16, }; +ColorByteType ToColorByteType(const MString& s); + class RawImageData { public: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-08-01 02:46:11
|
Revision: 447 http://hgengine.svn.sourceforge.net/hgengine/?rev=447&view=rev Author: axlecrusher Date: 2009-08-01 02:46:05 +0000 (Sat, 01 Aug 2009) Log Message: ----------- fix and update vbos Modified Paths: -------------- Mercury2/src/MercuryFBO.cpp Mercury2/src/MercuryFBO.h Modified: Mercury2/src/MercuryFBO.cpp =================================================================== --- Mercury2/src/MercuryFBO.cpp 2009-08-01 02:45:23 UTC (rev 446) +++ Mercury2/src/MercuryFBO.cpp 2009-08-01 02:46:05 UTC (rev 447) @@ -8,7 +8,11 @@ MercuryFBO::MercuryFBO() :m_fboID(0), m_depthBufferID(0), m_initiated(false), m_useDepth(false),m_useScreenSize(false), m_width(0),m_height(0), m_numTextures(0) { - for (uint8_t i = 0; i < 4; ++i) m_textures[i] = NULL; + for (uint8_t i = 0; i < 4; ++i) + { + m_textures[i] = NULL; + m_cbt[i] = RGB; + } } MercuryFBO::~MercuryFBO() @@ -46,7 +50,7 @@ { MString n = ssprintf("%s_%d", m_name.c_str(), i); m_textures[i] = Texture::LoadDynamicTexture(n); - m_textures[i]->MakeDynamic(m_width, m_height, RGBA, n); + m_textures[i]->MakeDynamic(m_width, m_height, m_cbt[i], n); } } @@ -76,7 +80,8 @@ GLERRORCHECK; } */ -void MercuryFBO::PreRender(const MercuryMatrix& matrix) + +void MercuryFBO::Render(const MercuryMatrix& matrix) { if ( !m_initiated ) Setup(); @@ -90,19 +95,14 @@ for (uint8_t i = 0; i < m_numTextures; ++i) { MString n = ssprintf("%s_%d", m_name.c_str(), i); - m_textures[i]->MakeDynamic(m_width, m_height, RGBA, n); + m_textures[i]->MakeDynamic(m_width, m_height, m_cbt[i], n); } } Bind(); CHECKFBO; //Incomplete FBO GLERRORCHECK; } - - MercuryNode::PreRender(matrix); -} - -void MercuryFBO::Render(const MercuryMatrix& matrix) -{ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fboID); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GLERRORCHECK; @@ -160,6 +160,13 @@ if ( !node.Attribute("usescreensize").empty() ) m_useScreenSize = node.Attribute("usescreensize") == "true"?true:false; + for (uint8_t i = 0; i < m_numTextures; ++i) + { + MString aname = ssprintf("colorbyte%d", i); + if ( !node.Attribute(aname).empty() ) + m_cbt[i] = ToColorByteType( ToUpper( node.Attribute(aname) ) ); + } + MercuryNode::LoadFromXML(node); } Modified: Mercury2/src/MercuryFBO.h =================================================================== --- Mercury2/src/MercuryFBO.h 2009-08-01 02:45:23 UTC (rev 446) +++ Mercury2/src/MercuryFBO.h 2009-08-01 02:46:05 UTC (rev 447) @@ -3,6 +3,7 @@ #include <MercuryNode.h> #include <Texture.h> +#include <RawImageData.h> class MercuryFBO : public MercuryNode { @@ -10,7 +11,6 @@ MercuryFBO(); virtual ~MercuryFBO(); - virtual void PreRender(const MercuryMatrix& matrix); virtual void Render(const MercuryMatrix& matrix); virtual void PostRender(const MercuryMatrix& matrix); @@ -19,7 +19,7 @@ inline void SetWidth(uint16_t width) { m_width = width; } inline void SetHeight(uint16_t height) { m_height = height; } inline void SetUseDepth(bool toggle) { m_useDepth = toggle; } - inline void SetNumTextures(uint8_t x) { m_numTextures = x; } + inline void SetNumTextures(uint8_t x) { m_numTextures = MIN<uint8_t>(x,4); } GENRTTI(MercuryFBO); @@ -37,6 +37,7 @@ // uint32_t m_textureID[4]; MAutoPtr< Texture > m_textures[4]; uint8_t m_numTextures; + ColorByteType m_cbt[4]; // static uint32_t m_lastRendered; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-08-02 02:21:00
|
Revision: 451 http://hgengine.svn.sourceforge.net/hgengine/?rev=451&view=rev Author: axlecrusher Date: 2009-08-02 02:20:50 +0000 (Sun, 02 Aug 2009) Log Message: ----------- more fixes and uniforms for shaders Modified Paths: -------------- Mercury2/src/Camera.cpp Mercury2/src/GLHelpers.cpp Mercury2/src/MercuryFBO.cpp Mercury2/src/RawImageData.cpp Mercury2/src/RawImageData.h Modified: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp 2009-08-01 17:48:06 UTC (rev 450) +++ Mercury2/src/Camera.cpp 2009-08-02 02:20:50 UTC (rev 451) @@ -3,6 +3,8 @@ #include <MercuryInput.h> #include <Viewport.h> +#include <Shader.h> + REGISTER_NODE_TYPE(CameraNode); CameraNode::CameraNode() @@ -37,6 +39,14 @@ m_lookAt = m_lookAt.Rotate( r ); m_lookAt.NormalizeSelf(); LOOKAT = m_lookAt; + + ShaderAttribute sa; + sa.type = ShaderAttribute::TYPE_FLOATV4; + sa.value.fFloatV4[0] = LOOKAT.GetX(); + sa.value.fFloatV4[1] = LOOKAT.GetY(); + sa.value.fFloatV4[2] = LOOKAT.GetZ(); + sa.value.fFloatV4[3] = 0; + Shader::SetAttribute("HG_LookVector", sa); r.W() *= -1; //reverse angle for camera Modified: Mercury2/src/GLHelpers.cpp =================================================================== --- Mercury2/src/GLHelpers.cpp 2009-08-01 17:48:06 UTC (rev 450) +++ Mercury2/src/GLHelpers.cpp 2009-08-02 02:20:50 UTC (rev 451) @@ -91,10 +91,14 @@ case RGBA: return GL_RGBA; case RGB16: - return GL_RGBA16; + return GL_RGB16; case RGBA16: return GL_RGBA16; - break; + case RGBA16F: + return GL_RGBA16F_ARB; + case RGBA32F: + printf( "GL_RGBA32F_ARB unsupported using GL_RGBA16F_ARB\n" ); + return GL_RGBA16F_ARB; default: printf( "Unsupported color byte type (%d)\n", cbt ); return GL_RGB; Modified: Mercury2/src/MercuryFBO.cpp =================================================================== --- Mercury2/src/MercuryFBO.cpp 2009-08-01 17:48:06 UTC (rev 450) +++ Mercury2/src/MercuryFBO.cpp 2009-08-02 02:20:50 UTC (rev 451) @@ -11,7 +11,7 @@ for (uint8_t i = 0; i < 4; ++i) { m_textures[i] = NULL; - m_cbt[i] = RGB; + m_cbt[i] = RGBA; } } Modified: Mercury2/src/RawImageData.cpp =================================================================== --- Mercury2/src/RawImageData.cpp 2009-08-01 17:48:06 UTC (rev 450) +++ Mercury2/src/RawImageData.cpp 2009-08-02 02:20:50 UTC (rev 451) @@ -21,7 +21,11 @@ return RGB16; else if (s == "RGBA16") return RGBA16; - + else if (s == "RGBA16F") + return RGBA16F; + else if (s == "RGBA32F") + return RGBA32F; + printf("Color Byte Type %s unknown\n", s.c_str()); return RGB; } Modified: Mercury2/src/RawImageData.h =================================================================== --- Mercury2/src/RawImageData.h 2009-08-01 17:48:06 UTC (rev 450) +++ Mercury2/src/RawImageData.h 2009-08-02 02:20:50 UTC (rev 451) @@ -11,6 +11,8 @@ RGBA, RGB16, RGBA16, + RGBA16F, + RGBA32F }; ColorByteType ToColorByteType(const MString& s); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-08-05 00:38:05
|
Revision: 453 http://hgengine.svn.sourceforge.net/hgengine/?rev=453&view=rev Author: axlecrusher Date: 2009-08-05 00:37:56 +0000 (Wed, 05 Aug 2009) Log Message: ----------- updates for deferred shading Modified Paths: -------------- Mercury2/src/BoundingBox.cpp Mercury2/src/BoundingBox.h Mercury2/src/FullscreenQuad.h Mercury2/src/GLHelpers.h Mercury2/src/HGMDLModel.cpp Mercury2/src/HGMDLModel.h Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryFBO.cpp Mercury2/src/MercuryNode.cpp Mercury2/src/Quad.cpp Mercury2/src/RenderGraph.cpp Mercury2/src/RenderGraph.h Mercury2/src/Texture.cpp Modified: Mercury2/src/BoundingBox.cpp =================================================================== --- Mercury2/src/BoundingBox.cpp 2009-08-05 00:34:44 UTC (rev 452) +++ Mercury2/src/BoundingBox.cpp 2009-08-05 00:37:56 UTC (rev 453) @@ -28,14 +28,14 @@ } BoundingBox::BoundingBox(const MercuryVertex& center, const MercuryVertex& extend) - :m_center(center), m_extend(extend) + :BoundingVolume(), m_center(center), m_extend(extend) { PopulateVertices(); ComputeNormals(); } BoundingBox::BoundingBox(const BoundingBox& bb) - :m_center(bb.m_center), m_extend(bb.m_extend) + :BoundingVolume(), m_center(bb.m_center), m_extend(bb.m_extend) { PopulateVertices(); for (uint8_t i = 0; i < 3; ++i) @@ -172,7 +172,30 @@ glEndQueryARB(GL_SAMPLES_PASSED_ARB); // glGetQueryObjectuivARB(q, GL_QUERY_RESULT_ARB, &samples); + glPopMatrix(); glPopAttrib( ); +} + +void BoundingBox::RenderFaces() const +{ + const float* center = GetCenter(); + const float* extend = GetExtend(); + + glPushMatrix(); + glTranslatef(center[0], center[1], center[2]); + glScalef(extend[0],extend[1],extend[2]); + + if (m_vboID == 0) InitVBO(); + +// if ( MercuryVBO::m_lastVBOrendered != &m_vboID ) + { + MercuryVBO::m_lastVBOrendered = &m_vboID; + glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vboID); // once + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); // once + glVertexPointer(3, GL_FLOAT, 0, 0); // once + } + + glDrawArrays(GL_QUADS, 0, 24); glPopMatrix(); } @@ -275,10 +298,10 @@ uint32_t i = 0; //back + m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; + m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; - m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; - m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; - m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; //front m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; @@ -293,10 +316,10 @@ m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; //right + m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; - m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; - m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; - m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; //top m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; @@ -305,10 +328,10 @@ m_vertexData[i++] = 1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; //bottom + m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; + m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; + m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; - m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; - m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = 1.0f; - m_vertexData[i++] = 1.0f; m_vertexData[i++] = -1.0f; m_vertexData[i++] = -1.0f; } void BoundingBox::InitVBO() Modified: Mercury2/src/BoundingBox.h =================================================================== --- Mercury2/src/BoundingBox.h 2009-08-05 00:34:44 UTC (rev 452) +++ Mercury2/src/BoundingBox.h 2009-08-05 00:37:56 UTC (rev 453) @@ -79,6 +79,7 @@ const MercuryVector& Normal(uint8_t i) const { return m_normals[i]; } virtual void Render(); + void RenderFaces() const; virtual BoundingVolume* SpawnClone() const; virtual bool Clip( const MercuryPlane& p ); Modified: Mercury2/src/FullscreenQuad.h =================================================================== --- Mercury2/src/FullscreenQuad.h 2009-08-05 00:34:44 UTC (rev 452) +++ Mercury2/src/FullscreenQuad.h 2009-08-05 00:37:56 UTC (rev 453) @@ -1,5 +1,9 @@ +#ifndef FULLSCREENQUAD_H +#define FULLSCREENQUAD_H + #include <Quad.h> + class FullscreenQuad : public Quad { public: @@ -13,6 +17,8 @@ MercuryMatrix m_matrix; }; +#endif + /**************************************************************************** * Copyright (C) 2009 by Joshua Allen * * * Modified: Mercury2/src/GLHelpers.h =================================================================== --- Mercury2/src/GLHelpers.h 2009-08-05 00:34:44 UTC (rev 452) +++ Mercury2/src/GLHelpers.h 2009-08-05 00:37:56 UTC (rev 453) @@ -7,7 +7,7 @@ MString GlError2String(uint32_t e); void glLoadMatrix(const MercuryMatrix& m); -MercuryMatrix glGetMatrix(int m); +MercuryMatrix glGetMatrix(GLenum m); MercuryVertex pointFromScreenLoc(int screen_x, int screen_y); GLenum ToGLColorType(ColorByteType cbt); Modified: Mercury2/src/HGMDLModel.cpp =================================================================== --- Mercury2/src/HGMDLModel.cpp 2009-08-05 00:34:44 UTC (rev 452) +++ Mercury2/src/HGMDLModel.cpp 2009-08-05 00:37:56 UTC (rev 453) @@ -19,6 +19,8 @@ { MString path = node.Attribute("file"); LoadHGMDL( path ); + + MercuryAsset::LoadFromXML( node ); } void HGMDLModel::LoadModel(MercuryFile* hgmdl, HGMDLModel* model) @@ -58,11 +60,16 @@ } } -void HGMDLModel::DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix) +bool HGMDLModel::DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix) { + bool culled = false; if ( GetLoadState() != LOADING ) + { + culled = true; for(uint16_t i = 0; i < m_meshes.size(); ++i) - m_meshes[i]->DoCullingTests(n, matrix); + culled = culled && m_meshes[i]->DoCullingTests(n, matrix); + } + return culled; } void HGMDLModel::PreRender(const MercuryNode* node) Modified: Mercury2/src/HGMDLModel.h =================================================================== --- Mercury2/src/HGMDLModel.h 2009-08-05 00:34:44 UTC (rev 452) +++ Mercury2/src/HGMDLModel.h 2009-08-05 00:37:56 UTC (rev 453) @@ -19,7 +19,7 @@ static HGMDLModel* Generate(); - virtual void DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix); + virtual bool DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix); virtual void PreRender(const MercuryNode* node); virtual void Render(const MercuryNode* node); Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-08-05 00:34:44 UTC (rev 452) +++ Mercury2/src/MercuryAsset.cpp 2009-08-05 00:37:56 UTC (rev 453) @@ -39,14 +39,16 @@ SetLoadState( LOADED ); } -void MercuryAsset::DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix) +bool MercuryAsset::DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix) { + bool culled = false; if ( m_boundingVolume ) { - n->SetCulled( m_boundingVolume->DoFrustumTest(matrix) ); - if ( !n->IsCulled() && DOOCCLUSIONCULL) + culled = m_boundingVolume->DoFrustumTest(matrix); + if ( !culled && DOOCCLUSIONCULL) m_boundingVolume->DoOcclusionTest( n->GetOcclusionResult() ); } + return culled; } void MercuryAsset::PreRender(const MercuryNode* node) @@ -62,6 +64,17 @@ */ } +void MercuryAsset::LoadFromXML(const XMLNode& node) +{ + + printf("asset xml\n"); + if ( !node.Attribute("nocull").empty() ) + { + printf("NO CULL!!!!!!!!!!\n"); + SetExcludeFromCull( node.Attribute("nocull")=="true" ); + } +} + void MercuryAsset::DrawAxes() { glBegin(GL_LINES); Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-08-05 00:34:44 UTC (rev 452) +++ Mercury2/src/MercuryAsset.h 2009-08-05 00:37:56 UTC (rev 453) @@ -42,7 +42,7 @@ virtual void PostRender(const MercuryNode* node) {}; ///Loads an asset from an XMLAsset representing itself - virtual void LoadFromXML(const XMLNode& node) {}; + virtual void LoadFromXML(const XMLNode& node); virtual void LoadedCallback(); //thread safe @@ -51,8 +51,12 @@ inline BoundingVolume* GetBoundingVolume() const { return m_boundingVolume; } inline const MString& Path() const { return m_path; } - virtual void DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix); + ///Retuns true if culled, also will initiate occlusion test + virtual bool DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix); void DrawAxes(); + + inline void SetExcludeFromCull(bool t) { m_excludeFromCull = t; } + inline bool ExcludeFromCull() const { return m_excludeFromCull; } protected: void SetLoadState(LoadState ls); //thread safe LoadState GetLoadState(); //thread safe @@ -63,6 +67,7 @@ private: LoadState m_loadState; MSemaphore m_lock; + bool m_excludeFromCull; }; class LoaderThreadData Modified: Mercury2/src/MercuryFBO.cpp =================================================================== --- Mercury2/src/MercuryFBO.cpp 2009-08-05 00:34:44 UTC (rev 452) +++ Mercury2/src/MercuryFBO.cpp 2009-08-05 00:37:56 UTC (rev 453) @@ -3,6 +3,8 @@ #include <MercuryWindow.h> #include <assert.h> +#include <RenderGraph.h> + REGISTER_NODE_TYPE(MercuryFBO); MercuryFBO::MercuryFBO() @@ -134,8 +136,10 @@ // glActiveTextureARB( GL_TEXTURE0_ARB + i ); // glDisable( GL_TEXTURE_2D ); // } +// CURRENTRENDERGRAPH->DoDifferedLightPass(); glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); // glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, 0 ); +// CURRENTRENDERGRAPH->DoDifferedLightPass(); CHECKFBO; GLERRORCHECK; Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-08-05 00:34:44 UTC (rev 452) +++ Mercury2/src/MercuryNode.cpp 2009-08-05 00:37:56 UTC (rev 453) @@ -220,6 +220,7 @@ MAutoPtr< MercuryAsset > asset( AssetFactory::GetInstance().Generate( child.Attribute("type"), key ) ); if ( asset.IsValid() ) { + printf("new asset %s\n", child.Attribute("type").c_str()); asset->LoadFromXML( child ); this->AddAsset( asset ); asset->Init( this ); @@ -231,11 +232,15 @@ void MercuryNode::PreRender(const MercuryMatrix& matrix) { + SetCulled( false ); + bool culled = true; list< MercuryAsset* >::iterator i; for (i = m_prerender.begin(); i != m_prerender.end(); ++i ) { - (*i)->DoCullingTests( this, matrix ); + if ( !(*i)->ExcludeFromCull() ) + culled = culled && (*i)->DoCullingTests( this, matrix ); (*i)->PreRender(this); + SetCulled( culled ); } } Modified: Mercury2/src/Quad.cpp =================================================================== --- Mercury2/src/Quad.cpp 2009-08-05 00:34:44 UTC (rev 452) +++ Mercury2/src/Quad.cpp 2009-08-05 00:37:56 UTC (rev 453) @@ -36,6 +36,8 @@ m_indexData[1] = 1; m_indexData[3] = m_indexData[2] = 2; m_indexData[4] = 3; + + SetExcludeFromCull( true ); } Quad::~Quad() Modified: Mercury2/src/RenderGraph.cpp =================================================================== --- Mercury2/src/RenderGraph.cpp 2009-08-05 00:34:44 UTC (rev 452) +++ Mercury2/src/RenderGraph.cpp 2009-08-05 00:37:56 UTC (rev 453) @@ -104,6 +104,20 @@ } } +void RenderGraph::AddDifferedLight( Light* l ) +{ + m_lights.push_back( l ); +} + +void RenderGraph::DoDifferedLightPass() +{ + std::list< Light* >::iterator i; + for (i = m_lights.begin();i != m_lights.end(); ++i) + (*i)->DifferedRender(); + + m_lights.clear(); +} + StoreRenderState::StoreRenderState() :Node(NULL) { Modified: Mercury2/src/RenderGraph.h =================================================================== --- Mercury2/src/RenderGraph.h 2009-08-05 00:34:44 UTC (rev 452) +++ Mercury2/src/RenderGraph.h 2009-08-05 00:37:56 UTC (rev 453) @@ -5,6 +5,8 @@ //#include <RenderableNode.h> #include <PriorityQueue.h> +#include <Light.h> + class RenderGraphEntry { friend class RenderGraph; @@ -49,12 +51,16 @@ void AddAlphaNode( MercuryNode* node ); void RenderAlpha(); + + void AddDifferedLight( Light* l ); + void DoDifferedLightPass(); private: void Build( MercuryNode* node, RenderGraphEntry& entry ); RenderGraphEntry m_root; //nodes that use alpha, ordered from farthest to nearest from the camera PriorityQueue<float, StoreRenderState > m_alphaNodesQueue; + std::list< Light* > m_lights; }; extern RenderGraph* CURRENTRENDERGRAPH; Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-08-05 00:34:44 UTC (rev 452) +++ Mercury2/src/Texture.cpp 2009-08-05 00:37:56 UTC (rev 453) @@ -18,6 +18,8 @@ m_initTextureSuccess = true; m_numActiveTextures = 0; } + + SetExcludeFromCull( true ); } Texture::~Texture() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-08-05 00:44:15
|
Revision: 454 http://hgengine.svn.sourceforge.net/hgengine/?rev=454&view=rev Author: axlecrusher Date: 2009-08-05 00:44:07 +0000 (Wed, 05 Aug 2009) Log Message: ----------- lights Added Paths: ----------- Mercury2/src/Light.cpp Mercury2/src/Light.h Mercury2/src/RenderDifferedLights.cpp Mercury2/src/RenderDifferedLights.h Added: Mercury2/src/Light.cpp =================================================================== --- Mercury2/src/Light.cpp (rev 0) +++ Mercury2/src/Light.cpp 2009-08-05 00:44:07 UTC (rev 454) @@ -0,0 +1,159 @@ +#include <Light.h> +#include <BoundingBox.h> +#include <MercuryNode.h> + +#include <RenderGraph.h> +#include <GLHeaders.h> + +#include <Shader.h> + +REGISTER_ASSET_TYPE(Light); + +Light::Light() + :MercuryAsset() +{ + m_atten[0] = m_atten[1] = m_atten[2] = 0.0f; + m_radius = 1.0f; + m_fullscreen = false; +} + +Light::~Light() +{ +} + +void Light::Render(const MercuryNode* node) +{ + m_worldPosition = glGetMatrix(GL_MODELVIEW_MATRIX); + m_worldPosition2 = node->FindGlobalMatrix(); + CURRENTRENDERGRAPH->AddDifferedLight( this ); + m_parent = node; +} + +void Light::LoadFromXML(const XMLNode& node) +{ + if ( !node.Attribute("atten").empty() ) + StrTo3Float(node.Attribute("atten"), m_atten); + + if ( !node.Attribute("fullscreen").empty() ) + m_fullscreen = node.Attribute("fullscreen")=="true"?true:false; + + ComputeRadius(); + + MercuryAsset::LoadFromXML( node ); +} + +void Light::StrTo3Float(const MString& s, float* a) +{ + sscanf(s.c_str(), "%f,%f,%f", &a[0], &a[1], &a[2]); +} + +Light* Light::Generate() +{ + return new Light(); +} + +void Light::ComputeRadius() +{ + //300 ensures that RGB of 255 reaches 0 + //at 50, 255 is about 5. Close enough for me + const float maxDenom = 50;//300; + float a = m_atten[2]; //quadratic + float b = m_atten[1]; //linear + float c = m_atten[0]; //constant + float d = 0; + + if ((a == 0)&&(b == 0)) + { + d = 1000.0; + } + else if (a == 0) + { + d = (maxDenom - c)/b; + } + else if (b == 0) + { + d = SQRT((maxDenom - c)/a); + } + else + { + //reciprocal of the quadratic equation + float bottom = 2*a; + float s = SQRT((b*b)-(4*a*c)); + float x1 = ((-b) - s)/bottom; + float x2 = ((-b) + s)/bottom; + d = MAX<float>(x1,x2); + } + + m_radius = Clamp<float>(0.0f, 1000.0f, d); + + SAFE_DELETE( m_boundingVolume ); + m_boundingVolume = new BoundingBox(MercuryVertex(0,0,0), MercuryVertex(m_radius,m_radius,m_radius) ); +} + +void Light::DifferedRender() +{ + glLoadMatrix( m_worldPosition ); + if ( !m_boundingVolume ) return; + + BoundingBox* bb = (BoundingBox*)m_boundingVolume; +// bb->Render(); + + MercuryVertex p(0,0,0,1); + p = m_worldPosition2 * p; + +// p.Print(); + + ShaderAttribute sa; + sa.type = ShaderAttribute::TYPE_FLOATV4; + sa.value.fFloatV4[0] = p.GetX(); + sa.value.fFloatV4[1] = p.GetY(); + sa.value.fFloatV4[2] = p.GetZ(); + Shader::SetAttribute("HG_LightPos", sa); + + sa.value.fFloatV4[0] = m_atten[0]; + sa.value.fFloatV4[1] = m_atten[1]; + sa.value.fFloatV4[2] = m_atten[2]; + sa.value.fFloatV4[3] = m_radius; + Shader::SetAttribute("HG_LightAtten", sa); + + if (m_fullscreen) + { + glCullFace(GL_BACK); + m_fullScreenQuad.Render( m_parent ); + glCullFace(GL_FRONT); + } + else + bb->RenderFaces(); +} + +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen * + * * + * * + * 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/Light.h =================================================================== --- Mercury2/src/Light.h (rev 0) +++ Mercury2/src/Light.h 2009-08-05 00:44:07 UTC (rev 454) @@ -0,0 +1,75 @@ +#include <MercuryAsset.h> +#include <FullscreenQuad.h> + +#ifndef MLIGHT_H +#define MLIGHT_H + +class Light : public MercuryAsset +{ + public: + Light(); + virtual ~Light(); + +// virtual void Init(MercuryNode* node); + + /** PreRender should be called before any real openGL render commands. + It is used to handles things like frustum culling, and occlusion culling. + Currently only occlusion culling test is run here.**/ +// virtual void PreRender(const MercuryNode* node); + + virtual void Render(const MercuryNode* node); +// virtual void PostRender(const MercuryNode* node) {}; + + ///Loads an asset from an XMLAsset representing itself + virtual void LoadFromXML(const XMLNode& node); + + static Light* Generate(); + + void DifferedRender(); + private: + void StrTo3Float(const MString& s, float* a); + void ComputeRadius(); + + float m_atten[3]; + float m_radius; + MercuryMatrix m_worldPosition; + MercuryMatrix m_worldPosition2; + + bool m_fullscreen; + const MercuryNode* m_parent; + + FullscreenQuad m_fullScreenQuad; +}; + +#endif +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen * + * * + * * + * 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/RenderDifferedLights.cpp =================================================================== --- Mercury2/src/RenderDifferedLights.cpp (rev 0) +++ Mercury2/src/RenderDifferedLights.cpp 2009-08-05 00:44:07 UTC (rev 454) @@ -0,0 +1,81 @@ +#include <RenderDifferedLights.h> +#include <RenderGraph.h> + +#include <Texture.h> +#include <GLHeaders.h> + +REGISTER_ASSET_TYPE(RenderDifferedLights); +#define BUFFER_OFFSET(i) ((char*)NULL + (i)) + +RenderDifferedLights::RenderDifferedLights() +{ +} + +RenderDifferedLights::~RenderDifferedLights() +{ +} + +void RenderDifferedLights::Render(const MercuryNode* node) +{ + uint8_t numTextures = Texture::NumberActiveTextures(); + uint16_t stride = sizeof(float)*8; + + //apply all the active Textures + for (uint8_t i = 0; i < numTextures; ++i) + { + glActiveTexture( GL_TEXTURE0+i ); + glClientActiveTextureARB(GL_TEXTURE0+i); + glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*0)); + } + + glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_POLYGON_BIT); +// glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + + glDisable(GL_DEPTH_TEST); + glDepthMask(false); + glBlendFunc(GL_ONE, GL_ONE); + + CURRENTRENDERGRAPH->DoDifferedLightPass(); + + glPopAttrib( ); +// glCullFace(GL_BACK); +} + +RenderDifferedLights* RenderDifferedLights::Generate() +{ + return new RenderDifferedLights(); +} + + +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen * + * * + * * + * 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/RenderDifferedLights.h =================================================================== --- Mercury2/src/RenderDifferedLights.h (rev 0) +++ Mercury2/src/RenderDifferedLights.h 2009-08-05 00:44:07 UTC (rev 454) @@ -0,0 +1,49 @@ +#ifndef RENDERDIFFEREDLIGHTS_H +#define RENDERDIFFEREDLIGHTS_H + +#include <MercuryAsset.h> + +class RenderDifferedLights : public MercuryAsset +{ + public: + RenderDifferedLights(); + virtual ~RenderDifferedLights(); + + virtual void Render(const MercuryNode* node); + static RenderDifferedLights* Generate(); + +}; + +#endif + +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen * + * * + * * + * 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: <axl...@us...> - 2009-08-08 23:08:42
|
Revision: 462 http://hgengine.svn.sourceforge.net/hgengine/?rev=462&view=rev Author: axlecrusher Date: 2009-08-08 23:08:31 +0000 (Sat, 08 Aug 2009) Log Message: ----------- remove debugging Modified Paths: -------------- Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryNode.cpp Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-08-08 23:07:49 UTC (rev 461) +++ Mercury2/src/MercuryAsset.cpp 2009-08-08 23:08:31 UTC (rev 462) @@ -67,10 +67,8 @@ void MercuryAsset::LoadFromXML(const XMLNode& node) { - printf("asset xml\n"); if ( !node.Attribute("nocull").empty() ) { - printf("NO CULL!!!!!!!!!!\n"); SetExcludeFromCull( node.Attribute("nocull")=="true" ); } } Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-08-08 23:07:49 UTC (rev 461) +++ Mercury2/src/MercuryNode.cpp 2009-08-08 23:08:31 UTC (rev 462) @@ -220,7 +220,6 @@ MAutoPtr< MercuryAsset > asset( AssetFactory::GetInstance().Generate( child.Attribute("type"), key ) ); if ( asset.IsValid() ) { - printf("new asset %s\n", child.Attribute("type").c_str()); asset->LoadFromXML( child ); this->AddAsset( asset ); asset->Init( this ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-08-10 00:38:46
|
Revision: 467 http://hgengine.svn.sourceforge.net/hgengine/?rev=467&view=rev Author: axlecrusher Date: 2009-08-10 00:38:39 +0000 (Mon, 10 Aug 2009) Log Message: ----------- updates Modified Paths: -------------- Mercury2/src/HGMDLModel.cpp Mercury2/src/Light.cpp Mercury2/src/Light.h Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryFBO.h Mercury2/src/MercuryNode.cpp Modified: Mercury2/src/HGMDLModel.cpp =================================================================== --- Mercury2/src/HGMDLModel.cpp 2009-08-09 01:14:31 UTC (rev 466) +++ Mercury2/src/HGMDLModel.cpp 2009-08-10 00:38:39 UTC (rev 467) @@ -69,6 +69,7 @@ for(uint16_t i = 0; i < m_meshes.size(); ++i) culled = culled && m_meshes[i]->DoCullingTests(n, matrix); } + m_culled = culled; return culled; } Modified: Mercury2/src/Light.cpp =================================================================== --- Mercury2/src/Light.cpp 2009-08-09 01:14:31 UTC (rev 466) +++ Mercury2/src/Light.cpp 2009-08-10 00:38:39 UTC (rev 467) @@ -16,15 +16,20 @@ m_color[0] = m_color[1] = m_color[2] = 1.0f; m_radius = 0.0f; m_fullscreen = false; + m_power = 1.0f; } Light::~Light() { } +void Light::PreRender(const MercuryMatrix& matrix) +{ + SetCulled( m_boundingVolume->DoFrustumTest( matrix ) ); +} + void Light::Render(const MercuryMatrix& matrix) { -// printf("render!\n"); m_worldPosition = FindModelViewMatrix(); m_worldPosition2 = FindGlobalMatrix(); CURRENTRENDERGRAPH->AddDifferedLight( this ); @@ -36,6 +41,9 @@ if ( !node.Attribute("atten").empty() ) StrTo3Float(node.Attribute("atten"), m_atten); + if ( !node.Attribute("power").empty() ) + m_power = StrToFloat(node.Attribute("power"), 1.0); + if ( !node.Attribute("fullscreen").empty() ) m_fullscreen = node.Attribute("fullscreen")=="true"?true:false; @@ -74,7 +82,7 @@ { //300 ensures that RGB of 255 reaches 0 //at 50, 255 is about 5. Close enough for me - const float maxDenom = 50;//300; + const float maxDenom = 50; float a = m_atten[2]; //quadratic float b = m_atten[1]; //linear float c = m_atten[0]; //constant @@ -99,11 +107,16 @@ float s = SQRT((b*b)-(4*a*c)); float x1 = ((-b) - s)/bottom; float x2 = ((-b) + s)/bottom; + x1 = x1>=0?x1:-x1; + x2 = x2>=0?x2:-x2; d = MAX<float>(x1,x2); } + d = m_power * d; m_radius = Clamp<float>(0.0f, 1000.0f, d); + printf("light radius %f\n", m_radius); + SAFE_DELETE( m_boundingVolume ); m_boundingVolume = new BoundingBox(MercuryVertex(0,0,0), MercuryVertex(m_radius,m_radius,m_radius) ); } @@ -143,6 +156,7 @@ sa.value.fFloatV4[0] = m_color[0]; sa.value.fFloatV4[1] = m_color[1]; sa.value.fFloatV4[2] = m_color[2]; + sa.value.fFloatV4[3] = m_power; Shader::SetAttribute("HG_LightColor", sa); if (m_fullscreen) Modified: Mercury2/src/Light.h =================================================================== --- Mercury2/src/Light.h 2009-08-09 01:14:31 UTC (rev 466) +++ Mercury2/src/Light.h 2009-08-10 00:38:39 UTC (rev 467) @@ -16,8 +16,7 @@ /** PreRender should be called before any real openGL render commands. It is used to handles things like frustum culling, and occlusion culling. Currently only occlusion culling test is run here.**/ -// virtual void PreRender(const MercuryNode* node); - + virtual void PreRender(const MercuryMatrix& matrix); virtual void Render(const MercuryMatrix& matrix); // virtual void PostRender(const MercuryNode* node) {}; @@ -35,6 +34,7 @@ float m_atten[3]; float m_color[3]; float m_radius; + float m_power; MercuryMatrix m_worldPosition; MercuryMatrix m_worldPosition2; Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-08-09 01:14:31 UTC (rev 466) +++ Mercury2/src/MercuryAsset.cpp 2009-08-10 00:38:39 UTC (rev 467) @@ -6,7 +6,7 @@ extern bool DOOCCLUSIONCULL; MercuryAsset::MercuryAsset() - :m_isInstanced(false), m_boundingVolume(NULL), m_loadState(NONE) + :m_isInstanced(false), m_boundingVolume(NULL), m_loadState(NONE), m_culled(false) { } @@ -48,6 +48,7 @@ if ( !culled && DOOCCLUSIONCULL) m_boundingVolume->DoOcclusionTest( n->GetOcclusionResult() ); } + m_culled = culled; return culled; } Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-08-09 01:14:31 UTC (rev 466) +++ Mercury2/src/MercuryAsset.h 2009-08-10 00:38:39 UTC (rev 467) @@ -57,6 +57,8 @@ inline void SetExcludeFromCull(bool t) { m_excludeFromCull = t; } inline bool ExcludeFromCull() const { return m_excludeFromCull; } + + inline bool IsCulled() const { return m_culled; } protected: void SetLoadState(LoadState ls); //thread safe LoadState GetLoadState(); //thread safe @@ -64,6 +66,7 @@ bool m_isInstanced; BoundingVolume* m_boundingVolume; MString m_path; + bool m_culled; private: LoadState m_loadState; MSemaphore m_lock; Modified: Mercury2/src/MercuryFBO.h =================================================================== --- Mercury2/src/MercuryFBO.h 2009-08-09 01:14:31 UTC (rev 466) +++ Mercury2/src/MercuryFBO.h 2009-08-10 00:38:39 UTC (rev 467) @@ -34,18 +34,10 @@ uint32_t m_fboID, m_depthBufferID; bool m_initiated, m_useDepth, m_useScreenSize; uint16_t m_width, m_height; -// uint32_t m_textureID[4]; MAutoPtr< Texture > m_textures[4]; uint8_t m_numTextures; ColorByteType m_cbt[4]; - -// static uint32_t m_lastRendered; - -// uint32_t m_lastInStask; - protected: -// AlignedBuffer<float> m_vertexData; -// AlignedBuffer<uint16_t> m_indexData; }; #endif Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-08-09 01:14:31 UTC (rev 466) +++ Mercury2/src/MercuryNode.cpp 2009-08-10 00:38:39 UTC (rev 467) @@ -146,7 +146,10 @@ PreRender( matrix ); //calls on children assets for (MercuryNode* child = FirstChild(); child != NULL; child = NextChild(child)) + { child->RecursivePreRender(); + m_culled = m_culled && child->IsCulled(); + } } void MercuryNode::RecursiveRender() @@ -247,7 +250,10 @@ { list< MercuryAsset* >::iterator i; for (i = m_render.begin(); i != m_render.end(); ++i ) - (*i)->Render(this); + { + if ( !(*i)->IsCulled() ) + (*i)->Render(this); + } } void MercuryNode::PostRender(const MercuryMatrix& matrix) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-08-11 02:26:32
|
Revision: 471 http://hgengine.svn.sourceforge.net/hgengine/?rev=471&view=rev Author: cnlohr Date: 2009-08-11 02:26:25 +0000 (Tue, 11 Aug 2009) Log Message: ----------- add self-traversal code for nodes. Modified Paths: -------------- Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-08-11 02:01:09 UTC (rev 470) +++ Mercury2/src/MercuryNode.cpp 2009-08-11 02:26:25 UTC (rev 471) @@ -128,7 +128,27 @@ return ret; } +MercuryNode * MercuryNode::TraversalNextNode( MercuryNode * stopnode ) +{ + if( !m_children.empty() ) + return *(m_children.begin()); + else if( m_nextSibling ) + return m_nextSibling; + else if( m_parent ) + { + MercuryNode * ret = m_parent; + while( ret && ret != stopnode && !ret->m_nextSibling ) + ret = ret->m_parent; + + if( !ret || ret == stopnode ) + return 0; + return ret->m_nextSibling; + } + else + return 0; +} + void MercuryNode::RecursiveUpdate(float dTime) { Update(dTime); Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-08-11 02:01:09 UTC (rev 470) +++ Mercury2/src/MercuryNode.h 2009-08-11 02:26:25 UTC (rev 471) @@ -52,6 +52,11 @@ /** Traversal is from the closest parent on upward */ MercuryNode* FindParent( const MString & sNameOfNode, int depth = MAXINT ); + ///Get the next node in an in-order traversal + /** In the traversal, stopnode indicates the node that when passing + by on returning up the tree haults traversal. */ + MercuryNode * TraversalNextNode( MercuryNode * stopnode ); + virtual void Update(float dTime) {}; virtual void RecursiveUpdate(float dTime); void ThreadedUpdate(float dTime); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-08-11 03:06:58
|
Revision: 472 http://hgengine.svn.sourceforge.net/hgengine/?rev=472&view=rev Author: cnlohr Date: 2009-08-11 03:06:51 +0000 (Tue, 11 Aug 2009) Log Message: ----------- tweak - do not require gl stuff for glhelpers, now since it could be for other systems. I don't know if this is going to stay or not. Modified Paths: -------------- Mercury2/src/GLHelpers.cpp Mercury2/src/GLHelpers.h Modified: Mercury2/src/GLHelpers.cpp =================================================================== --- Mercury2/src/GLHelpers.cpp 2009-08-11 02:26:25 UTC (rev 471) +++ Mercury2/src/GLHelpers.cpp 2009-08-11 03:06:51 UTC (rev 472) @@ -47,7 +47,7 @@ glLoadMatrixf( l.Ptr() ); } -MercuryMatrix glGetMatrix(GLenum m) +MercuryMatrix glGetMatrix(unsigned int m) { MercuryMatrix mm; glGetFloatv(m, mm.Ptr()); @@ -78,7 +78,7 @@ return MercuryVertex( (float)mouseX, (float)mouseY, (float)mouseZ ); } -GLenum ToGLColorType(ColorByteType cbt) +unsigned int ToGLColorType(ColorByteType cbt) { switch (cbt) { Modified: Mercury2/src/GLHelpers.h =================================================================== --- Mercury2/src/GLHelpers.h 2009-08-11 02:26:25 UTC (rev 471) +++ Mercury2/src/GLHelpers.h 2009-08-11 03:06:51 UTC (rev 472) @@ -7,9 +7,9 @@ MString GlError2String(uint32_t e); void glLoadMatrix(const MercuryMatrix& m); -MercuryMatrix glGetMatrix(GLenum m); +MercuryMatrix glGetMatrix(unsigned int m); MercuryVertex pointFromScreenLoc(int screen_x, int screen_y); -GLenum ToGLColorType(ColorByteType cbt); +unsigned int ToGLColorType(ColorByteType cbt); /**************************************************************************** * Copyright (C) 2009 by Joshua Allen * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-08-11 03:17:40
|
Revision: 474 http://hgengine.svn.sourceforge.net/hgengine/?rev=474&view=rev Author: cnlohr Date: 2009-08-11 03:17:29 +0000 (Tue, 11 Aug 2009) Log Message: ----------- add tentative traversal code Modified Paths: -------------- Mercury2/src/Viewport.cpp Mercury2/src/Viewport.h Modified: Mercury2/src/Viewport.cpp =================================================================== --- Mercury2/src/Viewport.cpp 2009-08-11 03:08:53 UTC (rev 473) +++ Mercury2/src/Viewport.cpp 2009-08-11 03:17:29 UTC (rev 474) @@ -1,6 +1,7 @@ #include <Viewport.h> #include <GLHeaders.h> #include <MercuryWindow.h> +#include <TransformNode.h> #include <Shader.h> @@ -17,6 +18,65 @@ { } +void Viewport::GoAll( const float fDtime ) +{ + MercuryNode * n; + int depth = 0; + + if( NeedsRebuild() ) + { + printf( "Xxxx\n" ); + } + + //Update pass + n = this; + while( n ) + { + n->Update( fDtime ); + n = n->TraversalNextNode( this, depth ); + } + + //Prerender pass + n = this; + while( n ) + { + const MercuryMatrix& matrix = n->FindGlobalMatrix(); + +// TransformNode * tn = dynamic_cast< TransformNode * >( n ); +// if( tn ) +// tn->m_modelView = tn->ManipulateMatrix( matrix ); + + n->PreRender( matrix ); + n = n->TraversalNextNode( this, depth ); + } + + n = this; + while( n ) + { + const MercuryMatrix& matrix = n->FindGlobalMatrix(); + const MercuryMatrix& modelView = n->FindModelViewMatrix(); //get the one computed in the last transform + + glLoadMatrix( modelView ); + + ShaderAttribute sa; + sa.type = ShaderAttribute::TYPE_MATRIX; + sa.value.matrix = matrix.Ptr(); + Shader::SetAttribute("HG_ModelMatrix", sa); + + n->Render( modelView ); + + glLoadMatrix( modelView ); + Shader::SetAttribute("HG_ModelMatrix", sa); + + n->PostRender( modelView ); + + n = n->TraversalNextNode( this, depth ); + } + + +} + + void Viewport::PreRender(const MercuryMatrix& matrix) { FRUSTUM = &m_frustum; Modified: Mercury2/src/Viewport.h =================================================================== --- Mercury2/src/Viewport.h 2009-08-11 03:08:53 UTC (rev 473) +++ Mercury2/src/Viewport.h 2009-08-11 03:17:29 UTC (rev 474) @@ -11,6 +11,9 @@ { public: Viewport(); + + virtual void GoAll( const float fDtime ); + virtual void PreRender(const MercuryMatrix& matrix); virtual void Render(const MercuryMatrix& matrix); virtual void PostRender(const MercuryMatrix& matrix); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-08-11 03:30:00
|
Revision: 475 http://hgengine.svn.sourceforge.net/hgengine/?rev=475&view=rev Author: cnlohr Date: 2009-08-11 03:29:52 +0000 (Tue, 11 Aug 2009) Log Message: ----------- enable use of new traverser - it's still way slower. Modified Paths: -------------- Mercury2/src/Mercury2.cpp Mercury2/src/TransformNode.cpp Mercury2/src/TransformNode.h Mercury2/src/Viewport.cpp Modified: Mercury2/src/Mercury2.cpp =================================================================== --- Mercury2/src/Mercury2.cpp 2009-08-11 03:17:29 UTC (rev 474) +++ Mercury2/src/Mercury2.cpp 2009-08-11 03:29:52 UTC (rev 475) @@ -76,22 +76,42 @@ { timer.Touch(); MESSAGEMAN::GetInstance().PumpMessages( timer.MicrosecondsSinceInit() ); - root->RecursiveUpdate( timer.Age() ); //comment to use threads + + //If false, use experimental traversal technique. + if(true) + { + root->RecursiveUpdate( timer.Age() ); //comment to use threads - CURRENTRENDERGRAPH = &renderGraph; - if ( MercuryNode::NeedsRebuild() ) + CURRENTRENDERGRAPH = &renderGraph; + if ( MercuryNode::NeedsRebuild() ) + { + renderGraph.Build(root); + } + + w->Clear(); + // renderGraph.Render(); + // RenderableNode::RecursiveRender(root); + // printf("\n"); + root->RecursivePreRender(); + root->RecursiveRender(); + // renderGraph.RenderAlpha(); + w->SwapBuffers(); + } + else { - renderGraph.Build(root); + CURRENTRENDERGRAPH = &renderGraph; + if ( MercuryNode::NeedsRebuild() ) + { + renderGraph.Build(root); + } + + Viewport* vp = (Viewport*)root->FirstChild(); + w->Clear(); + vp->GoAll( timer.Age() ); + w->SwapBuffers(); } - - w->Clear(); -// renderGraph.Render(); -// RenderableNode::RecursiveRender(root); -// printf("\n"); - root->RecursivePreRender(); - root->RecursiveRender(); -// renderGraph.RenderAlpha(); - w->SwapBuffers(); + + ++m_count; fpsTimer.Touch(timer); Modified: Mercury2/src/TransformNode.cpp =================================================================== --- Mercury2/src/TransformNode.cpp 2009-08-11 03:17:29 UTC (rev 474) +++ Mercury2/src/TransformNode.cpp 2009-08-11 03:29:52 UTC (rev 475) @@ -28,6 +28,17 @@ MercuryNode::RecursivePreRender(); } +void TransformNode::HandleMatrixOperations() +{ + if ( IsHidden() ) return; + + const MercuryMatrix& matrix = FindGlobalMatrix(); + m_modelView = ManipulateMatrix( matrix ); + + glLoadMatrix( m_modelView ); +} + + void TransformNode::SetScale( const MercuryVertex& scale ) { if (scale != m_scale) Modified: Mercury2/src/TransformNode.h =================================================================== --- Mercury2/src/TransformNode.h 2009-08-11 03:17:29 UTC (rev 474) +++ Mercury2/src/TransformNode.h 2009-08-11 03:29:52 UTC (rev 475) @@ -38,6 +38,10 @@ virtual void RecursivePreRender(); + //XXX: For charles' tests. This function will proably overtake the + //RecursivePreRender stuff, and be renamed + virtual void HandleMatrixOperations(); + GENRTTI(TransformNode); private: Modified: Mercury2/src/Viewport.cpp =================================================================== --- Mercury2/src/Viewport.cpp 2009-08-11 03:17:29 UTC (rev 474) +++ Mercury2/src/Viewport.cpp 2009-08-11 03:29:52 UTC (rev 475) @@ -42,9 +42,9 @@ { const MercuryMatrix& matrix = n->FindGlobalMatrix(); -// TransformNode * tn = dynamic_cast< TransformNode * >( n ); -// if( tn ) -// tn->m_modelView = tn->ManipulateMatrix( matrix ); + TransformNode * tn = dynamic_cast< TransformNode * >( n ); + if( tn ) + tn->HandleMatrixOperations(); n->PreRender( matrix ); n = n->TraversalNextNode( this, depth ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-08-16 13:58:15
|
Revision: 479 http://hgengine.svn.sourceforge.net/hgengine/?rev=479&view=rev Author: axlecrusher Date: 2009-08-16 13:58:08 +0000 (Sun, 16 Aug 2009) Log Message: ----------- Change how MercuryNodes handle assets. Asset are still instanced, but instead of MercuryNode storing auto pointers to assets, they store a MercuryAssetInstance. Assets are still instanced, but also allows for per-instance data storage. Perviously no per-instance data was allowed as it would affect all instaces of an asset. This change is useful for culling and occlusion tests. Also the Prerender, Render, and PostRender lists have been removed. Currently all assets have all 3 render functions executed. This may change in the future. Modified Paths: -------------- Mercury2/src/HGMDLMesh.h Mercury2/src/HGMDLModel.cpp Mercury2/src/HGMDLModel.h Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Mercury2/src/Shader.cpp Mercury2/src/Texture.cpp Mercury2/src/Viewport.cpp Modified: Mercury2/src/HGMDLMesh.h =================================================================== --- Mercury2/src/HGMDLMesh.h 2009-08-16 13:40:19 UTC (rev 478) +++ Mercury2/src/HGMDLMesh.h 2009-08-16 13:58:08 UTC (rev 479) @@ -11,6 +11,7 @@ void ReadExtraData(MercuryFile* hgmdl); void LoadOBB(MercuryFile* hgmdl); + OcclusionResult m_occlusionResult; private: MString m_name; bool m_cachable; Modified: Mercury2/src/HGMDLModel.cpp =================================================================== --- Mercury2/src/HGMDLModel.cpp 2009-08-16 13:40:19 UTC (rev 478) +++ Mercury2/src/HGMDLModel.cpp 2009-08-16 13:58:08 UTC (rev 479) @@ -60,14 +60,14 @@ } } -bool HGMDLModel::DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix) +bool HGMDLModel::DoCullingTests(OcclusionResult& occlusion, const MercuryMatrix& matrix) { bool culled = false; if ( GetLoadState() != LOADING ) { culled = true; for(uint16_t i = 0; i < m_meshes.size(); ++i) - culled = culled && m_meshes[i]->DoCullingTests(n, matrix); + culled = culled && m_meshes[i]->DoCullingTests(m_meshes[i]->m_occlusionResult, matrix); } return culled; } @@ -85,7 +85,7 @@ { for(uint16_t i = 0; i < m_meshes.size(); ++i) { - if ( !(node->GetOcclusionResult().IsOccluded() || node->IsCulled()) ) + if ( !(m_meshes[i]->m_occlusionResult.IsOccluded() || node->IsCulled()) ) m_meshes[i]->Render(node); } } Modified: Mercury2/src/HGMDLModel.h =================================================================== --- Mercury2/src/HGMDLModel.h 2009-08-16 13:40:19 UTC (rev 478) +++ Mercury2/src/HGMDLModel.h 2009-08-16 13:58:08 UTC (rev 479) @@ -19,7 +19,7 @@ static HGMDLModel* Generate(); - virtual bool DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix); + virtual bool DoCullingTests(OcclusionResult& occlusion, const MercuryMatrix& matrix); virtual void PreRender(const MercuryNode* node); virtual void Render(const MercuryNode* node); Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-08-16 13:40:19 UTC (rev 478) +++ Mercury2/src/MercuryAsset.cpp 2009-08-16 13:58:08 UTC (rev 479) @@ -17,9 +17,8 @@ void MercuryAsset::Init(MercuryNode* node) { -// RenderableNode* rn; - if ( node ) node->AddPreRender(this); - if ( node ) node->AddRender(this); +// if ( node ) node->AddPreRender(this); +// if ( node ) node->AddRender(this); } void MercuryAsset::SetLoadState(LoadState ls) @@ -39,14 +38,13 @@ SetLoadState( LOADED ); } -bool MercuryAsset::DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix) +bool MercuryAsset::DoCullingTests(OcclusionResult& occlusion, const MercuryMatrix& matrix) { bool culled = false; if ( m_boundingVolume ) { culled = m_boundingVolume->DoFrustumTest(matrix); - if ( !culled && DOOCCLUSIONCULL) - m_boundingVolume->DoOcclusionTest( n->GetOcclusionResult() ); + if ( !culled && DOOCCLUSIONCULL) m_boundingVolume->DoOcclusionTest( occlusion ); } return culled; } @@ -89,6 +87,11 @@ glEnd(); } +MercuryAssetInstance::MercuryAssetInstance(MercuryAsset* asset) + :m_asset( asset ), m_isCulled( false ) +{ +} + AssetFactory& AssetFactory::GetInstance() { static AssetFactory* instance = NULL; Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-08-16 13:40:19 UTC (rev 478) +++ Mercury2/src/MercuryAsset.h 2009-08-16 13:58:08 UTC (rev 479) @@ -52,7 +52,7 @@ inline const MString& Path() const { return m_path; } ///Retuns true if culled, also will initiate occlusion test - virtual bool DoCullingTests(MercuryNode* n, const MercuryMatrix& matrix); + virtual bool DoCullingTests(OcclusionResult& occlusion, const MercuryMatrix& matrix); void DrawAxes(); inline void SetExcludeFromCull(bool t) { m_excludeFromCull = t; } @@ -70,6 +70,26 @@ bool m_excludeFromCull; }; +/** This holds the per-instance data for each asset instance. +Used in MercuryNode. */ +class MercuryAssetInstance +{ + public: + MercuryAssetInstance(MercuryAsset* asset); + inline MercuryAsset& Asset() { return *m_asset; } + inline const MercuryAsset& Asset() const { return *m_asset; } + inline const MercuryAsset* AssetPtr() const { return m_asset; } + + inline bool Culled() const { return m_isCulled; } + inline bool Culled(bool t) { m_isCulled = t; return m_isCulled; } + + inline OcclusionResult& GetOcclusionResult() { return m_occlusionResult; } + private: + MAutoPtr< MercuryAsset > m_asset; //actual asset storage + OcclusionResult m_occlusionResult; + bool m_isCulled; +}; + class LoaderThreadData { public: @@ -97,7 +117,7 @@ std::list< std::pair< MString, Callback0R< MAutoPtr<MercuryAsset> > > > m_factoryCallbacks; - //the actual storage point is in renderable nodes + //the actual storage point is in MercuryAssetInstance static std::map<MString, MercuryAsset*> m_assetInstances; }; Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-08-16 13:40:19 UTC (rev 478) +++ Mercury2/src/MercuryNode.cpp 2009-08-16 13:58:08 UTC (rev 479) @@ -29,6 +29,11 @@ m_children.clear(); } +void MercuryNode::AddAsset(MercuryAsset* asset) +{ + m_assets.push_back( MercuryAssetInstance(asset) ); +} + void MercuryNode::AddChild(MercuryNode* n) { // list< MercuryNode* >::iterator last = m_children.end(); @@ -181,7 +186,7 @@ void MercuryNode::RecursiveRender() { - if ( IsHidden() || m_occlusionResult.IsOccluded() || IsCulled() ) return; + if ( IsHidden() || IsCulled() ) return; const MercuryMatrix& matrix = FindGlobalMatrix(); const MercuryMatrix& modelView = FindModelViewMatrix(); //get the one computed in the last transform @@ -263,28 +268,31 @@ { SetCulled( false ); bool culled = true; - list< MercuryAsset* >::iterator i; - for (i = m_prerender.begin(); i != m_prerender.end(); ++i ) + + std::list< MercuryAssetInstance >::iterator i; + for (i = m_assets.begin(); i != m_assets.end(); ++i ) { - if ( !(*i)->ExcludeFromCull() ) - culled = culled && (*i)->DoCullingTests( this, matrix ); - (*i)->PreRender(this); - SetCulled( culled ); + MercuryAssetInstance& mai = *i; + MercuryAsset& a = mai.Asset(); + if ( !a.ExcludeFromCull() ) + culled = culled && mai.Culled( a.DoCullingTests( mai.GetOcclusionResult(), matrix ) ); + if ( !mai.Culled() ) a.PreRender(this); } + SetCulled( culled ); } void MercuryNode::Render(const MercuryMatrix& matrix) { - list< MercuryAsset* >::iterator i; - for (i = m_render.begin(); i != m_render.end(); ++i ) - (*i)->Render(this); + std::list< MercuryAssetInstance >::iterator i; + for (i = m_assets.begin(); i != m_assets.end(); ++i ) + if ( !(i->Culled() || i->GetOcclusionResult().IsOccluded()) ) i->Asset().Render(this); } void MercuryNode::PostRender(const MercuryMatrix& matrix) { - list< MercuryAsset* >::iterator i; - for (i = m_postrender.begin(); i != m_postrender.end(); ++i ) - (*i)->PostRender(this); + std::list< MercuryAssetInstance >::iterator i; + for (i = m_assets.begin(); i != m_assets.end(); ++i ) + i->Asset().PostRender(this); } const MercuryMatrix& MercuryNode::FindGlobalMatrix() const @@ -315,43 +323,6 @@ return MercuryMatrix::Identity(); } -void MercuryNode::AddPreRender(MercuryAsset* asset) -{ -#ifdef MCHECKASSETS - if ( !IsInAssetList(asset) ) //yell and scream - assert(!"Asset does not exist in list!"); -#endif - - m_prerender.push_back(asset); -} - -void MercuryNode::AddRender(MercuryAsset* asset) -{ -#ifdef MCHECKASSETS - if ( !IsInAssetList(asset) ) //yell and scream - assert(!"Asset does not exist in list!"); -#endif - - m_render.push_back(asset); -} -void MercuryNode::AddPostRender(MercuryAsset* asset) -{ -#ifdef MCHECKASSETS - if ( !IsInAssetList(asset) ) //yell and scream - assert(!"Asset does not exist in list!"); -#endif - - m_postrender.push_back(asset); -} - -bool MercuryNode::IsInAssetList( MercuryAsset* asset ) const -{ - std::list< MAutoPtr< MercuryAsset > >::const_iterator i; - for (i = m_assets.begin(); i != m_assets.end(); ++i ) - if ( (*i) == asset ) return true; - return false; -} - bool MercuryNode::IsCulled(const MercuryMatrix& matrix) { bool clip = false; Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-08-16 13:40:19 UTC (rev 478) +++ Mercury2/src/MercuryNode.h 2009-08-16 13:58:08 UTC (rev 479) @@ -35,7 +35,7 @@ void AddChild(MercuryNode* n); void RemoveChild(MercuryNode* n); - + inline MercuryNode* Parent() const { return m_parent; } inline MercuryNode* NextSibling() const { return m_nextSibling; } inline MercuryNode* PrevSibling() const { return m_prevSibling; } @@ -86,12 +86,8 @@ inline void SetName(const MString& name) { m_name = name; } inline MString GetName() const { return m_name; } - inline void AddAsset(MAutoPtr< MercuryAsset > asset) { m_assets.push_back(asset); } + void AddAsset(MercuryAsset* asset); - void AddPreRender(MercuryAsset* asset); - void AddRender(MercuryAsset* asset); - void AddPostRender(MercuryAsset* asset); - virtual void PreRender(const MercuryMatrix& matrix); virtual void Render(const MercuryMatrix& matrix); virtual void PostRender(const MercuryMatrix& matrix); @@ -107,8 +103,6 @@ inline bool IsCulled() const { return m_culled; } virtual MercuryMatrix ManipulateMatrix(const MercuryMatrix& matrix); - inline OcclusionResult& GetOcclusionResult() { return m_occlusionResult; } - inline const OcclusionResult& GetOcclusionResult() const { return m_occlusionResult; } protected: std::list< MercuryNode* > m_children; //These nodes are unique, not instanced MercuryNode* m_parent; @@ -119,22 +113,22 @@ MString m_name; bool m_hidden; - bool m_useAlphaPath; - bool m_culled; public: //XXX: This will become private sooner or later... It is temporarily public for other work. bool IsInAssetList(MercuryAsset* asset) const; + bool m_useAlphaPath; - OcclusionResult m_occlusionResult; + private: + bool m_culled; //The asset is actually stored here - std::list< MAutoPtr< MercuryAsset > > m_assets; + std::list< MercuryAssetInstance > m_assets; //we will just use normal pointers here because we don't want to waste too much time //dereferencing the autopointer. As a precaution when assets are added to these lists, //they must exist in m_assets. - std::list< MercuryAsset* > m_prerender; - std::list< MercuryAsset* > m_render; - std::list< MercuryAsset* > m_postrender; +// std::list< MercuryAsset* > m_prerender; +// std::list< MercuryAsset* > m_render; +// std::list< MercuryAsset* > m_postrender; }; class NodeFactory Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-08-16 13:40:19 UTC (rev 478) +++ Mercury2/src/Shader.cpp 2009-08-16 13:58:08 UTC (rev 479) @@ -61,8 +61,6 @@ void Shader::Init(MercuryNode* node) { MercuryAsset::Init( node ); -// RenderableNode* rn = RenderableNode::Cast( node ); - if ( node ) node->AddPostRender( this ); } void Shader::Render(const MercuryNode* node) Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-08-16 13:40:19 UTC (rev 478) +++ Mercury2/src/Texture.cpp 2009-08-16 13:58:08 UTC (rev 479) @@ -40,9 +40,6 @@ void Texture::Init(MercuryNode* node) { MercuryAsset::Init( node ); - -// RenderableNode* rn = RenderableNode::Cast( node ); - if ( node ) node->AddPostRender( this ); } void Texture::LoadFromRaw() Modified: Mercury2/src/Viewport.cpp =================================================================== --- Mercury2/src/Viewport.cpp 2009-08-16 13:40:19 UTC (rev 478) +++ Mercury2/src/Viewport.cpp 2009-08-16 13:58:08 UTC (rev 479) @@ -66,7 +66,7 @@ n->PreRender( matrix ); if( n->Parent() ) - n->Parent()->m_culled = n->Parent()->m_culled && n->IsCulled(); + n->Parent()->SetCulled( n->Parent()->IsCulled() && n->IsCulled() ); //Traverse next /* @@ -103,7 +103,7 @@ n = this; while( n ) { - if( n->IsHidden() || m_occlusionResult.IsOccluded() || IsCulled() ) + if( n->IsHidden() || IsCulled() ) { //Make sure we have a next sibling... while( n && n != this && !n->NextSibling() ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-08-16 15:34:04
|
Revision: 480 http://hgengine.svn.sourceforge.net/hgengine/?rev=480&view=rev Author: axlecrusher Date: 2009-08-16 15:33:55 +0000 (Sun, 16 Aug 2009) Log Message: ----------- Init was used to add assets to pre and post render. Since that is gone, init does nothing. Init will probably be tranformed into a function to recycle assets. Modified Paths: -------------- Mercury2/src/Light.cpp Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryNode.cpp Mercury2/src/RenderBuffer.cpp Mercury2/src/RenderBuffer.h Mercury2/src/Shader.cpp Mercury2/src/Shader.h Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/src/Light.cpp =================================================================== --- Mercury2/src/Light.cpp 2009-08-16 13:58:08 UTC (rev 479) +++ Mercury2/src/Light.cpp 2009-08-16 15:33:55 UTC (rev 480) @@ -63,7 +63,6 @@ // shader->LoadFromXML( node ); shader->LoadShader(key, 0); SetShader( shader ); -// shader->Init( this ); } m_fullscreen = node.Attribute("fullscreen")=="true"?true:false; Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-08-16 13:58:08 UTC (rev 479) +++ Mercury2/src/MercuryAsset.cpp 2009-08-16 15:33:55 UTC (rev 480) @@ -15,10 +15,8 @@ SAFE_DELETE(m_boundingVolume); } -void MercuryAsset::Init(MercuryNode* node) +void MercuryAsset::Init() { -// if ( node ) node->AddPreRender(this); -// if ( node ) node->AddRender(this); } void MercuryAsset::SetLoadState(LoadState ls) Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-08-16 13:58:08 UTC (rev 479) +++ Mercury2/src/MercuryAsset.h 2009-08-16 15:33:55 UTC (rev 480) @@ -30,7 +30,7 @@ MercuryAsset(); virtual ~MercuryAsset(); - virtual void Init(MercuryNode* node); + virtual void Init(); /** PreRender should be called before any real openGL render commands. It is used to handles things like frustum culling, and occlusion culling. Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-08-16 13:58:08 UTC (rev 479) +++ Mercury2/src/MercuryNode.cpp 2009-08-16 15:33:55 UTC (rev 480) @@ -257,7 +257,6 @@ { asset->LoadFromXML( child ); this->AddAsset( asset ); - asset->Init( this ); } } } Modified: Mercury2/src/RenderBuffer.cpp =================================================================== --- Mercury2/src/RenderBuffer.cpp 2009-08-16 13:58:08 UTC (rev 479) +++ Mercury2/src/RenderBuffer.cpp 2009-08-16 15:33:55 UTC (rev 480) @@ -17,18 +17,6 @@ if (m_bufferID != 0) glDeleteRenderbuffersEXT(1, &m_bufferID); } -void RenderBuffer::Init(MercuryNode* node) -{ - MercuryAsset::Init( node ); - - RenderableNode* rn = RenderableNode::Cast( node ); - if ( rn ) - { -// rn->AddPreRender( this ); - rn->AddPostRender( this ); - } -} - void RenderBuffer::Render(const MercuryNode* node) { if ( !m_initiated ) InitRenderBuffer(); Modified: Mercury2/src/RenderBuffer.h =================================================================== --- Mercury2/src/RenderBuffer.h 2009-08-16 13:58:08 UTC (rev 479) +++ Mercury2/src/RenderBuffer.h 2009-08-16 15:33:55 UTC (rev 480) @@ -18,8 +18,6 @@ RenderBuffer(); virtual ~RenderBuffer(); - virtual void Init(MercuryNode* node); - virtual void Render(const MercuryNode* node); virtual void PostRender(const MercuryNode* node); virtual void LoadFromXML(const XMLNode& node); Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-08-16 13:58:08 UTC (rev 479) +++ Mercury2/src/Shader.cpp 2009-08-16 15:33:55 UTC (rev 480) @@ -58,11 +58,6 @@ DestroyShader( ); } -void Shader::Init(MercuryNode* node) -{ - MercuryAsset::Init( node ); -} - void Shader::Render(const MercuryNode* node) { bool bApply = true; Modified: Mercury2/src/Shader.h =================================================================== --- Mercury2/src/Shader.h 2009-08-16 13:58:08 UTC (rev 479) +++ Mercury2/src/Shader.h 2009-08-16 15:33:55 UTC (rev 480) @@ -77,7 +77,6 @@ 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; } Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-08-16 13:58:08 UTC (rev 479) +++ Mercury2/src/Texture.cpp 2009-08-16 15:33:55 UTC (rev 480) @@ -37,11 +37,6 @@ m_textureID = 0; } -void Texture::Init(MercuryNode* node) -{ - MercuryAsset::Init( node ); -} - void Texture::LoadFromRaw() { if ( !m_raw ) return; Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2009-08-16 13:58:08 UTC (rev 479) +++ Mercury2/src/Texture.h 2009-08-16 15:33:55 UTC (rev 480) @@ -12,8 +12,6 @@ void Clean(); - virtual void Init(MercuryNode* node); - virtual void Render(const MercuryNode* node); virtual void PostRender(const MercuryNode* node); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-08-18 05:23:39
|
Revision: 486 http://hgengine.svn.sourceforge.net/hgengine/?rev=486&view=rev Author: cnlohr Date: 2009-08-18 05:23:32 +0000 (Tue, 18 Aug 2009) Log Message: ----------- use Memoized Matrices (Find and remember the location, so we can GetGlobalMatrix instead of FindGlobalMatrix()) Modified Paths: -------------- Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Mercury2/src/RenderGraph.cpp Mercury2/src/TransformNode.cpp Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-08-18 05:21:53 UTC (rev 485) +++ Mercury2/src/MercuryNode.cpp 2009-08-18 05:23:32 UTC (rev 486) @@ -14,7 +14,9 @@ REGISTER_NODE_TYPE(MercuryNode); MercuryNode::MercuryNode() - :m_parent(NULL), m_prevSibling(NULL), m_nextSibling(NULL), m_hidden(false), m_useAlphaPath(false), m_culled(false) + :m_parent(NULL), m_prevSibling(NULL), + m_nextSibling(NULL), m_hidden(false), + m_useAlphaPath(false), m_culled(false) { } @@ -173,7 +175,7 @@ { if ( IsHidden() ) return; - const MercuryMatrix& matrix = FindGlobalMatrix(); + const MercuryMatrix& matrix = GetGlobalMatrix(); PreRender( matrix ); //calls on children assets @@ -188,8 +190,8 @@ { if ( IsHidden() || IsCulled() ) return; - const MercuryMatrix& matrix = FindGlobalMatrix(); - const MercuryMatrix& modelView = FindModelViewMatrix(); //get the one computed in the last transform + const MercuryMatrix& matrix = GetGlobalMatrix(); + const MercuryMatrix& modelView = GetModelViewMatrix(); //get the one computed in the last transform //A lot of this stuff could be moved into the transform node, BUT @@ -370,6 +372,8 @@ } bool MercuryNode::m_rebuildRenderGraph = false; +__thread int g_iViewportID; + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-08-18 05:21:53 UTC (rev 485) +++ Mercury2/src/MercuryNode.h 2009-08-18 05:23:32 UTC (rev 486) @@ -27,6 +27,10 @@ while(tn) { if (typeid(x) == typeid(*tn)) return true; tn = *n; } \ return false;} */ + +///The Global Viewport ID for this thread (to enable multi-threaded functioning for Viewports) +extern __thread int g_iViewportID; + class MercuryNode : public MessageHandler { public: @@ -91,18 +95,16 @@ virtual void PreRender(const MercuryMatrix& matrix); virtual void Render(const MercuryMatrix& matrix); virtual void PostRender(const MercuryMatrix& matrix); - - ///This will get the world space matrix - const MercuryMatrix& FindGlobalMatrix() const; - const MercuryMatrix& FindModelViewMatrix() const; - + virtual bool IsCulled(const MercuryMatrix& matrix); inline bool IsHidden() { return m_hidden; } inline void SetCulled(bool t) { m_culled = t; } inline bool IsCulled() const { return m_culled; } virtual MercuryMatrix ManipulateMatrix(const MercuryMatrix& matrix); - + + const MercuryMatrix & GetGlobalMatrix() const { return m_pGlobalMatrix[g_iViewportID]; } + const MercuryMatrix & GetModelViewMatrix() const { return m_pModelViewMatrix[g_iViewportID]; } protected: std::list< MercuryNode* > m_children; //These nodes are unique, not instanced MercuryNode* m_parent; @@ -112,13 +114,10 @@ static bool m_rebuildRenderGraph; MString m_name; - bool m_hidden; - public: //XXX: This will become private sooner or later... It is temporarily public for other work. - bool IsInAssetList(MercuryAsset* asset) const; + bool m_hidden; bool m_useAlphaPath; - - private: bool m_culled; + bool IsInAssetList(MercuryAsset* asset) const; //The asset is actually stored here std::list< MercuryAssetInstance > m_assets; @@ -129,6 +128,15 @@ // std::list< MercuryAsset* > m_prerender; // std::list< MercuryAsset* > m_render; // std::list< MercuryAsset* > m_postrender; + + ///This will get the world space matrix + const MercuryMatrix& FindGlobalMatrix() const; + const MercuryMatrix& FindModelViewMatrix() const; + + const MercuryMatrix * m_pGlobalMatrix; + const MercuryMatrix * m_pModelViewMatrix; + + friend class RenderGraph; }; class NodeFactory Modified: Mercury2/src/RenderGraph.cpp =================================================================== --- Mercury2/src/RenderGraph.cpp 2009-08-18 05:21:53 UTC (rev 485) +++ Mercury2/src/RenderGraph.cpp 2009-08-18 05:23:32 UTC (rev 486) @@ -53,6 +53,10 @@ { RenderGraphEntry* lastEntry = &entry; // MercuryNode* rn = MercuryNode::Cast(node); + + //Update the Matrices + node->m_pGlobalMatrix = &node->FindGlobalMatrix(); + node->m_pModelViewMatrix = &node->FindModelViewMatrix(); if ( node ) { @@ -72,7 +76,7 @@ { StoreRenderState srs; srs.Save(); - srs.Matrix = node->FindGlobalMatrix(); + srs.Matrix = node->GetGlobalMatrix(); srs.Node = node; MercuryVertex p = srs.Matrix * MercuryVertex(0,0,0,1); Modified: Mercury2/src/TransformNode.cpp =================================================================== --- Mercury2/src/TransformNode.cpp 2009-08-18 05:21:53 UTC (rev 485) +++ Mercury2/src/TransformNode.cpp 2009-08-18 05:23:32 UTC (rev 486) @@ -20,7 +20,7 @@ { if ( IsHidden() ) return; - const MercuryMatrix& matrix = FindGlobalMatrix(); + const MercuryMatrix& matrix = GetGlobalMatrix(); m_modelView = ManipulateMatrix( matrix ); glLoadMatrix( m_modelView ); @@ -32,7 +32,7 @@ { if ( IsHidden() ) return; - const MercuryMatrix& matrix = FindGlobalMatrix(); + const MercuryMatrix& matrix = GetGlobalMatrix(); m_modelView = ManipulateMatrix( matrix ); glLoadMatrix( m_modelView ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-08-18 10:41:08
|
Revision: 491 http://hgengine.svn.sourceforge.net/hgengine/?rev=491&view=rev Author: axlecrusher Date: 2009-08-18 10:41:01 +0000 (Tue, 18 Aug 2009) Log Message: ----------- Fix completly broken culling Modified Paths: -------------- Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryNode.cpp Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-08-18 05:47:39 UTC (rev 490) +++ Mercury2/src/MercuryAsset.cpp 2009-08-18 10:41:01 UTC (rev 491) @@ -6,7 +6,7 @@ extern bool DOOCCLUSIONCULL; MercuryAsset::MercuryAsset() - :m_isInstanced(false), m_boundingVolume(NULL), m_loadState(NONE), m_excludeFromCull(true) + :m_isInstanced(false), m_boundingVolume(NULL), m_loadState(NONE), m_excludeFromCull(false) { } Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-08-18 05:47:39 UTC (rev 490) +++ Mercury2/src/MercuryNode.cpp 2009-08-18 10:41:01 UTC (rev 491) @@ -275,13 +275,16 @@ { MercuryAssetInstance& mai = *i; MercuryAsset& a = mai.Asset(); + if ( !a.ExcludeFromCull() ) - culled = culled && mai.Culled( a.DoCullingTests( mai.GetOcclusionResult(), matrix ) ); - if ( !mai.Culled() ) { - culled = false; - a.PreRender(this); + mai.Culled( a.DoCullingTests( mai.GetOcclusionResult(), matrix ) ); + culled = culled && mai.Culled(); } + + if ( a.ExcludeFromCull() ) culled = false; //node must be rendered if something was excluded + + if ( !mai.Culled() ) a.PreRender(this); } SetCulled( culled ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-08-18 22:26:58
|
Revision: 494 http://hgengine.svn.sourceforge.net/hgengine/?rev=494&view=rev Author: cnlohr Date: 2009-08-18 22:26:48 +0000 (Tue, 18 Aug 2009) Log Message: ----------- add the C formatting stuff ( \n => (newline) ) Modified Paths: -------------- Mercury2/src/MercuryUtil.cpp Mercury2/src/MercuryUtil.h Modified: Mercury2/src/MercuryUtil.cpp =================================================================== --- Mercury2/src/MercuryUtil.cpp 2009-08-18 22:25:48 UTC (rev 493) +++ Mercury2/src/MercuryUtil.cpp 2009-08-18 22:26:48 UTC (rev 494) @@ -4,6 +4,85 @@ #include <MercuryVector.h> #include <MercuryBacktrace.h> +MString ConvertToCFormat( const MString & ncf ) +{ + MString ret; + const char* nccf = ncf.c_str(); + + for ( int i = 0; (unsigned)i < ncf.length(); i++ ) + { + switch ( nccf[i] ) + { + case '\t': ret += "\\t"; break; + case '\n': ret += "\\n"; break; + case '\r': ret += "\\r"; break; + case '\f': ret += "\\f"; break; + case '\b': ret += "\\b"; break; + case '\\': ret += "\\\\"; break; + case '\'': ret += "\\\'"; break; + case '\"': ret += "\\\""; break; + default: + if( nccf[i] < 32 ) + { + ret += "\\"; + ret += ((unsigned char)nccf[i]/64)%8 + '0'; + ret += ((unsigned char)nccf[i]/8)%8 + '0'; + ret += (unsigned char)nccf[i]%8 + '0'; + } else + ret += nccf[i]; + } + } + return ret; +} + +MString ConvertToUnformatted( const MString & cf ) +{ + MString ret; + const char* ccf = cf.c_str(); + + for ( int i = 0; (unsigned)i < cf.length(); i++ ) + { + switch ( ccf[i] ) + { + case '\\': + i++; + if ( (unsigned)i >= cf.length() ) + return ret; + switch ( ccf[i] ) + { + case 't': ret += '\t'; break; + case 'n': ret += '\n'; break; + case 'r': ret += '\r'; break; + case 'f': ret += '\f'; break; + case 'b': ret += '\b'; break; + case '\\': ret += '\\'; break; + case '\'': ret += '\''; break; + case '\"': ret += '\"'; break; + default: + if( ccf[i] >= '0' && ccf[i] <= '7' ) + { + char c = ccf[i] - '0'; + if( ccf[i+1] >= '0' && ccf[i+1] <= '8' ) + { + i++; + c = c * 8 + ccf[i] - '0'; + } + if( ccf[i+1] >= '0' && ccf[i+1] <= '8' ) + { + i++; + c = c * 8 + ccf[i] - '0'; + } + ret += c; + } + } + break; + default: + ret += ccf[i]; + } + } + return ret; +} + MString ToUpper(const MString& s) { MString t = s; Modified: Mercury2/src/MercuryUtil.h =================================================================== --- Mercury2/src/MercuryUtil.h 2009-08-18 22:25:48 UTC (rev 493) +++ Mercury2/src/MercuryUtil.h 2009-08-18 22:26:48 UTC (rev 494) @@ -124,7 +124,12 @@ ///Split given string into other strings using delimiters from termin void SplitStrings( const MString & in, MVector < MString > & out, const char * termin, const char * whitespace, long termlen, long wslen ); +///Convert string containing binary characters to C-style formatted string. +MString ConvertToCFormat( const MString & ncf ); +///Convert a C-style formatted string into it's binary string equivalent. +MString ConvertToUnformatted( const MString & cf ); + #endif /* Copyright (c) 2009, Joshua Allen and Charles Lohr This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-08-18 22:27:46
|
Revision: 495 http://hgengine.svn.sourceforge.net/hgengine/?rev=495&view=rev Author: cnlohr Date: 2009-08-18 22:27:31 +0000 (Tue, 18 Aug 2009) Log Message: ----------- fix warnings Modified Paths: -------------- Mercury2/src/MercuryWindow.h Mercury2/src/X11Window.cpp Modified: Mercury2/src/MercuryWindow.h =================================================================== --- Mercury2/src/MercuryWindow.h 2009-08-18 22:26:48 UTC (rev 494) +++ Mercury2/src/MercuryWindow.h 2009-08-18 22:27:31 UTC (rev 495) @@ -38,11 +38,11 @@ static Callback0R< MercuryWindow* > genWindowClbk; static MercuryWindow* m_windowInstance; - bool m_bGrabbed; MString m_title; int m_width, m_height; uint8_t m_bits, m_depthBits; bool m_fullscreen; + bool m_bGrabbed; }; #endif Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-08-18 22:26:48 UTC (rev 494) +++ Mercury2/src/X11Window.cpp 2009-08-18 22:27:31 UTC (rev 495) @@ -261,7 +261,7 @@ case FocusIn: case FocusOut: { - XFocusChangeEvent*e = (XFocusChangeEvent*)&event; + //XFocusChangeEvent*e = (XFocusChangeEvent*)&event; inFocus = (event.type == FocusIn); if (inFocus && m_bGrabbed ) XWarpPointer(m_display, None, m_window, 0,0,0,0,m_width/2,m_height/2); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-08-18 22:39:04
|
Revision: 496 http://hgengine.svn.sourceforge.net/hgengine/?rev=496&view=rev Author: cnlohr Date: 2009-08-18 22:38:55 +0000 (Tue, 18 Aug 2009) Log Message: ----------- switch to MHash - It's roughly 4% faster total scene graph traversal with MHash instead of map when the CPU is forced to be the bottleneck. Modified Paths: -------------- Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/Shader.cpp Mercury2/src/Shader.h Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-08-18 22:27:31 UTC (rev 495) +++ Mercury2/src/MercuryAsset.cpp 2009-08-18 22:38:55 UTC (rev 496) @@ -120,13 +120,6 @@ return NULL; } -MercuryAsset* AssetFactory::LocateAsset( const MString& key ) -{ - std::map<MString, MercuryAsset*>::iterator asset = m_assetInstances.find(key); - if ( asset != m_assetInstances.end() ) return asset->second; - return NULL; -} - void AssetFactory::AddAssetInstance(const MString& key, MercuryAsset* asset) { asset->IsInstanced(true); @@ -135,16 +128,10 @@ void AssetFactory::RemoveAssetInstance(const MString& key) { - std::map<MString, MercuryAsset*>::iterator asset = m_assetInstances.find(key); - if ( asset != m_assetInstances.end() ) - { - m_assetInstances.erase( asset ); - printf("removed asset %s\n", key.c_str()); - } - + m_assetInstances.remove( key ); } -std::map<MString, MercuryAsset*> AssetFactory::m_assetInstances; +MHash< MercuryAsset*> AssetFactory::m_assetInstances; /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-08-18 22:27:31 UTC (rev 495) +++ Mercury2/src/MercuryAsset.h 2009-08-18 22:38:55 UTC (rev 496) @@ -9,7 +9,7 @@ #include <XMLParser.h> #include <Callback.h> -#include <map> +#include <MercuryHash.h> #include <list> enum LoadState @@ -113,12 +113,12 @@ void RemoveAssetInstance(const MString& key); private: - MercuryAsset* LocateAsset( const MString& key ); + MercuryAsset* LocateAsset( const MString& key ) { MercuryAsset ** a = m_assetInstances.get( key ); return a?(*a):0; } std::list< std::pair< MString, Callback0R< MAutoPtr<MercuryAsset> > > > m_factoryCallbacks; //the actual storage point is in MercuryAssetInstance - static std::map<MString, MercuryAsset*> m_assetInstances; + static MHash< MercuryAsset*> m_assetInstances; }; Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-08-18 22:27:31 UTC (rev 495) +++ Mercury2/src/Shader.cpp 2009-08-18 22:38:55 UTC (rev 496) @@ -425,11 +425,9 @@ std::list< UniformMap >::iterator ui = m_uniforms.begin(); for (;ui != m_uniforms.end(); ++ui) { - std::map< MString, ShaderAttribute >::iterator sai = m_globalAttributes.find( ui->name ); - if (sai != m_globalAttributes.end()) - { - SetAttributeInternal(sai->first, sai->second); - } + ShaderAttribute* a = m_globalAttributes.get( ui->name ); + if( a ) + SetAttributeInternal(ui->name,*a); } } @@ -459,8 +457,7 @@ void Shader::RemoveAttribute(const MString& name) { - std::map< MString, ShaderAttribute>::iterator i = m_globalAttributes.find( name ); - if ( i != m_globalAttributes.end() ) m_globalAttributes.erase( i ); + m_globalAttributes.remove( name ); //no sense in unsetting it in the current shader, what would we set it to? } @@ -491,7 +488,7 @@ } } -std::map< MString, ShaderAttribute> Shader::m_globalAttributes; +MHash< ShaderAttribute> Shader::m_globalAttributes; /* * Copyright (c) 2009 Charles Lohr Modified: Mercury2/src/Shader.h =================================================================== --- Mercury2/src/Shader.h 2009-08-18 22:27:31 UTC (rev 495) +++ Mercury2/src/Shader.h 2009-08-18 22:38:55 UTC (rev 496) @@ -2,7 +2,7 @@ #define SHADER_H #include <MercuryAsset.h> -#include <map> +#include <MercuryHash.h> #include <vector> #include <MercuryMatrix.h> @@ -49,7 +49,7 @@ 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; + MHash< ShaderAttribute * > m_AllShaderAttributes; }; class UniformMap @@ -176,7 +176,7 @@ Shader * OriginalShader; //global uniform that should be applied to all shaders - static std::map< MString, ShaderAttribute > m_globalAttributes; + static MHash< ShaderAttribute > m_globalAttributes; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-08-19 01:40:48
|
Revision: 497 http://hgengine.svn.sourceforge.net/hgengine/?rev=497&view=rev Author: axlecrusher Date: 2009-08-19 01:40:37 +0000 (Wed, 19 Aug 2009) Log Message: ----------- Add program log. Modified Paths: -------------- Mercury2/src/GLHeaders.h Mercury2/src/GLHelpers.cpp Mercury2/src/HGMDLMesh.cpp Mercury2/src/HGMDLModel.cpp Mercury2/src/ImageLoader.cpp Mercury2/src/Light.cpp Mercury2/src/MQuaternion.cpp Mercury2/src/Mercury2.cpp Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryMatrix.cpp Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Mercury2/src/MercuryVertex.cpp Mercury2/src/PNGLoader.cpp Mercury2/src/Quad.cpp Mercury2/src/RawImageData.cpp Mercury2/src/Shader.cpp Added Paths: ----------- Mercury2/src/MercuryLog.cpp Mercury2/src/MercuryLog.h Modified: Mercury2/src/GLHeaders.h =================================================================== --- Mercury2/src/GLHeaders.h 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/GLHeaders.h 2009-08-19 01:40:37 UTC (rev 497) @@ -21,16 +21,18 @@ #include <GLHelpers.h> #include <assert.h> +#include <MercuryLog.h> + #define GLERRORCHECK { \ uint32_t e = glGetError(); \ if ( e != GL_NO_ERROR ) { \ -printf("GL Error:%s\n", GlError2String(e).c_str()); \ +LOG.Write(ssprintf("GL Error:%s", GlError2String(e).c_str())); \ assert(0); } } #define CHECKFBO { \ uint32_t e = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); \ if ( e != GL_FRAMEBUFFER_COMPLETE ) { \ -printf("GL FBO Error:%s\n", GlError2String(e).c_str()); \ +LOG.Write(ssprintf("GL FBO Error:%s", GlError2String(e).c_str())); \ assert(0); } } Modified: Mercury2/src/GLHelpers.cpp =================================================================== --- Mercury2/src/GLHelpers.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/GLHelpers.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -97,10 +97,10 @@ case RGBA16F: return GL_RGBA16F_ARB; case RGBA32F: - printf( "GL_RGBA32F_ARB unsupported using GL_RGBA16F_ARB\n" ); + LOG.Write("GL_RGBA32F_ARB unsupported using GL_RGBA16F_ARB" ); return GL_RGBA16F_ARB; default: - printf( "Unsupported color byte type (%d)\n", cbt ); + LOG.Write(ssprintf( "Unsupported color byte type (%d)", cbt )); return GL_RGB; } Modified: Mercury2/src/HGMDLMesh.cpp =================================================================== --- Mercury2/src/HGMDLMesh.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/HGMDLMesh.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -41,7 +41,7 @@ uint32_t extraDataCount; hgmdl->Read( &extraDataCount, sizeof( uint32_t ) ); - printf("has %d extras\n", extraDataCount); + LOG.Write(ssprintf("has %d extras", extraDataCount)); for (uint32_t i = 0; i < extraDataCount; ++i) { ReadExtraData(hgmdl); @@ -62,7 +62,7 @@ } default: { - printf("Junk extra type '%x'\n", type); + LOG.Write(ssprintf("Junk extra type '%x'", type)); //read and discard as junk uint32_t length; hgmdl->Read( &length, sizeof(uint32_t) ); Modified: Mercury2/src/HGMDLModel.cpp =================================================================== --- Mercury2/src/HGMDLModel.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/HGMDLModel.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -1,5 +1,6 @@ #include <HGMDLModel.h> #include <MercuryNode.h> + REGISTER_ASSET_TYPE(HGMDLModel); const uint16_t EXPCTMJRV = 2; @@ -33,7 +34,7 @@ MString p(fingerPrint); if (p != "MBMF") { - printf("Not a HGMDL file.\n"); + LOG.Write("Not a HGMDL file."); return; } @@ -45,7 +46,7 @@ if ((majorVersion != EXPCTMJRV) || (minorVersion != EXPCTMNRV)) { - printf("Can only read HGMDL version %d.%d, this file is %d.%d\n", EXPCTMJRV,EXPCTMNRV,majorVersion,minorVersion); + LOG.Write(ssprintf("Can only read HGMDL version %d.%d, this file is %d.%d", EXPCTMJRV,EXPCTMNRV,majorVersion,minorVersion) ); return; } @@ -109,7 +110,7 @@ HGMDLModel* HGMDLModel::Generate() { - printf("new HGMDL\n"); + LOG.Write( "new HGMDL" ); return new HGMDLModel(); } @@ -124,7 +125,7 @@ MercuryFile * f = FILEMAN.Open( model->m_path ); if( !f ) { - printf( "Could not open file: \"%s\" for model\n", model->m_path.c_str() ); + LOG.Write( "Could not open file: \""+ model->m_path +"\" for model"); return 0; } Modified: Mercury2/src/ImageLoader.cpp =================================================================== --- Mercury2/src/ImageLoader.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/ImageLoader.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -1,6 +1,7 @@ #include <ImageLoader.h> #include <MercuryUtil.h> #include <Texture.h> +#include <MercuryLog.h> using namespace std; @@ -41,7 +42,7 @@ if( !f ) { - printf( "Error opening image: %s\n", filename.c_str() ); + LOG.Write( "Error opening image: "+filename ); return 0; } Modified: Mercury2/src/Light.cpp =================================================================== --- Mercury2/src/Light.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/Light.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -120,7 +120,7 @@ d = m_power * d; m_radius = Clamp<float>(0.0f, 1000.0f, d); - printf("light radius %f\n", m_radius); + LOG.Write(ssprintf("light radius %f", m_radius)); } void Light::BuildBoundingBox() Modified: Mercury2/src/MQuaternion.cpp =================================================================== --- Mercury2/src/MQuaternion.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/MQuaternion.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -1,6 +1,7 @@ #include <MQuaternion.h> #include <MercuryMath.h> #include <MercuryMatrix.h> +#include <MercuryLog.h> MQuaternion::MQuaternion() { @@ -257,7 +258,7 @@ void MQuaternion::Print(const MString& s) const { - printf("%s: %f %f %f %f\n", s.c_str(), m_wxyz[0], m_wxyz[1], m_wxyz[2], m_wxyz[3]); + LOG.Write( ssprintf("%s: %f %f %f %f", s.c_str(), m_wxyz[0], m_wxyz[1], m_wxyz[2], m_wxyz[3]) ); } //Returns the Euclidian Inner Product of two MQuaternions (Similar to Vector Dot-Product) Modified: Mercury2/src/Mercury2.cpp =================================================================== --- Mercury2/src/Mercury2.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/Mercury2.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -18,6 +18,9 @@ #include <GLHeaders.h> #include <ModuleManager.h> #include <MercuryFile.h> + +#include <MercuryLog.h> + bool SHOWBOUNDINGVOLUME = false; bool SHOWAXISES = false; bool DOOCCLUSIONCULL = false; @@ -36,9 +39,9 @@ int SignalHandler( int signal ) { char buffer[2048]; - printf( "Fatal error encountered in Mercury 2: %s\n", cn_get_crash_description( signal ) ); + LOG.Write(ssprintf( "Fatal error encountered in Mercury 2: %s", cn_get_crash_description( signal ) )); cnget_backtrace( 1, buffer, 2047 ); - printf( "%s\n", buffer ); + LOG.Write( buffer ); return 0; //Continue regular crash. } @@ -103,7 +106,7 @@ float batches = MercuryVBO::ResetBatchCount()/(float)m_count; float VBinds = MercuryVBO::ResetBindCount()/(float)m_count; float Tbinds = Texture::ReadAndResetBindCount()/(float)m_count; - printf("FPS: %f, VBO batches %f, TBinds %f, VBinds %f\n", m_count/fpsTimer.Age(), batches, Tbinds, VBinds); + LOG.Write( ssprintf("FPS: %f, VBO batches %f, TBinds %f, VBinds %f", m_count/fpsTimer.Age(), batches, Tbinds, VBinds) ); m_count = 0; fpsTimer = timer; } Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/MercuryAsset.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -116,7 +116,7 @@ std::list< std::pair< MString, Callback0R< MAutoPtr<MercuryAsset> > > >::iterator i; for (i = m_factoryCallbacks.begin(); i != m_factoryCallbacks.end(); ++i) if (i->first == t) return i->second(); - printf("WARNING: Asset type %s not found.\n", type.c_str()); + LOG.Write( "WARNING: Asset type " + type + " not found." ); return NULL; } @@ -129,6 +129,7 @@ void AssetFactory::RemoveAssetInstance(const MString& key) { m_assetInstances.remove( key ); + LOG.Write( "removed asset "+key ); } MHash< MercuryAsset*> AssetFactory::m_assetInstances; Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/MercuryAsset.h 2009-08-19 01:40:37 UTC (rev 497) @@ -8,6 +8,7 @@ #include <MSemaphore.h> #include <XMLParser.h> #include <Callback.h> +#include <MercuryLog.h> #include <MercuryHash.h> #include <list> Added: Mercury2/src/MercuryLog.cpp =================================================================== --- Mercury2/src/MercuryLog.cpp (rev 0) +++ Mercury2/src/MercuryLog.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -0,0 +1,113 @@ +#include <MercuryLog.h> +#include <iostream> + +using namespace std; + +void* MercuryLog::ThreadLoop(void* d) +{ + MercuryLog* log = static_cast<MercuryLog*>(d); + + while (true) + { + log->CopyQueue(); + log->WriteQueue(); + usleep(100000); //10x/sec + } +} + +MercuryLog::MercuryLog() +{ + m_thread.Create(MercuryLog::ThreadLoop, this, true); +} + +MercuryLog::~MercuryLog() +{ + m_thread.Halt(); + CopyQueue(); + WriteQueue(); +} + +void MercuryLog::Open(const MString& file) +{ + m_file.open(file.c_str()); +} + +void MercuryLog::Close() +{ + m_file.close(); +} + +void MercuryLog::Write(const MString& message) +{ + AutoMutexLock lock(m_mutex); + m_queue.push_back( message ); +} + +void MercuryLog::CopyQueue() +{ + AutoMutexLock lock(m_mutex); + + std::list< MString >::iterator i; + + for (i = m_queue.begin(); i != m_queue.end(); ++i) + m_outQueue.push_back( *i ); + + m_queue.clear(); +} + +void MercuryLog::WriteQueue() +{ + std::list< MString >::iterator i; + + for (i = m_outQueue.begin(); i != m_outQueue.end(); ++i) + { + const MString& m = *i; + cout << m << endl; + m_file << m << endl; + } + + m_outQueue.clear(); +} + +MercuryProgramLog& MercuryProgramLog::GetInstance() +{ + static MercuryProgramLog* pl = NULL; + if (!pl) + { + pl = new MercuryProgramLog; + pl->m_log.Open("log.txt"); + } + return *pl; +} + +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen * + * * + * * + * 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/MercuryLog.h =================================================================== --- Mercury2/src/MercuryLog.h (rev 0) +++ Mercury2/src/MercuryLog.h 2009-08-19 01:40:37 UTC (rev 497) @@ -0,0 +1,83 @@ +#ifndef MERCURYLOG_H +#define MERCURYLOG_H + +#include <fstream> +#include <list> +#include <MercuryString.h> +#include <MercuryThreads.h> + +#include <MercuryUtil.h> + +class MercuryLog +{ + public: + MercuryLog(); + ~MercuryLog(); + + static MercuryLog& GetInstance(); + + void Open(const MString& file); + void Close(); + + void Write(const MString& message); + + private: + static void* ThreadLoop(void* d); + void CopyQueue(); + void WriteQueue(); + + std::list< MString > m_queue; + std::list< MString > m_outQueue; + + std::ofstream m_file; + MercuryMutex m_mutex; + + MercuryThread m_thread; +}; + +class MercuryProgramLog +{ + public: + static MercuryProgramLog& GetInstance(); + inline MercuryLog& Log() { return m_log; } + private: + MercuryLog m_log; +}; + +static InstanceCounter<MercuryProgramLog> MLOGcounter("MercuryProgramLog"); + +#define LOG MercuryProgramLog::GetInstance().Log() + +#endif + +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen * + * * + * * + * 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. * + ***************************************************************************/ Modified: Mercury2/src/MercuryMatrix.cpp =================================================================== --- Mercury2/src/MercuryMatrix.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/MercuryMatrix.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -1,5 +1,5 @@ #include "MercuryMatrix.h" -#include <stdio.h> +#include <MercuryLog.h> MercuryMatrix::MercuryMatrix() { @@ -197,9 +197,9 @@ { for (int i = 0; i < 4; ++i) { - printf( "%f %f %f %f\n", (*this)[i][0], (*this)[i][1], (*this)[i][2], (*this)[i][3] ); + LOG.Write( ssprintf( "%f %f %f %f", (*this)[i][0], (*this)[i][1], (*this)[i][2], (*this)[i][3] ) ); } - printf("\n"); + LOG.Write("\n"); } MercuryVector MercuryMatrix::operator*(const MercuryVector& v) const Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/MercuryNode.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -374,7 +374,7 @@ std::list< std::pair< MString, Callback0R<MercuryNode*> > >::iterator i; for (i = m_factoryCallbacks.begin(); i != m_factoryCallbacks.end(); ++i) if (i->first == t) return i->second(); - printf("WARNING: Node type %s not found.\n", type.c_str()); + LOG.Write( "WARNING: Node type " + type + " not found." ); return NULL; } Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/MercuryNode.h 2009-08-19 01:40:37 UTC (rev 497) @@ -7,7 +7,9 @@ #include <XMLParser.h> #include <MercuryUtil.h> #include <MessageHandler.h> +#include <MercuryLog.h> + #include <MercuryAsset.h> #include <BoundingBox.h> @@ -156,7 +158,7 @@ MercuryNode* FactoryFunct##class() { return new class(); } \ Callback0R<MercuryNode*> factoryclbk##class( FactoryFunct##class ); \ bool GlobalRegisterSuccess##class = NodeFactory::GetInstance().RegisterFactoryCallback(#class, factoryclbk##class); \ - extern "C" { int Install##class() { printf( "Installing "#class "\n" ); NodeFactory::GetInstance().RegisterFactoryCallback(#class, factoryclbk##class); return 0; } } + extern "C" { int Install##class() { LOG.Write("Installing "#class ); NodeFactory::GetInstance().RegisterFactoryCallback(#class, factoryclbk##class); return 0; } } #endif Modified: Mercury2/src/MercuryVertex.cpp =================================================================== --- Mercury2/src/MercuryVertex.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/MercuryVertex.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -2,6 +2,7 @@ #include <MercuryUtil.h> #include <MercuryMath.h> #include <MQuaternion.h> +#include <MercuryLog.h> MercuryVertex::MercuryVertex() { @@ -120,7 +121,7 @@ void MercuryVertex::Print(const MString& s) const { - printf("%s: %f %f %f %f\n", s.c_str(), (*this)[0], (*this)[1], (*this)[2], (*this)[3]); + LOG.Write(ssprintf("%s: %f %f %f %f", s.c_str(), (*this)[0], (*this)[1], (*this)[2], (*this)[3])); } MercuryVertex MercuryVertex::Rotate(const MQuaternion& q) const Modified: Mercury2/src/PNGLoader.cpp =================================================================== --- Mercury2/src/PNGLoader.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/PNGLoader.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -1,5 +1,6 @@ #include <ImageLoader.h> #include <MercuryUtil.h> +#include <MercuryLog.h> #include <assert.h> @@ -163,7 +164,7 @@ } break; default: - printf("Invalid color byte type for PNG.\n"); + LOG.Write("Invalid color byte type for PNG."); SAFE_DELETE_ARRAY( image ); return false; } @@ -207,4 +208,4 @@ * 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. - */ \ No newline at end of file + */ Modified: Mercury2/src/Quad.cpp =================================================================== --- Mercury2/src/Quad.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/Quad.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -49,7 +49,7 @@ { Quad *asset = new Quad(); ADD_ASSET_INSTANCE(Quad,"",asset); - printf("new quad\n"); + LOG.Write( "new quad" ); return asset; } Modified: Mercury2/src/RawImageData.cpp =================================================================== --- Mercury2/src/RawImageData.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/RawImageData.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -1,5 +1,6 @@ #include <RawImageData.h> #include <MercuryUtil.h> +#include <MercuryLog.h> RawImageData::RawImageData() :m_data(NULL) @@ -25,7 +26,7 @@ return RGBA16F; else if (s == "RGBA32F") return RGBA32F; - printf("Color Byte Type %s unknown\n", s.c_str()); + LOG.Write( "Color Byte Type " + s + " unknown" ); return RGB; } Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-08-18 22:38:55 UTC (rev 496) +++ Mercury2/src/Shader.cpp 2009-08-19 01:40:37 UTC (rev 497) @@ -123,9 +123,9 @@ if( f1 == 0 || f2 == 0 ) { if( !f1 ) - printf( "Could not open %s.\n", (char*)s1.c_str() ); + LOG.Write(ssprintf( "Could not open %s.", (char*)s1.c_str() )); if( !f2 ) - printf( "Could not open %s.\n", (char*)s2.c_str() ); + LOG.Write(ssprintf( "Could not open %s.", (char*)s2.c_str() )); return false; } if( f1 ) @@ -134,7 +134,7 @@ Buffer = (char*)malloc( i+1 ); f1->Read( Buffer, i ); f1->Close(); - printf( "Compiling: %s\n", s1.c_str() ); + LOG.Write( "Compiling: " + s1 ); Buffer[i] = '\0'; if( !LoadShaderFrag( Buffer ) ) { @@ -143,7 +143,7 @@ f2->Close(); if( f3 ) f3->Close(); - printf( "Reporting failed shaderload. Not linking.\n" ); + LOG.Write("Reporting failed shaderload. Not linking." ); return false; } free( Buffer ); @@ -155,13 +155,13 @@ f2->Read( Buffer, i ); f2->Close(); Buffer[i] = '\0'; - printf( "Compiling: %s\n", s2.c_str() ); + LOG.Write("Compiling: %s"+s2); if( !LoadShaderVert( Buffer ) ) { if( f3 ) f3->Close(); free( Buffer ); - printf( "Reporting failed shaderload. Not linking.\n" ); + LOG.Write("Reporting failed shaderload. Not linking." ); return false; } free( Buffer ); @@ -173,11 +173,11 @@ f3->Read( Buffer, i ); f3->Close(); Buffer[i] = '\0'; - printf( "Compiling: %s\n", s3.c_str() ); + LOG.Write("Compiling: %s"+s3); if( !LoadShaderGeom( Buffer ) ) { free( Buffer ); - printf( "Reporting failed shaderload. Not linking.\n" ); + LOG.Write("Reporting failed shaderload. Not linking." ); return false; } free( Buffer ); @@ -297,7 +297,7 @@ { 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 ); + LOG.Write( ssprintf( "The last error received was: %d", ierror ) ); } for( i = 1; i < imaxvert; i++ ) { @@ -305,7 +305,7 @@ 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 ); + LOG.Write(ssprintf( "Geometry Shader loaded with a total of %d max verticies. Because there are %d max vertices, and %d preceived components per vert.", imaxvert/i, imaxvert, i )); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |