CmGLGpuProgram.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #include "CmGLGpuProgram.h"
  25. #include "CmException.h"
  26. namespace CamelotEngine
  27. {
  28. GLGpuProgram::GLGpuProgram(const String& source, const String& entryPoint, const String& language,
  29. GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired)
  30. : GpuProgram(source, entryPoint, language, gptype, profile, isAdjacencyInfoRequired)
  31. {
  32. }
  33. GLGpuProgram::~GLGpuProgram()
  34. {
  35. // have to call this here reather than in Resource destructor
  36. // since calling virtual methods in base destructors causes crash
  37. unload_internal();
  38. }
  39. GLuint GLGpuProgram::getAttributeIndex(VertexElementSemantic semantic, CamelotEngine::UINT32 index)
  40. {
  41. return getFixedAttributeIndex(semantic, index);
  42. }
  43. GLuint GLGpuProgram::getFixedAttributeIndex(VertexElementSemantic semantic, CamelotEngine::UINT32 index)
  44. {
  45. // Some drivers (e.g. OS X on nvidia) incorrectly determine the attribute binding automatically
  46. // and end up aliasing existing built-ins. So avoid! Fixed builtins are:
  47. // a builtin custom attrib name
  48. // ----------------------------------------------
  49. // 0 gl_Vertex vertex
  50. // 1 n/a blendWeights
  51. // 2 gl_Normal normal
  52. // 3 gl_Color colour
  53. // 4 gl_SecondaryColor secondary_colour
  54. // 5 gl_FogCoord fog_coord
  55. // 7 n/a blendIndices
  56. // 8 gl_MultiTexCoord0 uv0
  57. // 9 gl_MultiTexCoord1 uv1
  58. // 10 gl_MultiTexCoord2 uv2
  59. // 11 gl_MultiTexCoord3 uv3
  60. // 12 gl_MultiTexCoord4 uv4
  61. // 13 gl_MultiTexCoord5 uv5
  62. // 14 gl_MultiTexCoord6 uv6, tangent
  63. // 15 gl_MultiTexCoord7 uv7, binormal
  64. switch(semantic)
  65. {
  66. case VES_POSITION:
  67. return 0;
  68. case VES_BLEND_WEIGHTS:
  69. return 1;
  70. case VES_NORMAL:
  71. return 2;
  72. case VES_DIFFUSE:
  73. return 3;
  74. case VES_SPECULAR:
  75. return 4;
  76. case VES_BLEND_INDICES:
  77. return 7;
  78. case VES_TEXTURE_COORDINATES:
  79. return 8 + index;
  80. case VES_TANGENT:
  81. return 14;
  82. case VES_BITANGENT:
  83. return 15;
  84. default:
  85. assert(false && "Missing attribute!");
  86. return 0;
  87. };
  88. }
  89. bool GLGpuProgram::isAttributeValid(VertexElementSemantic semantic, CamelotEngine::UINT32 index)
  90. {
  91. // default implementation
  92. switch(semantic)
  93. {
  94. case VES_POSITION:
  95. case VES_NORMAL:
  96. case VES_DIFFUSE:
  97. case VES_SPECULAR:
  98. case VES_TEXTURE_COORDINATES:
  99. return false;
  100. case VES_BLEND_WEIGHTS:
  101. case VES_BLEND_INDICES:
  102. case VES_BITANGENT:
  103. case VES_TANGENT:
  104. return true; // with default binding
  105. }
  106. return false;
  107. }
  108. }