Compare commits
No commits in common. "6ec993c6f8b57698bc7c7488901c209e7142d8b2" and "43d62948b7d58deacc4f2090388a6c72de1286bc" have entirely different histories.
6ec993c6f8
...
43d62948b7
@ -32,6 +32,8 @@ static void rk_printf(char const * message) {
|
|||||||
printf("[RK] %s\n", message);
|
printf("[RK] %s\n", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define rk_gl_error(_message) { if (glGetError() != GL_NO_ERROR) { printf("[GL] %s\n", (_message)); } }
|
||||||
|
|
||||||
static void rk_debug_message_callback(
|
static void rk_debug_message_callback(
|
||||||
GLenum source,
|
GLenum source,
|
||||||
GLenum type,
|
GLenum type,
|
||||||
@ -53,16 +55,6 @@ void rk_render_initialize(
|
|||||||
printf("[GL] version: %s, language: %s\n", version, language);
|
printf("[GL] version: %s, language: %s\n", version, language);
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
GLint max_texture_layers = 0;
|
|
||||||
glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &max_texture_layers);
|
|
||||||
printf("[GL] Max texture layers: %d\n", max_texture_layers);
|
|
||||||
GLint max_vertex_attribs = 0;
|
|
||||||
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs);
|
|
||||||
printf("[GL] Max vertex attribs: %d\n", max_vertex_attribs);
|
|
||||||
GLint max_vertex_bindings = 0;
|
|
||||||
glGetIntegerv(GL_MAX_VERTEX_ATTRIB_BINDINGS, &max_vertex_bindings);
|
|
||||||
printf("[GL] Max vertex bindings: %d\n", max_vertex_bindings);
|
|
||||||
|
|
||||||
glDebugMessageCallback(rk_debug_message_callback, nullptr);
|
glDebugMessageCallback(rk_debug_message_callback, nullptr);
|
||||||
glEnable(GL_DEBUG_OUTPUT);
|
glEnable(GL_DEBUG_OUTPUT);
|
||||||
}
|
}
|
||||||
@ -81,7 +73,7 @@ void rk_render_initialize(
|
|||||||
}
|
}
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glDisable(GL_DITHER);
|
glEnable(GL_DITHER);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_SCISSOR_TEST);
|
glDisable(GL_SCISSOR_TEST);
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
@ -94,79 +86,60 @@ void rk_render_initialize(
|
|||||||
void rk_render_terminate() {
|
void rk_render_terminate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static char rk_infolog[1024];
|
|
||||||
|
|
||||||
static void rk_print_shader_infolog(GLuint shader) {
|
static void rk_print_shader_infolog(GLuint shader) {
|
||||||
GLsizei length;
|
GLsizei length;
|
||||||
glGetShaderInfoLog(shader, sizeof(rk_infolog) - 1, &length, rk_infolog);
|
char infolog[1024];
|
||||||
|
glGetShaderInfoLog(shader, sizeof(infolog), &length, infolog);
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
rk_gl_printf(rk_infolog);
|
rk_printf(infolog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rk_print_program_infolog(GLuint program) {
|
static void rk_print_program_infolog(GLuint program) {
|
||||||
GLsizei length;
|
GLsizei length;
|
||||||
glGetProgramInfoLog(program, sizeof(rk_infolog) - 1, &length, rk_infolog);
|
char infolog[1024];
|
||||||
|
glGetProgramInfoLog(program, sizeof(infolog), &length, infolog);
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
rk_gl_printf(rk_infolog);
|
rk_printf(infolog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: error handling
|
||||||
rk_shader_t rk_load_shader(
|
rk_shader_t rk_load_shader(
|
||||||
rk_uint const vert_nlines,
|
rk_uint const vert_nlines,
|
||||||
char const ** const vert_lines,
|
char const ** const vert_lines,
|
||||||
rk_uint const frag_nlines,
|
rk_uint const frag_nlines,
|
||||||
char const ** const frag_lines) {
|
char const ** const frag_lines) {
|
||||||
if (!vert_nlines || !vert_lines || !frag_nlines || !frag_lines) {
|
rk_shader * const shader = new rk_shader;
|
||||||
rk_printf("rk_load_shader(): invalid params.");
|
shader->vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||||
return RK_INVALID_HANDLE;
|
shader->fragment = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
shader->program = glCreateProgram();
|
||||||
|
if (!vert_nlines || !vert_lines) {
|
||||||
|
rk_printf("Missing vertex shader.");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
if (!frag_nlines || !frag_lines) {
|
||||||
|
rk_printf("Missing fragment shader.");
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
rk_printf("Compiling vertex shader...");
|
rk_printf("Compiling vertex shader...");
|
||||||
while (glGetError() != GL_NO_ERROR);
|
glShaderSource(shader->vertex, vert_nlines, vert_lines, nullptr);
|
||||||
GLuint const vert = glCreateShader(GL_VERTEX_SHADER);
|
glCompileShader(shader->vertex);
|
||||||
glShaderSource(vert, vert_nlines, vert_lines, nullptr);
|
rk_gl_error("glCompileShader() failed.");
|
||||||
glCompileShader(vert);
|
rk_print_shader_infolog(shader->vertex);
|
||||||
GLint vert_success = 0;
|
|
||||||
glGetShaderiv(vert, GL_COMPILE_STATUS, &vert_success);
|
|
||||||
if (!vert_success || glGetError() != GL_NO_ERROR) {
|
|
||||||
rk_print_shader_infolog(vert);
|
|
||||||
glDeleteShader(vert);
|
|
||||||
return RK_INVALID_HANDLE;
|
|
||||||
}
|
|
||||||
rk_printf("Compiling fragment shader...");
|
rk_printf("Compiling fragment shader...");
|
||||||
while (glGetError() != GL_NO_ERROR);
|
glShaderSource(shader->fragment, frag_nlines, frag_lines, nullptr);
|
||||||
GLuint const frag = glCreateShader(GL_FRAGMENT_SHADER);
|
glCompileShader(shader->fragment);
|
||||||
glShaderSource(frag, frag_nlines, frag_lines, nullptr);
|
rk_gl_error("glCompileShader() failed.");
|
||||||
glCompileShader(frag);
|
rk_print_shader_infolog(shader->fragment);
|
||||||
GLint frag_success = 0;
|
|
||||||
glGetShaderiv(frag, GL_COMPILE_STATUS, &frag_success);
|
|
||||||
if (!frag_success || glGetError() != GL_NO_ERROR) {
|
|
||||||
rk_print_shader_infolog(frag);
|
|
||||||
glDeleteShader(vert);
|
|
||||||
glDeleteShader(frag);
|
|
||||||
return RK_INVALID_HANDLE;
|
|
||||||
}
|
|
||||||
rk_printf("Linking program...");
|
rk_printf("Linking program...");
|
||||||
while (glGetError() != GL_NO_ERROR);
|
glAttachShader(shader->program, shader->vertex);
|
||||||
GLuint prog = glCreateProgram();
|
glAttachShader(shader->program, shader->fragment);
|
||||||
glAttachShader(prog, vert);
|
glLinkProgram(shader->program);
|
||||||
glAttachShader(prog, frag);
|
rk_gl_error("glLinkProgram() failed.");
|
||||||
glLinkProgram(prog);
|
rk_print_program_infolog(shader->program);
|
||||||
GLint prog_success = 0;
|
|
||||||
glGetProgramiv(prog, GL_LINK_STATUS, &prog_success);
|
|
||||||
if (!prog_success || glGetError() != GL_NO_ERROR) {
|
|
||||||
rk_print_program_infolog(prog);
|
|
||||||
glDeleteShader(vert);
|
|
||||||
glDeleteShader(frag);
|
|
||||||
glDeleteProgram(prog);
|
|
||||||
return RK_INVALID_HANDLE;
|
|
||||||
}
|
|
||||||
rk_printf("Done.");
|
rk_printf("Done.");
|
||||||
glReleaseShaderCompiler();
|
glReleaseShaderCompiler();
|
||||||
rk_shader * const shader = new rk_shader;
|
|
||||||
shader->vertex = vert;
|
|
||||||
shader->fragment = frag;
|
|
||||||
shader->program = prog;
|
|
||||||
return reinterpret_cast<rk_shader_t>(shader);
|
return reinterpret_cast<rk_shader_t>(shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,8 +148,7 @@ rk_input_t rk_resolve_input(
|
|||||||
char const * name) {
|
char const * name) {
|
||||||
rk_shader const * const shader = reinterpret_cast<rk_shader const *>(_shader);
|
rk_shader const * const shader = reinterpret_cast<rk_shader const *>(_shader);
|
||||||
if (!shader || !name) {
|
if (!shader || !name) {
|
||||||
rk_printf("rk_resolve_input(): invalid params.");
|
return nullptr;
|
||||||
return RK_INVALID_HANDLE;
|
|
||||||
}
|
}
|
||||||
GLint const uniform = glGetUniformLocation(shader->program, name);
|
GLint const uniform = glGetUniformLocation(shader->program, name);
|
||||||
return reinterpret_cast<rk_input_t>(uniform + 1);
|
return reinterpret_cast<rk_input_t>(uniform + 1);
|
||||||
@ -187,8 +159,7 @@ rk_param_t rk_resolve_param(
|
|||||||
char const * name) {
|
char const * name) {
|
||||||
rk_shader const * const shader = reinterpret_cast<rk_shader const *>(_shader);
|
rk_shader const * const shader = reinterpret_cast<rk_shader const *>(_shader);
|
||||||
if (!shader || !name) {
|
if (!shader || !name) {
|
||||||
rk_printf("rk_resolve_param(): invalid params.");
|
return nullptr;
|
||||||
return RK_INVALID_HANDLE;
|
|
||||||
}
|
}
|
||||||
GLint const location = glGetAttribLocation(shader->program, name);
|
GLint const location = glGetAttribLocation(shader->program, name);
|
||||||
return reinterpret_cast<rk_param_t>(location + 1);
|
return reinterpret_cast<rk_param_t>(location + 1);
|
||||||
@ -202,8 +173,7 @@ rk_texture_t rk_create_texture(
|
|||||||
rk_texture_flags flags,
|
rk_texture_flags flags,
|
||||||
rk_ubyte const * pixels) {
|
rk_ubyte const * pixels) {
|
||||||
if (!width || !height || !pixels) {
|
if (!width || !height || !pixels) {
|
||||||
rk_printf("rk_create_texture(): invalid params.");
|
return nullptr;
|
||||||
return RK_INVALID_HANDLE;
|
|
||||||
}
|
}
|
||||||
GLint internal_format;
|
GLint internal_format;
|
||||||
GLenum source_format;
|
GLenum source_format;
|
||||||
@ -230,8 +200,7 @@ rk_texture_t rk_create_texture(
|
|||||||
source_type = GL_FLOAT;
|
source_type = GL_FLOAT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rk_printf("rk_create_texture(): invalid texture format.");
|
return nullptr;
|
||||||
return RK_INVALID_HANDLE;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
rk_texture * const texture = new rk_texture;
|
rk_texture * const texture = new rk_texture;
|
||||||
@ -285,8 +254,7 @@ rk_triangles_t rk_create_triangles(
|
|||||||
rk_uint nvertices,
|
rk_uint nvertices,
|
||||||
rk_vec3 const * vertices) {
|
rk_vec3 const * vertices) {
|
||||||
if (!nvertices || !vertices) {
|
if (!nvertices || !vertices) {
|
||||||
rk_printf("rk_create_triangles(): invalid params.");
|
return nullptr;
|
||||||
return RK_INVALID_HANDLE;
|
|
||||||
}
|
}
|
||||||
rk_triangles * const triangles = new rk_triangles;
|
rk_triangles * const triangles = new rk_triangles;
|
||||||
triangles->size = nvertices;
|
triangles->size = nvertices;
|
||||||
@ -309,8 +277,7 @@ rk_vertices_t rk_create_vertices(
|
|||||||
rk_uint nindices,
|
rk_uint nindices,
|
||||||
rk_ushort const * indices) {
|
rk_ushort const * indices) {
|
||||||
if (!format || !nvertices || !_vertices || !nindices || !indices) {
|
if (!format || !nvertices || !_vertices || !nindices || !indices) {
|
||||||
rk_printf("rk_create_vertices(): invalid params.");
|
return nullptr;
|
||||||
return RK_INVALID_HANDLE;
|
|
||||||
}
|
}
|
||||||
unsigned format_size = 0;
|
unsigned format_size = 0;
|
||||||
unsigned vertex_size = 0;
|
unsigned vertex_size = 0;
|
||||||
@ -326,14 +293,14 @@ rk_vertices_t rk_create_vertices(
|
|||||||
vertex_size += sizeof(rk_vec3_uint10);
|
vertex_size += sizeof(rk_vec3_uint10);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rk_printf("rk_create_vertices(): invalid vertex format.");
|
rk_printf("rk_create_vertices(): invalid format.");
|
||||||
return RK_INVALID_HANDLE;
|
return nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!format_size) {
|
if (!format_size) {
|
||||||
rk_printf("rk_create_vertices(): empty vertex format.");
|
rk_printf("rk_create_vertices(): empty format.");
|
||||||
return RK_INVALID_HANDLE;
|
return nullptr;
|
||||||
}
|
}
|
||||||
rk_vertices * const vertices = new rk_vertices;
|
rk_vertices * const vertices = new rk_vertices;
|
||||||
vertices->nvertices = nvertices;
|
vertices->nvertices = nvertices;
|
||||||
@ -485,8 +452,8 @@ rk_batch_t rk_create_batch(
|
|||||||
rk_param_format const * params_format) {
|
rk_param_format const * params_format) {
|
||||||
rk_vertices const * const vertices = reinterpret_cast<rk_vertices const *>(_vertices);
|
rk_vertices const * const vertices = reinterpret_cast<rk_vertices const *>(_vertices);
|
||||||
if (!vertices || !max_size || max_size > RK_BATCH_MAX_SIZE) {
|
if (!vertices || !max_size || max_size > RK_BATCH_MAX_SIZE) {
|
||||||
rk_printf("rk_create_batch(): invalid params.");
|
rk_printf("rk_create_batch(): invalid parameters.");
|
||||||
return RK_INVALID_HANDLE;
|
return nullptr;
|
||||||
}
|
}
|
||||||
unsigned vertex_size = 0;
|
unsigned vertex_size = 0;
|
||||||
for (rk_vertex_format const * f = vertices->format; *f; ++f) {
|
for (rk_vertex_format const * f = vertices->format; *f; ++f) {
|
||||||
@ -524,7 +491,7 @@ rk_batch_t rk_create_batch(
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rk_printf("rk_create_batch(): invalid param format.");
|
rk_printf("rk_create_batch(): invalid param format.");
|
||||||
return RK_INVALID_HANDLE;
|
return nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,4 @@ typedef uint64_t rk_ulong;
|
|||||||
|
|
||||||
typedef void * rk_handle_t;
|
typedef void * rk_handle_t;
|
||||||
|
|
||||||
#define RK_INVALID_HANDLE nullptr
|
|
||||||
|
|
||||||
#endif // _RK_ENGINE_TYPES_H
|
#endif // _RK_ENGINE_TYPES_H
|
||||||
|
Loading…
Reference in New Issue
Block a user