|
From: <axl...@us...> - 2009-06-23 00:59:32
|
Revision: 358
http://hgengine.svn.sourceforge.net/hgengine/?rev=358&view=rev
Author: axlecrusher
Date: 2009-06-23 00:23:23 +0000 (Tue, 23 Jun 2009)
Log Message:
-----------
add transparent pass
Modified Paths:
--------------
Mercury2/scenegraph.xml
Mercury2/src/Mercury2.cpp
Mercury2/src/MercuryNode.cpp
Mercury2/src/MercuryNode.h
Mercury2/src/RenderGraph.cpp
Mercury2/src/RenderGraph.h
Mercury2/src/Texture.cpp
Mercury2/src/Texture.h
Mercury2/src/X11Window.cpp
Added Paths:
-----------
Mercury2/flame.png
Added: Mercury2/flame.png
===================================================================
(Binary files differ)
Property changes on: Mercury2/flame.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: Mercury2/scenegraph.xml
===================================================================
--- Mercury2/scenegraph.xml 2009-06-21 13:49:48 UTC (rev 357)
+++ Mercury2/scenegraph.xml 2009-06-23 00:23:23 UTC (rev 358)
@@ -6,21 +6,27 @@
<node type="cameranode" movx="0" movz="0" movy="0" rotx="0" roty="0" rotz="0" name="camera">
<node type="viewport" fov="45" aspect="1.3333" near="0.01" far="100" name="vp"/>
</node>
- <asset type="texture" file="screenFBO_0" dynamic="true"/>
+<!-- <asset type="texture" file="screenFBO_0" dynamic="true"/>
<asset type="fullscreenquad"/>
<node type="mercuryfbo" width="640" height="480" depth="true" tnum="2" name="screenFBO" usescreensize="true">
<asset type="shader" file="testShader"/>
- <node type="transformnode" rotx="-90" movz="-10" movx="0" movy="-5">
+--> <node type="transformnode" rotx="-90" movz="-10" movx="0" movy="-5">
<asset type="texture" file="map.png"/>
<asset type="hgmdlmodel" file="map.hgmdl" />
</node>
<node type="mercurynode" name="lampForest" >
- <asset type="texture" file="lamp.png"/>
<node type="transformnode" movz="-5" movx="0" movy="0" name="lamprow" >
- <node type="transformnode" rotx="-90" name="lamp">
- <node type="billboardnode" billboardaxis="0,0,1" spheremode="true" >
+ <node type="mercurynode" name="lamp">
+ <node type="transformnode" rotx="-90" >
+ <asset type="texture" file="lamp.png"/>
<asset type="hgmdlmodel" file="lampN.hgmdl" />
</node>
+ <node type="billboardnode" billboardaxis="0,1,0" spheremode="true" >
+ <node type="transformnode" roty="180" scalex="0.1" scaley="0.1" alphaPath="true">
+ <asset type="texture" file="flame.png"/>
+ <asset type="quad"/>
+ </node>
+ </node>
</node>
<node type="transformnode" movx="1" fallback="lamprow.lamp" />
<node type="transformnode" movx="2" fallback="lamprow.lamp" />
@@ -36,5 +42,5 @@
<node type="transformnode" movz="-4" fallback="lampForest.lamprow"/>
<node type="transformnode" movz="-3" fallback="lampForest.lamprow"/>
</node>
- </node>
+<!-- </node> -->
</SceneGraph>
Modified: Mercury2/src/Mercury2.cpp
===================================================================
--- Mercury2/src/Mercury2.cpp 2009-06-21 13:49:48 UTC (rev 357)
+++ Mercury2/src/Mercury2.cpp 2009-06-23 00:23:23 UTC (rev 358)
@@ -6,7 +6,7 @@
#include <XMLParser.h>
-//#include <RenderableNode.h>
+#include <RenderGraph.h>
#include <MercuryCrash.h>
#include <MercuryBacktrace.h>
@@ -76,6 +76,7 @@
MESSAGEMAN::GetInstance().PumpMessages( timer.MicrosecondsSinceInit() );
root->RecursiveUpdate( timer.Age() ); //comment to use threads
+ CURRENTRENDERGRAPH = &renderGraph;
if ( MercuryNode::NeedsRebuild() )
{
renderGraph.Build(root);
@@ -86,6 +87,7 @@
// RenderableNode::RecursiveRender(root);
// printf("\n");
root->RecursiveRender();
+ renderGraph.RenderAlpha();
w->SwapBuffers();
++m_count;
Modified: Mercury2/src/MercuryNode.cpp
===================================================================
--- Mercury2/src/MercuryNode.cpp 2009-06-21 13:49:48 UTC (rev 357)
+++ Mercury2/src/MercuryNode.cpp 2009-06-23 00:23:23 UTC (rev 358)
@@ -7,13 +7,14 @@
#include <GLHeaders.h>
#include <Shader.h>
+#include <RenderGraph.h>
using namespace std;
REGISTER_NODE_TYPE(MercuryNode);
MercuryNode::MercuryNode()
- :m_parent(NULL), m_prevSibling(NULL), m_nextSibling(NULL), m_hidden(false)
+ :m_parent(NULL), m_prevSibling(NULL), m_nextSibling(NULL), m_hidden(false), m_useAlphaPath(false)
{
}
@@ -104,7 +105,7 @@
child->RecursiveUpdate(dTime);
}
-void MercuryNode::RecursiveRender()
+void MercuryNode::RecursiveRender(bool doAlpha)
{
MercuryMatrix modelView;
ShaderAttribute sa;
@@ -126,7 +127,12 @@
//call render on other render graph entries under me
for (MercuryNode* child = FirstChild(); child != NULL; child = NextChild(child))
- child->RecursiveRender();
+ {
+ if (child->m_useAlphaPath && !doAlpha)
+ CURRENTRENDERGRAPH->AddAlphaNode(child);
+ else
+ child->RecursiveRender();
+ }
glLoadMatrixf( modelView.Ptr() );
Shader::SetAttribute("HG_ModelMatrix", sa);
@@ -150,6 +156,9 @@
if ( !node.Attribute("hidden").empty() )
m_hidden = node.Attribute("hidden")=="true"?true:false;
+ if ( !node.Attribute("alphaPath").empty() )
+ m_useAlphaPath = node.Attribute("alphaPath")=="true"?true:false;
+
//Not much to do here except run through all the children nodes
for (XMLNode child = node.Child(); child.IsValid(); child = child.NextNode())
{
Modified: Mercury2/src/MercuryNode.h
===================================================================
--- Mercury2/src/MercuryNode.h 2009-06-21 13:49:48 UTC (rev 357)
+++ Mercury2/src/MercuryNode.h 2009-06-23 00:23:23 UTC (rev 358)
@@ -47,7 +47,7 @@
void ThreadedUpdate(float dTime);
- void RecursiveRender();
+ void RecursiveRender(bool doAlpha = false);
///Run on parent when a child is added
virtual void OnAddChild() {};
@@ -98,6 +98,7 @@
static bool m_rebuildRenderGraph;
MString m_name;
bool m_hidden;
+ bool m_useAlphaPath;
private:
bool IsInAssetList(MercuryAsset* asset) const;
Modified: Mercury2/src/RenderGraph.cpp
===================================================================
--- Mercury2/src/RenderGraph.cpp 2009-06-21 13:49:48 UTC (rev 357)
+++ Mercury2/src/RenderGraph.cpp 2009-06-23 00:23:23 UTC (rev 358)
@@ -4,7 +4,11 @@
#include <GLHeaders.h>
#include <Shader.h>
+#include <Viewport.h>
+#include <Texture.h>
+RenderGraph* CURRENTRENDERGRAPH = NULL;
+
void RenderGraphEntry::Render()
{
MercuryMatrix modelView;
@@ -65,6 +69,60 @@
// entry = lastEntry;
}
+void RenderGraph::AddAlphaNode( MercuryNode* node )
+{
+ StoreRenderState srs;
+ srs.Save();
+ srs.Matrix = node->FindGlobalMatrix();
+ srs.Node = node;
+
+ MercuryVertex p = srs.Matrix * MercuryVertex(0,0,0,1);
+
+ //order from back to front (ensure furthest has lowest number and is first)
+ float length = (p - EYE).Length() * -1;
+ m_alphaNodesQueue.Insert(length, srs);
+}
+
+void RenderGraph::RenderAlpha()
+{
+ while ( !m_alphaNodesQueue.empty() )
+ {
+ StoreRenderState& srs = m_alphaNodesQueue.GetNext();
+
+ std::list< MercuryAsset* >::iterator i = srs.Assets.begin();
+ for (;i != srs.Assets.end(); ++i)
+ {
+ (*i)->PreRender(srs.Node);
+ (*i)->Render(srs.Node);
+ }
+
+ srs.Node->RecursiveRender(true);
+
+ for (i = srs.Assets.begin();i != srs.Assets.end(); ++i)
+ (*i)->PostRender(srs.Node);
+
+ m_alphaNodesQueue.PopNext();
+ }
+}
+
+StoreRenderState::StoreRenderState()
+ :Node(NULL)
+{
+}
+
+void StoreRenderState::Save()
+{
+ //get assets for current textures
+ const std::list< Texture* >& textures = Texture::GetActiveTextures();
+ std::list< Texture* >::const_iterator i = textures.begin();
+ for (;i != textures.end(); ++i)
+ Assets.push_back( *i );
+
+ //save the active shader
+ Shader* s = Shader::GetCurrentShader();
+ if (s) Assets.push_back(s);
+}
+
/****************************************************************************
* Copyright (C) 2009 by Joshua Allen *
* *
Modified: Mercury2/src/RenderGraph.h
===================================================================
--- Mercury2/src/RenderGraph.h 2009-06-21 13:49:48 UTC (rev 357)
+++ Mercury2/src/RenderGraph.h 2009-06-23 00:23:23 UTC (rev 358)
@@ -3,6 +3,7 @@
#include <MercuryNode.h>
//#include <RenderableNode.h>
+#include <PriorityQueue.h>
class RenderGraphEntry
{
@@ -26,16 +27,38 @@
const MercuryMatrix* m_matrix;
};
+/** Tries to get pointers to all assets needed to rebuild an accurate render state.
+This will only work for restoring the render state within the same render loop.
+**/
+class StoreRenderState
+{
+ public:
+ StoreRenderState();
+ void Save();
+ MercuryNode* Node;
+ MercuryMatrix Matrix;
+// private:
+ std::list< MercuryAsset* > Assets;
+};
+
class RenderGraph
{
public:
void Build( MercuryNode* node );
inline void Render() { m_root.Render(); }
+
+ void AddAlphaNode( MercuryNode* node );
+ void RenderAlpha();
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;
};
+extern RenderGraph* CURRENTRENDERGRAPH;
+
#endif
/****************************************************************************
Modified: Mercury2/src/Texture.cpp
===================================================================
--- Mercury2/src/Texture.cpp 2009-06-21 13:49:48 UTC (rev 357)
+++ Mercury2/src/Texture.cpp 2009-06-23 00:23:23 UTC (rev 358)
@@ -15,7 +15,7 @@
if (!m_initTextureSuccess)
{
m_initTextureSuccess = true;
- m_activeTextures = 0;
+ m_numActiveTextures = 0;
}
}
@@ -76,7 +76,7 @@
GL_UNSIGNED_BYTE,
m_raw->m_data);
*/
- gluBuild2DMipmaps( GL_TEXTURE_2D, 3, 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);
@@ -121,7 +121,7 @@
void Texture::BindTexture()
{
- m_textureResource = GL_TEXTURE0+m_activeTextures;
+ m_textureResource = GL_TEXTURE0+m_numActiveTextures;
glActiveTexture( m_textureResource );
glClientActiveTextureARB(m_textureResource);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
@@ -134,9 +134,11 @@
ShaderAttribute sa;
sa.type = ShaderAttribute::TYPE_SAMPLER;
sa.value.iSampler = m_textureResource;
- Shader::SetAttribute( ssprintf("HG_Texture%d", m_activeTextures), sa);
+ Shader::SetAttribute( ssprintf("HG_Texture%d", m_numActiveTextures), sa);
- ++m_activeTextures;
+ m_activeTextures.push_back(this);
+
+ ++m_numActiveTextures;
++m_textureBinds;
}
@@ -148,9 +150,10 @@
glDisable( GL_TEXTURE_2D );
GLERRORCHECK;
- Shader::RemoveAttribute( ssprintf("HG_Texture%d", m_activeTextures) );
+ Shader::RemoveAttribute( ssprintf("HG_Texture%d", m_numActiveTextures) );
+ m_activeTextures.pop_back();
- --m_activeTextures;
+ --m_numActiveTextures;
}
void Texture::LoadImagePath(const MString& path)
@@ -220,8 +223,9 @@
}
bool Texture::m_initTextureSuccess = false;
-uint8_t Texture::m_activeTextures = 0;
+uint8_t Texture::m_numActiveTextures = 0;
uint32_t Texture::m_textureBinds = 0;
+std::list< Texture* > Texture::m_activeTextures;
/***************************************************************************
* Copyright (C) 2008 by Joshua Allen *
Modified: Mercury2/src/Texture.h
===================================================================
--- Mercury2/src/Texture.h 2009-06-21 13:49:48 UTC (rev 357)
+++ Mercury2/src/Texture.h 2009-06-23 00:23:23 UTC (rev 358)
@@ -21,7 +21,7 @@
void LoadFromRaw();
- inline static uint8_t NumberActiveTextures() { return m_activeTextures; }
+ inline static uint8_t NumberActiveTextures() { return m_numActiveTextures; }
inline static uint32_t ReadAndResetBindCount() { uint32_t t = m_textureBinds; m_textureBinds = 0; return t; }
inline uint32_t TextureID() const { return m_textureID; }
@@ -31,6 +31,7 @@
static Texture* Generate();
static MAutoPtr< Texture > LoadFromFile(const MString& path);
static MAutoPtr< Texture > LoadDynamicTexture(const MString& name);
+ static const std::list< Texture* >& GetActiveTextures() { return m_activeTextures; }
void SetRawData(RawImageData* raw);
private:
@@ -44,8 +45,10 @@
uint32_t m_textureResource;
static bool m_initTextureSuccess;
- static uint8_t m_activeTextures;
+ static uint8_t m_numActiveTextures;
static uint32_t m_textureBinds;
+ static std::list< Texture* > m_activeTextures;
+
// MString m_filename;
};
Modified: Mercury2/src/X11Window.cpp
===================================================================
--- Mercury2/src/X11Window.cpp 2009-06-21 13:49:48 UTC (rev 357)
+++ Mercury2/src/X11Window.cpp 2009-06-23 00:23:23 UTC (rev 358)
@@ -77,6 +77,8 @@
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_NORMALIZE);
+
+ glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
X11Window::~X11Window()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|