~jb55/polyadvent

a288c4b3a2ad849b34b65dd6a5ce16fce599cfc8 — William Casarin 1 year, 7 months ago 79bca44
initialize gpu programs

otherwise we get memory corruption
5 files changed, 17 insertions(+), 2 deletions(-)

M src/game.c
M src/input.c
M src/shader.c
M src/shader.h
M test/test_resource.c
M src/game.c => src/game.c +7 -0
@@ 90,6 90,7 @@ void init_misc(struct game *game, int width, int height) {

    struct node *root = new_node(&res->root_id);
    struct node *sun_camera = new_node(&res->sun_camera_id);

    struct terrain *terrain = &game->terrain;
    struct entity *player;



@@ 226,7 227,13 @@ void init_controller(struct input *input) {
    }
}

void init_resources(struct resources *res)
{
    memset(res, 0, sizeof(*res));
}

void game_init(struct game *game, int width, int height) {
    init_resources(&game->test_resources);
    init_sdl(&game->window, width, height);
    init_gl(&game->test_resources, width, height);
    init_entity_system();

M src/input.c => src/input.c +1 -0
@@ 140,6 140,7 @@ void init_input(struct input *input) {
  memset(input->key_edge_states, 0, sizeof(input->key_edge_states));
  memset(input->button_edge_states, 0, sizeof(input->button_edge_states));
  memset(input->axis, 0, sizeof(input->axis));
  memset(input->mbuttons, 0, sizeof(input->mbuttons));
  input->axis_min_input = 1024;
  input->mx = 0;
  input->my = 0;

M src/shader.c => src/shader.c +7 -0
@@ 145,6 145,11 @@ int make_shader(GLenum type, const char *filename, struct shader *shader) {

#define N_SHADERS 3

void init_gpu_program(struct gpu_program *program) {
    program->n_shaders = 0;
    memset(program->shaders, 0, sizeof(program->shaders));
}

#ifdef DEBUG
int reload_program(struct gpu_program *program) {
	int ok;


@@ 154,6 159,8 @@ int reload_program(struct gpu_program *program) {
    struct shader new_shaders[n_shaders];
    struct shader *new_shaders_p[n_shaders];

    init_gpu_program(&new_program);

    int changes[n_shaders];

    for (int i = 0; i < n_shaders; i++) {

M src/shader.h => src/shader.h +1 -0
@@ 32,6 32,7 @@ struct gpu_program {
int reload_program(struct gpu_program *program);
int make_shader(GLenum type, const char *filename, struct shader *shader);

void init_gpu_program(struct gpu_program *program);
int make_program_from_shaders(struct shader **shaders,
                              int n_shaders,
                              struct gpu_program *program);

M test/test_resource.c => test/test_resource.c +1 -2
@@ 74,8 74,7 @@ static void test_compact()
static void test_int_resource_manager()
{
    printf("test_int_resource_manager\n");
    struct resource_manager r
;
    struct resource_manager r;
    struct resource_id id, first_id;
    int *p;
    // 2 item case