本文整理汇总了C++中CGrowableArray::Add方法的典型用法代码示例。如果您正苦于以下问题:C++ CGrowableArray::Add方法的具体用法?C++ CGrowableArray::Add怎么用?C++ CGrowableArray::Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGrowableArray
的用法示例。
在下文中一共展示了CGrowableArray::Add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InFile
//--------------------------------------------------------------------------------------
HRESULT CMeshLoader10::LoadGeometryFromOBJ( const WCHAR* strFileName )
{
WCHAR strMaterialFilename[MAX_PATH] = {0};
WCHAR wstr[MAX_PATH];
char str[MAX_PATH];
HRESULT hr;
// Find the file
V_RETURN( DXUTFindDXSDKMediaFileCch( wstr, MAX_PATH, strFileName ) );
WideCharToMultiByte( CP_ACP, 0, wstr, -1, str, MAX_PATH, NULL, NULL );
// Store the directory where the mesh was found
wcscpy_s( m_strMediaDir, MAX_PATH - 1, wstr );
WCHAR* pch = wcsrchr( m_strMediaDir, L'/' );
if( pch )
*pch = NULL;
// Create temporary storage for the input data. Once the data has been loaded into
// a reasonable format we can create a D3DXMesh object and load it with the mesh data.
CGrowableArray <D3DXVECTOR3> Positions;
CGrowableArray <D3DXVECTOR2> TexCoords;
CGrowableArray <D3DXVECTOR3> Normals;
// The first subset uses the default material
Material* pMaterial = new Material();
if( pMaterial == NULL )
return E_OUTOFMEMORY;
InitMaterial( pMaterial );
wcscpy_s( pMaterial->strName, MAX_PATH - 1, L"default" );
m_Materials.Add( pMaterial );
DWORD dwCurSubset = 0;
// File input
WCHAR strCommand[256] = {0};
wifstream InFile( str );
if( !InFile )
return DXTRACE_ERR( L"wifstream::open", E_FAIL );
for(; ; )
{
InFile >> strCommand;
if( !InFile )
break;
if( 0 == wcscmp( strCommand, L"#" ) )
{
// Comment
}
else if( 0 == wcscmp( strCommand, L"v" ) )
{
// Vertex Position
float x, y, z;
InFile >> x >> y >> z;
Positions.Add( D3DXVECTOR3( x, y, z ) );
}
else if( 0 == wcscmp( strCommand, L"vt" ) )
示例2: ClearAdapterInfoList
//--------------------------------------------------------------------------------------
// Enumerates available D3D adapters, devices, modes, etc.
//--------------------------------------------------------------------------------------
HRESULT CD3DEnumeration::Enumerate( IDirect3D9* pD3D,
LPDXUTCALLBACKISDEVICEACCEPTABLE IsDeviceAcceptableFunc,
void* pIsDeviceAcceptableFuncUserContext )
{
if( pD3D == NULL )
{
pD3D = DXUTGetD3DObject();
if( pD3D == NULL )
return DXUTERR_NODIRECT3D;
}
m_pD3D = pD3D;
m_IsDeviceAcceptableFunc = IsDeviceAcceptableFunc;
m_pIsDeviceAcceptableFuncUserContext = pIsDeviceAcceptableFuncUserContext;
HRESULT hr;
ClearAdapterInfoList();
CGrowableArray<D3DFORMAT> adapterFormatList;
const D3DFORMAT allowedAdapterFormatArray[] =
{
D3DFMT_X8R8G8B8,
D3DFMT_X1R5G5B5,
D3DFMT_R5G6B5,
D3DFMT_A2R10G10B10
};
const UINT allowedAdapterFormatArrayCount = sizeof(allowedAdapterFormatArray) / sizeof(allowedAdapterFormatArray[0]);
UINT numAdapters = pD3D->GetAdapterCount();
for (UINT adapterOrdinal = 0; adapterOrdinal < numAdapters; adapterOrdinal++)
{
CD3DEnumAdapterInfo* pAdapterInfo = MEMALLOC_NEW(CD3DEnumAdapterInfo);
if( pAdapterInfo == NULL )
return E_OUTOFMEMORY;
pAdapterInfo->AdapterOrdinal = adapterOrdinal;
pD3D->GetAdapterIdentifier(adapterOrdinal, 0, &pAdapterInfo->AdapterIdentifier);
// Get list of all display modes on this adapter.
// Also build a temporary list of all display adapter formats.
adapterFormatList.RemoveAll();
for( UINT iFormatList = 0; iFormatList < allowedAdapterFormatArrayCount; iFormatList++ )
{
D3DFORMAT allowedAdapterFormat = allowedAdapterFormatArray[iFormatList];
UINT numAdapterModes = pD3D->GetAdapterModeCount( adapterOrdinal, allowedAdapterFormat );
for (UINT mode = 0; mode < numAdapterModes; mode++)
{
D3DDISPLAYMODE displayMode;
pD3D->EnumAdapterModes( adapterOrdinal, allowedAdapterFormat, mode, &displayMode );
if( displayMode.Width < m_nMinWidth ||
displayMode.Height < m_nMinHeight ||
displayMode.Width > m_nMaxWidth ||
displayMode.Height > m_nMaxHeight ||
displayMode.RefreshRate < m_nRefreshMin ||
displayMode.RefreshRate > m_nRefreshMax )
{
continue;
}
pAdapterInfo->displayModeList.Add( displayMode );
if( !adapterFormatList.Contains(displayMode.Format) )
adapterFormatList.Add( displayMode.Format );
}
}
D3DDISPLAYMODE displayMode;
pD3D->GetAdapterDisplayMode( adapterOrdinal, &displayMode );
if( !adapterFormatList.Contains(displayMode.Format) )
adapterFormatList.Add( displayMode.Format );
// Sort displaymode list
::qsort( pAdapterInfo->displayModeList.GetData(),
pAdapterInfo->displayModeList.GetSize(), sizeof( D3DDISPLAYMODE ),
SortModesCallback );
// Get info for each device on this adapter
if( FAILED( EnumerateDevices( pAdapterInfo, &adapterFormatList ) ) )
{
delete pAdapterInfo;
continue;
}
// If at least one device on this adapter is available and compatible
// with the app, add the adapterInfo to the list
if( pAdapterInfo->deviceInfoList.GetSize() > 0 )
{
hr = m_AdapterInfoList.Add( pAdapterInfo );
if( FAILED(hr) )
return hr;
} else
delete pAdapterInfo;
}
//.........这里部分代码省略.........
示例3: if
void Dx11TextHelper::DrawText11DXUT( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3d11DeviceContext,
LPCSTR strText, RECT rcScreen, D3DXCOLOR vFontColor,
float fBBWidth, float fBBHeight, bool bCenter )
{
float fCharTexSizeX = 0.010526315f;
//float fGlyphSizeX = 14.0f / fBBWidth;
//float fGlyphSizeY = 32.0f / fBBHeight;
float fGlyphSizeX = 15.0f / fBBWidth;
float fGlyphSizeY = 42.0f / fBBHeight;
float fRectLeft = rcScreen.left / fBBWidth;
float fRectTop = 1.0f - rcScreen.top / fBBHeight;
fRectLeft = fRectLeft * 2.0f - 1.0f;
fRectTop = fRectTop * 2.0f - 1.0f;
int NumChars = (int)strlen( strText );
if (bCenter) {
float fRectRight = rcScreen.right / fBBWidth;
fRectRight = fRectRight * 2.0f - 1.0f;
float fRectBottom = 1.0f - rcScreen.bottom / fBBHeight;
fRectBottom = fRectBottom * 2.0f - 1.0f;
float fcenterx = ((fRectRight - fRectLeft) - (float)NumChars*fGlyphSizeX) *0.5f;
float fcentery = ((fRectTop - fRectBottom) - (float)1*fGlyphSizeY) *0.5f;
fRectLeft += fcenterx ;
fRectTop -= fcentery;
}
float fOriginalLeft = fRectLeft;
float fTexTop = 0.0f;
float fTexBottom = 1.0f;
float fDepth = 0.5f;
for( int i=0; i<NumChars; i++ )
{
if( strText[i] == '\n' )
{
fRectLeft = fOriginalLeft;
fRectTop -= fGlyphSizeY;
continue;
}
else if( strText[i] < 32 || strText[i] > 126 )
{
continue;
}
// Add 6 sprite vertices
DXUTSpriteVertex SpriteVertex;
float fRectRight = fRectLeft + fGlyphSizeX;
float fRectBottom = fRectTop - fGlyphSizeY;
float fTexLeft = ( strText[i] - 32 ) * fCharTexSizeX;
float fTexRight = fTexLeft + fCharTexSizeX;
// tri1
SpriteVertex.vPos = D3DXVECTOR3( fRectLeft, fRectTop, fDepth );
SpriteVertex.vTex = D3DXVECTOR2( fTexLeft, fTexTop );
SpriteVertex.vColor = vFontColor;
g_FontVertices.Add( SpriteVertex );
SpriteVertex.vPos = D3DXVECTOR3( fRectRight, fRectTop, fDepth );
SpriteVertex.vTex = D3DXVECTOR2( fTexRight, fTexTop );
SpriteVertex.vColor = vFontColor;
g_FontVertices.Add( SpriteVertex );
SpriteVertex.vPos = D3DXVECTOR3( fRectLeft, fRectBottom, fDepth );
SpriteVertex.vTex = D3DXVECTOR2( fTexLeft, fTexBottom );
SpriteVertex.vColor = vFontColor;
g_FontVertices.Add( SpriteVertex );
// tri2
SpriteVertex.vPos = D3DXVECTOR3( fRectRight, fRectTop, fDepth );
SpriteVertex.vTex = D3DXVECTOR2( fTexRight, fTexTop );
SpriteVertex.vColor = vFontColor;
g_FontVertices.Add( SpriteVertex );
SpriteVertex.vPos = D3DXVECTOR3( fRectRight, fRectBottom, fDepth );
SpriteVertex.vTex = D3DXVECTOR2( fTexRight, fTexBottom );
SpriteVertex.vColor = vFontColor;
g_FontVertices.Add( SpriteVertex );
SpriteVertex.vPos = D3DXVECTOR3( fRectLeft, fRectBottom, fDepth );
SpriteVertex.vTex = D3DXVECTOR2( fTexLeft, fTexBottom );
SpriteVertex.vColor = vFontColor;
g_FontVertices.Add( SpriteVertex );
fRectLeft += fGlyphSizeX;
}
// We have to end text after every line so that rendering order between sprites and fonts is preserved
EndText11( pd3dDevice, pd3d11DeviceContext );
}
示例4: ifs
//--------------------------------------------------------------------------------------
// Create any D3D11 resources that aren't dependant on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,
void* pUserContext )
{
HRESULT hr;
static bool bFirstOnCreateDevice = true;
// Warn the user that in order to support CS4x, a non-hardware device has been created, continue or quit?
if ( DXUTGetDeviceSettings().d3d11.DriverType != D3D_DRIVER_TYPE_HARDWARE && bFirstOnCreateDevice )
{
if ( MessageBox( 0, L"CS4x capability is missing. "\
L"In order to continue, a non-hardware device has been created, "\
L"it will be very slow, continue?", L"Warning", MB_ICONEXCLAMATION | MB_YESNO ) != IDYES )
return E_FAIL;
}
bFirstOnCreateDevice = false;
ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();
V_RETURN( g_DialogResourceManager.OnD3D11CreateDevice( pd3dDevice, pd3dImmediateContext ) );
V_RETURN( g_D3DSettingsDlg.OnD3D11CreateDevice( pd3dDevice ) );
V_RETURN( g_Tessellator.OnD3D11CreateDevice( pd3dDevice ) );
g_pTxtHelper = new CDXUTTextHelper( pd3dDevice, pd3dImmediateContext, &g_DialogResourceManager, 15 );
// find the file
WCHAR str[MAX_PATH];
V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"BaseMesh.obj" ) );
std::wifstream ifs( str );
WCHAR line[256] = {0};
CGrowableArray<D3DXVECTOR4> initdata;
// Parse the .obj file. Both triangle faces and quad faces are supported.
// Only v and f tags are processed, other tags like vn, vt etc are ignored.
{
CGrowableArray<D3DXVECTOR4> v;
while ( ifs >> line )
{
if ( 0 == wcscmp( line, L"#" ) )
ifs.getline( line, 255 );
else
if ( 0 == wcscmp( line, L"v" ) )
{
D3DXVECTOR4 pos;
ifs >> pos.x >> pos.y >> pos.z;
pos.w = 1;
v.Add( pos );
}
}
ifs.clear( 0 );
ifs.seekg( 0 );
while ( ifs >> line )
{
if ( 0 == wcscmp( line, L"#" ) )
ifs.getline( line, 255 );
else
if ( 0 == wcscmp( line, L"f" ) )
{
ifs.getline( line, 255 );
std::wstringstream ss(line);
int idx[4], i = 0;
while ( ss >> line )
{
std::wstringstream ss(line);
ss >> idx[i++];
}
initdata.Add( v[idx[0]-1] ); initdata.Add( v[idx[1]-1] ); initdata.Add( v[idx[2]-1] );
if ( i >= 4 ) // quad face?
{
initdata.Add( v[idx[2]-1] ); initdata.Add( v[idx[3]-1] ); initdata.Add( v[idx[0]-1] );
}
}
}
示例5: AddEffect
//-------------------------------------------------------------------------------------
// Investigates all the parameters, looking at semantics and annotations and placing
// handles to these parameters within the internal database.
//-------------------------------------------------------------------------------------
HRESULT CDXUTEffectMap::AddEffect( ID3DXEffect* pEffect )
{
HRESULT hr;
if( pEffect == NULL )
return E_INVALIDARG;
// Get the number of parameters
D3DXEFFECT_DESC descEffect;
V_RETURN( pEffect->GetDesc( &descEffect ) );
// Enumerate the parameters
for( UINT iParam=0; iParam < descEffect.Parameters; iParam++ )
{
// Retrieve param
D3DXHANDLE hParameter = pEffect->GetParameter( NULL, iParam );
if( NULL == hParameter )
return E_FAIL;
// Grab description
D3DXPARAMETER_DESC desc;
V_RETURN( pEffect->GetParameterDesc( hParameter, &desc ) );
// If this parameter doesn't have a semantic, skip to the next parameter
if( desc.Semantic == NULL )
continue;
// Map the semantic to the standard set
DXUT_SEMANTIC eSemantic = StringToSemantic( desc.Semantic );
if( eSemantic == DXUT_UNKNOWN_SEMANTIC )
continue;
// Get the object annotation
const char* cstrObject = "Geometry";
D3DXHANDLE hAnnotation = pEffect->GetAnnotationByName( hParameter, "Object" );
if( hAnnotation )
{
V_RETURN( pEffect->GetString( hAnnotation, &cstrObject ) );
}
// Map the object to the standard set
DXUT_OBJECT eObject = StringToObject( cstrObject );
if( eObject == DXUT_UNKNOWN_OBJECT )
continue;
// Extract the index from the semantic
int index = 0;
const char* strIndex = desc.Semantic + strlen(desc.Semantic)-1;
// If there is a digit at the end of the semantic, locate the beginning of the index
// and convert to an integer
if( isdigit( (BYTE) (*strIndex) ) )
{
while( isdigit( (BYTE) (*(strIndex-1)) ) )
{
--strIndex;
}
index = atoi( strIndex );
}
// Check whether index is out of bounds
if( index < 0 || index >= MAX_INDEX )
continue;
// Store the handle
CGrowableArray<ParamList>* pBindings = &m_Bindings[ eSemantic ][ eObject ][ index ];
bool bBound = false;
for( int i=0; i < pBindings->GetSize(); i++ )
{
if( pBindings->GetAt(i).pEffect == pEffect )
{
// Found the containing effect for this parameter in the list, add the new handle
pBindings->GetAt(i).ahParameters.Add( hParameter );
bBound = true;
break;
}
}
if( !bBound )
{
// This parameter belongs to a new effect
ParamList newParamList;
newParamList.pEffect = pEffect;
pEffect->AddRef();
newParamList.ahParameters.Add( hParameter );
pBindings->Add( newParamList );
}
}
return S_OK;
}