Direct3D11 Engine/source changes

This commit is contained in:
rextimmy 2016-03-20 21:52:11 +10:00
parent 3a9b50f702
commit 41e5caf22b
81 changed files with 1291 additions and 617 deletions

View file

@ -826,6 +826,7 @@ GFXVertexBuffer * GFXD3D9Device::allocVertexBuffer( U32 numVerts,
switch(bufferType)
{
case GFXBufferTypeImmutable:
case GFXBufferTypeStatic:
pool = isD3D9Ex() ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
break;

View file

@ -1307,10 +1307,15 @@ void GFXD3D9Shader::_buildSamplerShaderConstantHandles( Vector<GFXShaderConstDes
void GFXD3D9Shader::_buildInstancingShaderConstantHandles()
{
// If we have no instancing than just return
if (!mInstancingFormat)
return;
U32 offset = 0;
for ( U32 i=0; i < mInstancingFormat.getElementCount(); i++ )
for ( U32 i=0; i < mInstancingFormat->getElementCount(); i++ )
{
const GFXVertexElement &element = mInstancingFormat.getElement( i );
const GFXVertexElement &element = mInstancingFormat->getElement( i );
String constName = String::ToString( "$%s", element.getSemantic().c_str() );
@ -1347,9 +1352,9 @@ void GFXD3D9Shader::_buildInstancingShaderConstantHandles()
// If this is a matrix we will have 2 or 3 more of these
// semantics with the same name after it.
for ( ; i < mInstancingFormat.getElementCount(); i++ )
for ( ; i < mInstancingFormat->getElementCount(); i++ )
{
const GFXVertexElement &nextElement = mInstancingFormat.getElement( i );
const GFXVertexElement &nextElement = mInstancingFormat->getElement( i );
if ( nextElement.getSemantic() != element.getSemantic() )
{
i--;

View file

@ -55,6 +55,7 @@ void GFXD3D9VertexBuffer::lock(U32 vertexStart, U32 vertexEnd, void **vertexPtr)
switch( mBufferType )
{
case GFXBufferTypeImmutable:
case GFXBufferTypeStatic:
break;
@ -203,7 +204,7 @@ void GFXD3D9VertexBuffer::zombify()
{
AssertFatal(lockedVertexStart == 0 && lockedVertexEnd == 0, "GFXD3D9VertexBuffer::zombify - Cannot zombify a locked buffer!");
// Static buffers are managed by D3D9 so we don't deal with them.
if(mBufferType == GFXBufferTypeDynamic)
if(mBufferType == GFXBufferTypeDynamic || mBufferType == GFXBufferTypeImmutable)
{
SAFE_RELEASE(vb);
}

View file

@ -302,7 +302,6 @@ void GFXD3D9EnumTranslate::init()
GFXD3D9PrimType[GFXLineStrip] = D3DPT_LINESTRIP;
GFXD3D9PrimType[GFXTriangleList] = D3DPT_TRIANGLELIST;
GFXD3D9PrimType[GFXTriangleStrip] = D3DPT_TRIANGLESTRIP;
GFXD3D9PrimType[GFXTriangleFan] = D3DPT_TRIANGLEFAN;
VALIDATE_LOOKUPTABLE( GFXD3D9PrimType, GFXPT );
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

View file

@ -514,7 +514,7 @@ void GFXPCD3D9Device::init( const GFXVideoMode &mode, PlatformWindow *window /*
mCardProfiler = new GFXD3D9CardProfiler(mAdapterIndex);
mCardProfiler->init();
gScreenShot = new ScreenShotD3D;
gScreenShot = new ScreenShotD3D9;
// Set the video capture frame grabber.
mVideoFrameGrabber = new VideoFrameGrabberD3D9();

View file

@ -30,7 +30,7 @@
#include <d3dx9tex.h>
GBitmap* ScreenShotD3D::_captureBackBuffer()
GBitmap* ScreenShotD3D9::_captureBackBuffer()
{
#ifdef TORQUE_OS_XENON
return NULL;

View file

@ -19,15 +19,15 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _SCREENSHOTD3D_H_
#define _SCREENSHOTD3D_H_
#ifndef _SCREENSHOTD3D9_H_
#define _SCREENSHOTD3D9_H_
#include "gfx/screenshot.h"
//**************************************************************************
// D3D implementation of screenshot
//**************************************************************************
class ScreenShotD3D : public ScreenShot
class ScreenShotD3D9 : public ScreenShot
{
protected:
@ -36,4 +36,4 @@ protected:
};
#endif // _SCREENSHOTD3D_H_
#endif // _SCREENSHOTD3D9_H_

View file

@ -106,7 +106,7 @@ public:
virtual ~GenericConstBufferLayout() {}
/// Add a parameter to the buffer
void addParameter(const String& name, const GFXShaderConstType constType, const U32 offset, const U32 size, const U32 arraySize, const U32 alignValue);
virtual void addParameter(const String& name, const GFXShaderConstType constType, const U32 offset, const U32 size, const U32 arraySize, const U32 alignValue);
/// Get the size of the buffer
inline U32 getBufferSize() const { return mBufferSize; }
@ -210,6 +210,9 @@ public:
/// state at the same time.
inline const U8* getDirtyBuffer( U32 *start, U32 *size );
/// Gets the entire buffer ignoring dirty range
inline const U8* getEntireBuffer();
/// Sets the entire buffer as dirty or clears the dirty state.
inline void setDirty( bool dirty );
@ -348,6 +351,13 @@ inline const U8* GenericConstBuffer::getDirtyBuffer( U32 *start, U32 *size )
return buffer;
}
inline const U8* GenericConstBuffer::getEntireBuffer()
{
AssertFatal(mBuffer, "GenericConstBuffer::getDirtyBuffer() - Buffer is empty!");
return mBuffer;
}
inline bool GenericConstBuffer::isEqual( const GenericConstBuffer *buffer ) const
{
U32 bsize = mLayout->getBufferSize();

View file

@ -41,7 +41,7 @@ ImplementEnumType( GFXAdapterType,
"Back-end graphics API used by the GFX subsystem.\n\n"
"@ingroup GFX" )
{ OpenGL, "OpenGL", "OpenGL." },
{ Direct3D8, "D3D8", "Direct3D 8." },
{ Direct3D11, "D3D11", "Direct3D 11." },
{ Direct3D9, "D3D9", "Direct3D 9." },
{ NullDevice, "NullDevice", "Null device for dedicated servers." },
{ Direct3D9_360, "Xenon", "Direct3D 9 on Xbox 360." }

View file

@ -514,6 +514,8 @@ void GFXDevice::updateStates(bool forceSetAll /*=false*/)
mStateBlockDirty = false;
}
_updateRenderTargets();
if( mTexturesDirty )
{
mTexturesDirty = false;

View file

@ -458,7 +458,7 @@ void GFXDrawUtil::drawRect( const Point2F &upperLeft, const Point2F &lowerRight,
Point2F nw(-0.5f,-0.5f); /* \ */
Point2F ne(0.5f,-0.5f); /* / */
GFXVertexBufferHandle<GFXVertexPC> verts (mDevice, 10, GFXBufferTypeVolatile );
GFXVertexBufferHandle<GFXVertexPCT> verts (mDevice, 10, GFXBufferTypeVolatile );
verts.lock();
F32 ulOffset = 0.5f - mDevice->getFillConventionOffset();
@ -521,12 +521,12 @@ void GFXDrawUtil::drawRectFill( const Point2F &upperLeft, const Point2F &lowerRi
Point2F nw(-0.5,-0.5); /* \ */
Point2F ne(0.5,-0.5); /* / */
GFXVertexBufferHandle<GFXVertexPC> verts(mDevice, 4, GFXBufferTypeVolatile);
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, 4, GFXBufferTypeVolatile);
verts.lock();
F32 ulOffset = 0.5f - mDevice->getFillConventionOffset();
verts[0].point.set( upperLeft.x + nw.x + ulOffset, upperLeft.y + nw.y + ulOffset, 0.0f);
verts[0].point.set( upperLeft.x+nw.x + ulOffset, upperLeft.y+nw.y + ulOffset, 0.0f );
verts[1].point.set( lowerRight.x + ne.x + ulOffset, upperLeft.y + ne.y + ulOffset, 0.0f);
verts[2].point.set( upperLeft.x - ne.x + ulOffset, lowerRight.y - ne.y + ulOffset, 0.0f);
verts[3].point.set( lowerRight.x - nw.x + ulOffset, lowerRight.y - nw.y + ulOffset, 0.0f);
@ -548,7 +548,7 @@ void GFXDrawUtil::draw2DSquare( const Point2F &screenPoint, F32 width, F32 spinA
Point3F offset( screenPoint.x, screenPoint.y, 0.0 );
GFXVertexBufferHandle<GFXVertexPC> verts( mDevice, 4, GFXBufferTypeVolatile );
GFXVertexBufferHandle<GFXVertexPCT> verts( mDevice, 4, GFXBufferTypeVolatile );
verts.lock();
verts[0].point.set( -width, -width, 0.0f );
@ -608,7 +608,7 @@ void GFXDrawUtil::drawLine( F32 x1, F32 y1, F32 x2, F32 y2, const ColorI &color
void GFXDrawUtil::drawLine( F32 x1, F32 y1, F32 z1, F32 x2, F32 y2, F32 z2, const ColorI &color )
{
GFXVertexBufferHandle<GFXVertexPC> verts( mDevice, 2, GFXBufferTypeVolatile );
GFXVertexBufferHandle<GFXVertexPCT> verts( mDevice, 2, GFXBufferTypeVolatile );
verts.lock();
verts[0].point.set( x1, y1, z1 );
@ -647,7 +647,7 @@ void GFXDrawUtil::drawSphere( const GFXStateBlockDesc &desc, F32 radius, const P
const SphereMesh::TriangleMesh * sphereMesh = gSphere.getMesh(2);
S32 numPoly = sphereMesh->numPoly;
S32 totalPoly = 0;
GFXVertexBufferHandle<GFXVertexPC> verts(mDevice, numPoly*3, GFXBufferTypeVolatile);
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, numPoly*3, GFXBufferTypeVolatile);
verts.lock();
S32 vertexIndex = 0;
for (S32 i=0; i<numPoly; i++)
@ -712,7 +712,7 @@ void GFXDrawUtil::drawTriangle( const GFXStateBlockDesc &desc, const Point3F &p0
void GFXDrawUtil::_drawWireTriangle( const GFXStateBlockDesc &desc, const Point3F &p0, const Point3F &p1, const Point3F &p2, const ColorI &color, const MatrixF *xfm )
{
GFXVertexBufferHandle<GFXVertexPC> verts(mDevice, 4, GFXBufferTypeVolatile);
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, 4, GFXBufferTypeVolatile);
verts.lock();
// Set up the line strip
@ -745,7 +745,7 @@ void GFXDrawUtil::_drawWireTriangle( const GFXStateBlockDesc &desc, const Point3
void GFXDrawUtil::_drawSolidTriangle( const GFXStateBlockDesc &desc, const Point3F &p0, const Point3F &p1, const Point3F &p2, const ColorI &color, const MatrixF *xfm )
{
GFXVertexBufferHandle<GFXVertexPC> verts(mDevice, 3, GFXBufferTypeVolatile);
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, 3, GFXBufferTypeVolatile);
verts.lock();
// Set up the line strip
@ -778,7 +778,7 @@ void GFXDrawUtil::drawPolygon( const GFXStateBlockDesc& desc, const Point3F* poi
{
const bool isWireframe = ( desc.fillMode == GFXFillWireframe );
const U32 numVerts = isWireframe ? numPoints + 1 : numPoints;
GFXVertexBufferHandle< GFXVertexPC > verts( mDevice, numVerts, GFXBufferTypeVolatile );
GFXVertexBufferHandle< GFXVertexPCT > verts( mDevice, numVerts, GFXBufferTypeVolatile );
verts.lock();
for( U32 i = 0; i < numPoints; ++ i )
@ -809,7 +809,7 @@ void GFXDrawUtil::drawPolygon( const GFXStateBlockDesc& desc, const Point3F* poi
if( desc.fillMode == GFXFillWireframe )
mDevice->drawPrimitive( GFXLineStrip, 0, numPoints );
else
mDevice->drawPrimitive( GFXTriangleFan, 0, numPoints - 2 );
mDevice->drawPrimitive( GFXTriangleStrip, 0, numPoints - 2 );
}
void GFXDrawUtil::drawCube( const GFXStateBlockDesc &desc, const Box3F &box, const ColorI &color, const MatrixF *xfm )
@ -827,7 +827,7 @@ void GFXDrawUtil::drawCube( const GFXStateBlockDesc &desc, const Point3F &size,
void GFXDrawUtil::_drawWireCube( const GFXStateBlockDesc &desc, const Point3F &size, const Point3F &pos, const ColorI &color, const MatrixF *xfm )
{
GFXVertexBufferHandle<GFXVertexPC> verts(mDevice, 30, GFXBufferTypeVolatile);
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, 30, GFXBufferTypeVolatile);
verts.lock();
Point3F halfSize = size * 0.5f;
@ -870,7 +870,7 @@ void GFXDrawUtil::_drawWireCube( const GFXStateBlockDesc &desc, const Point3F &s
void GFXDrawUtil::_drawSolidCube( const GFXStateBlockDesc &desc, const Point3F &size, const Point3F &pos, const ColorI &color, const MatrixF *xfm )
{
GFXVertexBufferHandle<GFXVertexPC> verts(mDevice, 36, GFXBufferTypeVolatile);
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, 36, GFXBufferTypeVolatile);
verts.lock();
Point3F halfSize = size * 0.5f;
@ -950,7 +950,7 @@ void GFXDrawUtil::_drawWirePolyhedron( const GFXStateBlockDesc &desc, const AnyP
// Allocate a temporary vertex buffer.
GFXVertexBufferHandle< GFXVertexPC > verts( mDevice, numEdges * 2, GFXBufferTypeVolatile);
GFXVertexBufferHandle< GFXVertexPCT > verts( mDevice, numEdges * 2, GFXBufferTypeVolatile);
// Fill it with the vertices for the edges.
@ -997,7 +997,7 @@ void GFXDrawUtil::_drawSolidPolyhedron( const GFXStateBlockDesc &desc, const Any
// Create a temp buffer for the vertices and
// put all the polyhedron's points in there.
GFXVertexBufferHandle< GFXVertexPC > verts( mDevice, numPoints, GFXBufferTypeVolatile );
GFXVertexBufferHandle< GFXVertexPCT > verts( mDevice, numPoints, GFXBufferTypeVolatile );
verts.lock();
for( U32 i = 0; i < numPoints; ++ i )
@ -1071,7 +1071,7 @@ void GFXDrawUtil::_drawSolidPolyhedron( const GFXStateBlockDesc &desc, const Any
for( U32 i = 0; i < numPolys; ++ i )
{
U32 numVerts = numIndicesForPoly[ i ];
mDevice->drawIndexedPrimitive( GFXTriangleFan, 0, 0, numPoints, startIndex, numVerts - 2 );
mDevice->drawIndexedPrimitive( GFXTriangleStrip, 0, 0, numPoints, startIndex, numVerts - 2 );
startIndex += numVerts;
}
}
@ -1119,7 +1119,7 @@ void GFXDrawUtil::drawObjectBox( const GFXStateBlockDesc &desc, const Point3F &s
PrimBuild::end();
}
static const Point2F circlePoints[] =
static const Point2F circlePoints[] =
{
Point2F(0.707107f, 0.707107f),
Point2F(0.923880f, 0.382683f),
@ -1156,7 +1156,7 @@ void GFXDrawUtil::_drawSolidCapsule( const GFXStateBlockDesc &desc, const Point3
mat = MatrixF::Identity;
S32 numPoints = sizeof(circlePoints)/sizeof(Point2F);
GFXVertexBufferHandle<GFXVertexPC> verts(mDevice, numPoints * 2 + 2, GFXBufferTypeVolatile);
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, numPoints * 2 + 2, GFXBufferTypeVolatile);
verts.lock();
for (S32 i=0; i<numPoints + 1; i++)
@ -1222,7 +1222,7 @@ void GFXDrawUtil::_drawWireCapsule( const GFXStateBlockDesc &desc, const Point3F
mDevice->multWorld(mat);
S32 numPoints = sizeof(circlePoints)/sizeof(Point2F);
GFXVertexBufferHandle<GFXVertexPC> verts(mDevice, numPoints, GFXBufferTypeVolatile);
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, numPoints, GFXBufferTypeVolatile);
verts.lock();
for (S32 i=0; i< numPoints; i++)
{
@ -1268,27 +1268,57 @@ void GFXDrawUtil::drawCone( const GFXStateBlockDesc &desc, const Point3F &basePn
mDevice->multWorld(mat);
S32 numPoints = sizeof(circlePoints)/sizeof(Point2F);
GFXVertexBufferHandle<GFXVertexPC> verts(mDevice, numPoints + 2, GFXBufferTypeVolatile);
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, numPoints * 3 + 2, GFXBufferTypeVolatile);
verts.lock();
verts[0].point = Point3F(0.0f,0.0f,1.0f);
verts[0].color = color;
for (S32 i=0; i<numPoints + 1; i++)
F32 sign = -1.f;
S32 indexDown = 0; //counting down from numPoints
S32 indexUp = 0; //counting up from 0
S32 index = 0; //circlePoints index for cap
for (S32 i = 0; i < numPoints + 1; i++)
{
//Top cap
if (i != numPoints)
{
if (sign < 0)
index = indexDown;
else
index = indexUp;
verts[i].point = Point3F(circlePoints[index].x, circlePoints[index].y, 0);
verts[i].color = color;
if (sign < 0)
indexUp += 1;
else
indexDown = numPoints - indexUp;
// invert sign
sign *= -1.0f;
}
//cone
S32 imod = i % numPoints;
verts[i + 1].point = Point3F(circlePoints[imod].x,circlePoints[imod].y, 0.0f);
verts[i + 1].color = color;
S32 vertindex = 2 * i + numPoints;
verts[vertindex].point = Point3F(circlePoints[imod].x, circlePoints[imod].y, 0);
verts[vertindex].color = color;
verts[vertindex + 1].point = Point3F(0.0f, 0.0f, 1.0f);
verts[vertindex + 1].color = color;
}
verts.unlock();
mDevice->setStateBlockByDesc( desc );
mDevice->setVertexBuffer( verts );
mDevice->setupGenericShaders( GFXDevice::GSModColorTexture );
mDevice->setupGenericShaders();
mDevice->drawPrimitive( GFXTriangleFan, 0, numPoints );
mDevice->drawPrimitive( GFXTriangleFan, 1, numPoints-1 );
mDevice->drawPrimitive(GFXTriangleStrip, 0, numPoints - 2);
mDevice->drawPrimitive(GFXTriangleStrip, numPoints, numPoints * 2);
mDevice->popWorldMatrix();
}
void GFXDrawUtil::drawCylinder( const GFXStateBlockDesc &desc, const Point3F &basePnt, const Point3F &tipPnt, F32 radius, const ColorI &color )
@ -1307,32 +1337,59 @@ void GFXDrawUtil::drawCylinder( const GFXStateBlockDesc &desc, const Point3F &ba
mDevice->pushWorldMatrix();
mDevice->multWorld(mat);
S32 numPoints = sizeof(circlePoints)/sizeof(Point2F);
GFXVertexBufferHandle<GFXVertexPC> verts(mDevice, numPoints * 4 + 4, GFXBufferTypeVolatile);
S32 numPoints = sizeof(circlePoints) / sizeof(Point2F);
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, numPoints *4 + 2, GFXBufferTypeVolatile);
verts.lock();
for (S32 i=0; i<numPoints + 1; i++)
{
S32 imod = i % numPoints;
verts[i].point = Point3F(circlePoints[imod].x,circlePoints[imod].y, 0.5f);
verts[i].color = color;
verts[i + numPoints + 1].point = Point3F(circlePoints[imod].x,circlePoints[imod].y, 0);
verts[i + numPoints + 1].color = color;
verts[2*numPoints + 2 + 2 * i].point = Point3F(circlePoints[imod].x,circlePoints[imod].y, 0.5f);
verts[2*numPoints + 2 + 2 * i].color = color;
verts[2*numPoints + 2 + 2 * i + 1].point = Point3F(circlePoints[imod].x,circlePoints[imod].y, 0);
verts[2*numPoints + 2 + 2 * i + 1].color = color;
F32 sign = -1.f;
S32 indexDown = 0; //counting down from numPoints
S32 indexUp = 0; //counting up from 0
S32 index = 0; //circlePoints index for caps
for (S32 i = 0; i < numPoints + 1; i++)
{
//Top/Bottom cap
if (i != numPoints)
{
if (sign < 0)
index = indexDown;
else
index = indexUp;
verts[i].point = Point3F(circlePoints[index].x, circlePoints[index].y, 0);
verts[i].color = color;
verts[i + numPoints].point = Point3F(circlePoints[index].x, circlePoints[index].y, 0.5f);
verts[i + numPoints].color = color;
if (sign < 0)
indexUp += 1;
else
indexDown = numPoints - indexUp;
// invert sign
sign *= -1.0f;
}
//cylinder
S32 imod = i % numPoints;
S32 vertindex = 2 * i + (numPoints * 2);
verts[vertindex].point = Point3F(circlePoints[imod].x, circlePoints[imod].y, 0);
verts[vertindex].color = color;
verts[vertindex + 1].point = Point3F(circlePoints[imod].x, circlePoints[imod].y, 0.5f);
verts[vertindex + 1].color = color;
}
verts.unlock();
mDevice->setStateBlockByDesc( desc );
mDevice->setVertexBuffer( verts );
mDevice->setupGenericShaders( GFXDevice::GSModColorTexture );
mDevice->setupGenericShaders();
mDevice->drawPrimitive( GFXTriangleFan, 0, numPoints );
mDevice->drawPrimitive( GFXTriangleFan, numPoints + 1, numPoints );
mDevice->drawPrimitive( GFXTriangleStrip, 2 * numPoints + 2, 2 * numPoints);
mDevice->drawPrimitive( GFXTriangleStrip, 0, numPoints-2 );
mDevice->drawPrimitive( GFXTriangleStrip, numPoints, numPoints - 2);
mDevice->drawPrimitive( GFXTriangleStrip, numPoints*2, numPoints * 2);
mDevice->popWorldMatrix();
}
@ -1393,7 +1450,7 @@ void GFXDrawUtil::drawFrustum( const Frustum &f, const ColorI &color )
void GFXDrawUtil::drawSolidPlane( const GFXStateBlockDesc &desc, const Point3F &pos, const Point2F &size, const ColorI &color )
{
GFXVertexBufferHandle<GFXVertexPC> verts(mDevice, 4, GFXBufferTypeVolatile);
GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, 4, GFXBufferTypeVolatile);
verts.lock();
verts[0].point = pos + Point3F( -size.x / 2.0f, -size.y / 2.0f, 0 );
@ -1412,7 +1469,7 @@ void GFXDrawUtil::drawSolidPlane( const GFXStateBlockDesc &desc, const Point3F &
mDevice->setVertexBuffer( verts );
mDevice->setupGenericShaders();
mDevice->drawPrimitive( GFXTriangleFan, 0, 2 );
mDevice->drawPrimitive( GFXTriangleStrip, 0, 2 );
}
void GFXDrawUtil::drawPlaneGrid( const GFXStateBlockDesc &desc, const Point3F &pos, const Point2F &size, const Point2F &step, const ColorI &color, Plane plane )
@ -1449,7 +1506,7 @@ void GFXDrawUtil::drawPlaneGrid( const GFXStateBlockDesc &desc, const Point3F &p
break;
}
GFXVertexBufferHandle<GFXVertexPC> verts( mDevice, numVertices, GFXBufferTypeVolatile );
GFXVertexBufferHandle<GFXVertexPCT> verts( mDevice, numVertices, GFXBufferTypeVolatile );
verts.lock();
U32 vertCount = 0;
@ -1541,7 +1598,7 @@ void GFXDrawUtil::drawTransform( const GFXStateBlockDesc &desc, const MatrixF &m
GFX->multWorld( mat );
GFXVertexBufferHandle<GFXVertexPC> verts( mDevice, 6, GFXBufferTypeVolatile );
GFXVertexBufferHandle<GFXVertexPCT> verts( mDevice, 6, GFXBufferTypeVolatile );
verts.lock();
const static ColorI defColors[3] =

View file

@ -68,7 +68,6 @@ enum GFXPrimitiveType
GFXLineStrip,
GFXTriangleList,
GFXTriangleStrip,
GFXTriangleFan,
GFXPT_COUNT
};
@ -277,8 +276,8 @@ enum GFXBlend
enum GFXAdapterType
{
OpenGL = 0,
Direct3D11,
Direct3D9,
Direct3D8,
NullDevice,
Direct3D9_360,
GFXAdapterType_Count

View file

@ -77,8 +77,8 @@ inline static void _GFXInitReportAdapters(Vector<GFXAdapter*> &adapters)
case NullDevice:
Con::printf(" Null device found");
break;
case Direct3D8:
Con::printf(" Direct 3D (version 8.1) device found");
case Direct3D11:
Con::printf(" Direct 3D (version 11.x) device found");
break;
default :
Con::printf(" Unknown device found");
@ -221,7 +221,8 @@ GFXAdapter* GFXInit::chooseAdapter( GFXAdapterType type, const char* outputDevic
const char* GFXInit::getAdapterNameFromType(GFXAdapterType type)
{
static const char* _names[] = { "OpenGL", "D3D9", "D3D8", "NullDevice", "Xenon" };
// must match GFXAdapterType order
static const char* _names[] = { "OpenGL", "D3D11", "D3D9", "NullDevice", "Xenon" };
if( type < 0 || type >= GFXAdapterType_Count )
{
@ -268,51 +269,53 @@ GFXAdapter *GFXInit::getBestAdapterChoice()
//
// If D3D is unavailable, we're not on windows, so GL is de facto the
// best choice!
F32 highestSM9 = 0.f, highestSMGL = 0.f;
GFXAdapter *foundAdapter8 = NULL, *foundAdapter9 = NULL,
*foundAdapterGL = NULL;
F32 highestSMDX = 0.f, highestSMGL = 0.f;
GFXAdapter *foundAdapter9 = NULL, *foundAdapterGL = NULL, *foundAdapter11 = NULL;
for(S32 i=0; i<smAdapters.size(); i++)
for (S32 i = 0; i<smAdapters.size(); i++)
{
GFXAdapter *currAdapter = smAdapters[i];
switch(currAdapter->mType)
switch (currAdapter->mType)
{
case Direct3D9:
if(currAdapter->mShaderModel > highestSM9)
case Direct3D11:
if (currAdapter->mShaderModel > highestSMDX)
{
highestSM9 = currAdapter->mShaderModel;
highestSMDX = currAdapter->mShaderModel;
foundAdapter11 = currAdapter;
}
break;
case Direct3D9:
if (currAdapter->mShaderModel > highestSMDX)
{
highestSMDX = currAdapter->mShaderModel;
foundAdapter9 = currAdapter;
}
break;
case OpenGL:
if(currAdapter->mShaderModel > highestSMGL)
if (currAdapter->mShaderModel > highestSMGL)
{
highestSMGL = currAdapter->mShaderModel;
foundAdapterGL = currAdapter;
}
break;
case Direct3D8:
if(!foundAdapter8)
foundAdapter8 = currAdapter;
break;
default:
break;
}
}
// Return best found in order DX9, GL, DX8.
if(foundAdapter9)
// Return best found in order DX11,DX9, GL
if (foundAdapter11)
return foundAdapter11;
if (foundAdapter9)
return foundAdapter9;
if(foundAdapterGL)
if (foundAdapterGL)
return foundAdapterGL;
if(foundAdapter8)
return foundAdapter8;
// Uh oh - we didn't find anything. Grab whatever we can that's not Null...
for(S32 i=0; i<smAdapters.size(); i++)
if(smAdapters[i]->mType != NullDevice)

View file

@ -35,7 +35,8 @@ bool GFXShader::smLogWarnings = true;
GFXShader::GFXShader()
: mPixVersion( 0.0f ),
mReloadKey( 0 )
mReloadKey( 0 ),
mInstancingFormat( NULL )
{
}
@ -43,6 +44,8 @@ GFXShader::~GFXShader()
{
Torque::FS::RemoveChangeNotification( mVertexFile, this, &GFXShader::_onFileChanged );
Torque::FS::RemoveChangeNotification( mPixelFile, this, &GFXShader::_onFileChanged );
SAFE_DELETE(mInstancingFormat);
}
#ifndef TORQUE_OPENGL
@ -60,8 +63,16 @@ bool GFXShader::init( const Torque::Path &vertFile,
const Torque::Path &pixFile,
F32 pixVersion,
const Vector<GFXShaderMacro> &macros,
const Vector<String> &samplerNames)
const Vector<String> &samplerNames,
GFXVertexFormat *instanceFormat)
{
// Take care of instancing
if (instanceFormat)
{
mInstancingFormat = new GFXVertexFormat;
mInstancingFormat->copy(*instanceFormat);
}
// Store the inputs for use in reloading.
mVertexFile = vertFile;
mPixelFile = pixFile;

View file

@ -262,13 +262,12 @@ protected:
/// their destructor.
Vector<GFXShaderConstBuffer*> mActiveBuffers;
GFXVertexFormat *mInstancingFormat;
/// A protected constructor so it cannot be instantiated.
GFXShader();
public:
// TODO: Add this into init().
GFXVertexFormat mInstancingFormat;
public:
/// Adds a global shader macro which will be merged with
/// the script defined macros on every shader reload.
@ -312,7 +311,8 @@ public:
const Torque::Path &pixFile,
F32 pixVersion,
const Vector<GFXShaderMacro> &macros,
const Vector<String> &samplerNames);
const Vector<String> &samplerNames,
GFXVertexFormat *instanceFormat = NULL );
/// Reloads the shader from disk.
bool reload();
@ -358,6 +358,9 @@ public:
// GFXResource
const String describeSelf() const { return mDescription; }
// Get instancing vertex format
GFXVertexFormat *getInstancingFormat() { return mInstancingFormat; }
protected:
/// Called when the shader files change on disk.

View file

@ -347,7 +347,6 @@ void GFXStringEnumTranslate::init()
GFX_STRING_ASSIGN_MACRO( GFXStringPrimType, GFXLineStrip );
GFX_STRING_ASSIGN_MACRO( GFXStringPrimType, GFXTriangleList );
GFX_STRING_ASSIGN_MACRO( GFXStringPrimType, GFXTriangleStrip );
GFX_STRING_ASSIGN_MACRO( GFXStringPrimType, GFXTriangleFan );
VALIDATE_LOOKUPTABLE( GFXStringPrimType, GFXPT );
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

View file

@ -70,6 +70,7 @@ GFXVertexFormat::GFXVertexFormat()
mHasColor( false ),
mHasNormal( false ),
mHasTangent( false ),
mHasInstancing( false ),
mTexCoordCount( 0 ),
mSizeInBytes( 0 ),
mDecl( NULL )
@ -83,6 +84,7 @@ void GFXVertexFormat::copy( const GFXVertexFormat &format )
mHasNormal = format.mHasNormal;
mHasTangent = format.mHasTangent;
mHasColor = format.mHasColor;
mHasInstancing = format.mHasInstancing;
mTexCoordCount = format.mTexCoordCount;
mSizeInBytes = format.mSizeInBytes;
mDescription = format.mDescription;
@ -161,6 +163,14 @@ bool GFXVertexFormat::hasColor() const
return mHasColor;
}
bool GFXVertexFormat::hasInstancing() const
{
if (mDirty)
const_cast<GFXVertexFormat*>(this)->_updateDirty();
return mHasInstancing;
}
U32 GFXVertexFormat::getTexCoordCount() const
{
if ( mDirty )
@ -177,6 +187,11 @@ U32 GFXVertexFormat::getSizeInBytes() const
return mSizeInBytes;
}
void GFXVertexFormat::enableInstancing()
{
mHasInstancing = true;
}
void GFXVertexFormat::_updateDirty()
{
PROFILE_SCOPE( GFXVertexFormat_updateDirty );

View file

@ -153,6 +153,9 @@ public:
/// The copy constructor.
GFXVertexFormat( const GFXVertexFormat &format ) { copy( format ); }
/// Tell this format it has instancing
void enableInstancing();
/// Copy the other vertex format.
void copy( const GFXVertexFormat &format );
@ -163,7 +166,7 @@ public:
const String& getDescription() const;
/// Clears all the vertex elements.
void clear();
void clear();
/// Adds a vertex element to the format.
///
@ -182,6 +185,9 @@ public:
/// Returns true if there is a COLOR semantic in this vertex format.
bool hasColor() const;
/// Return true if instancing is used with this vertex format.
bool hasInstancing() const;
/// Returns the texture coordinate count by
/// counting the number of TEXCOORD semantics.
U32 getTexCoordCount() const;
@ -225,6 +231,9 @@ protected:
/// Is true if there is a COLOR semantic in this vertex format.
bool mHasColor;
/// Is instaning used with this vertex format.
bool mHasInstancing;
/// The texture coordinate count by counting the
/// number of "TEXCOORD" semantics.
U32 mTexCoordCount;

View file

@ -513,9 +513,6 @@ inline GLsizei GFXGLDevice::primCountToIndexCount(GFXPrimitiveType primType, U32
case GFXTriangleStrip :
return 2 + primitiveCount;
break;
case GFXTriangleFan :
return 2 + primitiveCount;
break;
default:
AssertFatal(false, "GFXGLDevice::primCountToIndexCount - unrecognized prim type");
break;
@ -789,7 +786,8 @@ void GFXGLDevice::setupGenericShaders( GenericShaderType type )
shaderData->registerObject();
mGenericShader[GSColor] = shaderData->getShader();
mGenericShaderBuffer[GSColor] = mGenericShader[GSColor]->allocConstBuffer();
mModelViewProjSC[GSColor] = mGenericShader[GSColor]->getShaderConstHandle( "$modelView" );
mModelViewProjSC[GSColor] = mGenericShader[GSColor]->getShaderConstHandle( "$modelView" );
Sim::getRootGroup()->addObject(shaderData);
shaderData = new ShaderData();
shaderData->setField("OGLVertexShaderFile", "shaders/common/fixedFunction/gl/modColorTextureV.glsl");
@ -799,7 +797,8 @@ void GFXGLDevice::setupGenericShaders( GenericShaderType type )
shaderData->registerObject();
mGenericShader[GSModColorTexture] = shaderData->getShader();
mGenericShaderBuffer[GSModColorTexture] = mGenericShader[GSModColorTexture]->allocConstBuffer();
mModelViewProjSC[GSModColorTexture] = mGenericShader[GSModColorTexture]->getShaderConstHandle( "$modelView" );
mModelViewProjSC[GSModColorTexture] = mGenericShader[GSModColorTexture]->getShaderConstHandle( "$modelView" );
Sim::getRootGroup()->addObject(shaderData);
shaderData = new ShaderData();
shaderData->setField("OGLVertexShaderFile", "shaders/common/fixedFunction/gl/addColorTextureV.glsl");
@ -809,7 +808,8 @@ void GFXGLDevice::setupGenericShaders( GenericShaderType type )
shaderData->registerObject();
mGenericShader[GSAddColorTexture] = shaderData->getShader();
mGenericShaderBuffer[GSAddColorTexture] = mGenericShader[GSAddColorTexture]->allocConstBuffer();
mModelViewProjSC[GSAddColorTexture] = mGenericShader[GSAddColorTexture]->getShaderConstHandle( "$modelView" );
mModelViewProjSC[GSAddColorTexture] = mGenericShader[GSAddColorTexture]->getShaderConstHandle( "$modelView" );
Sim::getRootGroup()->addObject(shaderData);
shaderData = new ShaderData();
shaderData->setField("OGLVertexShaderFile", "shaders/common/fixedFunction/gl/textureV.glsl");
@ -820,6 +820,7 @@ void GFXGLDevice::setupGenericShaders( GenericShaderType type )
mGenericShader[GSTexture] = shaderData->getShader();
mGenericShaderBuffer[GSTexture] = mGenericShader[GSTexture]->allocConstBuffer();
mModelViewProjSC[GSTexture] = mGenericShader[GSTexture]->getShaderConstHandle( "$modelView" );
Sim::getRootGroup()->addObject(shaderData);
}
MatrixF tempMatrix = mProjectionMatrix * mViewMatrix * mWorldMatrix[mWorldStackSize];

View file

@ -53,7 +53,6 @@ void GFXGLEnumTranslate::init()
GFXGLPrimType[GFXLineStrip] = GL_LINE_STRIP;
GFXGLPrimType[GFXTriangleList] = GL_TRIANGLES;
GFXGLPrimType[GFXTriangleStrip] = GL_TRIANGLE_STRIP;
GFXGLPrimType[GFXTriangleFan] = GL_TRIANGLE_FAN;
// Blend
GFXGLBlend[GFXBlendZero] = GL_ZERO;

View file

@ -664,10 +664,14 @@ void GFXGLShader::initHandles()
glUseProgram(0);
//instancing
if (!mInstancingFormat)
return;
U32 offset = 0;
for ( U32 i=0; i < mInstancingFormat.getElementCount(); i++ )
for ( U32 i=0; i < mInstancingFormat->getElementCount(); i++ )
{
const GFXVertexElement &element = mInstancingFormat.getElement( i );
const GFXVertexElement &element = mInstancingFormat->getElement( i );
String constName = String::ToString( "$%s", element.getSemantic().c_str() );
@ -702,9 +706,9 @@ void GFXGLShader::initHandles()
// If this is a matrix we will have 2 or 3 more of these
// semantics with the same name after it.
for ( ; i < mInstancingFormat.getElementCount(); i++ )
for ( ; i < mInstancingFormat->getElementCount(); i++ )
{
const GFXVertexElement &nextElement = mInstancingFormat.getElement( i );
const GFXVertexElement &nextElement = mInstancingFormat->getElement( i );
if ( nextElement.getSemantic() != element.getSemantic() )
{
i--;

View file

@ -117,7 +117,6 @@ GFXVertexBuffer * endToBuffer( U32 &numPrims )
}
case GFXTriangleStrip:
case GFXTriangleFan:
{
numPrims = mCurVertIndex - 2;
break;
@ -171,7 +170,6 @@ void end( bool useGenericShaders )
}
case GFXTriangleStrip:
case GFXTriangleFan:
{
stripStart = 2;
vertStride = 1;