COpenGLSLMaterialRenderer.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #ifndef __C_OPENGL_SHADER_LANGUAGE_MATERIAL_RENDERER_H_INCLUDED__
  5. #define __C_OPENGL_SHADER_LANGUAGE_MATERIAL_RENDERER_H_INCLUDED__
  6. #include "IrrCompileConfig.h"
  7. #ifdef _IRR_COMPILE_WITH_OPENGL_
  8. #ifdef _IRR_WINDOWS_API_
  9. #define WIN32_LEAN_AND_MEAN
  10. #include <windows.h>
  11. #include <GL/gl.h>
  12. #include "glext.h"
  13. #else
  14. #if defined(_IRR_OPENGL_USE_EXTPOINTER_)
  15. #define GL_GLEXT_LEGACY 1
  16. #else
  17. #define GL_GLEXT_PROTOTYPES 1
  18. #endif
  19. #if defined(_IRR_OSX_PLATFORM_)
  20. #include <OpenGL/gl.h>
  21. #else
  22. #include <GL/gl.h>
  23. #endif
  24. #if defined(_IRR_OPENGL_USE_EXTPOINTER_)
  25. #include "glext.h"
  26. #endif
  27. #endif
  28. #include "IMaterialRenderer.h"
  29. #include "IMaterialRendererServices.h"
  30. #include "IGPUProgrammingServices.h"
  31. #include "irrArray.h"
  32. #include "irrString.h"
  33. namespace irr
  34. {
  35. namespace video
  36. {
  37. class COpenGLDriver;
  38. class IShaderConstantSetCallBack;
  39. //! Class for using GLSL shaders with OpenGL
  40. //! Please note: This renderer implements its own IMaterialRendererServices
  41. class COpenGLSLMaterialRenderer : public IMaterialRenderer, public IMaterialRendererServices
  42. {
  43. public:
  44. //! Constructor
  45. COpenGLSLMaterialRenderer(
  46. COpenGLDriver* driver,
  47. s32& outMaterialTypeNr,
  48. const c8* vertexShaderProgram = 0,
  49. const c8* vertexShaderEntryPointName = 0,
  50. E_VERTEX_SHADER_TYPE vsCompileTarget = video::EVST_VS_1_1,
  51. const c8* pixelShaderProgram = 0,
  52. const c8* pixelShaderEntryPointName = 0,
  53. E_PIXEL_SHADER_TYPE psCompileTarget = video::EPST_PS_1_1,
  54. const c8* geometryShaderProgram = 0,
  55. const c8* geometryShaderEntryPointName = "main",
  56. E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
  57. scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
  58. scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
  59. u32 verticesOut = 0,
  60. IShaderConstantSetCallBack* callback = 0,
  61. IMaterialRenderer* baseMaterial = 0,
  62. s32 userData = 0);
  63. //! Destructor
  64. virtual ~COpenGLSLMaterialRenderer();
  65. virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
  66. bool resetAllRenderstates, IMaterialRendererServices* services);
  67. virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
  68. virtual void OnUnsetMaterial();
  69. //! Returns if the material is transparent.
  70. virtual bool isTransparent() const;
  71. // implementations for the render services
  72. virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates);
  73. virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count);
  74. virtual bool setVertexShaderConstant(const c8* name, const bool* bools, int count);
  75. virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count);
  76. virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
  77. virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count);
  78. virtual bool setPixelShaderConstant(const c8* name, const bool* bools, int count);
  79. virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count);
  80. virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
  81. virtual IVideoDriver* getVideoDriver();
  82. protected:
  83. //! constructor only for use by derived classes who want to
  84. //! create a fall back material for example.
  85. COpenGLSLMaterialRenderer(COpenGLDriver* driver,
  86. IShaderConstantSetCallBack* callback,
  87. IMaterialRenderer* baseMaterial,
  88. s32 userData=0);
  89. void init(s32& outMaterialTypeNr,
  90. const c8* vertexShaderProgram,
  91. const c8* pixelShaderProgram,
  92. const c8* geometryShaderProgram,
  93. scene::E_PRIMITIVE_TYPE inType=scene::EPT_TRIANGLES,
  94. scene::E_PRIMITIVE_TYPE outType=scene::EPT_TRIANGLE_STRIP,
  95. u32 verticesOut=0);
  96. bool createProgram();
  97. bool createShader(GLenum shaderType, const char* shader);
  98. bool linkProgram();
  99. COpenGLDriver* Driver;
  100. IShaderConstantSetCallBack* CallBack;
  101. IMaterialRenderer* BaseMaterial;
  102. struct SUniformInfo
  103. {
  104. core::stringc name;
  105. GLenum type;
  106. };
  107. GLhandleARB Program;
  108. GLuint Program2;
  109. core::array<SUniformInfo> UniformInfo;
  110. s32 UserData;
  111. };
  112. } // end namespace video
  113. } // end namespace irr
  114. #endif // compile with OpenGL
  115. #endif // if included