Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Gfx::CEngine Class Reference

The graphics engine. More...

#include <engine.h>

Inheritance diagram for Gfx::CEngine:
Inheritance graph
[legend]

Public Member Functions

 CEngine (CApplication *app)
 
void SetDevice (CDevice *device)
 Sets the device to be used.
 
CDeviceGetDevice ()
 Returns the current device.
 
CTextGetText ()
 Returns the text rendering engine.
 
CLightManagerGetLightManager ()
 Returns the light manager.
 
CParticleGetParticle ()
 Returns the particle manager.
 
CTerrainGetTerrain ()
 Returns the terrain manager.
 
CWaterGetWater ()
 Returns the water manager.
 
CLightningGetLightning ()
 Returns the lighting manager.
 
CPlanetGetPlanet ()
 Returns the planet manager.
 
CCloudGetCloud ()
 Returns the fog manager.
 
void SetTerrain (CTerrain *terrain)
 Sets the terrain object.
 
bool Create ()
 Performs the initialization; must be called after device was set.
 
void Destroy ()
 Frees all resources before exit.
 
void ResetAfterDeviceChanged ()
 Resets some states and flushes textures after device was changed (e.g. resoulution changed)
 
void Render ()
 Called once per frame, the call is the entry point for rendering. More...
 
bool ProcessEvent (const Event &event)
 Processes incoming event.
 
void FrameUpdate ()
 Called once per frame, the call is the entry point for animating the scene.
 
bool WriteScreenShot (const std::string &fileName, int width, int height)
 Writes a screenshot containing the current frame.
 
TEST_VIRTUAL bool GetPause ()
 Get pause mode.
 
void SetRenderEnable (bool enable)
 Enables/disables rendering.
 
Math::IntPoint GetWindowSize ()
 Returns current size of viewport window.
 
void AddStatisticTriangle (int nb)
 Increments the triangle counter for the current frame.
 
int GetStatisticTriangle ()
 Returns the number of triangles in current frame.
 
void SetStatisticPos (Math::Vector pos)
 Sets the coordinates to display in stats window.
 
void SetTimerDisplay (const std::string &text)
 Sets text to display as mission timer.
 
int CreateBaseObject ()
 Creates a base object and returns its rank.
 
void DeleteBaseObject (int baseObjRank)
 Deletes a base object.
 
void DeleteAllBaseObjects ()
 Deletes all base objects.
 
void CopyBaseObject (int sourceBaseObjRank, int destBaseObjRank)
 Copies geometry between two base objects.
 
void AddBaseObjTriangles (int baseObjRank, const std::vector< VertexTex2 > &vertices, EngineTriangleType triangleType, const Material &material, int state, std::string tex1Name, std::string tex2Name, LODLevel lodLevel, bool globalUpdate)
 Adds triangles to given object with the specified params.
 
void AddBaseObjQuick (int baseObjRank, const EngineBaseObjDataTier &buffer, std::string tex1Name, std::string tex2Name, LODLevel lodLevel, bool globalUpdate)
 Adds a tier 4 engine object directly.
 
void DebugObject (int rank)
 Print debug info about an object.
 
int CreateObject ()
 Creates a new object and returns its rank.
 
void DeleteAllObjects ()
 Deletes all objects, shadows and ground spots.
 
void DeleteObject (int objRank)
 Deletes the given object.
 
void SetObjectDrawWorld (int objRank, bool draw)
 Sets drawWorld for given object.
 
void SetObjectDrawFront (int objRank, bool draw)
 Sets drawFront for given object.
 
void SetObjectTransparency (int objRank, float value)
 Sets the transparency level for given object.
 
void GetObjectBBox (int objRank, Math::Vector &min, Math::Vector &max)
 Returns the bounding box for an object.
 
int GetObjectTotalTriangles (int objRank)
 Returns the total number of triangles of given object.
 
EngineBaseObjDataTierFindTriangles (int objRank, const Material &material, int state, std::string tex1Name, std::string tex2Name, int lodLevelMask)
 Returns the first found tier 4 engine object for the given params or nullptr if not found.
 
int GetPartialTriangles (int objRank, int lodLevelMask, float percent, int maxCount, std::vector< EngineTriangle > &triangles)
 Returns a partial list of triangles for given object.
 
