PolyGLRenderer.h 6.5 KB

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