CmGLSLProgram.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __GLSLProgram_H__
  25. #define __GLSLProgram_H__
  26. #include "CmGLPrerequisites.h"
  27. #include "CmHighLevelGpuProgram.h"
  28. namespace CamelotFramework {
  29. /** Specialisation of HighLevelGpuProgram to provide support for OpenGL
  30. Shader Language (GLSL).
  31. @remarks
  32. GLSL has no target assembler or entry point specification like DirectX 9 HLSL.
  33. Vertex and Fragment shaders only have one entry point called "main".
  34. When a shader is compiled, microcode is generated but can not be accessed by
  35. the application.
  36. GLSL also does not provide assembler low level output after compiling. The GL Render
  37. system assumes that the Gpu program is a GL Gpu program so GLSLProgram will create a
  38. GLSLGpuProgram that is subclassed from GLGpuProgram for the low level implementation.
  39. The GLSLProgram class will create a shader object and compile the source but will
  40. not create a program object. It's up to GLSLGpuProgram class to request a program object
  41. to link the shader object to.
  42. @note
  43. GLSL supports multiple modular shader objects that can be attached to one program
  44. object to form a single shader. This is supported through the "attach" material script
  45. command. All the modules to be attached are listed on the same line as the attach command
  46. seperated by white space.
  47. */
  48. class CM_RSGL_EXPORT GLSLProgram : public HighLevelGpuProgram
  49. {
  50. public:
  51. ~GLSLProgram();
  52. const GLuint getGLHandle() const { return mGLHandle; }
  53. /** Sets the preprocessor defines use to compile the program. */
  54. void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
  55. /** Sets the preprocessor defines use to compile the program. */
  56. const String& getPreprocessorDefines(void) const { return mPreprocessorDefines; }
  57. /// Overridden from GpuProgram
  58. const String& getLanguage(void) const;
  59. /** Returns the operation type that this geometry program expects to
  60. receive as input
  61. */
  62. virtual DrawOperationType getInputOperationType(void) const
  63. { return mInputOperationType; }
  64. /** Returns the operation type that this geometry program will emit
  65. */
  66. virtual DrawOperationType getOutputOperationType(void) const
  67. { return mOutputOperationType; }
  68. /** Returns the maximum number of vertices that this geometry program can
  69. output in a single run
  70. */
  71. virtual int getMaxOutputVertices(void) const { return mMaxOutputVertices; }
  72. /** Sets the operation type that this geometry program expects to receive
  73. */
  74. virtual void setInputOperationType(DrawOperationType operationType)
  75. { mInputOperationType = operationType; }
  76. /** Set the operation type that this geometry program will emit
  77. */
  78. virtual void setOutputOperationType(DrawOperationType operationType)
  79. { mOutputOperationType = operationType; }
  80. /** Set the maximum number of vertices that a single run of this geometry program
  81. can emit.
  82. */
  83. virtual void setMaxOutputVertices(int maxOutputVertices)
  84. { mMaxOutputVertices = maxOutputVertices; }
  85. const VertexDeclaration& getInputAttributes() const { return *mVertexDeclaration; }
  86. protected:
  87. friend class GLSLProgramFactory;
  88. GLSLProgram(const String& source, const String& entryPoint, const String& language,
  89. GpuProgramType gptype, GpuProgramProfile profile, const Vector<HGpuProgInclude>::type* includes,
  90. bool isAdjacencyInfoRequired = false);
  91. /**
  92. * @copydoc HighLevelGpuProgram::initialize_internal()
  93. */
  94. void initialize_internal();
  95. /**
  96. * @copydoc HighLevelGpuProgram::destroy_internal()
  97. */
  98. void destroy_internal();
  99. private:
  100. /// GL handle for shader object
  101. GLuint mGLHandle;
  102. /// flag indicating if shader object successfully compiled
  103. GLint mCompiled;
  104. /// The input operation type for this (geometry) program
  105. DrawOperationType mInputOperationType;
  106. /// The output operation type for this (geometry) program
  107. DrawOperationType mOutputOperationType;
  108. /// The maximum amount of vertices that this (geometry) program can output
  109. int mMaxOutputVertices;
  110. /// Preprocessor options
  111. String mPreprocessorDefines;
  112. VertexDeclarationPtr mVertexDeclaration;
  113. /************************************************************************/
  114. /* SERIALIZATION */
  115. /************************************************************************/
  116. public:
  117. friend class GLSLProgramRTTI;
  118. static RTTITypeBase* getRTTIStatic();
  119. virtual RTTITypeBase* getRTTI() const;
  120. };
  121. }
  122. #endif // __GLSLProgram_H__