GFXDevice

Engine/source/gfx/gfxDevice.h

GFXDevice is the TSE graphics interface layer.

More...

State tracking variables

enum
TexDirtyType {
  GFXTDT_Normal 
  GFXTDT_Cube 
  GFXTDT_CubeArray 
  GFXTDT_TextureArray 
}
bool

Set if ANY state is dirty, including matrices or primitive buffers.

mCurrentTexture [GFX_TEXTURE_STAGE_COUNT]
mNewTexture [GFX_TEXTURE_STAGE_COUNT]
mCurrentCubemap [GFX_TEXTURE_STAGE_COUNT]
mNewCubemap [GFX_TEXTURE_STAGE_COUNT]
mCurrentCubemapArray [GFX_TEXTURE_STAGE_COUNT]
mNewCubemapArray [GFX_TEXTURE_STAGE_COUNT]
mCurrentTextureArray [GFX_TEXTURE_STAGE_COUNT]
mNewTextureArray [GFX_TEXTURE_STAGE_COUNT]
mTexType [GFX_TEXTURE_STAGE_COUNT]
bool
mTextureDirty [GFX_TEXTURE_STAGE_COUNT]
bool

A global forced wireframe mode.

bool

The global vsync state.

The forced shader model version if non-zero.

bool

Disable all hardware occlusion queries causing them to return only the visibile state.

StateBlockMap 

Device management variables

Resource debug methods

fillResourceVectors(const char * resNames, bool unflaggedOnly, Vector< GFXResource * > & textureObjects, Vector< GFXResource * > & textureTargets, Vector< GFXResource * > & windowTargets, Vector< GFXResource * > & vertexBuffers, Vector< GFXResource * > & primitiveBuffers, Vector< GFXResource * > & fences, Vector< GFXResource * > & cubemaps, Vector< GFXResource * > & shaders, Vector< GFXResource * > & stateblocks)

This is a helper method for describeResourcesToFile.

listResources(bool unflaggedOnly)

