| 419 | } |
| 420 | |
| 421 | VertexBuffer const * ResourceHandler::createQuadTriVertexBuffer( GraphContext & context |
| 422 | , std::string const & suffix |
| 423 | , bool texCoords |
| 424 | , Texcoord const & config ) |
| 425 | { |
| 426 | VertexBuffer * vertexBuffer{}; |
| 427 | lock_type lock( m_vertexBuffersMutex ); |
| 428 | |
| 429 | if ( context.vkCreateBuffer ) |
| 430 | { |
| 431 | auto bufferId = createBufferId( BufferData{ "QuadVertexMemory_" + suffix |
| 432 | , BufferCreateFlags::eNone |
| 433 | , 3u * sizeof( reshdl::Quad::Vertex ) |
| 434 | , BufferUsageFlags::eVertexBuffer |
| 435 | , MemoryPropertyFlags::eHostVisible } ); |
| 436 | auto result = std::make_unique< VertexBuffer >( createViewId( BufferViewData{ "QuadVertexMemory_" + suffix |
| 437 | , bufferId |
| 438 | , { 0u, bufferId.data->info.size } } ) ); |
| 439 | vertexBuffer = result.get(); |
| 440 | |
| 441 | if ( context.device ) |
| 442 | { |
| 443 | auto created = createBuffer( context, vertexBuffer->buffer.data->buffer ); |
| 444 | reshdl::Quad::Vertex * buffer{}; |
| 445 | auto res = context.vkMapMemory( context.device |
| 446 | , created.memory |
| 447 | , 0u |
| 448 | , VK_WHOLE_SIZE |
| 449 | , 0u |
| 450 | , reinterpret_cast< void ** >( &buffer ) ); |
| 451 | checkVkResult( res, "Buffer memory mapping" ); |
| 452 | |
| 453 | if ( buffer ) |
| 454 | { |
| 455 | auto rangeU = 1.0; |
| 456 | auto minU = 0.0; |
| 457 | auto maxU = minU + 2.0 * rangeU; |
| 458 | auto rangeV = 1.0; |
| 459 | auto minV = -rangeV; |
| 460 | auto maxV = minV + 2.0 * rangeV; |
| 461 | auto realMinU = float( config.invertU ? maxU : minU ); |
| 462 | auto realMaxU = float( config.invertU ? minU : maxU ); |
| 463 | auto realMinV = float( config.invertV ? maxV : minV ); |
| 464 | auto realMaxV = float( config.invertV ? minV : maxV ); |
| 465 | std::array<reshdl::Quad::Vertex, 3u > vertexData |
| 466 | { reshdl::Quad::Vertex{ reshdl::Quad::Data{ -1.0f, -3.0f }, reshdl::Quad::Data{ realMinU, realMinV } } |
| 467 | , reshdl::Quad::Vertex{ reshdl::Quad::Data{ -1.0f, +1.0f }, reshdl::Quad::Data{ realMinU, realMaxV } } |
| 468 | , reshdl::Quad::Vertex{ reshdl::Quad::Data{ +3.0f, +1.0f }, reshdl::Quad::Data{ realMaxU, realMaxV } } }; |
| 469 | std::copy( vertexData.begin(), vertexData.end(), buffer ); |
| 470 | |
| 471 | VkMappedMemoryRange memoryRange{ VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE |
| 472 | , nullptr |
| 473 | , created.memory |
| 474 | , 0u |
| 475 | , VK_WHOLE_SIZE }; |
| 476 | context.vkFlushMappedMemoryRanges( context.device, 1u, &memoryRange ); |
| 477 | context.vkUnmapMemory( context.device, created.memory ); |
| 478 | } |