[OpenGL] Use GLAD instead on gl3w and hook EGL

pull/131/head
jackun 4 years ago
parent 772ab6aa5b
commit 780ea7c89b
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -0,0 +1,290 @@
#ifndef __khrplatform_h_
#define __khrplatform_h_
/*
** Copyright (c) 2008-2018 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
/* Khronos platform-specific types and definitions.
*
* The master copy of khrplatform.h is maintained in the Khronos EGL
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
* The last semantic modification to khrplatform.h was at commit ID:
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
*
* Adopters may modify this file to suit their platform. Adopters are
* encouraged to submit platform specific modifications to the Khronos
* group so that they can be included in future versions of this file.
* Please submit changes by filing pull requests or issues on
* the EGL Registry repository linked above.
*
*
* See the Implementer's Guidelines for information about where this file
* should be located on your system and for more details of its use:
* http://www.khronos.org/registry/implementers_guide.pdf
*
* This file should be included as
* #include <KHR/khrplatform.h>
* by Khronos client API header files that use its types and defines.
*
* The types in khrplatform.h should only be used to define API-specific types.
*
* Types defined in khrplatform.h:
* khronos_int8_t signed 8 bit
* khronos_uint8_t unsigned 8 bit
* khronos_int16_t signed 16 bit
* khronos_uint16_t unsigned 16 bit
* khronos_int32_t signed 32 bit
* khronos_uint32_t unsigned 32 bit
* khronos_int64_t signed 64 bit
* khronos_uint64_t unsigned 64 bit
* khronos_intptr_t signed same number of bits as a pointer
* khronos_uintptr_t unsigned same number of bits as a pointer
* khronos_ssize_t signed size
* khronos_usize_t unsigned size
* khronos_float_t signed 32 bit floating point
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
* nanoseconds
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
* khronos_boolean_enum_t enumerated boolean type. This should
* only be used as a base type when a client API's boolean type is
* an enum. Client APIs which use an integer or other type for
* booleans cannot use this as the base type for their boolean.
*
* Tokens defined in khrplatform.h:
*
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
*
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
*
* Calling convention macros defined in this file:
* KHRONOS_APICALL
* KHRONOS_APIENTRY
* KHRONOS_APIATTRIBUTES
*
* These may be used in function prototypes as:
*
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
* int arg1,
* int arg2) KHRONOS_APIATTRIBUTES;
*/
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
# define KHRONOS_STATIC 1
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APICALL
*-------------------------------------------------------------------------
* This precedes the return type of the function in the function prototype.
*/
#if defined(KHRONOS_STATIC)
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
* header compatible with static linking. */
# define KHRONOS_APICALL
#elif defined(_WIN32)
# define KHRONOS_APICALL __declspec(dllimport)
#elif defined (__SYMBIAN32__)
# define KHRONOS_APICALL IMPORT_C
#elif defined(__ANDROID__)
# define KHRONOS_APICALL __attribute__((visibility("default")))
#else
# define KHRONOS_APICALL
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APIENTRY
*-------------------------------------------------------------------------
* This follows the return type of the function and precedes the function
* name in the function prototype.
*/
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(KHRONOS_STATIC)
/* Win32 but not WinCE */
# define KHRONOS_APIENTRY __stdcall
#else
# define KHRONOS_APIENTRY
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APIATTRIBUTES
*-------------------------------------------------------------------------
* This follows the closing parenthesis of the function prototype arguments.
*/
#if defined (__ARMCC_2__)
#define KHRONOS_APIATTRIBUTES __softfp
#else
#define KHRONOS_APIATTRIBUTES
#endif
/*-------------------------------------------------------------------------
* basic type definitions
*-----------------------------------------------------------------------*/
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
/*
* Using <stdint.h>
*/
#include <stdint.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(__VMS ) || defined(__sgi)
/*
* Using <inttypes.h>
*/
#include <inttypes.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
/*
* Win32
*/
typedef __int32 khronos_int32_t;
typedef unsigned __int32 khronos_uint32_t;
typedef __int64 khronos_int64_t;
typedef unsigned __int64 khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(__sun__) || defined(__digital__)
/*
* Sun or Digital
*/
typedef int khronos_int32_t;
typedef unsigned int khronos_uint32_t;
#if defined(__arch64__) || defined(_LP64)
typedef long int khronos_int64_t;
typedef unsigned long int khronos_uint64_t;
#else
typedef long long int khronos_int64_t;
typedef unsigned long long int khronos_uint64_t;
#endif /* __arch64__ */
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif 0
/*
* Hypothetical platform with no float or int64 support
*/
typedef int khronos_int32_t;
typedef unsigned int khronos_uint32_t;
#define KHRONOS_SUPPORT_INT64 0
#define KHRONOS_SUPPORT_FLOAT 0
#else
/*
* Generic fallback
*/
#include <stdint.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#endif
/*
* Types that are (so far) the same on all platforms
*/
typedef signed char khronos_int8_t;
typedef unsigned char khronos_uint8_t;
typedef signed short int khronos_int16_t;
typedef unsigned short int khronos_uint16_t;
/*
* Types that differ between LLP64 and LP64 architectures - in LLP64,
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
* to be the only LLP64 architecture in current use.
*/
#ifdef _WIN64
typedef signed long long int khronos_intptr_t;
typedef unsigned long long int khronos_uintptr_t;
typedef signed long long int khronos_ssize_t;
typedef unsigned long long int khronos_usize_t;
#else
typedef signed long int khronos_intptr_t;
typedef unsigned long int khronos_uintptr_t;
typedef signed long int khronos_ssize_t;
typedef unsigned long int khronos_usize_t;
#endif
#if KHRONOS_SUPPORT_FLOAT
/*
* Float type
*/
typedef float khronos_float_t;
#endif
#if KHRONOS_SUPPORT_INT64
/* Time types
*
* These types can be used to represent a time interval in nanoseconds or
* an absolute Unadjusted System Time. Unadjusted System Time is the number
* of nanoseconds since some arbitrary system event (e.g. since the last
* time the system booted). The Unadjusted System Time is an unsigned
* 64 bit value that wraps back to 0 every 584 years. Time intervals
* may be either signed or unsigned.
*/
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
typedef khronos_int64_t khronos_stime_nanoseconds_t;
#endif
/*
* Dummy value used to pad enum types to 32 bits.
*/
#ifndef KHRONOS_MAX_ENUM
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
#endif
/*
* Enumerated boolean type
*
* Values other than zero should be considered to be true. Therefore
* comparisons should not be made against KHRONOS_TRUE.
*/
typedef enum {
KHRONOS_FALSE = 0,
KHRONOS_TRUE = 1,
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
} khronos_boolean_enum_t;
#endif /* __khrplatform_h_ */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -7,9 +7,7 @@
#include "imgui_hud_shared.h"
#include "imgui_hud.h"
#ifdef IMGUI_GLX
#include "GL/gl3w.h"
#endif
#include <glad/glad.h>
namespace MangoHud { namespace GL {
@ -48,7 +46,8 @@ static state state;
static uint32_t vendorID;
static std::string deviceName;
static void imgui_create(void *ctx)
//static
void imgui_create(void *ctx)
{
if (inited)
return;
@ -59,6 +58,8 @@ static void imgui_create(void *ctx)
imgui_init();
gladLoadGL();
std::cerr << "GL version: " << glGetString(GL_VERSION) << std::endl;
glGetIntegerv(GL_MAJOR_VERSION, &sw_stats.version_gl.major);
glGetIntegerv(GL_MINOR_VERSION, &sw_stats.version_gl.minor);
@ -117,7 +118,7 @@ static void imgui_create(void *ctx)
// Restore global context or ours might clash with apps that use Dear ImGui
ImGui::SetCurrentContext(saved_ctx);
}
/*
#ifdef IMGUI_GLX
void VARIANT(imgui_create)(void *ctx)
{
@ -127,7 +128,6 @@ void VARIANT(imgui_create)(void *ctx)
if (!ctx)
return;
gl3wInit();
imgui_create(ctx);
}
#endif
@ -143,7 +143,7 @@ void VARIANT(imgui_create)(void *ctx)
imgui_create(ctx);
}
#endif
#endif*/
void VARIANT(imgui_shutdown)()
{

@ -68,20 +68,7 @@
#include <stdio.h>
#include <stdint.h> // intptr_t
#ifdef IMGUI_GLX
#include <GL/gl3w.h>
#endif
#ifdef IMGUI_GLX
#define GL_CLIP_ORIGIN 0x935C
#define GL_NEGATIVE_ONE_TO_ONE 0x935E
#define GL_ZERO_TO_ONE 0x935F
#define GL_CLIP_DEPTH_MODE 0x935D
void* get_glx_proc_address(const char* name);
void (*glClipControl)(int origin, int depth) = nullptr;
#endif
#include <glad/glad.h>
namespace MangoHud {
@ -100,6 +87,7 @@ static GLuint g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0; // Uniforms location
static int g_AttribLocationVtxPos = 0, g_AttribLocationVtxUV = 0, g_AttribLocationVtxColor = 0; // Vertex attributes location
static unsigned int g_VboHandle = 0, g_ElementsHandle = 0;
static bool g_IsGLES = false;
// Functions
static bool ImGui_ImplOpenGL3_CreateFontsTexture()
@ -380,27 +368,40 @@ static void ImGui_ImplOpenGL3_DestroyDeviceObjects()
bool VARIANT(ImGui_ImplOpenGL3_Init)(const char* glsl_version)
{
#ifdef IMGUI_GLX
glClipControl = reinterpret_cast<decltype(glClipControl)> (get_glx_proc_address("glClipControl"));
#endif
// Query for GL version
#if !defined(IMGUI_IMPL_OPENGL_ES2)
const char *glVersionStr = (const char *)glGetString(GL_VERSION);
glsl_version = "#version 130";
GLint major = -1, minor = -1;
glGetIntegerv(GL_MAJOR_VERSION, &major);
glGetIntegerv(GL_MINOR_VERSION, &minor);
g_GlVersion = major * 1000 + minor;
printf("Version: %d.%d\n", major, minor);
if (major >= 4 && minor >= 1)
glsl_version = "#version 410";
else if (major > 3 || (major == 3 && minor >= 2))
glsl_version = "#version 150";
#else
g_GlVersion = 2000; // GLES 2
#endif
if (strncmp(glVersionStr, "OpenGL ES", 9)) {
// Not GL ES
glsl_version = "#version 130";
g_GlVersion = major * 1000 + minor;
printf("Version: %d.%d\n", major, minor);
if (major >= 4 && minor >= 1)
glsl_version = "#version 410";
else if (major > 3 || (major == 3 && minor >= 2))
glsl_version = "#version 150";
else if (major < 2)
glsl_version = "#version 100";
} else {
g_IsGLES = true;
if (major >= 3)
g_GlVersion = major * 1000 + minor; // GLES >= 3
else
g_GlVersion = 2000; // GLES 2
// 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 (g_GlVersion == 2000)
glsl_version = "#version 100";
else if (g_GlVersion >= 3000)
glsl_version = "#version 300 es";
else
glsl_version = "#version 130";
}
// Setup back-end capabilities flags
ImGuiIO& io = ImGui::GetIO();
@ -448,9 +449,10 @@ static void VARIANT(ImGui_ImplOpenGL3_SetupRenderState)(ImDrawData* draw_data, i
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glEnable(GL_SCISSOR_TEST);
#ifdef GL_POLYGON_MODE
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
#endif
//#ifdef GL_POLYGON_MODE
if (!g_IsGLES && g_GlVersion >= 2000)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// Setup viewport, orthographic projection matrix
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
@ -469,14 +471,14 @@ static void VARIANT(ImGui_ImplOpenGL3_SetupRenderState)(ImDrawData* draw_data, i
glUseProgram(g_ShaderHandle);
glUniform1i(g_AttribLocationTex, 0);
glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
#ifdef GL_SAMPLER_BINDING
glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise.
#endif
if (g_GlVersion >= 3003)
glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise.
(void)vertex_array_object;
#ifndef IMGUI_IMPL_OPENGL_ES2
glBindVertexArray(vertex_array_object);
#endif
//#ifndef IMGUI_IMPL_OPENGL_ES2
if (!g_IsGLES || (g_IsGLES && g_GlVersion >= 3000))
glBindVertexArray(vertex_array_object);
// Bind vertex/index buffers and setup attributes for ImDrawVert
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
@ -505,16 +507,23 @@ void VARIANT(ImGui_ImplOpenGL3_RenderDrawData)(ImDrawData* draw_data)
glActiveTexture(GL_TEXTURE0);
GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
#ifdef GL_SAMPLER_BINDING
GLint last_sampler; glGetIntegerv(GL_SAMPLER_BINDING, &last_sampler);
#endif
// GL_SAMPLER_BINDING
GLint last_sampler;
if (!g_IsGLES && g_GlVersion >= 3003)
glGetIntegerv(GL_SAMPLER_BINDING, &last_sampler);
GLint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
#ifndef IMGUI_IMPL_OPENGL_ES2
GLint last_vertex_array_object; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array_object);
#endif
#ifdef GL_POLYGON_MODE
GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
#endif
//#ifndef IMGUI_IMPL_OPENGL_ES2
GLint last_vertex_array_object;
if (!g_IsGLES || (g_IsGLES && g_GlVersion >= 3000))
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array_object);
GLint last_polygon_mode[2];
if (!g_IsGLES && g_GlVersion >= 2000)
glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box);
GLenum last_blend_src_rgb; glGetIntegerv(GL_BLEND_SRC_RGB, (GLint*)&last_blend_src_rgb);
@ -528,23 +537,25 @@ void VARIANT(ImGui_ImplOpenGL3_RenderDrawData)(ImDrawData* draw_data)
GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST);
GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
bool clip_origin_lower_left = true;
#if defined(GL_CLIP_ORIGIN) && !defined(__APPLE__)
GLenum last_clip_origin = 0; glGetIntegerv(GL_CLIP_ORIGIN, (GLint*)&last_clip_origin); // Support for GL 4.5's glClipControl(GL_UPPER_LEFT)
GLenum last_clip_depth_mode = 0; glGetIntegerv(GL_CLIP_DEPTH_MODE, (GLint*)&last_clip_depth_mode);
if (last_clip_origin == GL_UPPER_LEFT) {
clip_origin_lower_left = false;
if (glClipControl)
glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
}
#endif
GLenum last_clip_origin = 0;
GLenum last_clip_depth_mode = 0;
if (!g_IsGLES && /*g_GlVersion >= 4005*/ (glad_glClipControl || glad_glClipControlEXT)) {
glGetIntegerv(GL_CLIP_ORIGIN, (GLint*)&last_clip_origin); // Support for GL 4.5's glClipControl(GL_UPPER_LEFT)
glGetIntegerv(GL_CLIP_DEPTH_MODE, (GLint*)&last_clip_depth_mode);
if (last_clip_origin == GL_UPPER_LEFT) {
clip_origin_lower_left = false;
if (glClipControl)
glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
}
}
// Setup desired GL state
// Recreate the VAO every time (this is to easily allow multiple GL contexts to be rendered to. VAO are not shared among GL contexts)
// The renderer would actually work without any VAO bound, but then our VertexAttrib calls would overwrite the default one currently bound.
GLuint vertex_array_object = 0;
#ifndef IMGUI_IMPL_OPENGL_ES2
glGenVertexArrays(1, &vertex_array_object);
#endif
if (!g_IsGLES || (g_IsGLES && g_GlVersion >= 3000))
glGenVertexArrays(1, &vertex_array_object);
VARIANT(ImGui_ImplOpenGL3_SetupRenderState)(draw_data, fb_width, fb_height, vertex_array_object);
// Will project scissor/clipping rectangles into framebuffer space
@ -603,20 +614,21 @@ void VARIANT(ImGui_ImplOpenGL3_RenderDrawData)(ImDrawData* draw_data)
}
// Destroy the temporary VAO
#ifndef IMGUI_IMPL_OPENGL_ES2
glDeleteVertexArrays(1, &vertex_array_object);
#endif
if (!g_IsGLES || (g_IsGLES && g_GlVersion >= 3000))
glDeleteVertexArrays(1, &vertex_array_object);
// Restore modified GL state
glUseProgram(last_program);
glBindTexture(GL_TEXTURE_2D, last_texture);
#ifdef GL_SAMPLER_BINDING
glBindSampler(0, last_sampler);
#endif
if (!g_IsGLES && g_GlVersion >= 3003)
glBindSampler(0, last_sampler);
glActiveTexture(last_active_texture);
#ifndef IMGUI_IMPL_OPENGL_ES2
glBindVertexArray(last_vertex_array_object);
#endif
if (!g_IsGLES || (g_IsGLES && g_GlVersion >= 3000))
glBindVertexArray(last_vertex_array_object);
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha);
glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
@ -624,16 +636,16 @@ void VARIANT(ImGui_ImplOpenGL3_RenderDrawData)(ImDrawData* draw_data)
if (last_enable_cull_face) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
if (last_enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
#ifdef GL_POLYGON_MODE
glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]);
#endif
if (!g_IsGLES && g_GlVersion >= 2000)
glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]);
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]);
#if defined(GL_CLIP_ORIGIN) && !defined(__APPLE__)
if (!clip_origin_lower_left && glClipControl)
glClipControl(last_clip_origin, last_clip_depth_mode);
#endif
if (!g_IsGLES && /*g_GlVersion >= 4005*/ glad_glClipControl)
if (!clip_origin_lower_left && glClipControl)
glClipControl(last_clip_origin, last_clip_depth_mode);
}
}

