PolyRenderer.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. Number distance;
  31. Number 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, Number fov=45.0f) = 0;
  51. virtual void loadIdentity() = 0;
  52. virtual void setOrthoMode(Number xSize=0.0f, Number ySize=0.0f) = 0;
  53. virtual void _setOrthoMode() = 0;
  54. virtual void setPerspectiveMode() = 0;
  55. virtual void setTexture(Texture *texture) = 0;
  56. virtual void enableBackfaceCulling(bool val) = 0;
  57. virtual void setClearColor(Number r, Number g, Number b) = 0;
  58. virtual void setClearColor(Color color);
  59. virtual void setAmbientColor(Number r, Number g, Number b);
  60. virtual void clearScreen() = 0;
  61. virtual void translate2D(Number x, Number y) = 0;
  62. virtual void rotate2D(Number angle) = 0;
  63. virtual void scale2D(Vector2 *scale) = 0;
  64. virtual void setFOV(Number fov) = 0;
  65. virtual void setVertexColor(Number r, Number g, Number b, Number a) = 0;
  66. void pushDataArrayForMesh(Mesh *mesh, int arrayType);
  67. virtual void pushRenderDataArray(RenderDataArray *array) = 0;
  68. virtual RenderDataArray *createRenderDataArrayForMesh(Mesh *mesh, int arrayType) = 0;
  69. virtual RenderDataArray *createRenderDataArray(int arrayType) = 0;
  70. virtual void setRenderArrayData(RenderDataArray *array, Number *arrayData) = 0;
  71. virtual void drawArrays(int drawType) = 0;
  72. virtual void translate3D(Vector3 *position) = 0;
  73. virtual void translate3D(Number x, Number y, Number z) = 0;
  74. virtual void scale3D(Vector3 *scale) = 0;
  75. virtual void pushMatrix() = 0;
  76. virtual void popMatrix() = 0;
  77. virtual void setLineSmooth(bool val) = 0;
  78. virtual void setLineSize(Number lineSize) = 0;
  79. virtual void enableLighting(bool enable) = 0;
  80. virtual void enableFog(bool enable) = 0;
  81. virtual void setFogProperties(int fogMode, Color color, Number density, Number startDepth, Number endDepth) = 0;
  82. virtual void multModelviewMatrix(Matrix4 m) = 0;
  83. virtual void setModelviewMatrix(Matrix4 m) = 0;
  84. virtual void setBlendingMode(int blendingMode) = 0;
  85. virtual void applyMaterial(Material *material, ShaderBinding *localOptions, unsigned int shaderIndex) = 0;
  86. virtual void clearShader() = 0;
  87. virtual void setDepthFunction(int depthFunction) = 0;
  88. virtual void createVertexBufferForMesh(Mesh *mesh) = 0;
  89. virtual void drawVertexBuffer(VertexBuffer *buffer) = 0;
  90. void setRenderMode(int newRenderMode);
  91. int getRenderMode();
  92. virtual void enableDepthTest(bool val) = 0;
  93. virtual void enableDepthWrite(bool val) = 0;
  94. void billboardMatrix();
  95. void billboardMatrixWithScale(Vector3 scale);
  96. void setTextureFilteringMode(int mode);
  97. virtual void enableAlphaTest(bool val) = 0;
  98. virtual void clearBuffer(bool colorBuffer, bool depthBuffer) = 0;
  99. virtual void drawToColorBuffer(bool val) = 0;
  100. Matrix4 getCameraMatrix();
  101. void setCameraMatrix(Matrix4 matrix);
  102. void setCameraPosition(Vector3 pos);
  103. virtual void drawScreenQuad(Number qx, Number qy) = 0;
  104. int getXRes();
  105. int getYRes();
  106. void clearLights();
  107. void addLight(Vector3 position, Vector3 direction, int type, Color color, Number distance, Number intensity, Matrix4 *textureMatrix);
  108. void setExposureLevel(Number level);
  109. bool rayTriangleIntersect(Vector3 ray_origin, Vector3 ray_direction, Vector3 vert0, Vector3 vert1, Vector3 vert2, Vector3 *hitPoint);
  110. void enableShaders(bool flag);
  111. void addShaderModule(PolycodeShaderModule *module);
  112. virtual bool test2DCoordinate(Number x, Number y, Polygon *poly, const Matrix4 &matrix, bool billboardMode) = 0;
  113. virtual Matrix4 getProjectionMatrix() = 0;
  114. virtual Matrix4 getModelviewMatrix() = 0;
  115. static const int RENDER_MODE_NORMAL = 0;
  116. static const int RENDER_MODE_WIREFRAME = 1;
  117. static const int BLEND_MODE_NORMAL = 0;
  118. static const int BLEND_MODE_LIGHTEN = 1;
  119. static const int BLEND_MODE_COLOR = 2;
  120. static const int FOG_LINEAR = 0;
  121. static const int FOG_EXP = 1;
  122. static const int FOG_EXP2 = 2;
  123. static const int DEPTH_FUNCTION_GREATER = 0;
  124. static const int DEPTH_FUNCTION_LEQUAL = 1;
  125. static const int TEX_FILTERING_NEAREST = 0;
  126. static const int TEX_FILTERING_LINEAR = 1;
  127. void addShadowMap(Texture *texture);
  128. vector<Texture*> getShadowMapTextures(){ return shadowMapTextures; };
  129. virtual Vector3 Unproject(Number x, Number y) = 0;
  130. Color ambientColor;
  131. Color clearColor;
  132. Number exposureLevel;
  133. Vector3 cameraPosition;
  134. int getNumAreaLights() { return numAreaLights; }
  135. int getNumSpotLights() { return numSpotLights; }
  136. int getNumLights() { return numLights; }
  137. vector<LightInfo> getAreaLights() { return areaLights; }
  138. vector<LightInfo> getSpotLights() { return spotLights; }
  139. protected:
  140. Texture *currentTexture;
  141. Material *currentMaterial;
  142. vector<Texture*> shadowMapTextures;
  143. Texture *currentFrameBufferTexture;
  144. Texture *previousFrameBufferTexture;
  145. int textureFilteringMode;
  146. int renderMode;
  147. Matrix4 cameraMatrix;
  148. PolycodeShaderModule* currentShaderModule;
  149. vector <PolycodeShaderModule*> shaderModules;
  150. vector<LightInfo> lights;
  151. vector<LightInfo> areaLights;
  152. vector<LightInfo> spotLights;
  153. int numLights;
  154. int numAreaLights;
  155. int numSpotLights;
  156. bool shadersEnabled;
  157. Number fov;
  158. bool lightingEnabled;
  159. bool orthoMode;
  160. int xRes;
  161. int yRes;
  162. };
  163. }