Skip to content

Commit

Permalink
Holy shit i finally got texture conversion working!
Browse files Browse the repository at this point in the history
  • Loading branch information
nchalkley2 committed Aug 28, 2024
1 parent 8508c3c commit 8f30000
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 120 deletions.
2 changes: 1 addition & 1 deletion assets/textures/bricks1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "texture",
"psm": "palette",
"psm": "16",
"alpha": false,
"file": "uv_tester.png"
}
Binary file added assets/textures/rgb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/textures/uv_tester.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ set -e
if [ ! "$1" ] || [ $1 != "ci" ]; then
# Check if apt is installed before trying to run prereqs
if command -v apt 2>&1 /dev/null; then
sudo apt install -y build-essential binutils-dev git cmake genisoimage libassimp-dev libmagick++-dev sox autoconf automake autopoint
sudo apt install -y build-essential binutils-dev git cmake genisoimage libstb-dev libassimp-dev libmagick++-dev sox autoconf automake autopoint
fi

if command -v pacman 2>&1 /dev/null; then
sudo pacman -S gcc make cmake patch texinfo flex bison gettext wget gsl gmp zlib mpfr mpc glibc linux-headers linux-api-headers ncurses assimp jsoncpp cdrkit libelf cimg imagemagick pkgconf sox
sudo pacman -S gcc make cmake patch texinfo flex bison gettext wget gsl gmp zlib mpfr mpc glibc linux-headers linux-api-headers ncurses assimp jsoncpp cdrkit libelf cimg imagemagick pkgconf sox stb
fi
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,4 @@ struct texture_descriptor
void upload_texture(texture_descriptor& texture, void* texture_data, void* clut_data);

void unload_texture(texture_descriptor& texture);

// Sets the texture currently being drawn
bool set_texture(texture_descriptor& texture);
} // namespace egg::ps2::graphics
1 change: 0 additions & 1 deletion dependencies/egg-ps2-graphics-lib/src/gs_mem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ int allocate_texture_slot(u32 pages)
// If the pointer overflows the vram size
if (graph_vram_pointer > graph_vram_max_words)
{

graph_vram_pointer -= size;
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion dependencies/egg-ps2-graphics-lib/src/mesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void draw_mesh_strip(const Matrix& mesh_to_screen_matrix, const mesh_descriptor&
assert(mesh.is_valid());

// TODO: calculate this dynamically based on how much stuff is being put into vu mem
static constexpr s32 verts_per_call = 80;
static constexpr s32 verts_per_call = 64;

for (u32 i = 0;;)
{
Expand Down
36 changes: 14 additions & 22 deletions dependencies/egg-ps2-graphics-lib/src/texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ texture_descriptor::texture_descriptor()

t_texbuff.info.width = 0;
t_texbuff.info.height = 0;
t_texbuff.info.components = TEXTURE_COMPONENTS_RGB;
t_texbuff.info.components = TEXTURE_COMPONENTS_RGBA;
t_texbuff.info.function = TEXTURE_FUNCTION_DECAL;

wrap.horizontal = WRAP_REPEAT;
Expand Down Expand Up @@ -72,20 +72,25 @@ void upload_texture(texture_descriptor& texture, void* texture_data, void* clut_
return;
}

utils::inline_packet2<50> texture_packet(P2_TYPE_NORMAL, P2_MODE_CHAIN, 0);
assert(__is_aligned(texture_data, 16));
utils::inline_packet2<128> texture_packet(P2_TYPE_NORMAL, P2_MODE_CHAIN, 0);

packet2_update(texture_packet, draw_texture_transfer(
texture_packet->next,
texture_data,
texture.get_width_height().first,
texture.get_width_height().second,
texture.t_texbuff.psm,
texture.t_texbuff.address,
texture.t_texbuff.width));
std::max((u32)64, texture.get_width_height().first)));

u8 clut_width = texture.t_texbuff.psm == GS_PSM_8 ? 16 : 8;
u8 clut_height = texture.t_texbuff.psm == GS_PSM_8 ? 16 : 2;
if (clut_data)
{
u8 clut_width = texture.t_texbuff.psm == GS_PSM_8 ? 16 : 8;
u8 clut_height = texture.t_texbuff.psm == GS_PSM_8 ? 16 : 2;
assert(__is_aligned(clut_data, 16));

printf("clut width, height : %u, %u\n", clut_width, clut_height);

packet2_update(texture_packet, draw_texture_transfer(
texture_packet->next,
Expand All @@ -94,10 +99,12 @@ void upload_texture(texture_descriptor& texture, void* texture_data, void* clut_
clut_height,
texture.clut.psm,
texture.clut.address,
clut_width));
64));
}

