git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1809 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
laurentgom 2011-03-21 07:08:26 +00:00
parent 6cf2303484
commit a94ed51702
25 changed files with 496 additions and 229 deletions

View file

@ -29,6 +29,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Resource.hpp>
#include <SFML/Window/GlResource.hpp>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <string>
@ -45,7 +46,7 @@ class RenderWindow;
/// \brief Class for loading, manipulating and saving images
///
////////////////////////////////////////////////////////////
class SFML_API Image : public Resource<Image>
class SFML_API Image : public Resource<Image>, GlResource
{
public :

View file

@ -30,6 +30,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#include <SFML/System/NonCopyable.hpp>
#include <SFML/Window/GlResource.hpp>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Matrix3.hpp>
@ -44,7 +45,7 @@ class Shader;
/// \brief Handles the low-level rendering (states and geometry)
///
////////////////////////////////////////////////////////////
class SFML_API Renderer : NonCopyable
class SFML_API Renderer : GlResource, NonCopyable
{
public :

View file

@ -30,6 +30,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#include <SFML/Graphics/Image.hpp>
#include <SFML/Window/GlResource.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/System/Vector3.hpp>
#include <map>
@ -44,7 +45,7 @@ class Renderer;
/// \brief Pixel/fragment shader class
///
////////////////////////////////////////////////////////////
class SFML_API Shader
class SFML_API Shader : GlResource
{
public :
@ -120,7 +121,7 @@ public :
/// \param name Name of the parameter in the shader
/// \param x Value to assign
///
/// \see SetTexture
/// \see SetTexture, SetCurrentTexture
///
////////////////////////////////////////////////////////////
void SetParameter(const std::string& name, float x);
@ -141,7 +142,7 @@ public :
/// \param x First component of the value to assign
/// \param y Second component of the value to assign
///
/// \see SetTexture
/// \see SetTexture, SetCurrentTexture
///
////////////////////////////////////////////////////////////
void SetParameter(const std::string& name, float x, float y);
@ -163,7 +164,7 @@ public :
/// \param y Second component of the value to assign
/// \param z Third component of the value to assign
///
/// \see SetTexture
/// \see SetTexture, SetCurrentTexture
///
////////////////////////////////////////////////////////////
void SetParameter(const std::string& name, float x, float y, float z);
@ -186,7 +187,7 @@ public :
/// \param z Third component of the value to assign
/// \param w Fourth component of the value to assign
///
/// \see SetTexture
/// \see SetTexture, SetCurrentTexture
///
////////////////////////////////////////////////////////////
void SetParameter(const std::string& name, float x, float y, float z, float w);
@ -206,7 +207,7 @@ public :
/// \param name Name of the parameter in the shader
/// \param vector Vector to assign
///
/// \see SetTexture
/// \see SetTexture, SetCurrentTexture
///
////////////////////////////////////////////////////////////
void SetParameter(const std::string& name, const Vector2f& vector);
@ -226,7 +227,7 @@ public :
/// \param name Name of the parameter in the shader
/// \param vector Vector to assign
///
/// \see SetTexture
/// \see SetTexture, SetCurrentTexture
///
////////////////////////////////////////////////////////////
void SetParameter(const std::string& name, const Vector3f& vector);
@ -235,19 +236,18 @@ public :
/// \brief Change a texture parameter of the shader
///
/// \a name is the name of the texture to change in the shader.
/// To tell the shader to use the current texture of the object being
/// drawn, pass Shader::CurrentTexture.
/// This function maps an external image to the texture variable;
/// to use the current texture of the object being drawn, use
/// SetCurrentTexture instead.
/// Example:
/// \code
/// // These are the variables in the pixel shader
/// uniform sampler2D current;
/// uniform sampler2D other;
/// uniform sampler2D texture;
/// \endcode
/// \code
/// sf::Image image;
/// ...
/// shader.SetParameter("current", sf::Shader::CurrentTexture);
/// shader.SetParameter("other", image);
/// shader.SetTexture("texture", image);
/// \endcode
/// It is important to note that \a texture must remain alive as long
/// as the shader uses it, no copy is made internally.
@ -255,11 +255,32 @@ public :
/// \param name Name of the texture in the shader
/// \param texture Image to assign
///
/// \see SetParameter
/// \see SetParameter, SetCurrentTexture
///
////////////////////////////////////////////////////////////
void SetTexture(const std::string& name, const Image& texture);
////////////////////////////////////////////////////////////
/// \brief Set the current object texture in the shader
///
/// This function maps a shader texture variable to the
/// image of the object being drawn.
/// Example:
/// \code
/// // This is the variable in the pixel shader
/// uniform sampler2D current;
/// \endcode
/// \code
/// shader.SetCurrentTexture("current");
/// \endcode
///
/// \param name Name of the texture in the shader
///
/// \see SetParameter, SetTexture
///
////////////////////////////////////////////////////////////
void SetCurrentTexture(const std::string& name);
////////////////////////////////////////////////////////////
/// \brief Bind the shader for rendering (activate it)
///
@ -312,11 +333,6 @@ public :
////////////////////////////////////////////////////////////
static bool IsAvailable();
////////////////////////////////////////////////////////////
// Static member data
////////////////////////////////////////////////////////////
static const Image CurrentTexture; ///< Special image representing the texture used by the object being drawn
private :
friend class Renderer;
@ -394,12 +410,12 @@ private :
/// \code
/// shader.SetParameter("offset", 2.f);
/// shader.SetParameter("color", 0.5f, 0.8f, 0.3f);
/// shader.SetTexture("image", image); // image is a sf::Image
/// shader.SetTexture("current", sf::Shader::CurrentTexture);
/// shader.SetTexture("overlay", image); // image is a sf::Image
/// shader.SetCurrentTexture("texture");
/// \endcode
///
/// Shader::CurrentTexture is a special value that represents
/// the texture that the object being drawn is using.
/// Shader::SetCurrentTexture maps the given texture variable
/// to the current texture of the object being drawn.
///
/// To apply a shader to a drawable, you must pass it as an
/// additional parameter to the Draw function:

View file

@ -29,6 +29,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#include <SFML/Window/GlResource.hpp>
#include <SFML/System/NonCopyable.hpp>
@ -43,7 +44,7 @@ namespace priv
/// \brief Class holding a valid drawing context
///
////////////////////////////////////////////////////////////
class SFML_API Context : NonCopyable
class SFML_API Context : GlResource, NonCopyable
{
public :
@ -71,18 +72,6 @@ public :
////////////////////////////////////////////////////////////
void SetActive(bool active);
////////////////////////////////////////////////////////////
/// \brief Make the current thread's reference context active
///
/// This function is meant to be called internally; it is used
/// to deactivate the current context by activating another one
/// (so that we still have an active context on the current thread).
///
/// \return True if operation was successful, false otherwise
///
////////////////////////////////////////////////////////////
static bool SetReferenceActive();
private :
////////////////////////////////////////////////////////////

View file

@ -0,0 +1,72 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_GLRESOURCE_HPP
#define SFML_GLRESOURCE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Base class for classes that require an OpenGL context
///
////////////////////////////////////////////////////////////
class SFML_API GlResource
{
protected :
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
GlResource();
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
~GlResource();
static void EnsureGlContext();
};
} // namespace sf
#endif // SFML_GLRESOURCE_HPP
////////////////////////////////////////////////////////////
/// \class sf::GlResource
/// \ingroup window
///
/// This class is for internal use only, it must be the base
/// of every class that requires a valid OpenGL context in
/// order to work.
///
////////////////////////////////////////////////////////////

View file

@ -33,6 +33,7 @@
#include <SFML/Window/VideoMode.hpp>
#include <SFML/Window/WindowHandle.hpp>
#include <SFML/Window/WindowStyle.hpp>
#include <SFML/Window/GlResource.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/System/NonCopyable.hpp>
#include <string>
@ -52,7 +53,7 @@ class Event;
/// \brief Window that serves as a target for OpenGL rendering
///
////////////////////////////////////////////////////////////
class SFML_API Window : NonCopyable
class SFML_API Window : GlResource, NonCopyable
{
public :