本文整理汇总了C++中CPUTAssetLibraryDX11::GetTexture方法的典型用法代码示例。如果您正苦于以下问题:C++ CPUTAssetLibraryDX11::GetTexture方法的具体用法?C++ CPUTAssetLibraryDX11::GetTexture怎么用?C++ CPUTAssetLibraryDX11::GetTexture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPUTAssetLibraryDX11
的用法示例。
在下文中一共展示了CPUTAssetLibraryDX11::GetTexture方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT
//-----------------------------------------------------------------------------
void CPUTMaterialDX11::BindTextures( CPUTShaderParameters ¶ms, const CPUTModel *pModel, int meshIndex )
{
CPUTAssetLibraryDX11 *pAssetLibrary = (CPUTAssetLibraryDX11*)CPUTAssetLibrary::GetAssetLibrary();
for(params.mTextureCount=0; params.mTextureCount < params.mTextureParameterCount; params.mTextureCount++)
{
cString textureName;
UINT textureCount = params.mTextureCount;
cString tagName = params.mpTextureParameterName[textureCount];
CPUTConfigEntry *pValue = mConfigBlock.GetValueByName(tagName);
if( !pValue->IsValid() )
{
// We didn't find our property in the file. Is it in the global config block?
pValue = mGlobalProperties.GetValueByName(tagName);
}
ASSERT( pValue->IsValid(), L"Can't find texture '" + tagName + L"'." ); // TODO: fix message
textureName = pValue->ValueAsString();
// If the texture name not specified. Load default.dds instead
if( 0 == textureName.length() ) { textureName = _L("default.dds"); }
UINT bindPoint = params.mpTextureParameterBindPoint[textureCount];
ASSERT( bindPoint < CPUT_MATERIAL_MAX_TEXTURE_SLOTS, _L("Texture bind point out of range.") );
if( textureName[0] == '@' )
{
// This is a per-mesh value. Add to per-mesh list.
textureName += ptoc(pModel) + itoc(meshIndex);
} else if( textureName[0] == '#' )
{
// This is a per-mesh value. Add to per-mesh list.
textureName += ptoc(pModel);
}
// Get the sRGB flag (default to true)
cString SRGBName = tagName+_L("sRGB");
CPUTConfigEntry *pSRGBValue = mConfigBlock.GetValueByName(SRGBName);
bool loadAsSRGB = pSRGBValue->IsValid() ? loadAsSRGB = pSRGBValue->ValueAsBool() : true;
if( !mpTexture[textureCount] )
{
mpTexture[textureCount] = pAssetLibrary->GetTexture( textureName, false, loadAsSRGB );
ASSERT( mpTexture[textureCount], _L("Failed getting texture ") + textureName);
}
// The shader file (e.g. .fx) can specify the texture bind point (e.g., t0). Those specifications
// might not be contiguous, and there might be gaps (bind points without assigned textures)
// TODO: Warn about missing bind points?
params.mppBindViews[bindPoint] = ((CPUTTextureDX11*)mpTexture[textureCount])->GetShaderResourceView();
params.mppBindViews[bindPoint]->AddRef();
}
}
示例2: ASSERT
// Load and register all the resources needed by the GUI system
//-----------------------------------------------------------------------------
CPUTResult CPUTGuiControllerDX11::RegisterGUIResources(ID3D11DeviceContext *pImmediateContext, cString VertexShaderFilename, cString PixelShaderFilename, cString RenderStateFile, cString DefaultFontFilename, cString ControlAtlasTexture)
{
if(NULL==pImmediateContext)
{
return CPUT_ERROR_INVALID_PARAMETER;
}
CPUTResult result;
HRESULT hr;
ID3D11Device *pD3dDevice = NULL;
CPUTOSServices *pServices = NULL;
CPUTAssetLibraryDX11 *pAssetLibrary = NULL;
cString ErrorMessage;
// Get the services/resource pointers we need
pServices = CPUTOSServices::GetOSServices();
pImmediateContext->GetDevice(&pD3dDevice);
pAssetLibrary = (CPUTAssetLibraryDX11*)CPUTAssetLibraryDX11::GetAssetLibrary();
// Get the resource directory
cString ResourceDirectory;
CPUTGuiControllerDX11::GetController()->GetResourceDirectory(ResourceDirectory);
// 1. Load the renderstate configuration for the GUI system
mpGUIRenderStateBlock = (CPUTRenderStateBlockDX11*) pAssetLibrary->GetRenderStateBlock(ResourceDirectory+RenderStateFile);
ASSERT(mpGUIRenderStateBlock, _L("Error loading the render state file (.rs) needed for the CPUT GUI system"));
// 2. Store the shader path from AssetLibrary, change it to OUR resource directory
cString OriginalAssetLibraryDirectory = pAssetLibrary->GetShaderDirectory();
pAssetLibrary->SetShaderDirectoryName(ResourceDirectory);
// 3. load the shaders for gui drawing
// Load the GUI Vertex Shader
cString FullPath, FinalPath;
FullPath = mResourceDirectory + VertexShaderFilename;
pServices->ResolveAbsolutePathAndFilename(FullPath, &FinalPath);
result = pAssetLibrary->GetVertexShader(FinalPath, pD3dDevice, _L("VS"), _L("vs_4_0"), &mpGUIVertexShader, true);
CPUTSetDebugName( mpGUIVertexShader->GetNativeVertexShader(), _L("GUIVertexShader"));
if(CPUTFAILED(result))
{
ASSERT(CPUTSUCCESS(result), _L("Error loading the vertex shader needed for the CPUT GUI system."));
}
ID3DBlob *pVertexShaderBlob = mpGUIVertexShader->GetBlob();
// Load the GUI Pixel Shader
FullPath = mResourceDirectory + PixelShaderFilename;
pServices->ResolveAbsolutePathAndFilename(FullPath, &FinalPath);
result = pAssetLibrary->GetPixelShader(FinalPath, pD3dDevice, _L("PS"), _L("ps_4_0"), &mpGUIPixelShader, true);
CPUTSetDebugName( mpGUIPixelShader->GetNativePixelShader(), _L("GUIPixelShader"));
if(CPUTFAILED(result))
{
ASSERT(CPUTSUCCESS(result), _L("Error loading the pixel shader needed for the CPUT GUI system."));
}
// Restore the previous shader directory
pAssetLibrary->SetShaderDirectoryName(OriginalAssetLibraryDirectory);
// 4. Create the vertex layout description for all the GUI controls we'll draw
// set vertex shader as active so we can configure it
ID3D11VertexShader *pVertexShader = mpGUIVertexShader->GetNativeVertexShader();
pImmediateContext->VSSetShader( pVertexShader, NULL, 0 );
D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
UINT numElements = ARRAYSIZE( layout );
// Create the input layout
hr = pD3dDevice->CreateInputLayout( layout, numElements, pVertexShaderBlob->GetBufferPointer(), pVertexShaderBlob->GetBufferSize(), &mpVertexLayout );
ASSERT( SUCCEEDED(hr), _L("Error creating CPUT GUI system input layout" ));
CPUTSetDebugName( mpVertexLayout, _L("CPUT GUI InputLayout object"));
// 5. create the vertex shader constant buffer pointers
D3D11_BUFFER_DESC bd;
ZeroMemory( &bd, sizeof(bd) );
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof(GUIConstantBufferVS);
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bd.CPUAccessFlags = 0;
hr = pD3dDevice->CreateBuffer( &bd, NULL, &mpConstantBufferVS );
ASSERT( SUCCEEDED(hr), _L("Error creating constant buffer VS" ));
CPUTSetDebugName( mpConstantBufferVS, _L("GUI ConstantBuffer"));
// Set the texture directory for loading the control texture atlas
pAssetLibrary->SetTextureDirectoryName(ResourceDirectory);
// load the control atlas
mpControlTextureAtlas = (CPUTTextureDX11*) pAssetLibrary->GetTexture(ControlAtlasTexture);
if(NULL==mpControlTextureAtlas)
{
return CPUT_TEXTURE_LOAD_ERROR;
}
mpControlTextureAtlasView = mpControlTextureAtlas->GetShaderResourceView();
//.........这里部分代码省略.........