More changes to accomodate Android - imgui/host display

This commit is contained in:
Connor McLaughlin 2019-11-28 23:29:03 +10:00 committed by Connor McLaughlin
parent f11d357ab9
commit ea0b13a05c
11 changed files with 71 additions and 124 deletions

View File

@ -32,3 +32,12 @@ if(SDL2_FOUND)
target_link_libraries(imgui PRIVATE glad SDL2::Core)
endif()
if(ANDROID)
target_sources(imgui PRIVATE
include/imgui_impl_opengl3.h
src/imgui_impl_opengl3.cpp
)
target_link_libraries(imgui PRIVATE glad)
endif()

View File

@ -13,8 +13,6 @@
#pragma once
#define IMGUI_IMPL_OPENGL_LOADER_GLAD
//---- Define assertion handler. Defaults to calling assert().
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts

View File

@ -35,31 +35,3 @@ IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture();
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
// Specific OpenGL versions
//#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten
//#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android
// Desktop OpenGL: attempt to detect default GL loader based on available header files.
// If auto-detection fails or doesn't select the same GL loader file as used by your application,
// you are likely to get a crash in ImGui_ImplOpenGL3_Init().
// You can explicitly select a loader by using '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
#if !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \
&& !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
#if defined(__has_include)
#if __has_include(<GL/glew.h>)
#define IMGUI_IMPL_OPENGL_LOADER_GLEW
#elif __has_include(<glad/glad.h>)
#define IMGUI_IMPL_OPENGL_LOADER_GLAD
#elif __has_include(<GL/gl3w.h>)
#define IMGUI_IMPL_OPENGL_LOADER_GL3W
#else
#error "Cannot detect OpenGL loader!"
#endif
#else
#define IMGUI_IMPL_OPENGL_LOADER_GL3W // Default to GL3W
#endif
#endif

View File

