|
|
@@ -10,6 +10,8 @@ using namespace anki;
|
|
|
class TextureViewerUiNode : public SceneNode
|
|
|
{
|
|
|
public:
|
|
|
+ TextureResourcePtr m_textureResource;
|
|
|
+
|
|
|
TextureViewerUiNode(SceneGraph* scene, CString name)
|
|
|
: SceneNode(scene, name)
|
|
|
{
|
|
|
@@ -17,28 +19,91 @@ public:
|
|
|
spatialc->setAlwaysVisible(true);
|
|
|
|
|
|
UiComponent* uic = newComponent<UiComponent>();
|
|
|
- uic->init([](CanvasPtr& canvas, const void* ud) { static_cast<const TextureViewerUiNode*>(ud)->draw(canvas); },
|
|
|
- this);
|
|
|
+ uic->init([](CanvasPtr& canvas, void* ud) { static_cast<TextureViewerUiNode*>(ud)->draw(canvas); }, this);
|
|
|
|
|
|
ANKI_CHECK_AND_IGNORE(getSceneGraph().getUiManager().newInstance(m_font, "EngineAssets/UbuntuMonoRegular.ttf",
|
|
|
- Array<U32, 1>{32}));
|
|
|
+ Array<U32, 1>{16}));
|
|
|
+ }
|
|
|
+
|
|
|
+ Error frameUpdate(Second prevUpdateTime, Second crntTime)
|
|
|
+ {
|
|
|
+ if(!m_textureView.isCreated())
|
|
|
+ {
|
|
|
+ m_textureView = m_textureResource->getGrTextureView();
|
|
|
+ }
|
|
|
+
|
|
|
+ return Error::NONE;
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
FontPtr m_font;
|
|
|
+ TextureViewPtr m_textureView;
|
|
|
+ U32 m_crntMip = 0;
|
|
|
+ F32 m_zoom = 1.0f;
|
|
|
|
|
|
- void draw(CanvasPtr& canvas) const
|
|
|
+ void draw(CanvasPtr& canvas)
|
|
|
{
|
|
|
+ const Texture& grTex = *m_textureResource->getGrTexture().get();
|
|
|
+
|
|
|
ImGui::Begin("Console", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoTitleBar);
|
|
|
|
|
|
- canvas->pushFont(m_font, 32);
|
|
|
+ canvas->pushFont(m_font, 16);
|
|
|
|
|
|
ImGui::SetWindowPos(Vec2(0.0f, 0.0f));
|
|
|
ImGui::SetWindowSize(Vec2(F32(canvas->getWidth()), F32(canvas->getHeight())));
|
|
|
|
|
|
- ImGui::PushStyleColor(ImGuiCol_Text, Vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
|
|
- ImGui::TextWrapped("Test");
|
|
|
- ImGui::PopStyleColor();
|
|
|
+ ImGui::BeginChild("Tools", ImVec2(ImGui::GetWindowContentRegionWidth() * 0.25f, -1.0f), false, 0);
|
|
|
+
|
|
|
+ // Info
|
|
|
+ ImGui::TextWrapped("Size %ux%u Mips %u", grTex.getWidth(), grTex.getHeight(), grTex.getMipmapCount());
|
|
|
+
|
|
|
+ // Zoom
|
|
|
+ ImGui::DragFloat("Zoom", &m_zoom, 0.01f, 0.1f, 10.0f, "%.3f");
|
|
|
+
|
|
|
+ // Mips combo
|
|
|
+ {
|
|
|
+ Array<CString, 8> mipTexts = {"0", "1", "2", "3", "4", "5", "6", "7"};
|
|
|
+ CString comboLevel = mipTexts[m_crntMip];
|
|
|
+ const U32 lastCrntMip = m_crntMip;
|
|
|
+ if(ImGui::BeginCombo("Mipmap", comboLevel.cstr(), 0))
|
|
|
+ {
|
|
|
+ for(U32 mip = 0; mip < grTex.getMipmapCount(); ++mip)
|
|
|
+ {
|
|
|
+ const Bool isSelected = (m_crntMip == mip);
|
|
|
+ if(ImGui::Selectable(mipTexts[mip].cstr(), isSelected))
|
|
|
+ {
|
|
|
+ m_crntMip = mip;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isSelected)
|
|
|
+ {
|
|
|
+ ImGui::SetItemDefaultFocus();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ImGui::EndCombo();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(lastCrntMip != m_crntMip)
|
|
|
+ {
|
|
|
+ // Re-create the image view
|
|
|
+ TextureViewInitInfo viewInitInf(m_textureResource->getGrTexture());
|
|
|
+ viewInitInf.m_firstMipmap = m_crntMip;
|
|
|
+ m_textureView = getSceneGraph().getGrManager().newTextureView(viewInitInf);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ImGui::EndChild();
|
|
|
+
|
|
|
+ ImGui::SameLine();
|
|
|
+
|
|
|
+ ImGui::BeginChild("Image", ImVec2(ImGui::GetWindowContentRegionWidth() * 0.75f, -1.0f), false,
|
|
|
+ ImGuiWindowFlags_HorizontalScrollbar);
|
|
|
+
|
|
|
+ ImGui::Image(const_cast<TextureView*>(m_textureView.get()),
|
|
|
+ ImVec2(F32(grTex.getWidth()) * m_zoom, F32(grTex.getHeight()) * m_zoom), ImVec2(0.0f, 0.0f),
|
|
|
+ ImVec2(1.0f, 1.0f), Vec4(1.0f), Vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
|
|
+
|
|
|
+ ImGui::EndChild();
|
|
|
|
|
|
canvas->popFont();
|
|
|
ImGui::End();
|
|
|
@@ -61,9 +126,20 @@ public:
|
|
|
|
|
|
ANKI_CHECK(App::init(config, allocAligned, nullptr));
|
|
|
|
|
|
+ // Load the texture
|
|
|
+ if(argc < 2)
|
|
|
+ {
|
|
|
+ ANKI_LOGE("Wrong number of arguments");
|
|
|
+ return Error::USER_DATA;
|
|
|
+ }
|
|
|
+ TextureResourcePtr tex;
|
|
|
+ ANKI_CHECK(getResourceManager().loadResource(argv[1], tex, false));
|
|
|
+
|
|
|
+ // Create the node
|
|
|
SceneGraph& scene = getSceneGraph();
|
|
|
TextureViewerUiNode* node;
|
|
|
ANKI_CHECK(scene.newSceneNode("TextureViewer", node));
|
|
|
+ node->m_textureResource = tex;
|
|
|
|
|
|
return Error::NONE;
|
|
|
}
|