add opengl 3+ helpers

This commit is contained in:
Adam D. Ruppe 2020-08-25 22:24:25 -04:00
parent 59d7a30734
commit d4f8ed6f18
2 changed files with 328 additions and 322 deletions

View File

@ -12190,326 +12190,17 @@ version(bindbc){
assert(0, "OpenGL initialization failed: a context needs to be created prior to initialization");
}
} else { // OpenGL API missing from simpledisplay
private extern(System) nothrow @nogc {
alias GLvoid = void;
alias GLboolean = ubyte;
alias GLuint = uint;
alias GLenum = uint;
alias GLchar = char;
alias GLsizei = int;
alias GLfloat = float;
alias GLintptr = size_t;
alias GLsizeiptr = ptrdiff_t;
enum uint GL_STENCIL_BUFFER_BIT = 0x00000400;
enum uint GL_INVALID_ENUM = 0x0500;
enum uint GL_ZERO = 0;
enum uint GL_ONE = 1;
enum uint GL_FLOAT = 0x1406;
enum uint GL_STREAM_DRAW = 0x88E0;
enum uint GL_CCW = 0x0901;
enum uint GL_STENCIL_TEST = 0x0B90;
enum uint GL_SCISSOR_TEST = 0x0C11;
enum uint GL_EQUAL = 0x0202;
enum uint GL_NOTEQUAL = 0x0205;
enum uint GL_ALWAYS = 0x0207;
enum uint GL_KEEP = 0x1E00;
enum uint GL_INCR = 0x1E02;
enum uint GL_INCR_WRAP = 0x8507;
enum uint GL_DECR_WRAP = 0x8508;
enum uint GL_CULL_FACE = 0x0B44;
enum uint GL_BACK = 0x0405;
enum uint GL_FRAGMENT_SHADER = 0x8B30;
enum uint GL_VERTEX_SHADER = 0x8B31;
enum uint GL_COMPILE_STATUS = 0x8B81;
enum uint GL_LINK_STATUS = 0x8B82;
enum uint GL_UNPACK_ALIGNMENT = 0x0CF5;
enum uint GL_UNPACK_ROW_LENGTH = 0x0CF2;
enum uint GL_UNPACK_SKIP_PIXELS = 0x0CF4;
enum uint GL_UNPACK_SKIP_ROWS = 0x0CF3;
enum uint GL_GENERATE_MIPMAP = 0x8191;
enum uint GL_LINEAR_MIPMAP_LINEAR = 0x2703;
enum uint GL_RED = 0x1903;
enum uint GL_TEXTURE0 = 0x84C0U;
enum uint GL_TEXTURE1 = 0x84C1U;
enum uint GL_ARRAY_BUFFER = 0x8892;
enum uint GL_SRC_COLOR = 0x0300;
enum uint GL_ONE_MINUS_SRC_COLOR = 0x0301;
enum uint GL_SRC_ALPHA = 0x0302;
enum uint GL_ONE_MINUS_SRC_ALPHA = 0x0303;
enum uint GL_DST_ALPHA = 0x0304;
enum uint GL_ONE_MINUS_DST_ALPHA = 0x0305;
enum uint GL_DST_COLOR = 0x0306;
enum uint GL_ONE_MINUS_DST_COLOR = 0x0307;
enum uint GL_SRC_ALPHA_SATURATE = 0x0308;
enum uint GL_INVERT = 0x150AU;
enum uint GL_DEPTH_STENCIL = 0x84F9U;
enum uint GL_UNSIGNED_INT_24_8 = 0x84FAU;
enum uint GL_FRAMEBUFFER = 0x8D40U;
enum uint GL_COLOR_ATTACHMENT0 = 0x8CE0U;
enum uint GL_DEPTH_STENCIL_ATTACHMENT = 0x821AU;
enum uint GL_FRAMEBUFFER_COMPLETE = 0x8CD5U;
enum uint GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6U;
enum uint GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7U;
enum uint GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9U;
enum uint GL_FRAMEBUFFER_UNSUPPORTED = 0x8CDDU;
enum uint GL_COLOR_LOGIC_OP = 0x0BF2U;
enum uint GL_CLEAR = 0x1500U;
enum uint GL_COPY = 0x1503U;
enum uint GL_XOR = 0x1506U;
enum uint GL_FRAMEBUFFER_BINDING = 0x8CA6U;
enum uint GL_TEXTURE_LOD_BIAS = 0x8501;
/*
version(Windows) {
private void* kglLoad (const(char)* name) {
void* res = glGetProcAddress(name);
if (res is null) {
import core.sys.windows.windef, core.sys.windows.winbase;
static HINSTANCE dll = null;
if (dll is null) {
dll = LoadLibraryA("opengl32.dll");
if (dll is null) return null; // <32, but idc
return GetProcAddress(dll, name);
}
}
}
} else {
alias kglLoad = glGetProcAddress;
}
*/
alias glbfn_glGenVertexArrays = void function(GLsizei, GLuint*);
__gshared glbfn_glGenVertexArrays glGenVertexArrays_NVGLZ; alias glGenVertexArrays = glGenVertexArrays_NVGLZ;
alias glbfn_glBindVertexArray = void function(GLuint);
__gshared glbfn_glBindVertexArray glBindVertexArray_NVGLZ; alias glBindVertexArray = glBindVertexArray_NVGLZ;
alias glbfn_glDeleteVertexArrays = void function(GLsizei, const(GLuint)*);
__gshared glbfn_glDeleteVertexArrays glDeleteVertexArrays_NVGLZ; alias glDeleteVertexArrays = glDeleteVertexArrays_NVGLZ;
alias glbfn_glGenerateMipmap = void function(GLenum);
__gshared glbfn_glGenerateMipmap glGenerateMipmap_NVGLZ; alias glGenerateMipmap = glGenerateMipmap_NVGLZ;
alias glbfn_glBufferSubData = void function(GLenum, GLintptr, GLsizeiptr, const(GLvoid)*);
__gshared glbfn_glBufferSubData glBufferSubData_NVGLZ; alias glBufferSubData = glBufferSubData_NVGLZ;
alias glbfn_glStencilMask = void function(GLuint);
__gshared glbfn_glStencilMask glStencilMask_NVGLZ; alias glStencilMask = glStencilMask_NVGLZ;
alias glbfn_glStencilFunc = void function(GLenum, GLint, GLuint);
__gshared glbfn_glStencilFunc glStencilFunc_NVGLZ; alias glStencilFunc = glStencilFunc_NVGLZ;
alias glbfn_glGetShaderInfoLog = void function(GLuint, GLsizei, GLsizei*, GLchar*);
__gshared glbfn_glGetShaderInfoLog glGetShaderInfoLog_NVGLZ; alias glGetShaderInfoLog = glGetShaderInfoLog_NVGLZ;
alias glbfn_glGetProgramInfoLog = void function(GLuint, GLsizei, GLsizei*, GLchar*);
__gshared glbfn_glGetProgramInfoLog glGetProgramInfoLog_NVGLZ; alias glGetProgramInfoLog = glGetProgramInfoLog_NVGLZ;
alias glbfn_glCreateProgram = GLuint function();
__gshared glbfn_glCreateProgram glCreateProgram_NVGLZ; alias glCreateProgram = glCreateProgram_NVGLZ;
alias glbfn_glCreateShader = GLuint function(GLenum);
__gshared glbfn_glCreateShader glCreateShader_NVGLZ; alias glCreateShader = glCreateShader_NVGLZ;
alias glbfn_glShaderSource = void function(GLuint, GLsizei, const(GLchar*)*, const(GLint)*);
__gshared glbfn_glShaderSource glShaderSource_NVGLZ; alias glShaderSource = glShaderSource_NVGLZ;
alias glbfn_glCompileShader = void function(GLuint);
__gshared glbfn_glCompileShader glCompileShader_NVGLZ; alias glCompileShader = glCompileShader_NVGLZ;
alias glbfn_glGetShaderiv = void function(GLuint, GLenum, GLint*);
__gshared glbfn_glGetShaderiv glGetShaderiv_NVGLZ; alias glGetShaderiv = glGetShaderiv_NVGLZ;
alias glbfn_glAttachShader = void function(GLuint, GLuint);
__gshared glbfn_glAttachShader glAttachShader_NVGLZ; alias glAttachShader = glAttachShader_NVGLZ;
alias glbfn_glBindAttribLocation = void function(GLuint, GLuint, const(GLchar)*);
__gshared glbfn_glBindAttribLocation glBindAttribLocation_NVGLZ; alias glBindAttribLocation = glBindAttribLocation_NVGLZ;
alias glbfn_glLinkProgram = void function(GLuint);
__gshared glbfn_glLinkProgram glLinkProgram_NVGLZ; alias glLinkProgram = glLinkProgram_NVGLZ;
alias glbfn_glGetProgramiv = void function(GLuint, GLenum, GLint*);
__gshared glbfn_glGetProgramiv glGetProgramiv_NVGLZ; alias glGetProgramiv = glGetProgramiv_NVGLZ;
alias glbfn_glDeleteProgram = void function(GLuint);
__gshared glbfn_glDeleteProgram glDeleteProgram_NVGLZ; alias glDeleteProgram = glDeleteProgram_NVGLZ;
alias glbfn_glDeleteShader = void function(GLuint);
__gshared glbfn_glDeleteShader glDeleteShader_NVGLZ; alias glDeleteShader = glDeleteShader_NVGLZ;
alias glbfn_glGetUniformLocation = GLint function(GLuint, const(GLchar)*);
__gshared glbfn_glGetUniformLocation glGetUniformLocation_NVGLZ; alias glGetUniformLocation = glGetUniformLocation_NVGLZ;
alias glbfn_glGenBuffers = void function(GLsizei, GLuint*);
__gshared glbfn_glGenBuffers glGenBuffers_NVGLZ; alias glGenBuffers = glGenBuffers_NVGLZ;
alias glbfn_glPixelStorei = void function(GLenum, GLint);
__gshared glbfn_glPixelStorei glPixelStorei_NVGLZ; alias glPixelStorei = glPixelStorei_NVGLZ;
alias glbfn_glUniform4fv = void function(GLint, GLsizei, const(GLfloat)*);
__gshared glbfn_glUniform4fv glUniform4fv_NVGLZ; alias glUniform4fv = glUniform4fv_NVGLZ;
alias glbfn_glColorMask = void function(GLboolean, GLboolean, GLboolean, GLboolean);
__gshared glbfn_glColorMask glColorMask_NVGLZ; alias glColorMask = glColorMask_NVGLZ;
alias glbfn_glStencilOpSeparate = void function(GLenum, GLenum, GLenum, GLenum);
__gshared glbfn_glStencilOpSeparate glStencilOpSeparate_NVGLZ; alias glStencilOpSeparate = glStencilOpSeparate_NVGLZ;
alias glbfn_glDrawArrays = void function(GLenum, GLint, GLsizei);
__gshared glbfn_glDrawArrays glDrawArrays_NVGLZ; alias glDrawArrays = glDrawArrays_NVGLZ;
alias glbfn_glStencilOp = void function(GLenum, GLenum, GLenum);
__gshared glbfn_glStencilOp glStencilOp_NVGLZ; alias glStencilOp = glStencilOp_NVGLZ;
alias glbfn_glUseProgram = void function(GLuint);
__gshared glbfn_glUseProgram glUseProgram_NVGLZ; alias glUseProgram = glUseProgram_NVGLZ;
alias glbfn_glCullFace = void function(GLenum);
__gshared glbfn_glCullFace glCullFace_NVGLZ; alias glCullFace = glCullFace_NVGLZ;
alias glbfn_glFrontFace = void function(GLenum);
__gshared glbfn_glFrontFace glFrontFace_NVGLZ; alias glFrontFace = glFrontFace_NVGLZ;
alias glbfn_glActiveTexture = void function(GLenum);
__gshared glbfn_glActiveTexture glActiveTexture_NVGLZ; alias glActiveTexture = glActiveTexture_NVGLZ;
alias glbfn_glBindBuffer = void function(GLenum, GLuint);
__gshared glbfn_glBindBuffer glBindBuffer_NVGLZ; alias glBindBuffer = glBindBuffer_NVGLZ;
alias glbfn_glBufferData = void function(GLenum, GLsizeiptr, const(void)*, GLenum);
__gshared glbfn_glBufferData glBufferData_NVGLZ; alias glBufferData = glBufferData_NVGLZ;
alias glbfn_glEnableVertexAttribArray = void function(GLuint);
__gshared glbfn_glEnableVertexAttribArray glEnableVertexAttribArray_NVGLZ; alias glEnableVertexAttribArray = glEnableVertexAttribArray_NVGLZ;
alias glbfn_glVertexAttribPointer = void function(GLuint, GLint, GLenum, GLboolean, GLsizei, const(void)*);
__gshared glbfn_glVertexAttribPointer glVertexAttribPointer_NVGLZ; alias glVertexAttribPointer = glVertexAttribPointer_NVGLZ;
alias glbfn_glUniform1i = void function(GLint, GLint);
__gshared glbfn_glUniform1i glUniform1i_NVGLZ; alias glUniform1i = glUniform1i_NVGLZ;
alias glbfn_glUniform2fv = void function(GLint, GLsizei, const(GLfloat)*);
__gshared glbfn_glUniform2fv glUniform2fv_NVGLZ; alias glUniform2fv = glUniform2fv_NVGLZ;
alias glbfn_glDisableVertexAttribArray = void function(GLuint);
__gshared glbfn_glDisableVertexAttribArray glDisableVertexAttribArray_NVGLZ; alias glDisableVertexAttribArray = glDisableVertexAttribArray_NVGLZ;
alias glbfn_glDeleteBuffers = void function(GLsizei, const(GLuint)*);
__gshared glbfn_glDeleteBuffers glDeleteBuffers_NVGLZ; alias glDeleteBuffers = glDeleteBuffers_NVGLZ;
alias glbfn_glBlendFuncSeparate = void function(GLenum, GLenum, GLenum, GLenum);
__gshared glbfn_glBlendFuncSeparate glBlendFuncSeparate_NVGLZ; alias glBlendFuncSeparate = glBlendFuncSeparate_NVGLZ;
alias glbfn_glLogicOp = void function (GLenum opcode);
__gshared glbfn_glLogicOp glLogicOp_NVGLZ; alias glLogicOp = glLogicOp_NVGLZ;
alias glbfn_glFramebufferTexture2D = void function (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
__gshared glbfn_glFramebufferTexture2D glFramebufferTexture2D_NVGLZ; alias glFramebufferTexture2D = glFramebufferTexture2D_NVGLZ;
alias glbfn_glDeleteFramebuffers = void function (GLsizei n, const(GLuint)* framebuffers);
__gshared glbfn_glDeleteFramebuffers glDeleteFramebuffers_NVGLZ; alias glDeleteFramebuffers = glDeleteFramebuffers_NVGLZ;
alias glbfn_glGenFramebuffers = void function (GLsizei n, GLuint* framebuffers);
__gshared glbfn_glGenFramebuffers glGenFramebuffers_NVGLZ; alias glGenFramebuffers = glGenFramebuffers_NVGLZ;
alias glbfn_glCheckFramebufferStatus = GLenum function (GLenum target);
__gshared glbfn_glCheckFramebufferStatus glCheckFramebufferStatus_NVGLZ; alias glCheckFramebufferStatus = glCheckFramebufferStatus_NVGLZ;
alias glbfn_glBindFramebuffer = void function (GLenum target, GLuint framebuffer);
__gshared glbfn_glBindFramebuffer glBindFramebuffer_NVGLZ; alias glBindFramebuffer = glBindFramebuffer_NVGLZ;
alias glbfn_glGetIntegerv = void function (GLenum pname, GLint* data);
__gshared glbfn_glGetIntegerv glGetIntegerv_NVGLZ; alias glGetIntegerv = glGetIntegerv_NVGLZ;
private void nanovgInitOpenGL () {
private void nanovgInitOpenGL () @nogc nothrow {
__gshared bool initialized = false;
if (initialized) return;
glGenVertexArrays_NVGLZ = cast(glbfn_glGenVertexArrays)glbindGetProcAddress(`glGenVertexArrays`);
if (glGenVertexArrays_NVGLZ is null) assert(0, `OpenGL function 'glGenVertexArrays' not found!`);
glBindVertexArray_NVGLZ = cast(glbfn_glBindVertexArray)glbindGetProcAddress(`glBindVertexArray`);
if (glBindVertexArray_NVGLZ is null) assert(0, `OpenGL function 'glBindVertexArray' not found!`);
glDeleteVertexArrays_NVGLZ = cast(glbfn_glDeleteVertexArrays)glbindGetProcAddress(`glDeleteVertexArrays`);
if (glDeleteVertexArrays_NVGLZ is null) assert(0, `OpenGL function 'glDeleteVertexArrays' not found!`);
glGenerateMipmap_NVGLZ = cast(glbfn_glGenerateMipmap)glbindGetProcAddress(`glGenerateMipmap`);
if (glGenerateMipmap_NVGLZ is null) assert(0, `OpenGL function 'glGenerateMipmap' not found!`);
glBufferSubData_NVGLZ = cast(glbfn_glBufferSubData)glbindGetProcAddress(`glBufferSubData`);
if (glBufferSubData_NVGLZ is null) assert(0, `OpenGL function 'glBufferSubData' not found!`);
glStencilMask_NVGLZ = cast(glbfn_glStencilMask)glbindGetProcAddress(`glStencilMask`);
if (glStencilMask_NVGLZ is null) assert(0, `OpenGL function 'glStencilMask' not found!`);
glStencilFunc_NVGLZ = cast(glbfn_glStencilFunc)glbindGetProcAddress(`glStencilFunc`);
if (glStencilFunc_NVGLZ is null) assert(0, `OpenGL function 'glStencilFunc' not found!`);
glGetShaderInfoLog_NVGLZ = cast(glbfn_glGetShaderInfoLog)glbindGetProcAddress(`glGetShaderInfoLog`);
if (glGetShaderInfoLog_NVGLZ is null) assert(0, `OpenGL function 'glGetShaderInfoLog' not found!`);
glGetProgramInfoLog_NVGLZ = cast(glbfn_glGetProgramInfoLog)glbindGetProcAddress(`glGetProgramInfoLog`);
if (glGetProgramInfoLog_NVGLZ is null) assert(0, `OpenGL function 'glGetProgramInfoLog' not found!`);
glCreateProgram_NVGLZ = cast(glbfn_glCreateProgram)glbindGetProcAddress(`glCreateProgram`);
if (glCreateProgram_NVGLZ is null) assert(0, `OpenGL function 'glCreateProgram' not found!`);
glCreateShader_NVGLZ = cast(glbfn_glCreateShader)glbindGetProcAddress(`glCreateShader`);
if (glCreateShader_NVGLZ is null) assert(0, `OpenGL function 'glCreateShader' not found!`);
glShaderSource_NVGLZ = cast(glbfn_glShaderSource)glbindGetProcAddress(`glShaderSource`);
if (glShaderSource_NVGLZ is null) assert(0, `OpenGL function 'glShaderSource' not found!`);
glCompileShader_NVGLZ = cast(glbfn_glCompileShader)glbindGetProcAddress(`glCompileShader`);
if (glCompileShader_NVGLZ is null) assert(0, `OpenGL function 'glCompileShader' not found!`);
glGetShaderiv_NVGLZ = cast(glbfn_glGetShaderiv)glbindGetProcAddress(`glGetShaderiv`);
if (glGetShaderiv_NVGLZ is null) assert(0, `OpenGL function 'glGetShaderiv' not found!`);
glAttachShader_NVGLZ = cast(glbfn_glAttachShader)glbindGetProcAddress(`glAttachShader`);
if (glAttachShader_NVGLZ is null) assert(0, `OpenGL function 'glAttachShader' not found!`);
glBindAttribLocation_NVGLZ = cast(glbfn_glBindAttribLocation)glbindGetProcAddress(`glBindAttribLocation`);
if (glBindAttribLocation_NVGLZ is null) assert(0, `OpenGL function 'glBindAttribLocation' not found!`);
glLinkProgram_NVGLZ = cast(glbfn_glLinkProgram)glbindGetProcAddress(`glLinkProgram`);
if (glLinkProgram_NVGLZ is null) assert(0, `OpenGL function 'glLinkProgram' not found!`);
glGetProgramiv_NVGLZ = cast(glbfn_glGetProgramiv)glbindGetProcAddress(`glGetProgramiv`);
if (glGetProgramiv_NVGLZ is null) assert(0, `OpenGL function 'glGetProgramiv' not found!`);
glDeleteProgram_NVGLZ = cast(glbfn_glDeleteProgram)glbindGetProcAddress(`glDeleteProgram`);
if (glDeleteProgram_NVGLZ is null) assert(0, `OpenGL function 'glDeleteProgram' not found!`);
glDeleteShader_NVGLZ = cast(glbfn_glDeleteShader)glbindGetProcAddress(`glDeleteShader`);
if (glDeleteShader_NVGLZ is null) assert(0, `OpenGL function 'glDeleteShader' not found!`);
glGetUniformLocation_NVGLZ = cast(glbfn_glGetUniformLocation)glbindGetProcAddress(`glGetUniformLocation`);
if (glGetUniformLocation_NVGLZ is null) assert(0, `OpenGL function 'glGetUniformLocation' not found!`);
glGenBuffers_NVGLZ = cast(glbfn_glGenBuffers)glbindGetProcAddress(`glGenBuffers`);
if (glGenBuffers_NVGLZ is null) assert(0, `OpenGL function 'glGenBuffers' not found!`);
glPixelStorei_NVGLZ = cast(glbfn_glPixelStorei)glbindGetProcAddress(`glPixelStorei`);
if (glPixelStorei_NVGLZ is null) assert(0, `OpenGL function 'glPixelStorei' not found!`);
glUniform4fv_NVGLZ = cast(glbfn_glUniform4fv)glbindGetProcAddress(`glUniform4fv`);
if (glUniform4fv_NVGLZ is null) assert(0, `OpenGL function 'glUniform4fv' not found!`);
glColorMask_NVGLZ = cast(glbfn_glColorMask)glbindGetProcAddress(`glColorMask`);
if (glColorMask_NVGLZ is null) assert(0, `OpenGL function 'glColorMask' not found!`);
glStencilOpSeparate_NVGLZ = cast(glbfn_glStencilOpSeparate)glbindGetProcAddress(`glStencilOpSeparate`);
if (glStencilOpSeparate_NVGLZ is null) assert(0, `OpenGL function 'glStencilOpSeparate' not found!`);
glDrawArrays_NVGLZ = cast(glbfn_glDrawArrays)glbindGetProcAddress(`glDrawArrays`);
if (glDrawArrays_NVGLZ is null) assert(0, `OpenGL function 'glDrawArrays' not found!`);
glStencilOp_NVGLZ = cast(glbfn_glStencilOp)glbindGetProcAddress(`glStencilOp`);
if (glStencilOp_NVGLZ is null) assert(0, `OpenGL function 'glStencilOp' not found!`);
glUseProgram_NVGLZ = cast(glbfn_glUseProgram)glbindGetProcAddress(`glUseProgram`);
if (glUseProgram_NVGLZ is null) assert(0, `OpenGL function 'glUseProgram' not found!`);
glCullFace_NVGLZ = cast(glbfn_glCullFace)glbindGetProcAddress(`glCullFace`);
if (glCullFace_NVGLZ is null) assert(0, `OpenGL function 'glCullFace' not found!`);
glFrontFace_NVGLZ = cast(glbfn_glFrontFace)glbindGetProcAddress(`glFrontFace`);
if (glFrontFace_NVGLZ is null) assert(0, `OpenGL function 'glFrontFace' not found!`);
glActiveTexture_NVGLZ = cast(glbfn_glActiveTexture)glbindGetProcAddress(`glActiveTexture`);
if (glActiveTexture_NVGLZ is null) assert(0, `OpenGL function 'glActiveTexture' not found!`);
glBindBuffer_NVGLZ = cast(glbfn_glBindBuffer)glbindGetProcAddress(`glBindBuffer`);
if (glBindBuffer_NVGLZ is null) assert(0, `OpenGL function 'glBindBuffer' not found!`);
glBufferData_NVGLZ = cast(glbfn_glBufferData)glbindGetProcAddress(`glBufferData`);
if (glBufferData_NVGLZ is null) assert(0, `OpenGL function 'glBufferData' not found!`);
glEnableVertexAttribArray_NVGLZ = cast(glbfn_glEnableVertexAttribArray)glbindGetProcAddress(`glEnableVertexAttribArray`);
if (glEnableVertexAttribArray_NVGLZ is null) assert(0, `OpenGL function 'glEnableVertexAttribArray' not found!`);
glVertexAttribPointer_NVGLZ = cast(glbfn_glVertexAttribPointer)glbindGetProcAddress(`glVertexAttribPointer`);
if (glVertexAttribPointer_NVGLZ is null) assert(0, `OpenGL function 'glVertexAttribPointer' not found!`);
glUniform1i_NVGLZ = cast(glbfn_glUniform1i)glbindGetProcAddress(`glUniform1i`);
if (glUniform1i_NVGLZ is null) assert(0, `OpenGL function 'glUniform1i' not found!`);
glUniform2fv_NVGLZ = cast(glbfn_glUniform2fv)glbindGetProcAddress(`glUniform2fv`);
if (glUniform2fv_NVGLZ is null) assert(0, `OpenGL function 'glUniform2fv' not found!`);
glDisableVertexAttribArray_NVGLZ = cast(glbfn_glDisableVertexAttribArray)glbindGetProcAddress(`glDisableVertexAttribArray`);
if (glDisableVertexAttribArray_NVGLZ is null) assert(0, `OpenGL function 'glDisableVertexAttribArray' not found!`);
glDeleteBuffers_NVGLZ = cast(glbfn_glDeleteBuffers)glbindGetProcAddress(`glDeleteBuffers`);
if (glDeleteBuffers_NVGLZ is null) assert(0, `OpenGL function 'glDeleteBuffers' not found!`);
glBlendFuncSeparate_NVGLZ = cast(glbfn_glBlendFuncSeparate)glbindGetProcAddress(`glBlendFuncSeparate`);
if (glBlendFuncSeparate_NVGLZ is null) assert(0, `OpenGL function 'glBlendFuncSeparate' not found!`);
try
gl3.loadDynamicLibrary();
catch(Exception)
assert(0, "GL 3 failed to load");
glLogicOp_NVGLZ = cast(glbfn_glLogicOp)glbindGetProcAddress(`glLogicOp`);
if (glLogicOp_NVGLZ is null) assert(0, `OpenGL function 'glLogicOp' not found!`);
glFramebufferTexture2D_NVGLZ = cast(glbfn_glFramebufferTexture2D)glbindGetProcAddress(`glFramebufferTexture2D`);
if (glFramebufferTexture2D_NVGLZ is null) assert(0, `OpenGL function 'glFramebufferTexture2D' not found!`);
glDeleteFramebuffers_NVGLZ = cast(glbfn_glDeleteFramebuffers)glbindGetProcAddress(`glDeleteFramebuffers`);
if (glDeleteFramebuffers_NVGLZ is null) assert(0, `OpenGL function 'glDeleteFramebuffers' not found!`);
glGenFramebuffers_NVGLZ = cast(glbfn_glGenFramebuffers)glbindGetProcAddress(`glGenFramebuffers`);
if (glGenFramebuffers_NVGLZ is null) assert(0, `OpenGL function 'glGenFramebuffers' not found!`);
glCheckFramebufferStatus_NVGLZ = cast(glbfn_glCheckFramebufferStatus)glbindGetProcAddress(`glCheckFramebufferStatus`);
if (glCheckFramebufferStatus_NVGLZ is null) assert(0, `OpenGL function 'glCheckFramebufferStatus' not found!`);
glBindFramebuffer_NVGLZ = cast(glbfn_glBindFramebuffer)glbindGetProcAddress(`glBindFramebuffer`);
if (glBindFramebuffer_NVGLZ is null) assert(0, `OpenGL function 'glBindFramebuffer' not found!`);
glGetIntegerv_NVGLZ = cast(glbfn_glGetIntegerv)glbindGetProcAddress(`glGetIntegerv`);
if (glGetIntegerv_NVGLZ is null) assert(0, `OpenGL function 'glGetIntegerv' not found!`);
initialized = true;
}
}
}

View File

@ -8400,6 +8400,9 @@ version(Windows) {
return DefWindowProc(hWnd, iMessage, wParam, lParam);
}
} catch (Exception e) {
//try {
//MessageBoxA(null, (e.toString() ~ "\0").ptr, "Exception caught in WndProc", 0);
//} catch(Exception e) {}
assert(false, "Exception caught in WndProc " ~ e.toString());
}
}
@ -13944,7 +13947,7 @@ extern(System) nothrow @nogc {
static if (!SdpyIsUsingIVGLBinds) {
interface GL {
extern(System) @nogc nothrow {
extern(System) @nogc nothrow:
void glGetIntegerv(int, void*);
void glMatrixMode(int);
@ -14050,31 +14053,78 @@ extern(System) nothrow @nogc {
}
}
interface GL3 {
extern(System) @nogc nothrow:
void glGenVertexArrays(GLsizei, GLuint*);
void glBindVertexArray(GLuint);
void glDeleteVertexArrays(GLsizei, const(GLuint)*);
void glGenerateMipmap(GLenum);
void glBufferSubData(GLenum, GLintptr, GLsizeiptr, const(GLvoid)*);
void glStencilMask(GLuint);
void glStencilFunc(GLenum, GLint, GLuint);
void glGetShaderInfoLog(GLuint, GLsizei, GLsizei*, GLchar*);
void glGetProgramInfoLog(GLuint, GLsizei, GLsizei*, GLchar*);
GLuint glCreateProgram();
GLuint glCreateShader(GLenum);
void glShaderSource(GLuint, GLsizei, const(GLchar*)*, const(GLint)*);
void glCompileShader(GLuint);
void glGetShaderiv(GLuint, GLenum, GLint*);
void glAttachShader(GLuint, GLuint);
void glBindAttribLocation(GLuint, GLuint, const(GLchar)*);
void glLinkProgram(GLuint);
void glGetProgramiv(GLuint, GLenum, GLint*);
void glDeleteProgram(GLuint);
void glDeleteShader(GLuint);
GLint glGetUniformLocation(GLuint, const(GLchar)*);
void glGenBuffers(GLsizei, GLuint*);
void glUniform4fv(GLint, GLsizei, const(GLfloat)*);
void glUniform4f(GLint, float, float, float, float);
void glColorMask(GLboolean, GLboolean, GLboolean, GLboolean);
void glStencilOpSeparate(GLenum, GLenum, GLenum, GLenum);
void glDrawArrays(GLenum, GLint, GLsizei);
void glStencilOp(GLenum, GLenum, GLenum);
void glUseProgram(GLuint);
void glCullFace(GLenum);
void glFrontFace(GLenum);
void glActiveTexture(GLenum);
void glBindBuffer(GLenum, GLuint);
void glBufferData(GLenum, GLsizeiptr, const(void)*, GLenum);
void glEnableVertexAttribArray(GLuint);
void glVertexAttribPointer(GLuint, GLint, GLenum, GLboolean, GLsizei, const(void)*);
void glUniform1i(GLint, GLint);
void glUniform2fv(GLint, GLsizei, const(GLfloat)*);
void glDisableVertexAttribArray(GLuint);
void glDeleteBuffers(GLsizei, const(GLuint)*);
void glBlendFuncSeparate(GLenum, GLenum, GLenum, GLenum);
void glLogicOp (GLenum opcode);
void glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
void glDeleteFramebuffers (GLsizei n, const(GLuint)* framebuffers);
void glGenFramebuffers (GLsizei n, GLuint* framebuffers);
GLenum glCheckFramebufferStatus (GLenum target);
void glBindFramebuffer (GLenum target, GLuint framebuffer);
}
interface GLU {
extern(System) @nogc nothrow {
extern(System) @nogc nothrow:
void gluLookAt(double, double, double, double, double, double, double, double, double);
void gluPerspective(double, double, double, double);
char* gluErrorString(uint);
}
}
enum GL_RED = 0x1903;
enum GL_ALPHA = 0x1906;
enum GL_UNPACK_ALIGNMENT = 0x0CF5;
enum uint GL_FRONT = 0x0404;
enum uint GL_BLEND = 0x0be2;
enum uint GL_SRC_ALPHA = 0x0302;
enum uint GL_ONE_MINUS_SRC_ALPHA = 0x0303;
enum uint GL_LEQUAL = 0x0203;
enum uint GL_UNSIGNED_BYTE = 0x1401;
enum uint GL_RGB = 0x1907;
enum uint GL_BGRA = 0x80e1;
enum uint GL_RGBA = 0x1908;
@ -14122,6 +14172,113 @@ extern(System) nothrow @nogc {
enum int GL_QUADS = 7;
enum int GL_QUAD_STRIP = 8;
enum int GL_POLYGON = 9;
alias GLvoid = void;
alias GLboolean = ubyte;
alias GLuint = uint;
alias GLenum = uint;
alias GLchar = char;
alias GLsizei = int;
alias GLfloat = float;
alias GLintptr = size_t;
alias GLsizeiptr = ptrdiff_t;
enum uint GL_INVALID_ENUM = 0x0500;
enum uint GL_ZERO = 0;
enum uint GL_ONE = 1;
enum uint GL_BYTE = 0x1400;
enum uint GL_UNSIGNED_BYTE = 0x1401;
enum uint GL_SHORT = 0x1402;
enum uint GL_UNSIGNED_SHORT = 0x1403;
enum uint GL_INT = 0x1404;
enum uint GL_UNSIGNED_INT = 0x1405;
enum uint GL_FLOAT = 0x1406;
enum uint GL_2_BYTES = 0x1407;
enum uint GL_3_BYTES = 0x1408;
enum uint GL_4_BYTES = 0x1409;
enum uint GL_DOUBLE = 0x140A;
enum uint GL_STREAM_DRAW = 0x88E0;
enum uint GL_CCW = 0x0901;
enum uint GL_STENCIL_TEST = 0x0B90;
enum uint GL_SCISSOR_TEST = 0x0C11;
enum uint GL_EQUAL = 0x0202;
enum uint GL_NOTEQUAL = 0x0205;
enum uint GL_ALWAYS = 0x0207;
enum uint GL_KEEP = 0x1E00;
enum uint GL_INCR = 0x1E02;
enum uint GL_INCR_WRAP = 0x8507;
enum uint GL_DECR_WRAP = 0x8508;
enum uint GL_CULL_FACE = 0x0B44;
enum uint GL_BACK = 0x0405;
enum uint GL_FRAGMENT_SHADER = 0x8B30;
enum uint GL_VERTEX_SHADER = 0x8B31;
enum uint GL_COMPILE_STATUS = 0x8B81;
enum uint GL_LINK_STATUS = 0x8B82;
enum uint GL_ELEMENT_ARRAY_BUFFER = 0x8893;
enum uint GL_STATIC_DRAW = 0x88E4;
enum uint GL_UNPACK_ALIGNMENT = 0x0CF5;
enum uint GL_UNPACK_ROW_LENGTH = 0x0CF2;
enum uint GL_UNPACK_SKIP_PIXELS = 0x0CF4;
enum uint GL_UNPACK_SKIP_ROWS = 0x0CF3;
enum uint GL_GENERATE_MIPMAP = 0x8191;
enum uint GL_LINEAR_MIPMAP_LINEAR = 0x2703;
enum uint GL_TEXTURE0 = 0x84C0U;
enum uint GL_TEXTURE1 = 0x84C1U;
enum uint GL_ARRAY_BUFFER = 0x8892;
enum uint GL_SRC_COLOR = 0x0300;
enum uint GL_ONE_MINUS_SRC_COLOR = 0x0301;
enum uint GL_SRC_ALPHA = 0x0302;
enum uint GL_ONE_MINUS_SRC_ALPHA = 0x0303;
enum uint GL_DST_ALPHA = 0x0304;
enum uint GL_ONE_MINUS_DST_ALPHA = 0x0305;
enum uint GL_DST_COLOR = 0x0306;
enum uint GL_ONE_MINUS_DST_COLOR = 0x0307;
enum uint GL_SRC_ALPHA_SATURATE = 0x0308;
enum uint GL_INVERT = 0x150AU;
enum uint GL_DEPTH_STENCIL = 0x84F9U;
enum uint GL_UNSIGNED_INT_24_8 = 0x84FAU;
enum uint GL_FRAMEBUFFER = 0x8D40U;
enum uint GL_COLOR_ATTACHMENT0 = 0x8CE0U;
enum uint GL_DEPTH_STENCIL_ATTACHMENT = 0x821AU;
enum uint GL_FRAMEBUFFER_COMPLETE = 0x8CD5U;
enum uint GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6U;
enum uint GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7U;
enum uint GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9U;
enum uint GL_FRAMEBUFFER_UNSUPPORTED = 0x8CDDU;
enum uint GL_COLOR_LOGIC_OP = 0x0BF2U;
enum uint GL_CLEAR = 0x1500U;
enum uint GL_COPY = 0x1503U;
enum uint GL_XOR = 0x1506U;
enum uint GL_FRAMEBUFFER_BINDING = 0x8CA6U;
enum uint GL_TEXTURE_LOD_BIAS = 0x8501;
}
}
@ -14134,6 +14291,8 @@ static if(!SdpyIsUsingIVGLBinds) {
mixin DynamicLoad!(GL, "GL", true) gl;
mixin DynamicLoad!(GLU, "GLU", true) glu;
}
mixin DynamicLoadSupplementalOpenGL!(GL3) gl3;
shared static this() {
gl.loadDynamicLibrary();
@ -14142,6 +14301,141 @@ static if(!SdpyIsUsingIVGLBinds) {
}
}
/++
Convenience method for converting D arrays to opengl buffer data
I would LOVE to overload it with the original glBufferData, but D won't
let me since glBufferData is a function pointer :(
+/
void glBufferDataSlice(GLenum target, const(void[]) data, GLenum usage) {
glBufferData(target, data.length, data.ptr, usage);
}
/++
Convenience class for using opengl shaders.
Ensure that you've loaded opengl 3+ and set your active
context before trying to use this.
Added: August 25, 2020 (version 8.5)
+/
final class OpenGlShader {
private int shaderProgram_;
private @property void shaderProgram(int a) {
shaderProgram_ = a;
}
/// Get the program ID for use in OpenGL functions.
public @property int shaderProgram() {
return shaderProgram_;
}
/++
+/
static struct Source {
uint type; /// GL_FRAGMENT_SHADER, GL_VERTEX_SHADER, etc.
string code; ///
}
/++
Constructs the shader object by calling `glCreateProgram`, then
compiling each given [Source], and finally, linking them together.
Throws: on compile or link failure.
+/
this(Source[] codes...) {
shaderProgram = glCreateProgram();
int[16] shadersBufferStack;
int[] shadersBuffer = codes.length <= shadersBufferStack.length ?
shadersBufferStack[0 .. codes.length] :
new int[](codes.length);
foreach(idx, code; codes) {
shadersBuffer[idx] = glCreateShader(code.type);
const(char)*[1] buffer;
int[1] lengthBuffer;
buffer[0] = code.code.ptr;
lengthBuffer[0] = cast(int) code.code.length;
glShaderSource(shadersBuffer[idx], 1, buffer.ptr, lengthBuffer.ptr);
glCompileShader(shadersBuffer[idx]);
int success;
glGetShaderiv(shadersBuffer[idx], GL_COMPILE_STATUS, &success);
if(!success) {
char[512] info;
int len;
glGetShaderInfoLog(shadersBuffer[idx], info.length, &len, info.ptr);
throw new Exception("Shader compile failure: " ~ cast(immutable) info[0 .. len]);
}
glAttachShader(shaderProgram, shadersBuffer[idx]);
}
glLinkProgram(shaderProgram);
int success;
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if(!success) {
char[512] info;
int len;
glGetProgramInfoLog(shaderProgram, info.length, &len, info.ptr);
throw new Exception("Shader link failure: " ~ cast(immutable) info[0 .. len]);
}
foreach(s; shadersBuffer)
glDeleteShader(s);
}
/// Calls `glUseProgram(this.shaderProgram)`
void use() {
glUseProgram(this.shaderProgram);
}
/// Deletes the program.
void delete_() {
glDeleteProgram(shaderProgram);
shaderProgram = 0;
}
/++
[OpenGlShader.uniforms].name gives you one of these.
You can get the id out of it or just assign
+/
static struct Uniform {
/// the id passed to glUniform*
int id;
/// Assigns the 4 floats. You will probably have to call this via the .opAssign name
void opAssign(float x, float y, float z, float a) {
glUniform4f(id, x, y, z, a);
}
}
static struct UniformsHelper {
OpenGlShader _shader;
Uniform opDispatch(string name)() {
auto i = glGetUniformLocation(_shader.shaderProgram, name.ptr);
if(i == -1)
throw new Exception("Could not find uniform " ~ name);
return Uniform(i);
}
}
/++
Gives access to the uniforms through dot access.
`OpenGlShader.Uniform = shader.uniforms.foo; // calls glGetUniformLocation(this, "foo");
+/
@property UniformsHelper uniforms() { return UniformsHelper(this); }
}
version(linux) {
version(with_eventloop) {} else {
private int epollFd = -1;
@ -15366,13 +15660,34 @@ __gshared bool librariesSuccessfullyLoaded = true;
///
__gshared bool openGlLibrariesSuccessfullyLoaded = true;
private mixin template DynamicLoadSupplementalOpenGL(Iface) {
static foreach(name; __traits(derivedMembers, Iface))
mixin("__gshared typeof(&__traits(getMember, Iface, name)) " ~ name ~ ";");
void loadDynamicLibrary() @nogc {
(cast(void function() @nogc) &loadDynamicLibraryForReal)();
}
void loadDynamicLibraryForReal() {
foreach(name; __traits(derivedMembers, Iface)) {
mixin("alias tmp = " ~ name ~ ";");
tmp = cast(typeof(tmp)) glbindGetProcAddress(name);
if(tmp is null) throw new Exception("load failure of function " ~ name ~ " from supplemental OpenGL");
}
}
}
private mixin template DynamicLoad(Iface, string library, bool openGLRelated = false) {
static foreach(name; __traits(derivedMembers, Iface))
mixin("__gshared typeof(&__traits(getMember, Iface, name)) " ~ name ~ ";");
private void* libHandle;
void loadDynamicLibrary() {
void loadDynamicLibrary() @nogc {
(cast(void function() @nogc) &loadDynamicLibraryForReal)();
}
void loadDynamicLibraryForReal() {
version(Posix) {
import core.sys.posix.dlfcn;
version(OSX) {