void ChangeSecondTexture (int objRank, const std::string &tex2Name)
 Changes the 2nd texure for given object.
 
void ChangeTextureMapping (int objRank, const Material &mat, int state, const std::string &tex1Name, const std::string &tex2Name, int lodLevelMask, EngineTextureMapping mode, float au, float bu, float av, float bv)
 Changes (recalculates) texture mapping for given object.
 
void TrackTextureMapping (int objRank, const Material &mat, int state, const std::string &tex1Name, const std::string &tex2Name, int lodLevelMask, EngineTextureMapping mode, float pos, float factor, float tl, float ts, float tt)
 Changes texture mapping for robot tracks.
 
int DetectObject (Math::Point mouse)
 Detects the target object that is selected with the mouse. More...
 
void CreateShadow (int objRank)
 Creates a shadow for the given object.
 
void DeleteShadow (int objRank)
 Deletes the shadow for given object.
 
void SetHighlightRank (int *rankList)
 Lists the ranks of objects and subobjects selected.
 
bool GetHighlight (Math::Point &p1, Math::Point &p2)
 Returns the highlighted rectangle.
 
void DeleteAllGroundSpots ()
 Deletes all ground spots.
 
int CreateGroundSpot ()
 Creates a new ground spot and returns its rank.
 
void DeleteGroundSpot (int rank)
 Deletes the given ground spot.
 
void CreateGroundMark (Math::Vector pos, float radius, float delay1, float delay2, float delay3, int dx, int dy, char *table)
 Creates the ground mark with the given params.
 
void DeleteGroundMark (int rank)
 Deletes the ground mark.
 
void Update ()
 Updates the state after creating objects.
 
void SetState (int state, const Color &color=Color(1.0f, 1.0f, 1.0f, 1.0f))
 Sets the current rendering state.
 
void SetMaterial (const Material &mat)
 Sets the current material.
 
void SetViewParams (const Math::Vector &eyePt, const Math::Vector &lookatPt, const Math::Vector &upVec, float eyeDistance)
 Specifies the location and direction of view.
 
Texture LoadTexture (const std::string &name)
 Loads texture, creating it if not already present.
 
Texture LoadTexture (const std::string &name, CImage *image)
 Loads texture from existing image.
 
Texture LoadTexture (const std::string &name, const TextureCreateParams &params)
 Loads texture, creating it with given params if not already present.
 
bool LoadAllTextures ()
 Loads all necessary textures.
 
bool ChangeTextureColor (const std::string &texName, Color colorRef1, Color colorNew1, Color colorRef2, Color colorNew2, float tolerance1, float tolerance2, Math::Point ts, Math::Point ti, Math::Point *exclude=nullptr, float shift=0.0f, bool hsv=false)
 Changes colors in a texture.
 
bool SetTexture (const std::string &name, int stage=0)
 Sets texture for given stage; if not present in cache, the texture is loaded. More...
 
void SetTexture (const Texture &tex, int stage=0)
 Sets texture for given stage.
 
void DeleteTexture (const std::string &name)
 Deletes the given texture, unloading it and removing from cache.
 
void DeleteTexture (const Texture &tex)
 Deletes the given texture, unloading it and removing from cache.
 
void FlushTextureCache ()
 Empties the texture cache.
 
void SetTerrainVision (float vision)
 Defines of the distance field of vision.
 
void SetDrawWorld (bool draw)
 Whether to draw the world.
 
void SetDrawFront (bool draw)
 Whether to draw the world on the interface.
 
void SetForegroundName (const std::string &name)
 Specifies the name of foreground texture.
 
void SetOverFront (bool front)
 Specifies whether to draw the foreground.
 
void SetOverColor (const Color &color=Color(), int mode=ENG_RSTATE_TCOLOR_BLACK)
 Sets the foreground overlay color.
 
float ParticleAdapt (float factor)
 Adapts particle factor according to particle density.
 
void SetLightingMode (bool present)
 
bool GetLightingMode ()
 
const Math::MatrixGetMatView ()
 Returns the view matrix.
 
TEST_VIRTUAL Math::Vector GetEyePt ()
 Returns the camera center point.
 
