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.
108 lines
2.5 KiB
108 lines
2.5 KiB
|
|
#pragma once |
|
|
|
#if defined (_WIN32) |
|
#include <SDL.h> |
|
#else |
|
#include <SDL2/SDL.h> |
|
#endif |
|
#include <GL/glew.h> |
|
#include <glm/glm.hpp> |
|
|
|
#include "asset.h" |
|
#include "camera.h" |
|
#include "entity.h" |
|
#include "lights.h" |
|
#include "util.h" |
|
#include "shader_program.h" |
|
|
|
|
|
// NOTE: array of entities rendered with the same shader program |
|
struct render_group |
|
{ |
|
// TODO: also needs to be resizable |
|
entity* entities; |
|
uint entity_count; |
|
|
|
shader_wrapper shader; |
|
|
|
// TODO: does it makes sense to have the mesh_type stored on the |
|
// render_group? can then easily pass to roDraw() along with the entity |
|
// render_objects... |
|
// only the mesh object and render object really need to know about the |
|
// mesh_type... |
|
// |
|
//mesh_t mesh_type; |
|
}; |
|
|
|
struct SDL_Handles |
|
{ |
|
SDL_Window *window; |
|
SDL_GLContext glContext; |
|
SDL_DisplayMode currentDisplayMode; |
|
}; |
|
|
|
struct render_state |
|
{ |
|
glm::vec2 viewport_dims; |
|
camera cam; |
|
util_RGBA clear_col; |
|
SDL_Handles* handles; |
|
bool running; |
|
|
|
// TODO: this really needs to be a resizable array, or linked list, or |
|
// ...gasp, std::vector |
|
render_group** render_groups; |
|
uint render_group_count; |
|
|
|
// WIP |
|
model_assets* models; |
|
memory_arena* arena; |
|
// FIXME: should be a hashmap for textures loaded from assets |
|
// ie) pallete textures |
|
util_image* textures; |
|
|
|
// TODO: hide shaders behind a better abstraction than 'shader_wrapper' |
|
default_shader_program* default_shader; |
|
simple_shader_program* simple_shader; |
|
|
|
light_group* lights; |
|
}; |
|
|
|
#define DEFAULT_ASSET_SIZE 256 |
|
render_state* |
|
renInit(const char* title = "Tangerine", |
|
glm::vec2 viewport_dims = glm::vec2(1280, 720), |
|
Uint32 SDL_init_flags = 0, |
|
size_t arena_size = DEFAULT_ARENA_SIZE, |
|
uint asset_size = DEFAULT_ASSET_SIZE); |
|
|
|
void renShutdown(render_state* rs); |
|
|
|
render_group* |
|
renAllocateGroup(uint entity_count, shader_wrapper shader); |
|
|
|
// NOTE: callback function signature to use with renDoRenderLoop() |
|
typedef void (*frame_callback_fn) (render_state*); |
|
|
|
// NOTE: There are 2 callbacks to use here, cb_func_pre is called before |
|
// the call to renRenderFrame(), cb_fun_post is called after |
|
// NOTE: if you use cb_func_pre, you will have to use SDL_PollEvent() manually |
|
// and at minimum set rs->running = false on SDL_QUIT event |
|
void |
|
renDoRenderLoop(render_state* rs, |
|
uint framerate = 60, |
|
frame_callback_fn cb_func_pre = nullptr, |
|
frame_callback_fn cb_func_post = nullptr); |
|
|
|
void renRenderFrame(render_state* rs); |
|
|
|
bool |
|
renAddLight(render_state* rs, |
|
glm::vec3 pos = glm::vec3(0, 0, 0), |
|
glm::vec3 color = glm::vec3(1, 1, 1), |
|
float intensity = 1.0); |
|
|
|
glm::vec2 |
|
renGetWindowDims(render_state* rs); |
|
|
|
|