You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
2.8 KiB
169 lines
2.8 KiB
|
|
#pragma once |
|
|
|
#include <SDL2/SDL.h> |
|
#include <GL/glew.h> |
|
#include <glm/glm.hpp> |
|
|
|
|
|
typedef uint32_t u32; |
|
|
|
|
|
// FIXME: won't need this enum when dynamic shader parsing is working |
|
enum glsl_layout |
|
{ |
|
POSITION, |
|
NORMAL, |
|
UV |
|
}; |
|
|
|
struct gl_buffer |
|
{ |
|
GLuint id; |
|
GLenum target; |
|
GLenum data_type; |
|
GLuint data_size; |
|
GLuint binding_idx; // NOTE: set when used as backing for UBO |
|
}; |
|
|
|
struct gl_uniform |
|
{ |
|
GLuint idx; // NOTE: seems to map to location if not part of uniform block |
|
//GLuint location; |
|
GLint block_idx; |
|
GLenum data_type; |
|
GLint data_size; |
|
char* name; |
|
}; |
|
|
|
struct shader_program |
|
{ |
|
GLuint prog_id; |
|
GLuint xforms_ubo_id; |
|
GLuint model_xform_id; |
|
|
|
u32 num_uniforms; |
|
gl_uniform* uniforms; |
|
|
|
u32 num_buffers; |
|
gl_buffer* buffers; |
|
|
|
char* name; |
|
u64 hash; // NOTE: hash of vs filpath + fs filepath concat |
|
}; |
|
|
|
// TODO: is it a good idea to merge this into GLContext? |
|
struct ShaderArray |
|
{ |
|
u32 count; |
|
u32 max; |
|
shader_program* shaders; |
|
}; |
|
|
|
struct GLContext |
|
{ |
|
gl_buffer xform_ubo; |
|
// TODO: keep an array of uniform buffer objects store on ctx? |
|
|
|
GLuint binding_count; |
|
GLint max_binding_points; |
|
|
|
ShaderArray* shader_arr; |
|
}; |
|
|
|
struct transforms |
|
{ |
|
glm::mat4 view_xform; |
|
glm::mat4 proj_xform; |
|
glm::mat4 normal_xform; |
|
}; |
|
|
|
struct gl_mesh |
|
{ |
|
u32 num_indices; |
|
GLuint vao_id; |
|
GLuint tex_id; |
|
GLenum draw_mode; // NOTE: GL_LINES, GL_TRIANGLES |
|
GLenum usage; // NOTE: GL_STATIC_DRAW, GL_DYNAMIC_DRAW |
|
|
|
shader_program* shader; |
|
glm::mat4* model_xform; |
|
|
|
GLuint vert_buf_id; |
|
GLuint norm_buf_id; |
|
GLuint uv_buf_id; |
|
GLuint clr_buf_id; |
|
GLuint idx_buf_id; |
|
}; |
|
|
|
struct gl_mesh_array |
|
{ |
|
u32 count; |
|
u32 max; |
|
gl_mesh* gl_meshes; |
|
}; |
|
|
|
struct point_light |
|
{ |
|
glm::vec3 position; |
|
glm::vec3 color; |
|
u32 intensity; |
|
}; |
|
|
|
struct light_array |
|
{ |
|
u32 count; |
|
point_light* lights; |
|
}; |
|
|
|
struct SDLHandles |
|
{ |
|
SDL_Window* window; |
|
SDL_GLContext sdl_gl_ctx; |
|
SDL_DisplayMode display_mode; |
|
}; |
|
|
|
struct RenderState |
|
{ |
|
memory_arena* arena; |
|
model_assets* assets; |
|
texture_assets* textures; |
|
|
|
transforms* xforms; // NOTE: would be part of camera in libTangerine |
|
SDLHandles* handles; |
|
|
|
GLContext* gl_ctx; |
|
gl_mesh_array* gl_mesh_arr; |
|
light_array lights; |
|
}; |
|
|
|
struct node; |
|
struct entity; |
|
struct animation; |
|
|
|
|
|
const float DEFAULT_FOV = 60.f; |
|
const float NEAR_CLIP_PLANE = 5.f; |
|
const float DEFAULT_ASPECT_RATIO = 16.f / 9.f; |
|
const glm::vec3 DEFAULT_CAM_POS = { 0, 0, -30.f }; |
|
const glm::vec3 DEFAULT_LOOK_POS = { 0, 0, 0 }; |
|
|
|
|
|
bool addShaderProgram(memory_arena* arena, |
|
GLContext* gl_ctx, |
|
const char* vs, |
|
const char* fs, |
|
const char* name); |
|
void renderVAO(gl_mesh* glmesh); |
|
gl_mesh loadGLMesh(shader_program* s, |
|
const mesh& m, |
|
GLenum draw_mode, |
|
const glm::vec3& pos); |
|
gl_buffer initTransforms(transforms* xforms, |
|
GLContext* gl_ctx, |
|
float fov = DEFAULT_FOV, |
|
float near_clip_plane = NEAR_CLIP_PLANE, |
|
float aspect_ratio = DEFAULT_ASPECT_RATIO, |
|
glm::vec3 cam_pos = DEFAULT_CAM_POS, |
|
glm::vec3 look_pos = DEFAULT_LOOK_POS); |
|
|
|
|