OGLShaderVariation.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 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 "ArrayPtr.h"
  25. #include "GPUObject.h"
  26. #include "GraphicsDefs.h"
  27. #include "RefCounted.h"
  28. class Shader;
  29. class ShaderProgram;
  30. /// Vertex or pixel shader on the GPU.
  31. class ShaderVariation : public RefCounted, public GPUObject
  32. {
  33. public:
  34. /// Construct.
  35. ShaderVariation(Shader* owner, ShaderType type);
  36. /// Destruct.
  37. virtual ~ShaderVariation();
  38. /// Mark the GPU resource destroyed on context destruction.
  39. virtual void OnDeviceLost();
  40. /// Release the shader.
  41. virtual void Release();
  42. /// Compile the shader. Return true if successful.
  43. bool Create();
  44. /// Set name.
  45. void SetName(const String& name);
  46. /// Set source code.
  47. void SetSourceCode(const SharedArrayPtr<char>& code, unsigned length);
  48. /// Set defines.
  49. void SetDefines(const Vector<String>& defines, const Vector<String>& defineValues);
  50. /// Return shader type.
  51. ShaderType GetShaderType() const { return shaderType_; }
  52. /// Return full shader name.
  53. const String& GetName() const { return name_; }
  54. /// Return defines.
  55. const Vector<String>& GetDefines() const { return defines_; }
  56. /// Return define values.
  57. const Vector<String>& GetDefineValues() const { return defineValues_; }
  58. /// Return whether successfully compiled.
  59. bool IsCompiled() const { return compiled_; }
  60. /// Return compile error/warning string.
  61. const String& GetCompilerOutput() const { return compilerOutput_; }
  62. private:
  63. /// Shader type.
  64. ShaderType shaderType_;
  65. /// Full shader name.
  66. String name_;
  67. /// GLSL source code.
  68. SharedArrayPtr<char> sourceCode_;
  69. /// Source code length.
  70. unsigned sourceCodeLength_;
  71. /// Defines to use in compiling.
  72. Vector<String> defines_;
  73. /// Define values to use in compiling.
  74. Vector<String> defineValues_;
  75. /// Shader compile error string.
  76. String compilerOutput_;
  77. /// Compiled flag.
  78. bool compiled_;
  79. };