PolyRenderer.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * PolyRenderer.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 "PolyGlobals.h"
  13. #include "PolyColor.h"
  14. #include "PolyPolygon.h"
  15. #include "PolyMesh.h"
  16. #include "PolyTexture.h"
  17. #include "PolyCubemap.h"
  18. #include "PolyMaterial.h"
  19. #include "PolyModule.h"
  20. #include "PolyVector3.h"
  21. #include "PolyQuaternion.h"
  22. #include "PolyMatrix4.h"
  23. namespace Polycode {
  24. class Texture;
  25. class _PolyExport LightInfo {
  26. public:
  27. Vector3 position;
  28. Vector3 color;
  29. Vector3 dir;
  30. float distance;
  31. float intensity;
  32. int type;
  33. Matrix4 textureMatrix;
  34. };
  35. class _PolyExport Renderer {
  36. public:
  37. Renderer();
  38. virtual ~Renderer();
  39. virtual void Resize(int xRes, int yRes) = 0;
  40. virtual void BeginRender() = 0;
  41. virtual void EndRender() = 0;
  42. virtual Cubemap *createCubemap(Texture *t0, Texture *t1, Texture *t2, Texture *t3, Texture *t4, Texture *t5) = 0;
  43. virtual Texture *createTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, int type=Image::IMAGE_RGBA) = 0;
  44. virtual void createRenderTextures(Texture **colorBuffer, Texture **depthBuffer, int width, int height) = 0;
  45. virtual Texture *createFramebufferTexture(unsigned int width, unsigned int height) = 0;
  46. virtual void bindFrameBufferTexture(Texture *texture) = 0;
  47. virtual void unbindFramebuffers() = 0;
  48. virtual void renderToTexture(Texture *targetTexture) = 0;
  49. virtual void renderZBufferToTexture(Texture *targetTexture) = 0;
  50. virtual void setViewportSize(int w, int h, float fov=45.0f) = 0;
  51. virtual void loadIdentity() = 0;
  52. virtual void setOrthoMode(float xSize=0.0f, float ySize=0.0f) = 0;
  53. virtual void setPerspectiveMode() = 0;
  54. virtual void setTexture(Texture *texture) = 0;
  55. virtual void enableBackfaceCulling(bool val) = 0;
  56. virtual void setClearColor(float r, float g, float b) = 0;
  57. virtual void setClearColor(Color color);
  58. virtual void setAmbientColor(float r, float g, float b);
  59. virtual void clearScreen() = 0;
  60. virtual void translate2D(float x, float y) = 0;
  61. virtual void rotate2D(float angle) = 0;
  62. virtual void scale2D(Vector2 *scale) = 0;
  63. virtual void setFOV(float fov) = 0;
  64. virtual void setVertexColor(float r, float g, float b, float a) = 0;
  65. void pushDataArrayForMesh(Mesh *mesh, int arrayType);
  66. virtual void pushRenderDataArray(RenderDataArray *array) = 0;
  67. virtual RenderDataArray *createRenderDataArrayForMesh(Mesh *mesh, int arrayType) = 0;
  68. virtual RenderDataArray *createRenderDataArray(int arrayType) = 0;
  69. virtual void setRenderArrayData(RenderDataArray *array, float *arrayData) = 0;
  70. virtual void drawArrays(int drawType) = 0;
  71. virtual void translate3D(Vector3 *position) = 0;
  72. virtual void translate3D(float x, float y, float z) = 0;
  73. virtual void scale3D(Vector3 *scale) = 0;
  74. virtual void pushMatrix() = 0;
  75. virtual void popMatrix() = 0;
  76. virtual void setLineSmooth(bool val) = 0;
  77. virtual void setLineSize(float lineSize) = 0;
  78. virtual void enableLighting(bool enable) = 0;
  79. virtual void enableFog(bool enable) = 0;
  80. virtual void setFogProperties(int fogMode, Color color, float density, float startDepth, float endDepth) = 0;
  81. virtual void multModelviewMatrix(Matrix4 m) = 0;
  82. virtual void setModelviewMatrix(Matrix4 m) = 0;
  83. virtual void setBlendingMode(int blendingMode) = 0;
  84. virtual void applyMaterial(Material *material, ShaderBinding *localOptions, unsigned int shaderIndex) = 0;
  85. virtual void clearShader() = 0;
  86. virtual void setDepthFunction(int depthFunction) = 0;
  87. virtual void createVertexBufferForMesh(Mesh *mesh) = 0;
  88. virtual void drawVertexBuffer(VertexBuffer *buffer) = 0;
  89. void setRenderMode(int newRenderMode);
  90. int getRenderMode();
  91. virtual void enableDepthTest(bool val) = 0;
  92. void billboardMatrix();
  93. void billboardMatrixWithScale(Vector3 scale);
  94. void setTextureFilteringMode(int mode);
  95. virtual void enableAlphaTest(bool val) = 0;
  96. virtual void clearBuffer(bool colorBuffer, bool depthBuffer) = 0;
  97. virtual void drawToColorBuffer(bool val) = 0;
  98. Matrix4 getCameraMatrix();
  99. void setCameraMatrix(Matrix4 matrix);
  100. void setCameraPosition(Vector3 pos);
  101. virtual void drawScreenQuad(float qx, float qy) = 0;
  102. int getXRes();
  103. int getYRes();
  104. void clearLights();
  105. void addLight(Vector3 position, Vector3 direction, int type, Color color, float distance, float intensity, Matrix4 *textureMatrix);
  106. void setExposureLevel(float level);
  107. bool rayTriangleIntersect(Vector3 ray_origin, Vector3 ray_direction, Vector3 vert0, Vector3 vert1, Vector3 vert2, Vector3 *hitPoint);
  108. void enableShaders(bool flag);
  109. void addShaderModule(PolycodeShaderModule *module);
  110. virtual bool test2DCoordinate(float x, float y, Polygon *poly, const Matrix4 &matrix, bool billboardMode) = 0;
  111. virtual Matrix4 getProjectionMatrix() = 0;
  112. virtual Matrix4 getModelviewMatrix() = 0;
  113. static const int RENDER_MODE_NORMAL = 0;
  114. static const int RENDER_MODE_WIREFRAME = 1;
  115. static const int BLEND_MODE_NORMAL = 0;
  116. static const int BLEND_MODE_LIGHTEN = 1;
  117. static const int BLEND_MODE_COLOR = 2;
  118. static const int FOG_LINEAR = 0;
  119. static const int FOG_EXP = 1;
  120. static const int FOG_EXP2 = 2;
  121. static const int DEPTH_FUNCTION_GREATER = 0;
  122. static const int DEPTH_FUNCTION_LEQUAL = 1;
  123. static const int TEX_FILTERING_NEAREST = 0;
  124. static const int TEX_FILTERING_LINEAR = 1;
  125. void addShadowMap(Texture *texture);
  126. vector<Texture*> getShadowMapTextures(){ return shadowMapTextures; };
  127. virtual Vector3 Unproject(float x, float y) = 0;
  128. Color ambientColor;
  129. Color clearColor;
  130. float exposureLevel;
  131. Vector3 cameraPosition;
  132. int getNumAreaLights() { return numAreaLights; }
  133. int getNumSpotLights() { return numSpotLights; }
  134. int getNumLights() { return numLights; }
  135. vector<LightInfo> getAreaLights() { return areaLights; }
  136. vector<LightInfo> getSpotLights() { return spotLights; }
  137. protected:
  138. Texture *currentTexture;
  139. Material *currentMaterial;
  140. vector<Texture*> shadowMapTextures;
  141. Texture *currentFrameBufferTexture;
  142. Texture *previousFrameBufferTexture;
  143. int textureFilteringMode;
  144. int renderMode;
  145. Matrix4 cameraMatrix;
  146. PolycodeShaderModule* currentShaderModule;
  147. vector <PolycodeShaderModule*> shaderModules;
  148. vector<LightInfo> lights;
  149. vector<LightInfo> areaLights;
  150. vector<LightInfo> spotLights;
  151. int numLights;
  152. int numAreaLights;
  153. int numSpotLights;
  154. bool shadersEnabled;
  155. float fov;
  156. bool lightingEnabled;
  157. bool orthoMode;
  158. int xRes;
  159. int yRes;
  160. };
  161. }