containts list of objects, inits and draws 3D scene. It has 3 main lists: objects, materials and lights. Materials are being applied to objects and all this is lit by lights. More...
#include <scene.h>
Public Member Functions | |
TScene () | |
Initialize scene by clearing lists. | |
~TScene () | |
Destructor. Free dynamic data. | |
bool | PreInit (GLint _resx, GLint _resy, GLfloat near, GLfloat far, GLfloat fovy, int msamples, bool cust_cam=false, bool load_font=true) |
Scene first initialization. In this function it's being checked if accelerator has all necessary extensions to run program. Then are set basic scene variables like screen resolution, near and far clipping planes and perspective correction. | |
bool | PostInit () |
Scene second initialization. The purpose of this initialization is to assign default material to objects without material and create shadow maps(TScene::CreateShadowMap()) for lights with shadows enabled, and to add this shadow map(TMaterial::AddShadowMap()) to all materials. | |
void | Resize (GLint _resx, GLint _resy) |
Resize screen to new dimensions, re-initialize viewport and projection matrices. | |
void | Redraw (bool delete_buffer=true) |
Render scene - camera, lights and objects(run through object list and call render function for every object). | |
void | LoadScreen (bool swap=true) |
Draw loading screen. | |
void | Destroy (bool delete_cache=true) |
Destroys all dynamic scene data, but keeps scene settings (like perspective, clipping planes). | |
void | SetLoadList (int count) |
set load items count (extern objects, textures and scenes) | |
void | UpdateLoadList (int count) |
update load list (when loading scene) | |
void | TestName (string name) |
set test name | |
void | LoadScene (const char *file, bool load_materials=true, bool load_lights=true) |
Loads entire scene from 3DS file. | |
void | MoveCamera (GLfloat wx, GLfloat wy, GLfloat wz) |
Move camera to new position(relative). | |
void | MoveCameraAbs (GLfloat wx, GLfloat wy, GLfloat wz) |
Move camera to new position(absolute). | |
void | LookCameraAt (GLfloat wx, GLfloat wy, GLfloat wz) |
Camera look. | |
void | RotateCamera (GLfloat angle, GLint axis) |
Rotate camera around axis(A_X, A_Y or A_Z) by angle(relative). | |
void | RotateCameraAbs (GLfloat angle, GLint axis) |
Rotate camera around axis(A_X, A_Y or A_Z) by angle(absolute). | |
void | SwitchCamera () |
Switch between custom and scene camera. | |
void | PrintCamera () |
Print out camera position. | |
TVector | GetCameraPos () |
Get screen-space camera position. | |
void | AddLight (GLint _lights, TVector amb, TVector diff, TVector spec, TVector lpos, float radius=1000.0) |
Add light from TLight() object. New light is pushed to the end of the list. | |
void | RemoveLight () |
Remove light identified by number. | |
void | MoveLight (GLint light, TVector w) |
Move light identified by number to new absolute position (see TLight::Move() ). | |
void | ChangeLightColor (GLint light, GLint component, TVector color) |
Change color of light(identified by index) component(GL_AMBIENT,GL_DIFFUSE or GL_SPECULAR) (see TLight::ChangeColor() ). | |
int | GetLightCount () |
Return number of lights in scene. | |
TVector | GetLightPos (int light) |
Return light position. | |
void | UpdateLightCount () |
Update light count in shaders. | |
void | SetLightRadius (int light, float radius) |
set light radius | |
void | AddObject (const char *name, int primitive, GLfloat size=0.0, GLfloat height=0.0, GLint sliceX=1, GLint sliceY=1) |
Add new object (see TObject() into list. Index is object name. | |
void | AddObjectInstance (const char *ref_name, const char *inst_name) |
add new object as instance from existing object | |
void | AddObject (const char *name, const char *file) |
Add 3DS object to scene. If objects has been loaded, a object pointer from cache is used instead of reloading from file. | |
void | MoveObj (const char *name, GLfloat wx, GLfloat wy, GLfloat wz) |
Move object identified by name to new position(relative) (see TObject::Move() ). | |
void | MoveObjAbs (const char *name, GLfloat wx, GLfloat wy, GLfloat wz) |
Move object identified by name to new position(absolute) (see TObject::MoveAbs() ). | |
void | RotateObj (const char *name, GLfloat angle, GLint axis) |
Rotate object identified by name around axis(can be A_X, A_Y, A_Z) by angle(relative) (see TObject::Rotate() ). | |
void | RotateObjAbs (const char *name, GLfloat angle, GLint axis) |
Rotate object identified by name around axis(can be A_X, A_Y, A_Z) by angle(absolute) (see TObject::RotateAbs() ). | |
void | ResizeObj (const char *name, GLfloat sx, GLfloat sy, GLfloat sz) |
Resize object identified by name according to resize factor. | |
GLint | GetVertexBuffer (const char *name) |
Return object's vertex buffer ID. | |
TVector | GetObjPosition (const char *name) |
Get object position. | |
void | DrawObject (const char *obj_name, bool flag) |
toggle object drawing | |
void | SetGInstances (const char *obj_name, int count) |
Set count of object instances. | |
void | AddMaterial (const char *_name, TVector amb=black, TVector diff=silver, TVector spec=white, GLfloat shin=64.0, GLfloat reflect=0.0, GLfloat transp=0.0, GLint lm=PHONG) |
Add new material(see TMaterial()) to list. | |
void | AddTexture (const char *name, const char *file, GLint textype=BASE, GLint texmode=MODULATE, GLfloat intensity=1.0, GLfloat tileX=1.0, GLfloat tileY=1.0, bool mipmap=true, bool aniso=false) |
Return camera position in world space. | |
void | AddTexture (const char *name, const char **files, GLint textype=CUBEMAP, GLint texmode=MODULATE, GLfloat intensity=1.0, GLfloat tileX=1.0, GLfloat tileY=1.0, bool aniso=false) |
Add cubemap texture to scene. If texture has been loaded, a texture pointer from cache is used instead of reloading from file. | |
void | SetMaterial (const char *obj_name, const char *mat_name) |
Bind material(identified by mat_name) to object(identified by obj_name). | |
void | CustomShader (const char *name, const char *vert_source, const char *geom_source, const char *frag_source, const char *vert_defines=NULL, const char *frag_defines=NULL, const char *geom_defines=NULL) |
Load custom shader from file. Shader can be then applied to any material (see TMaterial::CustomShader() ). Geometry shader is optional, likewise shader defines. | |
void | SetUniform (const char *m_name, const char *v_name, float value) |
Set float uniform variable in material shader (see TMaterial::SetUniform() ). | |
void | SetUniform (const char *m_name, const char *v_name, double value) |
Set double uniform variable in material shader (see TMaterial::SetUniform() ). | |
void | SetUniform (const char *m_name, const char *v_name, int value) |
Set int uniform variable in material shader (see TMaterial::SetUniform() ). | |
void | SetUniforms (const char *m_name, const char *v_name, float *value, int values) |
Set array of uniform variables (eg. vector) in material shader (see TMaterial::SetUniforms() ). | |
void | BakeAllMaterials () |
Force regeneration of all materials. | |
bool | CreateShadowMap (vector< TLight >::iterator ii) |
Creates shadow map for selected light. Shadow map parameters are stored in TLight object. | |
void | RenderShadowMap (TLight l) |
Draws scene to shadow map. | |
void | SetShadow (GLint lightNum, GLint shadow_size=2048, GLfloat _shadow_intensity=0.5, bool shadow=true) |
Set shadow parameters(shadow size and intensity) for selected light (by index) (see TLight::SetShadow(). | |
void | CastShadow (const char *obj_name, bool flag) |
Enable/disable shadow casting by selected object (by name) (see TObject::CastShadow() ). | |
void | ReceiveShadow (const char *mat_name, bool flag) |
Enable/disable shadow receiving for selected material (by name) (see TMaterial::ReceiveShadow() ). | |
void | UseShadows (bool flag=true) |
GLobally enable/disable shadows (for enable, shadows must be created for light that casts them. | |
void | CreateRenderTarget (int resX=-1, int resY=-1, GLint tex_format=GL_RGBA16F, GLenum tex_type=GL_FLOAT) |
Create render target using framebuffer and attached texture. | |
void | ResizeRenderTarget (int resX, int resY, GLint tex_format=GL_RGBA16F, GLenum tex_type=GL_FLOAT) |
Resize render target textures. | |
bool | CreateRenderCubeMap (TObject *obj) |
Prepare cube map texture for rendering into. | |
void | RenderToCubeMap (TObject *obj) |
Render scene to cubemap using six framebuffers. | |
void | SetReflectionSize (const char *obj_name, int value) |
set dynamic reflection cubemap size for selected object (by name) | |
void | UseDynReflections (bool use_gs=false) |
Toggle using of dynamic shader cubemapping. | |
void | UseHDR (bool flag=true) |
toggle use of HDR | |
void | UseSSAO (bool flag=true) |
toggle use of SSAO | |
void | DrawScreenText (const char *s, float x, float y, float size=1.0) |
Print 2D texture font on screen. | |
void | BuildFont () |
Create display lists for all characters(256) in font. Font is read from file. | |
int | GetResX () |
Get screen width. | |
int | GetResY () |
Get screen height. | |
Protected Attributes | |
map< string, TObject > | objects |
associative array with all objects | |
map< string, TObject >::iterator | io |
iterator for objects container | |
map< string, TMaterial > | materials |
associative array with all materials | |
map< string, TMaterial >::iterator | im |
iterator for materials container | |
vector< TLight > | lights |
associative array with all lights | |
vector< TLight >::iterator | il |
iterator for lights container | |
map< string, GLuint > | tex_cache |
map< string, GLuint >::iterator | it |
iterator for texture cache container | |
map< string, VBO >::iterator | iob |
3DS objects cache - purpose is the same as texture cache | |
map< string, VBO > | obj_cache |
iterator for object cache container | |
Texture | font2D_tex |
2D font texture | |
Texture | font2D_bkg |
Background texture. | |
GLuint | font2D |
Display list for font. | |
GLint | resx |
resolution X | |
GLint | resy |
resolution Y | |
GLfloat | near_p |
near clipping plane | |
Glfloat | far_p |
far clipping plane | |
GLfloat | fovy |
field of view | |
TCamera | cam |
scene camera | |
bool | custom_cam |
do we use custom camera? | |
bool | use_gshader_ref |
do we use geometry shader for dynamic cubemapping? | |
int | msamples |
number of multisaples in antialiasing | |
TMatrix | viewMatrix |
camera view matrix | |
TMatrix | tmpMatrix |
temporary matrix | |
bool | useHDR |
shall we use HDR? | |
bool | useSSAO |
shall we use SSAO? | |
bool | useShadows |
shall we use shadows? | |
GLuint | f_buffer |
framebuffer object | |
GLuint | r_buffer_color |
renderbuffer for color | |
GLuint | r_buffer_depth |
renderbuffer for depth | |
GLuint | msaa_f_buffer |
multisampled framebuffer object | |
GLuint | msaa_r_buffer_color |
multisampled renderbuffer for color | |
GLuint | msaa_r_buffer_depth |
multisampled renderbuffer for depth | |
int | RT_resX |
render target size in X | |
int | RT_resY |
render target size in Y | |
GLuint | render_texture |
basic render textures | |
GLuint | bloom_texture |
texture for bloom effect | |
GLuint | normal_texture |
texture for normal values | |
GLuint | blur_texture |
texture for blurring | |
int | load_list |
number of items to be loaded | |
int | load_actual |
actual item in list | |
string | testname |
actual test name |
containts list of objects, inits and draws 3D scene. It has 3 main lists: objects, materials and lights. Materials are being applied to objects and all this is lit by lights.
void TScene::AddObject | ( | const char * | name, | |
const char * | file | |||
) |
Add 3DS object to scene. If objects has been loaded, a object pointer from cache is used instead of reloading from file.
name | object name | |
file | 3DS file with data |
find out, if object hasn't been loaded yet
if no match, load object normally
else use existing object data
void TScene::AddTexture | ( | const char * | name, | |
const char ** | files, | |||
GLint | textype = CUBEMAP , |
|||
GLint | texmode = MODULATE , |
|||
GLfloat | intensity = 1.0 , |
|||
GLfloat | tileX = 1.0 , |
|||
GLfloat | tileY = 1.0 , |
|||
bool | aniso = false | |||
) |
Add cubemap texture to scene. If texture has been loaded, a texture pointer from cache is used instead of reloading from file.
name | texture name | |
files | array of 6 external texture files (.tga) | |
textype | texture type (CUBEMAP) | |
texmode | texture addition mode (can be ADD,MODULATE,DECAL,BLEND) | |
intensity | texture color intensity (or bump intensity) | |
tileX | count of horizontal tiles | |
tileY | count of vertical tiles | |
aniso | should we use anisotropic filtering? |
if no match, load texture normally
else use existing texture
then save texture ID to cache
void TScene::AddTexture | ( | const char * | name, | |
const char * | file, | |||
GLint | textype = BASE , |
|||
GLint | texmode = MODULATE , |
|||
GLfloat | intensity = 1.0 , |
|||
GLfloat | tileX = 1.0 , |
|||
GLfloat | tileY = 1.0 , |
|||
bool | mipmap = true , |
|||
bool | aniso = false | |||
) |
Return camera position in world space.
Add texture to scene. If texture has been loaded, a texture pointer from cache is used instead of reloading from file
name | texture name | |
file | external texture file (.tga) | |
textype | texture type (can be BASE,ENV,BUMP) | |
texmode | texture addition mode (can be ADD,MODULATE,DECAL,BLEND) | |
intensity | texture color intensity (or bump intensity) | |
tileX | count of horizontal tiles | |
tileY | count of vertical tiles | |
mipmap | should we generate mipmaps? | |
aniso | should we use anisotropic filtering? |
find out, if texture hasn't been loaded yet
if no match, load texture normally
else use existing texture
then save texture ID to cache
bool TScene::CreateRenderCubeMap | ( | TObject * | obj | ) |
Prepare cube map texture for rendering into.
obj | pointer to object with reflection |
void TScene::CreateRenderTarget | ( | int | resX = -1 , |
|
int | resY = -1 , |
|||
GLint | tex_format = GL_RGBA16F , |
|||
GLenum | tex_type = GL_FLOAT | |||
) |
Create render target using framebuffer and attached texture.
resX | X-size of framebuffer texture | |
resY | Y-size of framebuffer texture | |
tex_format | OpenGL texture format (can be GL_RGBA, GL_RGBA16F or GL_RGBA32F) | |
tex_type | internal data format (can be GL_UNSIGNED_BYTE or GL_FLOAT) |
bool TScene::CreateShadowMap | ( | vector< TLight >::iterator | ii | ) |
Creates shadow map for selected light. Shadow map parameters are stored in TLight object.
ii | iterator to lights list |
1. generate depth texture for shadow map with desired dimensions for current light
2. set depth texture parameters
3. Enable shadow comparison in hardware
4. create framebuffer object and bind shadow texture into it
void TScene::Destroy | ( | bool | delete_cache = true |
) |
Destroys all dynamic scene data, but keeps scene settings (like perspective, clipping planes).
delete_cache | should we delete also loaded textures from cache? (can be useful when next scene uses the same textures) |
void TScene::DrawScreenText | ( | const char * | s, | |
float | px, | |||
float | py, | |||
float | size = 1.0 | |||
) |
Print 2D texture font on screen.
s | text to be drawn | |
px | text position in % relative to screen width | |
py | text position in % relative to screen height | |
size | font size (default 1.0) |
turn off shaders before text drawing
void TScene::LoadScene | ( | const char * | file, | |
bool | load_materials = true , |
|||
bool | load_lights = true | |||
) |
Loads entire scene from 3DS file.
file | 3DS file with scene | |
load_materials | shall we load materials? | |
load_lights | shall we load lights? |
bool TScene::PostInit | ( | ) |
Scene second initialization. The purpose of this initialization is to assign default material to objects without material and create shadow maps(TScene::CreateShadowMap()) for lights with shadows enabled, and to add this shadow map(TMaterial::AddShadowMap()) to all materials.
bool TScene::PreInit | ( | GLint | _resx, | |
GLint | _resy, | |||
GLfloat | _near, | |||
GLfloat | _far, | |||
GLfloat | _fovy, | |||
int | _msamples, | |||
bool | cust_cam = false , |
|||
bool | load_font = true | |||
) |
Scene first initialization. In this function it's being checked if accelerator has all necessary extensions to run program. Then are set basic scene variables like screen resolution, near and far clipping planes and perspective correction.
_resx | screen width in pixels | |
_resy | screen height in pixels | |
_near | near clipping plane (must be greater than 0.0) | |
_far | far clipping plane (must be greater than near) | |
_fovy | viewing angle (in degrees) | |
_msamples | number of samples used in multisampling | |
cust_cam | it's possible to use a custom camera instead of scene camera | |
load_font | shall we load font? |
at the end of init add basic material to list
void TScene::Redraw | ( | bool | delete_buffer = true |
) |
Render scene - camera, lights and objects(run through object list and call render function for every object).
delete_buffer | should we delete color and depth buffer? |
position all lights,
if light has a shadow, render scene from light view to texture (TScene::RenderShadowMap())
render all opaque objects (TObject::Draw())
then render all transparent objects (TObject::Draw())
render dynamic cubemaps for reflective objects
void TScene::RemoveLight | ( | ) | [inline] |
Remove light identified by number.
void TScene::RenderShadowMap | ( | TLight | l | ) |
Draws scene to shadow map.
l | current light |
1. set and get light projection and light view matrix save camera view matrix
get light projection matrix
get light view matrix
2.bind framebuffer to draw into and draw scene from light point of view
draw only back faces of polygons
enable polygon offset to avoid z-fighting
All scene is drawn(TObject::Draw()) without materials and lighting (only depth values and alpha tests are needed)
3. Apply shadow map to scene - load camera projection and view matrix
Calculate and inverse view matrix
4. Calculate texture shadow projection matrix by multiplying bias, view and light matrix
5.set created shadow texture matrix for every material (TMaterial::SetShadowMatrix())
void TScene::RenderToCubeMap | ( | TObject * | obj | ) |
Render scene to cubemap using six framebuffers.
obj | object with dynamic cubemap |
void TScene::Resize | ( | GLint | _resx, | |
GLint | _resy | |||
) |
Resize screen to new dimensions, re-initialize viewport and projection matrices.
_resx | X-resolution in pixels | |
_resy | Y-resolution in pixels |
void TScene::ResizeRenderTarget | ( | int | resX, | |
int | resY, | |||
GLint | tex_format = GL_RGBA16F , |
|||
GLenum | tex_type = GL_FLOAT | |||
) |
Resize render target textures.
resX | new X-size of framebuffer textures | |
resY | new Y-size of framebuffer texture | |
tex_format | OpenGL texture format (can be GL_RGBA, GL_RGBA16F or GL_RGBA32F) | |
tex_type | internal data format (can be GL_UNSIGNED_BYTE or GL_FLOAT) |
void TScene::SetMaterial | ( | const char * | obj_name, | |
const char * | mat_name | |||
) |
Bind material(identified by mat_name) to object(identified by obj_name).
obj_name | object name | |
mat_name | material name |
void TScene::UseDynReflections | ( | bool | use_gs = false |
) |
Toggle using of dynamic shader cubemapping.
use_gs | on/off geometry shader for cubemapping |
map<string,GLuint> TScene::tex_cache [protected] |
texture cache: all loaded textures are stored here; if there's request for load of already loaded texture, cache texture will be used. Cache contains source file and pointer to already created texture