Example #1
0
ERet rxTexture::Online( Assets::LoadContext2 & context )
{
	rxTexture* texture = static_cast< rxTexture* >( context.o );

	const UINT32 textureSize = context.GetSize();

	ScopedStackAlloc	tempAlloc( gCore.frameAlloc );
	void* textureData = tempAlloc.AllocA( textureSize );
	mxDO(context.Read( textureData, textureSize ));

	texture->m_texture = llgl::CreateTexture( textureData, textureSize );
	texture->m_resource = llgl::AsResource( texture->m_texture );

	return ALL_OK;
}
Example #2
0
ERet FxUtil_LoadShaderLibrary( AStreamReader& stream, Clump &clump, const Resolution& screen )
{
	FxLibraryHeader_d	libraryHeader;
	mxDO(stream.Get(libraryHeader));

	// Load shader library structures.

#if mxUSE_BINARY_EFFECT_FILE_FORMAT
	UNDONE;
	//mxTRY(Serialization::LoadClumpImage(stream, clump));
#else

	ByteBuffer32	buffer;
	buffer.SetNum(libraryHeader.runtimeSize);
	stream.Read(buffer.ToPtr(), buffer.Num());

	SON::Parser		parser;
	parser.buffer = (char*)buffer.ToPtr();
	parser.length = libraryHeader.runtimeSize;
	parser.line = 1;
	parser.file = "";

	SON::Allocator	allocator;
	SON::Node* root = SON::ParseBuffer(parser, allocator);
	chkRET_X_IF_NIL(root, ERR_FAILED_TO_PARSE_DATA);

	mxTRY(SON::LoadClump( root, clump ));
#endif

	// Initialization order:
	// 1) Render targets
	// 2) State objects
	// 3) Shaders
	// 4) Input layouts
	// 5) Everything else

	// render targets should be sorted by size
	// shader resources should be sorted by size
	// constant buffers should be sorted by size

	CreateRenderTargets(screen, clump, false);

	// Ideally, render states should be sorted by state deltas (so that changes between adjacent states are minimized).

	{
		TObjectIterator< FxSamplerState >	samplerStateIt( clump );
		while( samplerStateIt.IsValid() )
		{
			FxSamplerState& samplerState = samplerStateIt.Value();
			samplerState.handle = llgl::CreateSamplerState( samplerState );
			samplerStateIt.MoveToNext();
		}
	}
	{
		TObjectIterator< FxDepthStencilState >	depthStencilStateIt( clump );
		while( depthStencilStateIt.IsValid() )
		{
			FxDepthStencilState& depthStencilState = depthStencilStateIt.Value();
			depthStencilState.handle = llgl::CreateDepthStencilState( depthStencilState );
			depthStencilStateIt.MoveToNext();
		}
	}
	{
		TObjectIterator< FxRasterizerState >	rasterizerStateIt( clump );
		while( rasterizerStateIt.IsValid() )
		{
			FxRasterizerState& rasterizerState = rasterizerStateIt.Value();
			rasterizerState.handle = llgl::CreateRasterizerState( rasterizerState );
			rasterizerStateIt.MoveToNext();
		}
	}
	{
		TObjectIterator< FxBlendState >	blendStateIt( clump );
		while( blendStateIt.IsValid() )
		{
			FxBlendState& blendState = blendStateIt.Value();
			blendState.handle = llgl::CreateBlendState( blendState );
			blendStateIt.MoveToNext();
		}
	}

	FxRenderResources* renderStates = FindSingleInstance<FxRenderResources>(clump);
	if(renderStates)
	{
		for( UINT32 iStateBlock = 0; iStateBlock < renderStates->state_blocks.Num(); iStateBlock++ )
		{
			FxStateBlock* stateBlock = renderStates->state_blocks[ iStateBlock ];
			stateBlock->blendState		= renderStates->blend_states[ stateBlock->blendState.id ]->handle;
			stateBlock->rasterizerState	= renderStates->rasterizer_states[ stateBlock->rasterizerState.id ]->handle;
			stateBlock->depthStencilState= renderStates->depth_stencil_states[ stateBlock->depthStencilState.id ]->handle;
		}
	}

	// Create constant buffers and shader resources.
	{
		TObjectIterator< FxCBuffer >	cbufferIt( clump );
		while( cbufferIt.IsValid() )
		{
			FxCBuffer& ubo = cbufferIt.Value();
			ubo.handle = llgl::CreateBuffer( Buffer_Uniform, ubo.size, NULL );
			cbufferIt.MoveToNext();
		}
	}

	CacheHeader_d	cacheHeader;
	mxDO(stream.Get(cacheHeader));

	// Create shaders.
	FxShaderHandles	shaders;
	ScopedStackAlloc	tempAlloc( gCore.frameAlloc );
	for( UINT32 shaderType = 0; shaderType < ShaderTypeCount; shaderType++ )
	{
		const UINT32 shaderCount = cacheHeader.numShaders[shaderType];
		if( shaderCount ) {
			HShader* shaderHandlesStorage = tempAlloc.AllocMany< HShader >( shaderCount );
			shaders.handles[shaderType].SetExternalStorage( shaderHandlesStorage, shaderCount );
			shaders.handles[shaderType].SetNum( shaderCount );
		}
	}
	mxDO(ShaderCache_d::CreateShaders( cacheHeader, stream, shaders ));

	// Create programs.
	TArray< HProgram >	programHandles;
	{
		const UINT32 programsCount = cacheHeader.numPrograms;
		HProgram* programHandlesStorage = tempAlloc.AllocMany< HProgram >( programsCount );
		programHandles.SetExternalStorage( programHandlesStorage, programsCount );
		programHandles.SetNum( programsCount );

		ScopedStackAlloc	programAlloc( gCore.frameAlloc );
		char *	tempBuffer = programAlloc.Alloc( cacheHeader.bufferSize );
		ByteArrayT	programBlob( tempBuffer, cacheHeader.bufferSize );

		for( UINT32 programIndex = 0; programIndex < programsCount; programIndex++ )
		{
			stream >> programBlob;

			CachedProgram_d *	program;
			mxDO(Serialization::LoadInPlace( programBlob.ToPtr(), programBlob.Num(), program ));

			HShader* shaderIds = program->pd.shaders;
			for( UINT32 shaderType = 0; shaderType < ShaderTypeCount; shaderType++ )
			{
				const UINT16 shaderIndex = shaderIds[shaderType].id;
				if( shaderIndex != (UINT16)~0 ) {
					shaderIds[shaderType] = shaders.handles[shaderType][shaderIndex];
				}
			}

			const HProgram programHandle = llgl::CreateProgram( program->pd );
			programHandles[programIndex] = programHandle;
		}
	}

	{
		TObjectIterator< FxShader >	shaderIt( clump );
		while( shaderIt.IsValid() )
		{
			FxShader& shader = shaderIt.Value();

			for( UINT32 i = 0; i < shader.programs.Num(); i++ )
			{
				int programIndex = shader.programs[i].id;
				shader.programs[i] = programHandles[programIndex];
			}

			shaderIt.MoveToNext();
		}
	}


	return ALL_OK;
}
 virtual void report_free_memory(TestResult* result, TestMemoryAllocator* allocator, char* , const char* , int )
 {
     TemporaryDefaultNewAllocator tempAlloc(previousNewAllocator);
     mock("formatter").actualCall("report_free_memory").withParameter("result", result).withParameterOfType("TestMemoryAllocator", "allocator", allocator);
 }
 virtual void report_test_end(TestResult* result, UtestShell& test)
 {
     TemporaryDefaultNewAllocator tempAlloc(previousNewAllocator);
     mock("formatter").actualCall("report_test_end").withParameter("result", result).withParameter("test", &test);
 }