GL.h 4.1 KB

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