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