shader.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*************************************************************************/
  2. /* shader.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef SHADER_H
  30. #define SHADER_H
  31. #include "resource.h"
  32. #include "io/resource_loader.h"
  33. class Shader : public Resource {
  34. OBJ_TYPE(Shader,Resource);
  35. OBJ_SAVE_TYPE( Shader );
  36. RES_BASE_EXTENSION("shd");
  37. RID shader;
  38. Dictionary _get_code();
  39. void _set_code(const Dictionary& p_string);
  40. // hack the name of performance
  41. // shaders keep a list of ShaderMaterial -> VisualServer name translations, to make
  42. // convertion fast and save memory.
  43. mutable bool params_cache_dirty;
  44. mutable Map<StringName,StringName> params_cache; //map a shader param to a material param..
  45. protected:
  46. static void _bind_methods();
  47. public:
  48. enum Mode {
  49. MODE_MATERIAL,
  50. MODE_CANVAS_ITEM,
  51. MODE_POST_PROCESS
  52. };
  53. void set_mode(Mode p_mode);
  54. Mode get_mode() const;
  55. void set_code( const String& p_vertex, const String& p_fragment, const String& p_light,int p_fragment_ofs=0,int p_light_ofs=0);
  56. String get_vertex_code() const;
  57. String get_fragment_code() const;
  58. String get_light_code() const;
  59. void get_param_list(List<PropertyInfo> *p_params) const;
  60. bool has_param(const StringName& p_param) const;
  61. virtual RID get_rid() const;
  62. Shader();
  63. ~Shader();
  64. };
  65. VARIANT_ENUM_CAST( Shader::Mode );
  66. class ResourceFormatLoaderShader : public ResourceFormatLoader {
  67. public:
  68. virtual RES load(const String &p_path,const String& p_original_path="");
  69. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  70. virtual bool handles_type(const String& p_type) const;
  71. virtual String get_resource_type(const String &p_path) const;
  72. };
  73. #endif // SHADER_H