本文整理汇总了C++中CPUTOSServices类的典型用法代码示例。如果您正苦于以下问题:C++ CPUTOSServices类的具体用法?C++ CPUTOSServices怎么用?C++ CPUTOSServices使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CPUTOSServices类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindDomainShader
// Retrieve specified domain shader
//-----------------------------------------------------------------------------
CPUTResult CPUTAssetLibraryDX11::GetDomainShader(
const cString &name,
ID3D11Device *pD3dDevice,
const cString &shaderMain,
const cString &shaderProfile,
CPUTDomainShaderDX11 **ppDomainShader,
bool nameIsFullPathAndFilename
)
{
CPUTResult result = CPUT_SUCCESS;
cString finalName;
if( name.at(0) == '$' )
{
finalName = name;
} else
{
// Resolve name to absolute path
CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
pServices->ResolveAbsolutePathAndFilename( nameIsFullPathAndFilename? name : (mShaderDirectoryName + name), &finalName);
}
// see if the shader is already in the library
void *pShader = FindDomainShader(finalName + shaderMain + shaderProfile, true);
if(NULL!=pShader)
{
*ppDomainShader = (CPUTDomainShaderDX11*) pShader;
(*ppDomainShader)->AddRef();
return result;
}
*ppDomainShader = CPUTDomainShaderDX11::CreateDomainShader( finalName, pD3dDevice, shaderMain, shaderProfile );
return result;
}
示例2: SetResourceDirectory
// sets the resource directory to use when loading GUI resources
//-----------------------------------------------------------------------------
CPUTResult CPUTGuiController::SetResourceDirectory(const cString ResourceDirectory)
{
// check to see if the specified directory is valid
CPUTResult result = CPUT_SUCCESS;
// resolve the directory to a full path
cString FullPath;
CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
result = pServices->ResolveAbsolutePathAndFilename(ResourceDirectory, &FullPath);
if(CPUTFAILED(result))
{
return result;
}
// check existence of directory
result = pServices->DoesDirectoryExist(FullPath);
if(CPUTFAILED(result))
{
return result;
}
// set the resource directory (absolute path)
mResourceDirectory = FullPath;
return result;
}
示例3: CreateFont
//-----------------------------------------------------------------------------
CPUTFont *CPUTAssetLibrary::GetFont(const cString &name )
{
// Resolve name to absolute path
CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
cString absolutePathAndFilename;
pServices->ResolveAbsolutePathAndFilename( (mFontDirectoryName + name), &absolutePathAndFilename);
// If we already have one by this name, then return it
CPUTFont *pFont = FindFont(absolutePathAndFilename, true);
if(NULL==pFont)
{
return CPUTFont::CreateFont( name, absolutePathAndFilename);
}
pFont->AddRef();
return pFont;
}
示例4: GetPixelShader
// Retrieve specified pixel shader
// TODO: Delegate creation to asset (AssetLibrary shouldn't know the nitty-gritty details of how to create an asset)
//-----------------------------------------------------------------------------
CPUTResult CPUTAssetLibraryOGLES::GetPixelShader(
const cString &name,
const cString &shaderMain,
const cString &shaderProfile,
CPUTPixelShaderOGLES **ppPixelShader,
bool nameIsFullPathAndFilename
)
{
CPUTResult result = CPUT_SUCCESS;
// Resolve name to absolute path before searching
cString absolutePathAndFilename;
CPUTOSServices* pServices = CPUTOSServices::GetOSServices();
pServices->ResolveAbsolutePathAndFilename( nameIsFullPathAndFilename? name : (m_ShaderDirectoryName + name), &absolutePathAndFilename);
// see if the shader is already in the library
void *pShader = FindPixelShader(absolutePathAndFilename);
if(NULL!=pShader)
{
*ppPixelShader = (CPUTPixelShaderOGLES*) pShader;
(*ppPixelShader)->AddRef();
return result;
}
// load the pixel shader as null-terminated char* string
void* pShaderString=NULL;
result = LoadShaderFileString(absolutePathAndFilename, &pShaderString);
ASSERT( CPUTSUCCESS(result), _L("Error loading pixel shader: ")+name );
// compile the pixel/fragment shader
GLuint NewPixelShaderID = CompileShader(GL_FRAGMENT_SHADER, pShaderString);
ASSERT( (0!=NewPixelShaderID), _L("Error compiling pixel shader: "+name) );
// delete the shader's string now that it's no longer needed
delete [] pShaderString;
// store this new shader
CPUTPixelShaderOGLES *pNewCPUTPixelShader = new CPUTPixelShaderOGLES( NewPixelShaderID );
// add shader to library
AddPixelShader(absolutePathAndFilename, pNewCPUTPixelShader);
// return the shader
*ppPixelShader = pNewCPUTPixelShader;
return result;
}
示例5: CreateAssetSet
//-----------------------------------------------------------------------------
CPUTAssetSet *CPUTAssetLibrary::GetAssetSet( const cString &name, bool nameIsFullPathAndFilename )
{
// Resolve the absolute path
cString absolutePathAndFilename;
CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
pServices->ResolveAbsolutePathAndFilename( nameIsFullPathAndFilename ? name
: (mAssetSetDirectoryName + name + _L(".set")), &absolutePathAndFilename );
absolutePathAndFilename = nameIsFullPathAndFilename ? name : absolutePathAndFilename;
CPUTAssetSet *pAssetSet = FindAssetSet(absolutePathAndFilename, true);
if(NULL == pAssetSet)
{
return CPUTAssetSet::CreateAssetSet( name, absolutePathAndFilename );
}
pAssetSet->AddRef();
return pAssetSet;
}
示例6: CPUTComputeHash
// Find an asset in a specific library
// ** Does not Addref() returned items **
// Asset library doesn't care if we're using absolute paths for names or not, it
// just adds/finds/deletes the matching string literal.
//-----------------------------------------------------------------------------
void *CPUTAssetLibrary::FindAsset(const cString &name, CPUTAssetListEntry *pList, bool nameIsFullPathAndFilename)
{
cString absolutePathAndFilename;
CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
pServices->ResolveAbsolutePathAndFilename( nameIsFullPathAndFilename ? name : (mAssetSetDirectoryName + name), &absolutePathAndFilename);
absolutePathAndFilename = nameIsFullPathAndFilename ? name : absolutePathAndFilename;
UINT hash = CPUTComputeHash( absolutePathAndFilename );
while(NULL!=pList)
{
if( hash == pList->hash && (0 == _wcsicmp( absolutePathAndFilename.data(), pList->name.data() )) )
{
return (void*)pList->pData;
}
pList = pList->pNext;
}
return NULL;
}
示例7: CreateWindow
//
// FUNCTION: InitInstance(HINSTANCE, int)
// PURPOSE: Saves instance handle and creates main window
// COMMENTS:
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//-----------------------------------------------------------------------------
BOOL WindowWinCPRTViewer::InitInstance(HINSTANCE hInstance, int nCmdShow, int windowWidth, int windowHeight)
{
m_hInst = hInstance; // Store instance handle in our global variable
LPCSTR lpTitle = m_AppTitle;
if( (0==windowWidth) || (0==windowHeight) )
{
// zero sized windows means - you choose the size. :)
CPUTOSServices* pServices = CPUTOSServices::GetOSServices();
pServices->GetDesktopDimensions(windowWidth, windowHeight);
// default window size will be 1/3 of the screen size
windowWidth/=3;
windowHeight/=3;
}
m_hWnd = CreateWindow("CPRTChildWindowClass", lpTitle, //APPTITLE, APPTITLE, //szWindowClass, szTitle,
WS_CHILDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
100,
100,
parentHWnd,
NULL,
(HINSTANCE)GetWindowLongPtr(parentHWnd, GWLP_HINSTANCE),
NULL);
if (!m_hWnd)
{
return FALSE;
}
ShowWindow(m_hWnd, nCmdShow);
UpdateWindow(m_hWnd);
CPUTOSServices* pServices = CPUTOSServices::GetOSServices();
pServices->SethWnd(m_hWnd);
return TRUE;
}
示例8: CreateTexture
//-----------------------------------------------------------------------------
CPUTTexture *CPUTAssetLibrary::GetTexture(const cString &name, bool nameIsFullPathAndFilename, bool loadAsSRGB )
{
cString finalName;
if( name.at(0) == '$' )
{
finalName = name;
} else
{
// Resolve name to absolute path
CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
pServices->ResolveAbsolutePathAndFilename( nameIsFullPathAndFilename? name : (mTextureDirectoryName + name), &finalName);
}
// If we already have one by this name, then return it
CPUTTexture *pTexture = FindTexture(finalName, true);
if(NULL==pTexture)
{
return CPUTTexture::CreateTexture( name, finalName, loadAsSRGB);
}
pTexture->AddRef();
return pTexture;
}
示例9: CreateRenderStateBlock
//-----------------------------------------------------------------------------
CPUTRenderStateBlock *CPUTAssetLibrary::GetRenderStateBlock(const cString &name, bool nameIsFullPathAndFilename )
{
// Resolve name to absolute path before searching
cString finalName;
if( name.at(0) == '$' )
{
finalName = name;
} else
{
// Resolve name to absolute path
CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
pServices->ResolveAbsolutePathAndFilename( nameIsFullPathAndFilename? name : (mShaderDirectoryName + name), &finalName);
}
// see if the render state block is already in the library
CPUTRenderStateBlock *pRenderStateBlock = FindRenderStateBlock(finalName, true);
if(NULL==pRenderStateBlock)
{
return CPUTRenderStateBlock::CreateRenderStateBlock( name, finalName );
}
pRenderStateBlock->AddRef();
return pRenderStateBlock;
}
示例10: Present
// incoming resize event to be handled and translated
//-----------------------------------------------------------------------------
void CPUT_DX11::ResizeWindow(UINT width, UINT height)
{
HRESULT hr;
CPUTResult result;
CPUTAssetLibraryDX11 *pAssetLibrary = (CPUTAssetLibraryDX11*)CPUTAssetLibraryDX11::GetAssetLibrary();
// TODO: Making the back and depth buffers into CPUTRenderTargets should simplify this (CPUTRenderTarget* manages RTV, SRV, UAV, etc.)
if( mpBackBuffer ) ((CPUTBufferDX11*)mpBackBuffer)->ReleaseBuffer();
if( mpDepthBuffer ) ((CPUTBufferDX11*)mpDepthBuffer)->ReleaseBuffer();
if( mpBackBufferTexture ) ((CPUTTextureDX11*)mpBackBufferTexture)->ReleaseTexture();
if( mpDepthBufferTexture ) ((CPUTTextureDX11*)mpDepthBufferTexture)->ReleaseTexture();
// Make sure we don't have any buffers bound.
mpContext->ClearState();
Present();
mpContext->Flush();
SAFE_RELEASE(mpBackBufferRTV);
SAFE_RELEASE(mpBackBufferSRV);
SAFE_RELEASE(mpBackBufferUAV);
SAFE_RELEASE(mpDepthStencilSRV);
CPUT::ResizeWindow( width, height );
// Call the sample's clean up code if present.
ReleaseSwapChain();
// handle the internals of a resize
int windowWidth, windowHeight;
CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
pServices->GetClientDimensions( &windowWidth, &windowHeight);
// resize the swap chain
hr = mpSwapChain->ResizeBuffers(mSwapChainBufferCount, windowWidth, windowHeight, mSwapChainFormat, 0);
ASSERT( SUCCEEDED(hr), _L("Error resizing swap chain") );
// re-create the render-target view
ID3D11Texture2D *pSwapChainBuffer = NULL;
hr = mpSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D), (LPVOID*) (&pSwapChainBuffer));
ASSERT(SUCCEEDED(hr), _L(""));
hr = mpD3dDevice->CreateRenderTargetView( pSwapChainBuffer, NULL, &mpBackBufferRTV);
ASSERT(SUCCEEDED(hr), _L(""));
hr = mpD3dDevice->CreateShaderResourceView( pSwapChainBuffer, NULL, &mpBackBufferSRV);
ASSERT(SUCCEEDED(hr), _L(""));
#ifdef CREATE_SWAP_CHAIN_UAV
// Not every DXGI format supports UAV. So, create UAV only if sample chooses to do so.
hr = mpD3dDevice->CreateUnorderedAccessView( pSwapChainBuffer, NULL, &mpBackBufferUAV);
ASSERT(SUCCEEDED(hr), _L(""));
#endif
// Add the back buffer to the asset library. Create CPUTBuffer and a CPUTTexture forms and add them.
if( mpBackBuffer )
{
((CPUTBufferDX11*)mpBackBuffer)->SetBufferAndViews( NULL, mpBackBufferSRV, mpBackBufferUAV );
}
else
{
cString backBufferName = _L("$BackBuffer");
mpBackBuffer = new CPUTBufferDX11( backBufferName, NULL, mpBackBufferUAV );
pAssetLibrary->AddBuffer( backBufferName, mpBackBuffer );
}
if( mpBackBufferTexture )
{
((CPUTTextureDX11*)mpBackBufferTexture)->SetTextureAndShaderResourceView( NULL, mpBackBufferSRV );
}
else
{
cString backBufferName = _L("$BackBuffer");
mpBackBufferTexture = new CPUTTextureDX11( backBufferName, NULL, mpBackBufferSRV );
pAssetLibrary->AddTexture( backBufferName, mpBackBufferTexture );
}
// release the old depth buffer objects
// release the temporary swap chain buffer
SAFE_RELEASE(pSwapChainBuffer);
SAFE_RELEASE(mpDepthStencilBuffer);
SAFE_RELEASE(mpDepthStencilState);
SAFE_RELEASE(mpDepthStencilView);
result = CreateAndBindDepthBuffer(windowWidth, windowHeight);
if(CPUTFAILED(result))
{
// depth buffer creation error
ASSERT(0,_L(""));
}
if( mpDepthBuffer )
{
((CPUTBufferDX11*)mpDepthBuffer)->SetBufferAndViews( NULL, mpDepthStencilSRV, NULL );
}
else
{
cString depthBufferName = _L("$DepthBuffer");
mpDepthBuffer = new CPUTBufferDX11( depthBufferName, NULL, mpDepthStencilSRV );
pAssetLibrary->AddBuffer( depthBufferName, mpDepthBuffer );
}
if( mpDepthBufferTexture )
{
((CPUTTextureDX11*)mpDepthBufferTexture)->SetTextureAndShaderResourceView( NULL, mpDepthStencilSRV );
//.........这里部分代码省略.........
示例11: ASSERT
// InitInstance
// Saves the windows instance handle, creates, and displays the main program
// window
//-----------------------------------------------------------------------------
BOOL CPUTWindowWin::InitInstance(int nCmdShow, int windowWidth, int windowHeight, int windowX, int windowY)
{
// assure we have a valid hInstance
ASSERT(NULL!=mhInst, _L(""));
// zero sized windows means - you choose the size. :)
if( (0==windowWidth) || (0==windowHeight) )
{
CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
pServices->GetDesktopDimensions(&windowWidth, &windowHeight);
// default window size 1280x720
// but if screen is smaller than 1280x720, then pick 1/3 the screen size
// so that it doesn't appear off the edges
if(1280>windowWidth)
{
windowWidth = (2*windowWidth)/3;
windowHeight = (2*windowHeight)/3;
}
else
{
windowWidth=1280;
windowHeight=720;
}
}
// set up size structure
RECT rc = { 0, 0, windowWidth, windowHeight };
AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
// if x = -1, then let windows decide where to put it
if(-1==windowX)
{
windowX = CW_USEDEFAULT;
}
// create the window
mhWnd = CreateWindow(mAppTitle.c_str(), mAppTitle.c_str(),
WS_OVERLAPPEDWINDOW,
windowX, //CW_USEDEFAULT,
windowY, //CW_USEDEFAULT,
rc.right - rc.left,
rc.bottom - rc.top,
NULL,
NULL,
mhInst,
NULL);
if (!mhWnd)
{
return FALSE;
}
ShowWindow(mhWnd, nCmdShow);
UpdateWindow(mhWnd);
// initialize the OS services with the hWND so you can make
// reference to this object
CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
pServices->SethWnd(mhWnd);
return TRUE;
}
示例12: RecalculateLayout
// Re-calculates all the positions of the controls based on their sizes
// to have a 'pretty' layout
//--------------------------------------------------------------------------------
void CPUTGuiController::RecalculateLayout()
{
// if we have no valid panel, just return
if(CPUT_CONTROL_ID_INVALID == mActiveControlPanelSlotID)
{
return;
}
// if we don't want the auto-layout feature, just return
if(false == mbAutoLayout)
{
return;
}
// get window size
CPUT_RECT windowRect;
CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
pServices->GetClientDimensions(&windowRect.x, &windowRect.y, &windowRect.width, &windowRect.height);
// Build columns of controls right to left
int x,y;
x=0; y=0;
// walk list of controls, counting up their *heights*, until the
// column is full. While counting, keep track of the *widest*
int width, height;
const int GUI_WINDOW_PADDING = 5;
int numberOfControls = (int) mControlPanelIDList[mActiveControlPanelSlotID]->mControlList.size();
int indexStart=0;
int indexEnd=0;
int columnX = 0;
int columnNumber = 1;
while(indexEnd < numberOfControls)
{
int columnWidth=0;
y=0;
// figure out which controls belong in this column + column width
while( indexEnd < numberOfControls )
{
if(mControlPanelIDList[mActiveControlPanelSlotID]->mControlList[indexEnd]->IsVisible() &&
mControlPanelIDList[mActiveControlPanelSlotID]->mControlList[indexEnd]->IsAutoArranged())
{
mControlPanelIDList[mActiveControlPanelSlotID]->mControlList[indexEnd]->GetDimensions(width, height);
if( y + height + GUI_WINDOW_PADDING < (windowRect.height-2*GUI_WINDOW_PADDING))
{
y = y + height + GUI_WINDOW_PADDING;
if(columnWidth < width)
{
columnWidth = width;
}
indexEnd++;
}
else
{
// if the window is now so small it won't fit a whole control, just
// draw one anyway and it'll just have to be clipped
if(indexEnd == indexStart)
{
columnWidth = width;
indexEnd++;
}
break;
}
}
else
{
indexEnd++;
}
}
// ok, now re-position each control with x at widest, and y at proper height
y=GUI_WINDOW_PADDING;
for(int i=indexStart; i<indexEnd; i++)
{
if(mControlPanelIDList[mActiveControlPanelSlotID]->mControlList[i]->IsVisible() &&
mControlPanelIDList[mActiveControlPanelSlotID]->mControlList[i]->IsAutoArranged())
{
mControlPanelIDList[mActiveControlPanelSlotID]->mControlList[i]->GetDimensions(width, height);
x = windowRect.width - columnX - columnWidth - (columnNumber*GUI_WINDOW_PADDING);
mControlPanelIDList[mActiveControlPanelSlotID]->mControlList[i]->SetPosition(x,y);
y = y + height + GUI_WINDOW_PADDING;
}
}
indexStart = indexEnd;
columnX+=columnWidth;
columnNumber++;
}
mRecalculateLayout = false;
}
示例13: CreateRenderTarget
//-----------------------------------------------
HRESULT CPUTRenderTargetColor::CreateRenderTarget(
cString textureName,
UINT width,
UINT height,
DXGI_FORMAT colorFormat,
UINT multiSampleCount,
bool createUAV,
bool recreate
)
{
HRESULT result;
mName = textureName;
mWidth = width;
mHeight = height;
mColorFormat = colorFormat;
mMultiSampleCount = multiSampleCount;
CPUTAssetLibrary *pAssetLibrary = CPUTAssetLibrary::GetAssetLibrary();
CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
// Create the color texture
int createFlags = createUAV
? D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS
: D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
mColorDesc = CD3D11_TEXTURE2D_DESC(
colorFormat,
width,
height,
1, // Array Size
1, // MIP Levels
createFlags,
D3D11_USAGE_DEFAULT,
0,
mMultiSampleCount, 0
);
ID3D11Device *pD3dDevice = CPUT_DX11::GetDevice();
// If MSAA enabled, then create MSAA texture
if( mMultiSampleCount>1 )
{
result = pD3dDevice->CreateTexture2D( &mColorDesc, NULL, &mpColorTextureDXMSAA );
ASSERT( SUCCEEDED(result), _L("Failed creating MSAA render target texture") );
D3D11_SHADER_RESOURCE_VIEW_DESC srDesc = { colorFormat, D3D11_SRV_DIMENSION_TEXTURE2DMS, 0 };
srDesc.Texture2D.MipLevels = 1;
result = pD3dDevice->CreateShaderResourceView( mpColorTextureDXMSAA, &srDesc, &mpColorSRVMSAA );
ASSERT( SUCCEEDED(result), _L("Failed creating MSAA render target shader resource view") );
CPUTSetDebugName( mpColorSRVMSAA, textureName + _L(" ColorMSAA") );
if( !recreate )
{
cString msaaName = mName + _L("_MSAA");
mpColorTextureMSAA = new CPUTTextureDX11( msaaName );
// If the name starts with a '$', then its an internal texture (has no filesystem path).
// Otherwise, its a file, so prepend filesystem path
CPUTAssetLibrary *pAssetLibrary = CPUTAssetLibrary::GetAssetLibrary();
cString finalName;
if( mName.at(0) == '$' )
{
finalName = msaaName;
}else
{
pServices->ResolveAbsolutePathAndFilename( (pAssetLibrary->GetTextureDirectory() + msaaName), &finalName);
}
pAssetLibrary->AddTexture( finalName, mpColorTextureMSAA );
}
((CPUTTextureDX11*)mpColorTextureMSAA)->SetTextureAndShaderResourceView( mpColorTextureDXMSAA, mpColorSRVMSAA );
}
// Create non-MSAA texture. If we're MSAA, then we'll resolve into this. If not, then we'll render directly to this one.
mColorDesc.SampleDesc.Count = 1;
result = pD3dDevice->CreateTexture2D( &mColorDesc, NULL, &mpColorTextureDX );
ASSERT( SUCCEEDED(result), _L("Failed creating render target texture") );
// Create the shader-resource view from the non-MSAA texture
D3D11_SHADER_RESOURCE_VIEW_DESC srDesc = { colorFormat, D3D11_SRV_DIMENSION_TEXTURE2D, 0 };
srDesc.Texture2D.MipLevels = 1;
result = pD3dDevice->CreateShaderResourceView( mpColorTextureDX, &srDesc, &mpColorSRV );
ASSERT( SUCCEEDED(result), _L("Failed creating render target shader resource view") );
CPUTSetDebugName( mpColorSRV, textureName + _L(" Color") );
mHasUav = createUAV; // Remember, so we know to recreate it (or not) on RecreateRenderTarget()
if( createUAV )
{
// D3D11_SHADER_RESOURCE_VIEW_DESC srDesc = { colorFormat, D3D_SRV_DIMENSION_BUFFER, 0 };
D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc;
memset( &uavDesc, 0, sizeof(uavDesc) );
uavDesc.Format = colorFormat;
uavDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
uavDesc.Texture2D.MipSlice = 0;
result = pD3dDevice->CreateUnorderedAccessView( mpColorTextureDX, &uavDesc, &mpColorUAV );
ASSERT( SUCCEEDED(result), _L("Failed creating render target buffer shader resource view") );
CPUTSetDebugName( mpColorUAV, textureName + _L(" Color Buffer") );
}
if( !recreate )
//.........这里部分代码省略.........
示例14: 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();
//.........这里部分代码省略.........
示例15: SetGUIDrawingState
//.........这里部分代码省略.........
break;
}
}
// update the uber-buffers with the control graphics
UpdateUberBuffers(pImmediateContext);
// Clear dirty flag on uberbuffer
mUberBufferDirty = false;
}
HEAPCHECK
// calculate the fps
double elapsed = mpFPSTimer->GetElapsedTime();
double fps = 1.0 / elapsed;
mLastFPS = (float) fps;
mFPSAvg[mFPSInst] = (float) fps;
mFPSInst++;
if(mFPSInst == AVG_FRAMES)
mFPSInst = 0;
float total = 0.0f;
for(int i = 0; i < AVG_FRAMES; i++)
{
total += mFPSAvg[i];
}
int windowWidth, windowHeight;
CPUTOSServices *pServices = CPUTOSServices::GetOSServices( );
pServices->GetClientDimensions( &windowWidth, &windowHeight );
// if we're drawing the FPS counter - update that
// We do this independently of uber-buffer updates since we'll have FPS updates every frame,
// but likely not have control updates every frame
if(mbDrawFPS)
{
// calculate the time elapsed since last frame
bool UberBufferWasDirty = mUberBufferDirty;
cString Data;
{
wchar_t wcstring[CPUT_MAX_STRING_LENGTH];
float avgFps = total/(float)AVG_FRAMES;
swprintf_s(&wcstring[0], CPUT_MAX_STRING_LENGTH, _L("Window res: %d x %d, AVG FPS:%.2f \t(FPS:%.2f) "), windowWidth, windowHeight, avgFps, fps);
Data=wcstring;
}
// build the FPS string
cString FPS = Data;
mpFPSCounter->SetText(FPS);
// 'draw' the string into the buffer
mFPSBufferIndex = 0;
mpFPSCounter->DrawIntoBuffer(mpFPSMirrorBuffer, &mFPSBufferIndex, CPUT_GUI_BUFFER_STRING_SIZE);
// update the DirectX vertex buffer
ASSERT(CPUT_GUI_BUFFER_STRING_SIZE > mFocusedControlTextBufferIndex, _L("CPUT GUI: Too many strings for default-sized uber-buffer. Increase CPUT_GUI_BUFFER_STRING_SIZE"));
pImmediateContext->UpdateSubresource(mpFPSDirectXBuffer, 0, NULL, mpFPSMirrorBuffer, mFPSBufferIndex*sizeof(CPUTGUIVertex), 0);
// start next frame timer
mpFPSTimer->StartTimer();
if(false == UberBufferWasDirty)