Neo  0.5.0
Developer Documentation
RenderingContext.h
Go to the documentation of this file.
1 //========================================================================
2 // Copyright (c) 2003-2011 Anael Seghezzi <www.maratis3d.com>
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 //
8 // Permission is granted to anyone to use this software for any purpose,
9 // including commercial applications, and to alter it and redistribute it
10 // freely, subject to the following restrictions:
11 //
12 // 1. The origin of this software must not be misrepresented; you must not
13 // claim that you wrote the original software. If you use this software
14 // in a product, an acknowledgment in the product documentation would
15 // be appreciated but is not required.
16 //
17 // 2. Altered source versions must be plainly marked as such, and must not
18 // be misrepresented as being the original software.
19 //
20 // 3. This notice may not be removed or altered from any source
21 // distribution.
22 //
23 //========================================================================
24 
25 
26 #ifndef __RENDERING_CONTEXT_H
27 #define __RENDERING_CONTEXT_H
28 
29 namespace Neo
30 {
31 // blending modes
33 {
40 };
41 
42 // depth modes
44 {
53 };
54 
55 // matrix modes
57 {
61 };
62 
63 // primitives types
65 {
73 };
74 
75 // buffer types
77 {
81 };
82 
83 // texture image mode
85 {
86  TEX_DEPTH = 0,
87  TEX_R = 1,
88  TEX_RG = 2,
89  TEX_RGB = 3,
91 };
92 
93 // texture gen modes
95 {
99 };
100 
101 // texture combine modes
103 {
110 };
111 
112 // texture filtering modes
114 {
121 };
122 
123 // wrap modes
125 {
128 };
129 
130 // cull modes
132 {
137 };
138 
139 // types
141 {
142  VAR_BOOL = 0,
151 };
152 
154 {
165 };
166 
168 {
172 };
173 
174 // stencil funcs
176 {
185 };
186 
187 // stencil ops
189 {
195 };
196 
197 // VBO types
199 {
202 };
203 
204 // VBO modes
206 {
210 };
211 
212 
213 // rendering context
217 class NEO_CORE_EXPORT RenderingContext
218 {
219 public:
220 
221  // destructor
222  virtual ~RenderingContext(void){}
223 
224  // version
229  virtual const char* getRendererVersion() = 0;
230 
231  // view
246  virtual void setOrthoView(float left, float right, float bottom, float top, float zNear, float zFar) = 0;
247 
259  virtual void setPerspectiveView(float fov, float ratio, float zNear, float zFar) = 0;
260 
261  // viewport
274  virtual void setViewport(int x, int y, unsigned int width, unsigned int height) = 0;
275 
276  // clear
286  virtual void clear(int buffer) = 0;
287 
292  virtual void setClearColor(const Vector4 & color) = 0;
293 
294  virtual void init() = 0;
295 
296  // texture
297  virtual void enableTexture(void) = 0;
298  virtual void disableTexture(void) = 0;
299  virtual void setTextureGenMode(TEX_GEN_MODES mode) = 0;
300  virtual void setTextureFilterMode(TEX_FILTER_MODES min, TEX_FILTER_MODES mag) = 0;
301  virtual void setTextureUWrapMode(WRAP_MODES wrap) = 0;
302  virtual void setTextureVWrapMode(WRAP_MODES wrap) = 0;
303  virtual void setTextureCombineMode(TEX_COMBINE_MODES combine) = 0;
304  virtual void bindTexture(unsigned int textureId, const unsigned int multitextureId = 0) = 0;
305  virtual void createTexture(unsigned int * textureId) = 0;
306  virtual void deleteTexture(unsigned int * textureId) = 0;
307  virtual void sendTextureImage(Image * image, bool mipMap, bool filter, bool compress) = 0;
308  virtual void texImage(unsigned int level, unsigned int width, unsigned int height, VAR_TYPES type, TEX_MODES mode, const void * pixels) = 0;
309  virtual void texSubImage(unsigned int level, int xoffset, int yoffset, unsigned int width, unsigned int height, VAR_TYPES type, TEX_MODES mode, const void * pixels) = 0;
310  virtual void generateMipMap(void) = 0;
311  virtual void getTexImage(unsigned int level, Image * image){}
312 
313  // frame buffer
314  virtual void createFrameBuffer(unsigned int * frameBufferId) = 0;
315  virtual void deleteFrameBuffer(unsigned int * frameBufferId) = 0;
316  virtual void bindFrameBuffer(unsigned int frameBufferId) = 0;
317  virtual void getCurrentFrameBuffer(unsigned int * frameBufferId) = 0;
318  virtual void attachFrameBufferTexture(FRAME_BUFFER_ATTACHMENT attachment, unsigned int textureId) = 0;
319  virtual void attachFrameBufferRB(FRAME_BUFFER_ATTACHMENT attachment, unsigned int renderBufferId){}
320  virtual void setDrawingBuffers(FRAME_BUFFER_ATTACHMENT * buffers, unsigned int size) = 0;
321 
322  // render buffer
323  virtual void createRenderBuffer(unsigned int * renderBufferId){}
324  virtual void deleteRenderBuffer(unsigned int * renderBufferId){}
325  virtual void bindRenderBuffer(unsigned int renderBufferId){}
326  virtual void setRenderBuffer(RENDER_BUFFER_MODES mode, unsigned int width, unsigned int height){}
327 
328  // shaders
329  virtual void createVertexShader(unsigned int * shaderId) = 0;
330  virtual void createPixelShader(unsigned int * shaderId) = 0;
331  virtual void deleteShader(unsigned int * shaderId) = 0;
332  virtual bool sendShaderSource(unsigned int shaderId, const char * source) = 0;
333 
334  // FX
335  virtual void bindFX(unsigned int fxId) = 0;
336  virtual void createFX(unsigned int * fxId, unsigned int vertexShaderId, unsigned int pixelShaderId) = 0;
337  virtual void updateFX(unsigned int fxId) = 0;
338  virtual void deleteFX(unsigned int * fxId) = 0;
339  virtual void sendUniformInt(unsigned int fxId, const char * name, int * values, const int count = 1) = 0;
340  virtual void sendUniformFloat(unsigned int fxId, const char * name, float * value, const int count = 1) = 0;
341  virtual void sendUniformVec2(unsigned int fxId, const char * name, float * values, const int count = 1) = 0;
342  virtual void sendUniformVec3(unsigned int fxId, const char * name, float * values, const int count = 1) = 0;
343  virtual void sendUniformVec4(unsigned int fxId, const char * name, float * values, const int count = 1) = 0;
344  virtual void sendUniformMatrix(unsigned int fxId, const char * name, Matrix4x4 * matrix, const int count = 1, const bool transpose = false) = 0;
345  virtual void getAttribLocation(unsigned int fxId, const char * name, int * location) = 0;
346 
347  // VBO
348  virtual void createVBO(unsigned int * vboId){}
349  virtual void deleteVBO(unsigned int * vboId){}
350  virtual void bindVBO(VBO_TYPES type, unsigned int vboId){}
351  virtual void setVBO(VBO_TYPES type, const void * data, unsigned int size, VBO_MODES mode){}
352  virtual void setVBOSubData(VBO_TYPES type, unsigned int offset, const void * data, unsigned int size){}
353 
354  // arrays
355  virtual void enableVertexArray(void) = 0;
356  virtual void enableColorArray(void) = 0;
357  virtual void enableNormalArray(void) = 0;
358  virtual void enableTexCoordArray(void) = 0;
359  virtual void enableAttribArray(unsigned int location) = 0;
360  virtual void disableVertexArray(void) = 0;
361  virtual void disableColorArray(void) = 0;
362  virtual void disableNormalArray(void) = 0;
363  virtual void disableTexCoordArray(void) = 0;
364  virtual void disableAttribArray(unsigned int location) = 0;
365  virtual void setVertexPointer(VAR_TYPES type, unsigned int components, const void * pointer) = 0;
366  virtual void setColorPointer(VAR_TYPES type, unsigned int components, const void * pointer) = 0;
367  virtual void setNormalPointer(VAR_TYPES type, const void * pointer) = 0;
368  virtual void setTexCoordPointer(VAR_TYPES type, unsigned int components, const void * pointer) = 0;
369  virtual void setAttribPointer(unsigned int location, VAR_TYPES type, unsigned int components, const void * pointer, const bool normalized = false) = 0;
370 
371  // draw
372  virtual void drawArray(PRIMITIVE_TYPES type, unsigned int begin, unsigned int size) = 0;
373  virtual void drawElement(PRIMITIVE_TYPES type, unsigned int size, VAR_TYPES indicesType, const void * indices) = 0;
374 
375  // lines
376  virtual void enableLineAntialiasing(void) = 0;
377  virtual void disableLineAntialiasing(void) = 0;
378 
379  // material
380  virtual void setMaterialDiffuse(const Vector4 & diffuse) = 0;
381  virtual void setMaterialSpecular(const Vector4 & specular) = 0;
382  virtual void setMaterialAmbient(const Vector4 & ambient) = 0;
383  virtual void setMaterialEmit(const Vector4 & emit) = 0;
384  virtual void setMaterialShininess(float shininess) = 0;
385 
386  // scissor
387  virtual void enableScissorTest(void) = 0;
388  virtual void disableScissorTest(void) = 0;
389  virtual void setScissor(int x, int y, unsigned int width, unsigned int height) = 0;
390 
391  // color
392  virtual void setColor(const Color & color) = 0;
393  virtual void setColor3(const Vector3 & color) = 0;
394  virtual void setColor4(const Vector4 & color) = 0;
395 
396  // masks
397  virtual void setColorMask(bool r, bool g, bool b, bool a) = 0;
398  virtual void setDepthMask(bool depth) = 0;
399 
400  // alpha
401  virtual void setAlphaTest(float value) = 0;
402 
403  // depth
404  virtual void enableDepthTest(void) = 0;
405  virtual void disableDepthTest(void) = 0;
406  virtual void setDepthMode(DEPTH_MODES mode) = 0;
407  virtual void enablePolygonOffset(float x, float y) = 0;
408  virtual void disablePolygonOffset() = 0;
409 
410  // stencil
411  virtual void enableStencilTest(void) = 0;
412  virtual void disableStencilTest(void) = 0;
413  virtual void setStencilFunc(STENCIL_FUNCS func, int ref=0){};
414  virtual void setStencilOp(STENCIL_OPS op){};
415 
416  // cull face
417  virtual void enableCullFace(void) = 0;
418  virtual void disableCullFace(void) = 0;
419  virtual void setCullMode(CULL_MODES mode) = 0;
420 
421  // occlusion
422  virtual void createQuery(unsigned int * queryId){}
423  virtual void deleteQuery(unsigned int * queryId){}
424  virtual void beginQuery(unsigned int queryId){}
425  virtual void endQuery(void){}
426  virtual void getQueryResult(unsigned int queryId, unsigned int * result){}
427 
428  // matrix
429  virtual void loadIdentity(void) = 0;
430  virtual void setMatrixMode(MATRIX_MODES mode) = 0;
431  virtual void pushMatrix(void) = 0;
432  virtual void popMatrix(void) = 0;
433  virtual void multMatrix(const Matrix4x4 * matrix) = 0;
434  virtual void translate(const Vector3 & position) = 0;
435  virtual void rotate(const Vector3 & axis, float angle) = 0;
436  virtual void scale(const Vector3 & scale) = 0;
437  virtual void getViewport(int * viewport) = 0;
438  virtual void getModelViewMatrix(Matrix4x4 * matrix) = 0;
439  virtual void getProjectionMatrix(Matrix4x4 * matrix) = 0;
440  virtual void getTextureMatrix(Matrix4x4 * matrix) = 0;
441 
442  // fog
443  virtual void enableFog(void) = 0;
444  virtual void disableFog(void) = 0;
445  virtual void setFogColor(const Vector3 & color) = 0;
446  virtual void setFogDistance(float min, float max) = 0;
447  virtual void getFogColor(Vector3 * color) = 0;
448  virtual void getFogDistance(float * min, float * max) = 0;
449 
450  // lighting
451  virtual void enableLighting(void) = 0;
452  virtual void disableLighting(void) = 0;
453  virtual void enableLight(unsigned int id) = 0;
454  virtual void disableLight(unsigned int id) = 0;
455  virtual void setLightPosition(unsigned int id, const Vector4 & position) = 0;
456  virtual void setLightDiffuse(unsigned int id, const Vector4 & diffuse) = 0;
457  virtual void setLightSpecular(unsigned int id, const Vector4 & specular) = 0;
458  virtual void setLightAmbient(unsigned int id, const Vector4 & ambient) = 0;
459  virtual void setLightAttenuation(unsigned int id, float constant, float linear, float quadratic) = 0;
460  virtual void setLightSpotDirection(unsigned int id, const Vector3 & direction) = 0;
461  virtual void setLightSpotAngle(unsigned int id, float angle) = 0;
462  virtual void setLightSpotExponent(unsigned int id, float exponent) = 0;
463  virtual void getLightPosition(unsigned int id, Vector4 * position) = 0;
464  virtual void getLightDiffuse(unsigned int id, Vector4 * diffuse) = 0;
465  virtual void getLightSpecular(unsigned int id, Vector4 * specular) = 0;
466  virtual void getLightAmbient(unsigned int id, Vector4 * ambient) = 0;
467  virtual void getLightAttenuation(unsigned int id, float * constant, float * linear, float * quadratic) = 0;
468  virtual void getLightSpotDirection(unsigned int id, Vector3 * direction) = 0;
469  virtual void getLightSpotAngle(unsigned int id, float * angle) = 0;
470  virtual void getLightSpotExponent(unsigned int id, float * exponent) = 0;
471 
472  // blending
473  virtual void enableBlending(void) = 0;
474  virtual void disableBlending(void) = 0;
475  virtual void setBlendingMode(BLENDING_MODES mode) = 0;
476 
477  virtual void createVAO(unsigned int* vaoId) {}
478  virtual void deleteVAO(unsigned int* vaoId) {}
479  virtual void bindVAO(unsigned int vaoId) {}
480 
481  virtual void selectSubroutine(unsigned int fx, unsigned int type, const char* routine) {}
482  virtual void setPolygonMode(PRIMITIVE_TYPES t) {};
483 
484  // point size
485  virtual void setPointSize(float size) = 0;
486 };
487 }
488 #endif
Definition: Vector4.h:31
Definition: RenderingContext.h:147
Definition: RenderingContext.h:201
Definition: RenderingContext.h:161
PRIMITIVE_TYPES
Definition: RenderingContext.h:64
Definition: RenderingContext.h:88
Definition: RenderingContext.h:48
Definition: RenderingContext.h:180
Definition: RenderingContext.h:150
Definition: RenderingContext.h:163
STENCIL_FUNCS
Definition: RenderingContext.h:175
Definition: RenderingContext.h:78
Definition: RenderingContext.h:79
Definition: RenderingContext.h:184
virtual void endQuery(void)
Definition: RenderingContext.h:425
Definition: RenderingContext.h:159
The RenderingContext class defines an abstraction for the 3D rendering API like OpenGL.
Definition: RenderingContext.h:217
Definition: RenderingContext.h:144
virtual void attachFrameBufferRB(FRAME_BUFFER_ATTACHMENT attachment, unsigned int renderBufferId)
Definition: RenderingContext.h:319
BLENDING_MODES
Definition: RenderingContext.h:32
Definition: RenderingContext.h:119
Definition: RenderingContext.h:133
Definition: Matrix4x4.h:31
Definition: RenderingContext.h:60
Definition: Vector3.h:31
Definition: RenderingContext.h:193
Definition: RenderingContext.h:116
Definition: RenderingContext.h:155
Definition: RenderingContext.h:182
CULL_MODES
Definition: RenderingContext.h:131
Definition: RenderingContext.h:162
Definition: RenderingContext.h:143
RENDER_BUFFER_MODES
Definition: RenderingContext.h:167
virtual void bindVAO(unsigned int vaoId)
Definition: RenderingContext.h:479
Definition: RenderingContext.h:179
virtual void beginQuery(unsigned int queryId)
Definition: RenderingContext.h:424
Definition: RenderingContext.h:106
Definition: RenderingContext.h:109
virtual void setRenderBuffer(RENDER_BUFFER_MODES mode, unsigned int width, unsigned int height)
Definition: RenderingContext.h:326
Definition: RenderingContext.h:190
Definition: RenderingContext.h:158
TEX_MODES
Definition: RenderingContext.h:84
Definition: RenderingContext.h:156
Definition: RenderingContext.h:97
virtual void deleteRenderBuffer(unsigned int *renderBufferId)
Definition: RenderingContext.h:324
Definition: RenderingContext.h:46
Definition: RenderingContext.h:200
Definition: RenderingContext.h:35
virtual void bindRenderBuffer(unsigned int renderBufferId)
Definition: RenderingContext.h:325
Definition: RenderingContext.h:148
virtual void setVBO(VBO_TYPES type, const void *data, unsigned int size, VBO_MODES mode)
Definition: RenderingContext.h:351
Definition: RenderingContext.h:90
Definition: RenderingContext.h:96
Definition: RenderingContext.h:117
Definition: RenderingContext.h:164
Definition: RenderingContext.h:115
Definition: RenderingContext.h:37
Definition: RenderingContext.h:157
Definition: RenderingContext.h:89
WRAP_MODES
Definition: RenderingContext.h:124
STENCIL_OPS
Definition: RenderingContext.h:188
Definition: RenderingContext.h:68
Definition: RenderingContext.h:98
virtual void createRenderBuffer(unsigned int *renderBufferId)
Definition: RenderingContext.h:323
TEX_GEN_MODES
Definition: RenderingContext.h:94
Definition: RenderingContext.h:69
virtual void deleteVAO(unsigned int *vaoId)
Definition: RenderingContext.h:478
Definition: RenderingContext.h:134
Definition: RenderingContext.h:66
virtual void selectSubroutine(unsigned int fx, unsigned int type, const char *routine)
Definition: RenderingContext.h:481
Definition: RenderingContext.h:36
Definition: RenderingContext.h:52
Definition: RenderingContext.h:49
Definition: RenderingContext.h:67
DEPTH_MODES
Definition: RenderingContext.h:43
Definition: RenderingContext.h:38
Definition: RenderingContext.h:127
Definition: RenderingContext.h:87
Definition: RenderingContext.h:39
virtual void setStencilOp(STENCIL_OPS op)
Definition: RenderingContext.h:414
Definition: RenderingContext.h:177
Definition: RenderingContext.h:178
Definition: RenderingContext.h:105
Definition: RenderingContext.h:192
virtual void createQuery(unsigned int *queryId)
Definition: RenderingContext.h:422
Definition: RenderingContext.h:142
Definition: RenderingContext.h:86
Definition: RenderingContext.h:45
Definition: Color.h:31
Definition: RenderingContext.h:47
Definition: RenderingContext.h:146
virtual void deleteVBO(unsigned int *vboId)
Definition: RenderingContext.h:349
virtual void createVBO(unsigned int *vboId)
Definition: RenderingContext.h:348
FRAME_BUFFER_ATTACHMENT
Definition: RenderingContext.h:153
Definition: RenderingContext.h:126
virtual ~RenderingContext(void)
Definition: RenderingContext.h:222
Definition: RenderingContext.h:149
Definition: Image.h:32
Definition: RenderingContext.h:170
virtual void getQueryResult(unsigned int queryId, unsigned int *result)
Definition: RenderingContext.h:426
virtual void getTexImage(unsigned int level, Image *image)
Definition: RenderingContext.h:311
Definition: RenderingContext.h:107
Definition: RenderingContext.h:118
VBO_MODES
Definition: RenderingContext.h:205
Definition: RenderingContext.h:71
Definition: RenderingContext.h:191
Definition: RenderingContext.h:70
Definition: RenderingContext.h:51
Definition: RenderingContext.h:59
virtual void setVBOSubData(VBO_TYPES type, unsigned int offset, const void *data, unsigned int size)
Definition: RenderingContext.h:352
Definition: RenderingContext.h:207
MATRIX_MODES
Definition: RenderingContext.h:56
Definition: RenderingContext.h:135
Definition: RenderingContext.h:208
BUFFER_TYPES
Definition: RenderingContext.h:76
VBO_TYPES
Definition: RenderingContext.h:198
TEX_COMBINE_MODES
Definition: RenderingContext.h:102
Definition: RenderingContext.h:209
Definition: RenderingContext.h:58
Definition: RenderingContext.h:145
Definition: RenderingContext.h:72
virtual void setStencilFunc(STENCIL_FUNCS func, int ref=0)
Definition: RenderingContext.h:413
Definition: RenderingContext.h:120
Definition: RenderingContext.h:171
Definition: RenderingContext.h:169
virtual void deleteQuery(unsigned int *queryId)
Definition: RenderingContext.h:423
Definition: RenderingContext.h:160
Definition: RenderingContext.h:183
virtual void bindVBO(VBO_TYPES type, unsigned int vboId)
Definition: RenderingContext.h:350
Definition: RenderingContext.h:34
Definition: Color.h:29
virtual void setPolygonMode(PRIMITIVE_TYPES t)
Definition: RenderingContext.h:482
Definition: RenderingContext.h:50
VAR_TYPES
Definition: RenderingContext.h:140
Definition: RenderingContext.h:136
Definition: RenderingContext.h:108
Definition: RenderingContext.h:104
Definition: RenderingContext.h:194
Definition: RenderingContext.h:80
virtual void createVAO(unsigned int *vaoId)
Definition: RenderingContext.h:477
TEX_FILTER_MODES
Definition: RenderingContext.h:113
Definition: RenderingContext.h:181