Browse Source

remove static initializers from structs because of calloc

master
cinnaboot 8 years ago
parent
commit
0c42275b60
  1. 22
      src/hexgame.h
  2. 20
      src/mesh.h
  3. 40
      src/render_group.h
  4. 2
      src/renderer.cpp
  5. 7
      src/renderer.h
  6. 1
      src/util.cpp
  7. 20
      src/util.h

22
src/hexgame.h

@ -13,18 +13,18 @@ struct game_state
hexgrid grid;
// TODO: WiP
uint32 entity_count = 0;
Entity* entities = nullptr;
uint32 entity_count;
Entity* entities;
// camera movement controls
bool is_camera_rotate = false;
bool is_moveforward = false;
bool is_movebackward = false;
bool is_moveup = false;
bool is_movedown = false;
bool is_moveleft = false;
bool is_moveright = false;
bool is_rotateCW = false;
bool is_rotateCCW = false;
bool is_camera_rotate;
bool is_moveforward;
bool is_movebackward;
bool is_moveup;
bool is_movedown;
bool is_moveleft;
bool is_moveright;
bool is_rotateCW;
bool is_rotateCCW;
};

20
src/mesh.h

@ -12,23 +12,23 @@
struct meMeshInfo
{
glm::mat4 model_transform;
uint num_vertices = 0;
glm::vec3* vertices = nullptr;
glm::vec3* normals = nullptr;
glm::vec3* texture_coords = nullptr; // NOTE: using vec3 to stay aligned with other props
uint num_indices = 0;
uint* indices = nullptr;
uint num_vertices;
glm::vec3* vertices;
glm::vec3* normals;
glm::vec3* texture_coords; // NOTE: using vec3 to stay aligned with other props
uint num_indices;
uint* indices;
glm::vec3 diffuse_color;
bool use_texture = false;
bool use_texture;
util_image diffuse_texture;
};
struct meMeshGroup
{
bool use_normals = false;
uint num_meshes = 0;
meMeshInfo** meshes = nullptr;
bool use_normals;
uint num_meshes;
meMeshInfo** meshes;
// animation/bonemapping info here...
};

40
src/render_group.h

@ -12,36 +12,36 @@ struct Entity;
// TODO: can these structs be used as opaque pointers?
struct gl_buffer
{
GLuint buffer_id = 0;
size_t buffer_len = 0; // NOTE: number of elements in buffer
GLfloat* buffer = nullptr;
GLuint buffer_id;
size_t buffer_len; // NOTE: number of elements in buffer
GLfloat* buffer;
};
struct gl_index_buffer
{
GLuint buffer_id = 0;
size_t buffer_len = 0;
uint* buffer = nullptr;
GLuint buffer_id;
size_t buffer_len;
uint* buffer;
};
struct rg_shader_program
{
GLuint program_id = 0;
GLuint program_id;
GLuint model_matrix_id = 0;
GLuint view_matrix_id = 0;
GLuint projection_matrix_id = 0;
GLuint normal_matrix_id = 0;
GLuint model_matrix_id;
GLuint view_matrix_id;
GLuint projection_matrix_id;
GLuint normal_matrix_id;
GLuint vertex_array_id = 0;
GLuint sampler_id = 0;
GLuint num_lights_id = 0;
GLuint vertex_array_id;
GLuint sampler_id;
GLuint num_lights_id;
};
struct render_object
{
bool use_texture = false;
GLuint tex_id = 0;
bool use_texture;
GLuint tex_id;
gl_buffer vertex_buffer;
gl_buffer normal_buffer;
@ -51,11 +51,11 @@ struct render_object
struct render_group
{
uint num_objects = 0;
render_object** render_objects = nullptr;
uint num_objects;
render_object** render_objects;
rg_shader_program shader;
bool use_normals = false;
bool draw_indexed = false;
bool use_normals;
bool draw_indexed;
GLenum draw_mode = GL_TRIANGLES;
};

2
src/renderer.cpp

@ -29,7 +29,7 @@
#define CLEAR_COL_A 1.f
// TODO: add this to json scene properties and render_state
util_RGBA g_clear_col;
util_RGBA g_clear_col = {1.f,1.f,1.f,1.f};
// forward declarations

7
src/renderer.h

@ -34,6 +34,7 @@ struct render_state
SDL_Handles handles;
camera cam;
util_image palette_image;
// TODO: this needs to be initialized outside struct because calloc
GLuint palette_id = UINT_MAX;
render_group* filled_hex_render_group;
@ -42,9 +43,9 @@ struct render_state
// NOTE: entity render groups are stored on the entity object
rg_shader_program default_shader;
rg_point_light* lights = nullptr;
uint num_lights = 0;
uint max_lights = 0;
rg_point_light* lights;
uint num_lights;
uint max_lights;
};
bool renInit(render_state* rs);

1
src/util.cpp

@ -96,6 +96,7 @@ utilLoadImage(const char* base_dir, const char* filename)
std::memcpy(image.file_path, full_path, std::strlen(full_path) + 1);
stbi_set_flip_vertically_on_load(1);
image.pixels = stbi_load(full_path, &image.w, &image.h, &image.num_channels, 0);
image.bits_per_channel = 8;
image.data_len = image.w * image.h * image.num_channels; // NOTE: assumes 8 bits per channel
if (image.pixels == 0) {

20
src/util.h

@ -51,20 +51,20 @@ struct v4i
struct util_RGBA
{
real32 R = 1.f;
real32 G = 1.f;
real32 B = 1.f;
real32 A = 1.f;
real32 R;
real32 G;
real32 B;
real32 A;
};
struct util_image
{
int32 w = 0;
int32 h = 0;
int32 bits_per_channel = 8;
int32 num_channels = 4;
uint data_len = 0;
uint8* pixels = nullptr;
int32 w;
int32 h;
int32 bits_per_channel;
int32 num_channels;
uint data_len;
uint8* pixels;
char file_path[256];
};

Loading…
Cancel
Save