Oxygine  1
2g game engine
VideoDriver.h
1 #pragma once
2 #include "oxygine-include.h"
3 #include "ref_counter.h"
4 #include "vertex.h"
5 #include "math/Rect.h"
6 #include "math/Vector4.h"
7 #include "math/Matrix.h"
8 #include <vector>
9 
10 namespace oxygine
11 {
13  {
14  public:
15 
16  enum PRIMITIVE_TYPE
17  {
18  PT_POINTS,
19  PT_LINES,
20  PT_LINE_LOOP,
21  PT_LINE_STRIP,
22  PT_TRIANGLES,
23  PT_TRIANGLE_STRIP,
24  PT_TRIANGLE_FAN,
25  PT_COUNT,
26  };
27 
28 
29  class Stats
30  {
31  public:
32  Stats() : batches(0), duration(0), start(0) { memset(elements, 0, sizeof(elements)); }
33  int batches;
34  int elements[PT_COUNT];
35  timeMS start;
36  timeMS duration;
37  };
38  static Stats _stats;
39 
40  enum BLEND_TYPE
41  {
42  BT_ZERO,
43  BT_ONE,
44  BT_SRC_COLOR,
45  BT_ONE_MINUS_SRC_COLOR,
46  BT_SRC_ALPHA,
47  BT_ONE_MINUS_SRC_ALPHA,
48  BT_DST_ALPHA,
49  BT_DST_COLOR,
50  BT_ONE_MINUS_DST_ALPHA,
51  BT_ONE_MINUS_DST_COLOR,
52  };
53 
54  enum CULL_FACE_TYPE
55  {
56  CULL_FACE_FRONT_AND_BACK,
57  CULL_FACE_FRONT,
58  CULL_FACE_BACK,
59  };
60 
61  enum STATE
62  {
63  STATE_BLEND,
64  STATE_CULL_FACE,
65  STATE_NUM
66  };
67 
68  static IVideoDriver* instance;
69  virtual ~IVideoDriver() {}
70 
71  virtual void reset() = 0;
72  virtual void restore() = 0;
73  virtual bool isReady() const = 0;
74 
75  virtual spNativeTexture createTexture() = 0;
76 
77  virtual void clear(const Color& color) = 0;
78  virtual void begin(const Rect& viewport, const Color* color) = 0;
79  virtual void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int verticesDataSize) = 0;
80  virtual void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int verticesDataSize, const unsigned short* indicesData, unsigned int numIndices) = 0;
81 
82 
83  virtual void getViewport(Rect& r) const = 0;
84  virtual bool getScissorRect(Rect&) const = 0;
85  virtual spNativeTexture getRenderTarget() const = 0;
86  virtual ShaderProgram* getShaderProgram() const = 0;
87  virtual const VertexDeclaration* getVertexDeclaration(bvertex_format) const = 0;
88 
89  virtual void setScissorRect(const Rect*) = 0;
90  virtual void setDefaultSettings() = 0;
91  virtual void setViewport(const Rect& viewport) = 0;
92  virtual void setRenderTarget(spNativeTexture) = 0;
93  virtual void setShaderProgram(ShaderProgram*) = 0;
94  virtual void setTexture(int sampler, spNativeTexture) = 0;
95  virtual void setState(STATE, unsigned int value) = 0;
96  virtual void setBlendFunc(BLEND_TYPE src, BLEND_TYPE dest) = 0;
97 
98  virtual void setUniform(const char* id, const Vector4* v, int num) = 0;
99  virtual void setUniform(const char* id, const Vector3* v, int num) = 0;
100  virtual void setUniform(const char* id, const Vector2* v, int num) = 0;
101  virtual void setUniform(const char* id, const Matrix*) = 0;
102  virtual void setUniform(const char* id, float v) = 0;
103  virtual void setUniformInt(const char* id, int v) = 0;
104 
105 
106  void _debugAddPrimitives(PRIMITIVE_TYPE pt, int num);
107  };
108 
110  {
111  public:
112  spNativeTexture createTexture();
113 
114 
115  void clear(const Color& color) {}
116  void begin(const Rect& viewport, const Color* clearColor);
117  bool isReady() const {return true;}
118  void getViewport(Rect& r) const;
119  bool getScissorRect(Rect&) const;
120  ShaderProgram* getShaderProgram() const { return 0; }
121  spNativeTexture getRenderTarget() const;
122 
123  const VertexDeclaration* getVertexDeclaration(bvertex_format) const;
124 
125  void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int verticesDataSize) {}
126  void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int verticesDataSize, const unsigned short* indicesData, unsigned int indicesDataSize) {}
127 
128 
129  void setUniformInt(const char* id, int v) {}
130  void setUniform(const char* id, const Vector4* v, int num) {}
131  void setUniform(const char* id, const Vector3* v, int num) {}
132  void setUniform(const char* id, const Vector2* v, int num) {}
133  void setUniform(const char* id, const Matrix* mat) {}
134  void setUniform(const char* id, float val) {}
135 
136  void setViewport(const Rect& viewport) {}
137  void setScissorRect(const Rect*);
138  void setDefaultSettings();
139  void setRenderTarget(spNativeTexture);
140  void setShaderProgram(ShaderProgram*);
141  void setTexture(int sampler, spNativeTexture);
142  void setState(STATE, unsigned int value) {}
143  void setBlendFunc(BLEND_TYPE src, BLEND_TYPE dest) {}
144  void setDebugStats(bool enable) {}
145 
146  void reset() {}
147  void restore() {}
148 
149  spNativeTexture _rt;
150  };
151 
152 }
Definition: VertexDeclaration.h:6
Definition: ShaderProgram.h:7
Definition: VideoDriver.h:29
–oxgl-end–!
Definition: Actor.h:14
Definition: VideoDriver.h:109
Definition: Vector4.h:7
Definition: VideoDriver.h:12
Definition: Color.h:8
Definition: Vector3.h:7