diff --git a/bin/data/config.json b/bin/data/config.json index 82fdbe2e..eeb969ab 100644 --- a/bin/data/config.json +++ b/bin/data/config.json @@ -109,7 +109,7 @@ "invariant": { "default stage buffers": true, "default defer buffer destroy": true, - "default command buffer immediate": true, + "default command buffer immediate": false, "multithreaded recording": true }, "pipelines": { @@ -117,10 +117,10 @@ "gui": true, "vsync": true, // vsync on vulkan side rather than engine-side "hdr": true, - "vxgi": false, + "vxgi": true, "culling": false, - "bloom": true, - "dof": true, + "bloom": false, + "dof": false, "rt": false, "fsr": false, "postProcess": false // "postProcess.chromab" // false @@ -299,7 +299,7 @@ "enabled": true }, "imgui": { - "enabled": true + "enabled": false }, "fsr": { "enabled": true, diff --git a/bin/data/shaders/common/functions.h b/bin/data/shaders/common/functions.h index e626031a..ee6b5b41 100644 --- a/bin/data/shaders/common/functions.h +++ b/bin/data/shaders/common/functions.h @@ -2,6 +2,10 @@ float random(vec3 seed, int i){ return fract(sin(dot(vec4(seed,i), vec4(12.9898,78.233,45.164,94.673))) * 43758.5453); } float rand2(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 143758.5453); } float rand3(vec3 co){ return fract(sin(dot(co.xyz ,vec3(12.9898,78.233, 37.719))) * 143758.5453); } +float interleavedGradientNoise(vec2 co) { + vec3 seed = vec3(0.06711056, 0.00583715, 52.9829189); + return fract(seed.z * fract(dot(co, seed.xy))); +} // float mipLevel( in vec2 dx_vtc, in vec2 dy_vtc ) { const float delta_max_sqr = max(dot(dx_vtc, dx_vtc), dot(dy_vtc, dy_vtc)); @@ -44,7 +48,8 @@ void gammaCorrect( inout vec3 color, float gamma ) { } void toneMap( inout vec4 color, float exposure ) { toneMap(color.rgb, exposure); } void gammaCorrect( inout vec4 color, float gamma ) { gammaCorrect(color.rgb, gamma); } -float luma( vec3 color ) { return dot(color, vec3(0.2126, 0.7152, 0.0722)); } +float luma( vec3 color ) { return dot(color, vec3(0.2126, 0.7152, 0.0722)); } // REF 709 +float luminance( vec3 color ) { return dot(color, vec3(0.299, 0.587, 0.114)); } // REF 601 // uint tea(uint val0, uint val1) { uint v0 = val0; diff --git a/bin/data/shaders/display/deferred/comp/comp.h b/bin/data/shaders/display/deferred/comp/comp.h index 3358e997..8d26d024 100644 --- a/bin/data/shaders/display/deferred/comp/comp.h +++ b/bin/data/shaders/display/deferred/comp/comp.h @@ -94,19 +94,10 @@ layout (binding = 18) uniform sampler2D samplerTextures[TEXTURES]; layout (binding = 19) uniform samplerCube samplerCubemaps[CUBEMAPS]; layout (binding = 20) uniform sampler3D samplerNoise; #if VXGI - layout (binding = 21) uniform usampler3D voxelDrawId[CASCADES]; - layout (binding = 22) uniform usampler3D voxelInstanceId[CASCADES]; - layout (binding = 23) uniform sampler3D voxelNormalX[CASCADES]; - layout (binding = 24) uniform sampler3D voxelNormalY[CASCADES]; - layout (binding = 25) uniform sampler3D voxelRadianceR[CASCADES]; - layout (binding = 26) uniform sampler3D voxelRadianceG[CASCADES]; - layout (binding = 27) uniform sampler3D voxelRadianceB[CASCADES]; - layout (binding = 28) uniform sampler3D voxelRadianceA[CASCADES]; - layout (binding = 29) uniform sampler3D voxelCount[CASCADES]; - layout (binding = 30) uniform sampler3D voxelOutput[CASCADES]; + layout (binding = 21) uniform sampler3D voxelOutput[CASCADES]; #endif #if RT - layout (binding = 31) uniform accelerationStructureEXT tlas; + layout (binding = 22) uniform accelerationStructureEXT tlas; #endif #if BUFFER_REFERENCE @@ -296,7 +287,7 @@ void directLighting() { surface.material.albedo.rgb = radiance.rgb; surface.material.indirect.rgb = vec3(0); surface.fragment.rgb = radiance.rgb; - surface.fragment.a = radiance.a; + surface.fragment.a = 1; // radiance.a; //return; } #endif diff --git a/bin/data/shaders/display/vxgi/comp.glsl b/bin/data/shaders/display/vxgi/comp.glsl index 853acd20..fce6de7e 100644 --- a/bin/data/shaders/display/vxgi/comp.glsl +++ b/bin/data/shaders/display/vxgi/comp.glsl @@ -50,18 +50,11 @@ layout (std140, binding = 7) readonly buffer Lights { layout (binding = 8) uniform sampler2D samplerTextures[TEXTURES]; layout (binding = 9) uniform samplerCube samplerCubemaps[CUBEMAPS]; -layout (binding = 10) uniform sampler3D samplerNoise; -layout (binding = 11, r32ui) uniform readonly uimage3D voxelDrawId[CASCADES]; -layout (binding = 12, r32ui) uniform readonly uimage3D voxelInstanceId[CASCADES]; -layout (binding = 13, r32ui) uniform readonly uimage3D voxelNormalX[CASCADES]; -layout (binding = 14, r32ui) uniform readonly uimage3D voxelNormalY[CASCADES]; -layout (binding = 15, r32ui) uniform readonly uimage3D voxelRadianceR[CASCADES]; -layout (binding = 16, r32ui) uniform readonly uimage3D voxelRadianceG[CASCADES]; -layout (binding = 17, r32ui) uniform readonly uimage3D voxelRadianceB[CASCADES]; -layout (binding = 18, r32ui) uniform readonly uimage3D voxelRadianceA[CASCADES]; -layout (binding = 19, r32ui) uniform readonly uimage3D voxelCount[CASCADES]; -layout (binding = 20, rgba8) uniform writeonly image3D voxelOutput[CASCADES]; +layout (binding = 10, r32ui) uniform readonly uimage3D voxelId[CASCADES]; +layout (binding = 11, r32ui) uniform readonly uimage3D voxelNormal[CASCADES]; +layout (binding = 12, r32ui) uniform readonly uimage3D voxelRadiance[CASCADES]; +layout (binding = 13, rgba8) uniform writeonly image3D voxelOutput[CASCADES]; #include "../../common/functions.h" #include "../../common/light.h" @@ -71,55 +64,27 @@ layout (binding = 20, rgba8) uniform writeonly image3D voxelOutput[CASCADES]; void main() { const vec3 tUvw = gl_GlobalInvocationID.xzy; for ( uint CASCADE = 0; CASCADE < CASCADES; ++CASCADE ) { - vec2 N_E = vec2( - uintBitsToFloat(imageLoad(voxelNormalX[CASCADE], ivec3(tUvw) ).x), - uintBitsToFloat(imageLoad(voxelNormalY[CASCADE], ivec3(tUvw) ).x) - ); - - surface.normal.world = decodeNormals( N_E ); - surface.normal.eye = vec3( ubo.settings.vxgi.matrix * vec4( surface.normal.world, 0.0f ) ); - - surface.position.eye = (vec3(gl_GlobalInvocationID.xyz) / vec3(imageSize(voxelOutput[CASCADE])) * 2.0f - 1.0f) * cascadePower(CASCADE); - surface.position.world = vec3( inverse(ubo.settings.vxgi.matrix) * vec4( surface.position.eye, 1.0f ) ); - +#if 0 + vec4 A = unpackUnorm4x8(imageLoad(voxelRadiance[CASCADE], ivec3(tUvw)).r); + A.a = length(luma(A.rgb)) > 0.001 ? 1 : 0; + imageStore(voxelOutput[CASCADE], ivec3(tUvw), A); +#else surface.pass = 0; // PushConstant.pass; surface.fragment = vec4(0); surface.light = vec4(0); surface.motion = vec2(0); surface.material.indirect = vec4(0); -#if 0 - #if 0 - vec4 A = imageLoad(voxelOutput[CASCADE], ivec3(tUvw) ); - #else - vec4 A = vec4(0); - A.r = imageLoad(voxelRadianceR[CASCADE], ivec3(tUvw) ).r; - A.g = imageLoad(voxelRadianceG[CASCADE], ivec3(tUvw) ).r; - A.b = imageLoad(voxelRadianceB[CASCADE], ivec3(tUvw) ).r; - A.a = imageLoad(voxelRadianceA[CASCADE], ivec3(tUvw) ).r; - A /= 256.0; - - uint count = imageLoad(voxelCount[CASCADE], ivec3(tUvw) ).r; - if ( count > 0 ) A /= count; - /* - vec4 A = vec4(surface.normal.world, 1.0); - */ - #endif - - surface.material.albedo = A; - surface.fragment.rgb = surface.material.albedo.rgb; - - const bool DISCARD_DUE_TO_DIVERGENCE = surface.material.albedo.a == 0; -#else + const uint packedID = imageLoad(voxelId[CASCADE], ivec3(tUvw) ).x; const uvec2 ID = uvec2( - imageLoad(voxelDrawId[CASCADE], ivec3(tUvw) ).x, - imageLoad(voxelInstanceId[CASCADE], ivec3(tUvw) ).x + (packedID & 0xFFFF), + (packedID >> 16) ); const bool DISCARD_DUE_TO_DIVERGENCE = ID.x == 0 || ID.y == 0; const uint drawID = ID.x == 0 ? 0 : ID.x - 1; const uint instanceID = ID.y == 0 ? 0 : ID.y - 1; - + // if ( ID.x == 0 || ID.y == 0 ) { #if 1 if ( DISCARD_DUE_TO_DIVERGENCE ) { @@ -138,15 +103,8 @@ void main() { #if 0 vec4 A = imageLoad(voxelOutput[CASCADE], ivec3(tUvw) ); #else - vec4 A = vec4(0); - A.r = imageLoad(voxelRadianceR[CASCADE], ivec3(tUvw) ).r; - A.g = imageLoad(voxelRadianceG[CASCADE], ivec3(tUvw) ).r; - A.b = imageLoad(voxelRadianceB[CASCADE], ivec3(tUvw) ).r; - A.a = imageLoad(voxelRadianceA[CASCADE], ivec3(tUvw) ).r; - A /= 256.0; - - uint count = imageLoad(voxelCount[CASCADE], ivec3(tUvw) ).r; - if ( count > 0 ) A /= count; + vec4 A = unpackUnorm4x8(imageLoad(voxelRadiance[CASCADE], ivec3(tUvw)).r); + A.a = 1.0; #endif surface.material.albedo = A; @@ -205,7 +163,6 @@ void main() { #endif } surface.fragment.rgb += surface.light.rgb; - #endif #if TONE_MAP toneMap(surface.fragment.rgb, ubo.settings.bloom.exposure); @@ -214,14 +171,11 @@ void main() { gammaCorrect(surface.fragment.rgb, 1.0 / ubo.settings.bloom.gamma); #endif - #if 0 - imageStore(voxelOutput[CASCADE], ivec3(tUvw), vec4(surface.fragment.rgb, surface.material.albedo.a)); - #else if ( DISCARD_DUE_TO_DIVERGENCE ) { imageStore(voxelOutput[CASCADE], ivec3(tUvw), vec4(0)); } else { imageStore(voxelOutput[CASCADE], ivec3(tUvw), vec4(surface.fragment.rgb, surface.material.albedo.a)); } - #endif +#endif } } \ No newline at end of file diff --git a/bin/data/shaders/graph/voxelize/frag.glsl b/bin/data/shaders/graph/voxelize/frag.glsl index 529642b3..7ae35cec 100644 --- a/bin/data/shaders/graph/voxelize/frag.glsl +++ b/bin/data/shaders/graph/voxelize/frag.glsl @@ -37,16 +37,10 @@ layout (std140, binding = 12) readonly buffer Lights { Light lights[]; }; -layout (binding = 13, r32ui) uniform volatile uimage3D voxelDrawId[CASCADES]; -layout (binding = 14, r32ui) uniform volatile uimage3D voxelInstanceId[CASCADES]; -layout (binding = 15, r32ui) uniform volatile uimage3D voxelNormalX[CASCADES]; -layout (binding = 16, r32ui) uniform volatile uimage3D voxelNormalY[CASCADES]; -layout (binding = 17, r32ui) uniform volatile uimage3D voxelRadianceR[CASCADES]; -layout (binding = 18, r32ui) uniform volatile uimage3D voxelRadianceG[CASCADES]; -layout (binding = 19, r32ui) uniform volatile uimage3D voxelRadianceB[CASCADES]; -layout (binding = 20, r32ui) uniform volatile uimage3D voxelRadianceA[CASCADES]; -layout (binding = 21, r32ui) uniform volatile uimage3D voxelCount[CASCADES]; -layout (binding = 22, rgba8) uniform writeonly image3D voxelOutput[CASCADES]; +layout (binding = 13, r32ui) uniform volatile uimage3D voxelId[CASCADES]; +layout (binding = 14, r32ui) uniform volatile uimage3D voxelNormal[CASCADES]; +layout (binding = 15, r32ui) uniform volatile uimage3D voxelRadiance[CASCADES]; +layout (binding = 16, rgba8) uniform writeonly image3D voxelOutput[CASCADES]; layout (location = 0) flat in uvec4 inId; layout (location = 1) flat in vec4 inPOS0; @@ -94,7 +88,8 @@ void main() { A.a = 1; // alpha mode BLEND } else if ( material.modeAlpha == 1 ) { - + float dither = interleavedGradientNoise(gl_FragCoord.xy); + // if ( A.a < dither ) discard; // alpha mode MASK } else if ( material.modeAlpha == 2 ) { if ( A.a < abs(material.factorAlphaCutoff) ) discard; @@ -121,16 +116,13 @@ void main() { const ivec3 uvw = ivec3(P * imageSize(voxelOutput[CASCADE])); - imageAtomicMax(voxelDrawId[CASCADE], ivec3(uvw), uint( drawID + 1 ) ); - imageAtomicMax(voxelInstanceId[CASCADE], ivec3(uvw), uint( instanceID + 1 ) ); + uint packedId = ( instanceID + 1 ) << 16 | ( drawID + 1 ); + imageAtomicMax(voxelId[CASCADE], ivec3(uvw), packedId); vec2 N_E = encodeNormals( normalize( N ) ); - imageAtomicMin(voxelNormalX[CASCADE], ivec3(uvw), uint( floatBitsToUint( N_E.x ) ) ); - imageAtomicMin(voxelNormalY[CASCADE], ivec3(uvw), uint( floatBitsToUint( N_E.y ) ) ); - - imageAtomicAdd(voxelRadianceR[CASCADE], ivec3(uvw), uint( A.r * 256 ) ); - imageAtomicAdd(voxelRadianceG[CASCADE], ivec3(uvw), uint( A.g * 256 ) ); - imageAtomicAdd(voxelRadianceB[CASCADE], ivec3(uvw), uint( A.b * 256 ) ); - imageAtomicAdd(voxelRadianceA[CASCADE], ivec3(uvw), uint( A.a * 256 ) ); - imageAtomicAdd(voxelCount[CASCADE], ivec3(uvw), uint( 1 ) ); + uint packedNormal = packHalf2x16(N_E); + imageAtomicMin(voxelNormal[CASCADE], uvw, packedNormal); + + uint packedRadiance = packUnorm4x8(vec4(A.rgb, luminance(A.rgb))); + imageAtomicMax(voxelRadiance[CASCADE], uvw, packedRadiance); } \ No newline at end of file diff --git a/engine/inc/uf/engine/graph/scene.inl b/engine/inc/uf/engine/graph/scene.inl index 8c621fdf..d9fdef51 100644 --- a/engine/inc/uf/engine/graph/scene.inl +++ b/engine/inc/uf/engine/graph/scene.inl @@ -5,15 +5,9 @@ namespace pod { uf::renderer::Texture3D noise; uf::renderer::TextureCube skybox; struct { - uf::stl::vector drawId; - uf::stl::vector instanceId; - uf::stl::vector normalX; - uf::stl::vector normalY; - uf::stl::vector radianceR; - uf::stl::vector radianceG; - uf::stl::vector radianceB; - uf::stl::vector radianceA; - uf::stl::vector count; + uf::stl::vector id; + uf::stl::vector normal; + uf::stl::vector radiance; uf::stl::vector output; } voxels; }; diff --git a/engine/inc/uf/ext/vulkan/texture.h b/engine/inc/uf/ext/vulkan/texture.h index 71c09192..d426295d 100644 --- a/engine/inc/uf/ext/vulkan/texture.h +++ b/engine/inc/uf/ext/vulkan/texture.h @@ -59,6 +59,7 @@ namespace ext { VkImageViewType viewType = enums::Image::VIEW_TYPE_2D; VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED; VkImageUsageFlags usage = {}; + VkImageCreateFlags flags = {}; VkDeviceMemory deviceMemory = VK_NULL_HANDLE; VkDescriptorImageInfo descriptor = {}; VkFormat format = enums::Format::R8G8B8A8_UNORM; @@ -102,29 +103,45 @@ namespace ext { const uf::stl::string& filename, VkFormat format = DefaultFormat, VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT, - VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL + VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VkImageCreateFlags flags = {} ); void loadFromFile( const uf::stl::string& filename, Device& device, VkFormat format = DefaultFormat, VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT, - VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL + VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VkImageCreateFlags flags = {} ); void loadFromImage( const uf::Image& image, Device& device, VkFormat format = DefaultFormat, VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT, - VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL + VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VkImageCreateFlags flags = {} ); void loadFromImage( const uf::Image& image, VkFormat format = DefaultFormat, VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT, - VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL + VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VkImageCreateFlags flags = {} + ); + void fromBuffers( + void* buffer, + VkDeviceSize bufferSize, + VkFormat format, + uint32_t texWidth, + uint32_t texHeight, + uint32_t texDepth, + uint32_t layers, + Device& device, + VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT, + VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VkImageCreateFlags flags = {} ); - void fromBuffers( void* buffer, VkDeviceSize bufferSize, VkFormat format, uint32_t texWidth, uint32_t texHeight, uint32_t texDepth, uint32_t layers, Device& device, VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT, VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL ); void asRenderTarget( Device& device, uint32_t texWidth, uint32_t texHeight, VkFormat format = DefaultFormat ); Texture alias() const; @@ -136,14 +153,14 @@ namespace ext { void update( uf::Image& image, VkImageLayout, uint32_t layer = 1 ); void update( void*, VkDeviceSize, VkImageLayout, uint32_t layer = 1 ); - inline void fromBuffers( void* buffer, VkDeviceSize bufferSize, VkFormat format, uint32_t texWidth, uint32_t texHeight, Device& device, VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT, VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL ) { return this->fromBuffers(buffer, bufferSize, format, texWidth, texHeight, 1, 1, device, usage, layout); } + inline void fromBuffers( void* buffer, VkDeviceSize bufferSize, VkFormat format, uint32_t texWidth, uint32_t texHeight, Device& device, VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT, VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VkImageCreateFlags flags = {} ) { return this->fromBuffers(buffer, bufferSize, format, texWidth, texHeight, 1, 1, device, usage, layout, flags); } inline void update( uf::Image& image, uint32_t layer = 1 ) { return this->update(image, this->layout, layer); } inline void update( void* data, VkDeviceSize size, uint32_t layer = 1 ) { return this->update(data, size, this->layout, layer); } void generateMipmaps(VkCommandBuffer commandBuffer, uint32_t layer = 0); - void fromBuffers( void* buffer, VkDeviceSize bufferSize, VkFormat format, uint32_t texWidth, uint32_t texHeight, uint32_t texDepth, uint32_t layers, VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT, VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL ); - inline void fromBuffers( void* buffer, VkDeviceSize bufferSize, VkFormat format, uint32_t texWidth, uint32_t texHeight, VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT, VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL ) { return this->fromBuffers(buffer, bufferSize, format, texWidth, texHeight, 1, 1, usage, layout); } + void fromBuffers( void* buffer, VkDeviceSize bufferSize, VkFormat format, uint32_t texWidth, uint32_t texHeight, uint32_t texDepth, uint32_t layers, VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT, VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VkImageCreateFlags flags = {} ); + inline void fromBuffers( void* buffer, VkDeviceSize bufferSize, VkFormat format, uint32_t texWidth, uint32_t texHeight, VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT, VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VkImageCreateFlags flags = {} ) { return this->fromBuffers(buffer, bufferSize, format, texWidth, texHeight, 1, 1, usage, layout, flags); } }; class UF_API Texture2D : public Texture { public: diff --git a/engine/src/engine/ext/gui/glyph/behavior.cpp b/engine/src/engine/ext/gui/glyph/behavior.cpp index d78abea4..2827e754 100644 --- a/engine/src/engine/ext/gui/glyph/behavior.cpp +++ b/engine/src/engine/ext/gui/glyph/behavior.cpp @@ -384,7 +384,9 @@ void ext::GuiGlyphBehavior::initialize( uf::Object& self ) { bool forced = payload["force"].as(false); // override - // metadata.sdf = false; + #if UF_USE_OPENGL + metadata.sdf = false; + #endif metadataGui.scaling = "none"; auto& scene = uf::scene::getCurrentScene(); diff --git a/engine/src/engine/ext/raytrace/behavior.cpp b/engine/src/engine/ext/raytrace/behavior.cpp index cf3b3886..fa752936 100644 --- a/engine/src/engine/ext/raytrace/behavior.cpp +++ b/engine/src/engine/ext/raytrace/behavior.cpp @@ -225,39 +225,11 @@ void ext::RayTraceSceneBehavior::tick( uf::Object& self ) { shader.setDescriptorCounts({ { "samplerTextures", maxTextures2D }, { "samplerCubemaps", maxTexturesCube }, - { "voxelDrawId", maxCascades }, - { "voxelInstanceId", maxCascades }, - { "voxelNormalX", maxCascades }, - { "voxelNormalY", maxCascades }, - { "voxelRadianceR", maxCascades }, - { "voxelRadianceG", maxCascades }, - { "voxelRadianceB", maxCascades }, - { "voxelRadianceA", maxCascades }, - { "voxelCount", maxCascades }, + { "voxelId", maxCascades }, + { "voxelNormal", maxCascades }, + { "voxelRadiance", maxCascades }, { "voxelOutput", maxCascades }, }); - - /* - uint32_t* specializationConstants = (uint32_t*) (void*) shader.specializationConstants; - for ( auto pair : shader.metadata.definitions.specializationConstants ) { - auto& sc = pair.second; - if ( sc.name == "TEXTURES" ) sc.value.ui = (specializationConstants[sc.index] = maxTextures2D); - else if ( sc.name == "CUBEMAPS" ) sc.value.ui = (specializationConstants[sc.index] = maxTexturesCube); - else if ( sc.name == "CASCADES" ) sc.value.ui = (specializationConstants[sc.index] = maxCascades); - } - for ( auto pair : shader.metadata.definitions.textures ) { - auto& tx = pair.second; - for ( auto& layout : shader.descriptorSetLayoutBindings ) { - if ( layout.binding != tx.binding ) continue; - if ( tx.name == "samplerTextures" ) layout.descriptorCount = maxTextures2D; - else if ( tx.name == "samplerCubemaps" ) layout.descriptorCount = maxTexturesCube; - else if ( tx.name == "voxelId" ) layout.descriptorCount = maxCascades; - else if ( tx.name == "voxelUv" ) layout.descriptorCount = maxCascades; - else if ( tx.name == "voxelNormal" ) layout.descriptorCount = maxCascades; - else if ( tx.name == "voxelRadiance" ) layout.descriptorCount = maxCascades; - } - } - */ } } } diff --git a/engine/src/engine/ext/scene/behavior.cpp b/engine/src/engine/ext/scene/behavior.cpp index c307cc5c..ca029d60 100644 --- a/engine/src/engine/ext/scene/behavior.cpp +++ b/engine/src/engine/ext/scene/behavior.cpp @@ -740,26 +740,14 @@ void ext::ExtSceneBehavior::destroy( uf::Object& self ) { } if ( this->hasComponent() ) { auto& sceneTextures = this->getComponent(); - for ( auto& t : sceneTextures.voxels.drawId ) t.destroy(); - for ( auto& t : sceneTextures.voxels.instanceId ) t.destroy(); - for ( auto& t : sceneTextures.voxels.normalX ) t.destroy(); - for ( auto& t : sceneTextures.voxels.normalY ) t.destroy(); - for ( auto& t : sceneTextures.voxels.radianceR ) t.destroy(); - for ( auto& t : sceneTextures.voxels.radianceG ) t.destroy(); - for ( auto& t : sceneTextures.voxels.radianceB ) t.destroy(); - for ( auto& t : sceneTextures.voxels.radianceA ) t.destroy(); - for ( auto& t : sceneTextures.voxels.count ) t.destroy(); + for ( auto& t : sceneTextures.voxels.id ) t.destroy(); + for ( auto& t : sceneTextures.voxels.normal ) t.destroy(); + for ( auto& t : sceneTextures.voxels.radiance ) t.destroy(); for ( auto& t : sceneTextures.voxels.output ) t.destroy(); - sceneTextures.voxels.drawId.clear(); - sceneTextures.voxels.instanceId.clear(); - sceneTextures.voxels.normalX.clear(); - sceneTextures.voxels.normalY.clear(); - sceneTextures.voxels.radianceR.clear(); - sceneTextures.voxels.radianceG.clear(); - sceneTextures.voxels.radianceB.clear(); - sceneTextures.voxels.radianceA.clear(); - sceneTextures.voxels.count.clear(); + sceneTextures.voxels.id.clear(); + sceneTextures.voxels.normal.clear(); + sceneTextures.voxels.radiance.clear(); sceneTextures.voxels.output.clear(); sceneTextures.noise.destroy(); @@ -1136,17 +1124,14 @@ void ext::ExtSceneBehavior::bindBuffers( uf::Object& self, uf::renderer::Graphic // attach VXGI voxels if ( uf::renderer::settings::pipelines::vxgi ) { - for ( auto& t : sceneTextures.voxels.drawId ) textures3D.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.instanceId ) textures3D.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.normalX ) textures3D.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.normalY ) textures3D.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.radianceR ) textures3D.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.radianceG ) textures3D.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.radianceB ) textures3D.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.radianceA ) textures3D.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.count ) textures3D.emplace_back().aliasTexture(t); + /* + for ( auto& t : sceneTextures.voxels.id ) textures3D.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.normal ) textures3D.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.radiance ) textures3D.emplace_back().aliasTexture(t); + */ for ( auto& t : sceneTextures.voxels.output ) textures3D.emplace_back().aliasTexture(t); } + // bind textures while ( textures2D.size() < metadata.max.textures2D ) textures2D.emplace_back().aliasTexture(uf::renderer::Texture2D::empty); while ( texturesCube.size() < metadata.max.texturesCube ) texturesCube.emplace_back().aliasTexture(uf::renderer::TextureCube::empty); diff --git a/engine/src/engine/ext/voxelizer/behavior.cpp b/engine/src/engine/ext/voxelizer/behavior.cpp index feb3ae5f..442c4472 100644 --- a/engine/src/engine/ext/voxelizer/behavior.cpp +++ b/engine/src/engine/ext/voxelizer/behavior.cpp @@ -18,6 +18,7 @@ #include "../scene/behavior.h" #include +#define ALIAS_OUTPUT_TO_RADIANCE 1 UF_BEHAVIOR_REGISTER_CPP(ext::VoxelizerSceneBehavior) UF_BEHAVIOR_TRAITS_CPP(ext::VoxelizerSceneBehavior, ticks = true, renders = false, thread = "") @@ -35,44 +36,46 @@ void ext::VoxelizerSceneBehavior::initialize( uf::Object& self ) { for ( size_t i = 0; i < metadata.cascades; ++i ) { const bool HDR = false; - auto& drawId = sceneTextures.voxels.drawId.emplace_back(); - drawId.sampler.descriptor.filter.min = uf::renderer::enums::Filter::NEAREST; - drawId.sampler.descriptor.filter.mag = uf::renderer::enums::Filter::NEAREST; - drawId.fromBuffers( NULL, 0, uf::renderer::enums::Format::R32_UINT, metadata.voxelSize.x, metadata.voxelSize.y, metadata.voxelSize.z, 1, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); - - auto& instanceId = sceneTextures.voxels.instanceId.emplace_back(); - instanceId.sampler.descriptor.filter.min = uf::renderer::enums::Filter::NEAREST; - instanceId.sampler.descriptor.filter.mag = uf::renderer::enums::Filter::NEAREST; - instanceId.fromBuffers( NULL, 0, uf::renderer::enums::Format::R32_UINT, metadata.voxelSize.x, metadata.voxelSize.y, metadata.voxelSize.z, 1, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); + auto& id = sceneTextures.voxels.id.emplace_back(); + id.sampler.descriptor.filter.min = uf::renderer::enums::Filter::NEAREST; + id.sampler.descriptor.filter.mag = uf::renderer::enums::Filter::NEAREST; + id.fromBuffers( NULL, 0, uf::renderer::enums::Format::R32_UINT, metadata.voxelSize.x, metadata.voxelSize.y, metadata.voxelSize.z, 1, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); - auto& normalX = sceneTextures.voxels.normalX.emplace_back(); - normalX.fromBuffers( NULL, 0, uf::renderer::enums::Format::R32_UINT, metadata.voxelSize.x, metadata.voxelSize.y, metadata.voxelSize.z, 1, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); - - auto& normalY = sceneTextures.voxels.normalY.emplace_back(); - normalY.fromBuffers( NULL, 0, uf::renderer::enums::Format::R32_UINT, metadata.voxelSize.x, metadata.voxelSize.y, metadata.voxelSize.z, 1, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); + auto& normal = sceneTextures.voxels.normal.emplace_back(); + normal.fromBuffers( NULL, 0, uf::renderer::enums::Format::R32_UINT, metadata.voxelSize.x, metadata.voxelSize.y, metadata.voxelSize.z, 1, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); - auto& radianceR = sceneTextures.voxels.radianceR.emplace_back(); - radianceR.fromBuffers( NULL, 0, uf::renderer::enums::Format::R32_UINT, metadata.voxelSize.x, metadata.voxelSize.y, metadata.voxelSize.z, 1, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); + auto& radiance = sceneTextures.voxels.radiance.emplace_back(); + radiance.fromBuffers( NULL, 0, uf::renderer::enums::Format::R32_UINT, metadata.voxelSize.x, metadata.voxelSize.y, metadata.voxelSize.z, 1, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); - auto& radianceG = sceneTextures.voxels.radianceG.emplace_back(); - radianceG.fromBuffers( NULL, 0, uf::renderer::enums::Format::R32_UINT, metadata.voxelSize.x, metadata.voxelSize.y, metadata.voxelSize.z, 1, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); - - auto& radianceB = sceneTextures.voxels.radianceB.emplace_back(); - radianceB.fromBuffers( NULL, 0, uf::renderer::enums::Format::R32_UINT, metadata.voxelSize.x, metadata.voxelSize.y, metadata.voxelSize.z, 1, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); - - auto& radianceA = sceneTextures.voxels.radianceA.emplace_back(); - radianceA.fromBuffers( NULL, 0, uf::renderer::enums::Format::R32_UINT, metadata.voxelSize.x, metadata.voxelSize.y, metadata.voxelSize.z, 1, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); - - auto& count = sceneTextures.voxels.count.emplace_back(); - count.fromBuffers( NULL, 0, uf::renderer::enums::Format::R32_UINT, metadata.voxelSize.x, metadata.voxelSize.y, metadata.voxelSize.z, 1, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); - auto& output = sceneTextures.voxels.output.emplace_back(); + /* if ( metadata.filtering == "NEAREST" ) { output.sampler.descriptor.filter.min = uf::renderer::enums::Filter::NEAREST; output.sampler.descriptor.filter.mag = uf::renderer::enums::Filter::NEAREST; } + */ // output.fromBuffers( NULL, 0, uf::renderer::settings::pipelines::hdr ? uf::renderer::enums::Format::HDR : uf::renderer::enums::Format::SDR, metadata.voxelSize.x, metadata.voxelSize.y, metadata.voxelSize.z, 1, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); + #if ALIAS_OUTPUT_TO_RADIANCE + output.aliasTexture( radiance ); + { + VkImageViewCreateInfo viewCreateInfo = {}; + viewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + viewCreateInfo.image = radiance.image; + viewCreateInfo.viewType = radiance.viewType; + viewCreateInfo.format = VK_FORMAT_R8G8B8A8_UNORM; + viewCreateInfo.components = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A }; + viewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + viewCreateInfo.subresourceRange.baseMipLevel = 0; + viewCreateInfo.subresourceRange.levelCount = radiance.mips; + viewCreateInfo.subresourceRange.baseArrayLayer = 0; + viewCreateInfo.subresourceRange.layerCount = 1; + + VK_CHECK_RESULT(vkCreateImageView(uf::renderer::device.logicalDevice, &viewCreateInfo, nullptr, &output.view)); + VK_REGISTER_HANDLE( output.view ); + } + #else output.fromBuffers( NULL, 0, uf::renderer::enums::Format::R8G8B8A8_UNORM, metadata.voxelSize.x, metadata.voxelSize.y, metadata.voxelSize.z, 1, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); + #endif } // initialize render mode { @@ -120,15 +123,9 @@ void ext::VoxelizerSceneBehavior::initialize( uf::Object& self ) { for ( size_t i = 0; i < maxTexturesCube; ++i ) renderMode.blitter.material.textures.emplace_back().aliasTexture(uf::renderer::TextureCube::empty); for ( size_t i = 0; i < maxTextures3D; ++i ) renderMode.blitter.material.textures.emplace_back().aliasTexture(uf::renderer::Texture3D::empty); - for ( auto& t : sceneTextures.voxels.drawId ) renderMode.blitter.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.instanceId ) renderMode.blitter.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.normalX ) renderMode.blitter.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.normalY ) renderMode.blitter.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.radianceR ) renderMode.blitter.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.radianceG ) renderMode.blitter.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.radianceB ) renderMode.blitter.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.radianceA ) renderMode.blitter.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.count ) renderMode.blitter.material.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.id ) renderMode.blitter.material.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.normal ) renderMode.blitter.material.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.radiance ) renderMode.blitter.material.textures.emplace_back().aliasTexture(t); for ( auto& t : sceneTextures.voxels.output ) renderMode.blitter.material.textures.emplace_back().aliasTexture(t); renderMode.bindCallback( renderMode.CALLBACK_BEGIN, [&]( VkCommandBuffer commandBuffer, size_t _ ){ @@ -141,15 +138,9 @@ void ext::VoxelizerSceneBehavior::initialize( uf::Object& self ) { subresourceRange.layerCount = 1; VkClearColorValue clearColor = { 0.0, 0.0, 0.0, 0.0 }; - for ( auto& t : sceneTextures.voxels.drawId ) vkCmdClearColorImage( commandBuffer, t.image, t.layout, &clearColor, 1, &subresourceRange ); - for ( auto& t : sceneTextures.voxels.instanceId ) vkCmdClearColorImage( commandBuffer, t.image, t.layout, &clearColor, 1, &subresourceRange ); - for ( auto& t : sceneTextures.voxels.normalX ) vkCmdClearColorImage( commandBuffer, t.image, t.layout, &clearColor, 1, &subresourceRange ); - for ( auto& t : sceneTextures.voxels.normalY ) vkCmdClearColorImage( commandBuffer, t.image, t.layout, &clearColor, 1, &subresourceRange ); - for ( auto& t : sceneTextures.voxels.radianceR ) vkCmdClearColorImage( commandBuffer, t.image, t.layout, &clearColor, 1, &subresourceRange ); - for ( auto& t : sceneTextures.voxels.radianceG ) vkCmdClearColorImage( commandBuffer, t.image, t.layout, &clearColor, 1, &subresourceRange ); - for ( auto& t : sceneTextures.voxels.radianceB ) vkCmdClearColorImage( commandBuffer, t.image, t.layout, &clearColor, 1, &subresourceRange ); - for ( auto& t : sceneTextures.voxels.radianceA ) vkCmdClearColorImage( commandBuffer, t.image, t.layout, &clearColor, 1, &subresourceRange ); - for ( auto& t : sceneTextures.voxels.count ) vkCmdClearColorImage( commandBuffer, t.image, t.layout, &clearColor, 1, &subresourceRange ); + for ( auto& t : sceneTextures.voxels.id ) vkCmdClearColorImage( commandBuffer, t.image, t.layout, &clearColor, 1, &subresourceRange ); + for ( auto& t : sceneTextures.voxels.normal ) vkCmdClearColorImage( commandBuffer, t.image, t.layout, &clearColor, 1, &subresourceRange ); + for ( auto& t : sceneTextures.voxels.radiance ) vkCmdClearColorImage( commandBuffer, t.image, t.layout, &clearColor, 1, &subresourceRange ); for ( auto& t : sceneTextures.voxels.output ) vkCmdClearColorImage( commandBuffer, t.image, t.layout, &clearColor, 1, &subresourceRange ); }); @@ -287,15 +278,16 @@ void ext::VoxelizerSceneBehavior::tick( uf::Object& self ) { } void ext::VoxelizerSceneBehavior::render( uf::Object& self ){} void ext::VoxelizerSceneBehavior::destroy( uf::Object& self ){ -#if UF_USE_VULKAN -/* - if ( this->hasComponent() ) { - auto& renderMode = this->getComponent(); - - uf::renderer::removeRenderMode( &renderMode, false ); - // this->deleteComponent(); +#if ALIAS_OUTPUT_TO_RADIANCE + auto& sceneTextures = this->getComponent(); + for ( auto& t : sceneTextures.voxels.output ) { + ext::vulkan::mutex.lock(); + auto& texture = uf::renderer::device.transient.textures.emplace_back(); + ext::vulkan::mutex.unlock(); + + texture.device = &uf::renderer::device; + texture.view = t.view; } -*/ #endif } void ext::VoxelizerSceneBehavior::Metadata::serialize( uf::Object& self, uf::Serializer& serializer ) { diff --git a/engine/src/engine/graph/graph.cpp b/engine/src/engine/graph/graph.cpp index d56a6184..ef384222 100644 --- a/engine/src/engine/graph/graph.cpp +++ b/engine/src/engine/graph/graph.cpp @@ -80,20 +80,23 @@ namespace { for ( auto& key : storage.texture2Ds.keys ) graphic.material.textures.emplace_back().aliasTexture( storage.texture2Ds.map[key] ); // bind scene's voxel texture - #if UF_USE_VULKAN + #if 0 && UF_USE_VULKAN if ( uf::renderer::settings::pipelines::vxgi ) { auto& scene = uf::scene::getCurrentScene(); auto& sceneTextures = scene.getComponent(); - for ( auto& t : sceneTextures.voxels.drawId ) graphic.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.instanceId ) graphic.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.normalX ) graphic.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.normalY ) graphic.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.radianceR ) graphic.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.radianceG ) graphic.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.radianceB ) graphic.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.radianceA ) graphic.material.textures.emplace_back().aliasTexture(t); - for ( auto& t : sceneTextures.voxels.count ) graphic.material.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.id ) graphic.material.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.normal ) graphic.material.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.radiance ) graphic.material.textures.emplace_back().aliasTexture(t); for ( auto& t : sceneTextures.voxels.output ) graphic.material.textures.emplace_back().aliasTexture(t); + /* + auto& shader = graphic.material.getShader("fragment", uf::renderer::settings::pipelines::names::vxgi); + shader.textures.clear(); + + for ( auto& t : sceneTextures.voxels.id ) shader.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.normal ) shader.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.radiance ) shader.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.output ) shader.textures.emplace_back().aliasTexture(t); + */ } #endif } @@ -219,21 +222,9 @@ namespace { graphic.material.attachShader(geometryShaderFilename, uf::renderer::enums::Shader::GEOMETRY, uf::renderer::settings::pipelines::names::vxgi); } - uint32_t voxelTypes = 0; - if ( !sceneTextures.voxels.drawId.empty() ) ++voxelTypes; - if ( !sceneTextures.voxels.instanceId.empty() ) ++voxelTypes; - if ( !sceneTextures.voxels.normalX.empty() ) ++voxelTypes; - if ( !sceneTextures.voxels.normalY.empty() ) ++voxelTypes; - if ( !sceneTextures.voxels.radianceR.empty() ) ++voxelTypes; - if ( !sceneTextures.voxels.radianceG.empty() ) ++voxelTypes; - if ( !sceneTextures.voxels.radianceB.empty() ) ++voxelTypes; - if ( !sceneTextures.voxels.radianceA.empty() ) ++voxelTypes; - if ( !sceneTextures.voxels.count.empty() ) ++voxelTypes; - if ( !sceneTextures.voxels.output.empty() ) ++voxelTypes; - uint32_t maxTextures = texture2Ds; - uint32_t maxCascades = texture3Ds / voxelTypes; - + uint32_t maxCascades = sceneTextures.voxels.id.size(); + // fragment shader { auto& shader = graphic.material.getShader("fragment", uf::renderer::settings::pipelines::names::vxgi); @@ -243,17 +234,16 @@ namespace { }); shader.setDescriptorCounts({ { "samplerTextures", maxTextures }, - { "voxelDrawId", maxCascades }, - { "voxelInstanceId", maxCascades }, - { "voxelNormalX", maxCascades }, - { "voxelNormalY", maxCascades }, - { "voxelRadianceR", maxCascades }, - { "voxelRadianceG", maxCascades }, - { "voxelRadianceB", maxCascades }, - { "voxelRadianceA", maxCascades }, - { "voxelCount", maxCascades }, + { "voxelId", maxCascades }, + { "voxelNormal", maxCascades }, + { "voxelRadiance", maxCascades }, { "voxelOutput", maxCascades }, }); + + for ( auto& t : sceneTextures.voxels.id ) shader.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.normal ) shader.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.radiance ) shader.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.output ) shader.textures.emplace_back().aliasTexture(t); } } // baking pipeline diff --git a/engine/src/ext/gltf/processPrimitives.inl b/engine/src/ext/gltf/processPrimitives.inl index ddb2b9c2..dff50a60 100644 --- a/engine/src/ext/gltf/processPrimitives.inl +++ b/engine/src/ext/gltf/processPrimitives.inl @@ -273,17 +273,17 @@ for ( auto& p : m.primitives ) { }; float r = 1.0f / (deltaTriUV[0].x * deltaTriUV[1].y - deltaTriUV[0].y * deltaTriUV[1].x); - auto tangent_tri = (deltaTriPosition[0] * deltaTriUV[1].y - deltaTriPosition[1] * deltaTriUV[0].y) * r; - auto bitangent_tri = (deltaTriPosition[1] * deltaTriUV[0].x - deltaTriPosition[0] * deltaTriUV[1].x) * r; + auto tangent_tri = (deltaTriPosition[0] * deltaTriUV[1].y - deltaTriPosition[1] * deltaTriUV[0].y) * r; + auto bitangent_tri = (deltaTriPosition[1] * deltaTriUV[0].x - deltaTriPosition[0] * deltaTriUV[1].x) * r; - for ( auto i = 0; i < 3; ++i ) { - auto& normal = meshlet.vertices[indices[0]].normal; - auto& tangent = meshlet.vertices[indices[0]].tangent; + for ( auto i = 0; i < 3; ++i ) { + auto& normal = meshlet.vertices[indices[0]].normal; + auto& tangent = meshlet.vertices[indices[0]].tangent; tangent = uf::vector::normalize(tangent_tri - normal * uf::vector::dot(normal, tangent_tri)); if (uf::vector::dot(uf::vector::cross(normal, tangent), bitangent_tri) < 0.0f) tangent = tangent * -1.0f; - } + } } } else { for ( size_t i = 0; i < meshlet.vertices.size() / 3; ++i ) { @@ -313,17 +313,17 @@ for ( auto& p : m.primitives ) { }; float r = 1.0f / (deltaTriUV[0].x * deltaTriUV[1].y - deltaTriUV[0].y * deltaTriUV[1].x); - auto tangent_tri = (deltaTriPosition[0] * deltaTriUV[1].y - deltaTriPosition[1] * deltaTriUV[0].y) * r; - auto bitangent_tri = (deltaTriPosition[1] * deltaTriUV[0].x - deltaTriPosition[0] * deltaTriUV[1].x) * r; + auto tangent_tri = (deltaTriPosition[0] * deltaTriUV[1].y - deltaTriPosition[1] * deltaTriUV[0].y) * r; + auto bitangent_tri = (deltaTriPosition[1] * deltaTriUV[0].x - deltaTriPosition[0] * deltaTriUV[1].x) * r; - for ( auto i = 0; i < 3; ++i ) { - auto& normal = meshlet.vertices[indices[0]].normal; - auto& tangent = meshlet.vertices[indices[0]].tangent; + for ( auto i = 0; i < 3; ++i ) { + auto& normal = meshlet.vertices[indices[0]].normal; + auto& tangent = meshlet.vertices[indices[0]].tangent; tangent = uf::vector::normalize(tangent_tri - normal * uf::vector::dot(normal, tangent_tri)); if (uf::vector::dot(uf::vector::cross(normal, tangent), bitangent_tri) < 0.0f) tangent = tangent * -1.0f; - } + } } } } diff --git a/engine/src/ext/imgui/imgui.cpp b/engine/src/ext/imgui/imgui.cpp index d4678fcc..bc3235c2 100644 --- a/engine/src/ext/imgui/imgui.cpp +++ b/engine/src/ext/imgui/imgui.cpp @@ -173,10 +173,12 @@ void ext::imgui::tick() { auto& renderMode = uf::renderer::getRenderMode("Gui", true); // check if rendermode changed +#if UF_USE_VULKAN if ( ::boundRenderMode != &renderMode ) { ::shutdownRenderer(); ::initRenderer(); } +#endif ImGuiIO& io = ImGui::GetIO(); io.DeltaTime = uf::physics::time::delta; diff --git a/engine/src/ext/opengl/device.cpp b/engine/src/ext/opengl/device.cpp index f4254c75..8f1b5713 100644 --- a/engine/src/ext/opengl/device.cpp +++ b/engine/src/ext/opengl/device.cpp @@ -19,6 +19,7 @@ namespace { struct Pair { bool aliased = false; size_t index = 0; + size_t size = 0; }; uf::stl::vector local; uf::stl::vector aliases; @@ -105,7 +106,7 @@ void ext::opengl::Device::initialize() { #endif #if UF_USE_OPENGL_FIXED_FUNCTION { - ::buffers::type.emplace_back(::buffers::Pair{.aliased = false, .index = 0}); + ::buffers::type.emplace_back(::buffers::Pair{.aliased = false, .index = 0, .size = 0}); ::buffers::local.emplace_back((void*) NULL); } #endif @@ -172,7 +173,7 @@ GLuint ext::opengl::Device::createBuffer( enums::Buffer::type_t usage, GLsizeipt #else // CPU-based buffer index = ::buffers::type.size(); - ::buffers::type.emplace_back( ::buffers::Pair{.aliased = aliased, .index = index} ); + ::buffers::type.emplace_back( ::buffers::Pair{.aliased = aliased, .index = index, .size = size} ); if ( aliased ) { ::buffers::aliases.emplace_back( data ); @@ -215,11 +216,11 @@ void ext::opengl::Device::destroyBuffer( GLuint& index ) { auto& buffer = ::buffers::local[type.index]; if ( buffer ) { #if UF_MEMORYPOOL_INVALID_FREE - uf::memoryPool::global.free( buffer ); + uf::memoryPool::global.free( buffer, type.size ); #else uf::MemoryPool* memoryPool = uf::memoryPool::global.size() > 0 ? &uf::memoryPool::global : NULL; - if ( memoryPool ) memoryPool->free( buffer ); - else free( buffer ); + if ( memoryPool ) memoryPool->free( buffer, type.size ); + else free( buffer, type.size ); #endif } #endif diff --git a/engine/src/ext/vulkan/graphic.cpp b/engine/src/ext/vulkan/graphic.cpp index 71047a40..1afa9283 100644 --- a/engine/src/ext/vulkan/graphic.cpp +++ b/engine/src/ext/vulkan/graphic.cpp @@ -1226,13 +1226,13 @@ void ext::vulkan::Graphic::generateBottomAccelerationStructures() { uf::stl::vector asBuildOffsetInfo; VkBuildAccelerationStructureFlagsKHR flags{}; - VkAccelerationStructureBuildGeometryInfoKHR buildInfo{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR}; - VkAccelerationStructureBuildSizesInfoKHR sizeInfo{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR}; + VkAccelerationStructureBuildGeometryInfoKHR buildInfo{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR}; + VkAccelerationStructureBuildSizesInfoKHR sizeInfo{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR}; - const VkAccelerationStructureBuildRangeInfoKHR* rangeInfo; - uf::renderer::AccelerationStructure as; - - uf::renderer::AccelerationStructure previous; + const VkAccelerationStructureBuildRangeInfoKHR* rangeInfo; + uf::renderer::AccelerationStructure as; + + uf::renderer::AccelerationStructure previous; }; uf::stl::vector blasDatas; @@ -1297,7 +1297,7 @@ void ext::vulkan::Graphic::generateBottomAccelerationStructures() { triangles.indexData.deviceAddress = indexBufferAddress; VkAccelerationStructureBuildRangeInfoKHR& offset = blasData.asBuildOffsetInfo.emplace_back(); - offset.firstVertex = vertexInput.first; + offset.firstVertex = vertexInput.first; offset.primitiveCount = vertexInput.count / 3; offset.primitiveOffset = indexInput.first * indexInput.size; offset.transformOffset = 0; @@ -1334,7 +1334,7 @@ void ext::vulkan::Graphic::generateBottomAccelerationStructures() { triangles.indexData.deviceAddress = indexBufferAddress; VkAccelerationStructureBuildRangeInfoKHR& offset = blasData.asBuildOffsetInfo.emplace_back(); - offset.firstVertex = vertexInput.first; + offset.firstVertex = vertexInput.first; offset.primitiveCount = vertexInput.count / 3; offset.primitiveOffset = indexInput.first * indexInput.size; offset.transformOffset = 0; @@ -1715,7 +1715,7 @@ void ext::vulkan::Graphic::generateTopAccelerationStructure( const uf::stl::vect buildInfo.dstAccelerationStructure = tlas.handle; buildInfo.scratchData.deviceAddress = scratchBuffer.getAddress(); - VkAccelerationStructureBuildRangeInfoKHR buildOffsetInfo{countInstance, 0, 0, 0}; + VkAccelerationStructureBuildRangeInfoKHR buildOffsetInfo{countInstance, 0, 0, 0}; const VkAccelerationStructureBuildRangeInfoKHR* rangeInfo = &buildOffsetInfo; auto commandBuffer = device.fetchCommandBuffer(uf::renderer::QueueEnum::COMPUTE); diff --git a/engine/src/ext/vulkan/rendermodes/deferred.cpp b/engine/src/ext/vulkan/rendermodes/deferred.cpp index 5e7850ce..9896e211 100644 --- a/engine/src/ext/vulkan/rendermodes/deferred.cpp +++ b/engine/src/ext/vulkan/rendermodes/deferred.cpp @@ -329,15 +329,9 @@ void ext::vulkan::DeferredRenderMode::initialize( Device& device ) { shader.setDescriptorCounts({ { "samplerTextures", maxTextures2D }, { "samplerCubemaps", maxTexturesCube }, - { "voxelDrawId", maxCascades }, - { "voxelInstanceId", maxCascades }, - { "voxelNormalX", maxCascades }, - { "voxelNormalY", maxCascades }, - { "voxelRadianceR", maxCascades }, - { "voxelRadianceG", maxCascades }, - { "voxelRadianceB", maxCascades }, - { "voxelRadianceA", maxCascades }, - { "voxelCount", maxCascades }, + { "voxelId", maxCascades }, + { "voxelNormal", maxCascades }, + { "voxelRadiance", maxCascades }, { "voxelOutput", maxCascades }, }); diff --git a/engine/src/ext/vulkan/rendermodes/rendertarget.cpp b/engine/src/ext/vulkan/rendermodes/rendertarget.cpp index 5dccccb3..b09d4380 100644 --- a/engine/src/ext/vulkan/rendermodes/rendertarget.cpp +++ b/engine/src/ext/vulkan/rendermodes/rendertarget.cpp @@ -316,6 +316,7 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { {uf::io::resolveURI(fragmentShaderFilename), VK_SHADER_STAGE_FRAGMENT_BIT} }); } + if ( metadata.type == uf::renderer::settings::pipelines::names::vxgi ) { auto& shader = blitter.material.getShader("compute"); @@ -333,17 +334,21 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { shader.setDescriptorCounts({ { "samplerTextures", maxTextures2D }, { "samplerCubemaps", maxTexturesCube }, - { "voxelDrawId", maxCascades }, - { "voxelInstanceId", maxCascades }, - { "voxelNormalX", maxCascades }, - { "voxelNormalY", maxCascades }, - { "voxelRadianceR", maxCascades }, - { "voxelRadianceG", maxCascades }, - { "voxelRadianceB", maxCascades }, - { "voxelRadianceA", maxCascades }, - { "voxelCount", maxCascades }, + { "voxelId", maxCascades }, + { "voxelNormal", maxCascades }, + { "voxelRadiance", maxCascades }, { "voxelOutput", maxCascades }, }); + + auto& scene = uf::scene::getCurrentScene(); + auto& sceneTextures = scene.getComponent(); + + shader.textures.clear(); + + for ( auto& t : sceneTextures.voxels.id ) shader.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.normal ) shader.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.radiance ) shader.textures.emplace_back().aliasTexture(t); + for ( auto& t : sceneTextures.voxels.output ) shader.textures.emplace_back().aliasTexture(t); } else if ( metadata.type == uf::renderer::settings::pipelines::names::rt ) { #if 0 auto& shader = blitter.material.getShader("fragment"); diff --git a/engine/src/ext/vulkan/rendermodes/transition.inl b/engine/src/ext/vulkan/rendermodes/transition.inl index 90d8feae..34da3375 100644 --- a/engine/src/ext/vulkan/rendermodes/transition.inl +++ b/engine/src/ext/vulkan/rendermodes/transition.inl @@ -36,14 +36,14 @@ namespace { } if ( image == VK_NULL_HANDLE ) continue; subresourceRange.baseMipLevel = 0; - subresourceRange.levelCount = 1; + subresourceRange.levelCount = 1; subresourceRange.aspectMask = descriptor.name == "depth" ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; uf::renderer::Texture::setImageLayout( commandBuffer, image, layout, descriptor.layout, subresourceRange ); if ( mips > 1 ) { - subresourceRange.baseMipLevel = 1; - subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS; - uf::renderer::Texture::setImageLayout( commandBuffer, image, initialLayout, descriptor.layout, subresourceRange ); - } + subresourceRange.baseMipLevel = 1; + subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS; + uf::renderer::Texture::setImageLayout( commandBuffer, image, initialLayout, descriptor.layout, subresourceRange ); + } } } void transitionAttachmentsFrom( @@ -83,14 +83,14 @@ namespace { } if ( image == VK_NULL_HANDLE ) continue; subresourceRange.baseMipLevel = 0; - subresourceRange.levelCount = 1; + subresourceRange.levelCount = 1; subresourceRange.aspectMask = descriptor.name == "depth" ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; uf::renderer::Texture::setImageLayout( commandBuffer, image, descriptor.layout, layout, subresourceRange ); if ( mips > 1 ) { - subresourceRange.baseMipLevel = 1; - subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS; - uf::renderer::Texture::setImageLayout( commandBuffer, image, descriptor.layout, initialLayout, subresourceRange ); - } + subresourceRange.baseMipLevel = 1; + subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS; + uf::renderer::Texture::setImageLayout( commandBuffer, image, descriptor.layout, initialLayout, subresourceRange ); + } } } } \ No newline at end of file diff --git a/engine/src/ext/vulkan/texture.cpp b/engine/src/ext/vulkan/texture.cpp index 5e31f5ec..ce6c8d1d 100644 --- a/engine/src/ext/vulkan/texture.cpp +++ b/engine/src/ext/vulkan/texture.cpp @@ -371,35 +371,39 @@ void ext::vulkan::Texture::loadFromFile( const uf::stl::string& filename, VkFormat format, VkImageUsageFlags usage, - VkImageLayout layout + VkImageLayout layout, + VkImageCreateFlags flags ) { - return loadFromFile( filename, ext::vulkan::device, format, usage, layout ); + return loadFromFile( filename, ext::vulkan::device, format, usage, layout, flags ); } void ext::vulkan::Texture::loadFromFile( const uf::stl::string& filename, Device& device, VkFormat format, VkImageUsageFlags usage, - VkImageLayout layout + VkImageLayout layout, + VkImageCreateFlags flags ) { uf::Image image; image.open( filename ); - return loadFromImage( image, device, format, usage, layout ); + return loadFromImage( image, device, format, usage, layout, flags ); } void ext::vulkan::Texture::loadFromImage( const uf::Image& image, VkFormat format, VkImageUsageFlags usage, - VkImageLayout layout + VkImageLayout layout, + VkImageCreateFlags flags ) { - return loadFromImage( image, ext::vulkan::device, format, usage, layout ); + return loadFromImage( image, ext::vulkan::device, format, usage, layout, flags ); } void ext::vulkan::Texture::loadFromImage( const uf::Image& image, Device& device, VkFormat format, VkImageUsageFlags usage, - VkImageLayout layout + VkImageLayout layout, + VkImageCreateFlags flags ) { /* switch ( format ) { @@ -474,7 +478,8 @@ void ext::vulkan::Texture::loadFromImage( 1, device, usage, - layout + layout, + flags ); } @@ -487,9 +492,10 @@ void ext::vulkan::Texture::fromBuffers( uint32_t texDepth, uint32_t layers, VkImageUsageFlags usage, - VkImageLayout layout + VkImageLayout layout, + VkImageCreateFlags flags ) { - return this->fromBuffers( buffer, bufferSize, format, texWidth, texHeight, texDepth, layers, ext::vulkan::device, usage, layout ); + return this->fromBuffers( buffer, bufferSize, format, texWidth, texHeight, texDepth, layers, ext::vulkan::device, usage, layout, flags ); } @@ -503,11 +509,13 @@ void ext::vulkan::Texture::fromBuffers( uint32_t layers, Device& device, VkImageUsageFlags usage, - VkImageLayout layout + VkImageLayout layout, + VkImageCreateFlags flags ) { - this->initialize(device, texWidth, texHeight, texDepth, layers); - this->layout = VK_IMAGE_LAYOUT_UNDEFINED; + this->initialize( device, texWidth, texHeight, texDepth, layers ); this->usage = usage; + this->layout = VK_IMAGE_LAYOUT_UNDEFINED; + this->flags = flags; if ( this->mips == 0 ) { this->mips = 1; @@ -545,6 +553,7 @@ void ext::vulkan::Texture::fromBuffers( imageCreateInfo.initialLayout = this->layout; imageCreateInfo.extent = { width, height, depth }; imageCreateInfo.usage = this->usage; + imageCreateInfo.flags = this->flags; // Ensure that the TRANSFER_SRC bit is set for mip creation if ( this->mips > 1 && !(imageCreateInfo.usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT)) { imageCreateInfo.usage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; @@ -555,7 +564,7 @@ void ext::vulkan::Texture::fromBuffers( } // Ensure cube maps get the compat flag bit if ( this->viewType == ext::vulkan::enums::Image::VIEW_TYPE_CUBE || this->viewType == ext::vulkan::enums::Image::VIEW_TYPE_CUBE_ARRAY ) { - imageCreateInfo.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; + imageCreateInfo.flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; } VmaAllocationCreateInfo allocInfo = {}; @@ -955,8 +964,8 @@ void ext::vulkan::Texture::generateMipmaps( VkCommandBuffer commandBuffer, uint3 ); if (mipWidth > 1) mipWidth /= 2; - if (mipHeight > 1) mipHeight /= 2; - if (mipDepth > 1) mipDepth /= 2; + if (mipHeight > 1) mipHeight /= 2; + if (mipDepth > 1) mipDepth /= 2; } } diff --git a/engine/src/ext/xatlas/xatlas.cpp b/engine/src/ext/xatlas/xatlas.cpp index e3b3c6ba..a1a9125d 100644 --- a/engine/src/ext/xatlas/xatlas.cpp +++ b/engine/src/ext/xatlas/xatlas.cpp @@ -2,7 +2,7 @@ #if UF_USE_XATLAS #include -#define UF_XATLAS_UNWRAP_MULTITHREAD 1 // prone to crashing +#define UF_XATLAS_UNWRAP_MULTITHREAD 1 size_t ext::xatlas::unwrap( pod::Graph& graph ) { struct Entry { @@ -56,50 +56,49 @@ size_t ext::xatlas::unwrap( pod::Graph& graph ) { if ( !should ) continue; source = mesh; - source.updateDescriptor(); + source.updateDescriptor(); - for ( size_t viewIdx = 0; viewIdx < source.buffer_views.size(); ++viewIdx ) { - const auto& view = source.buffer_views[viewIdx]; + for ( size_t viewIdx = 0; viewIdx < source.buffer_views.size(); ++viewIdx ) { + const auto& view = source.buffer_views[viewIdx]; - size_t atlasID = 0; - if ( view.indirectIndex != -1 ) { - pod::DrawCommand* drawCommands = (pod::DrawCommand*) mesh.getBuffer(mesh.indirect).data(); - atlasID = drawCommands[view.indirectIndex].auxID; - } + size_t atlasID = 0; + if ( view.indirectIndex != -1 ) { + pod::DrawCommand* drawCommands = (pod::DrawCommand*) mesh.getBuffer(mesh.indirect).data(); + atlasID = drawCommands[view.indirectIndex].auxID; + } - auto& atlas = atlases[atlasID]; - auto& entry = atlas.entries.emplace_back(); - entry.index = index; - entry.commandID = viewIdx; + auto& atlas = atlases[atlasID]; + auto& entry = atlas.entries.emplace_back(); + entry.index = index; + entry.commandID = viewIdx; - auto& decl = entry.decl; - auto posView = view["position"]; - auto uvView = view["uv"]; - auto idxView = view["index"]; + auto& decl = entry.decl; + auto posView = view["position"]; + auto uvView = view["uv"]; + auto idxView = view["index"]; - UF_ASSERT( posView.valid() && uvView.valid() ); + UF_ASSERT( posView.valid() && uvView.valid() ); - decl.vertexCount = view.vertex.count; - decl.vertexPositionData = posView.data(view.vertex.first); - decl.vertexPositionStride = posView.stride(); - decl.vertexUvData = uvView.data(view.vertex.first); - decl.vertexUvStride = uvView.stride(); + decl.vertexCount = view.vertex.count; + decl.vertexPositionData = posView.data(view.vertex.first); + decl.vertexPositionStride = posView.stride(); + decl.vertexUvData = uvView.data(view.vertex.first); + decl.vertexUvStride = uvView.stride(); - if ( idxView.valid() ) { - decl.indexCount = view.index.count; - // Pass view.index.first to offset the index pointer! - decl.indexData = idxView.data(view.index.first); + if ( idxView.valid() ) { + decl.indexCount = view.index.count; + decl.indexData = idxView.data(view.index.first); - switch ( idxView.attribute.descriptor.size ) { - case 1: UF_EXCEPTION("xatlas does not support 8-bit indices"); break; - case 2: decl.indexFormat = ::xatlas::IndexFormat::UInt16; break; - case 4: decl.indexFormat = ::xatlas::IndexFormat::UInt32; break; - default: UF_EXCEPTION("unsupported index type"); break; - } - } else { - decl.indexCount = 0; - } - } + switch ( idxView.attribute.descriptor.size ) { + case 1: UF_EXCEPTION("xatlas does not support 8-bit indices"); break; + case 2: decl.indexFormat = ::xatlas::IndexFormat::UInt16; break; + case 4: decl.indexFormat = ::xatlas::IndexFormat::UInt32; break; + default: UF_EXCEPTION("unsupported index type"); break; + } + } else { + decl.indexCount = 0; + } + } } ::xatlas::ChartOptions chartOptions{}; @@ -236,70 +235,63 @@ size_t ext::xatlas::unwrap( pod::Graph& graph ) { // update vertices for ( auto& pair : atlases ) { - auto& atlas = pair.second; + auto& atlas = pair.second; - for ( auto i = 0; i < atlas.pointer->meshCount; i++ ) { - auto& xmesh = atlas.pointer->meshes[i]; - auto& entry = atlas.entries[i]; + for ( auto i = 0; i < atlas.pointer->meshCount; i++ ) { + auto& xmesh = atlas.pointer->meshes[i]; + auto& entry = atlas.entries[i]; - auto& name = graph.meshes[entry.index]; - auto& mesh = storage.meshes[name]; - auto& source = sources[entry.index]; + auto& name = graph.meshes[entry.index]; + auto& mesh = storage.meshes[name]; + auto& source = sources[entry.index]; - if ( source.vertex.count == 0 ) continue; + if ( source.vertex.count == 0 ) continue; - // Grab the read-only view from our unmodified source mesh - const auto& srcView = source.buffer_views[entry.commandID]; + const auto& srcView = source.buffer_views[entry.commandID]; - // We dynamically calculate the destination offsets using the updated draw commands - // Or if it's direct, it's just 0. - size_t dstVertexFirst = 0; - size_t dstIndexFirst = 0; - if ( mesh.indirect.count > 0 ) { - pod::DrawCommand* drawCommands = (pod::DrawCommand*) mesh.getBuffer(mesh.indirect).data(); - dstVertexFirst = drawCommands[entry.commandID].vertexID; - dstIndexFirst = drawCommands[entry.commandID].indexID; - } + size_t dstVertexFirst = 0; + size_t dstIndexFirst = 0; + if ( mesh.indirect.count > 0 ) { + pod::DrawCommand* drawCommands = (pod::DrawCommand*) mesh.getBuffer(mesh.indirect).data(); + dstVertexFirst = drawCommands[entry.commandID].vertexID; + dstIndexFirst = drawCommands[entry.commandID].indexID; + } - // 1. Copy over the vertices based on the xref mapping - for ( auto j = 0; j < xmesh.vertexCount; ++j ) { - auto& vertex = xmesh.vertexArray[j]; - uint32_t ref = vertex.xref; // original vertex index relative to the sub-mesh + for ( auto j = 0; j < xmesh.vertexCount; ++j ) { + auto& vertex = xmesh.vertexArray[j]; + uint32_t ref = vertex.xref; // original vertex index relative to the sub-mesh - for ( auto attrIdx = 0; attrIdx < mesh.vertex.attributes.size(); ++attrIdx ) { - auto srcAttribute = srcView.vertex.attributes[attrIdx]; - auto dstAttribute = mesh.vertex.attributes[attrIdx]; + for ( auto attrIdx = 0; attrIdx < mesh.vertex.attributes.size(); ++attrIdx ) { + auto srcAttribute = srcView.vertex.attributes[attrIdx]; + auto dstAttribute = mesh.vertex.attributes[attrIdx]; - uint8_t* dstPtr = static_cast(dstAttribute.pointer) + dstAttribute.stride * (dstVertexFirst + j); + uint8_t* dstPtr = static_cast(dstAttribute.pointer) + dstAttribute.stride * (dstVertexFirst + j); - if ( dstAttribute.descriptor.name == "st" ) { - // Write new lightmap STs! - pod::Vector2f& st = *(pod::Vector2f*)dstPtr; - st = pod::Vector2f{ vertex.uv[0] / atlas.pointer->width, vertex.uv[1] / atlas.pointer->height }; - } else { - // Copy original vertex data - const uint8_t* srcPtr = static_cast(srcAttribute.pointer) + srcAttribute.stride * (srcView.vertex.first + ref); - memcpy(dstPtr, srcPtr, srcAttribute.descriptor.size); - } - } - } + if ( dstAttribute.descriptor.name == "st" ) { + pod::Vector2f& st = *(pod::Vector2f*)dstPtr; + st = pod::Vector2f{ vertex.uv[0] / atlas.pointer->width, vertex.uv[1] / atlas.pointer->height }; + } else { + const uint8_t* srcPtr = static_cast(srcAttribute.pointer) + srcAttribute.stride * (srcView.vertex.first + ref); + memcpy(dstPtr, srcPtr, srcAttribute.descriptor.size); + } + } + } - // 2. Write new indices - if ( mesh.index.count ) { - uf::Mesh::Attribute indexAttribute = mesh.index.attributes.front(); - uint8_t* dstIndexPtr = static_cast(indexAttribute.pointer) + indexAttribute.stride * dstIndexFirst; + if ( mesh.index.count ) { + uf::Mesh::Attribute indexAttribute = mesh.index.attributes.front(); + uint8_t* dstIndexPtr = static_cast(indexAttribute.pointer) + indexAttribute.stride * dstIndexFirst; - for ( auto idx = 0; idx < xmesh.indexCount; ++idx ) { - switch ( mesh.index.size ) { - case 1: (( uint8_t*) dstIndexPtr)[idx] = (uint8_t) xmesh.indexArray[idx]; break; - case 2: ((uint16_t*) dstIndexPtr)[idx] = (uint16_t) xmesh.indexArray[idx]; break; - case 4: ((uint32_t*) dstIndexPtr)[idx] = (uint32_t) xmesh.indexArray[idx]; break; - } - } - } - mesh.updateDescriptor(); - } - } + for ( auto idx = 0; idx < xmesh.indexCount; ++idx ) { + switch ( mesh.index.size ) { + case 1: (( uint8_t*) dstIndexPtr)[idx] = (uint8_t) xmesh.indexArray[idx]; break; + case 2: ((uint16_t*) dstIndexPtr)[idx] = (uint16_t) xmesh.indexArray[idx]; break; + case 4: ((uint32_t*) dstIndexPtr)[idx] = (uint32_t) xmesh.indexArray[idx]; break; + } + } + } + mesh.updateDescriptor(); + } + } // cleanup size_t atlasCount = 0; diff --git a/engine/src/spec/window/linux.cpp b/engine/src/spec/window/linux.cpp index e15b24f4..4e747f4f 100644 --- a/engine/src/spec/window/linux.cpp +++ b/engine/src/spec/window/linux.cpp @@ -74,14 +74,14 @@ namespace { for (int i = 0; i < res->noutput; i++) { XRROutputInfo *output_info = - XRRGetOutputInfo(display, res, res->outputs[i]); + XRRGetOutputInfo(display, res, res->outputs[i]); if (!output_info || output_info->connection == RR_Disconnected) { if (output_info) XRRFreeOutputInfo(output_info); continue; } XRRCrtcInfo *crtc_info = - XRRGetCrtcInfo(display, res, output_info->crtc); + XRRGetCrtcInfo(display, res, output_info->crtc); if (!crtc_info) { XRRFreeOutputInfo(output_info); continue; @@ -168,22 +168,22 @@ namespace { } // namespace spec::x11::Window::Window() - : m_display(nullptr), - m_screen(0), - m_handle(0), - m_gc(0), - m_xim(nullptr), - m_xic(nullptr), - m_context(nullptr), - m_lastSize({}), - m_keyRepeatEnabled(true), - m_resizing(false), - m_mouseGrabbed(false), - m_syncParse(true), - m_asyncParse(false) {} + : m_display(nullptr), + m_screen(0), + m_handle(0), + m_gc(0), + m_xim(nullptr), + m_xic(nullptr), + m_context(nullptr), + m_lastSize({}), + m_keyRepeatEnabled(true), + m_resizing(false), + m_mouseGrabbed(false), + m_syncParse(true), + m_asyncParse(false) {} spec::x11::Window::Window(const vector_t &size, const title_t &title) - : Window() { + : Window() { create(size, title); } @@ -197,14 +197,14 @@ void spec::x11::Window::create(const vector_t &size, const title_t &title) { int dimH = size.y > 0 ? size.y : DisplayHeight(m_display, m_screen); m_handle = XCreateSimpleWindow( - m_display, RootWindow(m_display, m_screen), 0, 0, dimW, dimH, 1, - BlackPixel(m_display, m_screen), WhitePixel(m_display, m_screen)); + m_display, RootWindow(m_display, m_screen), 0, 0, dimW, dimH, 1, + BlackPixel(m_display, m_screen), WhitePixel(m_display, m_screen)); // Input events mask XSelectInput(m_display, m_handle, - ExposureMask | KeyPressMask | KeyReleaseMask | - ButtonPressMask | ButtonReleaseMask | PointerMotionMask | - StructureNotifyMask | FocusChangeMask); + ExposureMask | KeyPressMask | KeyReleaseMask | + ButtonPressMask | ButtonReleaseMask | PointerMotionMask | + StructureNotifyMask | FocusChangeMask); // Set Title setTitle(title); @@ -217,7 +217,7 @@ void spec::x11::Window::create(const vector_t &size, const title_t &title) { m_xim = XOpenIM(m_display, nullptr, nullptr, nullptr); } m_xic = XCreateIC(m_xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, - XNClientWindow, m_handle, XNFocusWindow, m_handle, NULL); + XNClientWindow, m_handle, XNFocusWindow, m_handle, NULL); Atom WM_DELETE_WINDOW = XInternAtom(m_display, "WM_DELETE_WINDOW", False); XSetWMProtocols(m_display, m_handle, &WM_DELETE_WINDOW, 1); @@ -260,7 +260,7 @@ spec::x11::Window::vector_t spec::x11::Window::getPosition() const { int x, y; ::Window child; XTranslateCoordinates(m_display, m_handle, RootWindow(m_display, m_screen), - 0, 0, &x, &y, &child); + 0, 0, &x, &y, &child); return {(unsigned)x, (unsigned)y}; } @@ -273,13 +273,13 @@ spec::x11::Window::vector_t spec::x11::Window::getSize() const { /* float spec::x11::Window::getDPIScale() const { - if (!m_display) return 1.0f; + if (!m_display) return 1.0f; - float dpi = getXftDPI(m_display); - if (dpi <= 0.0f) dpi = getRandRDPI(m_display, m_screen); - if (dpi <= 0.0f) dpi = 96.0f; + float dpi = getXftDPI(m_display); + if (dpi <= 0.0f) dpi = getRandRDPI(m_display, m_screen); + if (dpi <= 0.0f) dpi = 96.0f; - return dpi / 96.0f; // scale relative to Win32 baseline + return dpi / 96.0f; // scale relative to Win32 baseline } */ @@ -287,46 +287,46 @@ float spec::x11::Window::getDPIScale() const { size_t spec::x11::Window::getRefreshRate() const { return 60; /* - if (!m_display) return 60; // safe default + if (!m_display) return 60; // safe default - Window root = RootWindow(m_display, m_screen); + Window root = RootWindow(m_display, m_screen); - XRRScreenResources* res = XRRGetScreenResourcesCurrent(m_display, root); - if (!res) return 60; + XRRScreenResources* res = XRRGetScreenResourcesCurrent(m_display, root); + if (!res) return 60; - RROutput primary = XRRGetOutputPrimary(m_display, root); - if (primary == None && res->noutput > 0) - primary = res->outputs[0]; // fallback + RROutput primary = XRRGetOutputPrimary(m_display, root); + if (primary == None && res->noutput > 0) + primary = res->outputs[0]; // fallback - XRROutputInfo* output_info = XRRGetOutputInfo(m_display, res, primary); - if (!output_info) { - XRRFreeScreenResources(res); - return 60; - } + XRROutputInfo* output_info = XRRGetOutputInfo(m_display, res, primary); + if (!output_info) { + XRRFreeScreenResources(res); + return 60; + } - XRRCrtcInfo* crtc_info = XRRGetCrtcInfo(m_display, res, + XRRCrtcInfo* crtc_info = XRRGetCrtcInfo(m_display, res, output_info->crtc); - size_t refresh = 60; // default fallback - if (crtc_info) { - for (int i = 0; i < res->nmode; i++) { - XRRModeInfo& mode = res->modes[i]; - if (mode.id == crtc_info->mode) { - if (mode.hTotal > 0 && mode.vTotal > 0) { - double rate = (double)mode.dotClock / - ((double)mode.hTotal * + size_t refresh = 60; // default fallback + if (crtc_info) { + for (int i = 0; i < res->nmode; i++) { + XRRModeInfo& mode = res->modes[i]; + if (mode.id == crtc_info->mode) { + if (mode.hTotal > 0 && mode.vTotal > 0) { + double rate = (double)mode.dotClock / + ((double)mode.hTotal * (double)mode.vTotal); refresh = static_cast(std::round(rate)); - } - break; - } - } - XRRFreeCrtcInfo(crtc_info); - } + } + break; + } + } + XRRFreeCrtcInfo(crtc_info); + } - XRRFreeOutputInfo(output_info); - XRRFreeScreenResources(res); + XRRFreeOutputInfo(output_info); + XRRFreeScreenResources(res); - return refresh; + return refresh; */ } @@ -370,7 +370,7 @@ void spec::x11::Window::centerWindow() { MonitorInfo target = monitors[0]; for (auto &mon : monitors) { if (winCenterX >= mon.x && winCenterX < mon.x + mon.width && - winCenterY >= mon.y && winCenterY < mon.y + mon.height) { + winCenterY >= mon.y && winCenterY < mon.y + mon.height) { target = mon; break; } @@ -394,7 +394,7 @@ spec::x11::Window::vector_t spec::x11::Window::getMousePosition() { unsigned mask; ::Window child, root; XQueryPointer(m_display, m_handle, &root, &child, &root_x, &root_y, &win_x, - &win_y, &mask); + &win_y, &mask); return {(unsigned)win_x, (unsigned)win_y}; } @@ -407,26 +407,26 @@ void spec::x11::Window::setTitle(const title_t &title) { } /* void spec::x11::Window::setIcon(const vector_t&, uint8_t*) { - // Convert RGBA8 -> ARGB32 (unsigned long) - uf::stl::vector icon; - icon.resize(2 + size.x * size.y); - icon[0] = size.x; - icon[1] = size.y; + // Convert RGBA8 -> ARGB32 (unsigned long) + uf::stl::vector icon; + icon.resize(2 + size.x * size.y); + icon[0] = size.x; + icon[1] = size.y; - for (int i = 0; i < size.x * size.y; i++) { - unsigned char r = pixels[i*4+0]; - unsigned char g = pixels[i*4+1]; - unsigned char b = pixels[i*4+2]; - unsigned char a = pixels[i*4+3]; - unsigned long argb = ((unsigned long)a << 24) | - ((unsigned long)r << 16) | - ((unsigned long)g << 8) | - ((unsigned long)b); - icon[2+i] = argb; - } + for (int i = 0; i < size.x * size.y; i++) { + unsigned char r = pixels[i*4+0]; + unsigned char g = pixels[i*4+1]; + unsigned char b = pixels[i*4+2]; + unsigned char a = pixels[i*4+3]; + unsigned long argb = ((unsigned long)a << 24) | + ((unsigned long)r << 16) | + ((unsigned long)g << 8) | + ((unsigned long)b); + icon[2+i] = argb; + } - Atom property = XInternAtom(m_display, "_NET_WM_ICON", False); - XChangeProperty(m_display, m_handle, property, XA_CARDINAL, 32, + Atom property = XInternAtom(m_display, "_NET_WM_ICON", False); + XChangeProperty(m_display, m_handle, property, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)icon.data(), icon.size()); XFlush(m_display); } */ @@ -445,16 +445,16 @@ void spec::x11::Window::setIcon(const vector_t &size, uint8_t *pixels) { // Pack ARGB as required by X unsigned long argb = ((unsigned long)a << 24) | - ((unsigned long)r << 16) | - ((unsigned long)g << 8) | ((unsigned long)b); + ((unsigned long)r << 16) | + ((unsigned long)g << 8) | ((unsigned long)b); icon[2 + i] = argb; } Atom property = XInternAtom(m_display, "_NET_WM_ICON", False); XChangeProperty( - m_display, m_handle, property, XA_CARDINAL, 32, PropModeReplace, - reinterpret_cast(icon.data()), icon.size()); + m_display, m_handle, property, XA_CARDINAL, 32, PropModeReplace, + reinterpret_cast(icon.data()), icon.size()); XFlush(m_display); } void spec::x11::Window::setVisible(bool vis) { @@ -467,19 +467,19 @@ void spec::x11::Window::setVisible(bool vis) { /* void spec::x11::Window::setCursorVisible(bool vis) { - if (!vis) { - // hide cursor - Pixmap bm_no; - XColor black; memset(&black, 0, sizeof(black)); - char no_data[] = { 0 }; - bm_no = XCreateBitmapFromData(m_display, m_handle, no_data, 1, 1); - Cursor invisible = XCreatePixmapCursor(m_display, bm_no, bm_no, - &black, &black, 0, 0); - XDefineCursor(m_display, m_handle, invisible); - XFreeCursor(m_display, invisible); - } else { - XUndefineCursor(m_display, m_handle); - } + if (!vis) { + // hide cursor + Pixmap bm_no; + XColor black; memset(&black, 0, sizeof(black)); + char no_data[] = { 0 }; + bm_no = XCreateBitmapFromData(m_display, m_handle, no_data, 1, 1); + Cursor invisible = XCreatePixmapCursor(m_display, bm_no, bm_no, + &black, &black, 0, 0); + XDefineCursor(m_display, m_handle, invisible); + XFreeCursor(m_display, invisible); + } else { + XUndefineCursor(m_display, m_handle); + } } */ @@ -497,7 +497,7 @@ void spec::x11::Window::setCursorVisible(bool visibility) { dummy.red = dummy.green = dummy.blue = 0; Cursor invisible = - XCreatePixmapCursor(m_display, bm_no, bm_no, &dummy, &dummy, 0, 0); + XCreatePixmapCursor(m_display, bm_no, bm_no, &dummy, &dummy, 0, 0); XDefineCursor(m_display, m_handle, invisible); XFreeCursor(m_display, invisible); XFreePixmap(m_display, bm_no); @@ -509,31 +509,31 @@ void spec::x11::Window::setCursorVisible(bool visibility) { #include void spec::x11::Window::setCustomCursor(const vector_t& size, uint8_t* pixels) { - XcursorImage* img = XcursorImageCreate(size.x, size.y); - if (!img) return; + XcursorImage* img = XcursorImageCreate(size.x, size.y); + if (!img) return; - img->xhot = size.x / 2; // center hot spot - img->yhot = size.y / 2; + img->xhot = size.x / 2; // center hot spot + img->yhot = size.y / 2; - // Fill ARGB pixels - for (size_t i = 0; i < size.x * size.y; i++) { - uint8_t r = pixels[i * 4 + 0]; - uint8_t g = pixels[i * 4 + 1]; - uint8_t b = pixels[i * 4 + 2]; - uint8_t a = pixels[i * 4 + 3]; + // Fill ARGB pixels + for (size_t i = 0; i < size.x * size.y; i++) { + uint8_t r = pixels[i * 4 + 0]; + uint8_t g = pixels[i * 4 + 1]; + uint8_t b = pixels[i * 4 + 2]; + uint8_t a = pixels[i * 4 + 3]; - img->pixels[i] = ((unsigned long)a << 24) | - ((unsigned long)r << 16) | - ((unsigned long)g << 8) | - ((unsigned long)b); - } + img->pixels[i] = ((unsigned long)a << 24) | + ((unsigned long)r << 16) | + ((unsigned long)g << 8) | + ((unsigned long)b); + } - Cursor cursor = XcursorImageLoadCursor(m_display, img); - XcursorImageDestroy(img); + Cursor cursor = XcursorImageLoadCursor(m_display, img); + XcursorImageDestroy(img); - XDefineCursor(m_display, m_handle, cursor); - XFreeCursor(m_display, cursor); - XFlush(m_display); + XDefineCursor(m_display, m_handle, cursor); + XFreeCursor(m_display, cursor); + XFlush(m_display); } */ @@ -550,12 +550,12 @@ void spec::x11::Window::grabMouse(bool state) { if (state) { // Grab pointer: locks input focus to this window int result = XGrabPointer( - m_display, m_handle, - True, // owner_events - ButtonPressMask | ButtonReleaseMask | PointerMotionMask, - GrabModeAsync, GrabModeAsync, - m_handle, // confine to this window - None, CurrentTime); + m_display, m_handle, + True, // owner_events + ButtonPressMask | ButtonReleaseMask | PointerMotionMask, + GrabModeAsync, GrabModeAsync, + m_handle, // confine to this window + None, CurrentTime); if (result != GrabSuccess) { UF_MSG_ERROR("Failed to grab mouse pointer via XGrabPointer"); @@ -591,8 +591,8 @@ void spec::x11::Window::bufferInputs() { char keys[32]; XQueryKeymap(m_display, keys); -#define GET_KEYSTATE(SYMBOL) \ - (uf::Window::focused && \ +#define GET_KEYSTATE(SYMBOL) \ + (uf::Window::focused && \ (keys[XKeysymToKeycode(m_display, SYMBOL) >> 3] & \ (1 << (XKeysymToKeycode(m_display, SYMBOL) & 7)))) @@ -719,209 +719,209 @@ void spec::x11::Window::bufferInputs() { int rootX, rootY, winX, winY; unsigned int mask; XQueryPointer(m_display, m_handle, &root, &child, &rootX, &rootY, &winX, - &winY, &mask); + &winY, &mask); uf::inputs::kbm::states::Mouse1 = (mask & Button1Mask); // Left uf::inputs::kbm::states::Mouse2 = (mask & Button3Mask); // Right uf::inputs::kbm::states::Mouse3 = (mask & Button2Mask); // Middle uf::inputs::kbm::states::MouseWheel = - uf::Window::focused ? ::lastMouseWheel : 0; + uf::Window::focused ? ::lastMouseWheel : 0; ::lastMouseWheel = 0; } /* void spec::x11::Window::processEvents() { - uf::stl::string prettyName = NormalizeKeyName( KeySymToString( sym ) ); - while (XPending(m_display) > 0) { - XEvent ev; - XNextEvent(m_display, &ev); + uf::stl::string prettyName = NormalizeKeyName( KeySymToString( sym ) ); + while (XPending(m_display) > 0) { + XEvent ev; + XNextEvent(m_display, &ev); - switch (ev.type) { - case ConfigureNotify: { - vector_t newSize = { (unsigned)ev.xconfigure.width, + switch (ev.type) { + case ConfigureNotify: { + vector_t newSize = { (unsigned)ev.xconfigure.width, (unsigned)ev.xconfigure.height }; if (newSize != m_lastSize) { m_lastSize = newSize; pod::payloads::windowResized event { { "window:Resized", "os" }, { m_lastSize } - }; - this->pushEvent(event.type, event); - } - } break; + }; + this->pushEvent(event.type, event); + } + } break; - case DestroyNotify: { - pod::payloads::windowEvent event { "window:Closed", "os" }; - this->pushEvent(event.type, event); - this->terminate(); - } break; + case DestroyNotify: { + pod::payloads::windowEvent event { "window:Closed", "os" }; + this->pushEvent(event.type, event); + this->terminate(); + } break; - case FocusIn: { - pod::payloads::windowFocusedChanged event { - { "window:Focus.Changed", "os" }, - { 1 } // gained - }; - this->pushEvent(event.type, event); - } break; - case FocusOut: { - pod::payloads::windowFocusedChanged event { - { "window:Focus.Changed", "os" }, - { -1 } // lost - }; - this->pushEvent(event.type, event); - } break; + case FocusIn: { + pod::payloads::windowFocusedChanged event { + { "window:Focus.Changed", "os" }, + { 1 } // gained + }; + this->pushEvent(event.type, event); + } break; + case FocusOut: { + pod::payloads::windowFocusedChanged event { + { "window:Focus.Changed", "os" }, + { -1 } // lost + }; + this->pushEvent(event.type, event); + } break; - case KeyPress: { - KeySym sym; - char buffer[32]; - Status status; - int len = Xutf8LookupString(m_xic, &ev.xkey, buffer, + case KeyPress: { + KeySym sym; + char buffer[32]; + Status status; + int len = Xutf8LookupString(m_xic, &ev.xkey, buffer, sizeof(buffer)-1, &sym, &status); buffer[len] = '\0'; - // Key info - uf::stl::string keycode = KeySymToString(sym); + // Key info + uf::stl::string keycode = KeySymToString(sym); - pod::payloads::windowKey event{ - { "window:Key", "os" }, - { - keycode, - (unsigned long)sym, - -1, // pressed - false, - { - .alt = (ev.xkey.state & Mod1Mask), - .ctrl = (ev.xkey.state & ControlMask), - .shift= (ev.xkey.state & ShiftMask), - .sys = (ev.xkey.state & Mod4Mask) - } - } - }; - this->pushEvent(event.type, event); - this->pushEvent(event.type + "." + keycode, event); + pod::payloads::windowKey event{ + { "window:Key", "os" }, + { + keycode, + (unsigned long)sym, + -1, // pressed + false, + { + .alt = (ev.xkey.state & Mod1Mask), + .ctrl = (ev.xkey.state & ControlMask), + .shift= (ev.xkey.state & ShiftMask), + .sys = (ev.xkey.state & Mod4Mask) + } + } + }; + this->pushEvent(event.type, event); + this->pushEvent(event.type + "." + keycode, event); - // Text input (if UTF-8 char is present) - if (len > 0) { - uf::stl::string utf8(buffer); - pod::payloads::windowTextEntered textEvent{ - { "window:Text.Entered", "os" }, - { (uint32_t)utf8[0], utf8 } // simplistic, full UTF-32 + // Text input (if UTF-8 char is present) + if (len > 0) { + uf::stl::string utf8(buffer); + pod::payloads::windowTextEntered textEvent{ + { "window:Text.Entered", "os" }, + { (uint32_t)utf8[0], utf8 } // simplistic, full UTF-32 conversion recommended - }; - this->pushEvent(textEvent.type, textEvent); - } - } break; + }; + this->pushEvent(textEvent.type, textEvent); + } + } break; - case KeyRelease: { - KeySym sym = XLookupKeysym(&ev.xkey, 0); - uf::stl::string keycode = KeySymToString(sym); + case KeyRelease: { + KeySym sym = XLookupKeysym(&ev.xkey, 0); + uf::stl::string keycode = KeySymToString(sym); - pod::payloads::windowKey event{ - { "window:Key", "os" }, - { - keycode, - (unsigned long)sym, - 1, // released - false, - { - .alt = (ev.xkey.state & Mod1Mask), - .ctrl = (ev.xkey.state & ControlMask), - .shift= (ev.xkey.state & ShiftMask), - .sys = (ev.xkey.state & Mod4Mask) - } - } - }; - this->pushEvent(event.type, event); - this->pushEvent(event.type + "." + keycode, event); - } break; + pod::payloads::windowKey event{ + { "window:Key", "os" }, + { + keycode, + (unsigned long)sym, + 1, // released + false, + { + .alt = (ev.xkey.state & Mod1Mask), + .ctrl = (ev.xkey.state & ControlMask), + .shift= (ev.xkey.state & ShiftMask), + .sys = (ev.xkey.state & Mod4Mask) + } + } + }; + this->pushEvent(event.type, event); + this->pushEvent(event.type + "." + keycode, event); + } break; - case ButtonPress: { - pod::Vector2i pos = { ev.xbutton.x, ev.xbutton.y }; - int state = -1; - uf::stl::string button; + case ButtonPress: { + pod::Vector2i pos = { ev.xbutton.x, ev.xbutton.y }; + int state = -1; + uf::stl::string button; - switch (ev.xbutton.button) { - case 1: button = "Left"; break; - case 2: button = "Middle"; break; - case 3: button = "Right"; break; - case 8: // aux typical - case 9: button = "Aux"; break; - case 4: { // wheel up - pod::payloads::windowMouseWheel wheelEvent { - { "window:Mouse.Wheel", "os" }, - { { (unsigned)pos.x, (unsigned)pos.y }, +120 } - }; - this->pushEvent(wheelEvent.type, wheelEvent); - continue; - } - case 5: { // wheel down - pod::payloads::windowMouseWheel wheelEvent { - { "window:Mouse.Wheel", "os" }, - { { (unsigned)pos.x, (unsigned)pos.y }, -120 } - }; - this->pushEvent(wheelEvent.type, wheelEvent); - continue; - } - } + switch (ev.xbutton.button) { + case 1: button = "Left"; break; + case 2: button = "Middle"; break; + case 3: button = "Right"; break; + case 8: // aux typical + case 9: button = "Aux"; break; + case 4: { // wheel up + pod::payloads::windowMouseWheel wheelEvent { + { "window:Mouse.Wheel", "os" }, + { { (unsigned)pos.x, (unsigned)pos.y }, +120 } + }; + this->pushEvent(wheelEvent.type, wheelEvent); + continue; + } + case 5: { // wheel down + pod::payloads::windowMouseWheel wheelEvent { + { "window:Mouse.Wheel", "os" }, + { { (unsigned)pos.x, (unsigned)pos.y }, -120 } + }; + this->pushEvent(wheelEvent.type, wheelEvent); + continue; + } + } - pod::payloads::windowMouseClick event{ - { "window:Mouse.Click", "os" }, - { pos, {0,0}, button, state } - }; - this->pushEvent(event.type, event); - } break; + pod::payloads::windowMouseClick event{ + { "window:Mouse.Click", "os" }, + { pos, {0,0}, button, state } + }; + this->pushEvent(event.type, event); + } break; - case ButtonRelease: { - pod::Vector2i pos = { ev.xbutton.x, ev.xbutton.y }; - int state = 1; - uf::stl::string button; + case ButtonRelease: { + pod::Vector2i pos = { ev.xbutton.x, ev.xbutton.y }; + int state = 1; + uf::stl::string button; - switch (ev.xbutton.button) { - case 1: button = "Left"; break; - case 2: button = "Middle"; break; - case 3: button = "Right"; break; - case 8: - case 9: button = "Aux"; break; - } + switch (ev.xbutton.button) { + case 1: button = "Left"; break; + case 2: button = "Middle"; break; + case 3: button = "Right"; break; + case 8: + case 9: button = "Aux"; break; + } - pod::payloads::windowMouseClick event{ - { "window:Mouse.Click", "os" }, - { pos, {0,0}, button, state } - }; - this->pushEvent(event.type, event); - } break; - case MotionNotify: { - static pod::Vector2i lastPosition{}; - pod::Vector2i current = { ev.xmotion.x, ev.xmotion.y }; + pod::payloads::windowMouseClick event{ + { "window:Mouse.Click", "os" }, + { pos, {0,0}, button, state } + }; + this->pushEvent(event.type, event); + } break; + case MotionNotify: { + static pod::Vector2i lastPosition{}; + pod::Vector2i current = { ev.xmotion.x, ev.xmotion.y }; - // Hard clamp inside window bounds - auto winSize = getSize(); - bool clamped = false; - if (current.x < 0) { current.x = 0; clamped = true; } - if (current.y < 0) { current.y = 0; clamped = true; } - if (current.x >= (int)winSize.x) { current.x = winSize.x-1; + // Hard clamp inside window bounds + auto winSize = getSize(); + bool clamped = false; + if (current.x < 0) { current.x = 0; clamped = true; } + if (current.y < 0) { current.y = 0; clamped = true; } + if (current.x >= (int)winSize.x) { current.x = winSize.x-1; clamped = true; } if (current.y >= (int)winSize.y) { current.y = winSize.y-1; clamped = true; } - if (clamped) { - // Warp pointer back into client area - XWarpPointer(m_display, None, m_handle, 0,0,0,0, current.x, + if (clamped) { + // Warp pointer back into client area + XWarpPointer(m_display, None, m_handle, 0,0,0,0, current.x, current.y); XFlush(m_display); - } + } - // Fire payload as usual - pod::payloads::windowMouseMoved event { - { { "window:Mouse.Moved", "client" }, { winSize } }, - { current, current - lastPosition, 0 } - }; - this->pushEvent(event.type, event); + // Fire payload as usual + pod::payloads::windowMouseMoved event { + { { "window:Mouse.Moved", "client" }, { winSize } }, + { current, current - lastPosition, 0 } + }; + this->pushEvent(event.type, event); - lastPosition = current; - } break; - case ClientMessage: { - if ((Atom)ev.xclient.data.l[0] == XInternAtom(m_display, + lastPosition = current; + } break; + case ClientMessage: { + if ((Atom)ev.xclient.data.l[0] == XInternAtom(m_display, "WM_DELETE_WINDOW", False)) { pod::payloads::windowEvent event { "window:Closed", "os" }; this->pushEvent(event.type, event); this->terminate(); - } - } break; - } - } + } + } break; + } + } } */ void spec::x11::Window::processEvents() { @@ -932,11 +932,11 @@ void spec::x11::Window::processEvents() { switch (ev.type) { case ConfigureNotify: { vector_t newSize = {(unsigned)ev.xconfigure.width, - (unsigned)ev.xconfigure.height}; + (unsigned)ev.xconfigure.height}; if (newSize != m_lastSize) { m_lastSize = newSize; pod::payloads::windowResized event{{"window:Resized", "os"}, - {m_lastSize}}; + {m_lastSize}}; this->pushEvent(event.type, event); } else { pod::payloads::windowEvent moved{"window:Moved", "os"}; @@ -946,7 +946,7 @@ void spec::x11::Window::processEvents() { case ClientMessage: { Atom wmDelete = - XInternAtom(m_display, "WM_DELETE_WINDOW", False); + XInternAtom(m_display, "WM_DELETE_WINDOW", False); if ((Atom)ev.xclient.data.l[0] == wmDelete) { pod::payloads::windowEvent event{"window:Closed", "os"}; this->pushEvent(event.type, event); @@ -956,13 +956,13 @@ void spec::x11::Window::processEvents() { case FocusIn: { pod::payloads::windowFocusedChanged focusEvent{ - {"window:Focus.Changed", "os"}, {1}}; + {"window:Focus.Changed", "os"}, {1}}; this->pushEvent(focusEvent.type, focusEvent); } break; case FocusOut: { pod::payloads::windowFocusedChanged focusEvent{ - {"window:Focus.Changed", "os"}, {-1}}; + {"window:Focus.Changed", "os"}, {-1}}; this->pushEvent(focusEvent.type, focusEvent); } break; @@ -971,30 +971,30 @@ void spec::x11::Window::processEvents() { char buffer[32]; Status status; int len = Xutf8LookupString(m_xic, &ev.xkey, buffer, - sizeof(buffer) - 1, &sym, &status); + sizeof(buffer) - 1, &sym, &status); buffer[len] = '\0'; uf::stl::string keyName = NormalizeKeyName(KeySymToString(sym)); pod::payloads::windowKey keyEvent{ - {"window:Key", "os"}, - {keyName, - (unsigned long)sym, - -1, // pressed - false, - {.alt = (ev.xkey.state & Mod1Mask), - .ctrl = (ev.xkey.state & ControlMask), - .shift = (ev.xkey.state & ShiftMask), - .sys = (ev.xkey.state & Mod4Mask)}}}; + {"window:Key", "os"}, + {keyName, + (unsigned long)sym, + -1, // pressed + false, + {.alt = (ev.xkey.state & Mod1Mask), + .ctrl = (ev.xkey.state & ControlMask), + .shift = (ev.xkey.state & ShiftMask), + .sys = (ev.xkey.state & Mod4Mask)}}}; this->pushEvent(keyEvent.type, keyEvent); this->pushEvent(keyEvent.type + "." + keyName, keyEvent); if (len > 0) { uf::stl::string utf8(buffer); uint32_t codepoint = - (uint8_t)utf8[0]; // simple, but can be upgraded + (uint8_t)utf8[0]; // simple, but can be upgraded pod::payloads::windowTextEntered textEvent{ - {"window:Text.Entered", "os"}, {codepoint, utf8}}; + {"window:Text.Entered", "os"}, {codepoint, utf8}}; this->pushEvent(textEvent.type, textEvent); } } break; @@ -1004,15 +1004,15 @@ void spec::x11::Window::processEvents() { uf::stl::string keyName = NormalizeKeyName(KeySymToString(sym)); pod::payloads::windowKey keyEvent{ - {"window:Key", "os"}, - {keyName, - (unsigned long)sym, - 1, // released - false, - {.alt = (ev.xkey.state & Mod1Mask), - .ctrl = (ev.xkey.state & ControlMask), - .shift = (ev.xkey.state & ShiftMask), - .sys = (ev.xkey.state & Mod4Mask)}}}; + {"window:Key", "os"}, + {keyName, + (unsigned long)sym, + 1, // released + false, + {.alt = (ev.xkey.state & Mod1Mask), + .ctrl = (ev.xkey.state & ControlMask), + .shift = (ev.xkey.state & ShiftMask), + .sys = (ev.xkey.state & Mod4Mask)}}}; this->pushEvent(keyEvent.type, keyEvent); this->pushEvent(keyEvent.type + "." + keyName, keyEvent); } break; @@ -1022,17 +1022,17 @@ void spec::x11::Window::processEvents() { if (ev.xbutton.button == 4) { // wheel up pod::payloads::windowMouseWheel w{ - {"window:Mouse.Wheel", "os"}, - {{(unsigned)pos.x, (unsigned)pos.y}, - ::lastMouseWheel = +120}}; + {"window:Mouse.Wheel", "os"}, + {{(unsigned)pos.x, (unsigned)pos.y}, + ::lastMouseWheel = +120}}; this->pushEvent(w.type, w); break; } if (ev.xbutton.button == 5) { // wheel down pod::payloads::windowMouseWheel w{ - {"window:Mouse.Wheel", "os"}, - {{(unsigned)pos.x, (unsigned)pos.y}, - ::lastMouseWheel = -120}}; + {"window:Mouse.Wheel", "os"}, + {{(unsigned)pos.x, (unsigned)pos.y}, + ::lastMouseWheel = -120}}; this->pushEvent(w.type, w); break; } @@ -1043,7 +1043,7 @@ void spec::x11::Window::processEvents() { if (ev.xbutton.button == 3) button = "Right"; pod::payloads::windowMouseClick click{ - {"window:Mouse.Click", "os"}, {pos, {0, 0}, button, -1}}; + {"window:Mouse.Click", "os"}, {pos, {0, 0}, button, -1}}; this->pushEvent(click.type, click); } break; @@ -1055,7 +1055,7 @@ void spec::x11::Window::processEvents() { if (ev.xbutton.button == 3) button = "Right"; pod::payloads::windowMouseClick click{ - {"window:Mouse.Click", "os"}, {pos, {0, 0}, button, 1}}; + {"window:Mouse.Click", "os"}, {pos, {0, 0}, button, 1}}; this->pushEvent(click.type, click); } break; @@ -1064,8 +1064,8 @@ void spec::x11::Window::processEvents() { pod::Vector2i current = {ev.xmotion.x, ev.xmotion.y}; pod::payloads::windowMouseMoved move{ - {{"window:Mouse.Moved", "client"}, {getSize()}}, - {current, current - last, 0}}; + {{"window:Mouse.Moved", "client"}, {getSize()}}, + {current, current - last, 0}}; if ( current == last ) break; @@ -1080,10 +1080,10 @@ void spec::x11::Window::processEvents() { bool spec::x11::Window::pollEvents(bool block) { /* if (block) { - // Block until one event is received - XEvent ev; - XNextEvent(m_display, &ev); // this blocks - XPutBackEvent(m_display, &ev); // push back into event queue + // Block until one event is received + XEvent ev; + XNextEvent(m_display, &ev); // this blocks + XPutBackEvent(m_display, &ev); // push back into event queue } */ if (block && XPending(m_display) == 0) { @@ -1092,7 +1092,7 @@ bool spec::x11::Window::pollEvents(bool block) { FD_ZERO(&in_fds); FD_SET(fd, &in_fds); select(fd + 1, &in_fds, NULL, NULL, - NULL); // block until input available + NULL); // block until input available } // Process whatever is pending now @@ -1115,7 +1115,7 @@ pod::Vector2ui spec::x11::Window::getResolution() { auto monitors = getMonitors(m_display, m_screen); if (monitors.empty()) return {(unsigned)DisplayWidth(m_display, m_screen), - (unsigned)DisplayHeight(m_display, m_screen)}; + (unsigned)DisplayHeight(m_display, m_screen)}; // Use primary monitor for (auto &mon : monitors) { @@ -1128,32 +1128,32 @@ pod::Vector2ui spec::x11::Window::getResolution() { /* void spec::x11::Window::toggleFullscreen(bool borderless) { - Atom wm_state = XInternAtom(m_display, "_NET_WM_STATE", False); - Atom fullscreen = XInternAtom(m_display, "_NET_WM_STATE_FULLSCREEN", False); + Atom wm_state = XInternAtom(m_display, "_NET_WM_STATE", False); + Atom fullscreen = XInternAtom(m_display, "_NET_WM_STATE_FULLSCREEN", False); - XEvent xev{}; - xev.type = ClientMessage; - xev.xclient.window = m_handle; - xev.xclient.message_type = wm_state; - xev.xclient.format = 32; - xev.xclient.data.l[0] = 2; // _NET_WM_STATE_TOGGLE - xev.xclient.data.l[1] = fullscreen; - xev.xclient.data.l[2] = 0; // No second property - xev.xclient.data.l[3] = 1; // Source indication: application - xev.xclient.data.l[4] = 0; + XEvent xev{}; + xev.type = ClientMessage; + xev.xclient.window = m_handle; + xev.xclient.message_type = wm_state; + xev.xclient.format = 32; + xev.xclient.data.l[0] = 2; // _NET_WM_STATE_TOGGLE + xev.xclient.data.l[1] = fullscreen; + xev.xclient.data.l[2] = 0; // No second property + xev.xclient.data.l[3] = 1; // Source indication: application + xev.xclient.data.l[4] = 0; - XSendEvent(m_display, DefaultRootWindow(m_display), False, - SubstructureRedirectMask | SubstructureNotifyMask, &xev); - XFlush(m_display); + XSendEvent(m_display, DefaultRootWindow(m_display), False, + SubstructureRedirectMask | SubstructureNotifyMask, &xev); + XFlush(m_display); } */ void spec::x11::Window::toggleFullscreen(bool borderless) { Atom wmState = XInternAtom(m_display, "_NET_WM_STATE", False); Atom wmFullscreen = - XInternAtom(m_display, "_NET_WM_STATE_FULLSCREEN", False); + XInternAtom(m_display, "_NET_WM_STATE_FULLSCREEN", False); Atom wmMonitors = - XInternAtom(m_display, "_NET_WM_FULLSCREEN_MONITORS", False); + XInternAtom(m_display, "_NET_WM_FULLSCREEN_MONITORS", False); // Find the monitor where the window currently resides auto monitors = getMonitors(m_display, m_screen); @@ -1168,7 +1168,7 @@ void spec::x11::Window::toggleFullscreen(bool borderless) { for (size_t i = 0; i < monitors.size(); i++) { auto &mon = monitors[i]; if (winCenterX >= mon.x && winCenterX < mon.x + mon.width && - winCenterY >= mon.y && winCenterY < mon.y + mon.height) { + winCenterY >= mon.y && winCenterY < mon.y + mon.height) { // Select this monitor index top = bottom = left = right = i; break; @@ -1181,14 +1181,14 @@ void spec::x11::Window::toggleFullscreen(bool borderless) { monEvent.xclient.window = m_handle; monEvent.xclient.message_type = wmMonitors; monEvent.xclient.format = 32; - monEvent.xclient.data.l[0] = top; // top monitor index + monEvent.xclient.data.l[0] = top; // top monitor index monEvent.xclient.data.l[1] = bottom; // bottom monitor index - monEvent.xclient.data.l[2] = left; // left monitor index + monEvent.xclient.data.l[2] = left; // left monitor index monEvent.xclient.data.l[3] = right; // right monitor index monEvent.xclient.data.l[4] = 0; XSendEvent(m_display, DefaultRootWindow(m_display), False, - SubstructureRedirectMask | SubstructureNotifyMask, &monEvent); + SubstructureRedirectMask | SubstructureNotifyMask, &monEvent); // Toggle fullscreen XEvent ev{}; @@ -1203,7 +1203,7 @@ void spec::x11::Window::toggleFullscreen(bool borderless) { ev.xclient.data.l[4] = 0; XSendEvent(m_display, DefaultRootWindow(m_display), False, - SubstructureRedirectMask | SubstructureNotifyMask, &ev); + SubstructureRedirectMask | SubstructureNotifyMask, &ev); if (borderless) { Atom wmHints = XInternAtom(m_display, "_MOTIF_WM_HINTS", True); @@ -1217,10 +1217,10 @@ void spec::x11::Window::toggleFullscreen(bool borderless) { }; MotifHints hints; - hints.flags = 2; // Decorations + hints.flags = 2; // Decorations hints.decorations = 0; // No borders/title XChangeProperty(m_display, m_handle, wmHints, wmHints, 32, - PropModeReplace, (unsigned char *)&hints, 5); + PropModeReplace, (unsigned char *)&hints, 5); } } @@ -1244,33 +1244,33 @@ void spec::x11::Window::display() { #if UF_USE_OPENGL void spec::x11::Window::createGLContext() { - static int visualAttribs[] = { - GLX_RGBA, - GLX_DOUBLEBUFFER, - GLX_DEPTH_SIZE, 24, - GLX_STENCIL_SIZE, 8, - None - }; + static int visualAttribs[] = { + GLX_RGBA, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 24, + GLX_STENCIL_SIZE, 8, + None + }; - int screen = DefaultScreen(m_display); - XVisualInfo* vi = glXChooseVisual(m_display, screen, visualAttribs); - if (!vi) { - UF_EXCEPTION("Failed to choose X11 GLX visual"); - } + int screen = DefaultScreen(m_display); + XVisualInfo* vi = glXChooseVisual(m_display, screen, visualAttribs); + if (!vi) { + UF_EXCEPTION("Failed to choose X11 GLX visual"); + } - GLXContext ctx = glXCreateContext(m_display, vi, NULL, GL_TRUE); - if (!ctx) { - UF_EXCEPTION("Failed to create GLX context"); - } + GLXContext ctx = glXCreateContext(m_display, vi, NULL, GL_TRUE); + if (!ctx) { + UF_EXCEPTION("Failed to create GLX context"); + } - glXMakeCurrent(m_display, m_handle, ctx); - this->m_context = ctx; + glXMakeCurrent(m_display, m_handle, ctx); + this->m_context = ctx; } void spec::x11::Window::display() { - if (m_context) { - glXSwapBuffers(m_display, m_handle); - } + if (m_context) { + glXSwapBuffers(m_display, m_handle); + } } #endif @@ -1278,22 +1278,22 @@ void spec::x11::Window::display() { #if UF_USE_VULKAN uf::stl::vector spec::x11::Window::getExtensions( - bool validationEnabled) { + bool validationEnabled) { uf::stl::vector exts = { - VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME}; + VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME}; if (validationEnabled) exts.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); return exts; } void spec::x11::Window::createSurface(VkInstance instance, - VkSurfaceKHR &surface) { + VkSurfaceKHR &surface) { VkXlibSurfaceCreateInfoKHR info{}; info.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR; info.dpy = m_display; info.window = m_handle; VkResult result = - vkCreateXlibSurfaceKHR(instance, &info, nullptr, &surface); + vkCreateXlibSurfaceKHR(instance, &info, nullptr, &surface); if (result != VK_SUCCESS) { UF_EXCEPTION("Failed to create Xlib Vulkan surface"); } diff --git a/engine/src/spec/window/windows.cpp b/engine/src/spec/window/windows.cpp index c856b033..29f1b739 100644 --- a/engine/src/spec/window/windows.cpp +++ b/engine/src/spec/window/windows.cpp @@ -57,10 +57,10 @@ namespace { } } LRESULT CALLBACK globalOnEvent(spec::win32::Window::handle_t handle, UINT message, WPARAM wParam, LPARAM lParam) { - #if UF_USE_IMGUI + #if UF_USE_IMGUI if (ImGui_ImplWin32_WndProcHandler(handle, message, wParam, lParam)) - return true; - #endif + return true; + #endif if (message == WM_CREATE) { LONG_PTR window = (LONG_PTR)reinterpret_cast(lParam)->lpCreateParams; SetWindowLongPtrW(handle, GWLP_USERDATA, window); diff --git a/engine/src/utils/http/http.cpp b/engine/src/utils/http/http.cpp index 3846c89b..ed6b6bcd 100644 --- a/engine/src/utils/http/http.cpp +++ b/engine/src/utils/http/http.cpp @@ -6,8 +6,8 @@ namespace { size_t writeFunction(void *ptr, size_t size, size_t nmemb, uf::stl::string* data) { - data->append((char*) ptr, size * nmemb); - return size * nmemb; + data->append((char*) ptr, size * nmemb); + return size * nmemb; } } @@ -39,5 +39,5 @@ uf::Http uf::http::get( const uf::stl::string& url ) { curl_easy_cleanup(curl); curl = NULL; #endif - return http; + return http; } \ No newline at end of file diff --git a/engine/src/utils/io/file.cpp b/engine/src/utils/io/file.cpp index 84d0e9d3..b8d14d37 100644 --- a/engine/src/utils/io/file.cpp +++ b/engine/src/utils/io/file.cpp @@ -190,11 +190,11 @@ uf::stl::vector& uf::io::readAsBuffer( uf::stl::vector& buffer // Read each range size_t currentOffset = 0; - for (const auto& r : ranges) { - is.seekg(r.start, std::ios::beg); - is.read(reinterpret_cast(buffer.data() + currentOffset), r.len); - currentOffset += static_cast(is.gcount()); - } + for (const auto& r : ranges) { + is.seekg(r.start, std::ios::beg); + is.read(reinterpret_cast(buffer.data() + currentOffset), r.len); + currentOffset += static_cast(is.gcount()); + } } uf::stl::string expected; diff --git a/engine/src/utils/math/quant.cpp b/engine/src/utils/math/quant.cpp index 2235dc81..cdd2d561 100644 --- a/engine/src/utils/math/quant.cpp +++ b/engine/src/utils/math/quant.cpp @@ -3,18 +3,18 @@ // credit: https://github.com/zeux/meshoptimizer/blob/master/src/quantization.cpp uint16_t UF_API uf::quant::quantize_f32u16( float v ) { union { float f; uint32_t ui; } u = {v}; - uint32_t ui = u.ui; + uint32_t ui = u.ui; - int s = (ui >> 16) & 0x8000; - int em = ui & 0x7fffffff; + int s = (ui >> 16) & 0x8000; + int em = ui & 0x7fffffff; - int h = (em - (112 << 23) + (1 << 12)) >> 13; - h = (em < (113 << 23)) ? 0 : h; - h = (em >= (143 << 23)) ? 0x7c00 : h; - h = (em > (255 << 23)) ? 0x7e00 : h; + int h = (em - (112 << 23) + (1 << 12)) >> 13; + h = (em < (113 << 23)) ? 0 : h; + h = (em >= (143 << 23)) ? 0x7c00 : h; + h = (em > (255 << 23)) ? 0x7e00 : h; - uint16_t res = (s | h); - return res; + uint16_t res = (s | h); + return res; } float UF_API uf::quant::dequantize_u16f32( uint16_t h ) { uint32_t s = unsigned(h & 0x8000) << 16; diff --git a/engine/src/utils/string/base64.cpp b/engine/src/utils/string/base64.cpp index b7e30b1a..bf7ca4a7 100644 --- a/engine/src/utils/string/base64.cpp +++ b/engine/src/utils/string/base64.cpp @@ -10,78 +10,78 @@ static const int B64index[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 }; static const uint8_t base64_table[65] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; uf::stl::string uf::base64::encode( const uint8_t* src, size_t len ) { - uint8_t *out, *pos; - const uint8_t *end, *in; + uint8_t *out, *pos; + const uint8_t *end, *in; - size_t olen; + size_t olen; - olen = 4*((len + 2) / 3); + olen = 4*((len + 2) / 3); - if (olen < len) - return uf::stl::string(); + if (olen < len) + return uf::stl::string(); - uf::stl::string outStr; - outStr.resize(olen); - out = (uint8_t*)&outStr[0]; + uf::stl::string outStr; + outStr.resize(olen); + out = (uint8_t*)&outStr[0]; - end = src + len; - in = src; - pos = out; - while (end - in >= 3) { - *pos++ = base64_table[in[0] >> 2]; - *pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)]; - *pos++ = base64_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)]; - *pos++ = base64_table[in[2] & 0x3f]; - in += 3; - } + end = src + len; + in = src; + pos = out; + while (end - in >= 3) { + *pos++ = base64_table[in[0] >> 2]; + *pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)]; + *pos++ = base64_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)]; + *pos++ = base64_table[in[2] & 0x3f]; + in += 3; + } - if (end - in) { - *pos++ = base64_table[in[0] >> 2]; - if (end - in == 1) { - *pos++ = base64_table[(in[0] & 0x03) << 4]; - *pos++ = '='; - } - else { - *pos++ = base64_table[((in[0] & 0x03) << 4) | - (in[1] >> 4)]; - *pos++ = base64_table[(in[1] & 0x0f) << 2]; - } - *pos++ = '='; - } + if (end - in) { + *pos++ = base64_table[in[0] >> 2]; + if (end - in == 1) { + *pos++ = base64_table[(in[0] & 0x03) << 4]; + *pos++ = '='; + } + else { + *pos++ = base64_table[((in[0] & 0x03) << 4) | + (in[1] >> 4)]; + *pos++ = base64_table[(in[1] & 0x0f) << 2]; + } + *pos++ = '='; + } - return outStr; + return outStr; } // uf::stl::vector uf::base64::decode( const uint8_t* data, size_t len ) { uf::stl::vector uf::base64::decode( const uf::stl::string& data ) { size_t len = data.size(); - uint8_t* p = (uint8_t*) &data[0]; - int pad = len > 0 && (len % 4 || p[len - 1] == '='); - const size_t L = ((len + 3) / 4 - pad) * 4; - uf::stl::vector str(L / 4 * 3 + pad, '\0'); + uint8_t* p = (uint8_t*) &data[0]; + int pad = len > 0 && (len % 4 || p[len - 1] == '='); + const size_t L = ((len + 3) / 4 - pad) * 4; + uf::stl::vector str(L / 4 * 3 + pad, '\0'); - for (size_t i = 0, j = 0; i < L; i += 4) - { - int n = B64index[p[i]] << 18 | B64index[p[i + 1]] << 12 | B64index[p[i + 2]] << 6 | B64index[p[i + 3]]; - str[j++] = n >> 16; - str[j++] = n >> 8 & 0xFF; - str[j++] = n & 0xFF; - } - if (pad) - { - int n = B64index[p[L]] << 18 | B64index[p[L + 1]] << 12; - str[str.size() - 1] = n >> 16; + for (size_t i = 0, j = 0; i < L; i += 4) + { + int n = B64index[p[i]] << 18 | B64index[p[i + 1]] << 12 | B64index[p[i + 2]] << 6 | B64index[p[i + 3]]; + str[j++] = n >> 16; + str[j++] = n >> 8 & 0xFF; + str[j++] = n & 0xFF; + } + if (pad) + { + int n = B64index[p[L]] << 18 | B64index[p[L + 1]] << 12; + str[str.size() - 1] = n >> 16; - if (len > L + 2 && p[L + 2] != '=') - { - n |= B64index[p[L + 2]] << 6; - str.push_back(n >> 8 & 0xFF); - } - } - return str; + if (len > L + 2 && p[L + 2] != '=') + { + n |= B64index[p[L + 2]] << 6; + str.push_back(n >> 8 & 0xFF); + } + } + return str; } uf::stl::string uf::string::base64::encode( const uf::stl::string& input ) { @@ -95,9 +95,9 @@ uf::stl::string uf::string::base64::decode( const uf::stl::string& input ) { /* static const uf::stl::string base64_chars = - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/"; + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; static inline bool is_base64(uint8_t c) { @@ -112,34 +112,34 @@ uf::stl::string uf::base64::encode(const uint8_t* buf, std::size_t bufLen) { uint8_t char_array_4[4]; while (bufLen--) { - char_array_3[i++] = *(buf++); - if (i == 3) { - char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; - char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); - char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); - char_array_4[3] = char_array_3[2] & 0x3f; + char_array_3[i++] = *(buf++); + if (i == 3) { + char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; + char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); + char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); + char_array_4[3] = char_array_3[2] & 0x3f; - for(i = 0; (i <4) ; i++) - ret += base64_chars[char_array_4[i]]; - i = 0; - } + for(i = 0; (i <4) ; i++) + ret += base64_chars[char_array_4[i]]; + i = 0; + } } if (i) { - for(j = i; j < 3; j++) - char_array_3[j] = '\0'; + for(j = i; j < 3; j++) + char_array_3[j] = '\0'; - char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; - char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); - char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); - char_array_4[3] = char_array_3[2] & 0x3f; + char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; + char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); + char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); + char_array_4[3] = char_array_3[2] & 0x3f; - for (j = 0; (j < i + 1); j++) - ret += base64_chars[char_array_4[j]]; + for (j = 0; (j < i + 1); j++) + ret += base64_chars[char_array_4[j]]; - while((i++ < 3)) - ret += '='; + while((i++ < 3)) + ret += '='; } return ret; @@ -154,33 +154,33 @@ uf::stl::vector uf::base64::decode(const uf::stl::string& encoded_strin uf::stl::vector ret; while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) { - char_array_4[i++] = encoded_string[in_]; in_++; - if (i ==4) { - for (i = 0; i <4; i++) - char_array_4[i] = base64_chars.find(char_array_4[i]); + char_array_4[i++] = encoded_string[in_]; in_++; + if (i ==4) { + for (i = 0; i <4; i++) + char_array_4[i] = base64_chars.find(char_array_4[i]); - char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); - char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); - char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; + char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); + char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); + char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; - for (i = 0; (i < 3); i++) - ret.push_back(char_array_3[i]); - i = 0; - } + for (i = 0; (i < 3); i++) + ret.push_back(char_array_3[i]); + i = 0; + } } if (i) { - for (j = i; j <4; j++) - char_array_4[j] = 0; + for (j = i; j <4; j++) + char_array_4[j] = 0; - for (j = 0; j <4; j++) - char_array_4[j] = base64_chars.find(char_array_4[j]); + for (j = 0; j <4; j++) + char_array_4[j] = base64_chars.find(char_array_4[j]); - char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); - char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); - char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; + char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); + char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); + char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; - for (j = 0; (j < i - 1); j++) ret.push_back(char_array_3[j]); + for (j = 0; (j < i - 1); j++) ret.push_back(char_array_3[j]); } return ret; diff --git a/engine/src/utils/type/type.cpp b/engine/src/utils/type/type.cpp index daa8aa66..4f1c6920 100644 --- a/engine/src/utils/type/type.cpp +++ b/engine/src/utils/type/type.cpp @@ -9,10 +9,10 @@ namespace { int status = -4; std::unique_ptr demangled{ - abi::__cxa_demangle(mangled.c_str(), NULL, NULL, &status), - std::free - }; - return ( status == 0 ) ? demangled.get() : mangled; + abi::__cxa_demangle(mangled.c_str(), NULL, NULL, &status), + std::free + }; + return ( status == 0 ) ? demangled.get() : mangled; /* int status; char* pointer = abi::__cxa_demangle(mangled.c_str(), 0, 0, &status);