00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00025 #ifndef SFML_RENDERER_HPP
00026 #define SFML_RENDERER_HPP
00027
00029
00031 #include <SFML/Config.hpp>
00032 #include <SFML/System/NonCopyable.hpp>
00033 #include <SFML/Window/GlResource.hpp>
00034 #include <SFML/Graphics/Color.hpp>
00035 #include <SFML/Graphics/Drawable.hpp>
00036 #include <SFML/Graphics/Matrix3.hpp>
00037
00038
00039 namespace sf
00040 {
00041 class Shader;
00042 class Texture;
00043
00048 class SFML_API Renderer : GlResource, NonCopyable
00049 {
00050 public :
00051
00056 enum PrimitiveType
00057 {
00058 TriangleList,
00059 TriangleStrip,
00060 TriangleFan,
00061 QuadList
00062 };
00063
00064 public :
00065
00072 Renderer(RenderTarget& target);
00073
00078 void Initialize();
00079
00086 void SaveGLStates();
00087
00094 void RestoreGLStates();
00095
00102 void Clear(const Color& color);
00103
00110 void PushStates();
00111
00118 void PopStates();
00119
00128 void SetModelView(const Matrix3& matrix);
00129
00138 void ApplyModelView(const Matrix3& matrix);
00139
00148 void SetProjection(const Matrix3& matrix);
00149
00160 void SetColor(const Color& color);
00161
00172 void ApplyColor(const Color& color);
00173
00180 void SetViewport(const IntRect& viewport);
00181
00188 void SetBlendMode(Blend::Mode mode);
00189
00196 void SetTexture(const Texture* texture);
00197
00204 void SetShader(const Shader* shader);
00205
00227 void Begin(PrimitiveType type);
00228
00235 void End();
00236
00247 void AddVertex(float x, float y);
00248
00261 void AddVertex(float x, float y, float u, float v);
00262
00274 void AddVertex(float x, float y, const Color& color);
00275
00288 void AddVertex(float x, float y, float u, float v, const Color& color);
00289
00290 private :
00291
00308 void ProcessVertex(float x, float y, float u, float v, float r, float g, float b, float a);
00309
00311
00313 struct States
00314 {
00315 States() : r(1.f), g(1.f), b(1.f), a(1.f) {}
00316
00317 Matrix3 modelView;
00318 float r, g, b, a;
00319 };
00320
00322
00324 RenderTarget& myTarget;
00325 States myStatesStack[64];
00326 States* myStates;
00327 const Texture* myTexture;
00328 unsigned int myTextureId;
00329 const Shader* myShader;
00330 Blend::Mode myBlendMode;
00331 IntRect myViewport;
00332 bool myTextureIsValid;
00333 bool myShaderIsValid;
00334 bool myBlendModeIsValid;
00335 bool myViewportIsValid;
00336 };
00337
00338 }
00339
00340
00341 #endif // SFML_RENDERER_HPP
00342
00343