Fixed bug with meshes registering with uninitialized materials and not rendering

dev
Shariq Shah 6 years ago
parent 6629078c3e
commit 239d44ac6e
  1. 11
      src/game/editor.c
  2. 1
      src/game/editor.h
  3. 3
      src/game/entity.h
  4. 2
      src/game/game.c
  5. 2
      src/game/gl_load.c
  6. 3
      src/game/material.c
  7. 14
      src/game/renderer.c
  8. 1
      src/game/scene.c
  9. 12
      src/game/scene.h
  10. 5
      todo.txt

@ -156,9 +156,12 @@ void editor_init(struct Editor* editor)
event_manager_subscribe(event_manager, EVT_MOUSEMOTION, &editor_on_mousemotion); event_manager_subscribe(event_manager, EVT_MOUSEMOTION, &editor_on_mousemotion);
event_manager_subscribe(event_manager, EVT_KEY_PRESSED, &editor_on_key_press); event_manager_subscribe(event_manager, EVT_KEY_PRESSED, &editor_on_key_press);
event_manager_subscribe(event_manager, EVT_KEY_RELEASED, &editor_on_key_release); event_manager_subscribe(event_manager, EVT_KEY_RELEASED, &editor_on_key_release);
}
void editor_init_entities(struct Editor* editor)
{
editor->cursor_entity = scene_static_mesh_create(game_state_get()->scene, "EDITOR_SELECTED_ENTITY_WIREFRAME", NULL, "sphere.symbres", MAT_UNSHADED); editor->cursor_entity = scene_static_mesh_create(game_state_get()->scene, "EDITOR_SELECTED_ENTITY_WIREFRAME", NULL, "sphere.symbres", MAT_UNSHADED);
editor->cursor_entity->base.flags |= EF_TRANSIENT | EF_HIDE_IN_EDITOR_SCENE_HIERARCHY; editor->cursor_entity->base.flags |= EF_TRANSIENT | EF_SKIP_RENDER | EF_HIDE_IN_EDITOR_SCENE_HIERARCHY;
} }
void editor_init_camera(struct Editor* editor, struct Hashmap* cvars) void editor_init_camera(struct Editor* editor, struct Hashmap* cvars)
@ -1897,7 +1900,6 @@ void editor_window_property_inspector(struct nk_context* context, struct Editor*
nk_label(context, "Diffuse Color", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE); nk_label(context, "Diffuse Color", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE);
editor_widget_color_combov4(context, &mesh->model.material_params[MMP_DIFFUSE_COL].val_vec4, 200, 300); editor_widget_color_combov4(context, &mesh->model.material_params[MMP_DIFFUSE_COL].val_vec4, 200, 300);
nk_layout_row_dynamic(context, row_height * 4, 2); nk_layout_row_dynamic(context, row_height * 4, 2);
const char* diffuse_texture_name = texture_get_name(mesh->model.material_params[MMP_DIFFUSE_TEX].val_int); const char* diffuse_texture_name = texture_get_name(mesh->model.material_params[MMP_DIFFUSE_TEX].val_int);
nk_label(context, "Diffuse Texture", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE); nk_label(context, "Diffuse Texture", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE);
@ -1935,11 +1937,10 @@ void editor_window_property_inspector(struct nk_context* context, struct Editor*
nk_contextual_end(context); nk_contextual_end(context);
} }
nk_layout_row_dynamic(context, row_height, 1);
mesh->model.material_params[MMP_DIFFUSE].val_float = nk_propertyf(context, "Diffuse", 0.f, mesh->model.material_params[MMP_DIFFUSE].val_float, 10.f, 0.5f, 0.1f);
if(mesh->model.material->type == MAT_BLINN) if(mesh->model.material->type == MAT_BLINN)
{ {
nk_layout_row_dynamic(context, row_height, 1);
mesh->model.material_params[MMP_DIFFUSE].val_float = nk_propertyf(context, "Diffuse", 0.f, mesh->model.material_params[MMP_DIFFUSE].val_float, 10.f, 0.5f, 0.1f);
nk_layout_row_dynamic(context, row_height, 1); nk_layout_row_dynamic(context, row_height, 1);
mesh->model.material_params[MMP_SPECULAR].val_float = nk_propertyf(context, "Specular", 0.f, mesh->model.material_params[MMP_SPECULAR].val_float, 10.f, 0.5f, 0.1f); mesh->model.material_params[MMP_SPECULAR].val_float = nk_propertyf(context, "Specular", 0.f, mesh->model.material_params[MMP_SPECULAR].val_float, 10.f, 0.5f, 0.1f);
nk_layout_row_dynamic(context, row_height, 1); nk_layout_row_dynamic(context, row_height, 1);

@ -57,6 +57,7 @@ struct Editor
void editor_init(struct Editor* editor_state); void editor_init(struct Editor* editor_state);
void editor_init_camera(struct Editor* editor_state, struct Hashmap* cvars); void editor_init_camera(struct Editor* editor_state, struct Hashmap* cvars);
void editor_init_entities(struct Editor* editor);
void editor_render(struct Editor* editor_state, struct Camera* active_camera); void editor_render(struct Editor* editor_state, struct Camera* active_camera);
void editor_update(struct Editor* editor_state, float dt); void editor_update(struct Editor* editor_state, float dt);
void editor_cleanup(struct Editor* editor_state); void editor_cleanup(struct Editor* editor_state);

@ -52,7 +52,8 @@ enum Entity_Flags
EF_SELECTED_IN_EDITOR = 1 << 1, EF_SELECTED_IN_EDITOR = 1 << 1,
EF_MARKED_FOR_DELETION = 1 << 2, EF_MARKED_FOR_DELETION = 1 << 2,
EF_TRANSIENT = 1 << 3, EF_TRANSIENT = 1 << 3,
EF_HIDE_IN_EDITOR_SCENE_HIERARCHY = 1 << 4 EF_HIDE_IN_EDITOR_SCENE_HIERARCHY = 1 << 4,
EF_SKIP_RENDER = 1 << 5
}; };
struct Transform struct Transform