TEST_VIRTUAL Math::Vector GetLookatPt ()
 Returns the camera target point.
 
float GetEyeDirH ()
 Returns the horizontal direction angle of view.
 
float GetEyeDirV ()
 Returns the vertical direction angle of view.
 
bool IsVisiblePoint (const Math::Vector &pos)
 Indicates whether a point is visible.
 
void UpdateMatProj ()
 Resets the projection matrix after changes.
 
void ApplyChange ()
 Updates the scene after a change of parameters.
 
void SetMovieLock (bool lock)
 Management of lock for the duration of movie sequence.
 
bool GetMovieLock ()
 
void SetShowStats (bool show)
 Management of displaying statistic information.
 
bool GetShowStats ()
 
Math::Point WindowToInterfaceCoords (Math::IntPoint pos)
 Conversion functions between window and interface coordinates. More...
 
Math::IntPoint InterfaceToWindowCoords (Math::Point pos)
 
Math::Point WindowToInterfaceSize (Math::IntPoint size)
 Conversion functions between window and interface sizes. More...
 
Math::IntPoint InterfaceToWindowSize (Math::Point size)
 
void SetObjectBaseRank (int objRank, int baseObjRank)
 Management of the base object rank for engine object.
 
int GetObjectBaseRank (int objRank)
 
void SetObjectType (int objRank, EngineObjectType type)
 Management of engine object type.
 
EngineObjectType GetObjectType (int objRank)
 
void SetObjectTransform (int objRank, const Math::Matrix &transform)
 Management of object transform.
 
void GetObjectTransform (int objRank, Math::Matrix &transform)
 
void SetObjectShadowHide (int objRank, bool hide)
 Management of different shadow params.
 
void SetObjectShadowType (int objRank, EngineShadowType type)
 
void SetObjectShadowPos (int objRank, const Math::Vector &pos)
 
void SetObjectShadowNormal (int objRank, const Math::Vector &normal)
 
void SetObjectShadowAngle (int objRank, float angle)
 
void SetObjectShadowRadius (int objRank, float radius)
 
void SetObjectShadowIntensity (int objRank, float intensity)
 
void SetObjectShadowHeight (int objRank, float height)
 
float GetObjectShadowRadius (int objRank)
 
void SetObjectGroundSpotPos (int rank, const Math::Vector &pos)
 Management of different ground spot params.
 
void SetObjectGroundSpotRadius (int rank, float radius)
 
void SetObjectGroundSpotColor (int rank, const Color &color)
 
void SetObjectGroundSpotMinMax (int rank, float min, float max)
 
void SetObjectGroundSpotSmooth (int rank, float smooth)
 
void SetFocus (float focus)
 Management of camera angle. More...
 
float GetFocus ()
 
void SetGroundSpot (bool mode)
 Management of the global mode of marking.
 
bool GetGroundSpot ()
 
void SetShadow (bool mode)
 Management of the global mode of shading.
 
bool GetShadow ()
 
void SetDirty (bool mode)
 Management of the global mode of contamination.
 
bool GetDirty ()
 
void SetFog (bool mode)
 Management of the global mode of horizontal fog patches.
 
bool GetFog ()
 
void SetSecondTexture (const std::string &texNum)
 Management of the global mode of secondary texturing.
 
const std::string & GetSecondTexture ()
 
void SetRankView (int rank)
 Management of view mode.
 
int GetRankView ()
 
void SetAmbientColor (const Color &color, int rank=0)
 Ambient color management.
 
Color GetAmbientColor (int rank=0)
 
void SetWaterAddColor (const Color &color)
 Color management under water.
 
Color GetWaterAddColor ()
 
void SetFogColor (const Color &color, int rank=0)
 Management of the fog color.
 
Color GetFogColor (int rank=0)
 
void SetDeepView (float length, int rank=0, bool ref=false)
 Management of the depth of field. More...
 
float GetDeepView (int rank=0)
 
void SetFogStart (float start, int rank=0)
 Management the start of fog. More...
 
float GetFogStart (int rank=0)
 
void SetBackground (const std::string &name, Color up=Color(), Color down=Color(), Color cloudUp=Color(), Color cloudDown=Color(), bool full=false)
 Management of the background image to use.
 
