mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-05-01 10:43:42 +00:00
Initial Android Support
This commit is contained in:
parent
1ea1801271
commit
fa6861b221
|
|
@ -73,6 +73,13 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#ifdef __android__
|
||||
#include <android/log.h>
|
||||
|
||||
#define TAG "4JCRAFT"
|
||||
#define AndroidPrintf(...) do { __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__); printf( __VA_ARGS__); } while( 0 );
|
||||
#endif
|
||||
|
||||
#include "platform/sdl2/Input.h"
|
||||
#include "app/common/src/Audio/SoundEngine.h"
|
||||
#include "app/common/src/Colours/ColourTable.h"
|
||||
|
|
@ -249,8 +256,12 @@ void Game::DebugPrintf(const char* szFormat, ...) {
|
|||
va_start(ap, szFormat);
|
||||
vsnprintf(buf, sizeof(buf), szFormat, ap);
|
||||
va_end(ap);
|
||||
#if defined(__android__)
|
||||
AndroidPrintf("%s", buf);
|
||||
#else
|
||||
OutputDebugStringA(buf);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void Game::DebugPrintf(int user, const char* szFormat, ...) {
|
||||
|
|
@ -261,7 +272,11 @@ void Game::DebugPrintf(int user, const char* szFormat, ...) {
|
|||
va_start(ap, szFormat);
|
||||
vsnprintf(buf, sizeof(buf), szFormat, ap);
|
||||
va_end(ap);
|
||||
#if defined(__android__)
|
||||
AndroidPrintf("%s", buf);
|
||||
#else
|
||||
OutputDebugStringA(buf);
|
||||
#endif
|
||||
if (user == USER_UI) {
|
||||
ui.logDebugString(buf);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "app/common/src/UI/Controls/UIControl_MinecraftHorse.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "UIControl_MinecraftPlayer.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
|
|
|
|||
|
|
@ -2,8 +2,12 @@
|
|||
|
||||
#include <string>
|
||||
#ifdef __linux__
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#endif
|
||||
|
||||
#undef GL_SMOOTH
|
||||
#undef GL_FLAT
|
||||
|
|
@ -166,7 +170,13 @@ public:
|
|||
static const int GL_FLAT = 0x1D00;
|
||||
#undef glShadeModel
|
||||
#define GL_SHADEMODEL_IS_FUNCTION
|
||||
static void glShadeModel(int mode) { ::glShadeModel(mode); }
|
||||
static void glShadeModel(int mode) {
|
||||
#ifdef GLES
|
||||
glShadeModel(mode);
|
||||
#else
|
||||
::glShadeModel(mode);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
#undef GL_ARRAY_BUFFER_ARB
|
||||
#undef GL_STREAM_DRAW_ARB
|
||||
|
|
|
|||
|
|
@ -2,6 +2,16 @@
|
|||
|
||||
#include "gdraw.h"
|
||||
|
||||
// Do we really really need gdraw for the java ui?
|
||||
#ifndef _ENABLEIGGY
|
||||
void gdraw_GL_BeginCustomDraw_4J(IggyCustomDrawCallbackRegion* region, F32* matrix) {}
|
||||
void gdraw_GL_CalculateCustomDraw_4J(IggyCustomDrawCallbackRegion* region, F32* matrix) {}
|
||||
void gdraw_GL_EndCustomDraw(IggyCustomDrawCallbackRegion* region) {}
|
||||
void gdraw_GL_SetTileOrigin(S32 vx, S32 vy, unsigned int framebuffer) {}
|
||||
void gdraw_GL_WrappedTextureDestroy(GDrawTexture* handle) {}
|
||||
|
||||
#else
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <dlfcn.h>
|
||||
#include <stdbool.h>
|
||||
|
|
@ -838,3 +848,4 @@ void gdraw_GL_CalculateCustomDraw_4J(IggyCustomDrawCallbackRegion* region,
|
|||
F32* matrix) {
|
||||
gdraw_GetObjectSpaceMatrix(matrix, region->o2w, gdraw->projection, 0.0f, 0);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -11,17 +11,14 @@ extern C4JRender RenderManager;
|
|||
|
||||
#ifdef GLES
|
||||
extern "C" {
|
||||
extern void glClearDepthf(float depth);
|
||||
void glClearDepth(double depth) { glClearDepthf((float)depth); }
|
||||
void glTexGeni(unsigned int, unsigned int, int) {}
|
||||
void glTexGenfv(unsigned int, unsigned int, const float*) {}
|
||||
void glTexCoordPointer(int, unsigned int, int, const void*) {}
|
||||
void glNormalPointer(unsigned int, int, const void*) {}
|
||||
void glColorPointer(int, unsigned int, int, const void*) {}
|
||||
void glVertexPointer(int, unsigned int, int, const void*) {}
|
||||
void glEndList(void) {}
|
||||
void glCallLists(int, unsigned int, const void*) {}
|
||||
void glTexGeni(GLenum, GLenum, GLint) {}
|
||||
}
|
||||
void glTexGenfv(unsigned int, unsigned int, const float*) {}
|
||||
void glTexCoordPointer(int, unsigned int, int) {}
|
||||
void glNormalPointer(unsigned int, int) {}
|
||||
void glColorPointer(int, unsigned int, int, const void*) {}
|
||||
void glVertexPointer(int, unsigned int, int) {}
|
||||
void glCallLists(int) {}
|
||||
#endif
|
||||
|
||||
inline int* getIntPtr(IntBuffer* buf) {
|
||||
|
|
@ -110,14 +107,32 @@ void glTexGen_4J(int, int, FloatBuffer*) {}
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef GLES
|
||||
static PFNGLGENQUERIESPROC _glGenQueriesARB = nullptr;
|
||||
static PFNGLBEGINQUERYPROC _glBeginQueryARB = nullptr;
|
||||
static PFNGLENDQUERYPROC _glEndQueryARB = nullptr;
|
||||
static PFNGLGETQUERYOBJECTUIVPROC _glGetQueryObjectuivARB = nullptr;
|
||||
static bool _queriesInitialized = false;
|
||||
#else
|
||||
static PFNGLGENQUERIESARBPROC _glGenQueriesARB = nullptr;
|
||||
static PFNGLBEGINQUERYARBPROC _glBeginQueryARB = nullptr;
|
||||
static PFNGLENDQUERYARBPROC _glEndQueryARB = nullptr;
|
||||
static PFNGLGETQUERYOBJECTUIVARBPROC _glGetQueryObjectuivARB = nullptr;
|
||||
static bool _queriesInitialized = false;
|
||||
#endif
|
||||
|
||||
static void initQueryFuncs() {
|
||||
if (_queriesInitialized) return;
|
||||
#ifdef GLES
|
||||
_queriesInitialized = true;
|
||||
_glGenQueriesARB =
|
||||
(PFNGLGENQUERIESPROC)dlsym(RTLD_DEFAULT, "glGenQueries");
|
||||
_glBeginQueryARB =
|
||||
(PFNGLBEGINQUERYPROC)dlsym(RTLD_DEFAULT, "glBeginQuery");
|
||||
_glEndQueryARB = (PFNGLENDQUERYPROC)dlsym(RTLD_DEFAULT, "glEndQuery");
|
||||
_glGetQueryObjectuivARB = (PFNGLGETQUERYOBJECTUIVPROC)dlsym(
|
||||
RTLD_DEFAULT, "glGetQueryObjectuiv");
|
||||
#else
|
||||
_queriesInitialized = true;
|
||||
_glGenQueriesARB =
|
||||
(PFNGLGENQUERIESARBPROC)dlsym(RTLD_DEFAULT, "glGenQueriesARB");
|
||||
|
|
@ -126,6 +141,7 @@ static void initQueryFuncs() {
|
|||
_glEndQueryARB = (PFNGLENDQUERYARBPROC)dlsym(RTLD_DEFAULT, "glEndQueryARB");
|
||||
_glGetQueryObjectuivARB = (PFNGLGETQUERYOBJECTUIVARBPROC)dlsym(
|
||||
RTLD_DEFAULT, "glGetQueryObjectuivARB");
|
||||
#endif
|
||||
}
|
||||
|
||||
void glGenQueriesARB_4J(IntBuffer* buf) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
|
||||
#endif
|
||||
// GDraw GL backend for Linux
|
||||
#include "platform/sdl2/Render.h"
|
||||
#include "Linux_UIController.h"
|
||||
|
|
|
|||
|
|
@ -69,6 +69,27 @@ endif
|
|||
|
||||
platform_services_src = files('../platform/PlatformServices.cpp')
|
||||
|
||||
if host_machine.system() == 'android'
|
||||
client_dependencies += declare_dependency(dependencies: cc.find_library('log', required: true))
|
||||
endif
|
||||
|
||||
if host_machine.system() == 'android'
|
||||
client = shared_library(
|
||||
'MinecraftClient',
|
||||
client_sources + platform_sources + platform_services_src + localisation[1],
|
||||
include_directories: include_directories('include', '..'),
|
||||
dependencies: client_dependencies,
|
||||
cpp_args: global_cpp_args
|
||||
+ global_cpp_defs
|
||||
+ [
|
||||
'-DUNICODE',
|
||||
'-D_UNICODE',
|
||||
],
|
||||
c_args: global_cpp_defs + ['-DUNICODE', '-D_UNICODE'],
|
||||
install: true,
|
||||
install_dir: '',
|
||||
)
|
||||
else
|
||||
client = executable(
|
||||
'Minecraft.Client',
|
||||
client_sources + platform_sources + platform_services_src + localisation[1],
|
||||
|
|
@ -84,6 +105,7 @@ client = executable(
|
|||
install: true,
|
||||
install_dir: '',
|
||||
)
|
||||
endif
|
||||
|
||||
custom_target(
|
||||
'copy_assets_to_client',
|
||||
|
|
|
|||
|
|
@ -205,7 +205,10 @@ bool File::mkdirs() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
return fs::create_directories(path, error);
|
||||
// Previous behavior could return false even if the directory did not exist
|
||||
// and was successfully created, at least this happens on Android
|
||||
fs::create_directories(path, error);
|
||||
return !error;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "Camera.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
#include <glm/glm.hpp>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
|
@ -9,6 +13,7 @@
|
|||
|
||||
#include "MemoryTracker.h"
|
||||
#include "app/include/stubs.h"
|
||||
#include "platform/sdl2/Render.h"
|
||||
#include "java/FloatBuffer.h"
|
||||
#include "minecraft/world/entity/LivingEntity.h"
|
||||
#include "minecraft/world/entity/player/Player.h"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "Lighting.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include "platform/sdl2/Render.h"
|
||||
#include "app/include/stubs.h"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "GuiComponent.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include "platform/sdl2/Render.h"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "Minimap.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "AchievementPopup.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include "platform/sdl2/Render.h"
|
||||
#include "java/System.h"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "AchievementScreen.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "BeaconScreen.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "CreativeInventoryScreen.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "RepairScreen.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "ChestModel.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include "minecraft/client/model/geom/ModelPart.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "ModelPart.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <numbers>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "FootstepParticle.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "HugeExplosionParticle.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include "platform/sdl2/Render.h"
|
||||
#include "app/common/App_enums.h"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "ParticleEngine.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "TakeAnimationParticle.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "Chunk.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
#include <mutex>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "ItemInHandRenderer.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
#include <numbers>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "LevelRenderer.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "Tesselator.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "TileRenderer.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "Frustum.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
#include <cmath>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <format>
|
||||
#include <string>
|
||||
|
|
@ -13,12 +18,19 @@ class BufferedImage;
|
|||
class Texture {
|
||||
public:
|
||||
static const int WM_WRAP = GL_REPEAT;
|
||||
#ifdef GLES
|
||||
static const int WM_CLAMP = GL_CLAMP_TO_EDGE;
|
||||
#else
|
||||
static const int WM_CLAMP = GL_CLAMP;
|
||||
#endif
|
||||
static const int WM_MIRROR = 0; // GL_MIRRORED_REPEAT;
|
||||
|
||||
static const int TFMT_RGBA = GL_RGBA;
|
||||
#ifdef GLES
|
||||
static const int TFMT_BGRA = GL_BGRA_EXT;
|
||||
#else
|
||||
static const int TFMT_BGRA = GL_BGRA;
|
||||
|
||||
#endif
|
||||
static const int TFLT_NEAREST = GL_NEAREST;
|
||||
static const int TFLT_LINEAR = GL_LINEAR;
|
||||
static const int TFLT_LINEAR_MIP_NEAREST = 0; // GL_LINEAR_MIPMAP_NEAREST;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#include "AbstractTexturePack.h"
|
||||
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
#include <wchar.h>
|
||||
|
||||
#include <vector>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#include <numbers> // for std::numbers
|
||||
|
||||
#include "platform/sdl2/Render.h"
|
||||
#include "app/linux/LinuxGame.h"
|
||||
|
|
|
|||
|
|
@ -75,13 +75,18 @@ public:
|
|||
}
|
||||
|
||||
std::filesystem::path getBasePath() override {
|
||||
#if defined(__linux__)
|
||||
#if defined(__linux__) && !defined (__android__)
|
||||
char buf[4096];
|
||||
ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
|
||||
if (len > 0) {
|
||||
buf[len] = '\0';
|
||||
return std::filesystem::path(buf).parent_path();
|
||||
}
|
||||
#elif defined(__android__)
|
||||
// Because of the static init fiasco
|
||||
// I need to set the path before loading the library
|
||||
// I can only do this through ENV
|
||||
return std::filesystem::path( getenv("MC_PATH") );
|
||||
#endif
|
||||
return std::filesystem::current_path();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
#include "Render.h"
|
||||
|
||||
#include "../PlatformTypes.h"
|
||||
#include "SDL.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_video.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_error.h>
|
||||
#include <SDL2/SDL_events.h>
|
||||
#include <SDL2/SDL_stdinc.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
#include "gl3_loader.h"
|
||||
|
||||
// undefine macros from header to avoid argument mismatch
|
||||
|
|
@ -41,6 +41,11 @@
|
|||
#include <dlfcn.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#ifdef __android__
|
||||
#include <android/log.h>
|
||||
#include <EGL/egl.h>
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
|
@ -51,6 +56,12 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#ifdef __android__
|
||||
#define fprintf(file, ...) ((void)__android_log_print(ANDROID_LOG_INFO, "4JRENDER", __VA_ARGS__))
|
||||
#define printf(...) ((void)__android_log_print(ANDROID_LOG_INFO, "4JRENDER", __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
C4JRender RenderManager;
|
||||
|
||||
// MARK: Shaders
|
||||
|
|
@ -81,6 +92,11 @@ static const char* FRAG_SRC =
|
|||
// MARK: OpenGL state
|
||||
|
||||
// Hello SDL and opengl 3.3
|
||||
#ifdef __android__
|
||||
static EGLDisplay s_eglDisplay = EGL_NO_DISPLAY;
|
||||
static EGLContext s_mainEglContext = EGL_NO_CONTEXT;
|
||||
static EGLSurface s_mainEglSurface = EGL_NO_SURFACE;
|
||||
#endif
|
||||
static SDL_Window* s_window = nullptr;
|
||||
static SDL_GLContext s_glContext = nullptr;
|
||||
static bool s_shouldClose = false;
|
||||
|
|
@ -94,8 +110,14 @@ static pthread_key_t s_glCtxKey;
|
|||
static pthread_once_t s_glCtxKeyOnce = PTHREAD_ONCE_INIT;
|
||||
static void makeGLCtxKey() { pthread_key_create(&s_glCtxKey, nullptr); }
|
||||
static const int MAX_SHARED_CTXS = 6;
|
||||
|
||||
#ifdef __android__
|
||||
static EGLSurface s_sharedWins[MAX_SHARED_CTXS] = {};
|
||||
static EGLContext s_sharedCtxs[MAX_SHARED_CTXS] = {};
|
||||
#else
|
||||
static SDL_Window* s_sharedWins[MAX_SHARED_CTXS] = {};
|
||||
static SDL_GLContext s_sharedCtxs[MAX_SHARED_CTXS] = {};
|
||||
#endif
|
||||
static int s_sharedCtxCount = 0;
|
||||
static int s_nextSharedCtx = 0;
|
||||
static pthread_mutex_t s_sharedMtx = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
|
@ -647,6 +669,9 @@ void C4JRender::Initialise() {
|
|||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
#ifdef __android__
|
||||
SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight");
|
||||
#endif
|
||||
Uint32 wf = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
|
||||
if (s_fullscreen) wf |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
s_window = SDL_CreateWindow("Minecraft Console Edition",
|
||||
|
|
@ -686,16 +711,50 @@ void C4JRender::Initialise() {
|
|||
s_mainThread = pthread_self();
|
||||
s_mainThreadSet = true;
|
||||
pthread_setspecific(s_glCtxKey, (void*)s_window);
|
||||
|
||||
#ifdef __android__
|
||||
s_eglDisplay = eglGetCurrentDisplay();
|
||||
|
||||
EGLint pb_atr[] = {
|
||||
EGL_WIDTH, 1,
|
||||
EGL_HEIGHT, 1,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLint cfg_id;
|
||||
if (!eglQueryContext(s_eglDisplay, (EGLContext)s_glContext, EGL_CONFIG_ID, &cfg_id))
|
||||
{
|
||||
printf("BRUH\n");
|
||||
}
|
||||
|
||||
EGLConfig cfg;
|
||||
EGLint cfgs;
|
||||
EGLint atrs[] = { EGL_CONFIG_ID, cfg_id, EGL_NONE };
|
||||
|
||||
eglChooseConfig(s_eglDisplay, atrs, &cfg, 1, &cfgs);
|
||||
#endif
|
||||
|
||||
SDL_GL_MakeCurrent(s_window, s_glContext);
|
||||
for (int i = 0; i < MAX_SHARED_CTXS; i++) {
|
||||
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
|
||||
#ifndef __android__
|
||||
SDL_Window* w = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED, 1, 1,
|
||||
SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
|
||||
if (!w) break;
|
||||
SDL_GLContext ctx = SDL_GL_CreateContext(w);
|
||||
#else
|
||||
EGLint ctx_atr[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
|
||||
EGLContext ctx = eglCreateContext(s_eglDisplay, cfg, (EGLContext)s_glContext, ctx_atr);
|
||||
EGLSurface w = eglCreatePbufferSurface(s_eglDisplay, cfg, pb_atr);
|
||||
if ( w == EGL_NO_SURFACE ) {
|
||||
printf("EGL_NO_SURFACE: %d\n", eglGetError() );
|
||||
}
|
||||
#endif
|
||||
if (!ctx) {
|
||||
#ifndef __android__
|
||||
SDL_DestroyWindow(w);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
s_sharedWins[s_sharedCtxCount] = w;
|
||||
|
|
@ -722,10 +781,18 @@ void C4JRender::InitialiseContext() {
|
|||
}
|
||||
void* cp = pthread_getspecific(s_glCtxKey);
|
||||
if (cp) {
|
||||
#ifdef __android__
|
||||
EGLContext ctx = (EGLContext)cp;
|
||||
#else
|
||||
SDL_GLContext ctx = (SDL_GLContext)cp;
|
||||
#endif
|
||||
for (int i = 0; i < s_sharedCtxCount; i++)
|
||||
if (s_sharedCtxs[i] == ctx) {
|
||||
#ifdef __android__
|
||||
eglMakeCurrent(s_eglDisplay, s_sharedWins[i], s_sharedWins[i], ctx );
|
||||
#else
|
||||
SDL_GL_MakeCurrent(s_sharedWins[i], ctx);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
|
@ -738,7 +805,11 @@ void C4JRender::InitialiseContext() {
|
|||
if (!shared) return;
|
||||
for (int i = 0; i < s_sharedCtxCount; i++)
|
||||
if (s_sharedCtxs[i] == shared)
|
||||
#ifdef __android__
|
||||
eglMakeCurrent(s_eglDisplay, s_sharedWins[i], s_sharedWins[i], shared );
|
||||
#else
|
||||
SDL_GL_MakeCurrent(s_sharedWins[i], shared);
|
||||
#endif
|
||||
pthread_setspecific(s_glCtxKey, (void*)shared);
|
||||
}
|
||||
|
||||
|
|
@ -801,8 +872,14 @@ void C4JRender::Shutdown() {
|
|||
s_window = nullptr;
|
||||
}
|
||||
for (int i = 0; i < s_sharedCtxCount; i++) {
|
||||
#ifdef __android__
|
||||
eglMakeCurrent(s_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
if (s_sharedCtxs[i]) eglDestroySurface(s_eglDisplay, s_sharedWins[i]);
|
||||
if (s_sharedWins[i]) eglDestroyContext(s_eglDisplay, s_sharedCtxs[i]);
|
||||
#else
|
||||
if (s_sharedCtxs[i]) SDL_GL_DeleteContext(s_sharedCtxs[i]);
|
||||
if (s_sharedWins[i]) SDL_DestroyWindow(s_sharedWins[i]);
|
||||
#endif
|
||||
}
|
||||
SDL_Quit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,12 @@
|
|||
|
||||
#include "gl3_loader.h"
|
||||
// NOTE: gl3_loader.h must be included before these two
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#endif
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
|
@ -386,6 +390,34 @@ extern C4JRender RenderManager;
|
|||
#define GL_TRIANGLE_STRIP 0x0005
|
||||
#endif
|
||||
|
||||
// These constants do not exist on the GLES,
|
||||
// so for now it is just stub
|
||||
#ifdef GLES
|
||||
|
||||
#ifndef GL_COLOR_MATERIAL
|
||||
#define GL_COLOR_MATERIAL 0x0B57
|
||||
#endif
|
||||
#ifndef GL_RESCALE_NORMAL
|
||||
#define GL_RESCALE_NORMAL 0x803A
|
||||
#endif
|
||||
#ifndef GL_NORMALIZE
|
||||
#define GL_NORMALIZE 0x0BA1
|
||||
#endif
|
||||
#ifndef GL_POLYGON_OFFSET_LINE
|
||||
#define GL_POLYGON_OFFSET_LINE 0x2A02
|
||||
#endif
|
||||
#ifndef GL_AMBIENT_AND_DIFFUSE
|
||||
#define GL_AMBIENT_AND_DIFFUSE 0x1602
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
void glShadeModel(GLenum);
|
||||
void glColorMaterial(GLenum, GLenum);
|
||||
void glNormal3f(GLfloat, GLfloat, GLfloat);
|
||||
void glTexGeni(GLenum, GLenum, GLint);
|
||||
}
|
||||
#endif
|
||||
|
||||
// glCallList / display list macros
|
||||
#undef glNewList
|
||||
#define glNewList(_list, _mode) RenderManager.CBuffStart(_list)
|
||||
|
|
@ -726,3 +758,7 @@ void glGetQueryObjectu_4J_Helper(unsigned int id, unsigned int pname,
|
|||
#define glLight(a, b, c) glLight_4J(a, b, c)
|
||||
#define glLightModel(a, b) glLightModel_4J(a, b)
|
||||
#define glTexGen(a, b, c) glTexGen_4J(a, b, c)
|
||||
|
||||
#ifdef GLES
|
||||
#define glClearDepth(a) glClearDepthf((float)a)
|
||||
#endif
|
||||
|
|
@ -2,9 +2,13 @@
|
|||
#ifndef GL_GLEXT_PROTOTYPES
|
||||
#define GL_GLEXT_PROTOTYPES 1
|
||||
#endif
|
||||
#ifdef GLES
|
||||
#include <GLES3/gl3.h>
|
||||
#include <GLES3/gl3ext.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#endif
|
||||
|
||||
#include <cstdio>
|
||||
#ifndef GL_ARRAY_BUFFER
|
||||
|
|
|
|||
Loading…
Reference in a new issue