src/render/direct3d11/SDL_render_d3d11.cpp
changeset 8452 a16533caf2b4
parent 8451 092ea651523a
child 8454 ac6a37f54dc2
equal deleted inserted replaced
8451:092ea651523a 8452:a16533caf2b4
   834     textureData->pixelFormat = SDL_AllocFormat(texture->format);
   834     textureData->pixelFormat = SDL_AllocFormat(texture->format);
   835     textureData->lockedTexturePosition = XMINT2(0, 0);
   835     textureData->lockedTexturePosition = XMINT2(0, 0);
   836 
   836 
   837     texture->driverdata = textureData;
   837     texture->driverdata = textureData;
   838 
   838 
   839     const int pixelSizeInBytes = textureData->pixelFormat->BytesPerPixel;
       
   840 
       
   841     D3D11_TEXTURE2D_DESC textureDesc = {0};
   839     D3D11_TEXTURE2D_DESC textureDesc = {0};
   842     textureDesc.Width = texture->w;
   840     textureDesc.Width = texture->w;
   843     textureDesc.Height = texture->h;
   841     textureDesc.Height = texture->h;
   844     textureDesc.MipLevels = 1;
   842     textureDesc.MipLevels = 1;
   845     textureDesc.ArraySize = 1;
   843     textureDesc.ArraySize = 1;
   849     textureDesc.Usage = D3D11_USAGE_DYNAMIC;
   847     textureDesc.Usage = D3D11_USAGE_DYNAMIC;
   850     textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
   848     textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
   851     textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
   849     textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
   852     textureDesc.MiscFlags = 0;
   850     textureDesc.MiscFlags = 0;
   853 
   851 
       
   852 #if 0
       
   853     // Fill the texture with a non-black color, for debugging purposes:
   854     const int numPixels = textureDesc.Width * textureDesc.Height;
   854     const int numPixels = textureDesc.Width * textureDesc.Height;
       
   855     const int pixelSizeInBytes = textureData->pixelFormat->BytesPerPixel;
   855     std::vector<uint8> initialTexturePixels(numPixels * pixelSizeInBytes, 0x00);
   856     std::vector<uint8> initialTexturePixels(numPixels * pixelSizeInBytes, 0x00);
   856 
   857     for (int i = 0; i < (numPixels * pixelSizeInBytes); i += pixelSizeInBytes) {
   857     // Fill the texture with a non-black color, for debugging purposes:
   858         initialTexturePixels[i+0] = 0xff;
   858     //for (int i = 0; i < (numPixels * pixelSizeInBytes); i += pixelSizeInBytes) {
   859         initialTexturePixels[i+1] = 0xff;
   859     //    initialTexturePixels[i+0] = 0xff;
   860         initialTexturePixels[i+2] = 0x00;
   860     //    initialTexturePixels[i+1] = 0xff;
   861         initialTexturePixels[i+3] = 0xff;
   861     //    initialTexturePixels[i+2] = 0x00;
   862     }
   862     //    initialTexturePixels[i+3] = 0xff;
       
   863     //}
       
   864 
       
   865     D3D11_SUBRESOURCE_DATA initialTextureData = {0};
   863     D3D11_SUBRESOURCE_DATA initialTextureData = {0};
   866     initialTextureData.pSysMem = (void *)&(initialTexturePixels[0]);
   864     initialTextureData.pSysMem = (void *)&(initialTexturePixels[0]);
   867     initialTextureData.SysMemPitch = textureDesc.Width * pixelSizeInBytes;
   865     initialTextureData.SysMemPitch = textureDesc.Width * pixelSizeInBytes;
   868     initialTextureData.SysMemSlicePitch = numPixels * pixelSizeInBytes;
   866     initialTextureData.SysMemSlicePitch = numPixels * pixelSizeInBytes;
       
   867 #endif
       
   868 
   869     result = rendererData->d3dDevice->CreateTexture2D(
   869     result = rendererData->d3dDevice->CreateTexture2D(
   870         &textureDesc,
   870         &textureDesc,
   871         &initialTextureData,
   871         NULL,   // &initialTextureData,
   872         &textureData->mainTexture
   872         &textureData->mainTexture
   873         );
   873         );
   874     if (FAILED(result)) {
   874     if (FAILED(result)) {
   875         D3D11_DestroyTexture(renderer, texture);
   875         D3D11_DestroyTexture(renderer, texture);
   876         WIN_SetErrorFromHRESULT(__FUNCTION__, result);
   876         WIN_SetErrorFromHRESULT(__FUNCTION__, result);