Lists how many of each GFX resource (e.g.

Flags all resources GFX is currently aware of.

Clears the flag on all resources GFX is currently aware of.

describeResources(const char * resName, const char * file, bool unflaggedOnly)

Dumps a description of the specified resource types to the console.

Returns the current GFXDeviceStatistics, stats are cleared every ::beginScene call.

Matrix managing variables

Current frustum planes

Buffer Allocation

These methods are implemented per-device and are called by the GFX layer when a user calls an alloc

note:

Primitive Buffers are NOT implemented per device, they wrap index buffers

allocVertexBuffer(U32 numVerts, const GFXVertexFormat * vertexFormat, U32 vertSize, GFXBufferType bufferType, void * data)

This allocates a vertex buffer and returns a pointer to the allocated buffer.

Called from GFXVertexFormat to allocate the hardware specific vertex declaration for rendering.

Sets the current vertex declaration on the device.

Sets the vertex buffer on the device.

setVertexStreamFrequency(U32 stream, U32 frequency)

Set the vertex stream frequency on the device.

allocPrimitiveBuffer(U32 numIndices, U32 numPrimitives, GFXBufferType bufferType, void * data)

This allocates a primitive buffer and returns a pointer to the allocated buffer.

bool
mVertexBufferDirty [VERTEX_STREAM_COUNT]
mVertexBufferFrequency [VERTEX_STREAM_COUNT]
bool
mVertexBufferFrequencyDirty [VERTEX_STREAM_COUNT]

The maximum number of supported vertex streams which may be more than the device supports.

Rendering methods

clear(U32 flags, const LinearColorF & color, F32 z, U32 stencil)
bool
setVertexBuffer(GFXVertexBuffer * buffer, U32 stream, U32 frequency)

Sets the vertex buffer.

Sets the current vertex format.

drawPrimitive(GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount)
drawIndexedPrimitive(GFXPrimitiveType primType, U32 startVertex, U32 minIndex, U32 numVerts, U32 startIndex, U32 primitiveCount)

The parameters to drawIndexedPrimitive are somewhat complicated.

drawPrimitive(U32 primitiveIndex)

General state interface

Sets the dirty Render/Texture/Sampler states from the caching system

bool

Returns the forced global wireframe state.

bool

Returns true if the occlusion query is disabled.

updateStates(bool forceSetAll)

Stateblock functions

Called by GFXDevice to create a device specific stateblock.

setStateBlockInternal(GFXStateBlock * block, bool force)

Called by GFXDevice to actually set a stateblock.

State Initialization.

State initialization.

Debug Methods

enterDebugEvent(ColorI color, const char * name)
setDebugMarker(ColorI color, const char * name)
const char *
interpretDebugResult(long result)

Video Mode Functions

Enumerates the supported video modes of the device

Returns the video mode list.

selectSupportedFormat(GFXTextureProfile * profile, const Vector< GFXFormat > & formats, bool texture, bool mustblend, bool mustfilter)

Returns the first format from the list which meets all the criteria of the texture profile and query options.

Render Target functions

Allocate a target for doing render to texture operations, with no depth/stencil buffer.

Allocate a target for a given window.

Store the current render target to restore later.

Restore the previous render target.

setActiveRenderTarget(GFXTarget * target, bool updateViewport)

Assign a new active render target.

Returns the current active render target.

Shader functions

Returns the number of texture samplers that can be used in a shader rendering pass.

Returns the number of simultaneous render targets supported by the device.

setShader(GFXShader * shader, bool force)

Set the buffer! (Actual set happens on the next draw call, just like textures, state blocks, etc)

Creates a new empty shader which must be initialized and deleted by the caller.

Copying methods

Texture State Settings

NONE of these should be overridden by API implementations because of the state caching stuff.

State Block Interface

Creates a state block object based on the desc passed in.

Sets the current stateblock (actually activated in ::updateStates)

This sets a stateblock directly from the description structure.

Matrix interface

Sets the top of the world matrix stack.

Gets the matrix on the top of the world matrix stack.

Pushes the world matrix stack and copies the current top matrix to the new top of the stack.

Pops the world matrix stack.

Sets the projection matrix.

Gets the projection matrix.

Sets the view matrix.

Gets the view matrix.

Multiplies the matrix at the top of the world matrix stack by a matrix and replaces the top of the matrix stack with the result.

Set texture matrix for a sampler.

Set an area of the target to render to.

Get the current area of the target we will render to.

setFrustum(F32 left, F32 right, F32 bottom, F32 top, F32 nearPlane, F32 farPlane, bool bRotate)

Set the projection frustum.

setFrustum(const Frustum & frust, bool bRotate)
getFrustum(F32 * left, F32 * right, F32 * bottom, F32 * top, F32 * nearPlane, F32 * farPlane, bool * isOrtho)

Get the projection frustum.

Get the projection frustum.

setOrtho(F32 left, F32 right, F32 bottom, F32 top, F32 nearPlane, F32 farPlane, bool doRotate)

This will construct and apply an orthographic projection matrix with the provided parameters.

bool

Return true if the current frustum uses orthographic projection rather than perspective projection.

Public Types

enum
GenericShaderType {
  GSColor = 0
  GSTexture 
  GSModColorTexture 
  GSAddColorTexture 
  GSTargetRestore 
  GS_COUNT 
}
enum
GFXDeviceEventType {
  deCreate 
  deInit 
  deDestroy 
  deStartOfFrame 
  deEndOfFrame 
  dePostFrame 
  deStartOfField 
  deLeftStereoFrameRendered 
  deRightStereoFrameRendered 
  deEndOfField 
}
enum
GFXDeviceLimits {  NumStereoPorts = 2
}
enum
GFXDeviceRenderStyles {
  RS_Standard = 0
  RS_StereoSideBySide = (1<<0)
  RS_StereoSeparate = (1<<1)
}
DeviceEventSignal 

Private Attributes

Adapter for this device.

Protected Attributes

bool

Set if we're in a mode where we want rendering to occur.

bool

Set once the device is active.

The CardProfiler for this device.

The style of rendering that is to be performed, based on GFXDeviceRenderStyles.

The current render target which may or may not not be yet activated.

Current stereo target being rendered to.

mFovPorts [NumStereoPorts]

Fov port settings.

bool

This will allow querying to see if a device is initialized and ready to have operations performed on it.

mInverseStereoEyeTransforms [NumStereoPorts]

Inverse of mStereoEyeTransforms.

bool

Head of the resource list.

This tracks a previously activated render target which need to be deactivated.

bool

This is set when the current and/or deactivate render targets have changed and the device need to update its state on the next draw/clear.

A stack of previously active render targets.

mStereoEyeOffset [NumStereoPorts]

Eye offset used when using a stereo rendering style.

mStereoEyeTransforms [NumStereoPorts]

Left and right matrix for eyes.

Center matrix for head.

mStereoTargets [NumStereoPorts]

Destination targets for stereo rendering.

mStereoViewports [NumStereoPorts]

Destination viewports for stereo rendering.

List of valid video modes for this device.

The current viewport rect.

bool

If true the viewport has been changed and it must be updated on the next draw/clear.

Protected Functions

Updates the render targets and viewport in a device specific manner when they are dirty.

Notify GFXDevice that we are initialized.

This is called before this, or any other device, is deleted in the global destroy() method.

Set the adapter that this device is using. For use by GFXInit::createDevice only.

Called by base GFXDevice to actually set a const buffer.

Public Functions

Activates a stereo render target, setting the correct viewport to render eye contents.

bool
bool

Returns true if the scene has begun and its safe to make rendering calls.

Allocate a fence.

Returns a hardware occlusion query object or NULL if this device does not support them.

dumpStates(const char * fileName)

This is a method designed for debugging.

Returns the Adapter that was used to create this device.

Returns active graphics adapter type.

Retrieve the current rendering style based on GFXDeviceRenderStyles.

Retrieve the current stereo target being rendered to.

const Swizzle< U8, 3 > *

Swizzle to convert 24bpp bitmaps from RGB to the native device format.

const Swizzle< U8, 4 > *

Swizzle to convert 32bpp bitmaps from RGBA to the native device format.

Get access to this device's drawing utility class.

Get the fill convention for this device.

Get the current eye offset used during stereo rendering.

Get the current eye offset used during stereo rendering.

Returns the scale for converting world space units to screen space units...

Initialize this GFXDevice, optionally specifying a platform window to bind to.

setAllowRender(bool render)

Set the current rendering style, based on GFXDeviceRenderStyles.

Set the current stereo target being rendered to (in case we're doing anything with postfx)

Set the current eye offset used during stereo rendering.

Set the current eye offset used during stereo rendering. Assumes NumStereoPorts are available.

Sets the head matrix for stereo rendering.

Sets stereo render targets.

Sets stereo viewports.

This is a helper function to set a default shader for rendering GUI elements on systems which do not support fixed-function operations as well as for things which need just generic position/texture/color shaders.

Detailed Description

GFXDevice is the TSE graphics interface layer.

This allows the TSE to do many things, such as use multiple render devices for multi-head systems, and allow a game to render in DirectX 9, OpenGL or any other API which has a GFX implementation seamlessly. There are many concepts in GFX device which may not be familiar to you, especially if you have not used DirectX.
Buffers There are three types of buffers in GFX: vertex, index and primitive. Please note that index buffers are not accessable outside the GFX layer, they are wrapped by primitive buffers. Primitive buffers will be explained in detail later. Buffers are allocated and deallocated using their associated allocXBuffer and freeXBuffer methods on the device. When a buffer is allocated you pass in a pointer to, depending on the buffer, a vertex type pointer or a U16 pointer. During allocation, this pointer is set to the address of where you should copy in the information for this buffer. You must the tell the GFXDevice that the information is in, and it should prepare the buffer for use by calling the prepare method on it. Dynamic vertex buffer example:

GFXVertexP *verts;        // Making a buffer containing verticies with only position

// Allocate a dynamic vertex buffer to hold 3 vertices and use *verts as the location to copy information into
GFXVertexBufferHandle vb = GFX->allocVertexBuffer( 3, &verts, true ); 

// Now set the information, we're making a triangle
verts[0].point = Point3F( 200.f, 200.f, 0.f );
verts[1].point = Point3F( 200.f, 400.f, 0.f );
verts[2].point = Point3F( 400.f, 200.f, 0.f );

// Tell GFX that the information is in and it should be made ready for use
// Note that nothing is done with verts, this should not and MUST NOT be deleted
// stored, or otherwise used after prepare is called.
GFX->prepare( vb );

// Because this is a dynamic vertex buffer, it is only assured to be valid until someone 
// else allocates a dynamic vertex buffer, so we will render it now
GFX->setVertexBuffer( vb );
GFX->drawPrimitive( GFXTriangleStrip, 0, 1 );

// Now because this is a dynamic vertex buffer it MUST NOT BE FREED you are only
// given a handle to a vertex buffer which belongs to the device

To use a static vertex buffer, it is very similar, this is an example using a static primitive buffer:
This takes place inside a constructor for a class which has a member variable called mPB which is the primitive buffer for the class instance.

U16 *idx;                          // This is going to be where to write indices
GFXPrimitiveInfo *primitiveInfo;   // This will be where to write primitive information

// Allocate a primitive buffer with 4 indices, and 1 primitive described for use
mPB = GFX->allocPrimitiveBuffer( 4, &idx, 1, &primitiveInfo );

// Write the index information, this is going to be for the outline of a triangle using
// a line strip
idx[0] = 0;
idx[1] = 1;
idx[2] = 2;
idx[3] = 0;

// Write the information for the primitive
primitiveInfo->indexStart = 0;            // Starting with index 0
primitiveInfo->minVertex = 0;             // The minimum vertex index is 0
primitiveInfo->maxVertex = 3;             // The maximum vertex index is 3
primitiveInfo->primitiveCount = 3;        // There are 3 lines we are drawing
primitiveInfo->type = GFXLineStrip;       // This primitive info describes a line strip
The following code takes place in the destructor for the same class
// Because this is a static buffer it's our responsibility to free it when we are done
GFX->freePrimitiveBuffer( mPB );
This last bit takes place in the rendering function for the class
// You need to set a vertex buffer as well, primitive buffers contain indexing
// information, not vertex information. This is so you could have, say, a static
// vertex buffer, and a dynamic primitive buffer.

// This sets the primitive buffer to the static buffer we allocated in the constructor
GFX->setPrimitiveBuffer( mPB );

// Draw the first primitive contained in the set primitive buffer, our primitive buffer
// has only one primitive, so we could also technically call GFX->drawPrimitives(); and
// get the same result. 
GFX->drawPrimitive( 0 );
If you need any more examples on how to use these buffers please see the rest of the engine.
Primitive Buffers
Primitive buffers wrap and extend the concept of index buffers. The purpose of a primitive buffer is to let objects store all information they have to render their primitives in a central place. Say that a shape is made up of triangle strips and triangle fans, it would still have only one primitive buffer which contained primitive information for each strip and fan. It could then draw itself with one call.

TO BE FINISHED LATER

State tracking variables

TexDirtyType

Enumerator

GFXTDT_Normal
GFXTDT_Cube
GFXTDT_CubeArray
GFXTDT_TextureArray
bool mStateDirty 

Set if ANY state is dirty, including matrices or primitive buffers.

GFXTexHandle mCurrentTexture [GFX_TEXTURE_STAGE_COUNT]
GFXTexHandle mNewTexture [GFX_TEXTURE_STAGE_COUNT]
GFXCubemapHandle mCurrentCubemap [GFX_TEXTURE_STAGE_COUNT]
GFXCubemapHandle mNewCubemap [GFX_TEXTURE_STAGE_COUNT]
GFXCubemapArrayHandle mCurrentCubemapArray [GFX_TEXTURE_STAGE_COUNT]
GFXCubemapArrayHandle mNewCubemapArray [GFX_TEXTURE_STAGE_COUNT]
GFXTextureArrayHandle mCurrentTextureArray [GFX_TEXTURE_STAGE_COUNT]
GFXTextureArrayHandle mNewTextureArray [GFX_TEXTURE_STAGE_COUNT]
TexDirtyType mTexType [GFX_TEXTURE_STAGE_COUNT]
bool mTextureDirty [GFX_TEXTURE_STAGE_COUNT]
bool mTexturesDirty 
StateBlockMap mCurrentStateBlocks 
bool mStateBlockDirty 
GFXStateBlockRef mCurrentStateBlock 
GFXStateBlockRef mNewStateBlock 
GFXShaderConstBuffer * mCurrentShaderConstBuffer 
bool smWireframe 

A global forced wireframe mode.

bool smDisableVSync 

The global vsync state.

F32 smForcedPixVersion 

The forced shader model version if non-zero.

bool smDisableOcclusionQuery 

Disable all hardware occlusion queries causing them to return only the visibile state.

typedef Map< U32, GFXStateBlockRef > StateBlockMap 

Device management variables

GFXDevice * smGFXDevice 

Global GFXDevice.

Resource debug methods

fillResourceVectors(const char * resNames, bool unflaggedOnly, Vector< GFXResource * > & textureObjects, Vector< GFXResource * > & textureTargets, Vector< GFXResource * > & windowTargets, Vector< GFXResource * > & vertexBuffers, Vector< GFXResource * > & primitiveBuffers, Vector< GFXResource * > & fences, Vector< GFXResource * > & cubemaps, Vector< GFXResource * > & shaders, Vector< GFXResource * > & stateblocks)

This is a helper method for describeResourcesToFile.

It walks through the GFXResource list and sorts it by item type, putting the resources into the proper vector.

listResources(bool unflaggedOnly)

Lists how many of each GFX resource (e.g.

textures, texture targets, shaders, etc.) GFX is aware of Parameters:

unflaggedOnly

If true, this method only counts unflagged resources

flagCurrentResources()

Flags all resources GFX is currently aware of.

clearResourceFlags()

Clears the flag on all resources GFX is currently aware of.

describeResources(const char * resName, const char * file, bool unflaggedOnly)

Dumps a description of the specified resource types to the console.

Parameters:

resNames

A string of space separated class names (e.g. "GFXTextureObject GFXTextureTarget GFXShader") to describe to the console

file

A path to the file to write the descriptions to. If it is NULL or "", descriptions are written to the console.

unflaggedOnly

If true, this method only counts unflagged resources

note:

resNames is case sensitive because there is no dStristr function.

getDeviceStatistics()

Returns the current GFXDeviceStatistics, stats are cleared every ::beginScene call.

GFXDeviceStatistics mDeviceStatistics 

Matrix managing variables

MatrixF mWorldMatrix [GFX_WORLD_STACK_MAX]
S32 mWorldStackSize 
MatrixF mProjectionMatrix 
MatrixF mViewMatrix 

Current frustum planes

Frustum mFrustum 

Buffer Allocation

These methods are implemented per-device and are called by the GFX layer when a user calls an alloc

note:

Primitive Buffers are NOT implemented per device, they wrap index buffers

allocVertexBuffer(U32 numVerts, const GFXVertexFormat * vertexFormat, U32 vertSize, GFXBufferType bufferType, void * data)

This allocates a vertex buffer and returns a pointer to the allocated buffer.

This function should not be called directly - rather it should be used by the GFXVertexBufferHandle class.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

allocVertexDecl(const GFXVertexFormat * vertexFormat)

Called from GFXVertexFormat to allocate the hardware specific vertex declaration for rendering.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

setVertexDecl(const GFXVertexDecl * decl)

Sets the current vertex declaration on the device.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

setVertexStream(U32 stream, GFXVertexBuffer * buffer)

Sets the vertex buffer on the device.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

setVertexStreamFrequency(U32 stream, U32 frequency)

Set the vertex stream frequency on the device.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

allocPrimitiveBuffer(U32 numIndices, U32 numPrimitives, GFXBufferType bufferType, void * data)

This allocates a primitive buffer and returns a pointer to the allocated buffer.

A primitive buffer's type argument refers to the index data - the primitive data will always be preserved from call to call.

note:

All index buffers use unsigned 16-bit indices.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

StrongRefPtr< GFXVertexBuffer > mCurrentVertexBuffer [VERTEX_STREAM_COUNT]
bool mVertexBufferDirty [VERTEX_STREAM_COUNT]
U32 mVertexBufferFrequency [VERTEX_STREAM_COUNT]
bool mVertexBufferFrequencyDirty [VERTEX_STREAM_COUNT]
const GFXVertexDecl * mCurrVertexDecl 
bool mVertexDeclDirty 
StrongRefPtr< GFXPrimitiveBuffer > mCurrentPrimitiveBuffer 
bool mPrimitiveBufferDirty 
const U32 VERTEX_STREAM_COUNT 

The maximum number of supported vertex streams which may be more than the device supports.

Texture functions

createCubemap()

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

createCubemapArray()

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

createTextureArray()

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

getTextureManager()

GFXTextureManager * mTextureManager 

Rendering methods

clear(U32 flags, const LinearColorF & color, F32 z, U32 stencil)

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

clearColorAttachment(const U32 attachment, const LinearColorF & color)

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

beginScene()

endScene()

beginField()

endField()

setPrimitiveBuffer(GFXPrimitiveBuffer * buffer)

setVertexBuffer(GFXVertexBuffer * buffer, U32 stream, U32 frequency)

Sets the vertex buffer.

When setting the stream 0 vertex buffer it will automatically set its associated vertex format as the active format.

Parameters:

buffer

The vertex buffer or NULL to clear the buffer.

stream

The stream index of the vertex source stream to place the buffer.

frequency

The stream frequency of the vertex buffer.

setVertexFormat(const GFXVertexFormat * vertexFormat)

Sets the current vertex format.

This should only be used if the vertex format of the stream 0 vertex buffer is different from the one associated to it. Typically this is used when rendering from multiple vertex streams.

drawPrimitive(GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount)

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

drawIndexedPrimitive(GFXPrimitiveType primType, U32 startVertex, U32 minIndex, U32 numVerts, U32 startIndex, U32 primitiveCount)

The parameters to drawIndexedPrimitive are somewhat complicated.

From a raw-data stand point they evaluate to something like the following:

U16 indicies[] = { 0, 1, 2, 1, 0, 0, 2 }; 
Point3F verts[] = { Point3F( 0.0f, 0.0f, 0.0f ), Point3F( 0.0f, 1.0f, 0.0f ), Point3F( 0.0f, 0.0f, 1.0f ) };

GFX->drawIndexedPrimitive( GFXLineList, // Drawing a list of lines, each line is two verts
                           0, // vertex 0 will be referenced so minIndex = 0
                           3, // 3 verticies will be used for this draw call
                           1, // We want index 1 to be the first index used, so indicies 1-6 will be used
                           3  // Drawing 3 LineList primitives, meaning 6 verts will be drawn
                            );

U16 *idxPtr = &indicies[1];  // 1 = startIndex, so the pointer is offset such that:
                             //    idxPtr[0] is the same as indicies[1]

U32 numVertsToDrawFromBuffer = primitiveCount * 2; // 2 verts define a line in the GFXLineList primitive type (6)

Parameters:

primType

Type of primitive to draw

startVertex

This defines index zero. Its the offset from the start of the vertex buffer to the first vertex.

minIndex

The smallest index into the vertex stream which will be used for this draw call. This is a zero based index relative to startVertex. It is strictly a performance hint for implementations. No vertex below minIndex will be referenced by this draw call. For device implementors, this should not be used to offset the vertex buffer, or index buffer.

numVerts

The number of verticies which will be referenced in this draw call. This is not the number of verticies which will be drawn. That is a function of 'primType' and 'primitiveCount'.

startIndex

An offset from the start of the index buffer to specify where to start. If 'idxBuffer' is a pointer to an array of integers, this could be written as int *offsetIdx = idxBuffer + startIndex;

primitiveCount

The number of primitives of type 'primType' to draw.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

drawPrimitive(const GFXPrimitive & prim)

drawPrimitive(U32 primitiveIndex)

drawPrimitives()

PlatformTimer * mFrameTime 

General state interface

Sets the dirty Render/Texture/Sampler states from the caching system

getWireframe()

Returns the forced global wireframe state.

getDisableOcclusionQuery()

Returns true if the occlusion query is disabled.

updateStates(bool forceSetAll)

clearTextureStateImmediate(U32 stage)

Stateblock functions

createStateBlockInternal(const GFXStateBlockDesc & desc)

Called by GFXDevice to create a device specific stateblock.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

setStateBlockInternal(GFXStateBlock * block, bool force)

Called by GFXDevice to actually set a stateblock.

Parameters:

force

If true, set all states

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

State Initialization.

initStates()

State initialization.

This MUST BE CALLED in setVideoMode after the device is created.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

Debug Methods

enterDebugEvent(ColorI color, const char * name)

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

leaveDebugEvent()

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

setDebugMarker(ColorI color, const char * name)

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

interpretDebugResult(long result)

Reimplemented by: GFXD3D11Device, GFXGLDevice

Video Mode Functions

Enumerates the supported video modes of the device

enumerateVideoModes()

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

getVideoModeList()

Returns the video mode list.

selectSupportedFormat(GFXTextureProfile * profile, const Vector< GFXFormat > & formats, bool texture, bool mustblend, bool mustfilter)

Returns the first format from the list which meets all the criteria of the texture profile and query options.


Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

Render Target functions

allocRenderToTextureTarget(bool genMips)

Allocate a target for doing render to texture operations, with no depth/stencil buffer.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

allocWindowTarget(PlatformWindow * window)

Allocate a target for a given window.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

pushActiveRenderTarget()

Store the current render target to restore later.

popActiveRenderTarget()

Restore the previous render target.

setActiveRenderTarget(GFXTarget * target, bool updateViewport)

Assign a new active render target.

getActiveRenderTarget()

Returns the current active render target.

Shader functions

getPixelShaderVersion()

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

setPixelShaderVersion(F32 version)

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

getNumSamplers()

Returns the number of texture samplers that can be used in a shader rendering pass.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

getNumRenderTargets()

Returns the number of simultaneous render targets supported by the device.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

setShader(GFXShader * shader, bool force)

Reimplemented by: GFXD3D11Device, GFXGLDevice

setShaderConstBuffer(GFXShaderConstBuffer * buffer)

Set the buffer! (Actual set happens on the next draw call, just like textures, state blocks, etc)

createShader()

Creates a new empty shader which must be initialized and deleted by the caller.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

Copying methods

copyResource(GFXTextureObject * pDst, GFXCubemap * pSrc, const U32 face)

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

Texture State Settings

NONE of these should be overridden by API implementations because of the state caching stuff.

setTexture(U32 stage, GFXTextureObject * texture)

setCubeTexture(U32 stage, GFXCubemap * cubemap)

setCubeArrayTexture(U32 stage, GFXCubemapArray * cubemapArray)

setTextureArray(U32 stage, GFXTextureArray * textureArray)

getCurrentTexture(U32 stage)

State Block Interface

createStateBlock(const GFXStateBlockDesc & desc)

Creates a state block object based on the desc passed in.

This object represents an immutable state.

setStateBlock(GFXStateBlock * block)

Sets the current stateblock (actually activated in ::updateStates)

getStateBlock()

setStateBlockByDesc(const GFXStateBlockDesc & desc)

This sets a stateblock directly from the description structure.

Its acceptable to use this for debug rendering and other low frequency rendering tasks.

Matrix interface

setWorldMatrix(const MatrixF & newWorld)

Sets the top of the world matrix stack.

Parameters:

newWorld

New world matrix to set

getWorldMatrix()

Gets the matrix on the top of the world matrix stack.

pushWorldMatrix()

Pushes the world matrix stack and copies the current top matrix to the new top of the stack.

popWorldMatrix()

Pops the world matrix stack.

setProjectionMatrix(const MatrixF & newProj)

Sets the projection matrix.

Parameters:

newProj

New projection matrix to set

getProjectionMatrix()

Gets the projection matrix.

setViewMatrix(const MatrixF & newView)

Sets the view matrix.

Parameters:

newView

New view matrix to set

getViewMatrix()

Gets the view matrix.

multWorld(const MatrixF & mat)

Multiplies the matrix at the top of the world matrix stack by a matrix and replaces the top of the matrix stack with the result.

Parameters:

mat

Matrix to multiply

setTextureMatrix(const U32 stage, const MatrixF & texMat)

Set texture matrix for a sampler.

setViewport(const RectI & rect)

Set an area of the target to render to.

getViewport()

Get the current area of the target we will render to.

setClipRect(const RectI & rect)

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

getClipRect()

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

setFrustum(F32 left, F32 right, F32 bottom, F32 top, F32 nearPlane, F32 farPlane, bool bRotate)

Set the projection frustum.

setFrustum(const Frustum & frust, bool bRotate)

getFrustum(F32 * left, F32 * right, F32 * bottom, F32 * top, F32 * nearPlane, F32 * farPlane, bool * isOrtho)

Get the projection frustum.

getFrustum()

Get the projection frustum.

setOrtho(F32 left, F32 right, F32 bottom, F32 top, F32 nearPlane, F32 farPlane, bool doRotate)

This will construct and apply an orthographic projection matrix with the provided parameters.

Parameters:

doRotate

If set to true, the resulting matrix will be rotated PI/2 around the X axis

isFrustumOrtho()

Return true if the current frustum uses orthographic projection rather than perspective projection.

Public Types

GenericShaderType

Enumerator

GSColor = 0
GSTexture
GSModColorTexture
GSAddColorTexture
GSTargetRestore
GS_COUNT
GFXDeviceEventType

Enumerator

deCreate

The device has been created, but not initialized.

deInit

The device has been initialized.

deDestroy

The device is about to be destroyed.

deStartOfFrame

The device has started rendering a frame.

deEndOfFrame

The device is about to finish rendering a frame.

dePostFrame

The device has rendered a frame and ended the scene.

deStartOfField

The device has started rendering a frame's field (such as for side-by-side rendering)

deLeftStereoFrameRendered

left stereo frame has been rendered

deRightStereoFrameRendered

right stereo frame has been rendered

deEndOfField

The device is about to finish rendering a frame's field.

GFXDeviceLimits

Enumerator

NumStereoPorts = 2
GFXDeviceRenderStyles

Enumerator

RS_Standard = 0
RS_StereoSideBySide = (1<<0)
RS_StereoSeparate = (1<<1)
typedef Signal< bool(GFXDeviceEventType)> DeviceEventSignal 

Public Friends

Private Attributes

GFXAdapter mAdapter 

Adapter for this device.

Protected Attributes

bool mAllowRender 

Set if we're in a mode where we want rendering to occur.

bool mCanCurrentlyRender 

Set once the device is active.

GFXCardProfiler * mCardProfiler 

The CardProfiler for this device.

U32 mCurrentRenderStyle 

The style of rendering that is to be performed, based on GFXDeviceRenderStyles.

GFXTargetRef mCurrentRT 

The current render target which may or may not not be yet activated.

S32 mCurrentStereoTarget 

Current stereo target being rendered to.

Swizzle< U8, 3 > * mDeviceSwizzle24 

Swizzle< U8, 4 > * mDeviceSwizzle32 

GFXDrawUtil * mDrawer 
FovPort mFovPorts [NumStereoPorts]

Fov port settings.

bool mInitialized 

This will allow querying to see if a device is initialized and ready to have operations performed on it.

MatrixF mInverseStereoEyeTransforms [NumStereoPorts]

Inverse of mStereoEyeTransforms.

bool mReset 
GFXResource * mResourceListHead 

Head of the resource list.

GFXTargetRef mRTDeactivate 

This tracks a previously activated render target which need to be deactivated.


bool mRTDirty 

This is set when the current and/or deactivate render targets have changed and the device need to update its state on the next draw/clear.

Vector< GFXTargetRef > mRTStack 

A stack of previously active render targets.

Point3F mStereoEyeOffset [NumStereoPorts]

Eye offset used when using a stereo rendering style.

MatrixF mStereoEyeTransforms [NumStereoPorts]

Left and right matrix for eyes.

MatrixF mStereoHeadTransform 

Center matrix for head.

GFXTextureTarget * mStereoTargets [NumStereoPorts]

Destination targets for stereo rendering.

RectI mStereoViewports [NumStereoPorts]

Destination viewports for stereo rendering.

Vector< GFXVideoMode > mVideoModes 

List of valid video modes for this device.

RectI mViewport 

The current viewport rect.

bool mViewportDirty 

If true the viewport has been changed and it must be updated on the next draw/clear.

Public Static Functions

destroy()

devicePresent()

get()

getDeviceEventSignal()

initConsole()

Protected Functions

_updateRenderTargets()

Updates the render targets and viewport in a device specific manner when they are dirty.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

beginSceneInternal()

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

deviceInited()

Notify GFXDevice that we are initialized.

endSceneInternal()

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

preDestroy()

This is called before this, or any other device, is deleted in the global destroy() method.

It allows the device to clean up anything while everything is still valid.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

setAdapter(const GFXAdapter & adapter)

Set the adapter that this device is using. For use by GFXInit::createDevice only.

setShaderConstBufferInternal(GFXShaderConstBuffer * buffer)

Called by base GFXDevice to actually set a const buffer.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

setTextureInternal(U32 textureUnit, const GFXTextureObject * texture)

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

Public Functions

GFXDevice()

~GFXDevice()

activateStereoTarget(S32 eyeId)

Activates a stereo render target, setting the correct viewport to render eye contents.

If eyeId is -1, set a viewport encompassing the entire size of the render targets.

allowRender()

beginReset()

canCurrentlyRender()

Returns true if the scene has begun and its safe to make rendering calls.

createFence()

Allocate a fence.

The API specific implementation of GFXDevice is responsible to make sure that the proper type is used. GFXGeneralFence should work in all cases.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

createOcclusionQuery()

Returns a hardware occlusion query object or NULL if this device does not support them.


Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

doParanoidStateCheck()

Reimplemented by: GFXD3D11Device

dumpStates(const char * fileName)

This is a method designed for debugging.

It will allow you to dump the states in the render manager out to a file so that it can be diffed and examined.

finalizeReset()

getAdapter()

Returns the Adapter that was used to create this device.

getAdapterType()

Returns active graphics adapter type.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

getCardProfiler()

getCurrentRenderStyle()

Retrieve the current rendering style based on GFXDeviceRenderStyles.

getCurrentStereoTarget()

Retrieve the current stereo target being rendered to.

getDeviceSwizzle24()

Swizzle to convert 24bpp bitmaps from RGB to the native device format.

getDeviceSwizzle32()

Swizzle to convert 32bpp bitmaps from RGBA to the native device format.

getDrawUtil()

Get access to this device's drawing utility class.

getFillConventionOffset()

Get the fill convention for this device.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

getInverseStereoEyeTransforms()

getMaxDynamicIndices()

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

getMaxDynamicVerts()

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

getStereoEyeOffsets()

Get the current eye offset used during stereo rendering.

getStereoEyeTransforms()

getStereoFovPort()

Get the current eye offset used during stereo rendering.

getStereoHeadTransform()

getStereoViewports()

getWorldToScreenScale()

Returns the scale for converting world space units to screen space units...

aka pixels.

This is the true scale which is best used for GUI drawing. For doing lod calculations you should be using the functions in SceneState which is adjusted for special cases like shadows and reflections.

see:

SceneState::getWorldToScreenScale()

see:

SceneState::projectRadius()

init(const GFXVideoMode & mode, PlatformWindow * window)

Initialize this GFXDevice, optionally specifying a platform window to bind to.

Reimplemented by: GFXD3D11Device, GFXGLDevice, GFXNullDevice

recentlyReset()

setAllowRender(bool render)

setCurrentRenderStyle(U32 style)

Set the current rendering style, based on GFXDeviceRenderStyles.

setCurrentStereoTarget(const F32 targetId)

Set the current stereo target being rendered to (in case we're doing anything with postfx)

setStereoEyeOffsets(Point3F * offsets)

Set the current eye offset used during stereo rendering.

setStereoEyeTransforms(MatrixF * transforms)

setStereoFovPort(const FovPort * ports)

Set the current eye offset used during stereo rendering. Assumes NumStereoPorts are available.

setStereoHeadTransform(const MatrixF & mat)

Sets the head matrix for stereo rendering.

setStereoTargets(GFXTextureTarget ** targets)

Sets stereo render targets.

setSteroViewports(const RectI * ports)

Sets stereo viewports.

setupGenericShaders(GenericShaderType type)

This is a helper function to set a default shader for rendering GUI elements on systems which do not support fixed-function operations as well as for things which need just generic position/texture/color shaders.

Parameters:

type

Type of generic shader, add your own if you need

Reimplemented by: GFXD3D11Device, GFXGLDevice