Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FF8: handle vram #375

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions misc/FFNx.toml
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ trace_files = false
#~~~~~~~~~~~~~~~~~~~~~~~~~~~
trace_loaders = false

# trace_vram - Dump in the logs only APIs that has to do with FF8 VRAM
#~~~~~~~~~~~~~~~~~~~~~~~~~~~
trace_vram = false

# trace_opcodes - Dump in the logs only APIs that has to do with field opcodes
#~~~~~~~~~~~~~~~~~~~~~~~~~~~
trace_opcodes = false
Expand Down
2 changes: 2 additions & 0 deletions src/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ bool trace_fake_dx;
bool trace_direct;
bool trace_files;
bool trace_loaders;
bool trace_vram;
bool trace_lights;
bool trace_opcodes;
bool trace_voice;
Expand Down Expand Up @@ -186,6 +187,7 @@ void read_cfg()
trace_direct = config["trace_direct"].value_or(false);
trace_files = config["trace_files"].value_or(false);
trace_loaders = config["trace_loaders"].value_or(false);
trace_vram = config["trace_vram"].value_or(false);
trace_lights = config["trace_lights"].value_or(false);
trace_opcodes = config["trace_opcodes"].value_or(false);
trace_voice = config["trace_voice"].value_or(false);
Expand Down
1 change: 1 addition & 0 deletions src/cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ extern bool trace_fake_dx;
extern bool trace_direct;
extern bool trace_files;
extern bool trace_loaders;
extern bool trace_vram;
extern bool trace_lights;
extern bool trace_opcodes;
extern bool trace_voice;
Expand Down
70 changes: 70 additions & 0 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#include "lighting.h"
#include "achievement.h"

#include "ff8/vram.h"

bool proxyWndProc = false;

// global game window handler
Expand Down Expand Up @@ -655,7 +657,13 @@ int common_create_window(HINSTANCE hInstance, struct game_obj* game_object)
sfx_init();
voice_init();
if (enable_ffmpeg_videos)
{
movie_init();
}
if (ff8)
{
vram_init();
}

// enable verbose logging for FFMpeg
av_log_set_level(AV_LOG_VERBOSE);
Expand Down Expand Up @@ -1127,6 +1135,7 @@ void common_unload_texture(struct texture_set *texture_set)
stats.texture_count--;

if(VREF(texture_set, ogl.external)) stats.external_textures--;
VRASS(texture_set, ogl.external, false); // texture_set can be reused (FF8)

// remove any other references to this texture
gl_check_deferred(texture_set);
Expand Down Expand Up @@ -1166,6 +1175,39 @@ uint32_t load_framebuffer_texture(struct texture_set *texture_set, struct tex_he
return true;
}

// Scale 32-bit BGRA image in place
void scale_up_image_date_in_place(uint8_t *sourceAndTarget, int w, int h, int scale)
{
if (scale <= 1)
{
return;
}

uint32_t *source = (uint32_t *)sourceAndTarget + w * h,
*target = (uint32_t *)sourceAndTarget + (w * scale) * (h * scale);

for (int y = 0; y < h; ++y)
{
uint32_t *source_line_start = source;

for (int i = 0; i < scale; ++i)
{
source = source_line_start;

for (int x = 0; x < w; ++x)
{
source -= 1;
target -= scale;

for (int i = 0; i < scale; ++i)
{
target[i] = *source;
}
}
}
}
}

// load modpath texture for tex file, returns true if successful
uint32_t load_external_texture(void* image_data, uint32_t dataSize, struct texture_set *texture_set, struct tex_header *tex_header, uint32_t originalWidth, uint32_t originalHeight)
{
Expand Down Expand Up @@ -1206,6 +1248,34 @@ uint32_t load_external_texture(void* image_data, uint32_t dataSize, struct textu

if(!_strnicmp(VREF(tex_header, file.pc_name), "flevel/hand_1", strlen("flevel/hand_1") - 1)) gl_set->force_filter = true;
}
else if(ff8)
{
uint8_t scale = texturePacker.getMaxScale();
uint8_t *image_data_scaled = (uint8_t *)image_data;

if (scale > 1)
{
uint32_t image_data_size = originalWidth * scale * originalHeight * scale * 4;
image_data_scaled = (uint8_t*)driver_malloc(image_data_size);

// convert source data
if (image_data_scaled != nullptr)
{
memcpy(image_data_scaled, image_data, dataSize);
scale_up_image_date_in_place(image_data_scaled, originalWidth, originalHeight, scale);
}
}

if (texturePacker.drawModdedTextures(VREF(tex_header, image_data), VREF(tex_header, palette_index), (uint32_t *)image_data_scaled, scale))
{
texture = newRenderer.createTexture(image_data_scaled, originalWidth * scale, originalHeight * scale);
}

if (image_data_scaled != image_data)
{
driver_free(image_data_scaled);
}
}

if(texture)
{
Expand Down
31 changes: 25 additions & 6 deletions src/ff8.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ struct ff8_file_fs

struct ff8_file
{
int field_0;
int is_open;
char* filename;
int field_8;
int fd;
struct ff8_file_context field_C;
int field_20;
int field_24;
Expand Down Expand Up @@ -402,6 +402,18 @@ struct ff8_texture_set
uint32_t field_9C;
};

struct struc_color_texture {
uint32_t field_0;
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t _padding;
int16_t x;
int16_t y;
int16_t w;
int16_t h;
};

struct texture_page
{
uint32_t field_0;
Expand All @@ -410,8 +422,8 @@ struct texture_page
uint32_t width;
uint32_t height;
uint32_t color_key;
uint32_t u;
uint32_t v;
float u;
float v;
uint32_t field_20;
struct ff8_graphics_object *tri_gfxobj;
struct ff8_graphics_object *quad_gfxobj;
Expand Down Expand Up @@ -445,7 +457,7 @@ struct struc_50
uint32_t vram_width;
uint32_t vram_height;
uint32_t vram_palette_data;
uint32_t field_448;
uint32_t vram_palette_pos; // 24-bit | 6-bit
};

struct struc_51
Expand Down Expand Up @@ -787,7 +799,7 @@ struct ff8_externals
uint32_t nvidia_hack2;
struct sprite_viewport *menu_viewport;
uint32_t main_loop;
uint32_t sub_47CF60;
uint32_t cardgame_mainloop;
uint32_t sub_47CCB0;
uint32_t sub_534640;
uint32_t sub_4972A0;
Expand Down Expand Up @@ -852,6 +864,7 @@ struct ff8_externals
struct ff8_graphics_object **swirl_texture1;
uint32_t sub_48D0A0;
uint32_t open_lzs_image;
uint32_t (*credits_open_file)(char *, char *);
uint32_t upload_psx_vram;
void (*sub_464850)(uint32_t, uint32_t, uint32_t, uint32_t);
WORD *psxvram_buffer;
Expand Down Expand Up @@ -965,6 +978,12 @@ struct ff8_externals
uint32_t** savemap;
int32_t (*check_game_is_paused)(int32_t);
uint32_t sub_470250;
uint32_t *ssigpu_callbacks_1;
uint32_t sub_462AD0;
uint32_t sub_462DF0;
uint32_t ssigpu_tx_select_2_sub_465CE0;
int (*sub_464F70)(int, int, int, int, int, int, int, int, int, uint8_t *);
void(*sub_4675C0)(uint8_t *, int, uint8_t *, int, signed int, int, int);
};

void ff8gl_field_78(struct ff8_polygon_set *polygon_set, struct ff8_game_obj *game_object);
Expand Down
Loading