Open Source Tomb Raider Engine
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Shader.h 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*!
  2. * \file include/system/Shader.h
  3. * \brief OpenGL Shader implementation
  4. *
  5. * \author xythobuz
  6. */
  7. #ifndef _SHADER_H_
  8. #define _SHADER_H_
  9. #include <vector>
  10. #include "TextureManager.h"
  11. class ShaderBuffer {
  12. public:
  13. ShaderBuffer() : created(false), buffer(0), boundSize(0) { }
  14. ~ShaderBuffer();
  15. void bufferData(int elem, int size, void* data);
  16. template<typename T>
  17. void bufferData(std::vector<T> v)
  18. { bufferData(v.size(), sizeof(T), &v[0]); }
  19. void bindBuffer();
  20. void bindBuffer(int location, int size);
  21. void unbind(int location);
  22. int getSize() { return boundSize; }
  23. private:
  24. bool created;
  25. unsigned int buffer;
  26. int boundSize;
  27. };
  28. class Shader {
  29. public:
  30. Shader() : programID(-1) { }
  31. ~Shader();
  32. int compile(const char* vertex, const char* fragment);
  33. void use();
  34. int addUniform(const char* name);
  35. unsigned int getUniform(int n);
  36. void loadUniform(int uni, glm::vec2 vec);
  37. void loadUniform(int uni, glm::vec4 vec);
  38. void loadUniform(int uni, glm::mat4 mat);
  39. void loadUniform(int uni, int texture, TextureStorage store);
  40. static int initialize();
  41. static void shutdown();
  42. static void set2DState(bool on);
  43. static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, unsigned int texture,
  44. TextureStorage store = TextureStorage::SYSTEM, Shader& shader = textShader);
  45. static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP,
  46. TextureStorage store = TextureStorage::GAME, Shader& shader = textureShader);
  47. static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& indices,
  48. unsigned int texture, glm::mat4 MVP,
  49. TextureStorage store = TextureStorage::GAME, Shader& shader = textureShader);
  50. static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
  51. unsigned int mode = GL_TRIANGLES, Shader& shader = colorShader);
  52. static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices,
  53. glm::mat4 MVP, unsigned int mode = GL_TRIANGLES, Shader& shader = colorShader);
  54. private:
  55. int programID;
  56. std::vector<unsigned int> uniforms;
  57. static Shader textShader;
  58. static const char* textShaderVertex;
  59. static const char* textShaderFragment;
  60. static Shader textureShader;
  61. static const char* textureShaderVertex;
  62. static const char* textureShaderFragment;
  63. static Shader colorShader;
  64. static const char* colorShaderVertex;
  65. static const char* colorShaderFragment;
  66. static unsigned int vertexArrayID;
  67. };
  68. #endif