Open Source Tomb Raider Engine
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Shader.h 2.5KB

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