void GetBackground (std::string &name, Color &up, Color &down, Color &cloudUp, Color &cloudDown, bool &full)
 
void SetParticleDensity (float value)
 Management of the particle density.
 
float GetParticleDensity ()
 
void SetClippingDistance (float value)
 Management of the distance of clipping.
 
float GetClippingDistance ()
 
void SetObjectDetail (float value)
 Management of objects detals.
 
float GetObjectDetail ()
 
void SetGadgetQuantity (float value)
 The amount of management objects gadgets.
 
float GetGadgetQuantity ()
 
void SetTextureQuality (int value)
 Management the quality of textures.
 
int GetTextureQuality ()
 
void SetTextureFilterMode (TexFilter value)
 Management the texture filter mode.
 
TexFilter GetTextureFilterMode ()
 
void SetTextureMipmapLevel (int value)
 Management the mipmap level for textures.
 
int GetTextureMipmapLevel ()
 
void SetTextureAnisotropyLevel (int value)
 Management the anisotropy level for textures.
 
int GetTextureAnisotropyLevel ()
 
void SetShadowMapping (bool value)
 Management of shadow mapping.
 
bool GetShadowMapping ()
 
void SetShadowColor (float value)
 Management of shadow mapping.
 
bool GetShadowColor ()
 
void SetTotoMode (bool present)
 Management mode of toto.
 
bool GetTotoMode ()
 
void SetLensMode (bool present)
 Management the mode of foreground.
 
bool GetLensMode ()
 
void SetWaterMode (bool present)
 Management the mode of water.
 
bool GetWaterMode ()
 
void SetSkyMode (bool present)
 Management the mode of sky.
 
bool GetSkyMode ()
 
void SetBackForce (bool present)
 Management the mode of background.
 
bool GetBackForce ()
 
void SetPlanetMode (bool present)
 Management the mode of planets.
 
bool GetPlanetMode ()
 
void SetLightMode (bool present)
 Managing the mode of dynamic lights.
 
bool GetLightMode ()
 
void SetEditIndentMode (bool autoIndent)
 Management of the indentation mode while editing (CEdit)
 
bool GetEditIndentMode ()
 
void SetEditIndentValue (int value)
 Management of tab indent when editing (CEdit)
 
int GetEditIndentValue ()
 
void SetTracePrecision (float factor)
 Management of precision of robot tracks.
 
float GetTracePrecision ()
 
void SetMouseType (EngineMouseType type)
 Management of mouse cursor type.
 
EngineMouseType GetMouseType ()
 

Protected Member Functions

void Draw3DScene ()
 Prepares the interface for 3D scene.
 
void RenderShadowMap ()
 Renders shadow map.
 
void UseShadowMapping (bool enable)
 Enables or disables shadow mapping.
 
void DrawObject (const EngineBaseObjDataTier &p4)
 Draw 3D object.
 
void DrawInterface ()
 Draws the user interface over the scene.
 
void UpdateGroundSpotTextures ()
 Updates the textures used for drawing ground spot.
 
void DrawShadow ()
 Draws shadows.
 
void DrawBackground ()
 Draws the gradient background.
 
void DrawBackgroundGradient (const Color &up, const Color &down)
 Draws the gradient background.
 
void DrawBackgroundImage ()
 Draws the image background.
 
void DrawPlanet ()
 Draws all the planets.
 
void DrawForegroundImage ()
 Draws the image foreground.
 
void DrawOverColor ()
 Draws the foreground color.
 
void DrawHighlight ()
 Draws the rectangle of the object highlighted.
 
void DrawMouse ()
 Draws the mouse cursor.
 
void DrawMouseSprite (Math::Point pos, Math::Point dim, int icon)
 Draw part of mouse cursor sprite.
 
void DrawStats ()
 Draw statistic texts.
 
void DrawTimer ()
 Draw mission timer.
 
EngineBaseObjTexTierAddLevel2 (EngineBaseObject &p1, const std::string &tex1Name, const std::string &tex2Name)
 Creates a new tier 2 object (texture)
 
EngineBaseObjLODTierAddLevel3 (EngineBaseObjTexTier &p2, LODLevel lodLevel)
 Creates a new tier 3 object (LOD)
 
