Merge pull request #538 from DrChat/trace_viewer_misc

Trace Viewer Zoomed View / Fix Alpha Test
This commit is contained in:
Ben Vanik 2016-02-16 17:19:26 -08:00
commit 864b1b5fac
5 changed files with 68 additions and 15 deletions

View File

@ -639,8 +639,8 @@ void TraceViewer::DrawTextureInfo(
ImGui::Columns(2);
ImVec2 button_size(256, 256);
if (ImGui::ImageButton(ImTextureID(texture), button_size, ImVec2(0, 0),
ImVec2(1, 1))) {
if (ImGui::ImageButton(ImTextureID(texture | ui::ImGuiDrawer::kIgnoreAlpha),
button_size, ImVec2(0, 0), ImVec2(1, 1))) {
// show viewer
}
ImGui::NextColumn();
@ -953,6 +953,18 @@ void ProgressBar(float frac, float width, float height = 0,
ImGui::Dummy(ImVec2(width, height));
}
void ZoomedImage(ImTextureID tex, ImVec2 rel_pos, ImVec2 tex_size,
float focus_size, ImVec2 image_size = ImVec2(128, 128)) {
ImVec2 focus;
focus.x = rel_pos.x - (focus_size * 0.5f);
focus.y = rel_pos.y - (focus_size * 0.5f);
ImVec2 uv0 = ImVec2(focus.x / tex_size.x, focus.y / tex_size.y);
ImVec2 uv1 = ImVec2((focus.x + focus_size) / tex_size.x,
(focus.y + focus_size) / tex_size.y);
ImGui::Image(tex, image_size, uv0, uv1);
}
void TraceViewer::DrawStateUI() {
auto command_processor = graphics_system_->command_processor();
auto& regs = *graphics_system_->register_file();
@ -1205,7 +1217,7 @@ void TraceViewer::DrawStateUI() {
// Alpha testing -- ALPHAREF, ALPHAFUNC, ALPHATESTENABLE
// if(ALPHATESTENABLE && frag_out.a [<=/ALPHAFUNC] ALPHAREF) discard;
uint32_t color_control = regs[XE_GPU_REG_RB_COLORCONTROL].u32;
if ((color_control & 0x4) != 0) {
if ((color_control & 0x8) != 0) {
ImGui::BulletText("Alpha Test: %s %.2f",
kCompareFuncNames[color_control & 0x7],
regs[XE_GPU_REG_RB_ALPHA_REF].f32);
@ -1300,14 +1312,15 @@ void TraceViewer::DrawStateUI() {
uint32_t color_base = color_info[i] & 0xFFF;
auto color_format =
static_cast<ColorRenderTargetFormat>((color_info[i] >> 16) & 0xF);
ImVec2 button_pos = ImGui::GetCursorScreenPos();
ImVec2 button_size(256, 256);
ImTextureID tex = 0;
if (write_mask) {
// FIXME: Valid color targets with alpha=0 don't show up.
auto color_target = GetColorRenderTarget(surface_pitch, surface_msaa,
color_base, color_format);
if (ImGui::ImageButton(ImTextureID(color_target), button_size,
ImVec2(0, 0), ImVec2(1, 1))) {
tex = ImTextureID(color_target | ui::ImGuiDrawer::kIgnoreAlpha);
if (ImGui::ImageButton(tex, button_size, ImVec2(0, 0),
ImVec2(1, 1))) {
// show viewer
}
} else {
@ -1316,9 +1329,20 @@ void TraceViewer::DrawStateUI() {
ImVec4(0, 0, 0, 0));
}
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Color Target %d (%s), base %.4X, pitch %d", i,
write_mask ? "enabled" : "disabled", color_base,
surface_pitch);
ImGui::BeginTooltip();
ImGui::Text(
"Color Target %d (%s), base %.4X, pitch %d, msaa %d, format %d",
i, write_mask ? "enabled" : "disabled", color_base, surface_pitch,
surface_msaa, color_format);
if (tex) {
ImVec2 rel_pos;
rel_pos.x = ImGui::GetMousePos().x - button_pos.x;
rel_pos.y = ImGui::GetMousePos().y - button_pos.y;
ZoomedImage(tex, rel_pos, button_size, 32.f, ImVec2(256, 256));
}
ImGui::EndTooltip();
}
ImGui::NextColumn();
}
@ -1380,10 +1404,22 @@ void TraceViewer::DrawStateUI() {
static_cast<DepthRenderTargetFormat>((rb_depth_info >> 16) & 0x1);
auto depth_target = GetDepthRenderTarget(surface_pitch, surface_msaa,
depth_base, depth_format);
auto button_pos = ImGui::GetCursorScreenPos();
ImVec2 button_size(256, 256);
if (ImGui::ImageButton(ImTextureID(depth_target), button_size,
ImVec2(0, 0), ImVec2(1, 1))) {
// show viewer
ImGui::ImageButton(
ImTextureID(depth_target | ui::ImGuiDrawer::kIgnoreAlpha),
button_size, ImVec2(0, 0), ImVec2(1, 1));
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImVec2 rel_pos;
rel_pos.x = ImGui::GetMousePos().x - button_pos.x;
rel_pos.y = ImGui::GetMousePos().y - button_pos.y;
ZoomedImage(ImTextureID(depth_target | ui::ImGuiDrawer::kIgnoreAlpha),
rel_pos, button_size, 32.f, ImVec2(256, 256));
ImGui::EndTooltip();
}
} else {
ImGui::Text("No depth target");
@ -1411,7 +1447,7 @@ void TraceViewer::DrawStateUI() {
vertices.resize(size / 4);
QueryVSOutput(vertices.data(), size);
ImGui::Text("%d output vertices", vertices.size());
ImGui::Text("%d output vertices", vertices.size() / 4);
ImGui::SameLine();
static bool normalize = false;
ImGui::Checkbox("Normalize", &normalize);

View File

@ -228,6 +228,14 @@ void GLImmediateDrawer::Draw(const ImmediateDraw& draw) {
glDisable(GL_SCISSOR_TEST);
}
if (draw.alpha_blend) {
glEnablei(GL_BLEND, 0);
glBlendEquationi(0, GL_FUNC_ADD);
glBlendFunci(0, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
} else {
glDisablei(GL_BLEND, 0);
}
if (draw.texture_handle) {
glBindTextureUnit(0, static_cast<GLuint>(draw.texture_handle));
} else {

View File

@ -207,7 +207,11 @@ void ImGuiDrawer::RenderDrawLists(ImDrawData* data) {
draw.primitive_type = ImmediatePrimitiveType::kTriangles;
draw.count = cmd.ElemCount;
draw.index_offset = index_offset;
draw.texture_handle = reinterpret_cast<uintptr_t>(cmd.TextureId);
draw.texture_handle =
reinterpret_cast<uintptr_t>(cmd.TextureId) & 0xFFFFFFFF;
draw.alpha_blend =
reinterpret_cast<uintptr_t>(cmd.TextureId) & kIgnoreAlpha ? false
: true;
draw.scissor = true;
draw.scissor_rect[0] = static_cast<int>(cmd.ClipRect.x);
draw.scissor_rect[1] = static_cast<int>(height - cmd.ClipRect.w);

View File

@ -35,6 +35,8 @@ class ImGuiDrawer : public WindowListener {
ImGuiIO& GetIO();
static const uint64_t kIgnoreAlpha = (1ull << 32);
protected:
void Initialize();
void SetupFont();

View File

@ -87,6 +87,9 @@ struct ImmediateDraw {
bool scissor = false;
// Scissoring region in framebuffer pixels as (x, y, w, h).
int scissor_rect[4] = {0};
// Blends this draw with the background depending on its alpha (if true).
bool alpha_blend = true;
};
class ImmediateDrawer {