glview.h
1 /************************************************************
2 * (C) Voxel Farm Inc. 2015
3 */
4 
5 #include "VoxelFarm.h"
6 #include "windows.h"
7 #include "glrender.h"
8 #include "ClipmapView.h"
9 #include <vector>
10 
11 namespace VoxelFarm
12 {
15  namespace GL
16  {
18  const int ERROR_INITIALIZATION_FAILED = 501;
20  const int ERROR_SHUTDOWN_FAILED = 502;
24  const int ERROR_SHADER = 504;
25 
27  int InitGL(GLvoid);
29  BOOL CreateGLWindow(
31  char* title,
33  int width,
35  int height,
37  int bits,
39  bool fullscreenflag,
41  WNDPROC WndProc,
43  bool hosted,
44  HWND parent);
46  GLvoid KillGLWindow();
48  GLvoid ReSizeGLScene(
50  GLsizei width,
52  GLsizei height);
54  bool IsExtensionSupported(char* szTargetExtension);
55 
57  RGBImageRec* loadImg(const char* szName);
59  bool loadMaterials(CMaterialLibrary* materialLibrary, char* path, bool loadCompressed);
61  void loadShaders();
63  void clearDisplacementMaps();
64 
66  bool bake(CClipmapView* clipmapView, StatTracker& stats);
68  void disposeDeadCells(CClipmapView* clipmapView, int iterations);
70  void bakeCell(CClipmapView* clipmapView, CGLCellData* cellData);
71 
73  void orthogonalStart();
75  void orthogonalEnd();
76 
77  bool createIcoSphere(float radius, float section, int levels, VoxelFarm::CCellData::CVert* verts, int& vertCount, GLushort* faceIndices, int& faceCount);
78 
80  int DrawGLScene(CClipmapView* clipmapView);
81 
82  void recomputeShadows();
83 
85  extern HDC hDC;
87  extern HGLRC hRC;
89  extern HWND hWnd;
91  extern HINSTANCE hInstance;
93  extern bool fullscreen;
95  extern int window_width;
97  extern int window_height;
98 
100  const int MATERIAL_PROPERTY_COUNT = 14;
101 
102  // shadow map
104  extern GLuint shadowFBOId;
106  extern GLuint shadowFBOIdPhysics;
108  extern int shadowMapWidth;
110  extern int shadowMapHeight;
112  void generateShadowFBO();
114  void setShadowTextureMatrix(GLuint textureSlot = GL_TEXTURE7);
115 
116  // skylight map
118  extern GLuint skylightFBOId;
120  extern int skylightMapWidth;
122  extern int skylightMapHeight;
124  void generateSkylightFBO();
127 
128  // cloud map
129  extern GLuint cloudTextureId;
130 
131 
133  typedef void OnBeforeRender();
135  typedef void OnAfterRender();
139  extern OnBeforeRender* afterRender;
140  }
141 
142 }
void clearDisplacementMaps()
Clear the created displacement maps.
int window_width
Width of the main window.
bool bake(CClipmapView *clipmapView, StatTracker &stats)
Moves multiple Cells from main memory into GPU memory.
bool IsExtensionSupported(char *szTargetExtension)
Determines whether the specified OpenGL extension is supported.
void loadShaders()
Initializes GLSL shaders.
Contains all classes and functions for the VoxelFarm engine.
Contains all materials available in the system.
GLuint shadowFBOId
FBO Id for the Sunlight shadow.
void orthogonalStart()
Starts orthogonal projection.
void generateSkylightFBO()
Initializes FBO for Sunlight shadows.
const int ERROR_SHUTDOWN_FAILED
Engine shutdown failed.
Definition: glview.h:20
void OnBeforeRender()
Prototype for BeforeRender event. This event fires before rendering begins.
Definition: glview.h:133
void setShadowTextureMatrix(GLuint textureSlot=GL_TEXTURE7)
Computes and stores the Sunlight shadow matrix.
GLuint shadowFBOIdPhysics
FBO Id for the Sunlight shadow for physics fragments.
bool loadMaterials(CMaterialLibrary *materialLibrary, char *path, bool loadCompressed)
Load material definitions and textures into main memory and GPU memory.
int window_height
Height of the main window.
void setSkylightTextureMatrix()
Computes and stores the Skylight shadow matrix.
GLuint skylightFBOId
FBO Id for the Skylight shadow.
void OnAfterRender()
Prototype for AfterRender event. This event fires after the world scene is rendered.
Definition: glview.h:135
int skylightMapWidth
Shadowmap Width for the Skylight shadow.
const int ERROR_RESOLUTION_NOT_SUPPORTED
Video resolution is not supported.
Definition: glview.h:22
GLvoid KillGLWindow()
Destroys the main window.
int shadowMapWidth
Shadowmap Width for the Sunlight shadow.
const int ERROR_INITIALIZATION_FAILED
Engine shutdown failed.
Definition: glview.h:18
const int ERROR_SHADER
Shader error.
Definition: glview.h:24
void bakeCell(CClipmapView *clipmapView, CGLCellData *cellData)
Moves the specified Cell data from main memory into GPU memory.
HDC hDC
HDC object for the main window.
BOOL CreateGLWindow(char *title, int width, int height, int bits, bool fullscreenflag, WNDPROC WndProc, bool hosted, HWND parent)
Creates the main window.
int skylightMapHeight
Shadowmap Height for the Skylight shadow.
int DrawGLScene(CClipmapView *clipmapView)
Draws the scene to screen.
bool fullscreen
Signals whether the application is full screen.
A CellData object for rendering in OpenGL.
Definition: glrender.h:28
HWND hWnd
Handle for the main window.
GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
Resizes the GL context.
Represents a moving view within a world. Computes new scenes as the view moves.
Definition: ClipmapView.h:65
void disposeDeadCells(CClipmapView *clipmapView, int iterations)
Disposes a specified number of inactive cells, removing them from GPU memory.
const int MATERIAL_PROPERTY_COUNT
Number of properties in each material defintion inside the GPU material array.
Definition: glview.h:100
RGBImageRec * loadImg(const char *szName)
Load a BMP image.
An object to track stats. Contains two different counters.
Definition: VoxelLayer.h:464
HGLRC hRC
HRC object for the main window.
int InitGL(GLvoid)
Initializes OpenGL.
void orthogonalEnd()
Ends orthogonal projection.
int shadowMapHeight
Shadowmap Height for the Sunlight shadow.
OnBeforeRender * afterRender
Pointer to AfterRender event. This event fires after the world scene is rendered. ...
OnBeforeRender * beforeRender
Pointer to BeforeRender event. This event fires before rendering begins.
HINSTANCE hInstance
HINSTANCE object for the main window.
void generateShadowFBO()
Initializes FBO for Sunlight shadows.