OGLShaderVariation.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // Copyright (c) 2008-2013 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "ArrayPtr.h"
  24. #include "GPUObject.h"
  25. #include "GraphicsDefs.h"
  26. #include "RefCounted.h"
  27. namespace Urho3D
  28. {
  29. class Shader;
  30. class ShaderProgram;
  31. /// Vertex or pixel shader on the GPU.
  32. class URHO3D_API ShaderVariation : public RefCounted, public GPUObject
  33. {
  34. public:
  35. /// Construct.
  36. ShaderVariation(Shader* owner, ShaderType type);
  37. /// Destruct.
  38. virtual ~ShaderVariation();
  39. /// Mark the GPU resource destroyed on context destruction.
  40. virtual void OnDeviceLost();
  41. /// Release the shader.
  42. virtual void Release();
  43. /// Compile the shader. Return true if successful.
  44. bool Create();
  45. /// Set name.
  46. void SetName(const String& name);
  47. /// Set source code.
  48. void SetSourceCode(const SharedArrayPtr<char>& code, unsigned length);
  49. /// Set defines.
  50. void SetDefines(const Vector<String>& defines, const Vector<String>& defineValues);
  51. /// Return shader type.
  52. ShaderType GetShaderType() const { return shaderType_; }
  53. /// Return full shader name.
  54. const String& GetName() const { return name_; }
  55. /// Return defines.
  56. const Vector<String>& GetDefines() const { return defines_; }
  57. /// Return define values.
  58. const Vector<String>& GetDefineValues() const { return defineValues_; }
  59. /// Return whether successfully compiled.
  60. bool IsCompiled() const { return compiled_; }
  61. /// Return compile error/warning string.
  62. const String& GetCompilerOutput() const { return compilerOutput_; }
  63. private:
  64. /// Shader type.
  65. ShaderType shaderType_;
  66. /// Full shader name.
  67. String name_;
  68. /// GLSL source code.
  69. SharedArrayPtr<char> sourceCode_;
  70. /// Source code length.
  71. unsigned sourceCodeLength_;
  72. /// Defines to use in compiling.
  73. Vector<String> defines_;
  74. /// Define values to use in compiling.
  75. Vector<String> defineValues_;
  76. /// Shader compile error string.
  77. String compilerOutput_;
  78. /// Compiled flag.
  79. bool compiled_;
  80. };
  81. }