2012-07-06 1 views
0

내 DirectX 11 응용 프로그램의 파일에서 메쉬를로드하려고했습니다. 기본으로 (지금은 일부 프리미티브 렌더링) 내 자신의 코드를 가져 와서 DirectX 11 SDK 샘플 (예 : SDKmesh.h 및 DXUT를 사용하는 "기본 HLSL"프로젝트에서 메쉬 생성/렌더링 코드를 추가하고 싶습니다. 샘플에서 시간DirectX11 메시로드 중 - 텍스처 때문에 (SDKmesh.h 사용) 오류가 발생 했습니까? 액세스 위반 읽기 위치 0x00000000

메쉬 코드는 다음과 같습니다.

class FeyModel : public Graphic::Model, public FeyGraphicElement{ 
protected: 
    CDXUTSDKMesh mesh; 
public: 
    FeyModel(ID3D11Device * device, std::string filename, const Common::Point3D center){  
     mesh.Create(device, L"tiny\\tiny.sdkmesh", false); //for now tiny.sdkmesh 
    } 

    void render(FeyShader * shader, 
     FeyCamera * camera, 
     ID3D11DeviceContext* context, 
     float t 
     ){ 

      UINT Strides[1]; 
      UINT Offsets[1]; 
      ID3D11Buffer* pVB[1]; 
      pVB[0] = mesh.GetVB11(0, 0); 
      Strides[0] = (UINT)mesh.GetVertexStride(0, 0); 
      Offsets[0] = 0; 
      context->IASetVertexBuffers(0, 1, pVB, Strides, Offsets); 
      context->IASetIndexBuffer(mesh.GetIB11(0), mesh.GetIBFormat11(0), 0); 


      SDKMESH_SUBSET* pSubset = NULL; 
      D3D11_PRIMITIVE_TOPOLOGY PrimType; 

      //! context->PSSetSamplers(0, 1, &samLinear); 

      for(UINT subset = 0; subset < mesh.GetNumSubsets(0); ++subset) 
      { 
       // Get the subset 
       pSubset = mesh.GetSubset(0, subset); 

       PrimType = CDXUTSDKMesh::GetPrimitiveType11((SDKMESH_PRIMITIVE_TYPE)pSubset->PrimitiveType); 
       context->IASetPrimitiveTopology(PrimType); 


       // TODO: D3D11 - material loading 

       ID3D11ShaderResourceView* pDiffuseRV = mesh.GetMaterial(pSubset->MaterialID)->pDiffuseRV11; 

       context->PSSetShaderResources(0, 1, &pDiffuseRV); 

       context->DrawIndexed((UINT)pSubset->IndexCount, 0, (UINT)pSubset->VertexStart); 
      } 
     } 
}; 

나는 또한 샘플에서 다른 정점 레이아웃 있다는 것을 발견했습니다, 그래서 내 쉐이더의 클래스 코드를 변경 (코드가 될 것입니다 메쉬 생성 전에 shader의 클래스 생성자에서 한 번 실행됩니다.) :

컴파일 작업이 수행됩니다.

SDKmish.h에서
Access violation reading location 0x00000000 

근처 : 정확하게 라인에

if (bSRGB) { 
    // This is a workaround so that we can load linearly, but sample in SRGB. Right now, we can't load 
    // as linear since D3DX will try to do conversion on load. Loading as TYPELESS doesn't work either, and 
    // loading as typed _UNORM doesn't allow us to create an SRGB view. 

    // on d3d11 featuer levels this is just a copy, but on 10L9 we must use a cpu side copy with 2 staging resources. 
    ID3D11Texture2D* unormStaging = NULL; 
    ID3D11Texture2D* srgbStaging = NULL; 

    D3D11_TEXTURE2D_DESC CopyDesc; 
    pRes->GetDesc(&CopyDesc); 

    pLoadInfo->BindFlags = 0; 
    pLoadInfo->CpuAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ; 
    pLoadInfo->Depth = 0; 
    pLoadInfo->Filter = D3DX11_FILTER_LINEAR; 
    pLoadInfo->FirstMipLevel = 0; 
    pLoadInfo->Format = CopyDesc.Format; 
    pLoadInfo->Height = CopyDesc.Height; 
    pLoadInfo->MipFilter = D3DX11_FILTER_LINEAR; 
    pLoadInfo->MiscFlags = CopyDesc.MiscFlags; 
    pLoadInfo->Usage = D3D11_USAGE_STAGING; 
    pLoadInfo->Width = CopyDesc.Width; 

    CopyDesc.BindFlags = 0; 
    CopyDesc.Usage = D3D11_USAGE_STAGING; 
    CopyDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ; 
    CopyDesc.Format = MAKE_SRGB(CopyDesc.Format); 

    hr = D3DX11CreateTextureFromFile(pDevice, pSrcFile, pLoadInfo, pPump, (ID3D11Resource**)&unormStaging, NULL); 
    DXUT_SetDebugName(unormStaging, "CDXUTResourceCache"); 

    hr = pDevice->CreateTexture2D(&CopyDesc, NULL, &srgbStaging); 
    DXUT_SetDebugName(srgbStaging, "CDXUTResourceCache"); 
    pContext->CopyResource(srgbStaging, unormStaging); 
    ID3D11Texture2D* srgbGPU; 

    pRes->GetDesc(&CopyDesc); 
    CopyDesc.Format = MAKE_SRGB(CopyDesc.Format); 
    hr = pDevice->CreateTexture2D(&CopyDesc, NULL, &srgbGPU); 
    pContext->CopyResource(srgbGPU, srgbStaging); 

    SAFE_RELEASE(pRes); 
    SAFE_RELEASE(srgbStaging); 
    SAFE_RELEASE(unormStaging); 
    pRes = srgbGPU; 
} 

: 그러나 코드를 실행하는 동안 나는 오류가 난 그 기능의 몇 줄을 주석

pContext->CopyResource(srgbStaging, unormStaging); 

그리고 뭔가 내 코드에서 (나는 지금 어떤 선이 있었는지 기억하지 못한다.) 나는 메쉬를 창에 넣었지만 텍스처는 사용하지 않았다. 그래서 텍스쳐가있는 것 같아요? 나는 적당한 폴더에 작은 모델과 텍스처를 가지고있다. 나는 위에 게시 한 것처럼 꼭지점 레이아웃을 설정했다.

그 밖의 무엇을해야합니까? 난 당신이 스레드 펌프를 통과 통지

+0

DX가 성공합니까? ('SUCCEEDED' 매크로와'FAILED' 매크로를 통해'hr' 매크로를 확인하십시오). DX 디버그 정보는 무엇을 알려줍니까? (디버그 플래그로 장치를 생성하고 sysinternals의 DgbView를 사용하여 메시지를 가져옵니다). – Necrolis

답변

0

,이 텍스처가 비동기를로드 의미하지만, 당신은 당신의 작업을 수행 마치 그 (펌프가있는 경우 D3DX11CreateTextureFromFile는 차단하지 않습니다) 동 기적으로로드.

D3DX11CreateTextureFromFile(...,pPump,...); 

그래서 당신은 질감이 아직로드되지 않은 (따라서 핸들이 NULL이) 있기 때문에, 널 포인터에 대한 작업을 수행 D3DX11CreateTextureFromFile에있는 문서를 보는 것을 시도 할 수있다.

관련 문제