RenderTarget.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef CPP3DS_RENDERTARGET_HPP
26 #define CPP3DS_RENDERTARGET_HPP
27 
28 #include <cpp3ds/Graphics/Color.hpp>
29 #include <cpp3ds/Graphics/Rect.hpp>
30 #include <cpp3ds/Graphics/View.hpp>
31 #include <cpp3ds/Graphics/Transform.hpp>
32 #include <cpp3ds/Graphics/BlendMode.hpp>
33 #include <cpp3ds/Graphics/RenderStates.hpp>
34 #include <cpp3ds/Graphics/PrimitiveType.hpp>
35 #include <cpp3ds/Graphics/Vertex.hpp>
36 #include <cpp3ds/System/NonCopyable.hpp>
37 
38 
39 namespace cpp3ds
40 {
41 class Drawable;
42 
48 {
49 public :
50 
55  virtual ~RenderTarget();
56 
66  void clear(const Color& color = Color(0, 0, 0, 255));
67 
87  void setView(const View& view);
88 
97  const View& getView() const;
98 
110  const View& getDefaultView() const;
111 
125  IntRect getViewport(const View& view) const;
126 
145  Vector2f mapPixelToCoords(const Vector2i& point) const;
146 
176  Vector2f mapPixelToCoords(const Vector2i& point, const View& view) const;
177 
196  Vector2i mapCoordsToPixel(const Vector2f& point) const;
197 
223  Vector2i mapCoordsToPixel(const Vector2f& point, const View& view) const;
224 
232  void draw(const Drawable& drawable, const RenderStates& states = RenderStates::Default);
233 
243  void draw(const Vertex* vertices, unsigned int vertexCount,
244  PrimitiveType type, const RenderStates& states = RenderStates::Default);
245 
252  virtual Vector2u getSize() const = 0;
253 
286  void pushGLStates();
287 
297  void popGLStates();
298 
320  void resetGLStates();
321 
322 protected :
323 
328  RenderTarget();
329 
337  void initialize();
338 
339 private:
340 
345  void applyCurrentView();
346 
353  void applyBlendMode(const BlendMode& mode);
354 
361  void applyTransform(const Transform& transform);
362 
369  void applyTexture(const Texture* texture);
370 
377  void applyShader(const Shader* shader);
378 
391  virtual bool activate(bool active) = 0;
392 
397  struct StatesCache
398  {
399  enum {VertexCacheSize = 4};
400 
401  bool glStatesSet;
402  bool viewChanged;
403  BlendMode lastBlendMode;
404  Uint64 lastTextureId;
405  bool useVertexCache;
406  Vertex* vertexCache;
407  };
408 
410  // Member data
412  View m_defaultView;
413  View m_view;
414  StatesCache m_cache;
415 };
416 
417 }
418 
419 
420 #endif
421 
422 
Shader class (vertex and fragment)
Definition: Shader.hpp:53
void setView(const View &view)
Change the current active view.
void draw(const Drawable &drawable, const RenderStates &states=RenderStates::Default)
Draw a drawable object to the render-target.
Blending modes for drawing.
Definition: BlendMode.hpp:36
Utility class for manpulating RGBA colors.
Definition: Color.hpp:36
void initialize()
Performs the common initialization step after creation.
Vector2f mapPixelToCoords(const Vector2i &point) const
Convert a point from target coordinates to world coordinates, using the current view.
virtual ~RenderTarget()
Destructor.
RenderTarget()
Default constructor.
const View & getDefaultView() const
Get the default view of the render target.
Define a point with color and texture coordinates.
Definition: Vertex.hpp:41
virtual Vector2u getSize() const =0
Return the size of the rendering region of the target.
void pushGLStates()
Save the current OpenGL render states and matrices.
const View & getView() const
Get the view currently in use in the render target.
static const RenderStates Default
Special instance holding the default render states.
Abstract base class for objects that can be drawn to a render target.
Definition: Drawable.hpp:43
void clear(const Color &color=Color(0, 0, 0, 255))
Clear the entire target with a single color.
void popGLStates()
Restore the previously saved OpenGL render states and matrices.
Base class for all render targets (window, texture, ...)
Utility class that makes any derived class non-copyable.
Definition: NonCopyable.hpp:35
Vector2i mapCoordsToPixel(const Vector2f &point) const
Convert a point from world coordinates to target coordinates, using the current view.
Define the states used for drawing to a RenderTarget.
PrimitiveType
Types of primitives that a cpp3ds::VertexArray can render.
IntRect getViewport(const View &view) const
Get the viewport of a view, applied to this render target.
void resetGLStates()
Reset the internal OpenGL states so that the target is ready for drawing.
2D camera that defines what region is shown on screen
Definition: View.hpp:42
Define a 3x3 transform matrix.
Definition: Transform.hpp:41
some things could easily be broken///////
Definition: Texture.hpp:47