PolyGLRenderer.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * PolyGLRenderer.h
  3. * TAU
  4. *
  5. * Created by Ivan Safrin on 3/12/08.
  6. * Copyright 2008 __MyCompanyName__. All rights reserved.
  7. *
  8. */
  9. // @package Renderer
  10. #pragma once
  11. #include "PolyString.h"
  12. #include "PolyLogger.h"
  13. #include "PolyGlobals.h"
  14. #include "PolyRenderer.h"
  15. #include "PolyTexture.h"
  16. #include "PolyGLTexture.h"
  17. #include "PolyCubemap.h"
  18. #include "PolyGLCubemap.h"
  19. #include "PolyGLVertexBuffer.h"
  20. #include "PolyFixedShader.h"
  21. #include "PolyMesh.h"
  22. #ifdef _WINDOWS
  23. #include <windows.h>
  24. #endif
  25. #if defined(__APPLE__) && defined(__MACH__)
  26. #include <OpenGL/gl.h>
  27. #include <OpenGL/glext.h>
  28. #include <OpenGL/glu.h>
  29. #else
  30. #include <GL/gl.h>
  31. #include <GL/glu.h>
  32. #include <GL/glext.h>
  33. #endif
  34. #ifdef _WINDOWS
  35. #define GL_EXT_framebuffer_object 1
  36. #if GL_EXT_framebuffer_object
  37. #define GL_FRAMEBUFFER_EXT 0x8D40
  38. #define GL_RENDERBUFFER_EXT 0x8D41
  39. #define GL_STENCIL_INDEX1_EXT 0x8D46
  40. #define GL_STENCIL_INDEX4_EXT 0x8D47
  41. #define GL_STENCIL_INDEX8_EXT 0x8D48
  42. #define GL_STENCIL_INDEX16_EXT 0x8D49
  43. #define GL_RENDERBUFFER_WIDTH_EXT 0x8D42
  44. #define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43
  45. #define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44
  46. #define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50
  47. #define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51
  48. #define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52
  49. #define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53
  50. #define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54
  51. #define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55
  52. #define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0
  53. #define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1
  54. #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2
  55. #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3
  56. #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4
  57. #define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
  58. #define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
  59. #define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
  60. #define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
  61. #define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
  62. #define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
  63. #define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
  64. #define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
  65. #define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
  66. #define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
  67. #define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
  68. #define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
  69. #define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
  70. #define GL_COLOR_ATTACHMENT13_EXT 0x8CED
  71. #define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
  72. #define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
  73. #define GL_DEPTH_ATTACHMENT_EXT 0x8D00
  74. #define GL_STENCIL_ATTACHMENT_EXT 0x8D20
  75. #define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5
  76. #define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6
  77. #define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7
  78. #define GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT 0x8CD8
  79. #define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9
  80. #define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA
  81. #define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB
  82. #define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC
  83. #define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD
  84. #define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6
  85. #define GL_RENDERBUFFER_BINDING_EXT 0x8CA7
  86. #define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF
  87. #define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8
  88. #define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506
  89. #endif
  90. #endif
  91. namespace Polycode {
  92. class _PolyExport OpenGLRenderer : public Renderer {
  93. public:
  94. OpenGLRenderer();
  95. ~OpenGLRenderer();
  96. void Resize(int xRes, int yRes);
  97. void BeginRender();
  98. void EndRender();
  99. Cubemap *createCubemap(Texture *t0, Texture *t1, Texture *t2, Texture *t3, Texture *t4, Texture *t5);
  100. Texture *createTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, int type = Image::IMAGE_RGBA);
  101. Texture *createFramebufferTexture(unsigned int width, unsigned int height);
  102. void createRenderTextures(Texture **colorBuffer, Texture **depthBuffer, int width, int height);
  103. void enableAlphaTest(bool val);
  104. void createVertexBufferForMesh(Mesh *mesh);
  105. void drawVertexBuffer(VertexBuffer *buffer);
  106. void bindFrameBufferTexture(Texture *texture);
  107. void unbindFramebuffers();
  108. void pushRenderDataArray(RenderDataArray *array);
  109. RenderDataArray *createRenderDataArrayForMesh(Mesh *mesh, int arrayType);
  110. RenderDataArray *createRenderDataArray(int arrayType);
  111. void setRenderArrayData(RenderDataArray *array, Number *arrayData);
  112. void drawArrays(int drawType);
  113. void setOrthoMode(Number xSize=0.0f, Number ySize=0.0f);
  114. void _setOrthoMode();
  115. void setPerspectiveMode();
  116. void enableBackfaceCulling(bool val);
  117. void setViewportSize(int w, int h, Number fov=45.0f);
  118. void setLineSmooth(bool val);
  119. void loadIdentity();
  120. void setClearColor(Number r, Number g, Number b);
  121. void setTexture(Texture *texture);
  122. void renderToTexture(Texture *targetTexture);
  123. void renderZBufferToTexture(Texture *targetTexture);
  124. void clearScreen();
  125. void translate2D(Number x, Number y);
  126. void rotate2D(Number angle);
  127. void scale2D(Vector2 *scale);
  128. void setLineSize(Number lineSize);
  129. void setVertexColor(Number r, Number g, Number b, Number a);
  130. void setBlendingMode(int blendingMode);
  131. void enableLighting(bool enable);
  132. void enableFog(bool enable);
  133. void setFogProperties(int fogMode, Color color, Number density, Number startDepth, Number endDepth);
  134. void translate3D(Vector3 *position);
  135. void translate3D(Number x, Number y, Number z);
  136. void scale3D(Vector3 *scale);
  137. Matrix4 getProjectionMatrix();
  138. Matrix4 getModelviewMatrix();
  139. void setModelviewMatrix(Matrix4 m);
  140. void multModelviewMatrix(Matrix4 m);
  141. void enableDepthTest(bool val);
  142. void enableDepthWrite(bool val);
  143. void clearBuffer(bool colorBuffer, bool depthBuffer);
  144. void drawToColorBuffer(bool val);
  145. void drawScreenQuad(Number qx, Number qy);
  146. void pushMatrix();
  147. void popMatrix();
  148. bool test2DCoordinate(Number x, Number y, Polycode::Polygon *poly, const Matrix4 &matrix, bool billboardMode);
  149. void setFOV(Number fov);
  150. Vector3 Unproject(Number x, Number y);
  151. void setDepthFunction(int depthFunction);
  152. void clearShader();
  153. void applyMaterial(Material *material, ShaderBinding *localOptions, unsigned int shaderIndex);
  154. protected:
  155. Number nearPlane;
  156. Number farPlane;
  157. int verticesToDraw;
  158. GLdouble sceneProjectionMatrix[16];
  159. };
  160. }