mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-06-08 06:32:59 +00:00
refactor: switch to glew for OpenGL loading
This commit is contained in:
parent
b0fac9fbc6
commit
a399023cca
|
|
@ -22,7 +22,7 @@ python = pymod.find_installation('python3', required: true)
|
|||
|
||||
cc = meson.get_compiler('cpp')
|
||||
|
||||
global_cpp_args = ['-Wshift-count-overflow', '-pipe']
|
||||
global_cpp_args = []
|
||||
global_cpp_defs = [
|
||||
'-DSPLIT_SAVES',
|
||||
'-D_LARGE_WORLDS',
|
||||
|
|
|
|||
12
subprojects/glew.wrap
Normal file
12
subprojects/glew.wrap
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[wrap-file]
|
||||
directory = glew-2.2.0
|
||||
source_url = http://downloads.sourceforge.net/glew/glew-2.2.0.tgz
|
||||
source_filename = glew-2.2.0.tgz
|
||||
source_hash = d4fc82893cfb00109578d0a1a2337fb8ca335b3ceccf97b97e5cc7f08e4353e1
|
||||
patch_filename = glew_2.2.0-2_patch.zip
|
||||
patch_url = https://wrapdb.mesonbuild.com/v2/glew_2.2.0-2/get_patch
|
||||
patch_hash = df7bc80456da53f83e93e89ca5035d04cdff19a836c956887a684b2bee16eb9b
|
||||
wrapdb_version = 2.2.0-2
|
||||
|
||||
[provide]
|
||||
glew = glew_dep
|
||||
|
|
@ -38,13 +38,6 @@
|
|||
#include "strings.h"
|
||||
#include "util/StringHelpers.h"
|
||||
|
||||
#if defined(_WINDOWS64)
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "../../../../../Windows64/Resource.h"
|
||||
#endif
|
||||
|
||||
#define GAME_CREATE_ONLINE_TIMER_ID 0
|
||||
#define GAME_CREATE_ONLINE_TIMER_TIME 100
|
||||
|
||||
|
|
|
|||
|
|
@ -1403,40 +1403,6 @@ void glDeleteTextures_4J(int n, const unsigned int* textures) {
|
|||
::glDeleteTextures(n, textures);
|
||||
}
|
||||
|
||||
// c hooks
|
||||
#undef glFogfv
|
||||
#undef glLightfv
|
||||
#undef glLightModelfv
|
||||
#undef glShadeModel
|
||||
#undef glColorMaterial
|
||||
#undef glNormal3f
|
||||
|
||||
extern "C" {
|
||||
void glFogfv(GLenum pname, const GLfloat* params) {
|
||||
if (pname == 0x0B66)
|
||||
PlatformRenderer.StateSetFogColour(params[0], params[1], params[2]);
|
||||
}
|
||||
void glLightfv(GLenum light, GLenum pname, const GLfloat* params) {
|
||||
if (pname == 0x1203)
|
||||
PlatformRenderer.StateSetLightDirection(
|
||||
light == 0x4000 ? 0 : 1, params[0], params[1], params[2]);
|
||||
else if (pname == 0x1200)
|
||||
PlatformRenderer.StateSetLightAmbientColour(params[0], params[1],
|
||||
params[2]);
|
||||
else if (pname == 0x1201)
|
||||
PlatformRenderer.StateSetLightColour(light == 0x4000 ? 0 : 1, params[0],
|
||||
params[1], params[2]);
|
||||
}
|
||||
void glLightModelfv(GLenum pname, const GLfloat* params) {
|
||||
if (pname == 0x0B53)
|
||||
PlatformRenderer.StateSetLightAmbientColour(params[0], params[1],
|
||||
params[2]);
|
||||
}
|
||||
void glShadeModel(GLenum) {}
|
||||
void glColorMaterial(GLenum, GLenum) {}
|
||||
void glNormal3f(GLfloat, GLfloat, GLfloat) {}
|
||||
}
|
||||
|
||||
// MARK: LinuxStubs
|
||||
|
||||
#ifdef GLES
|
||||
|
|
|
|||
|
|
@ -2,18 +2,16 @@
|
|||
|
||||
// windows hack: Windows SDK OpenGL headers include WINGDIAPI in their declarations,
|
||||
// which can only be found in the Windows API
|
||||
#ifdef _WIN32
|
||||
#if defined(_WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifndef GL_GLEXT_PROTOTYPES
|
||||
#define GL_GLEXT_PROTOTYPES 1
|
||||
#endif
|
||||
#include <GL/gl.h>
|
||||
// #include <GL/glext.h>
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#ifndef GL_ARRAY_BUFFER
|
||||
#define GL_ARRAY_BUFFER 0x8892
|
||||
#endif
|
||||
|
|
@ -32,24 +30,21 @@
|
|||
#ifndef GL_QUADS
|
||||
#define GL_QUADS 0x0007
|
||||
#endif
|
||||
|
||||
static inline bool gl3_load() {
|
||||
const char* ver = (const char*)glGetString(GL_VERSION);
|
||||
if (!ver) {
|
||||
fprintf(stderr, "[gl3_loader] ERROR: No active GL context found.\n");
|
||||
GLenum err = glewInit();
|
||||
if (err != GLEW_OK) {
|
||||
fprintf(stderr, "[gl_loader] ERROR: glewInit failed: %s\n",
|
||||
glewGetErrorString(err));
|
||||
return false;
|
||||
}
|
||||
int major = 0, minor = 0;
|
||||
if (sscanf(ver, "%d.%d", &major, &minor) >= 2) {
|
||||
if (major < 3 || (major == 3 && minor < 3)) {
|
||||
fprintf(stderr,
|
||||
"[gl3_loader] ERROR: Need GL 3.3, but system provides %s\n",
|
||||
ver);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GLEW_VERSION_3_3) {
|
||||
fprintf(stderr, "[gl_loader] ERROR: Need GL 3.3, not supported.\n");
|
||||
return false;
|
||||
}
|
||||
fprintf(
|
||||
stderr,
|
||||
"[gl3_loader] GL Version: %s, it's all okay!! until android support.\n",
|
||||
ver);
|
||||
|
||||
fprintf(stderr, "[gl_loader] GL %s loaded successfully.\n",
|
||||
(const char*)glewGetString(GLEW_VERSION));
|
||||
return true;
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
// rendering files compiling without dragging the concrete GLRenderer
|
||||
// class into every minecraft TU.
|
||||
|
||||
#include "gl3_loader.h"
|
||||
// #include "gl3_loader.h"
|
||||
// NOTE: gl3_loader.h must be included before these two
|
||||
#include <GL/gl.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ if get_option('renderer') == 'gles'
|
|||
platform_renderer_gl_dependencies += dependency('glesv2')
|
||||
platform_renderer_gl_defs = ['-DGLES']
|
||||
else
|
||||
platform_renderer_gl_dependencies += dependency('gl')
|
||||
platform_renderer_gl_dependencies += [dependency('gl'), dependency('glew')]
|
||||
platform_renderer_gl_defs = []
|
||||
endif
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
// windows hack: Windows SDK OpenGL headers include WINGDIAPI in their declarations,
|
||||
// which can only be found in the Windows API
|
||||
#ifdef _WIN32
|
||||
#if defined(_WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@
|
|||
#include <thread>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <Windows.h>
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
|
|
@ -82,46 +84,46 @@ std::int64_t getNativeThreadId() {
|
|||
|
||||
void setThreadNamePlatform([[maybe_unused]] std::uint32_t threadId,
|
||||
[[maybe_unused]] const char* name) {
|
||||
#if defined(_WIN32)
|
||||
// Try modern API first (Windows 10 1607+).
|
||||
if (threadId == static_cast<std::uint32_t>(-1) ||
|
||||
threadId == ::GetCurrentThreadId()) {
|
||||
using SetThreadDescriptionFn = int32_t(WINAPI*)(void*, PCWSTR);
|
||||
const HMODULE kernel = ::GetModuleHandleW("Kernel32.dll");
|
||||
if (kernel) {
|
||||
const auto fn = reinterpret_cast<SetThreadDescriptionFn>(
|
||||
::GetProcAddress(kernel, "SetThreadDescription"));
|
||||
if (fn) {
|
||||
char wide[64];
|
||||
const auto n = std::strncpy(
|
||||
wide, name, (sizeof(wide) / sizeof(wide[0])) - 1);
|
||||
if (n != static_cast<std::size_t>(-1)) {
|
||||
wide[n] = '\0';
|
||||
(void)fn(::GetCurrentThread(), wide);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// #if defined(_WIN32)
|
||||
// // Try modern API first (Windows 10 1607+).
|
||||
// if (threadId == static_cast<std::uint32_t>(-1) ||
|
||||
// threadId == ::GetCurrentThreadId()) {
|
||||
// using SetThreadDescriptionFn = int32_t(WINAPI*)(void*, PCWSTR);
|
||||
// const HMODULE kernel = ::GetModuleHandleA("Kernel32.dll");
|
||||
// if (kernel) {
|
||||
// const auto fn = reinterpret_cast<SetThreadDescriptionFn>(
|
||||
// ::GetProcAddress(kernel, "SetThreadDescription"));
|
||||
// if (fn) {
|
||||
// char wide[64];
|
||||
// const auto n = std::strncpy(
|
||||
// wide, name, (sizeof(wide) / sizeof(wide[0])) - 1);
|
||||
// if (n != static_cast<std::size_t>(-1)) {
|
||||
// wide[n] = '\0';
|
||||
// (void)fn(::GetCurrentThread(), wide);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// Legacy fallback: raise exception 0x406D1388 for older MSVC debuggers.
|
||||
#pragma pack(push, 8)
|
||||
struct THREADNAME_INFO {
|
||||
std::uint32_t dwType;
|
||||
const char* szName;
|
||||
std::uint32_t dwThreadID;
|
||||
std::uint32_t dwFlags;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
// // Legacy fallback: raise exception 0x406D1388 for older MSVC debuggers.
|
||||
// #pragma pack(push, 8)
|
||||
// struct THREADNAME_INFO {
|
||||
// std::uint32_t dwType;
|
||||
// const char* szName;
|
||||
// std::uint32_t dwThreadID;
|
||||
// std::uint32_t dwFlags;
|
||||
// };
|
||||
// #pragma pack(pop)
|
||||
|
||||
THREADNAME_INFO info{0x1000, name, threadId, 0};
|
||||
__try {
|
||||
::RaiseException(0x406D1388, 0, sizeof(info) / sizeof(uintptr_t),
|
||||
reinterpret_cast<uintptr_t*>(&info));
|
||||
} __except (EXCEPTION_EXECUTE_HANDLER) {
|
||||
}
|
||||
// THREADNAME_INFO info{0x1000, name, threadId, 0};
|
||||
// __try {
|
||||
// ::RaiseException(0x406D1388, 0, sizeof(info) / sizeof(uintptr_t),
|
||||
// reinterpret_cast<uintptr_t*>(&info));
|
||||
// } __except (EXCEPTION_EXECUTE_HANDLER) {
|
||||
// }
|
||||
|
||||
#elif defined(__linux__)
|
||||
#if defined(__linux__)
|
||||
// pthread_setname_np limit: 16 chars including null terminator.
|
||||
char truncated[16];
|
||||
std::snprintf(truncated, sizeof(truncated), "%s", name);
|
||||
|
|
|
|||
Loading…
Reference in a new issue