mirror of
https://github.com/SFML/SFML.git
synced 2024-12-01 15:51:04 +08:00
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
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderImageImplPBuffer::UpdateTexture(unsigned int textureId)
|
||||
void RenderImageImplPBuffer::UpdateTexture(unsigned int textureId)
|
||||
{
|
||||
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(glBindTexture(GL_TEXTURE_2D, previous));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
@ -83,7 +83,7 @@ private :
|
||||
/// /see RenderImageImpl::UpdateTexture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool UpdateTexture(unsigned textureId);
|
||||
virtual void UpdateTexture(unsigned textureId);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
|
@ -134,8 +134,9 @@ void RenderImage::Display()
|
||||
// Update the target image
|
||||
if (myRenderImage)
|
||||
{
|
||||
bool pixelsFlipped = myRenderImage->UpdateTexture(myImage.myTexture);
|
||||
myImage.myPixelsFlipped = pixelsFlipped;
|
||||
myRenderImage->UpdateTexture(myImage.myTexture);
|
||||
|
||||
myImage.myPixelsFlipped = true;
|
||||
myImage.myArrayUpdated = false;
|
||||
myImage.myTextureUpdated = true;
|
||||
}
|
||||
|
@ -74,10 +74,8 @@ public :
|
||||
///
|
||||
/// \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
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include <SFML/Graphics/RenderImageImplFBO.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <SFML/Window/Context.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@ -41,8 +40,7 @@ namespace priv
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderImageImplFBO::RenderImageImplFBO() :
|
||||
myFrameBuffer(0),
|
||||
myDepthBuffer(0),
|
||||
myContext (NULL)
|
||||
myDepthBuffer(0)
|
||||
{
|
||||
|
||||
}
|
||||
@ -66,9 +64,6 @@ RenderImageImplFBO::~RenderImageImplFBO()
|
||||
GLuint frameBuffer = static_cast<GLuint>(myFrameBuffer);
|
||||
GLCheck(glDeleteFramebuffersEXT(1, &frameBuffer));
|
||||
}
|
||||
|
||||
// Destroy the context
|
||||
delete myContext;
|
||||
}
|
||||
|
||||
|
||||
@ -89,13 +84,7 @@ bool RenderImageImplFBO::IsSupported()
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderImageImplFBO::Create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer)
|
||||
{
|
||||
// Create the context if not already done
|
||||
if (!myContext)
|
||||
myContext = new Context;
|
||||
|
||||
// Create the framebuffer object if not already done
|
||||
if (!myFrameBuffer)
|
||||
{
|
||||
// Create the framebuffer object
|
||||
GLuint frameBuffer = 0;
|
||||
GLCheck(glGenFramebuffersEXT(1, &frameBuffer));
|
||||
myFrameBuffer = static_cast<unsigned int>(frameBuffer);
|
||||
@ -104,17 +93,9 @@ bool RenderImageImplFBO::Create(unsigned int width, unsigned int height, unsigne
|
||||
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));
|
||||
|
||||
// Create the depth buffer
|
||||
if (myDepthBuffer)
|
||||
{
|
||||
GLuint depth = static_cast<GLuint>(myDepthBuffer);
|
||||
GLCheck(glDeleteRenderbuffersEXT(1, &depth));
|
||||
}
|
||||
// Create the depth buffer if requested
|
||||
if (depthBuffer)
|
||||
{
|
||||
GLuint depth = 0;
|
||||
@ -150,8 +131,7 @@ bool RenderImageImplFBO::Create(unsigned int width, unsigned int height, unsigne
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderImageImplFBO::Activate(bool active)
|
||||
{
|
||||
if (myContext)
|
||||
myContext->SetActive(active);
|
||||
myContext.SetActive(active);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -159,10 +139,9 @@ bool RenderImageImplFBO::Activate(bool active)
|
||||
////////////////////////////////////////////////////////////
|
||||
/// /see RenderImageImpl::UpdateTexture
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderImageImplFBO::UpdateTexture(unsigned int)
|
||||
void RenderImageImplFBO::UpdateTexture(unsigned int)
|
||||
{
|
||||
// Nothing to do: the FBO draws directly into the target image
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
@ -29,17 +29,16 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/RenderImageImpl.hpp>
|
||||
#include <SFML/Window/Context.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class Context;
|
||||
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Specialization of RenderImageImpl using the
|
||||
/// FrameBuffer Object extension
|
||||
/// Frame Buffer Object extension
|
||||
////////////////////////////////////////////////////////////
|
||||
class RenderImageImplFBO : public RenderImageImpl
|
||||
{
|
||||
@ -83,14 +82,14 @@ private :
|
||||
/// /see RenderImageImpl::UpdateTexture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool UpdateTexture(unsigned textureId);
|
||||
virtual void UpdateTexture(unsigned textureId);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int myFrameBuffer; ///< OpenGL frame buffer object
|
||||
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
|
||||
|
@ -191,7 +191,7 @@ bool RenderImageImplPBuffer::Activate(bool active)
|
||||
////////////////////////////////////////////////////////////
|
||||
/// /see RenderImageImpl::UpdateTexture
|
||||
////////////////////////////////////////////////////////////
|
||||
bool RenderImageImplPBuffer::UpdateTexture(unsigned int textureId)
|
||||
void RenderImageImplPBuffer::UpdateTexture(unsigned int textureId)
|
||||
{
|
||||
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(glBindTexture(GL_TEXTURE_2D, previous));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
@ -82,7 +82,7 @@ private :
|
||||
/// /see RenderImageImpl::UpdateTexture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool UpdateTexture(unsigned textureId);
|
||||
virtual void UpdateTexture(unsigned textureId);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
|
Loading…
Reference in New Issue
Block a user