PolyGLRenderer.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyRenderer.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. #ifdef _WINDOWS
  34. #include <GL/wglext.h>
  35. #endif
  36. #endif
  37. /*
  38. #ifdef _WINDOWS
  39. #define GL_EXT_framebuffer_object 1
  40. #if GL_EXT_framebuffer_object
  41. #define GL_FRAMEBUFFER_EXT 0x8D40
  42. #define GL_RENDERBUFFER_EXT 0x8D41
  43. #define GL_STENCIL_INDEX1_EXT 0x8D46
  44. #define GL_STENCIL_INDEX4_EXT 0x8D47
  45. #define GL_STENCIL_INDEX8_EXT 0x8D48
  46. #define GL_STENCIL_INDEX16_EXT 0x8D49
  47. #define GL_RENDERBUFFER_WIDTH_EXT 0x8D42
  48. #define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43
  49. #define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44
  50. #define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50
  51. #define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51
  52. #define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52
  53. #define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53
  54. #define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54
  55. #define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55
  56. #define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0
  57. #define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1
  58. #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2
  59. #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3
  60. #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4
  61. #define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
  62. #define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
  63. #define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
  64. #define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
  65. #define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
  66. #define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
  67. #define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
  68. #define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
  69. #define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
  70. #define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
  71. #define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
  72. #define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
  73. #define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
  74. #define GL_COLOR_ATTACHMENT13_EXT 0x8CED
  75. #define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
  76. #define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
  77. #define GL_DEPTH_ATTACHMENT_EXT 0x8D00
  78. #define GL_STENCIL_ATTACHMENT_EXT 0x8D20
  79. #define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5
  80. #define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6
  81. #define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7
  82. #define GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT 0x8CD8
  83. #define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9
  84. #define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA
  85. #define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB
  86. #define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC
  87. #define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD
  88. #define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6
  89. #define GL_RENDERBUFFER_BINDING_EXT 0x8CA7
  90. #define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF
  91. #define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8
  92. #define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506
  93. #endif
  94. #endif
  95. */
  96. namespace Polycode {
  97. class _PolyExport OpenGLRenderer : public Renderer {
  98. public:
  99. OpenGLRenderer();
  100. ~OpenGLRenderer();
  101. void Resize(int xRes, int yRes);
  102. void BeginRender();
  103. void EndRender();
  104. Cubemap *createCubemap(Texture *t0, Texture *t1, Texture *t2, Texture *t3, Texture *t4, Texture *t5);
  105. Texture *createTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, bool createMipmaps, int type = Image::IMAGE_RGBA);
  106. void destroyTexture(Texture *texture);
  107. Texture *createFramebufferTexture(unsigned int width, unsigned int height);
  108. void createRenderTextures(Texture **colorBuffer, Texture **depthBuffer, int width, int height, bool floatingPointBuffer);
  109. void enableAlphaTest(bool val);
  110. void createVertexBufferForMesh(Mesh *mesh);
  111. void drawVertexBuffer(VertexBuffer *buffer, bool enableColorBuffer);
  112. void bindFrameBufferTexture(Texture *texture);
  113. void unbindFramebuffers();
  114. void cullFrontFaces(bool val);
  115. void pushRenderDataArray(RenderDataArray *array);
  116. RenderDataArray *createRenderDataArrayForMesh(Mesh *mesh, int arrayType);
  117. RenderDataArray *createRenderDataArray(int arrayType);
  118. void setRenderArrayData(RenderDataArray *array, Number *arrayData);
  119. void drawArrays(int drawType);
  120. void setOrthoMode(Number xSize=0.0f, Number ySize=0.0f);
  121. void _setOrthoMode();
  122. void setPerspectiveMode();
  123. void enableBackfaceCulling(bool val);
  124. void resetViewport();
  125. void setLineSmooth(bool val);
  126. void loadIdentity();
  127. void setClearColor(Number r, Number g, Number b);
  128. void setTexture(Texture *texture);
  129. Image *renderScreenToImage();
  130. void clearScreen();
  131. void translate2D(Number x, Number y);
  132. void rotate2D(Number angle);
  133. void scale2D(Vector2 *scale);
  134. Vector3 projectRayFrom2DCoordinate(Number x, Number y);
  135. void initOSSpecific();
  136. void setLineSize(Number lineSize);
  137. void setVertexColor(Number r, Number g, Number b, Number a);
  138. void setBlendingMode(int blendingMode);
  139. void enableLighting(bool enable);
  140. void enableFog(bool enable);
  141. void setFogProperties(int fogMode, Color color, Number density, Number startDepth, Number endDepth);
  142. void translate3D(Vector3 *position);
  143. void translate3D(Number x, Number y, Number z);
  144. void scale3D(Vector3 *scale);
  145. Matrix4 getProjectionMatrix();
  146. Matrix4 getModelviewMatrix();
  147. void setModelviewMatrix(Matrix4 m);
  148. void multModelviewMatrix(Matrix4 m);
  149. void enableDepthTest(bool val);
  150. void enableDepthWrite(bool val);
  151. void setClippingPlanes(Number near, Number far);
  152. void clearBuffer(bool colorBuffer, bool depthBuffer);
  153. void drawToColorBuffer(bool val);
  154. void drawScreenQuad(Number qx, Number qy);
  155. void pushMatrix();
  156. void popMatrix();
  157. bool test2DCoordinate(Number x, Number y, Polycode::Polygon *poly, const Matrix4 &matrix, bool billboardMode);
  158. Vector3 Unproject(Number x, Number y);
  159. void setDepthFunction(int depthFunction);
  160. void clearShader();
  161. void applyMaterial(Material *material, ShaderBinding *localOptions, unsigned int shaderIndex);
  162. protected:
  163. Number nearPlane;
  164. Number farPlane;
  165. int verticesToDraw;
  166. GLdouble sceneProjectionMatrix[16];
  167. };
  168. }