version(WebAssembly):

import dlib.aliases;

import glenum;

import ldc.attributes;

enum WebGLAttributes
{
	None                         = 0<<0,
	NoAlpha                      = 1<<0,
	NoAntiAliasing               = 1<<1,
	NoDepth                      = 1<<2,
	FailIfMajorPerformanceCaveat = 1<<3,
	NoPremultipliedAlpha         = 1<<4,
	PreserveDrawingBuffer        = 1<<5,
	Stencil                      = 1<<6,
	Desynchronized               = 1<<7,
} alias WGLA = WebGLAttributes;

import wasm;

extern(C) @llvmAttr("wasm-import-module", "gl"):

@WasmName!("GenRenderbuffers") void
glGenRenderbuffers(usize n, u32* renderbuffers);

@WasmName!("DeleteBuffers") void
glDeleteBuffers(usize n, const u32* buffers);

@WasmName!("DeleteFramebuffers") void
glDeleteFramebuffers(usize n, const u32* framebuffers);

@WasmName!("GenBuffers") u32
glGenBuffers(usize n, u32* buffers);

@WasmName!("DeleteRenderbuffers") void
glDeleteRenderbuffers(usize n, const u32* renderbuffers);

@WasmName!("GenTextures") u32
glCreateTextures(usize n, u32* textures);

@WasmName!("GenVertexArrays") void
glGenVertexArrays(usize n, u32* vaos);

@WasmName!("DeleteVertexArrays") void
glDeleteVertexArrays(usize n, const u32* vaos);

@WasmName!("DeleteTextures") void
glDeleteTextures(usize n, const u32* textures);

@WasmName!("SetCurrentContextById") b32
glSetCurrentContextByID(string id);

@WasmName!("CreateCurrentContextById") b32
glCreateCurrentContextByID(string id, WebGLAttributes);

@WasmName!("Clear") void
glClear(u32 bits);

@WasmName!("ClearColor") void
glClearColor(f32 red, f32 green, f32 blue, f32 alpha);

@WasmName!("ClearDepth") void
glClearDepth(f32 depth);

@WasmName!("ClearStencil") void
glClearStencil(i32 s);

@WasmName!("ColorMask") void
glColorMask(u32 red, u32 green, u32 blue, u32 alpha);

@WasmName!("CompileShader") void
glCompileShader(u32 shader);

@WasmName!("UseProgram") void
glUseProgram(u32 program);

@WasmName!("ValidateProgram") void
glValidateProgram(u32 program);

@WasmName!("BindBufferBase") void
glBindBufferBase(GLEnum target, u32 index, u32 buffer);

@WasmName!("GetUniformBlockIndex") u32
glGetUniformBlockIndex(u32 program, const char* uniform_block_name);

@WasmName!("CullFace") void
glCullFace(GLEnum mode);

@WasmName!("Enable") void
glEnable(GLEnum cap);

@WasmName!("Disable") void
glDisable(GLEnum cap);

@WasmName!("EnableVertexAttribArray") void
glEnableVertexAttribArray(u32 index);

@WasmName!("DisableVertexAttribArray") void
glDisableVertexAttribArray(u32 index);

@WasmName!("FrontFace") void
glFrontFace(GLEnum mode);

@WasmName!("BlendFuncSeparate") void
glBlendFuncSeparate(GLEnum src_rgb, GLEnum dst_rgb, GLEnum src_alpha, GLEnum dst_alpha);

@WasmName!("BindTexture") void
glBindTexture(GLEnum target, u32 texture);

@WasmName!("TexParameterf") void
glTexParameterf(GLEnum target, GLEnum pname, f32 param);

@WasmName!("TexParameteri") void
glTexParameteri(GLEnum target, GLEnum pname, i32 param);

@WasmName!("TexImage2D") void
glTexImage2D(GLEnum target, i32 level, i32 internal_format, usize width, usize height, i32 border, GLEnum format, GLEnum type, const void* data);

@WasmName!("BindVertexArray") void
glBindVertexArray(u32 vao);

@WasmName!("BlendFunc") void
glBlendFunc(GLEnum sfactor, GLEnum dfactor);

@WasmName!("BindBuffer") void
glBindBuffer(GLEnum target, u32 buffer);

@WasmName!("BufferData") void
glBufferData(GLEnum target, usize size, const void* data, GLEnum usage);

@WasmName!("BufferSubData") void
glBufferSubData(GLEnum target, usize offset, usize size, const void* data);

@WasmName!("VertexAttribDivisor") void
glVertexAttribDivisor(u32 index, u32 divisor);

@WasmName!("VertexAttribPointer") void
glVertexAttribPointer(u32 index, i32 size, GLEnum type, b32 normalized, usize stride, const void* pointer);

@WasmName!("Viewport") void
glViewport(i32 x, i32 y, usize width, usize height);

@WasmName!("DrawArraysInstanced") void
glDrawArraysInstanced(GLEnum mode, i32 first, usize count, usize instance_count);

@WasmName!("DrawElementsInstanced") void
glDrawElementsInstanced(GLEnum mode, usize count, GLEnum type, const void* indices, usize instance_count);

@WasmName!("ActiveTexture") void
glActiveTexture(GLEnum texture);

@WasmName!("GetUniformLocation") i32
glGetUniformLocation(u32 program, const char* name);

@WasmName!("Uniform1f") void
glUniform1f(i32 location, f32 v0);

@WasmName!("Uniform2f") void
glUniform2f(i32 location, f32 v0, f32 v1);

@WasmName!("Uniform3f") void
glUniform3f(i32 location, f32 v0, f32 v1, f32 v2);

@WasmName!("Uniform4f") void
glUniform4f(i32 location, f32 v0, f32 v1, f32 v2, f32 v3);

@WasmName!("Uniform1i") void
glUniform1i(i32 location, i32 v0);

@WasmName!("Uniform2i") void
glUniform2i(i32 location, i32 v0, i32 v1);

@WasmName!("Uniform3i") void
glUniform3i(i32 location, i32 v0, i32 v1, i32 v2);

@WasmName!("Uniform4i") void
glUniform4i(i32 location, i32 v0, i32 v1, i32 v2, i32 v3);

@WasmName!("CreateProgram") u32
glCreateProgram();

@WasmName!("CreateShader") u32
glCreateShader(GLEnum shader_type);

@WasmName!("DeleteProgram") void
glDeleteProgram(u32 program);

@WasmName!("DeleteShader") void
glDeleteShader(u32 shader);

@WasmName!("ShaderSource") void
glShaderSource(u32 shader, usize count, const char** string, const i32* length);

@WasmName!("Scissor") void
glScissor(i32 x, i32 y, usize width, usize height);

@WasmName!("GetProgramiv") void
glGetProgramiv(u32 program, GLEnum pname, i32* params);

@WasmName!("GetProgramInfoLog") void
glGetProgramInfoLog(u32 program, i32 max_length, i32* length, char* info_log);

@WasmName!("GetShaderiv") void
glGetShaderiv(u32 shader, GLEnum pname, i32* params);

@WasmName!("GetShaderInfoLog") void
glGetShaderInfoLog(u32 shader, i32 max_length, i32* length, char* info_log);

@WasmName!("AttachShader") void
glAttachShader(u32 program, u32 shader);

@WasmName!("LinkProgram") void
glLinkProgram(u32 program);
