PolyGLRenderer.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. #include "PolyGLHeaders.h"
  26. /*
  27. #ifdef _WINDOWS
  28. #define GL_EXT_framebuffer_object 1
  29. #if GL_EXT_framebuffer_object
  30. #define GL_FRAMEBUFFER_EXT 0x8D40
  31. #define GL_RENDERBUFFER_EXT 0x8D41
  32. #define GL_STENCIL_INDEX1_EXT 0x8D46
  33. #define GL_STENCIL_INDEX4_EXT 0x8D47
  34. #define GL_STENCIL_INDEX8_EXT 0x8D48
  35. #define GL_STENCIL_INDEX16_EXT 0x8D49
  36. #define GL_RENDERBUFFER_WIDTH_EXT 0x8D42
  37. #define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43
  38. #define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44
  39. #define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50
  40. #define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51
  41. #define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52
  42. #define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53
  43. #define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54
  44. #define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55
  45. #define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0
  46. #define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1
  47. #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2
  48. #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3
  49. #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4
  50. #define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
  51. #define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
  52. #define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
  53. #define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
  54. #define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
  55. #define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
  56. #define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
  57. #define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
  58. #define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
  59. #define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
  60. #define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
  61. #define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
  62. #define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
  63. #define GL_COLOR_ATTACHMENT13_EXT 0x8CED
  64. #define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
  65. #define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
  66. #define GL_DEPTH_ATTACHMENT_EXT 0x8D00
  67. #define GL_STENCIL_ATTACHMENT_EXT 0x8D20
  68. #define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5
  69. #define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6
  70. #define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7
  71. #define GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT 0x8CD8
  72. #define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9
  73. #define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA
  74. #define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB
  75. #define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC
  76. #define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD
  77. #define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6
  78. #define GL_RENDERBUFFER_BINDING_EXT 0x8CA7
  79. #define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF
  80. #define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8
  81. #define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506
  82. #endif
  83. #endif
  84. */
  85. namespace Polycode {
  86. class _PolyExport OpenGLRenderer : public Renderer {
  87. public:
  88. OpenGLRenderer();
  89. ~OpenGLRenderer();
  90. bool Init();
  91. void Resize(int xRes, int yRes);
  92. void BeginRender();
  93. void EndRender();
  94. Cubemap *createCubemap(Texture *t0, Texture *t1, Texture *t2, Texture *t3, Texture *t4, Texture *t5);
  95. Texture *createTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, bool createMipmaps, int type = Image::IMAGE_RGBA);
  96. void destroyTexture(Texture *texture);
  97. void destroyVertexBuffer(VertexBuffer *buffer);
  98. Texture *createFramebufferTexture(unsigned int width, unsigned int height);
  99. void createRenderTextures(Texture **colorBuffer, Texture **depthBuffer, int width, int height, bool floatingPointBuffer);
  100. void enableAlphaTest(bool val);
  101. VertexBuffer *createVertexBufferForMesh(Mesh *mesh);
  102. void drawVertexBuffer(VertexBuffer *buffer, bool enableColorBuffer);
  103. void bindFrameBufferTexture(Texture *texture);
  104. void bindFrameBufferTextureDepth(Texture *texture);
  105. void unbindFramebuffers();
  106. Vector2 Project(const Matrix4 &cameraMatrix, const Matrix4 &projectionMatrix, const Polycode::Rectangle &viewport, const Vector3 &coordiante) const;
  107. void cullFrontFaces(bool val);
  108. void pushRenderDataArray(RenderDataArray *array);
  109. void drawArrays(int drawType, IndexDataArray *indexArray);
  110. void setProjectionOrtho(Number xSize=0.0f, Number ySize=0.0f, Number near=-256.0f, Number far=256.0f, bool centered = false);
  111. void setProjectionMatrix(Matrix4 matrix);
  112. void setPerspectiveDefaults();
  113. void enableBackfaceCulling(bool val);
  114. void resetViewport();
  115. void setLineSmooth(bool val);
  116. void loadIdentity();
  117. void setTexture(Texture *texture);
  118. Image *renderScreenToImage();
  119. Image *renderBufferToImage(Texture *texture);
  120. void clearScreen(bool clearColor = true, bool clearDepth = true);
  121. void translate2D(Number x, Number y);
  122. void rotate2D(Number angle);
  123. void scale2D(const Vector2 &scale);
  124. void enableScissor(bool val);
  125. void setScissorBox(Polycode::Rectangle box);
  126. Vector3 projectRayFrom2DCoordinate(Number x, Number y, const Matrix4 &cameraMatrix, const Matrix4 &projectionMatrix, const Polycode::Rectangle &viewport);
  127. Polycode::Rectangle getViewport();
  128. void setLineSize(Number lineSize);
  129. void setPointSize(Number pointSize);
  130. void setPointSmooth(bool val);
  131. void setVertexColor(Number r, Number g, Number b, Number a);
  132. void setBlendingMode(int blendingMode);
  133. void enableLighting(bool enable);
  134. void enableFog(bool enable);
  135. void setFogProperties(int fogMode, Color color, Number density, Number startDepth, Number endDepth);
  136. void translate3D(const Vector3 &position);
  137. void translate3D(Number x, Number y, Number z);
  138. void scale3D(const Vector3 &scale);
  139. Matrix4 getProjectionMatrix();
  140. Matrix4 getModelviewMatrix();
  141. void setModelviewMatrix(Matrix4 m);
  142. void multModelviewMatrix(Matrix4 m);
  143. void setWireframePolygonMode(bool val);
  144. void enableDepthTest(bool val);
  145. void enableDepthWrite(bool val);
  146. void setProjectionFromFrustum(Number left, Number right, Number bottom, Number top, Number near, Number far);
  147. void setProjectionFromFoV(Number fov, Number near, Number far);
  148. void clearBuffer(bool colorBuffer, bool depthBuffer);
  149. void drawToColorBuffer(bool val);
  150. void drawScreenQuad(Number qx, Number qy);
  151. void pushMatrix();
  152. void popMatrix();
  153. Vector3 Unproject(Number x, Number y, const Matrix4 &cameraMatrix, const Matrix4 &projectionMatrix, const Polycode::Rectangle &viewport);
  154. void setDepthFunction(int depthFunction);
  155. void clearShader();
  156. protected:
  157. void initOSSpecific();
  158. int verticesToDraw;
  159. GLdouble sceneProjectionMatrix[16];
  160. GLdouble sceneProjectionMatrixOrtho[16];
  161. };
  162. }