Exemplo n.º 1
0
void GuiRiverEditorCtrl::_drawRiverControlNodes( River *river, const ColorI &color )
{
   if ( !River::smShowSpline )
      return;

   RectI bounds = getBounds();

   GFXDrawUtil *drawer = GFX->getDrawUtil();

   bool isSelected = ( river == mSelRiver );
   bool isHighlighted = ( river == mHoverRiver );

   for ( U32 i = 0; i < river->mNodes.size(); i++ )
   {
      if ( false && isSelected && mSelNode == i  )
         continue;

      const Point3F &wpos = river->mNodes[i].point;

      Point3F spos;
      project( wpos, &spos );                  

      if ( spos.z > 1.0f )
         continue;

      Point2I posi;
      posi.x = spos.x;
      posi.y = spos.y;

      if ( !bounds.pointInRect( posi ) )
         continue;

      ColorI theColor = color;
      Point2I nodeHalfSize = mNodeHalfSize;

      if ( isHighlighted && mHoverNode == i )
      {
         //theColor = mHoverNodeColor;
         nodeHalfSize += Point2I(2,2);
      }

      if ( isSelected )
      {   
         if ( mSelNode == i )
         {
            theColor.set(0,0,255);
         }
         else if ( i == 0 )
         {
            theColor.set(0,255,0);
         }
         else if ( i == river->mNodes.size() - 1 )
         {
            theColor.set(255,0,0);
         }         
      }

      drawer->drawRectFill( posi - nodeHalfSize, posi + nodeHalfSize, theColor );
   }
}
Exemplo n.º 2
0
void TerrCell::renderBounds() const
{
   ColorI color;
   color.interpolate( ColorI::RED, ColorI::GREEN, (F32)mLevel / 3.0f );

   GFXStateBlockDesc desc;
   desc.setZReadWrite( true, false );
   desc.fillMode = GFXFillWireframe;
   
   GFX->getDrawUtil()->drawCube( desc, mBounds, color );
}
Exemplo n.º 3
0
 bool default_scan(const String &data, ColorI & result)
 {
    if(StringUnit::getUnitCount(data," ") == 3)
    {
       S32 r,g,b;
       dSscanf(data.c_str(),"%i %i %i",&r,&g,&b);
       result.set(r,g,b);
    }
    else
    {
       S32 r,g,b,a;
       dSscanf(data.c_str(),"%i %i %i %i",&r,&g,&b,&a);
       result.set(r,g,b,a);
    }
    return true;
 }