@ -25,6 +25,7 @@
namespace MangoHud {
/*
#if defined(IMGUI_GLX) && defined(IMGUI_EGL)
#error Both IMGUI_GLX and IMGUI_EGL can not be defined at the same time!
#elif !defined(IMGUI_GLX) && !defined(IMGUI_EGL)
@ -39,6 +40,10 @@ namespace MangoHud {
#ifdef IMGUI_EGL
#define VARIANT(x) x##_EGL
#endif
*/
// FIXME might not be needed, GLX/EGL _can_ maybe live together
#define VARIANT(x) x
// Backend API
IMGUI_IMPL_API bool VARIANT(ImGui_ImplOpenGL3_Init)(const char* glsl_version = nullptr);

@ -0,0 +1,103 @@
#include <iostream>
#include <array>
#include <cstring>
#include "real_dlsym.h"
#include "mesa/util/macros.h"
#include "mesa/util/os_time.h"
#include <chrono>
#include <iomanip>
#include "imgui_hud_shared.h"
#include "imgui_hud.h"
using namespace MangoHud::GL;
#define EXPORT_C_(type) extern "C" __attribute__((__visibility__("default"))) type
EXPORT_C_(void *) eglGetProcAddress(const char* procName);
void* get_egl_proc_address(const char* name) {
void *func = nullptr;
static void *(*pfn_eglGetProcAddress)(const char*) = nullptr;
if (!pfn_eglGetProcAddress)
pfn_eglGetProcAddress = reinterpret_cast<decltype(pfn_eglGetProcAddress)>(get_proc_address("eglGetProcAddress"));
if (pfn_eglGetProcAddress)
func = pfn_eglGetProcAddress(name);
if (!func)
func = get_proc_address( name );
if (!func) {
std::cerr << "MANGOHUD: Failed to get function '" << name << "'" << std::endl;
}
return func;
}
//EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
EXPORT_C_(int) eglMakeCurrent_OFF(void *dpy, void *draw, void *read,void *ctx) {
#ifndef NDEBUG
std::cerr << __func__ << ": " << draw << ", " << ctx << std::endl;
#endif
int ret = 0;
return ret;
}
EXPORT_C_(unsigned int) eglSwapBuffers( void* dpy, void* surf)
{
static int (*pfn_eglSwapBuffers)(void*, void*) = nullptr;
if (!pfn_eglSwapBuffers)
pfn_eglSwapBuffers = reinterpret_cast<decltype(pfn_eglSwapBuffers)>(get_proc_address("eglSwapBuffers"));
static int (*pfn_eglQuerySurface)(void* dpy, void* surface, int attribute, int *value) = nullptr;
if (!pfn_eglQuerySurface)
pfn_eglQuerySurface = reinterpret_cast<decltype(pfn_eglQuerySurface)>(get_proc_address("eglQuerySurface"));
//std::cerr << __func__ << "\n";
VARIANT(imgui_create)(surf);
int width=0, height=0;
if (pfn_eglQuerySurface(dpy, surf, 0x3056, &height) &&
pfn_eglQuerySurface(dpy, surf, 0x3057, &width))
VARIANT(imgui_render)(width, height);
//std::cerr << "\t" << width << " x " << height << "\n";
return pfn_eglSwapBuffers(dpy, surf);
}
struct func_ptr {
const char *name;
void *ptr;
};
static std::array<const func_ptr, 1> name_to_funcptr_map = {{
#define ADD_HOOK(fn) { #fn, (void *) fn }
ADD_HOOK(eglGetProcAddress),
#undef ADD_HOOK
}};
void *find_egl_ptr(const char *name)
{
for (auto& func : name_to_funcptr_map) {
if (strcmp(name, func.name) == 0)
return func.ptr;
}
return nullptr;
}
EXPORT_C_(void *) eglGetProcAddress(const char* procName) {
std::cerr << __func__ << ": " << procName << std::endl;
void* func = find_egl_ptr(procName);
if (func)
return func;
return get_egl_proc_address(procName);
}

@ -23,16 +23,6 @@ EXPORT_C_(void *) glXGetProcAddressARB(const unsigned char* procName);
static glx_loader glx;
void* get_proc_address(const char* name) {
void (*func)() = (void (*)())real_dlsym( RTLD_NEXT, name );
if (!func) {
std::cerr << "MANGOHUD: Failed to get function '" << name << "'" << std::endl;
}
return (void*)func;
}
void* get_glx_proc_address(const char* name) {
glx.Load();

@ -57,10 +57,13 @@ vklayer_files = files(
opengl_files = files(
'gl/imgui_hud_shared.cpp',
'gl/glad.c',
'gl/imgui_impl_opengl3.cpp',
'gl/imgui_hud.cpp',
'gl/inject_egl.cpp',
)
pre_args += '-DHOOK_DLSYM'
inc_opengl = include_directories('gl/gl3w')
glimgui_glx_dep = null_dep
glimgui_egl_dep = null_dep
@ -76,7 +79,6 @@ if get_option('with_x11').enabled() and \
endif
if get_option('with_x11').enabled()
glx_h_dep = cc.has_header('GL/glx.h')
pre_args += '-DHAVE_X11'
vklayer_files += files(
@ -86,71 +88,8 @@ if get_option('with_x11').enabled()
opengl_files += files(
'loaders/loader_glx.cpp',
'gl/inject_glx.cpp',
)
# build with GLX functions
glimgui_glx = static_library(
'glimgui_glx',
files(
'gl/inject_glx.cpp',
'gl/imgui_impl_opengl3.cpp',
'gl/imgui_hud.cpp',
'gl/gl3w/GL/gl3w.c',
),
pic : true,
c_args : [
pre_args,
c_vis_args,
no_override_init_args,
'-DIMGUI_GLX',
],
cpp_args : [
pre_args,
cpp_vis_args,
'-DIMGUI_GLX',
],
dependencies : [
libimgui_core_dep,
],
include_directories : [inc_common, inc_opengl],
)
glimgui_glx_dep = declare_dependency(
link_with : glimgui_glx,
)
endif
if false
#if get_option('with_wayland').enabled()
# build with EGL functions
glimgui_egl = static_library(
'glimgui_egl',
files(
'gl/imgui_impl_opengl3.cpp',
'gl/imgui_hud.cpp',
),
pic : true,
c_args : [
pre_args,
c_vis_args,
no_override_init_args,
'-DIMGUI_EGL',
],
cpp_args : [
pre_args,
cpp_vis_args,
'-DIMGUI_EGL',
],
dependencies : [
libimgui_core_dep,
],
include_directories : [inc_common, inc_opengl],
)
glimgui_egl_dep = declare_dependency(
link_with : glimgui_egl,
)
endif
if dbus_dep.found() and get_option('with_dbus').enabled()
@ -189,7 +128,7 @@ vklayer_mesa_overlay = shared_library(
dep_dl,
dep_pthread,
dep_vulkan],
include_directories : [inc_common, inc_opengl],
include_directories : [inc_common],
link_args : cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions', '-Wl,-z,relro']),
install_dir : libdir_mangohud,
install : true

@ -82,20 +82,32 @@ void *real_dlsym(void *handle, const char *symbol)
return result;
}
void* get_proc_address(const char* name) {
void (*func)() = (void (*)())real_dlsym(RTLD_NEXT, name);
return (void*)func;
}
#ifdef HOOK_DLSYM
extern void *find_glx_ptr(const char *name);
extern void *find_egl_ptr(const char *name);
EXPORT_C_(void*) dlsym(void * handle, const char * name)
{
void* func = nullptr;
#ifdef HAVE_X11
void* func = find_glx_ptr(name);
func = find_glx_ptr(name);
if (func) {
//fprintf(stderr,"%s: local: %s\n", __func__ , name);
return func;
}
#endif
func = find_egl_ptr(name);
if (func) {
//fprintf(stderr,"%s: local: %s\n", __func__ , name);
return func;
}
//fprintf(stderr,"%s: foreign: %s\n", __func__ , name);
return real_dlsym(handle, name);
}

@ -4,3 +4,4 @@
void *real_dlopen(const char *filename, int flag);
void* real_dlsym( void*, const char* );
void* get_proc_address(const char* name);

Loading…
Cancel
Save