From 981dcc21be09544262d073d37bfcec7b33358e41 Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Fri, 22 Jun 2012 19:44:30 -0700 Subject: [PATCH] Pass texture flags to render target. --- include/bgfx.h | 2 +- src/bgfx.cpp | 4 ++-- src/bgfx_p.h | 10 +++++++--- src/renderer_d3d9.cpp | 12 +++++++----- src/renderer_d3d9.h | 6 +++++- src/renderer_gl.cpp | 16 +++++++++------- src/renderer_gl.h | 4 ++-- src/renderer_null.cpp | 2 +- 8 files changed, 34 insertions(+), 22 deletions(-) diff --git a/include/bgfx.h b/include/bgfx.h index 985943483..17e96b7f7 100644 --- a/include/bgfx.h +++ b/include/bgfx.h @@ -368,7 +368,7 @@ namespace bgfx void destroyTexture(TextureHandle _handle); /// - RenderTargetHandle createRenderTarget(uint16_t _width, uint16_t _height, uint32_t _flags = BGFX_RENDER_TARGET_COLOR_RGBA); + RenderTargetHandle createRenderTarget(uint16_t _width, uint16_t _height, uint32_t _flags = BGFX_RENDER_TARGET_COLOR_RGBA, uint32_t _textureFlags = BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP); /// void destroyRenderTarget(RenderTargetHandle _handle); diff --git a/src/bgfx.cpp b/src/bgfx.cpp index cd4282d89..0b9a7c3d2 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -809,9 +809,9 @@ namespace bgfx s_ctx.destroyTexture(_handle); } - RenderTargetHandle createRenderTarget(uint16_t _width, uint16_t _height, uint32_t _flags) + RenderTargetHandle createRenderTarget(uint16_t _width, uint16_t _height, uint32_t _flags, uint32_t _textureFlags) { - return s_ctx.createRenderTarget(_width, _height, _flags); + return s_ctx.createRenderTarget(_width, _height, _flags, _textureFlags); } void destroyRenderTarget(RenderTargetHandle _handle) diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 6ca4f7233..8a97206dc 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -1668,7 +1668,7 @@ namespace bgfx m_submit->free(_handle); } - RenderTargetHandle createRenderTarget(uint16_t _width, uint16_t _height, uint32_t _flags) + RenderTargetHandle createRenderTarget(uint16_t _width, uint16_t _height, uint32_t _flags, uint32_t _textureFlags) { RenderTargetHandle handle = { m_renderTargetHandle.alloc() }; @@ -1677,6 +1677,7 @@ namespace bgfx cmdbuf.write(_width); cmdbuf.write(_height); cmdbuf.write(_flags); + cmdbuf.write(_textureFlags); return handle; } @@ -1930,7 +1931,7 @@ namespace bgfx void rendererDestroyMaterial(FragmentShaderHandle _handle); void rendererCreateTexture(TextureHandle _handle, Memory* _mem, uint32_t _flags); void rendererDestroyTexture(TextureHandle _handle); - void rendererCreateRenderTarget(RenderTargetHandle _handle, uint16_t _width, uint16_t _height, uint32_t _flags); + void rendererCreateRenderTarget(RenderTargetHandle _handle, uint16_t _width, uint16_t _height, uint32_t _flags, uint32_t _textureFlags); void rendererDestroyRenderTarget(RenderTargetHandle _handle); void rendererCreateUniform(UniformHandle _handle, ConstantType::Enum _type, uint16_t _num, const char* _name); void rendererDestroyUniform(UniformHandle _handle); @@ -2212,7 +2213,10 @@ namespace bgfx uint32_t flags; _cmdbuf.read(flags); - rendererCreateRenderTarget(handle, width, height, flags); + uint32_t textureFlags; + _cmdbuf.read(textureFlags); + + rendererCreateRenderTarget(handle, width, height, flags, textureFlags); } break; diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index e15027c1b..0b0a516c9 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -1297,11 +1297,13 @@ namespace bgfx DX_CHECK(s_renderCtx.m_device->SetTexture(_stage, m_ptr) ); } - void RenderTarget::create(uint16_t _width, uint16_t _height, uint32_t _flags) + void RenderTarget::create(uint16_t _width, uint16_t _height, uint32_t _flags, uint32_t _textureFlags) { m_width = _width; m_height = _height; m_flags = _flags; + m_minFilter = s_textureFilter[(_textureFlags&BGFX_TEXTURE_MIN_MASK)>>BGFX_TEXTURE_MIN_SHIFT]; + m_magFilter = s_textureFilter[(_textureFlags&BGFX_TEXTURE_MAG_MASK)>>BGFX_TEXTURE_MAG_SHIFT]; createTextures(); } @@ -1434,8 +1436,8 @@ namespace bgfx void RenderTarget::commit(uint8_t _stage) { - DX_CHECK(s_renderCtx.m_device->SetSamplerState(_stage, D3DSAMP_MINFILTER, D3DTEXF_LINEAR) ); - DX_CHECK(s_renderCtx.m_device->SetSamplerState(_stage, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR) ); + DX_CHECK(s_renderCtx.m_device->SetSamplerState(_stage, D3DSAMP_MINFILTER, m_minFilter) ); + DX_CHECK(s_renderCtx.m_device->SetSamplerState(_stage, D3DSAMP_MAGFILTER, m_magFilter) ); DX_CHECK(s_renderCtx.m_device->SetSamplerState(_stage, D3DSAMP_MIPFILTER, D3DTEXF_POINT) ); DX_CHECK(s_renderCtx.m_device->SetSamplerState(_stage, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP) ); DX_CHECK(s_renderCtx.m_device->SetSamplerState(_stage, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP) ); @@ -1694,9 +1696,9 @@ namespace bgfx s_renderCtx.m_textures[_handle.idx].destroy(); } - void Context::rendererCreateRenderTarget(RenderTargetHandle _handle, uint16_t _width, uint16_t _height, uint32_t _flags) + void Context::rendererCreateRenderTarget(RenderTargetHandle _handle, uint16_t _width, uint16_t _height, uint32_t _flags, uint32_t _textureFlags) { - s_renderCtx.m_renderTargets[_handle.idx].create(_width, _height, _flags); + s_renderCtx.m_renderTargets[_handle.idx].create(_width, _height, _flags, _textureFlags); } void Context::rendererDestroyRenderTarget(RenderTargetHandle _handle) diff --git a/src/renderer_d3d9.h b/src/renderer_d3d9.h index d8e4facf1..2bd898f74 100644 --- a/src/renderer_d3d9.h +++ b/src/renderer_d3d9.h @@ -316,6 +316,8 @@ namespace bgfx , m_color(NULL) , m_depthTexture(NULL) , m_depth(NULL) + , m_minFilter(D3DTEXF_LINEAR) + , m_magFilter(D3DTEXF_LINEAR) , m_width(0) , m_height(0) , m_flags(0) @@ -323,7 +325,7 @@ namespace bgfx { } - void create(uint16_t _width, uint16_t _height, uint32_t _flags); + void create(uint16_t _width, uint16_t _height, uint32_t _flags, uint32_t _textureFlags); void createTextures(); void destroyTextures(); @@ -352,6 +354,8 @@ namespace bgfx IDirect3DSurface9* m_color; IDirect3DTexture9* m_depthTexture; IDirect3DSurface9* m_depth; + D3DTEXTUREFILTERTYPE m_minFilter; + D3DTEXTUREFILTERTYPE m_magFilter; uint16_t m_width; uint16_t m_height; uint32_t m_flags; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 1938d8250..c18756d89 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1285,7 +1285,7 @@ namespace bgfx GL_CHECK(glBindTexture(m_target, 0) ); } - void Texture::createColor(uint32_t _width, uint32_t _height) + void Texture::createColor(uint32_t _width, uint32_t _height, GLenum _min, GLenum _mag) { GLenum internalFormat = /*_fp ? GL_RGBA16F_ARB :*/ GL_RGBA; GLenum type = /*_fp ? GL_HALF_FLOAT_ARB :*/ GL_UNSIGNED_BYTE; @@ -1294,8 +1294,8 @@ namespace bgfx GL_CHECK(glGenTextures(1, &m_id) ); BX_CHECK(0 != m_id, "Failed to generate texture id."); GL_CHECK(glBindTexture(m_target, m_id) ); - GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR) ); - GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR) ); + GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_MIN_FILTER, _min) ); + GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_MAG_FILTER, _mag) ); GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) ); GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) ); @@ -1352,7 +1352,7 @@ namespace bgfx } } - void RenderTarget::create(uint16_t _width, uint16_t _height, uint32_t _flags) + void RenderTarget::create(uint16_t _width, uint16_t _height, uint32_t _flags, uint32_t _textureFlags) { BX_TRACE("Create render target %dx%d 0x%02x", _width, _height, _flags); @@ -1362,10 +1362,12 @@ namespace bgfx // m_msaa = s_msaa[(m_flags&BGFX_RENDER_TARGET_MSAA_MASK)>>BGFX_RENDER_TARGET_MSAA_SHIFT]; uint32_t colorFormat = (_flags&BGFX_RENDER_TARGET_COLOR_MASK)>>BGFX_RENDER_TARGET_COLOR_SHIFT; uint32_t depthFormat = (_flags&BGFX_RENDER_TARGET_DEPTH_MASK)>>BGFX_RENDER_TARGET_DEPTH_SHIFT; + GLenum minFilter = s_textureFilter[(_textureFlags&BGFX_TEXTURE_MIN_MASK)>>BGFX_TEXTURE_MIN_SHIFT]; + GLenum magFilter = s_textureFilter[(_textureFlags&BGFX_TEXTURE_MAG_MASK)>>BGFX_TEXTURE_MAG_SHIFT]; if (0 < colorFormat) { - m_color.createColor(_width, _height); + m_color.createColor(_width, _height, minFilter, magFilter); } #if 0 // GLES can't create texture with depth texture format... @@ -1782,9 +1784,9 @@ namespace bgfx s_renderCtx.m_textures[_handle.idx].destroy(); } - void Context::rendererCreateRenderTarget(RenderTargetHandle _handle, uint16_t _width, uint16_t _height, uint32_t _flags) + void Context::rendererCreateRenderTarget(RenderTargetHandle _handle, uint16_t _width, uint16_t _height, uint32_t _flags, uint32_t _textureFlags) { - s_renderCtx.m_renderTargets[_handle.idx].create(_width, _height, _flags); + s_renderCtx.m_renderTargets[_handle.idx].create(_width, _height, _flags, _textureFlags); } void Context::rendererDestroyRenderTarget(RenderTargetHandle _handle) diff --git a/src/renderer_gl.h b/src/renderer_gl.h index 04f3bbc83..019127246 100644 --- a/src/renderer_gl.h +++ b/src/renderer_gl.h @@ -257,7 +257,7 @@ namespace bgfx } void create(const Memory* _mem, uint32_t _flags); - void createColor(uint32_t _width, uint32_t _height); + void createColor(uint32_t _width, uint32_t _height, GLenum _min, GLenum _mag); void createDepth(uint32_t _width, uint32_t _height); void destroy(); @@ -305,7 +305,7 @@ namespace bgfx struct RenderTarget { - void create(uint16_t _width, uint16_t _height, uint32_t _flags); + void create(uint16_t _width, uint16_t _height, uint32_t _flags, uint32_t _textureFlags); void destroy(); GLsizei m_width; diff --git a/src/renderer_null.cpp b/src/renderer_null.cpp index 46ab1717e..21df1c672 100644 --- a/src/renderer_null.cpp +++ b/src/renderer_null.cpp @@ -105,7 +105,7 @@ namespace bgfx { } - void Context::rendererCreateRenderTarget(RenderTargetHandle _handle, uint16_t _width, uint16_t _height, uint32_t _flags) + void Context::rendererCreateRenderTarget(RenderTargetHandle _handle, uint16_t _width, uint16_t _height, uint32_t _flags, uint32_t _textureFlags) { }