Browse Source

breaking everything to reorganize render_groups

testing
cinnaboot 6 years ago
parent
commit
3fa874c981
  1. 46
      examples/assimp_loading/animation_testing.cpp
  2. 17
      include/animation.h
  3. 39
      include/entity.h
  4. 6
      include/mesh.h
  5. 2
      include/render_group.h
  6. 4
      include/renderer.h
  7. 24
      src/entity.cpp
  8. 39
      src/renderer.cpp

46
examples/assimp_loading/animation_testing.cpp

@ -6,6 +6,7 @@
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include "util.h"
#include "dumbLog.h"
#include "mesh.h"
@ -18,10 +19,34 @@ debugParseNode(aiNode* node, aiMatrix4x4 xform, uint depth=0)
snprintf(tabs, 256, "%*s", depth * 4, " ");
std::cout << tabs << node->mName.C_Str() << ", has meshes: " << (node->mNumMeshes > 0) << "\n";
if (node->mNumMeshes > 0) {
for (uint i = 0; i < node->mNumMeshes; i++)
std::cout << tabs << " mesh index: " << node->mMeshes[i] << "\n";
}
for (uint i = 0; i < node->mNumChildren; i++)
debugParseNode(node->mChildren[i], xform, depth);
}
void
debugParseAnimation(aiAnimation* anim)
{
std::cout << "Animation, ticks/s: " << anim->mTicksPerSecond
<< ", duration: " << anim->mDuration
<< ", channels: " << anim->mNumChannels
<< "\n";
for (uint i = 0; i < anim->mNumChannels; i++) {
aiNodeAnim* chan = anim->mChannels[i];
std::cout << " channel " << i
<< ", node name: " << chan->mNodeName.C_Str()
<< ", mNumPositionKeys: " << chan->mNumPositionKeys
<< ", mNumRotationKeys: " << chan->mNumRotationKeys
<< ", mNumScalingKeys: " << chan->mNumScalingKeys
<< "\n";
}
}
void
logDebugAnimationInfo(const char* model_name)
{
@ -33,26 +58,15 @@ logDebugAnimationInfo(const char* model_name)
}
std::cout << "\n\n--------------------------------------\n";
std::cout << "Nodes:\n";
aiMatrix4x4 identity_mat;
debugParseNode(scene->mRootNode, identity_mat);
std::cout << "--------------------------------------\n";
if (scene->HasAnimations()) {
aiAnimation* anim = scene->mAnimations[0];
std::cout << "Animation, ticks/s: " << anim->mTicksPerSecond
<< ", duration: " << anim->mDuration
<< ", channels: " << anim->mNumChannels
<< "\n";
std::cout << "--------------------------------------\n";
std::cout << "Animations:\n";
for (uint i = 0; i < anim->mNumChannels; i++) {
aiNodeAnim* chan = anim->mChannels[i];
std::cout << "channel, node name: " << chan->mNodeName.C_Str()
<< ", mNumPositionKeys: " << chan->mNumPositionKeys
<< ", mNumRotationKeys: " << chan->mNumRotationKeys
<< ", mNumScalingKeys: " << chan->mNumScalingKeys
<< "\n";
}
}
if (scene->HasAnimations())
debugParseAnimation(scene->mAnimations[0]);
std::cout << "--------------------------------------\n\n\n";
}

17
include/animation.h

@ -0,0 +1,17 @@
#pragma once
#include <glm/glm.hpp>
#include "util.h"
#include "render_group.h"
struct node_animation
{
render_object* ro;
glm::mat4* xform_array;
uint key_count;
uint cur_frame;
};

39
include/entity.h

@ -7,33 +7,50 @@
#include "mesh.h"
#include "render_group.h"
struct Entity
// NOTE: an entity is the basic unit of the high level renderer interface
struct entity
{
// NOTE: glm::mat4 combines translation, scale, and rotation in a 4x4
// transform matrix. This is the equivalent of the 'model' matrix in
// the model, view, projection matrix composition
glm::mat4 world_transform;
glm::vec3 scale;
glm::vec3 translation;
glm::vec4 rotation;
// TODO: should be a pointer into a global array of mesh_info(s) or
// mesh_groups stored on the render_state object
meMeshGroup mesh_group;
render_group* ren_group;
char model_filename[256];
// NOTE: an array of render objects with all the vertex, normal, and uv
// data loaded from assimp
render_object* ren_objects;
uint ren_object_count;
//render_group* ren_group;
};
// NOTE: an entity group is an array of entities rendered with the same shader
// program
struct entity_group
{
entity* entities;
uint entity_count;
rg_shader_program shader_prg;
};
inline void
entTranslate(Entity& e, glm::vec3 v)
entTranslate(entity& e, glm::vec3 v)
{
e.world_transform = glm::translate(e.world_transform, v);
}
inline void
entScale(Entity& e, glm::vec3 v)
entScale(entity& e, glm::vec3 v)
{
e.world_transform = glm::scale(e.world_transform, v);
}
bool entInit(Entity& e, const char* model_path, rg_shader_program& shader);
bool entInit(entity& e, const char* model_path, rg_shader_program& shader);
void entFree(Entity& e);
void entFree(entity& e);
void entSetWorldPosition(Entity& e, float x, float y, float z);
void entSetWorldPosition(entity& e, float x, float y, float z);

6
include/mesh.h

