mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2025-03-14 00:49:53 -04:00
Fixed DX11 texture initialization.
This commit is contained in:
parent
97bcef11d9
commit
523572d400
3 changed files with 90 additions and 21 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <bgfx.h>
|
||||
#include <bx/bx.h>
|
||||
#include <bx/timer.h>
|
||||
#include <bx/uint32_t.h>
|
||||
#include "../common/dbg.h"
|
||||
#include "../common/math.h"
|
||||
|
||||
|
@ -244,7 +245,7 @@ int _main_(int _argc, char** _argv)
|
|||
|
||||
if (now > updateTime)
|
||||
{
|
||||
// updateTime = now + freq/100;
|
||||
// updateTime = now + freq/10;
|
||||
const bgfx::Memory* mem = bgfx::alloc(ti.storageSize);
|
||||
uint8_t* data = (uint8_t*)mem->data;
|
||||
for (uint32_t ii = 0, num = ti.storageSize*8/ti.bitsPerPixel; ii < num; ++ii)
|
||||
|
@ -259,12 +260,12 @@ int _main_(int _argc, char** _argv)
|
|||
bgfx::updateTextureCube(textureCube, blockSide, 0, blockX, blockY, blockWidth, blockHeight, mem);
|
||||
|
||||
blockX += 8;
|
||||
if (blockX > textureSide-1)
|
||||
if (blockX >= textureSide)
|
||||
{
|
||||
blockX = 0;
|
||||
blockY += 8;
|
||||
|
||||
if (blockY > textureSide-1)
|
||||
if (blockY >= textureSide)
|
||||
{
|
||||
rr = rand()%255;
|
||||
gg = rand()%255;
|
||||
|
|
|
@ -1120,6 +1120,7 @@ namespace bgfx
|
|||
{
|
||||
BGFX_CHECK_MAIN_THREAD();
|
||||
BX_CHECK(NULL != _mem, "_mem can't be NULL");
|
||||
BX_CHECK(_side >= 0 && _side <= 5, "Invalid side %d.", _side);
|
||||
if (_width == 0
|
||||
|| _height == 0)
|
||||
{
|
||||
|
|
|
@ -1541,23 +1541,42 @@ namespace bgfx
|
|||
TextureCreate tc;
|
||||
bx::read(&reader, tc);
|
||||
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
desc.Width = tc.m_width;
|
||||
desc.Height = tc.m_height;
|
||||
desc.MipLevels = tc.m_numMips;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = s_textureFormat[tc.m_format].m_fmt;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
if (tc.m_cubeMap)
|
||||
{
|
||||
m_type = TextureCube;
|
||||
}
|
||||
else if (tc.m_depth > 1)
|
||||
{
|
||||
m_type = Texture3D;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_type = Texture2D;
|
||||
}
|
||||
|
||||
m_numMips = tc.m_numMips;
|
||||
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC srvd;
|
||||
memset(&srvd, 0, sizeof(srvd) );
|
||||
srvd.Format = s_textureFormat[tc.m_format].m_fmt;
|
||||
|
||||
if (NULL != tc.m_mem)
|
||||
{
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
desc.Width = tc.m_width;
|
||||
desc.Height = tc.m_height;
|
||||
desc.MipLevels = tc.m_numMips;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = srvd.Format;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.Usage = D3D11_USAGE_IMMUTABLE;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
srvd.Texture2D.MipLevels = tc.m_numMips;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA* srd = (D3D11_SUBRESOURCE_DATA*)alloca(tc.m_numMips*sizeof(D3D11_SUBRESOURCE_DATA) );
|
||||
uint32_t bpp = s_textureFormat[tc.m_format].m_bpp;
|
||||
|
@ -1593,16 +1612,64 @@ namespace bgfx
|
|||
}
|
||||
else
|
||||
{
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
switch (m_type)
|
||||
{
|
||||
case Texture2D:
|
||||
case TextureCube:
|
||||
{
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
desc.Width = tc.m_width;
|
||||
desc.Height = tc.m_height;
|
||||
desc.MipLevels = tc.m_numMips;
|
||||
desc.Format = srvd.Format;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
|
||||
DX_CHECK(s_renderCtx.m_device->CreateTexture2D(&desc, NULL, &m_texture2d) );
|
||||
if (TextureCube == m_type)
|
||||
{
|
||||
desc.ArraySize = 6;
|
||||
desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
|
||||
srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
|
||||
srvd.TextureCube.MipLevels = m_numMips;
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.ArraySize = 1;
|
||||
desc.MiscFlags = 0;
|
||||
srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
srvd.Texture2D.MipLevels = m_numMips;
|
||||
}
|
||||
|
||||
DX_CHECK(s_renderCtx.m_device->CreateTexture2D(&desc, NULL, &m_texture2d) );
|
||||
}
|
||||
break;
|
||||
|
||||
case Texture3D:
|
||||
{
|
||||
D3D11_TEXTURE3D_DESC desc;
|
||||
desc.Width = tc.m_width;
|
||||
desc.Height = tc.m_height;
|
||||
desc.Depth = tc.m_depth;
|
||||
desc.MipLevels = tc.m_numMips;
|
||||
desc.Format = srvd.Format;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
|
||||
srvd.Texture3D.MipLevels = m_numMips;
|
||||
|
||||
DX_CHECK(s_renderCtx.m_device->CreateTexture3D(&desc, NULL, &m_texture3d) );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC srv;
|
||||
memset(&srv, 0, sizeof(srv) );
|
||||
srv.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
srv.Texture2D.MipLevels = tc.m_numMips;
|
||||
DX_CHECK(s_renderCtx.m_device->CreateShaderResourceView(m_ptr, &srv, &m_srv) );
|
||||
DX_CHECK(s_renderCtx.m_device->CreateShaderResourceView(m_ptr, &srvd, &m_srv) );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue