Changeset 27138
- Timestamp:
- Oct 9, 2022, 2:21:26 PM (22 months ago)
- Location:
- ps/trunk/source/graphics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/source/graphics/Canvas2D.cpp
r27136 r27138 68 68 deviceCommandContext->SetUniform(bindingSlots.grayscaleFactor, grayscaleFactor); 69 69 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 79 70 deviceCommandContext->SetVertexBufferData( 80 71 0, vertices.data(), vertices.size() * sizeof(vertices[0])); … … 127 118 DeviceCommandContext->SetUniform( 128 119 BindingSlots.translation, Translation.AsFloatArray()); 120 121 122 123 124 125 126 127 128 129 129 } 130 130 … … 327 327 m->BindingSlots.grayscaleFactor, 0.0f); 328 328 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 338 329 m->DeviceCommandContext->SetVertexBufferData(0, vertices.data(), vertices.size() * sizeof(vertices[0])); 339 330 m->DeviceCommandContext->SetVertexBufferData(1, uvs.data(), uvs.size() * sizeof(uvs[0])); -
ps/trunk/source/graphics/TextRenderer.cpp
r27136 r27138 183 183 } 184 184 185 186 struct t2f_v2i187 {188 t2f_v2i() : u(0), v(0), x(0), y(0) { }189 float u, v;190 i16 x, y;191 };192 193 185 struct SBatchCompare 194 186 { … … 207 199 const CVector2D& transformScale, const CVector2D& translation) 208 200 { 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; 211 204 212 205 // Try to merge non-consecutive batches that share the same font/color/translate: … … 264 257 deviceCommandContext->SetUniform(colorMulBindingSlot, batch.color.AsFloatArray()); 265 258 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); 268 262 269 263 size_t idx = 0; 270 264 271 auto flush = [deviceCommandContext, &idx, & vertexes, &indexes]() -> void265 auto flush = [deviceCommandContext, &idx, &es]() -> void 272 266 { 273 267 if (idx == 0) 274 268 return; 275 269 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 287 270 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])); 290 276 291 277 deviceCommandContext->DrawIndexed(0, idx * 6, 0); … … 307 293 continue; 308 294 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 ind exes[idx*6+0] = static_cast<u16>(idx*4+0);330 ind exes[idx*6+1] = static_cast<u16>(idx*4+1);331 ind exes[idx*6+2] = static_cast<u16>(idx*4+2);332 ind exes[idx*6+3] = static_cast<u16>(idx*4+2);333 ind exes[idx*6+4] = static_cast<u16>(idx*4+3);334 ind exes[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); 335 321 336 322 x += g->xadvance;
Note:
See TracChangeset
for help on using the changeset viewer.