PolyShader.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 "PolyString.h"
  21. #include "PolyGlobals.h"
  22. #include "PolyResource.h"
  23. namespace Polycode {
  24. class Cubemap;
  25. class ShaderBinding;
  26. class Texture;
  27. class _PolyExport Shader : public Resource {
  28. public:
  29. Shader(int type);
  30. virtual ~Shader();
  31. int getType() const;
  32. void setName(const String& name);
  33. const String& getName() const;
  34. virtual ShaderBinding *createBinding() = 0;
  35. static const int FIXED_SHADER = 0;
  36. static const int MODULE_SHADER = 1;
  37. int numSpotLights;
  38. int numAreaLights;
  39. protected:
  40. String name;
  41. int type;
  42. };
  43. class _PolyExport ShaderRenderTarget {
  44. public:
  45. String id;
  46. Number width;
  47. Number height;
  48. int sizeMode;
  49. bool hasSize;
  50. Texture *texture;
  51. static const int SIZE_MODE_PIXELS = 0;
  52. static const int SIZE_MODE_NORMALIZED = 1;
  53. };
  54. typedef struct {
  55. String name;
  56. void *data;
  57. } LocalShaderParam;
  58. typedef struct {
  59. String id;
  60. String name;
  61. int mode;
  62. Texture *texture;
  63. Number width;
  64. Number height;
  65. static const int MODE_IN= 0;
  66. static const int MODE_OUT = 1;
  67. } RenderTargetBinding;
  68. class _PolyExport ShaderBinding {
  69. public:
  70. ShaderBinding(Shader *shader);
  71. virtual ~ShaderBinding();
  72. virtual void clearTexture(const String& name){};
  73. virtual void addTexture(const String& name, Texture *texture) {};
  74. virtual void addParam(const String& type, const String& name, const String& value) {};
  75. virtual void addCubemap(const String& name, Cubemap *cubemap) {};
  76. unsigned int getNumLocalParams();
  77. LocalShaderParam *getLocalParam(unsigned int index);
  78. LocalShaderParam *getLocalParamByName(const String& name);
  79. void addRenderTargetBinding(RenderTargetBinding *binding);
  80. unsigned int getNumRenderTargetBindings();
  81. RenderTargetBinding *getRenderTargetBinding(unsigned int index);
  82. unsigned int getNumInTargetBindings();
  83. RenderTargetBinding *getInTargetBinding(unsigned int index);
  84. unsigned int getNumOutTargetBindings();
  85. RenderTargetBinding *getOutTargetBinding(unsigned int index);
  86. void addLocalParam(const String& name, void *ptr);
  87. Shader* shader;
  88. std::vector<LocalShaderParam*> localParams;
  89. std::vector<RenderTargetBinding*> renderTargetBindings;
  90. std::vector<RenderTargetBinding*> inTargetBindings;
  91. std::vector<RenderTargetBinding*> outTargetBindings;
  92. };
  93. }