2016-09-23 09:06:46 +02:00
# pragma once
# include <cstdint>
# include <map>
# include <vector>
2017-01-03 22:47:17 +01:00
# include "math_types.h"
2016-11-20 21:50:53 +01:00
2018-02-13 12:05:07 +01:00
# include <GL/gl3w.h> // This example is using gl3w to access OpenGL functions (because it is small). You may use glew/glad/glLoadGen/etc. whatever already works for you.
2017-02-23 15:19:26 +01:00
# include "Globals.h"
2018-02-13 12:05:07 +01:00
# include "RenderUtils.h"
2016-09-23 09:06:46 +02:00
struct Camera {
2017-01-03 22:47:17 +01:00
Vector3f eye ;
Vector3f poi ;
Vector3f up ;
2016-09-23 09:06:46 +02:00
float near ;
float far ;
float fov ;
bool orthographic ;
float width ;
float height ;
2018-02-12 21:35:44 +01:00
Matrix44f mtxProj ;
Matrix44f mtxView ;
2016-09-23 09:06:46 +02:00
Camera ( ) :
eye { 5.f , 4.f , 5.f } ,
poi { 0.f , 2.f , 0.f } ,
up { 0.f , 1.f , 0.f } ,
2016-10-21 22:07:23 +02:00
near ( 0.1f ) ,
far ( 150.f ) ,
2016-11-30 22:11:08 +01:00
fov ( 60.f ) ,
2016-09-23 09:06:46 +02:00
orthographic ( false ) ,
width ( - 1.f ) ,
height ( - 1.f ) ,
2018-02-12 21:35:44 +01:00
mtxProj (
2016-10-21 22:07:23 +02:00
1.f , 0.f , 0.f , 0.f ,
0.f , 1.f , 0.f , 0.f ,
0.f , 0.f , 1.f , 0.f ,
2018-02-12 21:35:44 +01:00
0.f , 0.f , 0.f , 1.f ) ,
mtxView (
2016-09-23 09:06:46 +02:00
1.f , 0.f , 0.f , 0.f ,
0.f , 1.f , 0.f , 0.f ,
0.f , 0.f , 1.f , 0.f ,
2018-02-12 21:35:44 +01:00
0.f , 0.f , 0.f , 1.f )
{ }
2016-09-23 09:06:46 +02:00
void updateMatrices ( ) ;
} ;
struct Light {
2017-04-11 08:16:10 +02:00
Vector3f pos ;
Vector3f dir ;
2016-09-23 09:06:46 +02:00
float mtxView [ 16 ] ;
float mtxProj [ 16 ] ;
float mtxLight [ 16 ] ;
float mtxShadow [ 16 ] ;
float shadowMapBias ;
uint16_t shadowMapSize ;
bool enabled ;
float near ;
float far ;
float area ;
Light ( ) :
2017-04-11 08:16:10 +02:00
pos ( Vector3f ( 0.f , 10.f , 10.f ) ) ,
dir ( Vector3f ( - 1.f , - 1.f , - 1.f ) ) ,
2016-09-23 09:06:46 +02:00
mtxView {
1.f , 0.f , 0.f , 0.f ,
0.f , 1.f , 0.f , 0.f ,
0.f , 0.f , 1.f , 0.f ,
0.f , 0.f , 0.f , 1.f
} ,
mtxProj {
1.f , 0.f , 0.f , 0.f ,
0.f , 1.f , 0.f , 0.f ,
0.f , 0.f , 1.f , 0.f ,
0.f , 0.f , 0.f , 1.f
} ,
mtxShadow {
1.f , 0.f , 0.f , 0.f ,
0.f , 1.f , 0.f , 0.f ,
0.f , 0.f , 1.f , 0.f ,
0.f , 0.f , 0.f , 1.f
} ,
2016-11-10 21:29:47 +01:00
shadowMapBias ( 0.004f ) ,
shadowMapSize ( 2048 ) ,
near ( 0.1f ) ,
2016-09-23 09:06:46 +02:00
far ( 100.f ) ,
area ( 10.f ) ,
enabled ( false )
{
}
} ;
2018-02-13 12:05:07 +01:00
struct Mesh {
GLuint mVertexArrayId = - 1 ;
GLuint mVertexBuffer = - 1 ;
2017-01-03 22:47:17 +01:00
} ;
2016-09-23 09:06:46 +02:00
struct Renderer {
2018-02-13 14:27:16 +01:00
bool mInitialized = false ;
uint32_t mWidth = 1 ;
uint32_t mHeight = 1 ;
2016-09-23 09:06:46 +02:00
2018-02-16 11:35:09 +01:00
Camera mCamera ;
2018-02-13 12:05:07 +01:00
Mesh mMesh ;
RenderProgram mProgram ;
2018-02-13 12:44:34 +01:00
RenderTarget mRenderTarget ;
2016-09-23 09:06:46 +02:00
2018-02-13 14:27:16 +01:00
GLuint mRenderQuadVertexArrayId ;
GLuint mRenderQuadVertexBufferId ;
2018-02-15 09:59:38 +01:00
2018-02-13 14:27:16 +01:00
RenderProgram mRenderQuadProgramColor ;
2018-02-16 11:35:09 +01:00
GLuint muRenderQuadModelViewProj ;
2018-02-13 14:27:16 +01:00
GLuint muRenderQuadTexture ;
GLuint muRenderQuadTime ;
2018-02-15 09:59:38 +01:00
RenderProgram mRenderQuadProgramDepth ;
2018-02-16 11:35:09 +01:00
GLuint muRenderQuadDepthModelViewProj ;
2018-02-15 09:59:38 +01:00
GLuint muRenderQuadDepthNear ;
GLuint muRenderQuadDepthFar ;
2016-09-23 09:06:46 +02:00
Renderer ( ) :
2018-02-13 14:27:16 +01:00
mInitialized ( false ) ,
mWidth ( 0 ) ,
mHeight ( 0 )
2017-07-02 23:26:02 +02:00
{ }
2016-09-23 09:06:46 +02:00
2018-02-12 21:35:44 +01:00
void Initialize ( int width , int height ) ;
void Shutdown ( ) ;
void RenderGl ( ) ;
void RenderGui ( ) ;
void Resize ( int width , int height ) ;
2016-09-23 09:06:46 +02:00
} ;