Some minor modifications in RenderImage implementation
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1363 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
c237305f9b
commit
2e40f341ba
@ -200,7 +200,7 @@ bool RenderImageImplPBuffer::Activate(bool active)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// /see RenderImageImpl::UpdateTexture
|
/// /see RenderImageImpl::UpdateTexture
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool RenderImageImplPBuffer::UpdateTexture(unsigned int textureId)
|
void RenderImageImplPBuffer::UpdateTexture(unsigned int textureId)
|
||||||
{
|
{
|
||||||
if (Activate(true))
|
if (Activate(true))
|
||||||
{
|
{
|
||||||
@ -215,11 +215,7 @@ bool RenderImageImplPBuffer::UpdateTexture(unsigned int textureId)
|
|||||||
GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, myWidth, myHeight));
|
GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, myWidth, myHeight));
|
||||||
|
|
||||||
GLCheck(glBindTexture(GL_TEXTURE_2D, previous));
|
GLCheck(glBindTexture(GL_TEXTURE_2D, previous));
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
|
@ -29,11 +29,11 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/RenderImageImpl.hpp>
|
#include <SFML/Graphics/RenderImageImpl.hpp>
|
||||||
#include <SFML/Graphics/GLEW/glew.h>
|
#include <SFML/Graphics/GLEW/glew.h>
|
||||||
#include <SFML/Graphics/GLEW/glxew.h>
|
#include <SFML/Graphics/GLEW/glxew.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
namespace priv
|
namespace priv
|
||||||
@ -83,11 +83,11 @@ private :
|
|||||||
/// /see RenderImageImpl::UpdateTexture
|
/// /see RenderImageImpl::UpdateTexture
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool UpdateTexture(unsigned textureId);
|
virtual void UpdateTexture(unsigned textureId);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
::Display* myDisplay; ///< Connection to the X display
|
::Display* myDisplay; ///< Connection to the X display
|
||||||
GLXPbuffer myPBuffer; ///< P-Buffer
|
GLXPbuffer myPBuffer; ///< P-Buffer
|
||||||
GLXContext myContext; ///< Associated OpenGL context
|
GLXContext myContext; ///< Associated OpenGL context
|
||||||
|
@ -134,9 +134,10 @@ void RenderImage::Display()
|
|||||||
// Update the target image
|
// Update the target image
|
||||||
if (myRenderImage)
|
if (myRenderImage)
|
||||||
{
|
{
|
||||||
bool pixelsFlipped = myRenderImage->UpdateTexture(myImage.myTexture);
|
myRenderImage->UpdateTexture(myImage.myTexture);
|
||||||
myImage.myPixelsFlipped = pixelsFlipped;
|
|
||||||
myImage.myArrayUpdated = false;
|
myImage.myPixelsFlipped = true;
|
||||||
|
myImage.myArrayUpdated = false;
|
||||||
myImage.myTextureUpdated = true;
|
myImage.myTextureUpdated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,10 +74,8 @@ public :
|
|||||||
///
|
///
|
||||||
/// \param textureId : OpenGL identifier of the target texture
|
/// \param textureId : OpenGL identifier of the target texture
|
||||||
///
|
///
|
||||||
/// \return True if the new pixels are flipped vertically
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool UpdateTexture(unsigned int textureId) = 0;
|
virtual void UpdateTexture(unsigned int textureId) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#include <SFML/Graphics/RenderImageImplFBO.hpp>
|
#include <SFML/Graphics/RenderImageImplFBO.hpp>
|
||||||
#include <SFML/Graphics/Image.hpp>
|
#include <SFML/Graphics/Image.hpp>
|
||||||
#include <SFML/Graphics/GLCheck.hpp>
|
#include <SFML/Graphics/GLCheck.hpp>
|
||||||
#include <SFML/Window/Context.hpp>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
@ -41,8 +40,7 @@ namespace priv
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
RenderImageImplFBO::RenderImageImplFBO() :
|
RenderImageImplFBO::RenderImageImplFBO() :
|
||||||
myFrameBuffer(0),
|
myFrameBuffer(0),
|
||||||
myDepthBuffer(0),
|
myDepthBuffer(0)
|
||||||
myContext (NULL)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -66,9 +64,6 @@ RenderImageImplFBO::~RenderImageImplFBO()
|
|||||||
GLuint frameBuffer = static_cast<GLuint>(myFrameBuffer);
|
GLuint frameBuffer = static_cast<GLuint>(myFrameBuffer);
|
||||||
GLCheck(glDeleteFramebuffersEXT(1, &frameBuffer));
|
GLCheck(glDeleteFramebuffersEXT(1, &frameBuffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy the context
|
|
||||||
delete myContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -89,32 +84,18 @@ bool RenderImageImplFBO::IsSupported()
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool RenderImageImplFBO::Create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer)
|
bool RenderImageImplFBO::Create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer)
|
||||||
{
|
{
|
||||||
// Create the context if not already done
|
// Create the framebuffer object
|
||||||
if (!myContext)
|
GLuint frameBuffer = 0;
|
||||||
myContext = new Context;
|
GLCheck(glGenFramebuffersEXT(1, &frameBuffer));
|
||||||
|
myFrameBuffer = static_cast<unsigned int>(frameBuffer);
|
||||||
// Create the framebuffer object if not already done
|
|
||||||
if (!myFrameBuffer)
|
if (!myFrameBuffer)
|
||||||
{
|
{
|
||||||
GLuint frameBuffer = 0;
|
std::cerr << "Impossible to create render image (failed to create the frame buffer object)" << std::endl;
|
||||||
GLCheck(glGenFramebuffersEXT(1, &frameBuffer));
|
return false;
|
||||||
myFrameBuffer = static_cast<unsigned int>(frameBuffer);
|
|
||||||
if (!myFrameBuffer)
|
|
||||||
{
|
|
||||||
std::cerr << "Impossible to create render image (failed to create the frame buffer object)" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind the framebuffer
|
|
||||||
GLCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, myFrameBuffer));
|
GLCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, myFrameBuffer));
|
||||||
|
|
||||||
// Create the depth buffer
|
// Create the depth buffer if requested
|
||||||
if (myDepthBuffer)
|
|
||||||
{
|
|
||||||
GLuint depth = static_cast<GLuint>(myDepthBuffer);
|
|
||||||
GLCheck(glDeleteRenderbuffersEXT(1, &depth));
|
|
||||||
}
|
|
||||||
if (depthBuffer)
|
if (depthBuffer)
|
||||||
{
|
{
|
||||||
GLuint depth = 0;
|
GLuint depth = 0;
|
||||||
@ -150,8 +131,7 @@ bool RenderImageImplFBO::Create(unsigned int width, unsigned int height, unsigne
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool RenderImageImplFBO::Activate(bool active)
|
bool RenderImageImplFBO::Activate(bool active)
|
||||||
{
|
{
|
||||||
if (myContext)
|
myContext.SetActive(active);
|
||||||
myContext->SetActive(active);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -159,10 +139,9 @@ bool RenderImageImplFBO::Activate(bool active)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// /see RenderImageImpl::UpdateTexture
|
/// /see RenderImageImpl::UpdateTexture
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool RenderImageImplFBO::UpdateTexture(unsigned int)
|
void RenderImageImplFBO::UpdateTexture(unsigned int)
|
||||||
{
|
{
|
||||||
// Nothing to do: the FBO draws directly into the target image
|
// Nothing to do: the FBO draws directly into the target image
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
|
@ -29,17 +29,16 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/RenderImageImpl.hpp>
|
#include <SFML/Graphics/RenderImageImpl.hpp>
|
||||||
|
#include <SFML/Window/Context.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class Context;
|
|
||||||
|
|
||||||
namespace priv
|
namespace priv
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Specialization of RenderImageImpl using the
|
/// Specialization of RenderImageImpl using the
|
||||||
/// FrameBuffer Object extension
|
/// Frame Buffer Object extension
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class RenderImageImplFBO : public RenderImageImpl
|
class RenderImageImplFBO : public RenderImageImpl
|
||||||
{
|
{
|
||||||
@ -83,14 +82,14 @@ private :
|
|||||||
/// /see RenderImageImpl::UpdateTexture
|
/// /see RenderImageImpl::UpdateTexture
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool UpdateTexture(unsigned textureId);
|
virtual void UpdateTexture(unsigned textureId);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned int myFrameBuffer; ///< OpenGL frame buffer object
|
unsigned int myFrameBuffer; ///< OpenGL frame buffer object
|
||||||
unsigned int myDepthBuffer; ///< Optional depth buffer attached to the frame buffer
|
unsigned int myDepthBuffer; ///< Optional depth buffer attached to the frame buffer
|
||||||
Context* myContext; ///< Needs a separate OpenGL context for not messing up the other ones
|
Context myContext; ///< Needs a separate OpenGL context for not messing up the other ones
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
|
@ -191,7 +191,7 @@ bool RenderImageImplPBuffer::Activate(bool active)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// /see RenderImageImpl::UpdateTexture
|
/// /see RenderImageImpl::UpdateTexture
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool RenderImageImplPBuffer::UpdateTexture(unsigned int textureId)
|
void RenderImageImplPBuffer::UpdateTexture(unsigned int textureId)
|
||||||
{
|
{
|
||||||
if (Activate(true))
|
if (Activate(true))
|
||||||
{
|
{
|
||||||
@ -206,11 +206,7 @@ bool RenderImageImplPBuffer::UpdateTexture(unsigned int textureId)
|
|||||||
GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, myWidth, myHeight));
|
GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, myWidth, myHeight));
|
||||||
|
|
||||||
GLCheck(glBindTexture(GL_TEXTURE_2D, previous));
|
GLCheck(glBindTexture(GL_TEXTURE_2D, previous));
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
|
@ -82,7 +82,7 @@ private :
|
|||||||
/// /see RenderImageImpl::UpdateTexture
|
/// /see RenderImageImpl::UpdateTexture
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool UpdateTexture(unsigned textureId);
|
virtual void UpdateTexture(unsigned textureId);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
|
Loading…
Reference in New Issue
Block a user