Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Shader.h 2.6KB

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