PolyGLES1Renderer.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 "PolyString.h"
  21. #include "PolyLogger.h"
  22. #include "PolyGlobals.h"
  23. #include "PolyRenderer.h"
  24. #include "PolyTexture.h"
  25. #include "PolyGLES1Texture.h"
  26. #include "PolyCubemap.h"
  27. #include "PolyFixedShader.h"
  28. #include "PolyMesh.h"
  29. #include <OpenGLES/ES1/gl.h>
  30. #include <OpenGLES/ES1/glext.h>
  31. #include <glu.h>
  32. namespace Polycode {
  33. class _PolyExport OpenGLES1Renderer : public Renderer {
  34. public:
  35. OpenGLES1Renderer();
  36. virtual ~OpenGLES1Renderer();
  37. void Resize(int xRes, int yRes);
  38. void BeginRender();
  39. void EndRender();
  40. Cubemap *createCubemap(Texture *t0, Texture *t1, Texture *t2, Texture *t3, Texture *t4, Texture *t5);
  41. Texture *createTexture(unsigned int width, unsigned int height, char *textureData, bool clamp, int type=Image::IMAGE_RGBA);
  42. Texture *createFramebufferTexture(unsigned int width, unsigned int height);
  43. void createRenderTextures(Texture **colorBuffer, Texture **depthBuffer, int width, int height);
  44. void enableAlphaTest(bool val);
  45. void createVertexBufferForMesh(Mesh *mesh);
  46. void drawVertexBuffer(VertexBuffer *buffer);
  47. void bindFrameBufferTexture(Texture *texture);
  48. void unbindFramebuffers();
  49. void setOrthoMode();
  50. void setPerspectiveMode();
  51. void enableBackfaceCulling(bool val);
  52. void setViewportSize(int w, int h, Number fov=45.0f);
  53. void setLineSmooth(bool val);
  54. void loadIdentity();
  55. void setClearColor(Number r, Number g, Number b);
  56. void setTexture(Texture *texture);
  57. void draw2DPolygon(Polygon *polygon);
  58. void draw2DVertex(Vertex *vertex);
  59. void renderToTexture(Texture *targetTexture);
  60. void renderZBufferToTexture(Texture *targetTexture);
  61. void clearScreen(bool clearColor = true, bool clearDepth = true);
  62. void translate2D(Number x, Number y);
  63. void rotate2D(Number angle);
  64. void scale2D(Vector2 *scale);
  65. void setLineSize(Number lineSize);
  66. void setVertexColor(Number r, Number g, Number b, Number a);
  67. void setBlendingMode(int blendingMode);
  68. void enableLighting(bool enable);
  69. void enableFog(bool enable);
  70. void setFogProperties(int fogMode, Color color, Number density, Number startDepth, Number endDepth);
  71. void draw3DPolygon(Polygon *polygon);
  72. void draw3DVertex(Vertex *vertex, Vector2 *faceUV);
  73. void draw3DVertex2UV(Vertex *vertex, Vector2 *faceUV1, Vector2 *faceUV2);
  74. void draw3DLine(Vector3 origin, Vector3 direction, Number length, Color color);
  75. virtual void setNormal(const Vector3 &normal);
  76. void translate3D(Vector3 *position);
  77. void translate3D(Number x, Number y, Number z);
  78. void scale3D(Vector3 *scale);
  79. Matrix4 getProjectionMatrix();
  80. Matrix4 getModelviewMatrix();
  81. void setModelviewMatrix(Matrix4 m);
  82. void multModelviewMatrix(Matrix4 m);
  83. void enableDepthTest(bool val);
  84. void drawScreenQuad(Number qx, Number qy);
  85. void beginRenderOperation(int meshType);
  86. void endRenderOperation();
  87. void pushMatrix();
  88. void popMatrix();
  89. bool test2DCoordinate(Number x, Number y, Polygon *poly, const Matrix4 &matrix, bool billboardMode);
  90. void setFOV(Number fov);
  91. Vector3 Unproject(Number x, Number y);
  92. void clearShader();
  93. void applyMaterial(Material *material, ShaderBinding *localOptions, unsigned int shaderIndex);
  94. protected:
  95. GLuint defaultFramebuffer, colorRenderbuffer;
  96. Number nearPlane;
  97. Number farPlane;
  98. GLfloat sceneProjectionMatrix[16];
  99. };
  100. }