Some Fixes

This commit is contained in:
TheBrokenRail 2024-11-18 18:47:13 -05:00
parent ecbbcef203
commit 5d7056645d
5 changed files with 42 additions and 27 deletions

View File

@ -49,7 +49,7 @@ if("${toolchain_dir}/bin/arm-none-linux-gnueabihf-gcc" IS_NEWER_THAN "${sysroot_
file(REMOVE_RECURSE "${sysroot_dir}/usr/lib/gconv") file(REMOVE_RECURSE "${sysroot_dir}/usr/lib/gconv")
# Strip Files # Strip Files
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
file(GLOB_RECURSE files LIST_DIRECTORIES FALSE "${sysroot_dir}/*") file(GLOB_RECURSE files LIST_DIRECTORIES FALSE "${sysroot_dir}/*")
foreach(file IN LISTS files) foreach(file IN LISTS files)
execute_process( execute_process(

View File

@ -36,3 +36,12 @@ endif()
# License # License
install(FILES src/LICENSE DESTINATION "${MCPI_LEGAL_DIR}/LIEF") install(FILES src/LICENSE DESTINATION "${MCPI_LEGAL_DIR}/LIEF")
# Fix Flags
function(fix_flags property)
get_target_property(flags LIB_LIEF "${property}")
list(REMOVE_ITEM flags "_GLIBCXX_USE_CXX11_ABI=1")
set_target_properties(LIB_LIEF PROPERTIES "${property}" "${flags}")
endfunction()
fix_flags(COMPILE_DEFINITIONS)
fix_flags(INTERFACE_COMPILE_DEFINITIONS)

View File

@ -5,6 +5,6 @@
struct Texture; struct Texture;
extern "C" { extern "C" {
void media_glTexSubImage2D_with_scaling(const Texture *target, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLsizei normal_texture_width, GLsizei normal_texture_height, const void *pixels); void media_glTexSubImage2D_with_scaling(const Texture *target, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLfloat normal_texture_width, GLfloat normal_texture_height, const void *pixels);
void textures_add(int width, int height, const unsigned char *pixels); void textures_add(int width, int height, const unsigned char *pixels);
} }

View File

@ -10,9 +10,14 @@
#include <mods/atlas/atlas.h> #include <mods/atlas/atlas.h>
#include <mods/init/init.h> #include <mods/init/init.h>
// Atlas Texture
constexpr int atlas_texture_size = 2048; // Must Be Power Of Two
// Atlas Dimensions
constexpr int atlas_entry_size = 48;
constexpr int atlas_size_entries = atlas_texture_size / atlas_entry_size;
// Render Atlas // Render Atlas
#define ATLAS_SIZE 32
#define ATLAS_ENTRY_SIZE 48
static int get_atlas_key(Item *item, const int data) { static int get_atlas_key(Item *item, const int data) {
const int id = item->id; const int id = item->id;
const int icon = item->getIcon(data); const int icon = item->getIcon(data);
@ -53,14 +58,15 @@ static void render_atlas(Textures *textures) {
const int key = info.first; const int key = info.first;
const int data = info.second; const int data = info.second;
// Check Remaining Space (Leave Last Slot Empty) // Check Remaining Space (Leave Last Slot Empty)
if (x == (ATLAS_SIZE - 1) && y == (ATLAS_SIZE - 1)) { constexpr int last_entry_pos = atlas_size_entries - 1;
if (x == last_entry_pos && y == last_entry_pos) {
WARN("Out Of gui_blocks Atlas Space!"); WARN("Out Of gui_blocks Atlas Space!");
return; return;
} }
// Position // Position
media_glPushMatrix(); media_glPushMatrix();
media_glTranslatef(ATLAS_ENTRY_SIZE * x, ATLAS_ENTRY_SIZE * y, 0); media_glTranslatef(atlas_entry_size * x, atlas_entry_size * y, 0);
constexpr float scale = ATLAS_ENTRY_SIZE / 16.0f; constexpr float scale = atlas_entry_size / 16.0f;
media_glScalef(scale, scale, 1); media_glScalef(scale, scale, 1);
// Render // Render
ItemInstance obj = { ItemInstance obj = {
@ -78,7 +84,7 @@ static void render_atlas(Textures *textures) {
} }
// Advance To Next Slot // Advance To Next Slot
x++; x++;
if (x >= ATLAS_SIZE) { if (x >= atlas_size_entries) {
x = 0; x = 0;
y++; y++;
} }
@ -87,16 +93,15 @@ static void render_atlas(Textures *textures) {
} }
static void generate_atlas(Minecraft *minecraft) { static void generate_atlas(Minecraft *minecraft) {
// Setup Offscreen Rendering // Setup Offscreen Rendering
constexpr int atlas_size = ATLAS_SIZE * ATLAS_ENTRY_SIZE; media_begin_offscreen_render(atlas_texture_size, atlas_texture_size);
media_begin_offscreen_render(atlas_size, atlas_size);
// Setup OpenGL // Setup OpenGL
((NinecraftApp *) minecraft)->initGLStates(); ((NinecraftApp *) minecraft)->initGLStates();
media_glViewport(0, 0, atlas_size, atlas_size); media_glViewport(0, 0, atlas_texture_size, atlas_texture_size);
media_glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); media_glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
media_glMatrixMode(GL_PROJECTION); media_glMatrixMode(GL_PROJECTION);
media_glLoadIdentity(); media_glLoadIdentity();
media_glOrthof(0, atlas_size, atlas_size, 0, 2000, 3000); media_glOrthof(0, atlas_texture_size, atlas_texture_size, 0, 2000, 3000);
media_glMatrixMode(GL_MODELVIEW); media_glMatrixMode(GL_MODELVIEW);
media_glLoadIdentity(); media_glLoadIdentity();
media_glTranslatef(0, 0, -2000); media_glTranslatef(0, 0, -2000);
@ -113,10 +118,10 @@ static void generate_atlas(Minecraft *minecraft) {
textures->loadAndBindTexture("gui/gui_blocks.png"); textures->loadAndBindTexture("gui/gui_blocks.png");
constexpr int icon_width = 28; constexpr int icon_width = 28;
constexpr int icon_height = 8; constexpr int icon_height = 8;
minecraft->gui.blit(atlas_size - icon_width, atlas_size - icon_height, 242, 252, icon_width, icon_height, 14, 4); minecraft->gui.blit(atlas_texture_size - icon_width, atlas_texture_size - icon_height, 242, 252, icon_width, icon_height, 14, 4);
// Read Texture // Read Texture
int line_size = atlas_size * 4; int line_size = atlas_texture_size * 4;
{ {
// Handle Alignment // Handle Alignment
int alignment; int alignment;
@ -125,15 +130,15 @@ static void generate_atlas(Minecraft *minecraft) {
line_size = ALIGN_UP(line_size, alignment); line_size = ALIGN_UP(line_size, alignment);
} }
Texture texture; Texture texture;
texture.width = atlas_size; texture.width = atlas_texture_size;
texture.height = atlas_size; texture.height = atlas_texture_size;
texture.field3_0xc = 0; texture.field3_0xc = 0;
texture.field4_0x10 = true; texture.field4_0x10 = true;
texture.field5_0x11 = false; texture.field5_0x11 = false;
texture.field6_0x14 = 0; texture.field6_0x14 = 0;
texture.field7_0x18 = -1; texture.field7_0x18 = -1;
texture.data = new unsigned char[atlas_size * line_size]; texture.data = new unsigned char[atlas_texture_size * line_size];
media_glReadPixels(0, 0, atlas_size, atlas_size, GL_RGBA, GL_UNSIGNED_BYTE, texture.data); media_glReadPixels(0, 0, atlas_texture_size, atlas_texture_size, GL_RGBA, GL_UNSIGNED_BYTE, texture.data);
for (int y = 0; y < (texture.height / 2); y++) { for (int y = 0; y < (texture.height / 2); y++) {
for (int x = 0; x < (texture.width * 4); x++) { for (int x = 0; x < (texture.width * 4); x++) {
unsigned char &a = texture.data[(y * line_size) + x]; unsigned char &a = texture.data[(y * line_size) + x];
@ -173,10 +178,11 @@ static void ItemRenderer_renderGuiItem_two_injection(__attribute__((unused)) Ite
} }
const std::pair<int, int> &pos = atlas_key_to_pos[key]; const std::pair<int, int> &pos = atlas_key_to_pos[key];
// Convert To UV // Convert To UV
float u0 = float(pos.first) / ATLAS_SIZE; constexpr float scale = float(atlas_texture_size) / atlas_entry_size;
float u1 = float(pos.first + 1) / ATLAS_SIZE; float u0 = float(pos.first) / scale;
float v0 = float(pos.second) / ATLAS_SIZE; float u1 = float(pos.first + 1) / scale;
float v1 = float(pos.second + 1) / ATLAS_SIZE; float v0 = float(pos.second) / scale;
float v1 = float(pos.second + 1) / scale;
// Render // Render
textures->loadAndBindTexture("gui/gui_blocks.png"); textures->loadAndBindTexture("gui/gui_blocks.png");
Tesselator &t = Tesselator::instance; Tesselator &t = Tesselator::instance;
@ -200,7 +206,7 @@ static int CropTile_getTexture2_injection(CropTile_getTexture2_t original, CropT
// Fix Open Inventory Button // Fix Open Inventory Button
static void Gui_renderToolBar_GuiComponent_blit_injection(GuiComponent *self, int x_dest, int y_dest, __attribute__((unused)) const int x_src, __attribute__((unused)) const int y_src, const int width_dest, const int height_dest, const int width_src, const int height_src) { static void Gui_renderToolBar_GuiComponent_blit_injection(GuiComponent *self, int x_dest, int y_dest, __attribute__((unused)) const int x_src, __attribute__((unused)) const int y_src, const int width_dest, const int height_dest, const int width_src, const int height_src) {
constexpr float size_scale = 2.0f / (ATLAS_SIZE * ATLAS_ENTRY_SIZE); constexpr float size_scale = 2.0f / atlas_texture_size;
constexpr float u1 = 1.0f; constexpr float u1 = 1.0f;
const float u0 = u1 - (float(width_src) * size_scale); const float u0 = u1 - (float(width_src) * size_scale);
constexpr float v1 = 1.0f; constexpr float v1 = 1.0f;
@ -221,7 +227,7 @@ void atlas_update_tile(Textures *textures, const int texture, const unsigned cha
uint32_t atlas_id = textures->loadAndBindTexture("gui/gui_blocks.png"); uint32_t atlas_id = textures->loadAndBindTexture("gui/gui_blocks.png");
const Texture *atlas_data = textures->getTemporaryTextureData(atlas_id); const Texture *atlas_data = textures->getTemporaryTextureData(atlas_id);
constexpr int texture_size = 16; constexpr int texture_size = 16;
constexpr int fake_atlas_size = (ATLAS_SIZE * texture_size); constexpr float fake_atlas_size = atlas_texture_size * (float(texture_size) / atlas_entry_size);
media_glTexSubImage2D_with_scaling(atlas_data, pos.first * texture_size, pos.second * texture_size, texture_size, texture_size, fake_atlas_size, fake_atlas_size, pixels); media_glTexSubImage2D_with_scaling(atlas_data, pos.first * texture_size, pos.second * texture_size, texture_size, texture_size, fake_atlas_size, fake_atlas_size, pixels);
} }
} }

View File

@ -75,14 +75,14 @@ static unsigned char *scale_texture(const unsigned char *src, const GLsizei old_
} }
// Scale Animated Textures // Scale Animated Textures
void media_glTexSubImage2D_with_scaling(const Texture *target, const GLint xoffset, const GLint yoffset, const GLsizei width, const GLsizei height, const GLsizei normal_texture_width, const GLsizei normal_texture_height, const void *pixels) { void media_glTexSubImage2D_with_scaling(const Texture *target, const GLint xoffset, const GLint yoffset, const GLsizei width, const GLsizei height, const GLfloat normal_texture_width, const GLfloat normal_texture_height, const void *pixels) {
// Get Current Texture Size // Get Current Texture Size
const GLsizei texture_width = target->width; const GLsizei texture_width = target->width;
const GLsizei texture_height = target->height; const GLsizei texture_height = target->height;
// Calculate Factor // Calculate Factor
const float width_factor = ((float) texture_width) / ((float) normal_texture_width); const float width_factor = float(texture_width) / normal_texture_width;
const float height_factor = ((float) texture_height) / ((float) normal_texture_height); const float height_factor = float(texture_height) / normal_texture_height;
// Only Scale If Needed // Only Scale If Needed
if (width_factor == 1.0f && height_factor == 1.0f) { if (width_factor == 1.0f && height_factor == 1.0f) {