diff --git a/examples/06-bump/bump.cpp b/examples/06-bump/bump.cpp index 1b55bb22..4851ef7e 100644 --- a/examples/06-bump/bump.cpp +++ b/examples/06-bump/bump.cpp @@ -22,8 +22,8 @@ struct PosNormalTangentTexcoordVertex float m_z; uint32_t m_normal; uint32_t m_tangent; - float m_u; - float m_v; + uint16_t m_u; + uint16_t m_v; }; static bgfx::VertexDecl s_PosNormalTangentTexcoordDecl; @@ -55,30 +55,30 @@ uint32_t packF4u(float _x, float _y = 0.0f, float _z = 0.0f, float _w = 0.0f) static PosNormalTangentTexcoordVertex s_cubeVertices[24] = { - {-1.0f, 1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 0.0f, 0.0f }, - { 1.0f, 1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 1.0f, 0.0f }, - {-1.0f, -1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 0.0f, 1.0f }, - { 1.0f, -1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 1.0f, 1.0f }, - {-1.0f, 1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 0.0f, 0.0f }, - { 1.0f, 1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 1.0f, 0.0f }, - {-1.0f, -1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 0.0f, 1.0f }, - { 1.0f, -1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 1.0f, 1.0f }, - {-1.0f, 1.0f, 1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 0.0f, 0.0f }, - { 1.0f, 1.0f, 1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 1.0f, 0.0f }, - {-1.0f, 1.0f, -1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 0.0f, 1.0f }, - { 1.0f, 1.0f, -1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 1.0f, 1.0f }, - {-1.0f, -1.0f, 1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 0.0f, 0.0f }, - { 1.0f, -1.0f, 1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 1.0f, 0.0f }, - {-1.0f, -1.0f, -1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 0.0f, 1.0f }, - { 1.0f, -1.0f, -1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 1.0f, 1.0f }, - { 1.0f, -1.0f, 1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 0.0f, 0.0f }, - { 1.0f, 1.0f, 1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 1.0f, 0.0f }, - { 1.0f, -1.0f, -1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 0.0f, 1.0f }, - { 1.0f, 1.0f, -1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 1.0f, 1.0f }, - {-1.0f, -1.0f, 1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 0.0f, 0.0f }, - {-1.0f, 1.0f, 1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 1.0f, 0.0f }, - {-1.0f, -1.0f, -1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 0.0f, 1.0f }, - {-1.0f, 1.0f, -1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 1.0f, 1.0f }, + {-1.0f, 1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 0, 0 }, + { 1.0f, 1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 0x7fff, 0 }, + {-1.0f, -1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 0, 0x7fff }, + { 1.0f, -1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 0x7fff, 0x7fff }, + {-1.0f, 1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 0, 0 }, + { 1.0f, 1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 0x7fff, 0 }, + {-1.0f, -1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 0, 0x7fff }, + { 1.0f, -1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 0x7fff, 0x7fff }, + {-1.0f, 1.0f, 1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 0, 0 }, + { 1.0f, 1.0f, 1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 0x7fff, 0 }, + {-1.0f, 1.0f, -1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 0, 0x7fff }, + { 1.0f, 1.0f, -1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 0x7fff, 0x7fff }, + {-1.0f, -1.0f, 1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 0, 0 }, + { 1.0f, -1.0f, 1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 0x7fff, 0 }, + {-1.0f, -1.0f, -1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 0, 0x7fff }, + { 1.0f, -1.0f, -1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 0x7fff, 0x7fff }, + { 1.0f, -1.0f, 1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 0, 0 }, + { 1.0f, 1.0f, 1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 0x7fff, 0 }, + { 1.0f, -1.0f, -1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 0, 0x7fff }, + { 1.0f, 1.0f, -1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 0x7fff, 0x7fff }, + {-1.0f, -1.0f, 1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 0, 0 }, + {-1.0f, 1.0f, 1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 0x7fff, 0 }, + {-1.0f, -1.0f, -1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 0, 0x7fff }, + {-1.0f, 1.0f, -1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 0x7fff, 0x7fff }, }; static const uint16_t s_cubeIndices[36] = @@ -299,7 +299,7 @@ int _main_(int _argc, char** _argv) s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float); s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true); s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::Tangent, 4, bgfx::AttribType::Uint8, true, true); - s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float); + s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Int16, true, true); s_PosNormalTangentTexcoordDecl.end(); const bgfx::Memory* mem; diff --git a/include/bgfx.h b/include/bgfx.h index 007b1b38..1c31e885 100644 --- a/include/bgfx.h +++ b/include/bgfx.h @@ -284,7 +284,7 @@ namespace bgfx enum Enum { Uint8, - Uint16, + Int16, Half, Float, @@ -450,6 +450,14 @@ namespace bgfx /// Add attribute to VertexDecl. /// + /// @param _attrib Attribute semantics. + /// @param _num Number of elements 1, 2, 3 or 4. + /// @param _type Element type. + /// @param _normalized Value is normalized for vertex shader. + /// @param _asInt Packaging rule for vertexPack, vertexUnpack, and + /// vertexConvert for AttribType::Uint8 and AttribType::Int16. + /// Unpacking code must be implemented inside vertex shader. + /// /// NOTE: /// Must be called between begin/end. void add(Attrib::Enum _attrib, uint8_t _num, AttribType::Enum _type, bool _normalized = false, bool _asInt = false); diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 01bd1e36..6a87a6e0 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -194,10 +194,10 @@ namespace bgfx { DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UNORM }, }, { - { DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_UNORM }, - { DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_UNORM }, - { DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UNORM }, - { DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UNORM }, + { DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_SNORM }, + { DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_SNORM }, + { DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SNORM }, + { DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SNORM }, }, { { DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT }, diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index b613cef1..9e080a71 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -534,7 +534,7 @@ namespace bgfx static const GLenum s_attribType[AttribType::Count] = { GL_UNSIGNED_BYTE, - GL_UNSIGNED_SHORT, + GL_SHORT, GL_HALF_FLOAT, GL_FLOAT, }; diff --git a/src/vertexdecl.cpp b/src/vertexdecl.cpp index 2a22f754..99bc2377 100644 --- a/src/vertexdecl.cpp +++ b/src/vertexdecl.cpp @@ -207,7 +207,7 @@ namespace bgfx } break; - case AttribType::Uint16: + case AttribType::Int16: { uint16_t* packed = (uint16_t*)data; if (_inputNormalized) @@ -216,20 +216,20 @@ namespace bgfx { switch (num) { - default: *packed++ = uint16_t(*_input++ * 32767.0f + 32768.0f); - case 3: *packed++ = uint16_t(*_input++ * 32767.0f + 32768.0f); - case 2: *packed++ = uint16_t(*_input++ * 32767.0f + 32768.0f); - case 1: *packed++ = uint16_t(*_input++ * 32767.0f + 32768.0f); + default: *packed++ = uint16_t(*_input++ * 32767.0f); + case 3: *packed++ = uint16_t(*_input++ * 32767.0f); + case 2: *packed++ = uint16_t(*_input++ * 32767.0f); + case 1: *packed++ = uint16_t(*_input++ * 32767.0f); } } else { switch (num) { - default: *packed++ = uint16_t(*_input++ * 65535.0f); - case 3: *packed++ = uint16_t(*_input++ * 65535.0f); - case 2: *packed++ = uint16_t(*_input++ * 65535.0f); - case 1: *packed++ = uint16_t(*_input++ * 65535.0f); + default: *packed++ = uint16_t(*_input++ * 65535.0f - 32768.0f); + case 3: *packed++ = uint16_t(*_input++ * 65535.0f - 32768.0f); + case 2: *packed++ = uint16_t(*_input++ * 65535.0f - 32768.0f); + case 1: *packed++ = uint16_t(*_input++ * 65535.0f - 32768.0f); } } } @@ -311,27 +311,27 @@ namespace bgfx } break; - case AttribType::Uint16: + case AttribType::Int16: { uint16_t* packed = (uint16_t*)data; if (asInt) { switch (num) { - default: *_output++ = (float(*packed++) - 32768.0f)*1.0f/32767.0f; - case 3: *_output++ = (float(*packed++) - 32768.0f)*1.0f/32767.0f; - case 2: *_output++ = (float(*packed++) - 32768.0f)*1.0f/32767.0f; - case 1: *_output++ = (float(*packed++) - 32768.0f)*1.0f/32767.0f; + default: *_output++ = float(*packed++)*1.0f/32767.0f; + case 3: *_output++ = float(*packed++)*1.0f/32767.0f; + case 2: *_output++ = float(*packed++)*1.0f/32767.0f; + case 1: *_output++ = float(*packed++)*1.0f/32767.0f; } } else { switch (num) { - default: *_output++ = float(*packed++)*1.0f/65535.0f; - case 3: *_output++ = float(*packed++)*1.0f/65535.0f; - case 2: *_output++ = float(*packed++)*1.0f/65535.0f; - case 1: *_output++ = float(*packed++)*1.0f/65535.0f; + default: *_output++ = (float(*packed++) + 32768.0f)*1.0f/65535.0f; + case 3: *_output++ = (float(*packed++) + 32768.0f)*1.0f/65535.0f; + case 2: *_output++ = (float(*packed++) + 32768.0f)*1.0f/65535.0f; + case 1: *_output++ = (float(*packed++) + 32768.0f)*1.0f/65535.0f; } } }