Show currently bound shaders.
authorZack Rusin <zack@kde.org>
Sat, 9 Apr 2011 23:20:58 +0000 (19:20 -0400)
committerZack Rusin <zack@kde.org>
Sat, 9 Apr 2011 23:21:24 +0000 (19:21 -0400)
gui/CMakeLists.txt
gui/apitracecall.cpp
gui/apitracecall.h
gui/mainwindow.cpp
gui/mainwindow.h
gui/shaderssourcewidget.cpp [new file with mode: 0644]
gui/shaderssourcewidget.h [new file with mode: 0644]
gui/ui/mainwindow.ui
gui/ui/shaderssourcewidget.ui [new file with mode: 0644]

index 7c54e26..f5d9859 100644 (file)
@@ -12,6 +12,7 @@ set(qapitrace_SRCS
    main.cpp
    retracer.cpp
    settingsdialog.cpp
+   shaderssourcewidget.cpp
    vertexdatainterpreter.cpp
  )
 
@@ -22,7 +23,9 @@ qt4_add_resources(qapitrace_SRCS qapitrace.qrc)
 set(qapitrace_UIS
    ui/mainwindow.ui
    ui/retracerdialog.ui
-   ui/settings.ui)
+   ui/settings.ui
+   ui/shaderssourcewidget.ui
+   )
 
 QT4_WRAP_UI(qapitrace_UIS_H ${qapitrace_UIS})
 
index 952d106..1327283 100644 (file)
@@ -397,12 +397,17 @@ ApiTraceCall::~ApiTraceCall()
 {
 }
 
-QVariantMap ApiTraceEvent::state() const
+QVariantMap ApiTraceEvent::stateParameters() const
+{
+    return m_state.parameters();
+}
+
+ApiTraceState ApiTraceEvent::state() const
 {
     return m_state;
 }
 
-void ApiTraceEvent::setState(const QVariantMap &state)
+void ApiTraceEvent::setState(const ApiTraceState &state)
 {
     m_state = state;
 }
@@ -416,3 +421,40 @@ int ApiTraceCall::binaryDataIndex() const
 {
     return m_binaryDataIndex;
 }
+
+ApiTraceState::ApiTraceState()
+{
+}
+
+ApiTraceState::ApiTraceState(const QVariantMap &parsedJson)
+{
+    m_parameters = parsedJson[QLatin1String("parameters")].toMap();
+    QVariantMap currentProgram =
+        parsedJson[QLatin1String("current_program")].toMap();
+    QVariantList attachedShaders =
+        currentProgram[QLatin1String("attached_shaders")].toList();
+
+
+    for (int i = 0; i < attachedShaders.count(); ++i) {
+        QVariantMap var = attachedShaders[i].toMap();
+        m_shaderSources.append(
+            var[QLatin1String("source")].toString());
+    }
+}
+
+QVariantMap ApiTraceState::parameters() const
+{
+    return m_parameters;
+}
+
+QStringList ApiTraceState::shaderSources() const
+{
+    return m_shaderSources;
+}
+
+bool ApiTraceState::isEmpty() const
+{
+    return m_parameters.isEmpty();
+}
+
+
index c2fd987..7af0e7d 100644 (file)
@@ -101,6 +101,20 @@ QString apiVariantToString(const QVariant &variant);
 
 class ApiTraceFrame;
 
+class ApiTraceState {
+public:
+    ApiTraceState();
+    explicit ApiTraceState(const QVariantMap &parseJson);
+
+    bool isEmpty() const;
+    QVariantMap parameters() const;
+    QStringList shaderSources() const;
+
+private:
+    QVariantMap m_parameters;
+    QStringList m_shaderSources;
+};
+
 class ApiTraceEvent
 {
 public:
@@ -118,12 +132,13 @@ public:
     virtual QStaticText staticText() const = 0;
     virtual int numChildren() const = 0;
 
-    QVariantMap state() const;
-    void setState(const QVariantMap &state);
+    QVariantMap stateParameters() const;
+    ApiTraceState state() const;
+    void setState(const ApiTraceState &state);
 
 protected:
     Type m_type;
-    QVariantMap m_state;
+    ApiTraceState m_state;
 };
 Q_DECLARE_METATYPE(ApiTraceEvent*);
 
index 0065309..57112e5 100644 (file)
@@ -7,6 +7,7 @@
 #include "apitracefilter.h"
 #include "retracer.h"
 #include "settingsdialog.h"
+#include "shaderssourcewidget.h"
 #include "ui_retracerdialog.h"
 #include "vertexdatainterpreter.h"
 
