Small program to quickly test OpenGL GLSL shaders.
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.
 
 
 

158 lines
3.1 KiB

#pragma once
#include <SDL2/SDL.h>
#include <GL/glew.h>
#include <glm/glm.hpp>
#include "types.h"
// 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;
char* name;
};
struct gl_uniform
{
// NOTE: would be nice to use idx as the location parameter because it seems
// to match when the uniform isn't part of a uniform block, at least with
// intel mesa driver, but apparently that's not guarantied
GLuint idx;
GLint location;
GLint block_idx;
GLenum data_type;
GLint data_size;
GLint num_elements;
char* name;
};
struct GLUniformBlock
{
GLuint block_id;
GLint binding_idx;
GLuint num_uniforms;
gl_uniform* uniforms;
char* name;
};
struct shader_program
{
GLuint prog_id;
GLuint xforms_ubo_id;
GLuint model_xform_id;
u32 num_blocks;
GLUniformBlock* uniform_blocks;
u32 num_uniforms;
gl_uniform* uniforms;
u32 num_buffers;
gl_buffer* buffers;
char* name;
u64 hash; // NOTE: hash of vs filpath + fs filepath concat
};
struct GLContext
{
GLuint binding_count;
GLint max_binding_points;
GLint max_vertex_blocks;
GLint max_fragment_blocks;
GLint max_ublock_size;
u32 max_ubos;
u32 num_ubos;
gl_buffer* uniform_buffers;
u32 max_shaders;
u32 num_shaders;
shader_program* shaders;
};
struct transforms
{
glm::mat4 view_xform;
glm::mat4 proj_xform;
glm::mat4 normal_xform;
};
struct GLmesh
{
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 PointLight
{
glm::vec3 position;
glm::vec3 color;
u32 intensity;
};
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 };
// NOTE: every shader program is assumed to have one uniform block named
// "matrices" that contains the projection and view matrices, and one uniform
// named "model_xform" for the model matrix
bool addShaderProgram(memory_arena* arena,
GLContext* gl_ctx,
const char* vs,
const char* fs,
const char* name);
shader_program* getShaderByName(const char* name, GLContext* gl_ctx);
shader_program* getShaderByID(GLContext* gl_ctx, GLuint prog_id);
shader_program* getShaderByHash(GLContext* gl_ctx, u64 hash);
shader_program* getFreeShader(GLContext* gl_ctx);
void renderVAO(GLmesh* glmesh);
GLmesh loadGLMesh(shader_program* s,
const mesh& m,
GLenum draw_mode,
const glm::vec3& pos);
void initTransforms(memory_arena* arena,
transforms* xforms,
gl_buffer* xform_ubo,
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);