Browse Source

Add argument for printing shader name in errors

master
Macoy Madson 9 months ago
parent
commit
42208db325
  1. 30
      src/OpenGL.cake

30
src/OpenGL.cake

@ -11,23 +11,31 @@
(def-type-alias-global gl-id (unsigned int))
(defun opengl-shader-was-compiled-sucessfully (shader gl-id &return bool)
(defun opengl-shader-was-compiled-sucessfully
(shader gl-id
helpful-name (addr (const char))
&return bool)
(var success int)
(var output-buffer (array 512 char))
(glGetShaderiv shader GL_COMPILE_STATUS (addr success))
(unless success
(glGetShaderInfoLog shader (sizeof output-buffer) null output-buffer)
(fprintf stderr "error: Shader compilation failed:\n%s\n" output-buffer)
(fprintf stderr "error: Shader '%s' compilation failed:\n%s\n"
helpful-name output-buffer)
(return false))
(return true))
(defun opengl-program-was-linked-sucessfully (program gl-id &return bool)
(defun opengl-program-was-linked-sucessfully
(program gl-id
helpful-name (addr (const char))
&return bool)
(var success int)
(var output-buffer (array 512 char))
(glGetProgramiv program GL_LINK_STATUS (addr success))
(unless success
(glGetProgramInfoLog program (sizeof output-buffer) null output-buffer)
(fprintf stderr "error: Program link failed:\n%s\n" output-buffer)
(fprintf stderr "error: Program '%s' link failed:\n%s\n"
helpful-name output-buffer)
(return false))
(return true))
@ -35,6 +43,7 @@
(program-id-out (addr gl-id)
vertex-shader-code (addr (const char))
fragment-shader-code (addr (const char))
helpful-name (addr (const char))
&return bool)
(set (deref program-id-out) (glCreateProgram))
(var vertex-shader gl-id (glCreateShader GL_VERTEX_SHADER))
@ -42,20 +51,21 @@
(scope ;; Vertex shader
(glShaderSource vertex-shader 1 (addr vertex-shader-code) null)
(glCompileShader vertex-shader)
(unless (opengl-shader-was-compiled-sucessfully vertex-shader)
(unless (opengl-shader-was-compiled-sucessfully vertex-shader helpful-name)
(return false)))
(var fragment-shader gl-id (glCreateShader GL_FRAGMENT_SHADER))
(defer (glDeleteShader fragment-shader))
(scope ;; Fragment shader
(glShaderSource fragment-shader 1 (addr fragment-shader-code) null)
(glCompileShader fragment-shader)
(unless (opengl-shader-was-compiled-sucessfully fragment-shader)
(unless (opengl-shader-was-compiled-sucessfully fragment-shader helpful-name)
(return false)))
(scope ;; Link vertex and fragment shader
(glAttachShader (deref program-id-out) vertex-shader)
(glAttachShader (deref program-id-out) fragment-shader)
(glLinkProgram (deref program-id-out))
(unless (opengl-program-was-linked-sucessfully (deref program-id-out))
(unless (opengl-program-was-linked-sucessfully (deref program-id-out)
helpful-name)
(return false)))
(return true))
@ -87,7 +97,7 @@ void main()
}#"#)
(glShaderSource vertex-shader 1 (addr vertex-shader-code) null)
(glCompileShader vertex-shader)
(unless (opengl-shader-was-compiled-sucessfully vertex-shader)
(unless (opengl-shader-was-compiled-sucessfully vertex-shader "Test vertex shader")
(sdl-shutdown window)
(return 1)))
@ -105,7 +115,7 @@ void main()
}#"#)
(glShaderSource fragment-shader 1 (addr fragment-shader-code) null)
(glCompileShader fragment-shader)
(unless (opengl-shader-was-compiled-sucessfully fragment-shader)
(unless (opengl-shader-was-compiled-sucessfully fragment-shader "Test fragment shader")
(sdl-shutdown window)
(return 1)))
@ -113,7 +123,7 @@ void main()
(glAttachShader shader-program vertex-shader)
(glAttachShader shader-program fragment-shader)
(glLinkProgram shader-program)
(unless (opengl-program-was-linked-sucessfully shader-program)
(unless (opengl-program-was-linked-sucessfully shader-program "Test shader")
(sdl-shutdown window)
(return 1)))

Loading…
Cancel
Save