@@ -22,6 +23,7 @@
 #include <QProgressBar>
 #include <QToolBar>
 #include <QUrl>
+#include <QVBoxLayout>
 #include <QWebPage>
 #include <QWebView>
 
@@ -35,6 +37,11 @@ MainWindow::MainWindow()
     m_ui.setupUi(this);
     m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
 
+    m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
+    QVBoxLayout *layout = new QVBoxLayout;
+    layout->addWidget(m_sourcesWidget);
+    m_ui.shadersTab->setLayout(layout);
+
     m_trace = new ApiTrace();
     connect(m_trace, SIGNAL(startedLoadingTrace()),
             this, SLOT(startedLoadingTrace()));
@@ -253,7 +260,7 @@ void MainWindow::replayFinished(const QByteArray &output)
     if (m_retracer->captureState()) {
         bool ok = false;
         QVariantMap parsedJson = m_jsonParser->parse(output, &ok).toMap();
-        parseState(parsedJson[QLatin1String("parameters")].toMap());
+        parseState(parsedJson);
     } else if (output.length() < 80) {
         statusBar()->showMessage(output);
     }
@@ -338,11 +345,9 @@ MainWindow::~MainWindow()
     delete m_jsonParser;
 }
 
-void MainWindow::parseState(const QVariantMap &params)
+void MainWindow::parseState(const QVariantMap &parsedJson)
 {
-    QVariantMap::const_iterator itr;
-
-    m_stateEvent->setState(params);
+    m_stateEvent->setState(ApiTraceState(parsedJson));
     m_model->stateSetOnEvent(m_stateEvent);
     if (m_selectedEvent == m_stateEvent) {
         fillStateForFrame();
@@ -381,8 +386,9 @@ void MainWindow::fillStateForFrame()
     if (!m_selectedEvent || m_selectedEvent->state().isEmpty())
         return;
 
+    const ApiTraceState &state = m_selectedEvent->state();
     m_ui.stateTreeWidget->clear();
-    params = m_selectedEvent->state();
+    params = state.parameters();
     QList<QTreeWidgetItem *> items;
     for (itr = params.constBegin(); itr != params.constEnd(); ++itr) {
         QString key = itr.key();
@@ -397,6 +403,15 @@ void MainWindow::fillStateForFrame()
         items.append(new QTreeWidgetItem((QTreeWidget*)0, lst));
     }
     m_ui.stateTreeWidget->insertTopLevelItems(0, items);
+
+    QStringList shaderSources = state.shaderSources();
+    if (shaderSources.isEmpty()) {
+        m_sourcesWidget->setShaders(shaderSources);
+    } else {
+        m_sourcesWidget->setShaders(shaderSources);
+    }
+
+    m_ui.surfacesTab->setEnabled(false);
     m_ui.stateDock->show();
 }
 
index 47f3328..19fffc2 100644 (file)
@@ -16,6 +16,7 @@ class QModelIndex;
 class QProgressBar;
 class QUrl;
 class Retracer;
+class ShadersSourceWidget;
 class VertexDataInterpreter;
 
 namespace QJson {
@@ -54,6 +55,8 @@ private:
 
 private:
     Ui_MainWindow m_ui;
+    ShadersSourceWidget *m_sourcesWidget;
+
     ApiTrace *m_trace;
     ApiTraceModel *m_model;
     ApiTraceFilter *m_proxyModel;
diff --git a/gui/shaderssourcewidget.cpp b/gui/shaderssourcewidget.cpp
new file mode 100644 (file)
index 0000000..0bec7a7
--- /dev/null
@@ -0,0 +1,44 @@
+#include "shaderssourcewidget.h"
+
+ShadersSourceWidget::ShadersSourceWidget(QWidget *parent)
+    : QWidget(parent)
+{
+    m_ui.setupUi(this);
+
+    connect(m_ui.shadersCB, SIGNAL(currentIndexChanged(int)),
+            SLOT(changeShader(int)));
+}
+
+void ShadersSourceWidget::setShaders(const QStringList &sources)
+{
+    m_sources = sources;
+
+    m_ui.shadersCB->clear();
+    m_ui.shadersTextEdit->clear();
+
+    if (m_sources.isEmpty()) {
+        m_ui.shadersCB->setDisabled(true);
+        m_ui.shadersTextEdit->setPlainText(
+            tr("No bound shaders."));
+        m_ui.shadersTextEdit->setDisabled(true);
+        return;
+    }
+
+    m_ui.shadersCB->setEnabled(true);
+    m_ui.shadersTextEdit->setEnabled(true);
+
+    for (int i = 0; i < m_sources.count(); ++i) {
+        QString source = m_sources[i];
+        m_ui.shadersCB->insertItem(
+            i,
+            tr("Shader %1").arg(i));
+    }
+    m_ui.shadersCB->setCurrentIndex(0);
+}
+
+void ShadersSourceWidget::changeShader(int idx)
+{
+    m_ui.shadersTextEdit->setPlainText(m_sources.value(idx));
+}
+
+#include "shaderssourcewidget.moc"
diff --git a/gui/shaderssourcewidget.h b/gui/shaderssourcewidget.h
new file mode 100644 (file)
index 0000000..4d7876d
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef SHADERSSOURCEWIDGET_H
+#define SHADERSSOURCEWIDGET_H
+
+#include "ui_shaderssourcewidget.h"
+#include <QWidget>
+
+class ShadersSourceWidget : public QWidget
+{
+    Q_OBJECT
+public:
+    ShadersSourceWidget(QWidget *parent=0);
+
+public slots:
+    void setShaders(const QStringList &sources);
+
+private slots:
+    void changeShader(int idx);
+private:
+    Ui::ShadersSourceWidget m_ui;
+    QStringList m_sources;
+};
+
+#endif
index 7d39a16..06988c7 100644 (file)
    <widget class="QWidget" name="dockWidgetContents_2">
     <layout class="QVBoxLayout" name="verticalLayout">
      <item>
-      <widget class="QTreeWidget" name="stateTreeWidget">
-       <property name="alternatingRowColors">
-        <bool>true</bool>
+      <widget class="QTabWidget" name="stateTabWidget">
+       <property name="currentIndex">
+        <number>1</number>
        </property>
-       <property name="selectionMode">
-        <enum>QAbstractItemView::NoSelection</enum>
-       </property>
-       <property name="uniformRowHeights">
-        <bool>true</bool>
-       </property>
-       <property name="sortingEnabled">
-        <bool>true</bool>
-       </property>
-       <property name="animated">
-        <bool>true</bool>
-       </property>
-       <property name="allColumnsShowFocus">
-        <bool>true</bool>
-       </property>
-       <attribute name="headerShowSortIndicator" stdset="0">
-        <bool>true</bool>
-       </attribute>
-       <column>
-        <property name="text">
-         <string>Variable</string>
-        </property>
-       </column>
-       <column>
-        <property name="text">
-         <string>Value</string>
-        </property>
-       </column>
+       <widget class="QWidget" name="parametersTab">
+        <attribute name="title">
+         <string>Parameters</string>
+        </attribute>
+        <layout class="QVBoxLayout" name="verticalLayout_3">
+         <item>
+          <widget class="QTreeWidget" name="stateTreeWidget">
+           <property name="editTriggers">
+            <set>QAbstractItemView::NoEditTriggers</set>
+           </property>
+           <property name="alternatingRowColors">
+            <bool>true</bool>
+           </property>
+           <property name="sortingEnabled">
+            <bool>true</bool>
+           </property>
+           <property name="allColumnsShowFocus">
+            <bool>true</bool>
+           </property>
+           <column>
+            <property name="text">
+             <string>Variable</string>
+            </property>
+           </column>
+           <column>
+            <property name="text">
+             <string>Value</string>
+            </property>
+           </column>
+          </widget>
+         </item>
+        </layout>
+       </widget>
+       <widget class="QWidget" name="shadersTab">
+        <attribute name="title">
+         <string>Shaders</string>
+        </attribute>
+       </widget>
+       <widget class="QWidget" name="surfacesTab">
+        <attribute name="title">
+         <string>Surfaces</string>
+        </attribute>
+        <layout class="QVBoxLayout" name="verticalLayout_5">
+         <item>
+          <widget class="QTreeWidget" name="surfacesTreeWidget">
+           <column>
+            <property name="text">
+             <string>Type</string>
+            </property>
+           </column>
+           <column>
+            <property name="text">
+             <string>Size</string>
+            </property>
+           </column>
+          </widget>
+         </item>
+        </layout>
+       </widget>
       </widget>
      </item>
     </layout>
diff --git a/gui/ui/shaderssourcewidget.ui b/gui/ui/shaderssourcewidget.ui
new file mode 100644 (file)
index 0000000..698eebf
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ShadersSourceWidget</class>
+ <widget class="QWidget" name="ShadersSourceWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QLabel" name="shadersLabel">
+       <property name="text">
+        <string>Select a shader:</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QComboBox" name="shadersCB"/>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QPlainTextEdit" name="shadersTextEdit">
+     <property name="readOnly">
+      <bool>true</bool>
+     </property>
+     <property name="textInteractionFlags">
+      <set>Qt::TextSelectableByMouse</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>