GL.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef GL_H
  2. #define GL_H
  3. #include "utils/Error.h"
  4. namespace GL {
  5. typedef unsigned int Shader;
  6. typedef unsigned int Program;
  7. typedef unsigned int Texture;
  8. typedef unsigned int Framebuffer;
  9. typedef unsigned int ColorAttachment;
  10. typedef unsigned int VertexArray;
  11. typedef unsigned int Buffer;
  12. enum class ShaderType {
  13. INVALID,
  14. VERTEX,
  15. FRAGMENT,
  16. GEOMETRY,
  17. TESSELATION_CONTROL,
  18. TESSELATION_EVALUATION
  19. };
  20. enum class BufferUsage { INVALID, STATIC, STREAM, DYNAMIC };
  21. class Attribute final {
  22. int count;
  23. int size;
  24. int type;
  25. bool normalized;
  26. Attribute(int count, int size, int type, bool normalized);
  27. friend void vertexAttribPointer(int index, const Attribute& a,
  28. int stride, int offset);
  29. public:
  30. bool isDummy() const;
  31. int getSize() const;
  32. static Attribute newFloat(int count);
  33. static Attribute newColor(int count);
  34. static Attribute newDummy();
  35. };
  36. class TextureFormat final {
  37. int internalformat;
  38. int format;
  39. int type;
  40. TextureFormat(int internalformat, int format, int type);
  41. friend void texImage2D(const TextureFormat& format, int width,
  42. int height, const void* data, int level);
  43. public:
  44. static TextureFormat color8(int channels);
  45. static TextureFormat float16(int channels);
  46. static TextureFormat float32(int channels);
  47. static TextureFormat depth16();
  48. static TextureFormat depth32();
  49. static TextureFormat unknown();
  50. };
  51. bool printError(const char* message);
  52. Error getError(const char* message);
  53. void enableDepthTesting();
  54. void disableDepthTesting();
  55. void bindMainFramebuffer();
  56. void clear();
  57. void enableBlending();
  58. void disableBlending();
  59. void setViewport(int width, int height);
  60. void vertexAttribPointer(int index, const Attribute& a, int stride,
  61. int offset);
  62. Program createProgram();
  63. void attachShader(Program p, Shader s);
  64. void linkProgram(Program p);
  65. Error getLinkerError(Program p);
  66. void deleteShader(Shader s);
  67. void deleteProgram(Program p);
  68. Shader createShader(ShaderType type);
  69. void compileShader(Shader s, const char* code);
  70. Error getCompileError(Shader s);
  71. void useProgram(Program p);
  72. void setMatrix(Program p, const char* name, const float* data);
  73. void setInt(Program p, const char* name, int data);
  74. void setFloat(Program p, const char* name, float data);
  75. void set2Float(Program p, const char* name, const float* data);
  76. void set3Float(Program p, const char* name, const float* data);
  77. void set4Float(Program p, const char* name, const float* data);
  78. void texImage2D(const TextureFormat& format, int width, int height,
  79. const void* data, int level = 0);
  80. Texture genTexture();
  81. void deleteTexture(Texture t);
  82. void setNearFilter2D();
  83. void setMipMapNearFilter2D();
  84. void setLinearFilter2D();
  85. void setMipMapLinearFilter2D();
  86. void setClampWrap2D();
  87. void setRepeatWrap2D();
  88. void bindTexture2D(Texture t);
  89. void activeTexture(int index);
  90. void generateMipmap2D(int maxLevels);
  91. void deleteFramebuffers(Framebuffer fb);
  92. Framebuffer genFramebuffer();
  93. void bindFramebuffer(Framebuffer fb);
  94. void framebufferDepthTexture2D(Texture t);
  95. ColorAttachment framebufferColorTexture2D(Texture t, int index);
  96. void drawBuffers(int length, ColorAttachment* c);
  97. Error getFramebufferError();
  98. VertexArray genVertexArray();
  99. Buffer genBuffer();
  100. void deleteBuffer(Buffer b);
  101. void deleteVertexArray(VertexArray va);
  102. void bindVertexArray(VertexArray va);
  103. void bindBuffer(Buffer b);
  104. void bufferData(int size, const void* data, BufferUsage usage);
  105. void bufferSubData(int offset, int size, const void* data);
  106. void drawTriangles(int offset, int vertices);
  107. void drawTriangleStrip(int offset, int vertices);
  108. void drawPoints(int offset, int vertices);
  109. }
  110. #endif