mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-18 20:55:44 +01:00
53 lines
1.6 KiB
C
53 lines
1.6 KiB
C
/* Copyright (c) 2025 Quinn
|
|
* Licensed under the MIT Licence. See LICENSE for details */
|
|
#include "shader.h"
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
#include "../error.h"
|
|
|
|
|
|
// NOTE: we are currently just sucking up the memory costs for ease. We can either include the source files themselves. Or use compression, where I'd prefer the latter for ease of installation.
|
|
extern const char sh_vert_glsl[];
|
|
extern const char sh_frag_glsl[];
|
|
extern const char sh_geom_glsl[];
|
|
extern const uint sh_vert_glsl_len;
|
|
extern const uint sh_frag_glsl_len;
|
|
extern const uint sh_geom_glsl_len;
|
|
|
|
/* compile a shader */
|
|
static GLuint shader_compile(GLenum type, const char *src, size_t len) {
|
|
int ilen = len;
|
|
GLuint shader = glCreateShader(type);
|
|
glShaderSource(shader, 1, &src, &ilen);
|
|
glCompileShader(shader);
|
|
|
|
// repurposing ilen for the max length of the shader log
|
|
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &ilen);
|
|
if (ilen > 0) {
|
|
char log[ilen];
|
|
glGetShaderInfoLog(shader, ilen, &ilen, log);
|
|
log[ilen - 1] = '\0'; // terminate the string one character sooner since the log includes a newline
|
|
error("error whilst compiling shader type '0x%X': '%s'", type, log);
|
|
}
|
|
|
|
return shader;
|
|
}
|
|
|
|
int shader_init(GLuint pipe) {
|
|
GLuint vs = shader_compile(GL_VERTEX_SHADER, sh_vert_glsl, sh_vert_glsl_len);
|
|
GLuint fs = shader_compile(GL_FRAGMENT_SHADER, sh_frag_glsl, sh_frag_glsl_len);
|
|
GLuint gs = shader_compile(GL_GEOMETRY_SHADER, sh_geom_glsl, sh_geom_glsl_len);
|
|
|
|
glAttachShader(pipe, vs);
|
|
glAttachShader(pipe, fs);
|
|
glAttachShader(pipe, gs);
|
|
|
|
glDeleteShader(vs);
|
|
glDeleteShader(fs);
|
|
glDeleteShader(gs);
|
|
return 1;
|
|
}
|