PolyOpenGLGraphicsInterface.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. Copyright (C) 2015 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 "polycode/core/PolyGlobals.h"
  21. #include "polycode/core/PolyRenderer.h"
  22. #include "polycode/core/PolyTexture.h"
  23. #if PLATFORM == PLATFORM_MAC
  24. #include <OpenGL/gl.h>
  25. #include <OpenGL/glext.h>
  26. #include <OpenGL/glu.h>
  27. #elif PLATFORM == PLATFORM_IOS
  28. #include <OpenGLES/ES2/gl.h>
  29. #include <OpenGLES/ES2/glext.h>
  30. #elif PLATFORM == PLATFORM_WINDOWS
  31. #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PC_APP || WINAPI == WINAPI_FAMILIY_PHONE_APP)
  32. #define STRICT_OPENGLES2
  33. #include <angle/GLES2/gl2.h>
  34. #include <angle/GLES2/gl2ext.h>
  35. #include <angle/EGL/egl.h>
  36. #include <angle/EGL/eglext.h>
  37. #include <angle/EGL/eglplatform.h>
  38. #include <angle/angle_windowsstore.h>
  39. #else
  40. #include <glew/GL/glew.h>
  41. #endif
  42. #else
  43. #if defined(USE_EGL)
  44. #include <angle/EGL/egl.h>
  45. #include <angle/EGL/eglext.h>
  46. #include <angle/GLES2/gl2.h>
  47. #else
  48. #include <GL/gl.h>
  49. #include <GL/glu.h>
  50. #include <GL/glext.h>
  51. #endif
  52. #endif
  53. namespace Polycode {
  54. class _PolyExport OpenGLGraphicsInterface : public GraphicsInterface {
  55. public:
  56. OpenGLGraphicsInterface();
  57. ~OpenGLGraphicsInterface();
  58. // implementation
  59. void createTexture(Texture *texture);
  60. void destroyTexture(Texture *texture);
  61. void setViewport(unsigned int x,unsigned int y,unsigned int width, unsigned height);
  62. void clearBuffers(const Color &clearColor, bool colorBuffer, bool depthBuffer, bool stencilBuffer);
  63. void setParamInShader(Shader *shader, ProgramParam *param, LocalShaderParam *localParam);
  64. void setAttributeInShader(Shader *shader, ProgramAttribute *attribute, AttributeBinding *attributeBinding);
  65. void disableAttribute(Shader *shader, const ProgramAttribute &attribute);
  66. void useShader(Shader *shader);
  67. void createProgram(ShaderProgram *program);
  68. void destroyProgram(ShaderProgram *program);
  69. void createShader(Shader *shader);
  70. void destroyShader(Shader *shader);
  71. void beginDrawCall();
  72. void endDrawCall();
  73. void setBlendingMode(unsigned int blendingMode);
  74. void createRenderBuffer(RenderBuffer *renderBuffer);
  75. void destroyRenderBuffer(RenderBuffer *renderBuffer);
  76. void bindRenderBuffer(RenderBuffer *renderBuffer);
  77. void createVertexBuffer(VertexDataArray *dataArray);
  78. void createIndexBuffer(IndexDataArray *dataArray);
  79. void destroyBuffer(RenderDataArray *array);
  80. void drawIndices(int type, IndexDataArray *indexArray);
  81. void drawArrays(int type, unsigned int vertexCount);
  82. void enableDepthTest(bool val);
  83. void enableDepthWrite(bool val);
  84. void enableBackfaceCulling(bool val);
  85. void setLineSize(Number lineSize);
  86. void setWireframeMode(bool val);
  87. void enableScissor(bool val);
  88. void setScissorBox(const Polycode::Rectangle &box);
  89. bool lineSmooth;
  90. protected:
  91. GLuint currentShaderID;
  92. int textureIndex;
  93. static GLenum getGLDrawMode(int polycodeMode);
  94. static int getPolycodeParamType(int glType);
  95. static int getAttributeSize(int glType);
  96. void setUniformMatrix(GLint paramLocation, const Polycode::Matrix4& matrix);
  97. };
  98. }