EngineBaseObjDataTierAddLevel4 (EngineBaseObjLODTier &p3, EngineTriangleType type, const Material &mat, int state)
 Creates a new tier 4 object (data)
 
Texture CreateTexture (const std::string &texName, const TextureCreateParams &params, CImage *image=nullptr)
 Create texture and add it to cache.
 
bool IsVisible (int objRank)
 Tests whether the given object is visible. More...
 
bool IsWithinLODLimit (float distance, LODLevel lodLevel)
 Checks whether the given distance is within LOD min & max limit.
 
bool DetectBBox (int objRank, Math::Point mouse)
 Detects whether an object is affected by the mouse.
 
bool GetBBox2D (int objRank, Math::Point &min, Math::Point &max)
 Compute and return the 2D box on screen of any object.
 
bool DetectTriangle (Math::Point mouse, VertexTex2 *triangle, int objRank, float &dist)
 Detects whether the mouse is in a triangle.
 
bool TransformPoint (Math::Vector &p2D, int objRank, Math::Vector p3D)
 Transforms a 3D point (x, y, z) in 2D space (x, y, -) of the window. More...
 
void ComputeDistance ()
 Calculates the distances between the viewpoint and the origin of different objects.
 
void UpdateGeometry ()
 Updates geometric parameters of objects (bounding box and radius)
 
void UpdateStaticBuffer (EngineBaseObjDataTier &p4)
 Updates a given static buffer.
 
void UpdateStaticBuffers ()
 Updates static buffers of changed objects.
 

Protected Attributes

CApplicationm_app
 
CSoundInterfacem_sound
 
CDevicem_device
 
CTextm_text
 
CLightManagerm_lightMan
 
CParticlem_particle
 
CWaterm_water
 
CCloudm_cloud
 
CLightningm_lightning
 
CPlanetm_planet
 
CTerrainm_terrain
 
CPauseManagerm_pause
 
std::string m_error
 Last encountered error.
 
SystemTimeStampm_lastFrameTime
 
SystemTimeStampm_currentFrameTime
 
int m_fpsCounter
 
float m_fps
 
bool m_showStats
 Whether to show stats (FPS, etc)
 
std::string m_fpsText
 
bool m_render
 Rendering enabled?
 
bool m_movieLock
 Lock for duration of movie?
 
Math::Matrix m_matProj
 Projection matrix for 3D scene.
 
Math::Matrix m_matView
 View matrix for 3D scene.
 
float m_focus
 Camera angle for 3D scene.
 
Math::Matrix m_shadowProjMat
 Projection matrix for rendering shadow maps.
 
Math::Matrix m_shadowViewMat
 View matrix for rendering shadow maps.
 
Math::Matrix m_shadowTextureMat
 Texture matrix for rendering shadow maps.
 
Math::Matrix m_shadowBias
 Texture bias for sampling shadow maps.
 
Math::Matrix m_matWorldInterface
 World matrix for 2D interface.
 
Math::Matrix m_matProjInterface
 Projection matrix for 2D interface.
 
Math::Matrix m_matViewInterface
 View matrix for 2D interface.
 
Math::IntPoint m_size
 Current size of viewport window.
 
std::vector< EngineBaseObjectm_baseObjects
 Base objects (also level 1 tier list)
 
std::vector< EngineObjectm_objects
 Object parameters.
 
std::vector< EngineShadowm_shadows
 Shadow list.
 
std::vector< EngineGroundSpotm_groundSpots
 Ground spot list.
 
EngineGroundMark m_groundMark
 Ground mark.
 
Math::Vector m_eyePt
 Location of camera.
 
Math::Vector m_lookatPt
 Camera target.
 
float m_eyeDirH
 
float m_eyeDirV
 
int m_rankView
 
Color m_ambientColor [2]
 
Color m_backColor [2]
 
Color m_fogColor [2]
 
float m_deepView [2]
 
float m_fogStart [2]
 
Color m_waterAddColor
 
int m_statisticTriangle
 
Math::Vector m_statisticPos
 
bool m_updateGeometry
 
bool m_updateStaticBuffers
 
int m_alphaMode
 
bool m_groundSpotVisible
 
bool m_shadowVisible
 
bool m_dirty
 
bool m_fog
 
