BsGLSLGpuProgram.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #pragma once
  2. #include "BsGLPrerequisites.h"
  3. #include "BsGpuProgram.h"
  4. namespace BansheeEngine {
  5. /** GLSL low level compiled shader object - this class is used to get at the linked program object
  6. and provide an interface for GLRenderSystem calls. GLSL does not provide access to the
  7. low level code of the shader so this class is really just a dummy place holder.
  8. GLSL uses a program object to represent the active vertex and fragment programs used
  9. but Ogre materials maintain seperate instances of the active vertex and fragment programs
  10. which creates a small problem for GLSL integration. The GLSLGpuProgram class provides the
  11. interface between the GLSLLinkProgramManager , GLRenderSystem, and the active GLSLProgram
  12. instances.
  13. */
  14. class BS_RSGL_EXPORT GLSLGpuProgram : public GpuProgram
  15. {
  16. public:
  17. ~GLSLGpuProgram();
  18. bool isSupported() const;
  19. const GLuint getGLHandle() const { return mGLHandle; }
  20. /** Sets the preprocessor defines use to compile the program. */
  21. void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
  22. /** Sets the preprocessor defines use to compile the program. */
  23. const String& getPreprocessorDefines() const { return mPreprocessorDefines; }
  24. /// Overridden from GpuProgram
  25. const String& getLanguage() const;
  26. /** Returns the operation type that this geometry program expects to
  27. receive as input
  28. */
  29. virtual DrawOperationType getInputOperationType() const
  30. {
  31. return mInputOperationType;
  32. }
  33. /** Returns the operation type that this geometry program will emit
  34. */
  35. virtual DrawOperationType getOutputOperationType() const
  36. {
  37. return mOutputOperationType;
  38. }
  39. /** Returns the maximum number of vertices that this geometry program can
  40. output in a single run
  41. */
  42. virtual int getMaxOutputVertices() const { return mMaxOutputVertices; }
  43. /** Sets the operation type that this geometry program expects to receive
  44. */
  45. virtual void setInputOperationType(DrawOperationType operationType)
  46. {
  47. mInputOperationType = operationType;
  48. }
  49. /** Set the operation type that this geometry program will emit
  50. */
  51. virtual void setOutputOperationType(DrawOperationType operationType)
  52. {
  53. mOutputOperationType = operationType;
  54. }
  55. /** Set the maximum number of vertices that a single run of this geometry program
  56. can emit.
  57. */
  58. virtual void setMaxOutputVertices(int maxOutputVertices)
  59. {
  60. mMaxOutputVertices = maxOutputVertices;
  61. }
  62. const VertexDeclaration& getInputAttributes() const { return *mVertexDeclaration; }
  63. /// Get the assigned GL program id
  64. const UINT32 getProgramID() const { return mProgramID; }
  65. private:
  66. friend class GLSLProgramFactory;
  67. GLSLGpuProgram(const String& source, const String& entryPoint, GpuProgramType gptype,
  68. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes, bool isAdjacencyInfoRequired);
  69. /**
  70. * @copydoc GpuProgram::initialize_internal()
  71. */
  72. void initialize_internal();
  73. /**
  74. * @copydoc GpuProgram::destroy_internal()
  75. */
  76. void destroy_internal();
  77. private:
  78. UINT32 mProgramID;
  79. GLuint mGLHandle;
  80. DrawOperationType mInputOperationType;
  81. DrawOperationType mOutputOperationType;
  82. int mMaxOutputVertices;
  83. String mPreprocessorDefines;
  84. VertexDeclarationPtr mVertexDeclaration;
  85. /// keep track of the number of vertex shaders created
  86. static UINT32 mVertexShaderCount;
  87. /// keep track of the number of fragment shaders created
  88. static UINT32 mFragmentShaderCount;
  89. /// keep track of the number of geometry shaders created
  90. static UINT32 mGeometryShaderCount;
  91. /// keep track of the number of hull shaders created
  92. static UINT32 mHullShaderCount;
  93. /// keep track of the number of domain shaders created
  94. static UINT32 mDomainShaderCount;
  95. /************************************************************************/
  96. /* SERIALIZATION */
  97. /************************************************************************/
  98. public:
  99. friend class GLSLGpuProgramRTTI;
  100. static RTTITypeBase* getRTTIStatic();
  101. virtual RTTITypeBase* getRTTI() const;
  102. };
  103. }