diff options
author | lawnjelly <lawnjelly@gmail.com> | 2020-11-18 18:11:30 +0000 |
---|---|---|
committer | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2021-10-30 02:05:48 +0200 |
commit | e3491a37445014cc3527d6f2c1467063222b2dd8 (patch) | |
tree | 7f8250aee66fbc382040f0c843a91a5f85238d45 /drivers/gles_common/batch_diagnose.inc | |
parent | d046817536a21358f9c51bf5b932d0a6615ee76a (diff) |
Add GLES2 2D renderer + Linux display manager
First implementation with Linux display manager.
- Add single-threaded mode for EditorResourcePreview (needed for OpenGL).
Co-authored-by: clayjohn <claynjohn@gmail.com>
Co-authored-by: Fabio Alessandrelli <fabio.alessandrelli@gmail.com>
Diffstat (limited to 'drivers/gles_common/batch_diagnose.inc')
-rw-r--r-- | drivers/gles_common/batch_diagnose.inc | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/drivers/gles_common/batch_diagnose.inc b/drivers/gles_common/batch_diagnose.inc new file mode 100644 index 0000000000..88a8792edb --- /dev/null +++ b/drivers/gles_common/batch_diagnose.inc @@ -0,0 +1,192 @@ +void _debug_write_garbage() { + // extremely slow, writes garbage over arrays to detect using + // uninitialized in graphical output. Do not enable in normal use!! +#ifdef RASTERIZER_EXTRA_CHECKS + int num_verts = MIN(bdata.vertices.max_size(), 32); + for (int n = 0; n < num_verts; n++) { + bdata.vertices[n].pos.set(Math::random(-200.0f, 200.0f), Math::random(-200.0f, 200.0f)); + bdata.vertices[n].uv.set(Math::random(0.0f, 1.0f), Math::random(0.0f, 1.0f)); + } + + int num_colors = MIN(bdata.vertex_colors.max_size(), 32); + for (int n = 0; n < num_colors; n++) { + bdata.vertex_colors[n].set(Math::randf(), Math::randf(), Math::randf(), 1.0f); + } + + int num_modulates = MIN(bdata.vertex_modulates.max_size(), 32); + for (int n = 0; n < num_modulates; n++) { + bdata.vertex_modulates[n].set(Math::randf(), Math::randf(), Math::randf(), 1.0f); + } + + int num_light_angles = MIN(bdata.light_angles.max_size(), 32); + for (int n = 0; n < num_light_angles; n++) { + bdata.light_angles[n] = Math::random(-3.0f, +3.0f); + } + + int num_transforms = MIN(bdata.vertex_transforms.max_size(), 32); + for (int n = 0; n < num_transforms; n++) { + bdata.vertex_transforms[n].translate.set(Math::random(-200.0f, 200.0f), Math::random(-200.0f, 200.0f)); + bdata.vertex_transforms[n].basis[0].set(Math::random(-2.0f, 2.0f), Math::random(-2.0f, 2.0f)); + bdata.vertex_transforms[n].basis[1].set(Math::random(-2.0f, 2.0f), Math::random(-2.0f, 2.0f)); + } + + int num_unit_verts = MIN(bdata.unit_vertices.max_size(), 32); + for (int n = 0; n < num_unit_verts; n++) { + uint8_t *data = bdata.unit_vertices.get_unit(n); + for (int b = 0; b > bdata.unit_vertices.get_unit_size_bytes(); b++) { + data[b] = Math::random(0, 255); + } + } + +#endif +} + +String get_command_type_string(const RendererCanvasRender::Item::Command &p_command) const { + String sz = ""; + + switch (p_command.type) { + default: + break; +#ifdef GODOT_3 + case RendererCanvasRender::Item::Command::GD_TYPE_LINE: { + sz = "l"; + } break; + case RendererCanvasRender::Item::Command::GD_TYPE_POLYLINE: { + sz = "PL"; + } break; + case RendererCanvasRender::Item::Command::GD_TYPE_CIRCLE: { + sz = "c"; + } break; +#endif + case RendererCanvasRender::Item::Command::TYPE_RECT: { + sz = "r"; + } break; + case RendererCanvasRender::Item::Command::TYPE_NINEPATCH: { + sz = "n"; + } break; + case RendererCanvasRender::Item::Command::TYPE_PRIMITIVE: { + sz = "PR"; + } break; + case RendererCanvasRender::Item::Command::TYPE_POLYGON: { + sz = "p"; + } break; + case RendererCanvasRender::Item::Command::TYPE_MESH: { + sz = "m"; + } break; + case RendererCanvasRender::Item::Command::TYPE_MULTIMESH: { + sz = "MM"; + } break; + case RendererCanvasRender::Item::Command::TYPE_PARTICLES: { + sz = "PA"; + } break; + case RendererCanvasRender::Item::Command::TYPE_TRANSFORM: { + sz = "t"; + + // add a bit more info in debug build + const RendererCanvasRender::Item::CommandTransform *transform = static_cast<const RendererCanvasRender::Item::CommandTransform *>(&p_command); + const Transform2D &mat = transform->xform; + + sz += " "; + sz += String(Variant(mat.elements[2])); + sz += " "; + } break; + case RendererCanvasRender::Item::Command::TYPE_CLIP_IGNORE: { + sz = "CI"; + } break; + } // switch + + return sz; +} + +void diagnose_batches(RendererCanvasRender::Item::Command *const *p_commands) { + int num_batches = bdata.batches.size(); + + BatchColor curr_color; + curr_color.set(Color(-1, -1, -1, -1)); + bool first_color_change = true; + + for (int batch_num = 0; batch_num < num_batches; batch_num++) { + const Batch &batch = bdata.batches[batch_num]; + bdata.frame_string += "\t\t\tbatch "; + + switch (batch.type) { + case RasterizerStorageCommon::BT_POLY: { + bdata.frame_string += "P "; + bdata.frame_string += itos(batch.first_command) + "-"; + bdata.frame_string += itos(batch.num_commands); + + bdata.frame_string += " " + batch.color.to_string(); + + if (batch.num_commands > 1) { + bdata.frame_string += " MULTI"; + } + if (curr_color != batch.color) { + curr_color = batch.color; + if (!first_color_change) { + bdata.frame_string += " color"; + } else { + first_color_change = false; + } + } + bdata.frame_string += "\n"; + } break; + case RasterizerStorageCommon::BT_LINE: + case RasterizerStorageCommon::BT_LINE_AA: { + bdata.frame_string += "L "; + bdata.frame_string += itos(batch.first_command) + "-"; + bdata.frame_string += itos(batch.num_commands); + + bdata.frame_string += " " + batch.color.to_string(); + + if (batch.num_commands > 1) { + bdata.frame_string += " MULTI"; + } + if (curr_color != batch.color) { + curr_color = batch.color; + if (!first_color_change) { + bdata.frame_string += " color"; + } else { + first_color_change = false; + } + } + bdata.frame_string += "\n"; + } break; + case RasterizerStorageCommon::BT_RECT: { + bdata.frame_string += "R "; + bdata.frame_string += itos(batch.first_command) + "-"; + bdata.frame_string += itos(batch.num_commands); + + int tex_id = (int)bdata.batch_textures[batch.batch_texture_id].RID_texture.get_id(); + bdata.frame_string += " [" + itos(batch.batch_texture_id) + " - " + itos(tex_id) + "]"; + + bdata.frame_string += " " + batch.color.to_string(); + + if (batch.num_commands > 1) { + bdata.frame_string += " MULTI"; + } + if (curr_color != batch.color) { + curr_color = batch.color; + if (!first_color_change) { + bdata.frame_string += " color"; + } else { + first_color_change = false; + } + } + bdata.frame_string += "\n"; + } break; + default: { + bdata.frame_string += "D "; + bdata.frame_string += itos(batch.first_command) + "-"; + bdata.frame_string += itos(batch.num_commands) + " "; + + int num_show = MIN(batch.num_commands, 16); + for (int n = 0; n < num_show; n++) { + const RendererCanvasRender::Item::Command &comm = *p_commands[batch.first_command + n]; + bdata.frame_string += get_command_type_string(comm) + " "; + } + + bdata.frame_string += "\n"; + } break; + } + } +} |