bool m_firstGroundSpot
 
std::string m_secondTex
 
bool m_backgroundFull
 
std::string m_backgroundName
 
Texture m_backgroundTex
 
Color m_backgroundColorUp
 
Color m_backgroundColorDown
 
Color m_backgroundCloudUp
 
Color m_backgroundCloudDown
 
bool m_overFront
 
Color m_overColor
 
int m_overMode
 
std::string m_foregroundName
 
Texture m_foregroundTex
 
bool m_drawWorld
 
bool m_drawFront
 
float m_particleDensity
 
float m_clippingDistance
 
float m_lastClippingDistance
 
float m_objectDetail
 
float m_terrainVision
 
float m_gadgetQuantity
 
int m_textureQuality
 
bool m_totoMode
 
bool m_lensMode
 
bool m_waterMode
 
bool m_skyMode
 
bool m_backForce
 
bool m_planetMode
 
bool m_lightMode
 
bool m_editIndentMode
 
int m_editIndentValue
 
float m_tracePrecision
 
Texture m_shadowMap
 
int m_highlightRank [100]
 Ranks of highlighted objects.
 
bool m_highlight
 Highlight visible?
 
float m_highlightTime
 Time counter for highlight animation.
 
TextureCreateParams m_defaultTexParams
 Default texture create params.
 
TextureCreateParams m_terrainTexParams
 Create params for terrain textures.
 
int m_textureMipmapLevel
 Requested texture mipmap level.
 
int m_textureAnisotropy
 Requested texture anisotropy level.
 
bool m_shadowMapping
 true if shadow mapping enabled
 
bool m_offscreenShadowRendering
 true enables offscreen shadow rendering
 
bool m_qualityShadows
 true enables higher quality shadows
 
float m_shadowColor
 Shadow color.
 
std::map< std::string, Texturem_texNameMap
 Map of loaded textures (by name)
 
std::map< Texture, std::string > m_revTexNameMap
 Reverse map of loaded textures (by texture)
 
std::set< std::string > m_texBlacklist
 Blacklist map of textures. More...
 
EngineMouse m_mice [ENG_MOUSE_COUNT]
 Mouse cursor definitions.
 
Texture m_miceTexture
 Texture with mouse cursors.
 
Math::Point m_mouseSize
 Size of mouse cursor.
 
EngineMouseType m_mouseType
 Type of mouse cursor.
 
int m_lastState
 Last engine render state (-1 at the beginning of frame)
 
Color m_lastColor
 Last color set with render state.
 
std::string m_lastTexture [2]
 Last texture names for 2 used texture stages.
 
Material m_lastMaterial
 Last material.
 
bool m_interfaceMode
 True when drawing 2D UI.
 
bool m_debugLights
 
bool m_debugDumpLights
 
std::string m_timerText
 
Math::Point m_highlightP1
 Highlight rectangle points.
 
Math::Point m_highlightP2
 

Additional Inherited Members

- Static Public Member Functions inherited from CSingleton< CEngine >
static CEngine & GetInstance ()
 
static CEngine * GetInstancePointer ()
 
static bool IsCreated ()
 
- Static Protected Attributes inherited from CSingleton< CEngine >
static CEngine * m_instance
 

Detailed Description

The graphics engine.

This is the main class for graphics engine. It is responsible for drawing the 3D scene, setting various render states, and facilitating the drawing of 2D interface.

It uses a lower-level CDevice object which is implementation-independent core engine.

3D Scene

The 3D scene is drawn with view coordinates set from camera position in 3D space and a perspective projection matrix. The world matrix depends on the object drawn. The coordinate system is left-handed: X axis is to the right, Y axis to the top and Z axis is into the screen (Z = 0 is the sceen surface).

In general, the 3D scene is composed of the following things:

2D Interface

The 2D interface is drawn in fixed XY coordinates, independent from window size. Lower-left corner of the screen is (0,0) and upper-right corner is (1,1). Matrices for world, view and projection are therefore fixed and never change.

The class tracks the change of window coordinates and conversion functions between the window and interface coordinates are provided.

Interface drawing is delegated to CInterface class and particular controls are instances of CControl class. The source code for these classes is in src/ui directory.

Engine Objects

