OGLShaderProgram.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  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. #pragma once
  24. #include "GPUObject.h"
  25. #include "GraphicsDefs.h"
  26. #include "HashMap.h"
  27. #include "RefCounted.h"
  28. class Graphics;
  29. class ShaderVariation;
  30. /// GLSL uniform definition
  31. struct UniformInfo
  32. {
  33. /// Location
  34. int location_;
  35. /// Element type of uniform
  36. unsigned type_;
  37. };
  38. /// Linked shader program on the GPU
  39. class ShaderProgram : public RefCounted, public GPUObject
  40. {
  41. public:
  42. /// Construct
  43. ShaderProgram(Graphics* graphics, ShaderVariation* vertexShader, ShaderVariation* pixelShader);
  44. /// Destruct
  45. ~ShaderProgram();
  46. /// Release the shader program object
  47. virtual void Release();
  48. /// Link the shaders and examine the uniforms and samplers used. Return true if successful
  49. bool Link();
  50. /// Return the vertex shader
  51. ShaderVariation* GetVertexShader() const;
  52. /// Return the pixel shader
  53. ShaderVariation* GetPixelShader() const;
  54. /// Return whether uses a shader parameter
  55. bool HasParameter(ShaderParameter param) const;
  56. /// Return whether uses a texture unit
  57. bool HasTextureUnit(TextureUnit unit) const { return useTextureUnit_[unit]; }
  58. /// Return the uniform info for a parameter, or null if does not exist
  59. const UniformInfo* GetUniformInfo(ShaderParameter param) const;
  60. /// Return the vertex attribute bindings
  61. const int* GetAttributeLocations() const { return attributeLocations_; }
  62. /// Return whether successfully linked
  63. bool IsLinked() const { return linked_; }
  64. /// Return linker output
  65. const String& GetLinkerOutput() const { return linkerOutput_; }
  66. private:
  67. /// Vertex shader
  68. WeakPtr<ShaderVariation> vertexShader_;
  69. /// Pixel shader
  70. WeakPtr<ShaderVariation> pixelShader_;
  71. /// Uniform info map
  72. HashMap<ShaderParameter, UniformInfo> uniformInfos_;
  73. /// Texture unit use
  74. bool useTextureUnit_[MAX_TEXTURE_UNITS];
  75. /// Vertex attribute bindings
  76. int attributeLocations_[MAX_VERTEX_ELEMENTS];
  77. /// Shader link error string
  78. String linkerOutput_;
  79. /// Linked flag
  80. bool linked_;
  81. };