Improvements to parse Texture data
This commit is contained in:
parent
6407f89667
commit
6ea257f650
|
@ -10,16 +10,17 @@ namespace FileProcessor {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Configuration;
|
struct Configuration;
|
||||||
typedef bool (*ProcessRoutine)(Configuration&, Reserved&, size_t);
|
typedef bool (*ProcessRoutine)(Configuration&, Reserved&);
|
||||||
|
|
||||||
struct Configuration {
|
struct Configuration {
|
||||||
ProcessRoutine process_routine = nullptr;
|
ProcessRoutine process_routine = nullptr;
|
||||||
const uint32_t* data_adr = nullptr;
|
const uint32_t* data_adr = nullptr;
|
||||||
|
size_t data_size = 0ull;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&, size_t), const uint32_t* data_adr) {
|
static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&), const uint32_t* data_adr) {
|
||||||
return {reinterpret_cast<ProcessRoutine>(process_routine), data_adr};
|
return {reinterpret_cast<ProcessRoutine>(process_routine), data_adr};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -27,14 +28,15 @@ namespace FileProcessor {
|
||||||
Reserved reserved;
|
Reserved reserved;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static __always_inline State from(const T& reserved, const uint32_t* data_adr, bool (*process_routine)(Configuration&, T&, size_t)) {
|
static __always_inline State from(const T& reserved, const uint32_t* data_adr, bool (*process_routine)(Configuration&, T&)) {
|
||||||
return {Configuration::from(process_routine, data_adr), *reinterpret_cast<const Reserved*>(&reserved)};
|
return {Configuration::from(process_routine, data_adr), *reinterpret_cast<const Reserved*>(&reserved)};
|
||||||
static_assert(sizeof(T) <= sizeof(Reserved));
|
static_assert(sizeof(T) <= sizeof(Reserved));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool process(size_t size) {
|
bool process(size_t size) {
|
||||||
return (*this->config.process_routine)(this->config, this->reserved, size);
|
this->config.data_size += size;
|
||||||
|
return (*this->config.process_routine)(this->config, this->reserved);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef __JABYENGINE_INTERNAL_SIMPLE_HELPER_HPP__
|
||||||
|
#define __JABYENGINE_INTERNAL_SIMPLE_HELPER_HPP__
|
||||||
|
#define private public
|
||||||
|
#include <PSX/File/Processor/File_Processor.hpp>
|
||||||
|
|
||||||
|
namespace FileProcessor {
|
||||||
|
namespace Helper {
|
||||||
|
template<typename T>
|
||||||
|
static void simple_read(T& dst, State::Configuration& config) {
|
||||||
|
static constexpr size_t UINT32_SIZE = (sizeof(T)/sizeof(uint32_t));
|
||||||
|
|
||||||
|
dst = *reinterpret_cast<const T*>(config.data_adr);
|
||||||
|
config.data_adr += UINT32_SIZE;
|
||||||
|
config.data_size -= UINT32_SIZE;
|
||||||
|
|
||||||
|
static_assert((UINT32_SIZE*sizeof(uint32_t)) == sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static bool exchange_and_execute_process_function(bool (*process_routine)(State::Configuration&, T&), State::Configuration& config, T& state) {
|
||||||
|
config.process_routine = reinterpret_cast<State::ProcessRoutine>(process_routine);
|
||||||
|
return process_routine(config, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !__JABYENGINE_INTERNAL_SIMPLE_HELPER_HPP__
|
|
@ -1,18 +0,0 @@
|
||||||
#ifndef __JABYENGINE_INTERNAL_SIMPLE_READ_HPP__
|
|
||||||
#define __JABYENGINE_INTERNAL_SIMPLE_READ_HPP__
|
|
||||||
#include <PSX/File/Processor/File_Processor.hpp>
|
|
||||||
|
|
||||||
namespace FileProcessor {
|
|
||||||
template<typename T>
|
|
||||||
static size_t simple_read(T& dst, State::Configuration& config) {
|
|
||||||
static constexpr size_t UINT32_SIZE = (sizeof(T)/sizeof(uint32_t));
|
|
||||||
|
|
||||||
dst = *reinterpret_cast<const T*>(config.data_adr);
|
|
||||||
config.data_adr += UINT32_SIZE;
|
|
||||||
|
|
||||||
return UINT32_SIZE;
|
|
||||||
static_assert((UINT32_SIZE*sizeof(uint32_t)) == sizeof(T));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // !__JABYENGINE_INTERNAL_SIMPLE_READ_HPP__
|
|
|
@ -1,6 +1,5 @@
|
||||||
#define private public
|
|
||||||
#include "../../../include/GPU/GPU.h"
|
#include "../../../include/GPU/GPU.h"
|
||||||
#include "SimpleRead.hpp"
|
#include "SimpleHelper.hpp"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
namespace FileProcessor {
|
namespace FileProcessor {
|
||||||
|
@ -35,7 +34,6 @@ namespace FileProcessor {
|
||||||
constexpr SimpleTIMState(const SimpleTIM& dst_info) : dst_info(dst_info) {
|
constexpr SimpleTIMState(const SimpleTIM& dst_info) : dst_info(dst_info) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static_assert(sizeof(SimpleTIMState) <= sizeof(State::Reserved));
|
|
||||||
|
|
||||||
static void set_gpu_receive(const uint32_t* src, uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
|
static void set_gpu_receive(const uint32_t* src, uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
|
||||||
GPU::DMA::Receive::prepare();
|
GPU::DMA::Receive::prepare();
|
||||||
|
@ -43,24 +41,33 @@ namespace FileProcessor {
|
||||||
GPU::DMA::Receive::set_src(reinterpret_cast<const uintptr_t>(src));
|
GPU::DMA::Receive::set_src(reinterpret_cast<const uintptr_t>(src));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parse_header(State::Configuration& config, SimpleTIMState& state, size_t size) {
|
static void set_gpu_receive_data(const uint32_t* src, const SimpleTIMState& state) {
|
||||||
if(size >= sizeof(SimpleTIMSize)) {
|
set_gpu_receive(src, state.dst_info.getTextureX(), state.dst_info.getTextureY(), state.size_info.getTextureWidth(), state.size_info.getTextureWidth());
|
||||||
size -= simple_read(state.size_info, config);
|
}
|
||||||
|
|
||||||
|
static bool parse_data(State::Configuration& config, SimpleTIMState& state) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool parse_header(State::Configuration& config, SimpleTIMState& state) {
|
||||||
|
if(config.data_size >= sizeof(SimpleTIMSize)) {
|
||||||
|
Helper::simple_read(state.size_info, config);
|
||||||
|
|
||||||
//Check if we have a clut to care about
|
//Check if we have a clut to care about
|
||||||
if(state.size_info.getClutWidth() > 0) {
|
if(state.size_info.getClutWidth() > 0) {
|
||||||
//CLUTs are 16bit full color anyway
|
//CLUTs are 16bit full color anyway
|
||||||
printf("We found a CLUT!\n");
|
printf("We found a CLUT which is not yet implemented!\n");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//We have direct data
|
//We have direct data
|
||||||
else {
|
else {
|
||||||
printf("We found direct data!\n");
|
set_gpu_receive_data(config.data_adr, state);
|
||||||
|
return Helper::exchange_and_execute_process_function(parse_data, config, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
static_assert(sizeof(SimpleTIMSize) == sizeof(uint32_t));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
State create(const uint32_t* data_adr, const SimpleTIM& file) {
|
State create(const uint32_t* data_adr, const SimpleTIM& file) {
|
||||||
|
|
Loading…
Reference in New Issue