mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 00:58:30 -05:00
Fixed RGBA16F DDS loading.
This commit is contained in:
parent
a674d734d3
commit
4dc9be09d3
7 changed files with 100 additions and 62 deletions
|
@ -306,6 +306,7 @@ namespace bgfx
|
|||
BGRX8,
|
||||
BGRA8,
|
||||
RGBA16,
|
||||
RGBA16F,
|
||||
R5G6B5,
|
||||
RGBA4,
|
||||
RGB5A1,
|
||||
|
|
|
@ -906,9 +906,9 @@ namespace bgfx
|
|||
|
||||
static const uint32_t s_bitsPerPixel[TextureFormat::Count] =
|
||||
{
|
||||
4, // Dxt1
|
||||
8, // Dxt3
|
||||
8, // Dxt5
|
||||
4, // BC1
|
||||
8, // BC2
|
||||
8, // BC3
|
||||
4, // BC4
|
||||
8, // BC5
|
||||
0, // Unknown
|
||||
|
@ -916,6 +916,7 @@ namespace bgfx
|
|||
32, // BGRX8
|
||||
32, // BGRA8
|
||||
64, // RGBA16
|
||||
64, // RGBA16F
|
||||
16, // R5G6B5
|
||||
16, // RGBA4
|
||||
16, // RGB5A1
|
||||
|
|
|
@ -24,6 +24,11 @@ vec4 bgfxTexture2D(BgfxSampler2D _sampler, vec2 _coord)
|
|||
return _sampler.m_texture.Sample(_sampler.m_sampler, _coord);
|
||||
}
|
||||
|
||||
vec4 bgfxTexture2DLod(BgfxSampler2D _sampler, vec2 _coord, float _level)
|
||||
{
|
||||
return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level);
|
||||
}
|
||||
|
||||
struct BgfxSampler3D
|
||||
{
|
||||
SamplerState m_sampler;
|
||||
|
@ -35,6 +40,11 @@ vec4 bgfxTexture3D(BgfxSampler3D _sampler, vec3 _coord)
|
|||
return _sampler.m_texture.Sample(_sampler.m_sampler, _coord);
|
||||
}
|
||||
|
||||
vec4 bgfxTexture3DLod(BgfxSampler3D _sampler, vec3 _coord, float _level)
|
||||
{
|
||||
return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level);
|
||||
}
|
||||
|
||||
struct BgfxSamplerCube
|
||||
{
|
||||
SamplerState m_sampler;
|
||||
|
@ -46,58 +56,87 @@ vec4 bgfxTextureCube(BgfxSamplerCube _sampler, vec3 _coord)
|
|||
return _sampler.m_texture.Sample(_sampler.m_sampler, _coord);
|
||||
}
|
||||
|
||||
vec4 bgfxTextureCubeLod(BgfxSamplerCube _sampler, vec3 _coord, float _level)
|
||||
{
|
||||
return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level);
|
||||
}
|
||||
|
||||
# define SAMPLER2D(_name, _reg) \
|
||||
uniform SamplerState _name ## Sampler : register(s[_reg]); \
|
||||
uniform Texture2D _name ## Texture : register(t[_reg]); \
|
||||
static BgfxSampler2D _name = { _name ## Sampler, _name ## Texture }
|
||||
# define sampler2D BgfxSampler2D
|
||||
# define texture2D(_name, _coord) bgfxTexture2D(_name, _coord)
|
||||
# define texture2D(_sampler, _coord) bgfxTexture2D(_sampler, _coord)
|
||||
# define texture2DLod(_sampler, _coord, _level) bgfxTexture2DLod(_sampler, _coord, _level)
|
||||
|
||||
# define SAMPLER3D(_name, _reg) \
|
||||
uniform SamplerState _name ## Sampler : register(s[_reg]); \
|
||||
uniform Texture3D _name ## Texture : register(t[_reg]); \
|
||||
static BgfxSampler3D _name = { _name ## Sampler, _name ## Texture }
|
||||
# define sampler3D BgfxSampler3D
|
||||
# define texture3D(_name, _coord) bgfxTexture3D(_name, _coord)
|
||||
# define texture3D(_sampler, _coord) bgfxTexture3D(_sampler, _coord)
|
||||
# define texture3DLod(_sampler, _coord, _level) bgfxTexture3DLod(_sampler, _coord, _level)
|
||||
|
||||
# define SAMPLERCUBE(_name, _reg) \
|
||||
uniform SamplerState _name ## Sampler : register(s[_reg]); \
|
||||
uniform TextureCube _name ## Texture : register(t[_reg]); \
|
||||
static BgfxSamplerCube _name = { _name ## Sampler, _name ## Texture }
|
||||
# define samplerCube BgfxSamplerCube
|
||||
# define textureCube(_name, _coord) bgfxTextureCube(_name, _coord)
|
||||
# define textureCube(_sampler, _coord) bgfxTextureCube(_sampler, _coord)
|
||||
# define textureCubeLod(_sampler, _coord, _level) bgfxTextureCubeLod(_sampler, _coord, _level)
|
||||
# else
|
||||
# define SAMPLER2D(_name, _reg) uniform sampler2D _name : register(s ## _reg)
|
||||
# define texture2D tex2D
|
||||
# define texture2D(_sampler, _coord) tex2D(_sampler, _coord)
|
||||
# define texture2DLod(_sampler, _coord, _level) tex2Dlod(_sampler, vec3( (_coord).xy, _level) )
|
||||
# define SAMPLER3D(_name, _reg) uniform sampler3D _name : register(s ## _reg)
|
||||
# define texture3D tex3D
|
||||
# define texture3D(_sampler, _coord) tex3D(_sampler, _coord)
|
||||
# define texture3DLod(_sampler, _coord, _level) tex3Dlod(_sampler, vec4( (_coord).xyz, _level) )
|
||||
# define SAMPLERCUBE(_name, _reg) uniform samplerCUBE _name : register(s[_reg])
|
||||
# define textureCube texCUBE
|
||||
# define textureCube(_sampler, _coord) texCUBE(_sampler, _coord)
|
||||
# define textureCubeLod(_sampler, _coord, _level) texCUBElod(_sampler, vec4( (_coord).xyz, _level) )
|
||||
# endif //
|
||||
|
||||
# define vec2_splat(_x) float2(_x, _x)
|
||||
# define vec3_splat(_x) float3(_x, _x, _x)
|
||||
# define vec4_splat(_x) float4(_x, _x, _x, _x)
|
||||
|
||||
vec3 instMul(vec3 _vec, mat3 _mtx)
|
||||
{
|
||||
return mul(_mtx, _vec);
|
||||
}
|
||||
# define bvec2 bool2
|
||||
# define bvec3 bool3
|
||||
# define bvec4 bool4
|
||||
|
||||
vec3 instMul(mat3 _mtx, vec3 _vec)
|
||||
{
|
||||
return mul(_vec, _mtx);
|
||||
}
|
||||
vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_mtx, _vec); }
|
||||
vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_vec, _mtx); }
|
||||
vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_mtx, _vec); }
|
||||
vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_vec, _mtx); }
|
||||
|
||||
vec4 instMul(vec4 _vec, mat4 _mtx)
|
||||
{
|
||||
return mul(_mtx, _vec);
|
||||
}
|
||||
bvec2 lessThan(vec2 _a, vec2 _b) { return _a < _b; }
|
||||
bvec3 lessThan(vec3 _a, vec3 _b) { return _a < _b; }
|
||||
bvec4 lessThan(vec4 _a, vec4 _b) { return _a < _b; }
|
||||
|
||||
bvec2 lessThanEqual(vec2 _a, vec2 _b) { return _a <= _b; }
|
||||
bvec2 lessThanEqual(vec3 _a, vec3 _b) { return _a <= _b; }
|
||||
bvec2 lessThanEqual(vec4 _a, vec4 _b) { return _a <= _b; }
|
||||
|
||||
bvec2 greaterThan(vec2 _a, vec2 _b) { return _a > _b; }
|
||||
bvec3 greaterThan(vec3 _a, vec3 _b) { return _a > _b; }
|
||||
bvec4 greaterThan(vec4 _a, vec4 _b) { return _a > _b; }
|
||||
|
||||
bvec2 greaterThanEqual(vec2 _a, vec2 _b) { return _a >= _b; }
|
||||
bvec3 greaterThanEqual(vec3 _a, vec3 _b) { return _a >= _b; }
|
||||
bvec4 greaterThanEqual(vec4 _a, vec4 _b) { return _a >= _b; }
|
||||
|
||||
bvec2 notEqual(vec2 _a, vec2 _b) { return _a != _b; }
|
||||
bvec3 notEqual(vec3 _a, vec3 _b) { return _a != _b; }
|
||||
bvec4 notEqual(vec4 _a, vec4 _b) { return _a != _b; }
|
||||
|
||||
bvec2 equal(vec2 _a, vec2 _b) { return _a == _b; }
|
||||
bvec3 equal(vec3 _a, vec3 _b) { return _a == _b; }
|
||||
bvec4 equal(vec4 _a, vec4 _b) { return _a == _b; }
|
||||
|
||||
vec2 mix(vec2 _a, vec2 _b, vec2 _t) { return lerp(_a, _b, _t); }
|
||||
vec3 mix(vec3 _a, vec3 _b, vec3 _t) { return lerp(_a, _b, _t); }
|
||||
vec4 mix(vec4 _a, vec4 _b, vec4 _t) { return lerp(_a, _b, _t); }
|
||||
|
||||
vec4 instMul(mat4 _mtx, vec4 _vec)
|
||||
{
|
||||
return mul(_vec, _mtx);
|
||||
}
|
||||
#elif BGFX_SHADER_LANGUAGE_GLSL
|
||||
# define atan2(_x, _y) atan(_x, _y)
|
||||
# define frac(_x) fract(_x)
|
||||
|
@ -111,25 +150,10 @@ vec4 instMul(mat4 _mtx, vec4 _vec)
|
|||
# define vec3_splat(_x) vec3(_x)
|
||||
# define vec4_splat(_x) vec4(_x)
|
||||
|
||||
vec3 instMul(vec3 _vec, mat3 _mtx)
|
||||
{
|
||||
return mul(_vec, _mtx);
|
||||
}
|
||||
|
||||
vec3 instMul(mat3 _mtx, vec3 _vec)
|
||||
{
|
||||
return mul(_mtx, _vec);
|
||||
}
|
||||
|
||||
vec4 instMul(vec4 _vec, mat4 _mtx)
|
||||
{
|
||||
return mul(_vec, _mtx);
|
||||
}
|
||||
|
||||
vec4 instMul(mat4 _mtx, vec4 _vec)
|
||||
{
|
||||
return mul(_mtx, _vec);
|
||||
}
|
||||
vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_vec, _mtx); }
|
||||
vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_mtx, _vec); }
|
||||
vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_vec, _mtx); }
|
||||
vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_mtx, _vec); }
|
||||
#endif // BGFX_SHADER_LANGUAGE_HLSL
|
||||
|
||||
#endif // __cplusplus
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace bgfx
|
|||
#define DDS_ATI1 BX_MAKEFOURCC('A', 'T', 'I', '1')
|
||||
#define DDS_ATI2 BX_MAKEFOURCC('A', 'T', 'I', '2')
|
||||
|
||||
#define D3DFMT_A16B16G16R16 36
|
||||
#define D3DFMT_A16B16G16R16F 113
|
||||
|
||||
#define DDSD_CAPS 0x00000001
|
||||
|
@ -495,11 +496,17 @@ bool parseDds(Dds& _dds, const Memory* _mem)
|
|||
bpp = 4;
|
||||
break;
|
||||
|
||||
case D3DFMT_A16B16G16R16F:
|
||||
case D3DFMT_A16B16G16R16:
|
||||
type = TextureFormat::RGBA16;
|
||||
blockSize = 8;
|
||||
bpp = 64;
|
||||
break;
|
||||
|
||||
case D3DFMT_A16B16G16R16F:
|
||||
type = TextureFormat::RGBA16F;
|
||||
blockSize = 8;
|
||||
bpp = 64;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -158,6 +158,7 @@ namespace bgfx
|
|||
{ DXGI_FORMAT_R8_UNORM, 8 },
|
||||
{ DXGI_FORMAT_B8G8R8A8_UNORM, 32 },
|
||||
{ DXGI_FORMAT_B8G8R8A8_UNORM, 32 },
|
||||
{ DXGI_FORMAT_R16G16B16A16_UNORM, 64 },
|
||||
{ DXGI_FORMAT_R16G16B16A16_FLOAT, 64 },
|
||||
{ DXGI_FORMAT_B5G6R5_UNORM, 16 },
|
||||
{ DXGI_FORMAT_B4G4R4A4_UNORM, 16 },
|
||||
|
|
|
@ -174,6 +174,7 @@ namespace bgfx
|
|||
{ D3DFMT_X8R8G8B8, 32 },
|
||||
{ D3DFMT_A8R8G8B8, 32 },
|
||||
{ D3DFMT_A16B16G16R16, 64 },
|
||||
{ D3DFMT_A16B16G16R16F, 64 },
|
||||
{ D3DFMT_R5G6B5, 16 },
|
||||
{ D3DFMT_A4R4G4B4, 16 },
|
||||
{ D3DFMT_A1R5G5B5, 16 },
|
||||
|
|
|
@ -539,6 +539,7 @@ namespace bgfx
|
|||
{ GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, 8, true },
|
||||
{ GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 32, true },
|
||||
{ GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 32, true },
|
||||
{ GL_RGBA16, GL_RGBA, GL_UNSIGNED_BYTE, 64, true },
|
||||
#if BGFX_CONFIG_RENDERER_OPENGL
|
||||
{ GL_RGBA16, GL_RGBA, GL_HALF_FLOAT, 64, true },
|
||||
#else
|
||||
|
@ -1047,11 +1048,13 @@ namespace bgfx
|
|||
if (!tfi.m_supported
|
||||
|| TextureFormat::Unknown < dds.m_type)
|
||||
{
|
||||
bool decompress = TextureFormat::Unknown > dds.m_type;
|
||||
uint8_t textureFormat = dds.m_type;
|
||||
bool decompress = TextureFormat::Unknown > textureFormat;
|
||||
|
||||
if (decompress)
|
||||
{
|
||||
const TextureFormatInfo& tfi = s_textureFormat[TextureFormat::BGRA8];
|
||||
textureFormat = TextureFormat::BGRA8;
|
||||
const TextureFormatInfo& tfi = s_textureFormat[textureFormat];
|
||||
internalFmt = tfi.m_internalFmt;
|
||||
m_fmt = tfi.m_fmt;
|
||||
m_type = tfi.m_type;
|
||||
|
@ -1069,7 +1072,7 @@ namespace bgfx
|
|||
}
|
||||
#endif // BGFX_CONFIG_RENDERER_OPENGL
|
||||
|
||||
uint8_t* bits = (uint8_t*)g_realloc(NULL, dds.m_width*dds.m_height*4);
|
||||
uint8_t* bits = (uint8_t*)g_realloc(NULL, dds.m_width*dds.m_height*tfi.m_bpp/8);
|
||||
|
||||
for (uint8_t side = 0, numSides = dds.m_cubeMap ? 6 : 1; side < numSides; ++side)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue