Cleanup sized int usage.
This commit is contained in:
parent
c1b9c0d17e
commit
eaff99a5b6
@ -22,12 +22,12 @@
|
|||||||
extern PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC rk_DrawElementsInstancedBaseInstance;
|
extern PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC rk_DrawElementsInstancedBaseInstance;
|
||||||
extern PFNGLMULTIDRAWELEMENTSINDIRECTPROC rk_MultiDrawElementsIndirect;
|
extern PFNGLMULTIDRAWELEMENTSINDIRECTPROC rk_MultiDrawElementsIndirect;
|
||||||
|
|
||||||
RK_EXPORT rk_window_t rk_create_context(
|
extern rk_window_t rk_create_context(
|
||||||
char const * name,
|
char const * name,
|
||||||
rk_uint width,
|
unsigned width,
|
||||||
rk_uint height);
|
unsigned height);
|
||||||
|
|
||||||
RK_EXPORT void rk_swap_buffers();
|
extern void rk_swap_buffers();
|
||||||
RK_EXPORT void rk_destroy_context();
|
extern void rk_destroy_context();
|
||||||
|
|
||||||
#endif // _RK_ENGINE_RENDER_CONTEXT_H
|
#endif // _RK_ENGINE_RENDER_CONTEXT_H
|
||||||
|
@ -91,8 +91,8 @@ static int rk_error_handler(
|
|||||||
|
|
||||||
rk_window_t rk_create_context(
|
rk_window_t rk_create_context(
|
||||||
char const * name,
|
char const * name,
|
||||||
rk_uint width,
|
unsigned width,
|
||||||
rk_uint height) {
|
unsigned height) {
|
||||||
rk_display = XOpenDisplay(nullptr);
|
rk_display = XOpenDisplay(nullptr);
|
||||||
if (!rk_display) {
|
if (!rk_display) {
|
||||||
rk_printf("Failed to open X display.");
|
rk_printf("Failed to open X display.");
|
||||||
@ -162,7 +162,7 @@ rk_window_t rk_create_context(
|
|||||||
char const * const glx_exts = glXQueryExtensionsString(rk_display, DefaultScreen(rk_display));
|
char const * const glx_exts = glXQueryExtensionsString(rk_display, DefaultScreen(rk_display));
|
||||||
glXCreateContextAttribsARBProc const glXCreateContextAttribsARB =
|
glXCreateContextAttribsARBProc const glXCreateContextAttribsARB =
|
||||||
reinterpret_cast<glXCreateContextAttribsARBProc>(
|
reinterpret_cast<glXCreateContextAttribsARBProc>(
|
||||||
glXGetProcAddressARB(reinterpret_cast<const GLubyte *>("glXCreateContextAttribsARB")));
|
glXGetProcAddressARB(reinterpret_cast<GLubyte const *>("glXCreateContextAttribsARB")));
|
||||||
|
|
||||||
rk_error_occured = false;
|
rk_error_occured = false;
|
||||||
int (*oldHandler)(Display *, XErrorEvent *) = XSetErrorHandler(&rk_error_handler);
|
int (*oldHandler)(Display *, XErrorEvent *) = XSetErrorHandler(&rk_error_handler);
|
||||||
@ -190,13 +190,13 @@ rk_window_t rk_create_context(
|
|||||||
if (rk_extension_supported(gl_exts, "GL_EXT_base_instance")) {
|
if (rk_extension_supported(gl_exts, "GL_EXT_base_instance")) {
|
||||||
rk_DrawElementsInstancedBaseInstance =
|
rk_DrawElementsInstancedBaseInstance =
|
||||||
reinterpret_cast<PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC>(
|
reinterpret_cast<PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC>(
|
||||||
glXGetProcAddressARB(reinterpret_cast<const GLubyte *>("DrawElementsInstancedBaseInstance")));
|
glXGetProcAddressARB(reinterpret_cast<GLubyte const *>("DrawElementsInstancedBaseInstance")));
|
||||||
if (rk_DrawElementsInstancedBaseInstance) {
|
if (rk_DrawElementsInstancedBaseInstance) {
|
||||||
rk_printf("Using extension GL_EXT_base_instance::DrawElementsInstancedBaseInstance.");
|
rk_printf("Using extension GL_EXT_base_instance::DrawElementsInstancedBaseInstance.");
|
||||||
if (rk_extension_supported(gl_exts, "GL_EXT_multi_draw_indirect")) {
|
if (rk_extension_supported(gl_exts, "GL_EXT_multi_draw_indirect")) {
|
||||||
rk_MultiDrawElementsIndirect =
|
rk_MultiDrawElementsIndirect =
|
||||||
reinterpret_cast<PFNGLMULTIDRAWELEMENTSINDIRECTPROC>(
|
reinterpret_cast<PFNGLMULTIDRAWELEMENTSINDIRECTPROC>(
|
||||||
glXGetProcAddressARB(reinterpret_cast<const GLubyte *>("MultiDrawElementsIndirectEXT")));
|
glXGetProcAddressARB(reinterpret_cast<GLubyte const *>("MultiDrawElementsIndirectEXT")));
|
||||||
if (rk_MultiDrawElementsIndirect) {
|
if (rk_MultiDrawElementsIndirect) {
|
||||||
rk_printf("Using extension GL_EXT_multi_draw_indirect::MultiDrawElementsIndirectEXT.");
|
rk_printf("Using extension GL_EXT_multi_draw_indirect::MultiDrawElementsIndirectEXT.");
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ rk_window_t rk_initialize(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void rk_print_shader_infolog(GLuint shader) {
|
static void rk_print_shader_infolog(GLuint shader) {
|
||||||
int length;
|
GLsizei length;
|
||||||
char infolog[1024];
|
char infolog[1024];
|
||||||
glGetShaderInfoLog(shader, sizeof(infolog), &length, infolog);
|
glGetShaderInfoLog(shader, sizeof(infolog), &length, infolog);
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
@ -75,7 +75,7 @@ static void rk_print_shader_infolog(GLuint shader) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void rk_print_program_infolog(GLuint program) {
|
static void rk_print_program_infolog(GLuint program) {
|
||||||
int length;
|
GLsizei length;
|
||||||
char infolog[1024];
|
char infolog[1024];
|
||||||
glGetProgramInfoLog(program, sizeof(infolog), &length, infolog);
|
glGetProgramInfoLog(program, sizeof(infolog), &length, infolog);
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
@ -258,7 +258,7 @@ rk_vertices_t rk_create_vertices(
|
|||||||
if (!format || !nvertices || !_vertices || !nindices || !indices) {
|
if (!format || !nvertices || !_vertices || !nindices || !indices) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
rk_uint vertex_size = 0;
|
unsigned vertex_size = 0;
|
||||||
for (rk_vertex_format const * f = format; *f; ++f) {
|
for (rk_vertex_format const * f = format; *f; ++f) {
|
||||||
switch (*f & RK_VERTEX_FORMAT_MASK) {
|
switch (*f & RK_VERTEX_FORMAT_MASK) {
|
||||||
case RK_VERTEX_FORMAT_VEC3_FLOAT:
|
case RK_VERTEX_FORMAT_VEC3_FLOAT:
|
||||||
@ -289,7 +289,7 @@ rk_vertices_t rk_create_vertices(
|
|||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
vertices->vertex_size = vertex_size;
|
vertices->vertex_size = vertex_size;
|
||||||
vertices->layout = 0;
|
vertices->layout = 0;
|
||||||
rk_uint offset = 0;
|
unsigned offset = 0;
|
||||||
for (rk_vertex_format const * f = format; *f; ++f, ++vertices->layout) {
|
for (rk_vertex_format const * f = format; *f; ++f, ++vertices->layout) {
|
||||||
glEnableVertexAttribArray(vertices->layout);
|
glEnableVertexAttribArray(vertices->layout);
|
||||||
GLboolean const normalize = (*f & RK_VERTEX_FORMAT_NORMALIZE) != 0;
|
GLboolean const normalize = (*f & RK_VERTEX_FORMAT_NORMALIZE) != 0;
|
||||||
@ -359,9 +359,9 @@ rk_batch_t rk_create_batch(
|
|||||||
rk_printf("rk_create_batch(): invalid parameters.");
|
rk_printf("rk_create_batch(): invalid parameters.");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
rk_uint nparams = 0;
|
unsigned nparams = 0;
|
||||||
rk_uint params_size = 0;
|
unsigned params_size = 0;
|
||||||
rk_uint packed_size = 0;
|
unsigned packed_size = 0;
|
||||||
for (rk_param_format const * f = params_format; *f; ++f, ++nparams) {
|
for (rk_param_format const * f = params_format; *f; ++f, ++nparams) {
|
||||||
switch (*f & RK_PARAM_FORMAT_MASK) {
|
switch (*f & RK_PARAM_FORMAT_MASK) {
|
||||||
case RK_PARAM_FORMAT_VEC3_FLOAT:
|
case RK_PARAM_FORMAT_VEC3_FLOAT:
|
||||||
@ -393,9 +393,9 @@ rk_batch_t rk_create_batch(
|
|||||||
batch->packers = new rk_packer[nparams];
|
batch->packers = new rk_packer[nparams];
|
||||||
batch->params = new rk_ubyte[max_size * packed_size];
|
batch->params = new rk_ubyte[max_size * packed_size];
|
||||||
glGenBuffers(1, &batch->params_buffer);
|
glGenBuffers(1, &batch->params_buffer);
|
||||||
rk_uint layout = vertices->layout;
|
unsigned layout = vertices->layout;
|
||||||
rk_packer * packer = batch->packers;
|
rk_packer * packer = batch->packers;
|
||||||
rk_uint offset = 0;
|
unsigned offset = 0;
|
||||||
glBindVertexArray(vertices->array);
|
glBindVertexArray(vertices->array);
|
||||||
for (rk_param_format const * f = params_format; *f; ++f, ++layout, ++packer) {
|
for (rk_param_format const * f = params_format; *f; ++f, ++layout, ++packer) {
|
||||||
GLboolean const normalize = (*f & RK_PARAM_FORMAT_NORMALIZE) != 0;
|
GLboolean const normalize = (*f & RK_PARAM_FORMAT_NORMALIZE) != 0;
|
||||||
@ -531,22 +531,22 @@ void rk_select_vertices(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static rk_uint rk_batch_filter(
|
static unsigned rk_batch_filter(
|
||||||
rk_batch & batch,
|
rk_batch & batch,
|
||||||
rk_uint const size,
|
unsigned const size,
|
||||||
rk_instance_flags const * flags) {
|
rk_instance_flags const * flags) {
|
||||||
rk_ushort * indices = batch.indices;
|
rk_ushort * indices = batch.indices;
|
||||||
for (rk_ushort index = 0; index < size; ++index, ++flags) {
|
for (unsigned index = 0; index < size; ++index, ++flags) {
|
||||||
if ((*flags & RK_INSTANCE_FLAGS_SPAWNED_VISIBLE) == RK_INSTANCE_FLAGS_SPAWNED_VISIBLE) {
|
if ((*flags & RK_INSTANCE_FLAGS_SPAWNED_VISIBLE) == RK_INSTANCE_FLAGS_SPAWNED_VISIBLE) {
|
||||||
*indices++ = index;
|
*indices++ = static_cast<rk_ushort>(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return indices - batch.indices;
|
return indices - batch.indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rk_uint rk_batch_build_commands(
|
static unsigned rk_batch_build_commands(
|
||||||
rk_batch & batch,
|
rk_batch & batch,
|
||||||
rk_uint const ninstances,
|
unsigned const ninstances,
|
||||||
rk_mesh const * const meshes) {
|
rk_mesh const * const meshes) {
|
||||||
rk_command * commands = batch.commands;
|
rk_command * commands = batch.commands;
|
||||||
rk_ushort * base = batch.indices;
|
rk_ushort * base = batch.indices;
|
||||||
@ -556,10 +556,10 @@ static rk_uint rk_batch_build_commands(
|
|||||||
for ( ; first < last && meshes[*first].packed == mesh.packed; ++first) {
|
for ( ; first < last && meshes[*first].packed == mesh.packed; ++first) {
|
||||||
}
|
}
|
||||||
for (rk_ushort * second = first; second < last; ++second) {
|
for (rk_ushort * second = first; second < last; ++second) {
|
||||||
rk_ushort const index = *second;
|
unsigned const index = *second;
|
||||||
if (meshes[index].packed == mesh.packed) {
|
if (meshes[index].packed == mesh.packed) {
|
||||||
*second = *first;
|
*second = *first;
|
||||||
*first++ = index;
|
*first++ = static_cast<rk_ushort>(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
commands->nvertices = static_cast<GLuint>(mesh.ntriangles) * 3;
|
commands->nvertices = static_cast<GLuint>(mesh.ntriangles) * 3;
|
||||||
@ -573,7 +573,7 @@ static rk_uint rk_batch_build_commands(
|
|||||||
|
|
||||||
static void rk_batch_pack(
|
static void rk_batch_pack(
|
||||||
rk_batch & batch,
|
rk_batch & batch,
|
||||||
rk_uint const ninstances,
|
unsigned const ninstances,
|
||||||
rk_ubyte const * const params) {
|
rk_ubyte const * const params) {
|
||||||
rk_pack_dst dst(batch.params);
|
rk_pack_dst dst(batch.params);
|
||||||
rk_ushort const * const last_index = batch.indices + ninstances;
|
rk_ushort const * const last_index = batch.indices + ninstances;
|
||||||
@ -598,11 +598,11 @@ void rk_draw_batch(
|
|||||||
if (!size || size > batch.size || !flags || !meshes || !rk_current_shader || !rk_current_vertices) {
|
if (!size || size > batch.size || !flags || !meshes || !rk_current_shader || !rk_current_vertices) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rk_uint const ninstances = rk_batch_filter(batch, size, flags);
|
unsigned const ninstances = rk_batch_filter(batch, size, flags);
|
||||||
if (!ninstances) {
|
if (!ninstances) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rk_uint const ncommands = rk_batch_build_commands(batch, ninstances, meshes);
|
unsigned const ncommands = rk_batch_build_commands(batch, ninstances, meshes);
|
||||||
if (rk_MultiDrawElementsIndirect) {
|
if (rk_MultiDrawElementsIndirect) {
|
||||||
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, batch.commands_buffer);
|
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, batch.commands_buffer);
|
||||||
glBufferData(GL_DRAW_INDIRECT_BUFFER, ncommands * sizeof(rk_command), batch.commands, GL_STREAM_DRAW);
|
glBufferData(GL_DRAW_INDIRECT_BUFFER, ncommands * sizeof(rk_command), batch.commands, GL_STREAM_DRAW);
|
||||||
@ -627,7 +627,7 @@ void rk_draw_batch(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rk_uint params_offset = 0;
|
unsigned params_offset = 0;
|
||||||
rk_command const * const last_command = batch.commands + ncommands;
|
rk_command const * const last_command = batch.commands + ncommands;
|
||||||
for (rk_command const * command = batch.commands; command < last_command; ++command) {
|
for (rk_command const * command = batch.commands; command < last_command; ++command) {
|
||||||
if (batch.nparams) {
|
if (batch.nparams) {
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include <GLES3/gl3ext.h>
|
#include <GLES3/gl3ext.h>
|
||||||
#include <GLES3/gl3platform.h>
|
#include <GLES3/gl3platform.h>
|
||||||
|
|
||||||
enum : rk_uint {
|
enum : GLuint {
|
||||||
RK_VERTICES_BINDING = 0,
|
RK_VERTICES_BINDING = 0,
|
||||||
RK_PARAMS_BINDING = 1
|
RK_PARAMS_BINDING = 1
|
||||||
};
|
};
|
||||||
@ -34,19 +34,19 @@ struct rk_shader {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct rk_texture {
|
struct rk_texture {
|
||||||
rk_uint nlevels;
|
unsigned nlevels;
|
||||||
GLuint texture;
|
GLuint texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct rk_triangles {
|
struct rk_triangles {
|
||||||
rk_uint size;
|
unsigned size;
|
||||||
GLuint array;
|
GLuint array;
|
||||||
GLuint vertices;
|
GLuint vertices;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct rk_vertices {
|
struct rk_vertices {
|
||||||
rk_uint vertex_size;
|
unsigned vertex_size;
|
||||||
rk_uint layout;
|
unsigned layout;
|
||||||
GLuint array;
|
GLuint array;
|
||||||
GLuint vertices;
|
GLuint vertices;
|
||||||
GLuint indices;
|
GLuint indices;
|
||||||
@ -81,8 +81,8 @@ typedef void (*rk_packer_fn)(rk_pack_dst, rk_pack_src);
|
|||||||
|
|
||||||
struct rk_packer {
|
struct rk_packer {
|
||||||
rk_packer_fn pack;
|
rk_packer_fn pack;
|
||||||
rk_uint dst_incr;
|
unsigned dst_incr;
|
||||||
rk_uint src_incr;
|
unsigned src_incr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct rk_command {
|
struct rk_command {
|
||||||
@ -94,10 +94,10 @@ struct rk_command {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct rk_batch {
|
struct rk_batch {
|
||||||
rk_uint size;
|
unsigned size;
|
||||||
rk_uint nparams;
|
unsigned nparams;
|
||||||
rk_uint params_size;
|
unsigned params_size;
|
||||||
rk_uint packed_size;
|
unsigned packed_size;
|
||||||
rk_ushort * indices;
|
rk_ushort * indices;
|
||||||
rk_command * commands;
|
rk_command * commands;
|
||||||
rk_packer * packers;
|
rk_packer * packers;
|
||||||
|
Loading…
Reference in New Issue
Block a user