Exemplo n.º 4
0
void color4f( F32 red, F32 green, F32 blue, F32 alpha )
{
   mCurColor.set( U8( red * 255 ), U8( green * 255 ), U8( blue * 255 ), U8( alpha * 255 ) );
}
Exemplo n.º 5
0
void color3f( F32 red, F32 green, F32 blue )
{
   mCurColor.set( U8( red * 255 ), U8( green * 255 ), U8( blue * 255 ) );
}
Exemplo n.º 6
0
void color4i( U8 red, U8 green, U8 blue, U8 alpha )
{
   mCurColor.set( red, green, blue, alpha );
}
Exemplo n.º 7
0
void color3i( U8 red, U8 green, U8 blue )
{
   mCurColor.set( red, green, blue );
}
Exemplo n.º 8
0
namespace PrimBuild
{
Vector<GFXVertexPCT> mTempVertBuff;
GFXVertexBufferHandle<GFXVertexPCT> mVertBuff;
GFXPrimitiveType  mType;
U32               mCurVertIndex;
ColorI            mCurColor( 255, 255, 255 );
Point2F           mCurTexCoord;
const ColorI      _colWhite( 255, 255, 255, 255 );

#ifdef TORQUE_DEBUG
U32 mMaxVerts;

#define INIT_VERTEX_SIZE(x) mMaxVerts = x;
#define VERTEX_BOUNDS_CHECK() AssertFatal( mCurVertIndex < mMaxVerts, "PrimBuilder encountered an out of bounds vertex! Break and debug!" );

// This next check shouldn't really be used a lot unless you are tracking down
// a specific bug. -pw
#define VERTEX_SIZE_CHECK() AssertFatal( mCurVertIndex <= mMaxVerts, "PrimBuilder allocated more verts than you used! Break and debug or rendering artifacts could occur." );

#else

#define INIT_VERTEX_SIZE(x)
#define VERTEX_BOUNDS_CHECK()
#define VERTEX_SIZE_CHECK()

#endif

//-----------------------------------------------------------------------------
// begin
//-----------------------------------------------------------------------------
void begin( GFXPrimitiveType type, U32 maxVerts )
{
   AssertFatal( type >= GFXPT_FIRST && type < GFXPT_COUNT, "PrimBuilder::end() - Bad primitive type!" );

   mType = type;
   mCurVertIndex = 0;
   INIT_VERTEX_SIZE( maxVerts );
   mTempVertBuff.setSize( maxVerts );
}

void beginToBuffer( GFXPrimitiveType type, U32 maxVerts )
{
   AssertFatal( type >= GFXPT_FIRST && type < GFXPT_COUNT, "PrimBuilder::end() - Bad primitive type!" );

   mType = type;
   mCurVertIndex = 0;
   INIT_VERTEX_SIZE( maxVerts );
   mTempVertBuff.setSize( maxVerts );
}

//-----------------------------------------------------------------------------
// end
//-----------------------------------------------------------------------------
GFXVertexBuffer * endToBuffer( U32 &numPrims )
{
   mVertBuff.set(GFX, mTempVertBuff.size(), GFXBufferTypeVolatile);
   GFXVertexPCT *verts = mVertBuff.lock();
   dMemcpy( verts, mTempVertBuff.address(), mTempVertBuff.size() * sizeof(GFXVertexPCT) );
   mVertBuff.unlock();

   VERTEX_SIZE_CHECK();

   switch( mType )
   {
      case GFXPointList:
      {
         numPrims = mCurVertIndex;
         break;
      }

      case GFXLineList:
      {
         numPrims = mCurVertIndex / 2;
         break;
      }

      case GFXLineStrip:
      {
         numPrims = mCurVertIndex - 1;
         break;
      }

      case GFXTriangleList:
      {
         numPrims = mCurVertIndex / 3;
         break;
      }

      case GFXTriangleStrip:
      case GFXTriangleFan:
      {
         numPrims = mCurVertIndex - 2;
         break;
      }
      case GFXPT_COUNT:
         // handle warning
         break;
   }

   return mVertBuff;
}

void end( bool useGenericShaders )
{
   if ( mCurVertIndex == 0 ) 
      return; 

   VERTEX_SIZE_CHECK();

   U32 vertStride = 1;
   U32 stripStart = 0;

   AssertFatal( mType >= GFXPT_FIRST && mType < GFXPT_COUNT, "PrimBuilder::end() - Bad primitive type!" );
               
   switch( mType )
   {
      default:
      case GFXPointList:
      {
         vertStride = 1;
         break;
      }

      case GFXLineList:
      {
         vertStride = 2;
         break;
      }

      case GFXTriangleList:
      {
         vertStride = 3;
         break;
      }

      case GFXLineStrip:
      {
         stripStart = 1;
         vertStride = 1;
         break;
      }

      case GFXTriangleStrip:
      case GFXTriangleFan:
      {
         stripStart = 2;
         vertStride = 1;
         break;
      }
   }

   if ( useGenericShaders )
      GFX->setupGenericShaders( GFXDevice::GSModColorTexture );

   const GFXVertexPCT *srcVerts = mTempVertBuff.address();
   U32 numVerts = mCurVertIndex;
   
   // Make sure we don't have a dirty prim buffer left.
   GFX->setPrimitiveBuffer( NULL );

   if ( stripStart > 0 )
   {
      // TODO: Fix this to allow > MAX_DYNAMIC_VERTS!

      U32 copyVerts = getMin( (U32)MAX_DYNAMIC_VERTS, numVerts );
      mVertBuff.set( GFX, copyVerts, GFXBufferTypeVolatile );

      GFXVertexPCT *verts = mVertBuff.lock();
      dMemcpy( verts, srcVerts, copyVerts * sizeof( GFXVertexPCT ) );
      mVertBuff.unlock();

      U32 numPrims = ( copyVerts / vertStride ) - stripStart;
      GFX->setVertexBuffer( mVertBuff );
      GFX->drawPrimitive( mType, 0, numPrims );
   }
   else
   {
      while ( numVerts > 0 )
      {
         U32 copyVerts = getMin( (U32)MAX_DYNAMIC_VERTS, numVerts );
         copyVerts -= copyVerts % vertStride;

         mVertBuff.set( GFX, copyVerts, GFXBufferTypeVolatile );

         GFXVertexPCT *verts = mVertBuff.lock();
         dMemcpy( verts, srcVerts, copyVerts * sizeof( GFXVertexPCT ) );
         mVertBuff.unlock();

         U32 numPrims = copyVerts / vertStride;
         GFX->setVertexBuffer( mVertBuff );
         GFX->drawPrimitive( mType, 0, numPrims );

         srcVerts += copyVerts;
         numVerts -= copyVerts;
      }
   }
}

//-----------------------------------------------------------------------------
// vertex2f
//-----------------------------------------------------------------------------
void vertex2f( F32 x, F32 y )
{
   VERTEX_BOUNDS_CHECK();
   GFXVertexPCT *vert = &mTempVertBuff[mCurVertIndex++];

   vert->point.x = x;
   vert->point.y = y;
   vert->point.z = 0.0;
   vert->color = mCurColor;
   vert->texCoord = mCurTexCoord;
}

//-----------------------------------------------------------------------------
// vertex3f
//-----------------------------------------------------------------------------
void vertex3f( F32 x, F32 y, F32 z )
{
   VERTEX_BOUNDS_CHECK();
   GFXVertexPCT *vert = &mTempVertBuff[mCurVertIndex++];

   vert->point.x = x;
   vert->point.y = y;
   vert->point.z = z;
   vert->color = mCurColor;
   vert->texCoord = mCurTexCoord;
}

//-----------------------------------------------------------------------------
// vertex3fv
//-----------------------------------------------------------------------------
void vertex3fv( const F32 *data )
{
   VERTEX_BOUNDS_CHECK();
   GFXVertexPCT *vert = &mTempVertBuff[mCurVertIndex++];

   vert->point.set( data[0], data[1], data[2] );
   vert->color = mCurColor;
   vert->texCoord = mCurTexCoord;
}

//-----------------------------------------------------------------------------
// vertex2fv
//-----------------------------------------------------------------------------
void vertex2fv( const F32 *data )
{
   VERTEX_BOUNDS_CHECK();
   GFXVertexPCT *vert = &mTempVertBuff[mCurVertIndex++];

   vert->point.set( data[0], data[1], 0.f );
   vert->color = mCurColor;
   vert->texCoord = mCurTexCoord;
}



//-----------------------------------------------------------------------------
// color
//-----------------------------------------------------------------------------
void color( const ColorI &inColor )
{
   mCurColor = inColor;
}

void color( const ColorF &inColor )
{
   mCurColor = inColor;
}

void color3i( U8 red, U8 green, U8 blue )
{
   mCurColor.set( red, green, blue );
}

void color4i( U8 red, U8 green, U8 blue, U8 alpha )
{
   mCurColor.set( red, green, blue, alpha );
}

void color3f( F32 red, F32 green, F32 blue )
{
   mCurColor.set( U8( red * 255 ), U8( green * 255 ), U8( blue * 255 ) );
}

void color4f( F32 red, F32 green, F32 blue, F32 alpha )
{
   mCurColor.set( U8( red * 255 ), U8( green * 255 ), U8( blue * 255 ), U8( alpha * 255 ) );
}


//-----------------------------------------------------------------------------
// texCoord
//-----------------------------------------------------------------------------
void texCoord2f( F32 x, F32 y )
{
   mCurTexCoord.set( x, y );
}

void shutdown()
{
   mVertBuff = NULL;
}

}  // namespace PrimBuild