GL.h 4.0 KB

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