int D3DOverdrawWindow:: ResetDevice(void) { Superclass::ResetDevice(); if (!SetQuery()) { return 0; } if (!m_pSoup) { return 1; } m_pSoup->ComputeNormals(); //TODO: check if we need this // create vertex buffer if (!SetVB()) { return 0; } if (!SetIB()) { return 0; } if (!SetVD()) { return 0; } return 1; }
VOID CameraWorkBase::CreateImage( LPIMAGE _pImage, LPINFO _pInfo ) { // Vertex는 외부에서 받아온다 if( _pImage->pVB == NULL && _pImage->pIB == NULL ) { // 처음 만들거나 iNumVertices정보가 변경되었을때 // Create VertexBuffer _pImage->iNumVertices = _pInfo->iNumVertices; CreateVB( &_pImage->pVB, _pImage->iNumVertices, sizeof( VERTEX ), VERTEX::FVF ); SetVB( _pImage->pVB, _pInfo->pVertex, _pImage->iNumVertices, sizeof( VERTEX ) ); // Create IndexBuffer _pImage->iNumIndices = _pInfo->iNumIndices; CreateIB( &_pImage->pIB, _pImage->iNumIndices, sizeof( INDEX ) ); SetIB( _pImage->pIB, _pInfo->pIndex, _pImage->iNumIndices, sizeof( INDEX) ); return; } LPVOID pVertices; if( FAILED( _pImage->pVB->Lock( 0, sizeof( VERTEX ) * _pInfo->iNumVertices, (LPVOID*)&pVertices, 0 ) ) ) { MessageBox( NULL, L"CreateImage_Course(){ ... pVB->Lock failed ... }", NULL, MB_OK ); return; } memcpy( pVertices, _pInfo->pVertex, sizeof( VERTEX ) * _pInfo->iNumVertices ); _pImage->pVB->Unlock(); }
VOID CameraWorkBase::CreateImage_Box( LPIMAGE _pImage ) { INT iNumVertices = 8; INT iNumIndices = 12; _pImage->iNumVertices = iNumVertices; _pImage->iNumIndices = iNumIndices; // Init Vertex VERTEX aVertex[ 8 ]; aVertex[ 0 ].vecPos = D3DXVECTOR3( -1.0f, 1.0f, -1.0f ); aVertex[ 1 ].vecPos = D3DXVECTOR3( 1.0f, 1.0f, -1.0f ); aVertex[ 2 ].vecPos = D3DXVECTOR3( -1.0f, 1.0f, 1.0f ); aVertex[ 3 ].vecPos = D3DXVECTOR3( 1.0f, 1.0f, 1.0f ); aVertex[ 4 ].vecPos = D3DXVECTOR3( -1.0f, -1.0f, -1.0f ); aVertex[ 5 ].vecPos = D3DXVECTOR3( 1.0f, -1.0f, -1.0f ); aVertex[ 6 ].vecPos = D3DXVECTOR3( -1.0f, -1.0f, 1.0f ); aVertex[ 7 ].vecPos = D3DXVECTOR3( 1.0f, -1.0f, 1.0f ); aVertex[ 0 ].dColor = m_dColBox; aVertex[ 1 ].dColor = m_dColBox; aVertex[ 2 ].dColor = m_dColBox; aVertex[ 3 ].dColor = m_dColBox; aVertex[ 4 ].dColor = m_dColBox; aVertex[ 5 ].dColor = m_dColBox; aVertex[ 6 ].dColor = m_dColBox; aVertex[ 7 ].dColor = m_dColBox; // Init Index INDEX aIndex[ 12 ]; aIndex[ 0 ]._0 = 0; aIndex[ 0 ]._1 = 1; aIndex[ 1 ]._0 = 0; aIndex[ 1 ]._1 = 2; aIndex[ 2 ]._0 = 2; aIndex[ 2 ]._1 = 3; aIndex[ 3 ]._0 = 3; aIndex[ 3 ]._1 = 1; aIndex[ 4 ]._0 = 0; aIndex[ 4 ]._1 = 4; aIndex[ 5 ]._0 = 1; aIndex[ 5 ]._1 = 5; aIndex[ 6 ]._0 = 2; aIndex[ 6 ]._1 = 6; aIndex[ 7 ]._0 = 3; aIndex[ 7 ]._1 = 7; aIndex[ 8 ]._0 = 4; aIndex[ 8 ]._1 = 5; aIndex[ 9 ]._0 = 5; aIndex[ 9 ]._1 = 7; aIndex[ 10 ]._0 = 6; aIndex[ 10 ]._1 = 7; aIndex[ 11 ]._0 = 6; aIndex[ 11 ]._1 = 4; // Init VertexBuffer, IndexBuffer CreateVB( &_pImage->pVB, iNumVertices, sizeof( VERTEX ), VERTEX::FVF ); SetVB( _pImage->pVB, aVertex, iNumVertices, sizeof( VERTEX ) ); CreateIB( &_pImage->pIB, iNumIndices, sizeof( INDEX ) ); SetIB( _pImage->pIB, aIndex, iNumIndices, sizeof( INDEX) ); }
bool JRenderServer::Draw( int firstIdx, int numIdx, int firstVert, int numVert, PrimitiveType primType ) { if (numVert == 0) return false; bool bIndexed = true; int numPri = 0; if (numIdx == 0) { numPri = GetNumPrimitives( primType, numVert ); bIndexed = false; } else { numPri = GetNumPrimitives( primType, numIdx ); } if (primType == PrimitiveType_QuadList) { numPri = numVert/2; bIndexed = true; firstIdx = 0; SetIB( m_QuadIB, firstVert ); } HRESULT hRes = m_pDevice->BeginScene(); if (hRes != S_OK) return false; if (bIndexed) { hRes = m_pDevice->DrawIndexedPrimitive( ConvertPrimitiveType( primType ), 0, numVert, firstIdx, numPri ); } else { hRes = m_pDevice->DrawPrimitive( ConvertPrimitiveType( primType ), firstVert, numPri ); } hRes = m_pDevice->EndScene(); if (hRes != S_OK) return false; return (hRes == S_OK); } // JRenderServer::Draw
int D3DOverdrawWindow:: SetSoup(Soup* pSoup) { // re-create vertex and index buffers m_pSoup = pSoup; if (!SetVB()) { return 0; } if (!SetIB()) { return 0; } // create other device objects as needed if (!m_VD) { if (!SetVD()) { return 0; } } if (!m_pOcclusionQuery[0] || !m_pOcclusionQueryPix[0]) { if (!SetQuery()) { return 0; } } return 1; }
///////////////////////////////////////////////////////////////////////////////// // MeshSegment implementation MeshSegment::MeshSegment( const Segment3 & vSegment, GPUInputLayout * pIL ): LineListMesh(), m_vSegment( vSegment ) { Assert( pIL != NULL ); SetIL( pIL ); UInt iVertexSize = m_pIL->GetSize(); UInt iVertexCount = 2; //UInt iEdgeCount = 1; UInt iIndexCount = 2; // Create buffers GPUVertexBuffer * pVB = RenderingFn->CreateVertexBuffer( iVertexSize, iVertexCount ); pVB->SetUsage( GPURESOURCE_USAGE_DEFAULT ); GPUIndexBuffer * pIB = RenderingFn->CreateIndexBuffer( iIndexCount ); pIB->SetUsage( GPURESOURCE_USAGE_DEFAULT ); SetVB( pVB ); SetIB( pIB ); // Generate vertices UInt iOffset, iSize; m_pIL->GetFieldRange( &iOffset, &iSize, GPUINPUTFIELD_SEMANTIC_POSITION, 0 ); Byte * arrPositions = m_pVB->GetData() + iOffset; Byte * arrTexCoords = NULL; if ( m_pIL->HasField(GPUINPUTFIELD_SEMANTIC_TEXCOORD, 0) ) { m_pIL->GetFieldRange( &iOffset, &iSize, GPUINPUTFIELD_SEMANTIC_TEXCOORD, 0 ); arrTexCoords = m_pVB->GetData() + iOffset; } Vertex4 * pPosition; TextureCoord1 * pTexCoord; pPosition = (Vertex4*)( arrPositions ); *pPosition = m_vSegment.EndA; arrPositions += iVertexSize; if ( arrTexCoords != NULL ) { pTexCoord = (TextureCoord1*)( arrTexCoords ); pTexCoord->T = 0.0f; arrTexCoords += iVertexSize; } pPosition = (Vertex4*)( arrPositions ); *pPosition = m_vSegment.EndB; if ( arrTexCoords != NULL ) { pTexCoord = (TextureCoord1*)( arrTexCoords ); pTexCoord->T = 1.0f; } // Generate indices UInt * arrIndices = (UInt*)( m_pIB->GetData() ); arrIndices[0] = 0; arrIndices[1] = 1; // Bind buffers m_pVB->Bind(); m_pIB->Bind(); }
///////////////////////////////////////////////////////////////////////////////// // MeshTriangle implementation MeshTriangle::MeshTriangle( const Triangle3 & vTriangle, GPUInputLayout * pIL ): TriangleListMesh(), m_vTriangle( vTriangle ) { Assert( pIL != NULL ); SetIL( pIL ); UInt iVertexSize = m_pIL->GetSize(); UInt iVertexCount = 3; //UInt iTriangleCount = 1; UInt iIndexCount = 3; // Create buffers GPUVertexBuffer * pVB = RenderingFn->CreateVertexBuffer( iVertexSize, iVertexCount ); pVB->SetUsage( GPURESOURCE_USAGE_DEFAULT ); GPUIndexBuffer * pIB = RenderingFn->CreateIndexBuffer( iIndexCount ); pIB->SetUsage( GPURESOURCE_USAGE_DEFAULT ); SetVB( pVB ); SetIB( pIB ); // Generate vertices UInt iOffset, iSize; m_pIL->GetFieldRange( &iOffset, &iSize, GPUINPUTFIELD_SEMANTIC_POSITION, 0 ); Byte * arrPositions = m_pVB->GetData() + iOffset; Byte * arrNormals = NULL; if ( m_pIL->HasField(GPUINPUTFIELD_SEMANTIC_NORMAL, 0) ) { m_pIL->GetFieldRange( &iOffset, &iSize, GPUINPUTFIELD_SEMANTIC_NORMAL, 0 ); arrNormals = m_pVB->GetData() + iOffset; } Byte * arrTexCoords = NULL; if ( m_pIL->HasField(GPUINPUTFIELD_SEMANTIC_TEXCOORD, 0) ) { m_pIL->GetFieldRange( &iOffset, &iSize, GPUINPUTFIELD_SEMANTIC_TEXCOORD, 0 ); arrTexCoords = m_pVB->GetData() + iOffset; } Vertex4 * pPosition; Vector4 * pNormal; TextureCoord2 * pTexCoord; Vector4 vNormal = m_vTriangle.GetPlane().Normal; pPosition = (Vertex4*)( arrPositions ); *pPosition = m_vTriangle.A; arrPositions += iVertexSize; if ( arrNormals != NULL ) { pNormal = (Vector4*)( arrNormals ); *pNormal = vNormal; arrNormals += iVertexSize; } if ( arrTexCoords != NULL ) { pTexCoord = (TextureCoord2*)( arrTexCoords ); pTexCoord->T = 0.0f; pTexCoord->U = 0.0f; arrTexCoords += iVertexSize; } pPosition = (Vertex4*)( arrPositions ); *pPosition = m_vTriangle.B; arrPositions += iVertexSize; if ( arrNormals != NULL ) { pNormal = (Vector4*)( arrNormals ); *pNormal = vNormal; arrNormals += iVertexSize; } if ( arrTexCoords != NULL ) { pTexCoord = (TextureCoord2*)( arrTexCoords ); pTexCoord->T = 1.0f; pTexCoord->U = 0.0f; arrTexCoords += iVertexSize; } pPosition = (Vertex4*)( arrPositions ); *pPosition = m_vTriangle.C; if ( arrNormals != NULL ) { pNormal = (Vector4*)( arrNormals ); *pNormal = vNormal; } if ( arrTexCoords != NULL ) { pTexCoord = (TextureCoord2*)( arrTexCoords ); pTexCoord->T = 0.0f; pTexCoord->U = 1.0f; } // Generate indices UInt * arrIndices = (UInt*)( m_pIB->GetData() ); arrIndices[0] = 0; arrIndices[1] = 1; arrIndices[2] = 2; // Bind buffers m_pVB->Bind(); m_pIB->Bind(); }