OgreGLSLLinkProgram.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 __GLSLLinkProgram_H__
  25. #define __GLSLLinkProgram_H__
  26. #include "OgreGLPrerequisites.h"
  27. #include "CmGpuProgram.h"
  28. #include "CmHardwareVertexBuffer.h"
  29. namespace CamelotEngine {
  30. /// structure used to keep track of named uniforms in the linked program object
  31. struct GLUniformReference
  32. {
  33. /// GL location handle
  34. GLint mLocation;
  35. /// Which type of program params will this value come from?
  36. GpuProgramType mSourceProgType;
  37. /// The constant definition it relates to
  38. const GpuConstantDefinition* mConstantDef;
  39. };
  40. typedef vector<GLUniformReference>::type GLUniformReferenceList;
  41. typedef GLUniformReferenceList::iterator GLUniformReferenceIterator;
  42. /** C++ encapsulation of GLSL Program Object
  43. */
  44. class _OgreGLExport GLSLLinkProgram
  45. {
  46. private:
  47. /// container of uniform references that are active in the program object
  48. GLUniformReferenceList mGLUniformReferences;
  49. /// Linked vertex program
  50. GLSLGpuProgram* mVertexProgram;
  51. /// Linked geometry program
  52. GLSLGpuProgram* mGeometryProgram;
  53. /// Linked fragment program
  54. GLSLGpuProgram* mFragmentProgram;
  55. /// flag to indicate that uniform references have already been built
  56. bool mUniformRefsBuilt;
  57. /// GL handle for the program object
  58. GLhandleARB mGLHandle;
  59. /// flag indicating that the program object has been successfully linked
  60. GLint mLinked;
  61. /// flag indicating skeletal animation is being performed
  62. bool mSkeletalAnimation;
  63. /// build uniform references from active named uniforms
  64. void buildGLUniformReferences(void);
  65. /// extract attributes
  66. void extractAttributes(void);
  67. typedef set<GLuint>::type AttributeSet;
  68. // Custom attribute bindings
  69. AttributeSet mValidAttributes;
  70. /// Name / attribute list
  71. struct CustomAttribute
  72. {
  73. String name;
  74. GLuint attrib;
  75. CustomAttribute(const String& _name, GLuint _attrib)
  76. :name(_name), attrib(_attrib) {}
  77. };
  78. static CustomAttribute msCustomAttributes[];
  79. public:
  80. /// constructor should only be used by GLSLLinkProgramManager
  81. GLSLLinkProgram(GLSLGpuProgram* vertexProgram, GLSLGpuProgram* geometryProgram, GLSLGpuProgram* fragmentProgram);
  82. ~GLSLLinkProgram(void);
  83. /** Makes a program object active by making sure it is linked and then putting it in use.
  84. */
  85. void activate(void);
  86. /** updates program object uniforms using data from GpuProgramParamters.
  87. normally called by GLSLGpuProgram::bindParameters() just before rendering occurs.
  88. */
  89. void updateUniforms(GpuProgramParametersSharedPtr params, UINT16 mask, GpuProgramType fromProgType);
  90. /** updates program object uniforms using data from pass iteration GpuProgramParamters.
  91. normally called by GLSLGpuProgram::bindMultiPassParameters() just before multi pass rendering occurs.
  92. */
  93. void updatePassIterationUniforms(GpuProgramParametersSharedPtr params);
  94. /// get the GL Handle for the program object
  95. GLhandleARB getGLHandle(void) const { return mGLHandle; }
  96. /** Sets whether the linked program includes the required instructions
  97. to perform skeletal animation.
  98. @remarks
  99. If this is set to true, OGRE will not blend the geometry according to
  100. skeletal animation, it will expect the vertex program to do it.
  101. */
  102. void setSkeletalAnimationIncluded(bool included)
  103. { mSkeletalAnimation = included; }
  104. /** Returns whether the linked program includes the required instructions
  105. to perform skeletal animation.
  106. @remarks
  107. If this returns true, OGRE will not blend the geometry according to
  108. skeletal animation, it will expect the vertex program to do it.
  109. */
  110. bool isSkeletalAnimationIncluded(void) const { return mSkeletalAnimation; }
  111. /// Get the index of a non-standard attribute bound in the linked code
  112. GLuint getAttributeIndex(VertexElementSemantic semantic, UINT32 index);
  113. /// Is a non-standard attribute bound in the linked code?
  114. bool isAttributeValid(VertexElementSemantic semantic, UINT32 index);
  115. };
  116. }
  117. #endif // __GLSLLinkProgram_H__