@ -82,44 +82,14 @@
// Auto-detect GL version
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3)
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
#undef IMGUI_IMPL_OPENGL_LOADER_GL3W
#undef IMGUI_IMPL_OPENGL_LOADER_GLEW
#undef IMGUI_IMPL_OPENGL_LOADER_GLAD
#undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM
#define IMGUI_IMPL_OPENGL_ES2
#elif defined(__EMSCRIPTEN__)
#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
#undef IMGUI_IMPL_OPENGL_LOADER_GL3W
#undef IMGUI_IMPL_OPENGL_LOADER_GLEW
#undef IMGUI_IMPL_OPENGL_LOADER_GLAD
#undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM
#define IMGUI_IMPL_OPENGL_ES2
#endif
#endif
// GL includes
#if defined(IMGUI_IMPL_OPENGL_ES2)
#include <GLES2/gl2.h>
#elif defined(IMGUI_IMPL_OPENGL_ES3)
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
#include <OpenGLES/ES3/gl.h> // Use GL ES 3
#else
#include <GLES3/gl3.h> // Use GL ES 3
#endif
#else
// About Desktop OpenGL function loaders:
// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
// Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad).
// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
#include <GL/gl3w.h> // Needs to be initialized with gl3wInit() in user's code
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
#include <GL/glew.h> // Needs to be initialized with glewInit() in user's code
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
#include <glad.h> // Needs to be initialized with gladLoadGL() in user's code
#else
#include IMGUI_IMPL_OPENGL_LOADER_CUSTOM
#endif
#endif
#include <glad.h>
// Desktop GL has glDrawElementsBaseVertex() which GL ES and WebGL don't have.
#if defined(IMGUI_IMPL_OPENGL_ES2) || defined(IMGUI_IMPL_OPENGL_ES3)
@ -147,66 +117,35 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
// Setup back-end capabilities flags
ImGuiIO& io = ImGui::GetIO();
io.BackendRendererName = "imgui_impl_opengl3";
#if IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
#endif
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
// Store GLSL version string so we can refer to it later in case we recreate shaders. Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure.
#if defined(IMGUI_IMPL_OPENGL_ES2)
if (glsl_version == NULL)
glsl_version = "#version 100";
g_IsGLES = true;
#elif defined(IMGUI_IMPL_OPENGL_ES3)
if (glsl_version == NULL)
glsl_version = "#version 300 es";
g_IsGLES = true;
#else
if (glsl_version == NULL)
glsl_version = "#version 130";
g_IsGLES = false;
#endif
#if defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
if (GLAD_GL_ES_VERSION_2_0)
{
if (glsl_version == NULL)
glsl_version = "#version 100";
g_IsGLES = true;
}
else if (GLAD_GL_ES_VERSION_3_0)
{
if (glsl_version == NULL)
glsl_version = "#version 300 es";
g_IsGLES = true;
}
#endif
else
{
if (glsl_version == NULL)
glsl_version = "#version 130";
g_IsGLES = false;
}
if (!g_IsGLES)
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(g_GlslVersionString));
strcpy(g_GlslVersionString, glsl_version);
strcat(g_GlslVersionString, "\n");
// Dummy construct to make it easily visible in the IDE and debugger which GL loader has been selected.
// The code actually never uses the 'gl_loader' variable! It is only here so you can read it!
// If auto-detection fails or doesn't select the same GL loader file as used by your application,
// you are likely to get a crash below.
// You can explicitly select a loader by using '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
const char* gl_loader = "Unknown";
IM_UNUSED(gl_loader);
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
gl_loader = "GL3W";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
gl_loader = "GLEW";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
gl_loader = "GLAD";
#else // IMGUI_IMPL_OPENGL_LOADER_CUSTOM
gl_loader = "Custom";
#endif
// Make a dummy GL call (we don't actually need the result)
// IF YOU GET A CRASH HERE: it probably means that you haven't initialized the OpenGL function loader used by this code.
// Desktop OpenGL 3/4 need a function loader. See the IMGUI_IMPL_OPENGL_LOADER_xxx explanation above.
GLint current_texture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &current_texture);
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
ImGui_ImplOpenGL3_InitPlatformInterface();
@ -256,7 +195,7 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
glUseProgram(g_ShaderHandle);
glUniform1i(g_AttribLocationTex, 0);
glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
#ifdef GL_SAMPLER_BINDING
#ifndef IMGUI_IMPL_OPENGL_ES2
glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise.
#endif
@ -398,11 +337,9 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
// Restore modified GL state
glUseProgram(last_program);
glBindTexture(GL_TEXTURE_2D, last_texture);
#ifdef GL_SAMPLER_BINDING
glBindSampler(0, last_sampler);
#endif
glActiveTexture(last_active_texture);
#ifndef IMGUI_IMPL_OPENGL_ES2
glBindSampler(0, last_sampler);
glBindVertexArray(last_vertex_array_object);
#endif
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);

View File

