Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Shader.h 2.7KB

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 "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, bool depth = true);
  43. static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, unsigned int texture,
  44. TextureStorage store = TextureStorage::SYSTEM, unsigned int mode = GL_TRIANGLES,
  45. Shader& shader = textShader);
  46. static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP,
  47. TextureStorage store = TextureStorage::GAME, Shader& shader = textureShader);
  48. static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& indices,
  49. unsigned int texture, glm::mat4 MVP,
  50. TextureStorage store = TextureStorage::GAME, Shader& shader = textureShader);
  51. static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
  52. unsigned int mode = GL_TRIANGLES, Shader& shader = colorShader);
  53. static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices,
  54. glm::mat4 MVP, unsigned int mode = GL_TRIANGLES, Shader& shader = colorShader);
  55. private:
  56. int programID;
  57. std::vector<unsigned int> uniforms;
  58. static Shader textShader;
  59. static const char* textShaderVertex;
  60. static const char* textShaderFragment;
  61. static Shader textureShader;
  62. static const char* textureShaderVertex;
  63. static const char* textureShaderFragment;
  64. static Shader colorShader;
  65. static const char* colorShaderVertex;
  66. static const char* colorShaderFragment;
  67. static unsigned int vertexArrayID;
  68. };
  69. #endif