PolyMaterialManager.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "PolyGlobals.h"
  21. #include "PolyImage.h"
  22. #include "PolyObject.h"
  23. #include "PolyShader.h"
  24. #include <vector>
  25. class TiXmlNode;
  26. namespace Polycode {
  27. class Cubemap;
  28. class Material;
  29. class PolycodeShaderModule;
  30. class Texture;
  31. class SceneRenderTexture;
  32. class Shader;
  33. class String;
  34. class ShaderProgram;
  35. class ResourcePool;
  36. /**
  37. * Manages loading and reloading of materials, textures and shaders. This class should be only accessed from the CoreServices singleton.
  38. */
  39. class _PolyExport MaterialManager : public PolyBase {
  40. public:
  41. MaterialManager();
  42. ~MaterialManager();
  43. void Update(int elapsed);
  44. /**
  45. * Creates a new framebuffer texture.
  46. */
  47. Texture *createFramebufferTexture(int width, int height, int type);
  48. Texture *createTexture(int width, int height, char *imageData, bool clamp=false, bool createMipmaps = true, int type=Image::IMAGE_RGBA);
  49. Texture *createNewTexture(int width, int height, bool clamp=false, bool createMipmaps = true, int type=Image::IMAGE_RGBA);
  50. Texture *createTextureFromImage(Image *image, bool clamp=false, bool createMipmaps = true);
  51. Texture *createTextureFromFile(const String& fileName, bool clamp=false, bool createMipmaps = true, ResourcePool *resourcePool = NULL);
  52. void deleteTexture(Texture *texture);
  53. void reloadTextures();
  54. void reloadProgramsAndTextures();
  55. void reloadPrograms();
  56. void addShaderModule(PolycodeShaderModule *module);
  57. //SceneRenderTexture *createRenderTexture(Scene *targetScene, Camera *targetCamera, int renderWidth,int renderHeight);
  58. Texture *getTextureByResourcePath(const String& resourcePath) const;
  59. ShaderProgram *createProgramFromFile(String programPath);
  60. void loadMaterialLibraryIntoPool(ResourcePool *pool, const String &materialFile);
  61. // cubemaps
  62. Cubemap *cubemapFromXMLNode(TiXmlNode *node);
  63. // materials
  64. Material *materialFromXMLNode(ResourcePool *resourcePool, TiXmlNode *node);
  65. Material *createMaterial(ResourcePool *resourcePool, String materialName, String shaderName);
  66. Shader *setShaderFromXMLNode(ResourcePool *resourcePool, TiXmlNode *node);
  67. Shader *createShaderFromXMLNode(ResourcePool *resourcePool, TiXmlNode *node);
  68. Shader *createShader(ResourcePool *resourcePool, String shaderType, String name, String vpName, String fpName, bool screenShader);
  69. std::vector<Material*> loadMaterialsFromFile(ResourcePool *resourcePool, const String &fileName);
  70. std::vector<Shader*> loadShadersFromFile(ResourcePool *resourcePool, String fileName);
  71. std::vector<Cubemap*> loadCubemapsFromFile(String fileName);
  72. void addMaterial(Material *material);
  73. void addShader(Shader *shader);
  74. unsigned int getNumShaders();
  75. Shader *getShaderByIndex(unsigned int index);
  76. bool premultiplyAlphaOnLoad;
  77. bool clampDefault;
  78. bool mipmapsDefault;
  79. bool keepTextureData;
  80. private:
  81. std::vector<Texture*> textures;
  82. std::vector<Material*> materials;
  83. std::vector<Shader*> shaders;
  84. std::vector <PolycodeShaderModule*> shaderModules;
  85. };
  86. };