Changeset 27138

Timestamp:
Oct 9, 2022, 2:21:26 PM (22 months ago)
Author:
Vladislav Belov
Message:

Reduces the number of SetVertexAttributeFormat calls in Canvas2D.

Location:
ps/trunk/source/graphics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/graphics/Canvas2D.cpp

    r27136 r27138  
    6868    deviceCommandContext->SetUniform(bindingSlots.grayscaleFactor, grayscaleFactor);
    6969
    70     deviceCommandContext->SetVertexAttributeFormat(
    71         Renderer::Backend::VertexAttributeStream::POSITION,
    72         Renderer::Backend::Format::R32G32_SFLOAT, 0, sizeof(float) * 2,
    73         Renderer::Backend::VertexAttributeRate::PER_VERTEX, 0);
    74     deviceCommandContext->SetVertexAttributeFormat(
    75         Renderer::Backend::VertexAttributeStream::UV0,
    76         Renderer::Backend::Format::R32G32_SFLOAT, 0, sizeof(float) * 2,
    77         Renderer::Backend::VertexAttributeRate::PER_VERTEX, 1);
    78 
    7970    deviceCommandContext->SetVertexBufferData(
    8071        0, vertices.data(), vertices.size() * sizeof(vertices[0]));
     
    127118        DeviceCommandContext->SetUniform(
    128119            BindingSlots.translation, Translation.AsFloatArray());
     120
     121
     122
     123
     124
     125
     126
     127
     128
    129129    }
    130130
     
    327327        m->BindingSlots.grayscaleFactor, 0.0f);
    328328
    329     m->DeviceCommandContext->SetVertexAttributeFormat(
    330         Renderer::Backend::VertexAttributeStream::POSITION,
    331         Renderer::Backend::Format::R32G32_SFLOAT, 0, 0,
    332         Renderer::Backend::VertexAttributeRate::PER_VERTEX, 0);
    333     m->DeviceCommandContext->SetVertexAttributeFormat(
    334         Renderer::Backend::VertexAttributeStream::UV0,
    335         Renderer::Backend::Format::R32G32_SFLOAT, 0, 0,
    336         Renderer::Backend::VertexAttributeRate::PER_VERTEX, 1);
    337 
    338329    m->DeviceCommandContext->SetVertexBufferData(0, vertices.data(), vertices.size() * sizeof(vertices[0]));
    339330    m->DeviceCommandContext->SetVertexBufferData(1, uvs.data(), uvs.size() * sizeof(uvs[0]));
  • ps/trunk/source/graphics/TextRenderer.cpp

    r27136 r27138  
    183183}
    184184
    185 
    186 struct t2f_v2i
    187 {
    188     t2f_v2i() : u(0), v(0), x(0), y(0) { }
    189     float u, v;
    190     i16 x, y;
    191 };
    192 
    193185struct SBatchCompare
    194186{
     
    207199    const CVector2D& transformScale, const CVector2D& translation)
    208200{
    209     std::vector<u16> indexes;
    210     std::vector<t2f_v2i> vertexes;
     201    std::vector<u16> indices;
     202    std::vector<CVector2D> positions;
     203    std::vector<CVector2D> uvs;
    211204
    212205    // Try to merge non-consecutive batches that share the same font/color/translate:
     
    264257        deviceCommandContext->SetUniform(colorMulBindingSlot, batch.color.AsFloatArray());
    265258
    266         vertexes.resize(std::min(MAX_CHAR_COUNT_PER_BATCH, batch.chars) * 4);
    267         indexes.resize(std::min(MAX_CHAR_COUNT_PER_BATCH, batch.chars) * 6);
     259        positions.resize(std::min(MAX_CHAR_COUNT_PER_BATCH, batch.chars) * 4);
     260        uvs.resize(std::min(MAX_CHAR_COUNT_PER_BATCH, batch.chars) * 4);
     261        indices.resize(std::min(MAX_CHAR_COUNT_PER_BATCH, batch.chars) * 6);
    268262
    269263        size_t idx = 0;
    270264
    271         auto flush = [deviceCommandContext, &idx, &vertexes, &indexes]() -> void
     265        auto flush = [deviceCommandContext, &idx, &es]() -> void
    272266        {
    273267            if (idx == 0)
    274268                return;
    275269
    276             const uint32_t stride = sizeof(t2f_v2i);
    277 
    278             deviceCommandContext->SetVertexAttributeFormat(
    279                 Renderer::Backend::VertexAttributeStream::POSITION,
    280                 Renderer::Backend::Format::R16G16_SINT, offsetof(t2f_v2i, x), stride,
    281                 Renderer::Backend::VertexAttributeRate::PER_VERTEX, 0);
    282             deviceCommandContext->SetVertexAttributeFormat(
    283                 Renderer::Backend::VertexAttributeStream::UV0,
    284                 Renderer::Backend::Format::R32G32_SFLOAT, offsetof(t2f_v2i, u), stride,
    285                 Renderer::Backend::VertexAttributeRate::PER_VERTEX, 0);
    286 
    287270            deviceCommandContext->SetVertexBufferData(
    288                 0, vertexes.data(), vertexes.size() * sizeof(vertexes[0]));
    289             deviceCommandContext->SetIndexBufferData(indexes.data(), indexes.size() * sizeof(indexes[0]));
     271                0, positions.data(), positions.size() * sizeof(positions[0]));
     272            deviceCommandContext->SetVertexBufferData(
     273                1, uvs.data(), uvs.size() * sizeof(uvs[0]));
     274            deviceCommandContext->SetIndexBufferData(
     275                indices.data(), indices.size() * sizeof(indices[0]));
    290276
    291277            deviceCommandContext->DrawIndexed(0, idx * 6, 0);
     
    307293                    continue;
    308294
    309                 vertexes[idx*4].u = g->u1;
    310                 vertexes[idx*4].v = g->v0;
    311                 vertexes[idx*4].x = g->x1 + x;
    312                 vertexes[idx*4].y = g->y0 + y;
    313 
    314                 vertexes[idx*4+1].u = g->u0;
    315                 vertexes[idx*4+1].v = g->v0;
    316                 vertexes[idx*4+1].x = g->x0 + x;
    317                 vertexes[idx*4+1].y = g->y0 + y;
    318 
    319                 vertexes[idx*4+2].u = g->u0;
    320                 vertexes[idx*4+2].v = g->v1;
    321                 vertexes[idx*4+2].x = g->x0 + x;
    322                 vertexes[idx*4+2].y = g->y1 + y;
    323 
    324                 vertexes[idx*4+3].u = g->u1;
    325                 vertexes[idx*4+3].v = g->v1;
    326                 vertexes[idx*4+3].x = g->x1 + x;
    327                 vertexes[idx*4+3].y = g->y1 + y;
    328 
    329                 indexes[idx*6+0] = static_cast<u16>(idx*4+0);
    330                 indexes[idx*6+1] = static_cast<u16>(idx*4+1);
    331                 indexes[idx*6+2] = static_cast<u16>(idx*4+2);
    332                 indexes[idx*6+3] = static_cast<u16>(idx*4+2);
    333                 indexes[idx*6+4] = static_cast<u16>(idx*4+3);
    334                 indexes[idx*6+5] = static_cast<u16>(idx*4+0);
     295                = g->u1;
     296                = g->v0;
     297                = g->x1 + x;
     298                = g->y0 + y;
     299
     300                = g->u0;
     301                = g->v0;
     302                = g->x0 + x;
     303                = g->y0 + y;
     304
     305                = g->u0;
     306                = g->v1;
     307                = g->x0 + x;
     308                = g->y1 + y;
     309
     310                = g->u1;
     311                = g->v1;
     312                = g->x1 + x;
     313                = g->y1 + y;
     314
     315                indes[idx*6+0] = static_cast<u16>(idx*4+0);
     316                indes[idx*6+1] = static_cast<u16>(idx*4+1);
     317                indes[idx*6+2] = static_cast<u16>(idx*4+2);
     318                indes[idx*6+3] = static_cast<u16>(idx*4+2);
     319                indes[idx*6+4] = static_cast<u16>(idx*4+3);
     320                indes[idx*6+5] = static_cast<u16>(idx*4+0);
    335321
    336322                x += g->xadvance;
Note: See TracChangeset for help on using the changeset viewer.