package electrosphere.client.ui.menu.debug;

import electrosphere.engine.Globals;
import electrosphere.renderer.pipelines.PostProcessingPipeline;
import electrosphere.renderer.pipelines.ShadowMapPipeline;
import electrosphere.renderer.ui.imgui.ImGuiWindow;
import electrosphere.renderer.ui.imgui.ImGuiWindow.ImGuiWindowCallback;
import imgui.ImGui;

public class ImGuiRenderer {
    
    //window for viewing information about loggers
    protected static ImGuiWindow rendererWindow;

    //stores far plane
    private static float[] farPlaneArr = new float[]{1};


    /**
     * Creates the windows in this file
     */
    protected static void createRendererWindows(){
        createRendererWindow();
    }

    /**
     * loggers view
     */
    protected static void createRendererWindow(){
        rendererWindow = new ImGuiWindow("Renderer");
        rendererWindow.setCallback(new ImGuiWindowCallback() {
            @Override
            public void exec() {
                if(ImGui.collapsingHeader("Pipelines")){
                    ImGui.indent();
                    if(ImGui.collapsingHeader("Shadow Map Pipeline")){
                        ShadowMapPipeline shadowMapPipeline = Globals.renderingEngine.getShadowMapPipeline();
                        if(ImGui.sliderFloat("Far Plane Distance", farPlaneArr, 1, 100)){
                            shadowMapPipeline.setFarPlane(farPlaneArr[0]);
                        }
                    }
                    if(ImGui.collapsingHeader("Post Processing Pipeline")){
                        PostProcessingPipeline postProcessingPipeline = Globals.renderingEngine.getPostProcessingPipeline();
                        if(ImGui.button("Toggle Blur")){
                            postProcessingPipeline.setApplyBlur(!postProcessingPipeline.isApplyingBlur());
                        }
                    }
                    ImGui.unindent();
                }
                if(ImGui.collapsingHeader("OpenGL Details")){
                    ImGui.text("GL_MAX_TEXTURE_IMAGE_UNITS: " + Globals.renderingEngine.getOpenGLContext().getMaxTextureImageUnits());
                    ImGui.text("GL_MAX_TEXTURE_SIZE: " + Globals.renderingEngine.getOpenGLContext().getMaxTextureSize());
                }
            }
        });
        rendererWindow.setOpen(false);
        Globals.renderingEngine.getImGuiPipeline().addImGuiWindow(rendererWindow);
    }

}
