Oxygine  1
2g game engine
STDRenderer.h
1 #pragma once
2 #include "oxygine-include.h"
3 #include "core/Renderer.h"
4 
5 namespace oxygine
6 {
8  {
9  public:
10 
11  static STDRenderer* instance;
13  static void setDefaultSettings();
15  static void initialize();
17  static void release();
19  static void reset();
21  static bool isReady();
23  static void restore();
24 
26  static spNativeTexture white;
27  static spNativeTexture invisible;
28 
29  static UberShaderProgram uberShader;
30  static std::vector<unsigned char> uberShaderBody;
31  static std::vector<unsigned short> indices16;
32  static size_t maxVertices;
33 
34 
35 
36  STDRenderer(IVideoDriver* driver = 0);
37  virtual ~STDRenderer();
38 
39  const Matrix& getViewProjection() const { return _vp; }
40  IVideoDriver* getDriver();
41  unsigned int getShaderFlags() const { return _shaderFlags; }
42 
43 
44  void setDriver(IVideoDriver*);
45 
46  void setViewProjTransform(const Matrix& viewProj);
47  void setVertexDeclaration(const VertexDeclaration* decl);
48  void setUberShaderProgram(UberShaderProgram* pr);
50  void setBlendMode(blend_mode blend);
52  void setTexture(const spNativeTexture& base, const spNativeTexture& alpha, bool basePremultiplied = true);
53  void setTexture(const spNativeTexture& base, bool basePremultiplied = true);
55  void setTransform(const Transform& tr) { _transform = tr; }
56 
57  void beginElementRendering(bool basePremultiplied);// OVERRIDE;
58  void beginSDFont(float contrast, float offset, const Color& outlineColor, float outlineOffset);
59  void endSDFont();
60  void drawElement(const spNativeTexture& texture, unsigned int color, const RectF& src, const RectF& dest) override;
61  void draw(const Color&, const RectF& srcRect, const RectF& destRect);
63  void drawBatch();
64 
66  void begin(STDRenderer* prev = 0);
67  void begin(spNativeTexture nt, const Rect* viewport = 0);
69  void end();
71  void initCoordinateSystem(int width, int height, bool flipU = false);
72  void resetSettings();
74  void cleanup();
75 
76  virtual void addVertices(const void* data, unsigned int size);
77 
78 
79  //debug utils
80 #ifdef OXYGINE_DEBUG_T2P
81  static void showTexel2PixelErrors(bool show);
82 #endif
83 
84  protected:
85  Transform _transform;
86 
87  STDRenderer* _previous;
88  void setShader(ShaderProgram* prog);
89 
90  void _drawBatch();
91 
92 
93  void _addVertices(const void* data, unsigned int size);
94  void _checkDrawBatch();
95 
96  std::vector<unsigned char> _vertices;
97 
98  const VertexDeclaration* _vdecl;
99 
100  IVideoDriver* _driver;
101  ShaderProgram* _program;
102  Matrix _vp;
103 
104  virtual void preDrawBatch();
105  virtual void _cleanup();
106  virtual void _begin();
107  virtual void _resetSettings();
108  //virtual
109  spNativeTexture _base;
110  spNativeTexture _alpha;
111 
112  blend_mode _blend;
113 
114  UberShaderProgram* _uberShader;
115  unsigned int _shaderFlags;
116 
117  bool _drawing;
118 
119  spNativeTexture _prevRT;
120  };
121 
122 
123  typedef void(*render_texture_hook)(const spNativeTexture& nt);
124  void set_render_texture_hook(render_texture_hook);
125  render_texture_hook get_render_texture_hook();
126 }
void setTransform(const Transform &tr)
Definition: STDRenderer.h:55
static bool isReady()
Definition: VertexDeclaration.h:6
static void reset()
Definition: ShaderProgram.h:7
void begin(STDRenderer *prev=0)
Definition: STDRenderer.h:7
static void setDefaultSettings()
void setBlendMode(blend_mode blend)
Definition: UberShaderProgram.h:44
–oxgl-end–!
Definition: Actor.h:14
static void restore()
void initCoordinateSystem(int width, int height, bool flipU=false)
static spNativeTexture white
Definition: STDRenderer.h:26
Definition: Renderer.h:217
static void initialize()
Definition: VideoDriver.h:12
Definition: Color.h:8
static void release()
void setTexture(const spNativeTexture &base, const spNativeTexture &alpha, bool basePremultiplied=true)