2021-02-06 16:55:08 +00:00
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "frontends/sdl/imgui/sdlimguiframe.h"
|
2021-02-07 19:23:28 +00:00
|
|
|
|
2021-02-06 16:55:08 +00:00
|
|
|
#include "frontends/sdl/utils.h"
|
2021-02-07 16:10:54 +00:00
|
|
|
#include "frontends/common2/fileregistry.h"
|
2021-02-09 16:02:36 +00:00
|
|
|
#include "frontends/common2/programoptions.h"
|
2021-02-07 19:23:28 +00:00
|
|
|
#include "frontends/sdl/imgui/image.h"
|
2021-02-06 16:55:08 +00:00
|
|
|
|
|
|
|
#include "Interface.h"
|
|
|
|
#include "Core.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2021-02-07 16:10:54 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
namespace sa2
|
2021-02-06 16:55:08 +00:00
|
|
|
{
|
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
SDLImGuiFrame::SDLImGuiFrame(const common2::EmulatorOptions & options)
|
|
|
|
: SDLFrame(options)
|
2021-02-06 16:55:08 +00:00
|
|
|
{
|
2021-02-25 16:31:24 +00:00
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, SDL_CONTEXT_MAJOR); // from local gles.h
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
2021-02-06 16:55:08 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
// Create window with graphics context
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
2021-02-06 16:55:08 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
const SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
|
|
|
const common2::Geometry & geometry = options.geometry;
|
2021-02-07 16:10:54 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
myWindow.reset(SDL_CreateWindow(g_pAppTitle.c_str(), geometry.x, geometry.y, geometry.width, geometry.height, windowFlags), SDL_DestroyWindow);
|
|
|
|
if (!myWindow)
|
|
|
|
{
|
|
|
|
throw std::runtime_error(SDL_GetError());
|
|
|
|
}
|
2021-02-07 16:10:54 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
SetApplicationIcon();
|
2021-02-06 16:55:08 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
myGLContext = SDL_GL_CreateContext(myWindow.get());
|
|
|
|
if (!myGLContext)
|
|
|
|
{
|
|
|
|
throw std::runtime_error(SDL_GetError());
|
|
|
|
}
|
2021-02-06 16:55:08 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
SDL_GL_MakeCurrent(myWindow.get(), myGLContext);
|
2021-02-06 16:55:08 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
// Setup Platform/Renderer backends
|
|
|
|
std::cerr << "IMGUI_VERSION: " << IMGUI_VERSION << std::endl;
|
|
|
|
std::cerr << "GL_VENDOR: " << glGetString(GL_VENDOR) << std::endl;
|
|
|
|
std::cerr << "GL_RENDERER: " << glGetString(GL_RENDERER) << std::endl;
|
|
|
|
std::cerr << "GL_VERSION: " << glGetString(GL_VERSION) << std::endl;
|
|
|
|
std::cerr << "GL_SHADING_LANGUAGE_VERSION: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
|
|
|
|
// const char* runtime_gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
|
|
|
|
// std::cerr << "GL_EXTENSIONS: " << runtime_gl_extensions << std::endl;
|
2021-02-06 16:55:08 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
// Setup Dear ImGui context
|
|
|
|
IMGUI_CHECKVERSION();
|
|
|
|
ImGui::CreateContext();
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
2021-02-06 16:55:08 +00:00
|
|
|
|
2021-03-06 17:41:32 +00:00
|
|
|
myIniFileLocation = common2::GetConfigFile("imgui.ini");
|
|
|
|
if (myIniFileLocation.empty())
|
2021-02-25 16:31:24 +00:00
|
|
|
{
|
|
|
|
io.IniFilename = nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-06 17:41:32 +00:00
|
|
|
io.IniFilename = myIniFileLocation.c_str();
|
2021-02-25 16:31:24 +00:00
|
|
|
}
|
2021-02-09 16:02:36 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
|
|
|
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
2021-02-09 16:02:36 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
ImGui::StyleColorsDark();
|
2021-02-06 16:55:08 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
ImGui_ImplSDL2_InitForOpenGL(myWindow.get(), myGLContext);
|
2021-02-08 11:42:14 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
ImGui_ImplOpenGL3_Init();
|
2021-02-06 16:55:08 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
glGenTextures(1, &myTexture);
|
2021-02-06 16:55:08 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
Video & video = GetVideo();
|
2021-02-06 16:55:08 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
myBorderlessWidth = video.GetFrameBufferBorderlessWidth();
|
|
|
|
myBorderlessHeight = video.GetFrameBufferBorderlessHeight();
|
2021-02-09 16:05:32 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
const int width = video.GetFrameBufferWidth();
|
|
|
|
const size_t borderWidth = video.GetFrameBufferBorderWidth();
|
|
|
|
const size_t borderHeight = video.GetFrameBufferBorderHeight();
|
2021-02-07 16:10:54 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
myPitch = width;
|
|
|
|
myOffset = (width * borderHeight + borderWidth) * sizeof(bgra_t);
|
2021-02-21 18:43:46 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
allocateTexture(myTexture, myBorderlessWidth, myBorderlessHeight);
|
2021-02-21 18:43:46 +00:00
|
|
|
}
|
2021-02-25 16:31:24 +00:00
|
|
|
|
|
|
|
SDLImGuiFrame::~SDLImGuiFrame()
|
2021-02-21 18:43:46 +00:00
|
|
|
{
|
2021-02-25 16:31:24 +00:00
|
|
|
glDeleteTextures(1, &myTexture);
|
|
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
ImGui_ImplSDL2_Shutdown();
|
|
|
|
ImGui::DestroyContext();
|
|
|
|
SDL_GL_DeleteContext(myGLContext);
|
2021-02-21 18:43:46 +00:00
|
|
|
}
|
2021-02-07 16:10:54 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
void SDLImGuiFrame::UpdateTexture()
|
2021-02-07 16:10:54 +00:00
|
|
|
{
|
2021-02-25 16:31:24 +00:00
|
|
|
loadTextureFromData(myTexture, myFramebuffer.data() + myOffset, myBorderlessWidth, myBorderlessHeight, myPitch);
|
2021-02-07 16:10:54 +00:00
|
|
|
}
|
2021-02-25 16:31:24 +00:00
|
|
|
|
|
|
|
void SDLImGuiFrame::ClearBackground()
|
2021-02-07 16:10:54 +00:00
|
|
|
{
|
2021-02-25 16:31:24 +00:00
|
|
|
const ImVec4 background(0.45f, 0.55f, 0.60f, 1.00f);
|
|
|
|
glClearColor(background.x, background.y, background.z, background.w);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2021-02-07 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
void SDLImGuiFrame::DrawAppleVideo()
|
2021-02-07 16:10:54 +00:00
|
|
|
{
|
2021-02-25 16:31:24 +00:00
|
|
|
// need to flip the texture vertically
|
|
|
|
const ImVec2 uv0(0, 1);
|
|
|
|
const ImVec2 uv1(1, 0);
|
|
|
|
|
2021-05-16 18:48:18 +01:00
|
|
|
const float menuBarHeight = mySettings.drawMenuBar(this);
|
2021-02-09 16:05:32 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
if (mySettings.windowed)
|
|
|
|
{
|
|
|
|
if (ImGui::Begin("Apple ]["))
|
|
|
|
{
|
|
|
|
ImGui::Image(myTexture, ImGui::GetContentRegionAvail(), uv0, uv1);
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const ImVec2 zero(0, menuBarHeight);
|
|
|
|
// draw on the background
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
ImGui::GetBackgroundDrawList()->AddImage(myTexture, zero, io.DisplaySize, uv0, uv1);
|
2021-02-07 19:23:28 +00:00
|
|
|
}
|
2021-02-07 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
void SDLImGuiFrame::RenderPresent()
|
2021-02-07 16:10:54 +00:00
|
|
|
{
|
2021-02-25 16:31:24 +00:00
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
ImGui_ImplSDL2_NewFrame(myWindow.get());
|
|
|
|
ImGui::NewFrame();
|
2021-02-07 16:10:54 +00:00
|
|
|
|
2021-03-14 11:14:03 +00:00
|
|
|
// "this" is a bit circular
|
|
|
|
mySettings.show(this);
|
2021-02-25 16:31:24 +00:00
|
|
|
DrawAppleVideo();
|
2021-02-23 19:32:00 +00:00
|
|
|
|
2021-02-25 16:31:24 +00:00
|
|
|
ImGui::Render();
|
|
|
|
ClearBackground();
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
SDL_GL_SwapWindow(myWindow.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDLImGuiFrame::ProcessSingleEvent(const SDL_Event & event, bool & quit)
|
2021-02-23 19:32:00 +00:00
|
|
|
{
|
2021-02-25 16:31:24 +00:00
|
|
|
ImGui_ImplSDL2_ProcessEvent(&event);
|
|
|
|
|
|
|
|
switch (event.type)
|
2021-02-23 19:32:00 +00:00
|
|
|
{
|
2021-02-25 16:31:24 +00:00
|
|
|
case SDL_KEYDOWN:
|
|
|
|
case SDL_KEYUP:
|
|
|
|
case SDL_TEXTINPUT:
|
|
|
|
{
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
if (io.WantCaptureKeyboard)
|
|
|
|
{
|
|
|
|
return; // do not pass on
|
|
|
|
}
|
|
|
|
}
|
2021-04-04 16:44:04 +01:00
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
case SDL_MOUSEMOTION:
|
|
|
|
{
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
if (io.WantCaptureMouse)
|
|
|
|
{
|
|
|
|
return; // do not pass on
|
|
|
|
}
|
|
|
|
}
|
2021-02-23 19:32:00 +00:00
|
|
|
}
|
2021-02-25 16:31:24 +00:00
|
|
|
|
|
|
|
SDLFrame::ProcessSingleEvent(event, quit);
|
2021-02-23 19:32:00 +00:00
|
|
|
}
|
|
|
|
|
2021-05-26 17:48:44 +01:00
|
|
|
void SDLImGuiFrame::ResetSpeed()
|
|
|
|
{
|
|
|
|
SDLFrame::ResetSpeed();
|
|
|
|
mySettings.resetDebuggerCycles();
|
|
|
|
}
|
|
|
|
|
2021-02-23 19:32:00 +00:00
|
|
|
}
|