COGLES2MaterialRenderer.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright (C) 2013 Patryk Nadrowski
  2. // Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
  3. // OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0
  4. // driver implemented by Amundis.
  5. // This file is part of the "Irrlicht Engine".
  6. // For conditions of distribution and use, see copyright notice in Irrlicht.h
  7. #ifndef __C_OGLES2_SL_MATERIAL_RENDERER_H_INCLUDED__
  8. #define __C_OGLES2_SL_MATERIAL_RENDERER_H_INCLUDED__
  9. #include "IrrCompileConfig.h"
  10. #ifdef _IRR_COMPILE_WITH_OGLES2_
  11. #if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  12. #include <OpenGLES/ES2/gl.h>
  13. #include <OpenGLES/ES2/glext.h>
  14. #else
  15. #include <GLES2/gl2.h>
  16. #include <EGL/eglplatform.h>
  17. #endif
  18. #include "EMaterialTypes.h"
  19. #include "EVertexAttributes.h"
  20. #include "IMaterialRenderer.h"
  21. #include "IMaterialRendererServices.h"
  22. #include "IGPUProgrammingServices.h"
  23. #include "IShaderConstantSetCallBack.h"
  24. #include "irrArray.h"
  25. #include "irrString.h"
  26. namespace irr
  27. {
  28. namespace video
  29. {
  30. class COGLES2Driver;
  31. //! Class for using GLSL shaders with OpenGL ES 2.0
  32. //! Please note: This renderer implements its own IMaterialRendererServices
  33. class COGLES2MaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices
  34. {
  35. public:
  36. //! Constructor
  37. COGLES2MaterialRenderer(
  38. COGLES2Driver* driver,
  39. s32& outMaterialTypeNr,
  40. const c8* vertexShaderProgram = 0,
  41. const c8* pixelShaderProgram = 0,
  42. IShaderConstantSetCallBack* callback = 0,
  43. E_MATERIAL_TYPE baseMaterial = EMT_SOLID,
  44. s32 userData = 0);
  45. //! Destructor
  46. virtual ~COGLES2MaterialRenderer();
  47. GLuint getProgram() const;
  48. virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
  49. bool resetAllRenderstates, IMaterialRendererServices* services);
  50. virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
  51. virtual void OnUnsetMaterial();
  52. //! Returns if the material is transparent.
  53. virtual bool isTransparent() const;
  54. // implementations for the render services
  55. virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates);
  56. virtual s32 getVertexShaderConstantID(const c8* name);
  57. virtual s32 getPixelShaderConstantID(const c8* name);
  58. virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
  59. virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
  60. virtual bool setVertexShaderConstant(s32 index, const f32* floats, int count);
  61. virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count);
  62. virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count);
  63. virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count);
  64. virtual IVideoDriver* getVideoDriver();
  65. protected:
  66. //! constructor only for use by derived classes who want to
  67. //! create a fall back material for example.
  68. COGLES2MaterialRenderer(COGLES2Driver* driver,
  69. IShaderConstantSetCallBack* callback = 0,
  70. E_MATERIAL_TYPE baseMaterial = EMT_SOLID,
  71. s32 userData = 0);
  72. void init(s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram, bool addMaterial = true);
  73. bool createShader(GLenum shaderType, const char* shader);
  74. bool linkProgram();
  75. COGLES2Driver* Driver;
  76. IShaderConstantSetCallBack* CallBack;
  77. bool Alpha;
  78. bool Blending;
  79. bool FixedBlending;
  80. struct SUniformInfo
  81. {
  82. core::stringc name;
  83. GLenum type;
  84. GLint location;
  85. };
  86. GLuint Program;
  87. core::array<SUniformInfo> UniformInfo;
  88. s32 UserData;
  89. };
  90. } // end namespace video
  91. } // end namespace irr
  92. #endif // compile with OpenGL ES 2.0
  93. #endif // if included