GL.h 4.3 KB

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