CmGLSLLinkProgram.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 "CmGLPrerequisites.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 CM_RSGL_EXPORT 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. /// build uniform references from active named uniforms
  62. void buildGLUniformReferences(void);
  63. /// extract attributes
  64. void extractAttributes(void);
  65. typedef set<GLuint>::type AttributeSet;
  66. // Custom attribute bindings
  67. AttributeSet mValidAttributes;
  68. /// Name / attribute list
  69. struct CustomAttribute
  70. {
  71. String name;
  72. GLuint attrib;
  73. CustomAttribute(const String& _name, GLuint _attrib)
  74. :name(_name), attrib(_attrib) {}
  75. };
  76. static CustomAttribute msCustomAttributes[];
  77. public:
  78. /// constructor should only be used by GLSLLinkProgramManager
  79. GLSLLinkProgram(GLSLGpuProgram* vertexProgram, GLSLGpuProgram* geometryProgram, GLSLGpuProgram* fragmentProgram);
  80. ~GLSLLinkProgram(void);
  81. /** Makes a program object active by making sure it is linked and then putting it in use.
  82. */
  83. void activate(void);
  84. /** updates program object uniforms using data from GpuProgramParamters.
  85. normally called by GLSLGpuProgram::bindParameters() just before rendering occurs.
  86. */
  87. void updateUniforms(GpuProgramParametersSharedPtr params, UINT16 mask, GpuProgramType fromProgType);
  88. /// get the GL Handle for the program object
  89. GLhandleARB getGLHandle(void) const { return mGLHandle; }
  90. /// Get the index of a non-standard attribute bound in the linked code
  91. GLuint getAttributeIndex(VertexElementSemantic semantic, UINT32 index);
  92. /// Is a non-standard attribute bound in the linked code?
  93. bool isAttributeValid(VertexElementSemantic semantic, UINT32 index);
  94. };
  95. }
  96. #endif // __GLSLLinkProgram_H__