Fix the shader loader
- fixed cmake file as well? - remove useless files from example - reenable runtime shader compiler for some reason the raw data of a shader must stay in ram while the shader is loaded. It can be unloaded when the shader gets unloaded
This commit is contained in:
@@ -7,11 +7,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED true)
|
|||||||
|
|
||||||
option(AMY_GOD_DEV "Turn this on if you think you are god" OFF)
|
option(AMY_GOD_DEV "Turn this on if you think you are god" OFF)
|
||||||
# THis option should be disabled if you use STB_IMAGE in you main project
|
# THis option should be disabled if you use STB_IMAGE in you main project
|
||||||
set(AMY_BUILD_STB_IMAGE 0)
|
set(AMY_BUILD_STB_IMAGE CACHE BOOL 0)
|
||||||
set(AMY_BUILD_STB_TRUETYPE 1)
|
set(AMY_BUILD_STB_TRUETYPE 1)
|
||||||
set(AMY_WITH_MPG123 "Include MP3 Support" CACHE BOOL 1)
|
set(AMY_WITH_MPG123 "Include MP3 Support" CACHE BOOL 1)
|
||||||
|
|
||||||
#add_subdirectory(vendor/libpicasso)
|
add_subdirectory(vendor/libpicasso)
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} STATIC
|
add_library(${PROJECT_NAME} STATIC
|
||||||
source/app.cpp
|
source/app.cpp
|
||||||
@@ -36,7 +36,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
|
|||||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/source/internal
|
${CMAKE_CURRENT_SOURCE_DIR}/source/internal
|
||||||
)
|
)
|
||||||
#target_link_libraries(${PROJECT_NAME} PUBLIC pica::pica)
|
target_link_libraries(${PROJECT_NAME} PUBLIC pica::pica)
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC m z ctru citro3d mpg123)
|
target_link_libraries(${PROJECT_NAME} PUBLIC m z ctru citro3d mpg123)
|
||||||
target_compile_definitions(${PROJECT_NAME} PUBLIC
|
target_compile_definitions(${PROJECT_NAME} PUBLIC
|
||||||
AMY_3DS
|
AMY_3DS
|
||||||
|
|||||||
@@ -1,27 +1,9 @@
|
|||||||
cmake_minimum_required(VERSION 3.22)
|
cmake_minimum_required(VERSION 3.22)
|
||||||
|
|
||||||
find_program(PICASSO NAMES picasso REQUIRED)
|
|
||||||
|
|
||||||
# Function origanally Created in Re-Craft-3DS
|
|
||||||
function(__amy_make_shader arg1 arg2)
|
|
||||||
# These only exist cause i was stupid
|
|
||||||
set(__FILE ${arg1})
|
|
||||||
set(__NAME ${arg2})
|
|
||||||
|
|
||||||
# Need to build shaders during config stage :(
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${PICASSO} -o "${CMAKE_CURRENT_SOURCE_DIR}/romfs/shaders/${__NAME}.shbin" "${__FILE}"
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
project(amethyst-example)
|
project(amethyst-example)
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED true)
|
set(CMAKE_CXX_STANDARD_REQUIRED true)
|
||||||
|
|
||||||
__amy_make_shader(${CMAKE_CURRENT_SOURCE_DIR}/shaders/shader2d.v.pica shader2d)
|
|
||||||
__amy_make_shader(${CMAKE_CURRENT_SOURCE_DIR}/shaders/lithium.v.pica lithium)
|
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} source/main.cpp)
|
add_executable(${PROJECT_NAME} source/main.cpp)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE amethyst)
|
target_link_libraries(${PROJECT_NAME} PRIVATE amethyst)
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE -O2)
|
target_compile_options(${PROJECT_NAME} PRIVATE -O2)
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
; LI7 Shader
|
|
||||||
; Constants
|
|
||||||
.constf myconst(0.0, 1.0, 0.00392156862745, 0.0)
|
|
||||||
.alias ones myconst.yyyy ; Vector full of ones
|
|
||||||
|
|
||||||
; Uniforms
|
|
||||||
.fvec projection[4]
|
|
||||||
|
|
||||||
; Outputs
|
|
||||||
.out out_position position
|
|
||||||
.out out_color color
|
|
||||||
.out out_uv texcoord0
|
|
||||||
|
|
||||||
; Inputs
|
|
||||||
.alias in_xy v0
|
|
||||||
.alias in_uvc v1
|
|
||||||
.alias in_col v2
|
|
||||||
|
|
||||||
.proc main
|
|
||||||
mov r0.xy, in_xy.xy
|
|
||||||
mov r0.w, ones
|
|
||||||
|
|
||||||
dp4 out_position.x, projection[0], r0
|
|
||||||
dp4 out_position.y, projection[1], r0
|
|
||||||
dp4 out_position.z, projection[2], r0
|
|
||||||
dp4 out_position.w, projection[3], r0
|
|
||||||
|
|
||||||
mov out_uv, in_uvc.xy
|
|
||||||
|
|
||||||
mul r1, myconst.zzzz, in_col
|
|
||||||
mov out_color, r1
|
|
||||||
end
|
|
||||||
.end
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
; Example PICA200 vertex shader
|
|
||||||
|
|
||||||
; Uniforms
|
|
||||||
.fvec projection[4]
|
|
||||||
|
|
||||||
; Constants
|
|
||||||
.constf myconst(0.0, 1.0, -1.0, 0.1)
|
|
||||||
.constf myconst2(0.3, 0.0, 0.0, 0.0)
|
|
||||||
.alias zeros myconst.xxxx ; Vector full of zeros
|
|
||||||
.alias ones myconst.yyyy ; Vector full of ones
|
|
||||||
|
|
||||||
; Outputs
|
|
||||||
.out outpos position
|
|
||||||
.out outclr color
|
|
||||||
|
|
||||||
; Inputs (defined as aliases for convenience)
|
|
||||||
.alias inpos v0
|
|
||||||
.alias inclr v1
|
|
||||||
|
|
||||||
.bool test
|
|
||||||
|
|
||||||
.proc main
|
|
||||||
; Force the w component of inpos to be 1.0
|
|
||||||
mov r0.xyz, inpos
|
|
||||||
mov r0.w, ones
|
|
||||||
|
|
||||||
; outpos = projectionMatrix * inpos
|
|
||||||
dp4 outpos.x, projection[0], r0
|
|
||||||
dp4 outpos.y, projection[1], r0
|
|
||||||
dp4 outpos.z, projection[2], r0
|
|
||||||
dp4 outpos.w, projection[3], r0
|
|
||||||
|
|
||||||
; outclr = inclr
|
|
||||||
mov outclr, inclr
|
|
||||||
|
|
||||||
; We're finished
|
|
||||||
end
|
|
||||||
.end
|
|
||||||
@@ -60,6 +60,7 @@ class C3D {
|
|||||||
shaderProgram_s pProgram;
|
shaderProgram_s pProgram;
|
||||||
DVLB_s* pCode = nullptr;
|
DVLB_s* pCode = nullptr;
|
||||||
int pReg = 0;
|
int pReg = 0;
|
||||||
|
std::vector<uc> pRawData;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Frag {
|
class Frag {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <amethyst/c3d.hpp>
|
#include <amethyst/c3d.hpp>
|
||||||
#include <amethyst/utils.hpp>
|
#include <amethyst/utils.hpp>
|
||||||
// #include <pica.hpp>
|
#include <pica.hpp>
|
||||||
|
|
||||||
namespace Amy {
|
namespace Amy {
|
||||||
|
|
||||||
@@ -58,22 +58,23 @@ void C3D::Shader::Load(const std::string& path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void C3D::Shader::Load(const std::vector<uc>& data) {
|
void C3D::Shader::Load(const std::vector<uc>& data) {
|
||||||
pCode = DVLB_ParseFile((u32*)&data[0], data.size());
|
if (!data.size()) {
|
||||||
|
throw std::runtime_error("[amy] unable to load shader from data!");
|
||||||
|
}
|
||||||
|
pRawData = data;
|
||||||
|
pCode = DVLB_ParseFile((u32*)&pRawData[0], pRawData.size());
|
||||||
shaderProgramInit(&pProgram);
|
shaderProgramInit(&pProgram);
|
||||||
shaderProgramSetVsh(&pProgram, &pCode->DVLE[0]);
|
shaderProgramSetVsh(&pProgram, &pCode->DVLE[0]);
|
||||||
C3D_BindProgram(&pProgram);
|
|
||||||
AttrInfo_Init(&pInfo);
|
AttrInfo_Init(&pInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void C3D::Shader::Compile(const std::string& code) {
|
void C3D::Shader::Compile(const std::string& code) {
|
||||||
throw std::runtime_error("[amy]: unable to compile shader (not allowed)");
|
auto ret = Pica::AssembleCode(code.c_str());
|
||||||
/*auto ret = Pica::AssembleCode(code.c_str());
|
Load(ret);
|
||||||
Load(ret);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void C3D::Shader::Use() {
|
void C3D::Shader::Use() {
|
||||||
// C3D_BindProgram(&pProgram);
|
// C3D_BindProgram(&pProgram);
|
||||||
// for some reason i need both ???
|
|
||||||
// code works perfectly without C3D_BindProgram
|
// code works perfectly without C3D_BindProgram
|
||||||
// but nor withour shaderProgramUse ...
|
// but nor withour shaderProgramUse ...
|
||||||
shaderProgramUse(&pProgram);
|
shaderProgramUse(&pProgram);
|
||||||
|
|||||||
@@ -39,12 +39,6 @@ const char* __ironshader__ = R"(; LI7 Shader
|
|||||||
end
|
end
|
||||||
.end)";
|
.end)";
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
unsigned char li_shader[] = {
|
|
||||||
0x44, 0x56, 0x4c, 0x42, 0x1, 0x0, 0x0, 0x0, 0xa4, 0x0, 0x0, 0x0, 0x44, 0x56, 0x4c, 0x50, 0x0, 0x0, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x50, 0x0, 0x0, 0x0, 0x9, 0x0, 0x0, 0x0, 0x98, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4e, 0x1, 0xf0, 0x7, 0x4e, 0x2, 0x8, 0x2, 0x8, 0x3, 0x18, 0x2, 0x8, 0x4, 0x28, 0x2, 0x8, 0x5, 0x38, 0x2, 0x8, 0x6, 0x10, 0x40, 0x4c, 0x7, 0xf1, 0x27, 0x22, 0x8, 0x10, 0x21, 0x4c, 0x0, 0x0, 0x0, 0x88, 0xac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|
|
||||||
// clang-format on
|
|
||||||
size_t li_shader_size = 0x124;
|
|
||||||
std::vector<Iron::Vertex, LinearAllocator<Iron::Vertex>> Iron::m_vbuf;
|
std::vector<Iron::Vertex, LinearAllocator<Iron::Vertex>> Iron::m_vbuf;
|
||||||
std::vector<u16, LinearAllocator<u16>> Iron::m_ibuf;
|
std::vector<u16, LinearAllocator<u16>> Iron::m_ibuf;
|
||||||
int Iron::uLocProj = 0;
|
int Iron::uLocProj = 0;
|
||||||
@@ -132,20 +126,11 @@ bool Iron::pCheckSize(size_t idx, size_t vtx) {
|
|||||||
|
|
||||||
void Iron::pSetupShader() {
|
void Iron::pSetupShader() {
|
||||||
m_shader = new C3D::Shader();
|
m_shader = new C3D::Shader();
|
||||||
m_shader->pCode = DVLB_ParseFile((u32*)li_shader, li_shader_size);
|
m_shader->Compile(__ironshader__);
|
||||||
shaderProgramInit(&m_shader->pProgram);
|
|
||||||
shaderProgramSetVsh(&m_shader->pProgram, &m_shader->pCode->DVLE[0]);
|
|
||||||
AttrInfo_Init(&m_shader->pInfo);
|
|
||||||
AttrInfo_AddLoader(&m_shader->pInfo, 0, GPU_FLOAT, 2);
|
|
||||||
AttrInfo_AddLoader(&m_shader->pInfo, 1, GPU_FLOAT, 2);
|
|
||||||
AttrInfo_AddLoader(&m_shader->pInfo, 2, GPU_UNSIGNED_BYTE, 4);
|
|
||||||
// TODO: FUNKTIONIRT NICHT AHHHHHHHHHH
|
|
||||||
/*m_shader->Load("romfs:/shaders/lithium.shbin");
|
|
||||||
// m_shader->Compile(__ironshader__);
|
|
||||||
m_shader->Input(GPU_FLOAT, 2); // pos
|
m_shader->Input(GPU_FLOAT, 2); // pos
|
||||||
m_shader->Input(GPU_FLOAT, 2); // uv
|
m_shader->Input(GPU_FLOAT, 2); // uv
|
||||||
m_shader->Input(GPU_UNSIGNED_BYTE, 4); // color
|
m_shader->Input(GPU_UNSIGNED_BYTE, 4); // color
|
||||||
uLocProj = m_shader->loc("projection");*/
|
uLocProj = m_shader->loc("projection");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Iron::pFragConfig() {
|
void Iron::pFragConfig() {
|
||||||
|
|||||||
Reference in New Issue
Block a user