@ -108,9 +108,9 @@ bool game_init(struct Window* window, struct Hashmap* cvars)
physics_body_set_collision_callback(entity_rigidbody_on_collision); physics_body_set_collision_callback(entity_rigidbody_on_collision);
sound_init(game_state->sound); sound_init(game_state->sound);
renderer_init(game_state->renderer);
scene_init(game_state->scene); scene_init(game_state->scene);
editor_init(game_state->editor); editor_init(game_state->editor);
renderer_init(game_state->renderer);
} }
/* Debug scene setup */ /* Debug scene setup */

@ -57,7 +57,7 @@ void gl_check_error(const char * expression, unsigned int line, const char * fil
{ {
case GL_INVALID_OPERATION: error_string = "Invalid Operation"; break; case GL_INVALID_OPERATION: error_string = "Invalid Operation"; break;
case GL_NO_ERROR: error_string = "No Error"; break; case GL_NO_ERROR: error_string = "No Error"; break;
case GL_INVALID_ENUM: error_string = "Invalid ENUM"; break; case GL_INVALID_ENUM: error_string = "Invalid Enum"; break;
case GL_INVALID_VALUE: error_string = "Invalid Value"; break; case GL_INVALID_VALUE: error_string = "Invalid Value"; break;
case GL_INVALID_FRAMEBUFFER_OPERATION: error_string = "Invalid FrameBuffer Operation"; break; case GL_INVALID_FRAMEBUFFER_OPERATION: error_string = "Invalid FrameBuffer Operation"; break;
case GL_OUT_OF_MEMORY: error_string = "Out of Memory"; break; case GL_OUT_OF_MEMORY: error_string = "Out of Memory"; break;

@ -137,6 +137,9 @@ bool material_register_static_mesh(struct Material* material, struct Static_Mesh
{ {
material->registered_static_meshes[i] = mesh; material->registered_static_meshes[i] = mesh;
for(int j = 0; j < MMP_MAX; j++)
variant_init_empty(&mesh->model.material_params[j]);
// Set default values for instance parameters // Set default values for instance parameters
switch(material->type) switch(material->type)
{ {

@ -122,9 +122,9 @@ void renderer_init(struct Renderer* renderer)
renderer->composition_shader = shader_create("fbo.vert", "fbo.frag", NULL); renderer->composition_shader = shader_create("fbo.vert", "fbo.frag", NULL);
renderer->debug_shader = shader_create("debug.vert", "debug.frag", NULL); renderer->debug_shader = shader_create("debug.vert", "debug.frag", NULL);
renderer->num_culled_slot = editor_debugvar_slot_create("Culled Geom", VT_INT); // renderer->num_culled_slot = editor_debugvar_slot_create("Culled Geom", VT_INT);
renderer->num_rendered_slot = editor_debugvar_slot_create("Rendered Geom", VT_INT); // renderer->num_rendered_slot = editor_debugvar_slot_create("Rendered Geom", VT_INT);
renderer->num_indices_slot = editor_debugvar_slot_create("Total Indices", VT_INT); // renderer->num_indices_slot = editor_debugvar_slot_create("Total Indices", VT_INT);
renderer->sprite_batch = malloc(sizeof(*renderer->sprite_batch)); renderer->sprite_batch = malloc(sizeof(*renderer->sprite_batch));
if(!renderer->sprite_batch) if(!renderer->sprite_batch)
@ -248,7 +248,7 @@ void renderer_render(struct Renderer* renderer, struct Scene* scene)
for(int j = 0; j < MAX_MATERIAL_REGISTERED_STATIC_MESHES; j++) for(int j = 0; j < MAX_MATERIAL_REGISTERED_STATIC_MESHES; j++)
{ {
if(!material->registered_static_meshes[j]) continue; if(!material->registered_static_meshes[j] || (material->registered_static_meshes[j]->base.flags & EF_SKIP_RENDER)) continue;
/* for each registered model, set up uniforms and render */ /* for each registered model, set up uniforms and render */
struct Static_Mesh* mesh = material->registered_static_meshes[j]; struct Static_Mesh* mesh = material->registered_static_meshes[j];
@ -311,9 +311,9 @@ void renderer_render(struct Renderer* renderer, struct Scene* scene)
} }
shader_unbind(); shader_unbind();
} }
editor_debugvar_slot_set_int(renderer->num_rendered_slot, renderer->num_rendered); //editor_debugvar_slot_set_int(renderer->num_rendered_slot, renderer->num_rendered);
editor_debugvar_slot_set_int(renderer->num_culled_slot, renderer->num_culled); //editor_debugvar_slot_set_int(renderer->num_culled_slot, renderer->num_culled);
editor_debugvar_slot_set_int(renderer->num_indices_slot, renderer->num_indices); //editor_debugvar_slot_set_int(renderer->num_indices_slot, renderer->num_indices);
renderer->num_culled = renderer->num_rendered = renderer->num_indices = 0; renderer->num_culled = renderer->num_rendered = renderer->num_indices = 0;
} }

@ -71,6 +71,7 @@ void scene_init(struct Scene* scene)
player_init(&scene->player, scene); player_init(&scene->player, scene);
editor_init_camera(game_state->editor, game_state->cvars); editor_init_camera(game_state->editor, game_state->cvars);
editor_init_entities(game_state->editor);
scene->active_camera_index = game_state_get()->game_mode == GAME_MODE_GAME ? CAM_GAME : CAM_EDITOR; scene->active_camera_index = game_state_get()->game_mode == GAME_MODE_GAME ? CAM_GAME : CAM_EDITOR;
} }

@ -4,12 +4,12 @@
#include "entity.h" #include "entity.h"
#include "renderer.h" #include "renderer.h"
#define MAX_ENTITIES 1024 #define MAX_ENTITIES 1024
#define MAX_LIGHTS 30 #define MAX_LIGHTS 30
#define MAX_CAMERAS 2 #define MAX_CAMERAS 2
#define MAX_STATIC_MESHES 1024 #define MAX_STATIC_MESHES 1024
#define MAX_SOUND_SOURCES 128 #define MAX_SOUND_SOURCES 128
#define MAX_ENTITY_ARCHETYPES 32 #define MAX_ENTITY_ARCHETYPES 32
struct Ray; struct Ray;
struct Raycast_Result; struct Raycast_Result;

@ -1,4 +1,6 @@
Todo: Todo:
- Save default entity archetype to be loaded when there is not other archetype or in case of an error as fallback
- Bring back debug variable display in editor and allow showing colours, textures etc
- Implment/Test reading/writing scene that has a mixture of default entites and entity archetypes - Implment/Test reading/writing scene that has a mixture of default entites and entity archetypes
- Serialize player, camera properties to file - Serialize player, camera properties to file
- Implement behaviour that avoids writing normal entities that do not have children or parent to file to avoid inconsistencies when loading them - Implement behaviour that avoids writing normal entities that do not have children or parent to file to avoid inconsistencies when loading them
@ -107,6 +109,7 @@ Improvements:
- Improve culling - Improve culling
- Allow scaling on all axes at once - Allow scaling on all axes at once
- Improve grid/immediate mode drawing by switching to glDrawElements instead of glDrawArrays. - Improve grid/immediate mode drawing by switching to glDrawElements instead of glDrawArrays.
- Investigate why transparency is not working for materials
Bugs: Bugs:
- Better handling of wav format checking at load time - Better handling of wav format checking at load time
@ -333,3 +336,5 @@ Done:
* Console command to read/write scene to/from file * Console command to read/write scene to/from file
* Implemented flags that specify whether an entity should be written to file or not for example to avoid writing cameras and player to file * Implemented flags that specify whether an entity should be written to file or not for example to avoid writing cameras and player to file
* In editor, only show entities with specific flags * In editor, only show entities with specific flags
* Fixed bugs with meshes being registered to uninitialized materials and not rendering
* Added EF_SKIP_RENDER flag to allow entites to skip rendering
Loading…
Cancel
Save