@ -7,9 +7,11 @@
#include <glm/glm.hpp>
#include "animation.h"
#include "util.h"
#include "util_image.h"
struct meMeshInfo
{
glm::mat4 model_transform;
@ -21,8 +23,11 @@ struct meMeshInfo
uint* indices;
glm::vec3 diffuse_color;
// TODO: move this to meMeshGroup
bool use_texture;
util_image diffuse_texture;
node_animation* node_anim;
};
struct meMeshGroup
@ -30,7 +35,6 @@ struct meMeshGroup
bool use_normals;
uint num_meshes;
meMeshInfo** meshes;
// animation/bonemapping info here...
};

2
include/render_group.h

@ -27,6 +27,8 @@ struct gl_index_buffer
struct render_object
{
glm::mat4 node_xform;
// TODO: can remove these once we're using the global color palatte for all textures
bool use_texture;
GLuint tex_id;

4
include/renderer.h

@ -32,7 +32,9 @@ struct render_state
camera cam;
util_RGBA clear_col;
rg_shader_program default_shader;
//rg_shader_program default_shader;
entity_group* entity_groups;
uint entity_group_count;
rg_point_light* lights;
uint num_lights;

24
src/entity.cpp

@ -3,19 +3,19 @@
#include "entity.h"
void initEntityRG(Entity& e, rg_shader_program& shader, bool use_normals);
bool initEntityROs(Entity& e);
void initEntityRG(entity& e, rg_shader_program& shader, bool use_normals);
bool initEntityROs(entity& e);
bool convertMeshInfo(meMeshInfo* mesh, render_object* ro, bool use_normals, bool use_texture);
bool
entInit(Entity& e, const char* model_path, rg_shader_program& shader)
entInit(entity& e, const char* model_path, rg_shader_program& shader)
{
e.world_transform = glm::mat4(1.0);
entScale(e, e.scale);
entScale(e, glm::vec3(1.0));
if (meLoadFromFile(e.mesh_group, model_path)) {
initEntityRG(e, shader, e.mesh_group.use_normals);
entSetWorldPosition(e, e.translation.x, e.translation.y, e.translation.z);
entSetWorldPosition(e, 0, 0, 0);
if (!initEntityROs(e))
goto cleanup;
@ -31,22 +31,22 @@ cleanup:
}
void
entFree(Entity& e)
entFree(entity& e)
{
meFreeMeshGroup(e.mesh_group);
rgFree(e.ren_group);
}
void
entSetWorldPosition(Entity& e, float x, float y, float z)
entSetWorldPosition(entity& e, float x, float y, float z)
{
e.world_transform[3][0] = e.translation.x = x;
e.world_transform[3][1] = e.translation.y = y;
e.world_transform[3][2] = e.translation.z = z;
e.world_transform[3][0] = x;
e.world_transform[3][1] = y;
e.world_transform[3][2] = z;
}
void
initEntityRG(Entity& e, rg_shader_program& shader, bool use_normals)
initEntityRG(entity& e, rg_shader_program& shader, bool use_normals)
{
render_group* rg = UTIL_ALLOC(1, render_group);
e.ren_group = rg;
@ -59,7 +59,7 @@ initEntityRG(Entity& e, rg_shader_program& shader, bool use_normals)
}
bool
initEntityROs(Entity& e)
initEntityROs(entity& e)
{
render_group* rg = e.ren_group;

39
src/renderer.cpp

@ -71,41 +71,18 @@ renRenderFrame(render_state* rs, Entity* entities, uint32 entity_count)
glClearColor(rs->clear_col.R, rs->clear_col.G, rs->clear_col.B, rs->clear_col.A);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//glm::mat4 m_model = rs->cam.model;
glm::mat4 m_view = rs->cam.view;
glm::mat4 m_projection = rs->cam.projection;
#if 0
// filled hexes
// get new colors every frame
hgUpdateUVBuffer(hg, rs->filled_hex_render_group);
rgDraw(rs->filled_hex_render_group, m_model, m_view, m_projection,
rs->lights, rs->num_lights);
// hex lines
rgDraw(rs->hex_line_render_group, m_model, m_view, m_projection,
rs->lights, rs->num_lights);
#endif
// entities
for (uint i = 0; i < entity_count; i++) {
rgDraw(entities[i].ren_group, entities[i].world_transform , m_view, m_projection,
rs->lights, rs->num_lights);
rgDraw(entities[i].ren_group,
entities[i].world_transform,
rs->cam.view,
rs->cam.projection,
rs->lights,
rs->num_lights
);
}
}
#if 0
void
renRenderDebug(render_state* rs, std::vector<Point> &vertices)
{
GLfloat* buf = rs->debug_render_group->render_objects[0]->vertex_buffer.buffer;
buf[0] = vertices[0].x; buf[1] = vertices[0].y; buf[2] = 0;
buf[3] = vertices[1].x; buf[4] = vertices[1].y; buf[2] = 0;
buf[6] = vertices[2].x; buf[7] = vertices[2].y; buf[8] = 0;
buf[9] = vertices[3].x; buf[10] = vertices[3].y; buf[11] = 0;
rgDraw(rs->debug_render_group, rs->cam.model, rs->cam.view,
rs->cam.projection, rs->lights, rs->num_lights, true);
}
#endif
// internal

Loading…
Cancel
Save