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