@ -2,6 +2,7 @@
#include "YBaseLib/Log.h"
#include "YBaseLib/MD5Digest.h"
#include "cpu_disasm.h"
#include <cerrno>
Log_SetChannel(BIOS);
namespace BIOS {
@ -56,7 +57,7 @@ std::optional<Image> LoadImageFromFile(std::string_view filename)
std::FILE* fp = std::fopen(filename_str.c_str(), "rb");
if (!fp)
{
Log_ErrorPrintf("Failed to open BIOS image '%s'", filename_str.c_str());
Log_ErrorPrintf("Failed to open BIOS image '%s', errno=%d", filename_str.c_str(), errno);
return std::nullopt;
}

View File

@ -34,8 +34,8 @@ bool GPU_HW_D3D11::Initialize(HostDisplay* host_display, System* system, DMA* dm
if (!GPU_HW::Initialize(host_display, system, dma, interrupt_controller, timers))
return false;
m_device = static_cast<ID3D11Device*>(host_display->GetHostRenderDevice());
m_context = static_cast<ID3D11DeviceContext*>(host_display->GetHostRenderContext());
m_device = static_cast<ID3D11Device*>(host_display->GetRenderDevice());
m_context = static_cast<ID3D11DeviceContext*>(host_display->GetRenderContext());
if (!m_device || !m_context)
return false;

View File

@ -29,8 +29,12 @@ public:
virtual ~HostDisplay() {}
virtual RenderAPI GetRenderAPI() const = 0;
virtual void* GetHostRenderDevice() const = 0;
virtual void* GetHostRenderContext() const = 0;
virtual void* GetRenderDevice() const = 0;
virtual void* GetRenderContext() const = 0;
virtual void* GetRenderWindow() const = 0;
/// Switches the render window, recreating the surface.
virtual void ChangeRenderWindow(void* new_window) = 0;
/// Creates an abstracted RGBA8 texture. If dynamic, the texture can be updated with UpdateTexture() below.
virtual std::unique_ptr<HostDisplayTexture> CreateTexture(u32 width, u32 height, const void* data, u32 data_stride,

View File

@ -78,16 +78,26 @@ HostDisplay::RenderAPI D3D11HostDisplay::GetRenderAPI() const
return HostDisplay::RenderAPI::D3D11;
}
void* D3D11HostDisplay::GetHostRenderDevice() const
void* D3D11HostDisplay::GetRenderDevice() const
{
return m_device.Get();
}
void* D3D11HostDisplay::GetHostRenderContext() const
void* D3D11HostDisplay::GetRenderContext() const
{
return m_context.Get();
}
void* D3D11HostDisplay::GetRenderWindow() const
{
return m_window;
}
void D3D11HostDisplay::ChangeRenderWindow(void* new_window)
{
Panic("Not supported");
}
std::unique_ptr<HostDisplayTexture> D3D11HostDisplay::CreateTexture(u32 width, u32 height, const void* data,
u32 data_stride, bool dynamic)
{

View File

@ -20,8 +20,11 @@ public:
static std::unique_ptr<HostDisplay> Create(SDL_Window* window);
RenderAPI GetRenderAPI() const override;
void* GetHostRenderDevice() const override;
void* GetHostRenderContext() const override;
void* GetRenderDevice() const override;
void* GetRenderContext() const override;
void* GetRenderWindow() const override;
void ChangeRenderWindow(void* new_window) override;
std::unique_ptr<HostDisplayTexture> CreateTexture(u32 width, u32 height, const void* data, u32 data_stride,
bool dynamic) override;

View File

@ -80,16 +80,26 @@ HostDisplay::RenderAPI OpenGLHostDisplay::GetRenderAPI() const
return m_is_gles ? HostDisplay::RenderAPI::OpenGLES : HostDisplay::RenderAPI::OpenGL;
}
void* OpenGLHostDisplay::GetHostRenderDevice() const
void* OpenGLHostDisplay::GetRenderDevice() const
{
return nullptr;
}
void* OpenGLHostDisplay::GetHostRenderContext() const
void* OpenGLHostDisplay::GetRenderContext() const
{
return m_gl_context;
}
void* OpenGLHostDisplay::GetRenderWindow() const
{
return m_window;
}
void OpenGLHostDisplay::ChangeRenderWindow(void* new_window)
{
Panic("Not implemented");
}
std::unique_ptr<HostDisplayTexture> OpenGLHostDisplay::CreateTexture(u32 width, u32 height, const void* data,
u32 data_stride, bool dynamic)
{

View File

@ -15,8 +15,11 @@ public:
static std::unique_ptr<HostDisplay> Create(SDL_Window* window);
RenderAPI GetRenderAPI() const override;
void* GetHostRenderDevice() const override;
void* GetHostRenderContext() const override;
void* GetRenderDevice() const override;
void* GetRenderContext() const override;
void* GetRenderWindow() const override;
void ChangeRenderWindow(void* new_window) override;
std::unique_ptr<HostDisplayTexture> CreateTexture(u32 width, u32 height, const void* data, u32 data_stride,
bool dynamic) override;