The 3D scene is composed of objects which are basically collections of triangles forming a surface or simply independent triangles in space.

Objects are uniquely identified by object rank obtained at object creation. Creating an object equals to allocating space for EngineObject structure which holds object parameters.

Object's geometric data is stored as a separate object – base engine object. Each object must reference a valid base engine object or an empty base engine object (with rank = -1). This many-to-one association allows to share same geometric data (e.g. from same model) across objects.

Base engine object data is stored in a 4-tier tree which splits the data describing triangles.

The 4 tiers contain the following information:

*NOTE: type of object in this context means only the internal type in 3D engine. It is not related to CObject types.

Last tier containing vertex data contains also an ID of static buffer holding the data. The static buffer is created and updated with new data as needed.

Such tiered structure complicates loops over all object data, but saves a lot of memory and optimizes the rendering process.

Shadows

Each engine object can be associated with a shadow (EngineShadow). Like objects, shadows are identified by their rank obtained upon creation.

Shadows are drawn as circular spots on the ground, except for shadows for worms, which have special mode for them.

Render States

Almost every primitive drawn on screen is drawn in state set through EngineRenderState enum. In some functions, custom modes are still set, using CDevice's SetRenderState. However, it will be subject to removal in the future. Generally, setting render states should be minimized to avoid unnecessary overhead.

Some states are clearly the result of legacy drawing and texturing methods. For example, TTEXTURE states should really be removed and the textures changed to ones with alpha channel. In the future, the whole modesetting code will probably be refactored to something more maintainable.

Textures

Textures are loaded from a texture subdir in data directory. In the old code, textures were identified by file name and loaded using some D3D util code. With new code and OpenGL backend, this approach is not efficient - name comparison, etc. takes a lot of time. In the future, textures should be loaded once at object creation time, and then referenced to as Texture structs, or even as unsigned int ID's which is what OpenGL actually wants. The old method is kept for now, with mapping between texture names and texture structs but it will also be subject to refactoring in the future.

Member Function Documentation

int Gfx::CEngine::DetectObject ( Math::Point  mouse)

Detects the target object that is selected with the mouse.

Returns the rank of the object or -1.

bool Gfx::CEngine::IsVisible ( int  objRank)
protected

Tests whether the given object is visible.

Use only after world transform already set.

void Gfx::CEngine::Render ( )

Called once per frame, the call is the entry point for rendering.

This function sets up render states, clears the viewport, and renders the scene.

void Gfx::CEngine::SetDeepView ( float  length,
int  rank = 0,
bool  ref = false 
)

Management of the depth of field.

Beyond this distance, nothing is visible. Shortly (according SetFogStart), one enters the fog.

void Gfx::CEngine::SetFocus ( float  focus)

Management of camera angle.

0.75 = normal 1.50 = wide-angle

void Gfx::CEngine::SetFogStart ( float  start,
int  rank = 0 
)

Management the start of fog.

With 0.0, the fog from the point of view (fog max). With 1.0, the fog from the depth of field (no fog).

bool Gfx::CEngine::SetTexture ( const std::string &  name,
int  stage = 0 
)

Sets texture for given stage; if not present in cache, the texture is loaded.

If loading fails, returns false.

bool Gfx::CEngine::TransformPoint ( Math::Vector p2D,
int  objRank,
Math::Vector  p3D 
)
protected

Transforms a 3D point (x, y, z) in 2D space (x, y, -) of the window.

The coordinated p2D.z gives the distance.

Math::Point Gfx::CEngine::WindowToInterfaceCoords ( Math::IntPoint  pos)

Conversion functions between window and interface coordinates.

Window coordinates are from top-left (0,0) to bottom-right (w,h) - size of window Interface cords are from bottom-left (0,0) to top-right (1,1) - and do not depend on window size

Math::Point Gfx::CEngine::WindowToInterfaceSize ( Math::IntPoint  size)

Conversion functions between window and interface sizes.

Unlike coordinate conversions, this is only scale conversion, not translation and scale.

Member Data Documentation

std::set<std::string> Gfx::CEngine::m_texBlacklist
protected

Blacklist map of textures.

Textures on this list were not successful in first loading, so are disabled for subsequent load calls.


The documentation for this class was generated from the following files: