Exemple #1
0
void DrawGridScene( std::shared_ptr<RenderingContext> context, const Matrix4& matWorld )
{
	Assert( context );

	ConstantBuffer& cbuffer = context->GetSharedConstantBuffer();

	float scale = model_scale.Float();

	size_t columns = grid_size.Int();
	float rowFactor = 1.0f / grid_size.Int();
	float colFactor = 1.0f / columns;
	for ( int row = 0; row < grid_size.Int(); ++row )
	{
		for ( size_t col = 0; col < columns; ++col )
		{
			// world transform
			Matrix4 matTrans;
			matTrans.Translate( ( ( col + 1 ) * colFactor - colFactor * ( columns * 0.5f ) ) * columns,
				( ( row + 1 ) * rowFactor - rowFactor * ( columns * 0.5f ) ) * columns,
				( ( row + 1 ) * rowFactor - rowFactor * ( columns * 0.5f ) ) * columns );

			Matrix4 matScale;
			matScale.Scaling( scale, scale, scale );

			Matrix4 matNewWorld = matScale * matWorld * matTrans;
			cbuffer.SetMatrix4( ConstantBuffer::WorldMatrix, matNewWorld );

			// various color
			cbuffer.SetVector4( ConstantBuffer::DiffuseColor, Vector4( max( 0.2f, matTrans.A41 * 0.5f + 0.8f ), max( 0.4f, matTrans.A42 * 0.5f + 0.6f ), matTrans.A43 * 0.5f + 1.0f, 1.0f ) );

			context->Draw( GetMeshes()[row * columns + col] );
		}
	}
}
Exemple #2
0
void ActorFactoryDelegate::SetLayerName(String layerName )
{
	String cvarName = "layer_" + layerName;
	ConsoleVariable* pCVar = theConsole.GetConsoleItemManager().FindCVar( cvarName );
	if( pCVar != NULL )
	{
		_renderLayer = pCVar->GetIntVal();
	}
}
Bool ConsoleEnvironment::AffectVariable( const GChar * strName, ConsoleVariableType iType, Void * pValue )
{
    ConsoleVariable * pVar = GetVariable( strName );
    if ( pVar == NULL )
        return false;

    pVar->Affect( iType, pValue );
    return true;
}
Exemple #4
0
void ActorFactoryAddCollisionFlag( const String& input )
{
	ACTORFACTORY_GETDELEGATE(pDel, PhysicsActorFactoryDelegate);
	String cvarName = "phys_cc_";
	cvarName += TrimString( input );

	ConsoleVariable* pCVar = theConsole.GetConsoleItemManager().FindCVar( cvarName );
	if( pCVar == NULL )
		return;

	pDel->AddCollisionFlag(pCVar->GetIntVal());
}
Bool ConsoleEnvironment::AffectVariable( const GChar * strDstName, const GChar * strSrcName )
{
    ConsoleVariable * pDstVar = GetVariable( strDstName );
    if ( pDstVar == NULL )
        return false;

    ConsoleVariable * pSrcVar = GetVariable( strSrcName );
    if ( pSrcVar == NULL )
        return false;

    pDstVar->Affect( pSrcVar );
    return true;
}
Bool CommandVarNew::Execute( GChar * strOutput, const GChar * strArgList )
{
    // Get console environment
    ConsoleEnvironment * pEnv = ConsoleFn->GetEnvironment();

    // Parse arguments
    GChar strArg0[CONSOLECOMMAND_OUTPUT_LENGTH];
    GChar strArg1[CONSOLECOMMAND_OUTPUT_LENGTH];

    // Pick first argument
    strArgList = _ExtractArgument_String( strArg0, strArgList );

    // No argument case
    if ( strArgList == NULL ) {
        strOutput = StringFn->Copy( strOutput, TEXT("Missing parameter 0 : varname ...") );
        return false;
    }

    // Pick second argument
    strArgList = _ExtractArgument_String( strArg1, strArgList );

    // One argument case
    if ( strArgList == NULL ) {
        ConsoleVariable * pVar = pEnv->CreateVariable( strArg0 );
        if ( pVar == NULL ) {
            strOutput = StringFn->Copy( strOutput, TEXT("Bad parameter 0 : varname already exists ...") );
            return false;
        }

        strOutput = StringFn->Format( strOutput, TEXT("Created variable %s"), pVar->GetName() );
        return true;
    }

    // Two arguments case
    ConsoleVariableType iVarType = ConsoleVariable::GetTypeValue( strArg0 );
    if ( iVarType == CONSOLEVAR_TYPE_UNDEFINED ) {
        strOutput = StringFn->Copy( strOutput, TEXT("Bad parameter 0 : Invalid vartype ...") );
        return false;
    }

    ConsoleVariable * pVar = pEnv->CreateVariable( strArg1, iVarType, NULL );
    if ( pVar == NULL ) {
        strOutput = StringFn->Copy( strOutput, TEXT("Bad parameter 1 : varname already exists ...") );
        return false;
    }

    strOutput = StringFn->Format( strOutput, TEXT("Created variable %s"), pVar->GetName() );
    return true;
}
ConsoleVariable * ConsoleEnvironment::CreateVariable( const GChar * strName, ConsoleVariableType iType, Void * pValue )
{
    // Variable already exists
    if ( m_mapVariables.Contains(strName) )
        return NULL;

    ConsoleFn->SelectMemory( TEXT("Environment") );
    ConsoleVariable * pVar = New ConsoleVariable( strName, iType, pValue );
    ConsoleFn->UnSelectMemory();

    VariableMap::Iterator itVar;
    Bool bInserted = m_mapVariables.Insert( pVar->GetName(), pVar, &itVar );
    Assert( bInserted && !(itVar.IsNull()) );

    return itVar.GetItem();
}
Exemple #8
0
void DrawGridSceneInParallel( StlVector<std::shared_ptr<RenderingContext>>& contexts, const Matrix4& matWorld )
{
	float scale = model_scale.Float();

	size_t rows = grid_size.Int();
	size_t columns = grid_size.Int();
	float rowFactor = 1.0f / grid_size.Int();
	float colFactor = 1.0f / columns;

	//using FuncPreRender = std::function<void( std::shared_ptr<RenderingContext> context, const std::shared_ptr<IMesh>& mesh, size_t index )>;
	RenderingContext::FuncPreRender funcPreRender(
		[=]( std::shared_ptr<RenderingContext> context, size_t index )
		{
			ConstantBuffer& cbuffer = context->GetSharedConstantBuffer();

			// world transform
			size_t row = kih::Clamp<size_t>( index / rows, 0, rows - 1 );
			size_t col = kih::Clamp<size_t>( index - row * columns, 0, columns - 1 );

			Matrix4 matTrans;
			matTrans.Translate( ( ( col + 1 ) * colFactor - colFactor * ( columns * 0.5f ) ) * columns,
				( ( row + 1 ) * rowFactor - rowFactor * ( columns * 0.5f ) ) * columns,
				( ( row + 1 ) * rowFactor - rowFactor * ( columns * 0.5f ) ) * columns );

			Matrix4 matScale;
			matScale.Scaling( scale, scale, scale );

			Matrix4 matNewWorld = matScale * matWorld * matTrans;			
			cbuffer.SetMatrix4( ConstantBuffer::WorldMatrix, matNewWorld );

			// various color
			cbuffer.SetVector4( ConstantBuffer::DiffuseColor, Vector4( max( 0.2f, matTrans.A41 * 0.5f + 0.8f ), max( 0.4f, matTrans.A42 * 0.5f + 0.6f ), matTrans.A43 * 0.5f + 1.0f, 1.0f ) );
		}
	);

	RenderingContext::DrawInParallel( contexts, GetMeshes(), grid_size.Int() * grid_size.Int(), funcPreRender );
}
Exemple #9
0
KIHX_API void kiRenderToBuffer( void* buffer, int width, int height, int bpp )
{
	if ( buffer == nullptr )
	{
		return;
	}
	
	__UNDONE( temporal testing code );

	// Create color and depth stencil buffers.
	ColorFormat colorFormat = kih::GetSuitableColorFormatFromBpp( bpp );
	static std::shared_ptr<Texture> renderTarget = Texture::Create( width, height, colorFormat, buffer );
	static std::shared_ptr<Texture> depthStencil = Texture::Create( width, height, ColorFormat::D32F, NULL );
	static std::shared_ptr<UnorderedAccessView<OutputMergerInputStream>> omUAV = std::make_shared<UnorderedAccessView<OutputMergerInputStream>>( width * height * 2 );

	// Create rendering contexts as many of Thread::HardwareConcurrency.
	const int Concurrency = 8;	// HACK
	static std::array<std::shared_ptr<RenderingContext>, Concurrency> contexts;
	if ( contexts[0] == nullptr )
	{
		int index = 0;
		LoopUnroll<Concurrency>::Work( 
			[&index]() 
			{ 
				auto context = RenderingDevice::GetInstance()->CreateRenderingContext();
				context->SetViewport( 0, 0, static_cast<unsigned short>( renderTarget->Width() ), static_cast<unsigned short>( renderTarget->Height() ) );
				context->SetFixedPipelineMode( false );
				
				context->SetRenderTarget( renderTarget, 0 );
				context->SetDepthStencil( depthStencil );

				contexts[index++] = context;
			} 
		);
	}
	
	auto context = contexts[0];

	context->Clear( 0, 0, 0, 255 );
	context->SetUnorderedAccessView( nullptr );

	// Draw the world.
	const Matrix4& matWorld = RenderingDevice::GetInstance()->GetWorldMatrix();

	// Grid arragement
	if ( grid_scene.Bool() )
	{
		// threading or not
		if ( concurrency.Int() <= 1 )
		{
			DrawGridScene( context, matWorld );
		}
		else
		{
			// Copy array contexts to vector one.
			StlVector<std::shared_ptr<RenderingContext>> concurrencyContexts;
			concurrencyContexts.resize( concurrency.Int() - 1 );		// the other thread is for resolve.	
			for ( size_t i = 0; i < concurrencyContexts.size(); ++i )
			{
				contexts[i]->SetUnorderedAccessView( omUAV );
				concurrencyContexts[i] = contexts[i];
			}

			DrawGridSceneInParallel( concurrencyContexts, matWorld );
		}
	}
	else
	{
		context->GetSharedConstantBuffer().SetMatrix4( ConstantBuffer::WorldMatrix, matWorld );
		context->GetSharedConstantBuffer().SetVector4( ConstantBuffer::DiffuseColor, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
		context->Draw( GetMeshes()[0] );
	}
}