|
From: <axl...@us...> - 2009-06-14 03:34:32
|
Revision: 320
http://hgengine.svn.sourceforge.net/hgengine/?rev=320&view=rev
Author: axlecrusher
Date: 2009-06-14 03:34:30 +0000 (Sun, 14 Jun 2009)
Log Message:
-----------
handle screen resize a little better
Modified Paths:
--------------
Mercury2/scenegraph.xml
Mercury2/src/MercuryAsset.h
Mercury2/src/MercuryFBO.cpp
Mercury2/src/MercuryFBO.h
Mercury2/src/Texture.cpp
Modified: Mercury2/scenegraph.xml
===================================================================
--- Mercury2/scenegraph.xml 2009-06-14 02:03:25 UTC (rev 319)
+++ Mercury2/scenegraph.xml 2009-06-14 03:34:30 UTC (rev 320)
@@ -7,10 +7,10 @@
<node type="viewport" fov="45" aspect="1.3333" near="0.01" far="100"/>
</node>
<node type="renderablenode">
- <asset type="texture" file="screenFBO" dynamic="true"/>
+ <asset type="texture" file="screenFBO_0" dynamic="true"/>
<asset type="fullscreenquad"/>
</node>
- <node type="mercuryfbo" width="640" height="480" depth="true" tnum="1" name="screenFBO">
+ <node type="mercuryfbo" width="640" height="480" depth="true" tnum="1" name="screenFBO" usescreensize="true">
<node type="transformnode" rotx="-90" movz="-10" movx="0" movy="-5">
<node type="renderablenode">
<asset type="texture" file="map.png"/>
Modified: Mercury2/src/MercuryAsset.h
===================================================================
--- Mercury2/src/MercuryAsset.h 2009-06-14 02:03:25 UTC (rev 319)
+++ Mercury2/src/MercuryAsset.h 2009-06-14 03:34:30 UTC (rev 320)
@@ -40,7 +40,7 @@
inline const BoundingVolume* GetBoundingVolume() const { return m_boundingVolume; }
inline const MString& Path() const { return m_path; }
-
+
void DrawAxes();
protected:
void SetLoadState(LoadState ls); //thread safe
Modified: Mercury2/src/MercuryFBO.cpp
===================================================================
--- Mercury2/src/MercuryFBO.cpp 2009-06-14 02:03:25 UTC (rev 319)
+++ Mercury2/src/MercuryFBO.cpp 2009-06-14 03:34:30 UTC (rev 320)
@@ -1,10 +1,11 @@
#include <MercuryFBO.h>
#include <GLHeaders.h>
+#include <MercuryWindow.h>
REGISTER_NODE_TYPE(MercuryFBO);
MercuryFBO::MercuryFBO()
- :m_fboID(0), m_depthBufferID(0), m_initiated(false), m_useDepth(false), m_numTextures(0)
+ :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;
}
@@ -29,15 +30,27 @@
m_initiated = true;
+ GenerateFBO();
+ Bind();
+
+// CHECKFBO; //Incomplete FBO
+}
+
+void MercuryFBO::GenerateFBO()
+{
if( m_useDepth ) glGenRenderbuffersEXT( 1, &m_depthBufferID );
glGenFramebuffersEXT( 1, &m_fboID );
for (uint8_t i = 0; i < m_numTextures; ++i)
{
- m_textures[i] = Texture::LoadDynamicTexture(m_name);
- m_textures[i]->MakeDynamic(m_width, m_height,m_name);
+ 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);
}
-
+}
+
+void MercuryFBO::Bind()
+{
if( m_useDepth )
{
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, m_fboID );
@@ -51,9 +64,9 @@
if( m_useDepth )
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBufferID );
+}
- CHECKFBO; //Incomplete FBO
-}
+
/*
void MercuryFBO::InitFBOBeforeRender()
{
@@ -66,6 +79,24 @@
void MercuryFBO::PreRender(const MercuryMatrix& matrix)
{
if ( !m_initiated ) Setup();
+
+ if ( m_useScreenSize )
+ {
+ int w = MercuryWindow::GetCurrentWindow()->Width();
+ int h = MercuryWindow::GetCurrentWindow()->Height();
+ if ((m_width != w) || (m_height != h))
+ {
+ m_width = w; m_height = h;
+ 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);
+ }
+ Bind();
+ }
+ }
+ GLERRORCHECK;
+
RenderableNode::PreRender(matrix);
}
@@ -80,16 +111,22 @@
// m_lastInStask = m_lastRendered;
}
+ GLERRORCHECK;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ GLERRORCHECK;
glPushAttrib(GL_VIEWPORT_BIT);
-// glViewport(0,0,m_width, m_width);
+ if ( !m_useScreenSize ) glViewport(0,0,m_width, m_height);
+
+ GLERRORCHECK;
RenderableNode::Render(matrix);
+ GLERRORCHECK;
}
void MercuryFBO::PostRender(const MercuryMatrix& matrix)
{
+ GLERRORCHECK;
glPopAttrib();
// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_lastInStask);
@@ -99,6 +136,7 @@
GLERRORCHECK;
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); //unbind
+
CHECKFBO;
GLERRORCHECK;
@@ -119,6 +157,9 @@
if ( !node.Attribute("tnum").empty() )
SetNumTextures( StrToInt(node.Attribute("tnum")) );
+ if ( !node.Attribute("usescreensize").empty() )
+ m_useScreenSize = node.Attribute("usescreensize") == "true"?true:false;
+
RenderableNode::LoadFromXML(node);
}
Modified: Mercury2/src/MercuryFBO.h
===================================================================
--- Mercury2/src/MercuryFBO.h 2009-06-14 02:03:25 UTC (rev 319)
+++ Mercury2/src/MercuryFBO.h 2009-06-14 03:34:30 UTC (rev 320)
@@ -27,10 +27,12 @@
private:
void Setup();
void Clean();
+ void GenerateFBO();
+ void Bind();
// void InitFBOBeforeRender();
uint32_t m_fboID, m_depthBufferID;
- bool m_initiated, m_useDepth;
+ bool m_initiated, m_useDepth, m_useScreenSize;
uint16_t m_width, m_height;
// uint32_t m_textureID[4];
Texture *m_textures[4];
Modified: Mercury2/src/Texture.cpp
===================================================================
--- Mercury2/src/Texture.cpp 2009-06-14 02:03:25 UTC (rev 319)
+++ Mercury2/src/Texture.cpp 2009-06-14 03:34:30 UTC (rev 320)
@@ -167,16 +167,16 @@
void Texture::MakeDynamic(uint16_t width, uint16_t height, const MString& name)
{
- Clean();
+// Clean();
SetLoadState(LOADED);
REMOVE_ASSET_INSTANCE(TEXTURE, m_path);
m_path = "DYNATEXT"+name;
ADD_ASSET_INSTANCE(Texture, m_path, this);
-
- glGenTextures( 1, &m_textureID );
- printf("booo %d\n", m_textureID);
+
+ if (m_textureID == 0) printf("booo %d\n", m_textureID);
+ 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 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|