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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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();
  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. private:
  26. unsigned int buffer;
  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 addBuffer(int n = 1);
  37. unsigned int getBuffer(int n);
  38. template<typename T>
  39. void bufferData(int buff, std::vector<T> v)
  40. { bufferData(buff, v.size(), sizeof(T), &v[0]); }
  41. void bufferData(int buff, int elem, int size, void* d);
  42. void loadUniform(int uni, glm::vec2 vec);
  43. void loadUniform(int uni, glm::vec4 vec);
  44. void loadUniform(int uni, glm::mat4 mat);
  45. void loadUniform(int uni, int texture, TextureManager::TextureStorage store, int slot = 0);
  46. void bindBuffer(int buff);
  47. void bindBuffer(int buff, int location, int size);
  48. void disableAttribs();
  49. static int initialize();
  50. static void shutdown();
  51. static void drawGL(std::vector<glm::vec2>& vertices, std::vector<glm::vec2>& uvs,
  52. glm::vec4 color, unsigned int texture);
  53. static void drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec2>& uvs,
  54. std::vector<unsigned short>& indices, glm::mat4 MVP, unsigned int texture);
  55. static void drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec3>& colors,
  56. std::vector<unsigned short>& indices, glm::mat4 MVP, int mode = GL_TRIANGLES);
  57. private:
  58. int programID;
  59. std::vector<unsigned int> uniforms;
  60. std::vector<unsigned int> buffers;
  61. std::vector<bool> attribs;
  62. static Shader textShader;
  63. static const char* textShaderVertex;
  64. static const char* textShaderFragment;
  65. static Shader textureShader;
  66. static const char* textureShaderVertex;
  67. static const char* textureShaderFragment;
  68. static Shader colorShader;
  69. static const char* colorShaderVertex;
  70. static const char* colorShaderFragment;
  71. static unsigned int vertexArrayID;
  72. };
  73. #endif