printf("Texture min: %d, %d\n", texture.wrap.minu, texture.wrap.minv);
printf("Texture max: %d, %d\n", texture.wrap.maxu, texture.wrap.maxv);

packet2_chain_open_cnt(texture_packet, 0, 0, 0);
packet2_update(texture_packet, draw_texture_wrapping(
texture_packet->next,
Expand All @@ -106,6 +113,7 @@ void upload_texture(texture_descriptor& texture, void* texture_data, void* clut_
packet2_chain_close_tag(texture_packet);

packet2_update(texture_packet, draw_texture_flush(texture_packet->next));
dma_channel_wait(DMA_CHANNEL_GIF, 0);
dma_channel_send_packet2(texture_packet, DMA_CHANNEL_GIF, 1);
dma_wait_fast();

Expand All @@ -129,20 +137,4 @@ void unload_texture(texture_descriptor& texture)
texture.is_uploaded = false;
}

bool set_texture(texture_descriptor& texture)
{
packet2_utils_vu_open_unpack(get_current_vif_packet(), 0, 1);
{
packet2_utils_gif_add_set(get_current_vif_packet(), 1);
packet2_utils_gs_add_lod(get_current_vif_packet(), &texture.lod);
packet2_utils_gs_add_texbuff_clut(get_current_vif_packet(), &texture.t_texbuff, &texture.clut);
packet2_utils_gs_add_prim_giftag(get_current_vif_packet(), &get_empty_prim(), 0,
((u64)GIF_REG_RGBAQ) << 0, 1, 0);
}
packet2_utils_vu_close_unpack(get_current_vif_packet());
packet2_utils_vu_add_start_program(get_current_vif_packet(), vu1_programs::get_kick_program_addr());

return true;
}

} // namespace egg::ps2::graphics
2 changes: 0 additions & 2 deletions include/renderer/texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ struct Texture: public Debuggable
// Deallocates the texture from gs memory
bool unload_texture();

bool use_texture();

AssetRegistry::Asset* texture_asset;

class TextureFileHeader* get_texture() const;
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/gs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ void render()

_gs_state.camera_rotation = Camera::get().transform.get_rotation();

epg::clear_screen(255, 192, 203);
epg::clear_screen(255, 255, 255);

{
epg::start_draw();

epg::set_fog_color(255, 192, 203);
epg::set_fog_color(255, 255, 255);

draw_objects(_gs_state);

Expand Down
17 changes: 1 addition & 16 deletions src/renderer/texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Texture::Texture(Asset::Reference texture_asset_ref, AssetRegistry::Asset* in_te
texture_descriptor.t_texbuff.info.function = texture->function;
texture_descriptor.t_texbuff.psm = texture->psm;

texture_descriptor.clut.start = 0;
texture_descriptor.clut.psm = GS_PSM_32;
texture_descriptor.clut.load_method = texture->clut.length > 0 ? CLUT_LOAD : CLUT_NO_LOAD;
texture_descriptor.clut.storage_mode = CLUT_STORAGE_MODE1;
Expand Down Expand Up @@ -99,22 +100,6 @@ bool Texture::unload_texture()
return true;
}

bool Texture::use_texture()
{
TextureFileHeader* texture = get_texture();
if (texture == nullptr)
{
return false;
}

if (texture_descriptor.is_uploaded == false)
{
return false;
}

return egg::ps2::graphics::set_texture(texture_descriptor);
}

TextureFileHeader* Texture::get_texture() const
{
return reinterpret_cast<TextureFileHeader*>(texture_asset->data.get());
Expand Down
2 changes: 1 addition & 1 deletion tools/ps2-mesh-converter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ FILE(GLOB_RECURSE Source "src/**.cpp")

add_executable(egg-ps2-mesh-converter ${Source})

target_include_directories(egg-ps2-mesh-converter PRIVATE include "/usr/include/jsoncpp" ${ImageMagick_INCLUDE_DIRS})
target_include_directories(egg-ps2-mesh-converter PRIVATE include "/usr/include/jsoncpp" "/usr/include" ${ImageMagick_INCLUDE_DIRS})
target_link_libraries(egg-ps2-mesh-converter PUBLIC meshoptimizer::meshoptimizer assimp ps2-egg jsoncpp ${ImageMagick_LIBRARIES})

set_property(TARGET egg-ps2-mesh-converter PROPERTY CXX_STANDARD 20)
Expand Down
Loading

0 comments on commit 8f30000

Please sign in to comment.