PolyMaterial.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "polycode/core/PolyString.h"
  21. #include "polycode/core/PolyGlobals.h"
  22. #include "polycode/core/PolyResource.h"
  23. #include "polycode/core/PolyResourceManager.h"
  24. #include "polycode/core/PolyColor.h"
  25. #include <vector>
  26. #include <memory>
  27. namespace Polycode {
  28. class Shader;
  29. class ShaderBinding;
  30. class ShaderRenderTarget;
  31. class Mesh;
  32. class VertexDataArray;
  33. class _PolyExport ShaderPass {
  34. public:
  35. ShaderPass();
  36. ShaderPass(Shader *shader);
  37. ShaderPass(const ShaderPass &other);
  38. ~ShaderPass();
  39. std::shared_ptr<ShaderBinding> getShaderBinding();
  40. std::shared_ptr<Shader> shader;
  41. bool wireframe;
  42. unsigned short blendingMode;
  43. std::shared_ptr<ShaderBinding> shaderBinding;
  44. std::shared_ptr<ShaderBinding> materialShaderBinding;
  45. };
  46. class _PolyExport Material : public Resource {
  47. public:
  48. explicit Material(const String& name);
  49. explicit Material(const String& name, std::shared_ptr<Shader> shader);
  50. virtual ~Material();
  51. void addShaderPass(const ShaderPass &pass);
  52. void addShaderPassForShader(std::shared_ptr<Shader> shader);
  53. void addShaderPassAtIndex(const ShaderPass &pass, unsigned int shaderIndex);
  54. unsigned int getNumShaderPasses() const;
  55. void removeShaderPass(int shaderIndex);
  56. void addShaderRenderTarget(ShaderRenderTarget *newTarget);
  57. int getNumShaderRenderTargets();
  58. ShaderRenderTarget *getShaderRenderTarget(unsigned int index);
  59. void removeShaderRenderTarget(int index);
  60. void recreateRenderTarget(ShaderRenderTarget *renderTarget, const Vector2 &screenSize);
  61. void recreateRenderTargets(const Vector2 &screenSize);
  62. const String& getName() const;
  63. ShaderPass getShaderPass(unsigned int index) const;
  64. std::shared_ptr<ShaderBinding> getShaderBinding(unsigned int index) const;
  65. std::shared_ptr<Shader> getShader(unsigned int index) const;
  66. void loadMaterial(const String& fileName);
  67. void setName(const String &name);
  68. void clearShaders();
  69. bool fp16RenderTargets;
  70. int blendingMode;
  71. bool screenMaterial;
  72. protected:
  73. std::vector<ShaderPass> shaderPasses;
  74. std::vector<ShaderRenderTarget*> renderTargets;
  75. String name;
  76. };
  77. }