This commit is contained in:
Branimir Karadžić 2015-10-19 15:09:56 -07:00
parent 0ad579f4cb
commit b6ae6fda61
6 changed files with 127 additions and 56 deletions

View file

@ -114,10 +114,10 @@ static void updateTextureCubeRectBgra8(bgfx::TextureHandle _handle, uint8_t _sid
int _main_(int /*_argc*/, char** /*_argv*/)
{
uint32_t width = 1280;
uint32_t width = 1280;
uint32_t height = 720;
uint32_t debug = BGFX_DEBUG_TEXT;
uint32_t reset = BGFX_RESET_VSYNC;
uint32_t debug = BGFX_DEBUG_TEXT;
uint32_t reset = BGFX_RESET_VSYNC;
bgfx::init();
bgfx::reset(width, height, reset);

View file

@ -217,10 +217,10 @@ class Deferred : public entry::AppI
{
void init(int /*_argc*/, char** /*_argv*/) BX_OVERRIDE
{
m_width = 1280;
m_width = 1280;
m_height = 720;
m_debug = BGFX_DEBUG_TEXT;
m_reset = BGFX_RESET_VSYNC;
m_debug = BGFX_DEBUG_TEXT;
m_reset = BGFX_RESET_VSYNC;
bgfx::init();
bgfx::reset(m_width, m_height, m_reset);
@ -410,9 +410,9 @@ class Deferred : public entry::AppI
else
{
if (m_oldWidth != m_width
|| m_oldHeight != m_height
|| m_oldReset != m_reset
|| !bgfx::isValid(m_gbuffer) )
|| m_oldHeight != m_height
|| m_oldReset != m_reset
|| !bgfx::isValid(m_gbuffer) )
{
// Recreate variable size render targets when resolution changes.
m_oldWidth = m_width;

View file

@ -4240,23 +4240,96 @@ BX_PRAGMA_DIAGNOSTIC_POP();
}
}
const uint32_t msaaQuality = bx::uint32_satsub( (texture.m_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1);
const DXGI_SAMPLE_DESC& msaa = s_msaa[msaaQuality];
if (isDepth( (TextureFormat::Enum)texture.m_textureFormat) )
{
BX_CHECK(NULL == m_dsv, "Frame buffer already has depth-stencil attached.");
const uint32_t msaaQuality = bx::uint32_satsub( (texture.m_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1);
const DXGI_SAMPLE_DESC& msaa = s_msaa[msaaQuality];
switch (texture.m_type)
{
default:
case TextureD3D11::Texture2D:
{
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
dsvDesc.Format = s_textureFormat[texture.m_textureFormat].m_fmtDsv;
dsvDesc.ViewDimension = 1 < msaa.Count
? D3D11_DSV_DIMENSION_TEXTURE2DMS
: D3D11_DSV_DIMENSION_TEXTURE2D
;
dsvDesc.Flags = 0;
dsvDesc.Texture2D.MipSlice = 0;
DX_CHECK(s_renderD3D11->m_device->CreateDepthStencilView(texture.m_ptr, &dsvDesc, &m_dsv) );
}
break;
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
dsvDesc.Format = s_textureFormat[texture.m_textureFormat].m_fmtDsv;
dsvDesc.ViewDimension = 1 < msaa.Count ? D3D11_DSV_DIMENSION_TEXTURE2DMS : D3D11_DSV_DIMENSION_TEXTURE2D;
dsvDesc.Flags = 0;
dsvDesc.Texture2D.MipSlice = 0;
DX_CHECK(s_renderD3D11->m_device->CreateDepthStencilView(texture.m_ptr, &dsvDesc, &m_dsv) );
case TextureD3D11::TextureCube:
{
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
dsvDesc.Format = s_textureFormat[texture.m_textureFormat].m_fmtDsv;
if (1 < msaa.Count)
{
dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY;
dsvDesc.Texture2DMSArray.ArraySize = 1;
dsvDesc.Texture2DMSArray.FirstArraySlice = 0;
}
else
{
dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
dsvDesc.Texture2DArray.ArraySize = 1;
dsvDesc.Texture2DArray.FirstArraySlice = 0;
dsvDesc.Texture2DArray.MipSlice = 0;
}
dsvDesc.Flags = 0;
DX_CHECK(s_renderD3D11->m_device->CreateDepthStencilView(texture.m_ptr, &dsvDesc, &m_dsv) );
}
break;
}
}
else
{
DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(texture.m_ptr, NULL, &m_rtv[m_num]) );
switch (texture.m_type)
{
default:
case TextureD3D11::Texture2D:
DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(texture.m_ptr, NULL, &m_rtv[m_num]) );
break;
case TextureD3D11::TextureCube:
{
D3D11_RENDER_TARGET_VIEW_DESC desc;
desc.Format = s_textureFormat[texture.m_textureFormat].m_fmt;
if (1 < msaa.Count)
{
desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY;
desc.Texture2DMSArray.ArraySize = 1;
desc.Texture2DMSArray.FirstArraySlice = 0;
}
else
{
desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
desc.Texture2DArray.ArraySize = 1;
desc.Texture2DArray.FirstArraySlice = 0;
desc.Texture2DArray.MipSlice = 0;
}
DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(texture.m_ptr, &desc, &m_rtv[m_num]) );
}
break;
case TextureD3D11::Texture3D:
{
D3D11_RENDER_TARGET_VIEW_DESC desc;
desc.Format = s_textureFormat[texture.m_textureFormat].m_fmt;
desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
desc.Texture3D.MipSlice = 0;
desc.Texture3D.WSize = 1;
desc.Texture3D.FirstWSlice = 0;
DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(texture.m_ptr, &desc, &m_rtv[m_num]) );
}
break;
}
DX_CHECK(s_renderD3D11->m_device->CreateShaderResourceView(texture.m_ptr, NULL, &m_srv[m_num]) );
m_num++;
}

View file

@ -2573,6 +2573,28 @@ namespace bgfx { namespace d3d9
BX_CHECK(false, "You should not be here.");
}
IDirect3DSurface9* TextureD3D9::getSurface(uint8_t _side, uint8_t _mip) const
{
IDirect3DSurface9* surface = NULL;
switch (m_type)
{
case Texture2D:
DX_CHECK(m_texture2d->GetSurfaceLevel(_mip, &surface) );
break;
case Texture3D:
BX_CHECK(false, "");
break;
case TextureCube:
DX_CHECK(m_textureCube->GetCubeMapSurface(D3DCUBEMAP_FACES(_side), _mip, &surface) );
break;
}
return surface;
}
void TextureD3D9::create(const Memory* _mem, uint32_t _flags, uint8_t _skip)
{
ImageContainer imageContainer;
@ -2796,8 +2818,7 @@ namespace bgfx { namespace d3d9
if (NULL != m_surface
&& NULL != m_texture2d)
{
IDirect3DSurface9* surface;
DX_CHECK(m_texture2d->GetSurfaceLevel(0, &surface) );
IDirect3DSurface9* surface = getSurface();
DX_CHECK(s_renderD3D9->m_device->StretchRect(m_surface
, NULL
, surface
@ -2856,7 +2877,7 @@ namespace bgfx { namespace d3d9
}
else
{
DX_CHECK(texture.m_texture2d->GetSurfaceLevel(0, &m_depthStencil) );
m_depthStencil = texture.getSurface();
}
}
else
@ -2869,7 +2890,7 @@ namespace bgfx { namespace d3d9
}
else
{
DX_CHECK(texture.m_texture2d->GetSurfaceLevel(0, &m_color[m_num]) );
m_color[m_num] = texture.getSurface();
}
m_num++;
}
@ -3057,7 +3078,7 @@ namespace bgfx { namespace d3d9
}
else
{
DX_CHECK(texture.m_texture2d->GetSurfaceLevel(0, &m_color[ii]) );
m_color[ii] = texture.getSurface();
}
}
}
@ -3072,7 +3093,7 @@ namespace bgfx { namespace d3d9
}
else
{
DX_CHECK(texture.m_texture2d->GetSurfaceLevel(0, &m_depthStencil) );
m_depthStencil = texture.getSurface();
}
if (0 == m_num)
@ -3336,37 +3357,8 @@ namespace bgfx { namespace d3d9
RECT srcRect = { LONG(blit.m_srcX), LONG(blit.m_srcY), LONG(blit.m_srcX + width), LONG(blit.m_srcY + height) };
RECT dstRect = { LONG(blit.m_dstX), LONG(blit.m_dstY), LONG(blit.m_dstX + width), LONG(blit.m_dstY + height) };
IDirect3DSurface9* srcSurface;
switch (src.m_type)
{
case TextureD3D9::Texture2D:
DX_CHECK(src.m_texture2d->GetSurfaceLevel(blit.m_srcMip, &srcSurface) );
break;
case TextureD3D9::Texture3D:
BX_CHECK(false, "");
break;
case TextureD3D9::TextureCube:
DX_CHECK(src.m_textureCube->GetCubeMapSurface(D3DCUBEMAP_FACES(blit.m_srcZ), blit.m_srcMip, &srcSurface) );
break;
}
IDirect3DSurface9* dstSurface;
switch (dst.m_type)
{
case TextureD3D9::Texture2D:
DX_CHECK(dst.m_texture2d->GetSurfaceLevel(blit.m_dstMip, &dstSurface) );
break;
case TextureD3D9::Texture3D:
BX_CHECK(false, "");
break;
case TextureD3D9::TextureCube:
DX_CHECK(dst.m_textureCube->GetCubeMapSurface(D3DCUBEMAP_FACES(blit.m_dstZ), blit.m_dstMip, &dstSurface) );
break;
}
IDirect3DSurface9* srcSurface = src.getSurface(uint8_t(blit.m_srcZ), blit.m_srcMip);
IDirect3DSurface9* dstSurface = dst.getSurface(uint8_t(blit.m_dstZ), blit.m_dstMip);
HRESULT hr = m_device->StretchRect(srcSurface
, &srcRect

View file

@ -321,6 +321,7 @@ namespace bgfx { namespace d3d9
uint8_t* lock(uint8_t _side, uint8_t _lod, uint32_t& _pitch, uint32_t& _slicePitch, const Rect* _rect = NULL);
void unlock(uint8_t _side, uint8_t _lod);
void dirty(uint8_t _side, const Rect& _rect, uint16_t _z, uint16_t _depth);
IDirect3DSurface9* getSurface(uint8_t _side = 0, uint8_t _mip = 0) const;
void create(const Memory* _mem, uint32_t _flags, uint8_t _skip);

View file

@ -4904,9 +4904,14 @@ namespace bgfx { namespace gl
}
else
{
GLenum target = GL_TEXTURE_CUBE_MAP == texture.m_target
? GL_TEXTURE_CUBE_MAP_POSITIVE_X
: texture.m_target
;
GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER
, attachment
, texture.m_target
, target
, texture.m_id
, 0
) );