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

Update Fast3D Render Engine #76

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ $(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c
# Compile C++ code
$(BUILD_DIR)/%.o: %.cpp
$(call print,Compiling:,$<,$@)
$(V)$(CXX) -c $(CFLAGS) -D_LANGUAGE_C_PLUS_PLUS=1 $(OPT_FLAGS) -MMD -MF $(BUILD_DIR)/$*.d -o $@ $<
$(V)$(CXX) -c $(CFLAGS) -std=c++20 -D_LANGUAGE_C_PLUS_PLUS=1 $(OPT_FLAGS) -MMD -MF $(BUILD_DIR)/$*.d -o $@ $<

# Assemble assembly code
$(BUILD_DIR)/%.o: %.s
Expand Down
6 changes: 3 additions & 3 deletions defines.mk
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ endif
ifeq ($(TARGET_PORT_CONSOLE),0)

# Check for Mouse Option
ifeq ($(MOUSE_ACTIONS),1)
CUSTOM_C_DEFINES += -DMOUSE_ACTIONS
endif
#ifeq ($(MOUSE_ACTIONS),1)
# CUSTOM_C_DEFINES += -DMOUSE_ACTIONS
#endif

# Check for Discord Rich Presence option
ifeq ($(DISCORDRPC),1)
Expand Down
8 changes: 4 additions & 4 deletions src/menu/intro_geo.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,11 @@ u16 *intro_sample_framebuffer(s32 imageW, s32 imageH, s32 sampleW, s32 sampleH)
s32 xOffset = 120;
s32 yOffset = 80;

#ifdef TARGET_N64
//#ifdef TARGET_N64
fb = sFramebuffers[sRenderingFramebuffer];
#else
fb = get_framebuffer();
#endif
//#else
// fb = get_framebuffer();
//#endif

image = alloc_display_list(imageW * imageH * sizeof(u16));

Expand Down
8 changes: 4 additions & 4 deletions src/pc/configfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ ConfigWindow configWindow = {
.reset = false,
.settings_changed = false,
#else
.x = WAPI_WIN_CENTERPOS,
.y = WAPI_WIN_CENTERPOS,
.w = DESIRED_SCREEN_WIDTH,
.h = DESIRED_SCREEN_HEIGHT,
.x = 640, // TODO
.y = 360,
.w = 640,
.h = 360,
.vsync = false,
.reset = false,
.fullscreen = false,
Expand Down
4 changes: 2 additions & 2 deletions src/pc/controller/controller_sdl1.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static void controller_sdl_init(void) {
controller_sdl_bind();

init_ok = true;
mouse_init_ok = true;
//mouse_init_ok = true;
}

static inline void update_button(const int i, const bool new) {
Expand Down Expand Up @@ -294,7 +294,7 @@ static void controller_sdl_shutdown(void) {
}

init_ok = false;
mouse_init_ok = false;
//mouse_init_ok = false;
}

struct ControllerAPI controller_sdl = {
Expand Down
4 changes: 2 additions & 2 deletions src/pc/controller/controller_sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static void controller_sdl_init(void) {
controller_sdl_bind();

init_ok = true;
mouse_init_ok = true;
//mouse_init_ok = true;
}

static SDL_Haptic *controller_sdl_init_haptics(const int joy) {
Expand Down Expand Up @@ -339,7 +339,7 @@ static void controller_sdl_shutdown(void) {

haptics_enabled = false;
init_ok = false;
mouse_init_ok = false;
//mouse_init_ok = false;
}

struct ControllerAPI controller_sdl = {
Expand Down
2 changes: 1 addition & 1 deletion src/pc/controller/controller_touchscreen.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//Feel free to use it in your port too, but please keep authorship!
//Touch Controls made by: VDavid003
#ifdef TOUCH_CONTROLS
#if 0
#include <ultra64.h>
#include <PR/ultratypes.h>
#include <PR/gbi.h>
Expand Down
2 changes: 1 addition & 1 deletion src/pc/crash/crash_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define ENABLE_CRASH_HANDLER
#endif

#if (defined(_WIN32) || defined(__linux__)) && !defined(WAPI_DUMMY) && defined(ENABLE_CRASH_HANDLER)
#if 0
#ifdef HAVE_SDL2
#include <SDL2/SDL.h>
#endif
Expand Down
45 changes: 45 additions & 0 deletions src/pc/gfx/gbi_pc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include "PR/gbi.h"

// CUSTOM OTR COMMANDS
// ALONOTE: Not used standalone
#define G_SETTIMG_OTR 0x20
#define G_DL_OTR 0x31
#define G_VTX_OTR 0x32
#define G_MARKER 0x33
#define G_BRANCH_Z_OTR 0x35
#define G_MTX_OTR 0x36

#define G_SETFB 0x21
#define G_RESETFB 0x22
#define G_SETTIMG_FB 0x23
#define G_INVALTEXCACHE 0x34
//#define G_TEXRECT_WIDE 0x37
//#define G_FILLWIDERECT 0x38

#define G_TEXRECT_WIDE G_TEXRECT
#define G_FILLWIDERECT G_FILLRECT

/* GFX Effects */

// RDP Cmd
#define G_SETGRAYSCALE 0x39
#define G_SETINTENSITY 0x40

/* Private macro to wrap other macros in do {...} while (0) */
#define _DW(macro) do {macro} while (0)

#define gSPGrayscale(pkt, state) \
{ \
Gfx* _g = (Gfx*)(pkt); \
\
_g->words.w0 = _SHIFTL(G_SETGRAYSCALE, 24, 8); \
_g->words.w1 = state; \
}

#define gsSPGrayscale(state) \
{ (_SHIFTL(G_SETGRAYSCALE, 24, 8)), (state) }

#define gDPSetGrayscaleColor(pkt, r, g, b, lerp) DPRGBColor(pkt, G_SETINTENSITY, r, g, b, lerp)
#define gsDPSetGrayscaleColor(r, g, b, a) sDPRGBColor(G_SETINTENSITY, r, g, b, a)
41 changes: 0 additions & 41 deletions src/pc/gfx/gfx_cc.c

This file was deleted.

58 changes: 58 additions & 0 deletions src/pc/gfx/gfx_cc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "gfx_cc.h"

void gfx_cc_get_features(uint64_t shader_id0, uint32_t shader_id1, struct CCFeatures* cc_features) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 4; k++) {
cc_features->c[i][j][k] = (shader_id0 >> (i * 32 + j * 16 + k * 4)) & 0xf;
}
}
}

cc_features->opt_alpha = (shader_id1 & SHADER_OPT_ALPHA) != 0;
cc_features->opt_fog = (shader_id1 & SHADER_OPT_FOG) != 0;
cc_features->opt_texture_edge = (shader_id1 & SHADER_OPT_TEXTURE_EDGE) != 0;
cc_features->opt_noise = (shader_id1 & SHADER_OPT_NOISE) != 0;
cc_features->opt_2cyc = (shader_id1 & SHADER_OPT_2CYC) != 0;
cc_features->opt_alpha_threshold = (shader_id1 & SHADER_OPT_ALPHA_THRESHOLD) != 0;
cc_features->opt_invisible = (shader_id1 & SHADER_OPT_INVISIBLE) != 0;
cc_features->opt_grayscale = (shader_id1 & SHADER_OPT_GRAYSCALE) != 0;

cc_features->clamp[0][0] = (shader_id1 & SHADER_OPT_TEXEL0_CLAMP_S);
cc_features->clamp[0][1] = (shader_id1 & SHADER_OPT_TEXEL0_CLAMP_T);
cc_features->clamp[1][0] = (shader_id1 & SHADER_OPT_TEXEL1_CLAMP_S);
cc_features->clamp[1][1] = (shader_id1 & SHADER_OPT_TEXEL1_CLAMP_T);

cc_features->used_textures[0] = false;
cc_features->used_textures[1] = false;
cc_features->num_inputs = 0;

for (int c = 0; c < 2; c++) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 4; j++) {
if (cc_features->c[c][i][j] >= SHADER_INPUT_1 && cc_features->c[c][i][j] <= SHADER_INPUT_7) {
if (cc_features->c[c][i][j] > cc_features->num_inputs) {
cc_features->num_inputs = cc_features->c[c][i][j];
}
}
if (cc_features->c[c][i][j] == SHADER_TEXEL0 || cc_features->c[c][i][j] == SHADER_TEXEL0A) {
cc_features->used_textures[0] = true;
}
if (cc_features->c[c][i][j] == SHADER_TEXEL1 || cc_features->c[c][i][j] == SHADER_TEXEL1A) {
cc_features->used_textures[1] = true;
}
}
}
}

for (int c = 0; c < 2; c++) {
cc_features->do_single[c][0] = cc_features->c[c][0][2] == SHADER_0;
cc_features->do_single[c][1] = cc_features->c[c][1][2] == SHADER_0;
cc_features->do_multiply[c][0] = cc_features->c[c][0][1] == SHADER_0 && cc_features->c[c][0][3] == SHADER_0;
cc_features->do_multiply[c][1] = cc_features->c[c][1][1] == SHADER_0 && cc_features->c[c][1][3] == SHADER_0;
cc_features->do_mix[c][0] = cc_features->c[c][0][1] == cc_features->c[c][0][3];
cc_features->do_mix[c][1] = cc_features->c[c][1][1] == cc_features->c[c][1][3];
cc_features->color_alpha_same[c] =
((shader_id0 >> c * 32) & 0xffff) == ((shader_id0 >> (c * 32 + 16)) & 0xffff);
}
}
55 changes: 34 additions & 21 deletions src/pc/gfx/gfx_cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdint.h>
#include <stdbool.h>

enum {
/*enum {
CC_0,
CC_TEXEL0,
CC_TEXEL1,
Expand All @@ -13,46 +13,59 @@ enum {
CC_ENV,
CC_TEXEL0A,
CC_LOD
};
};*/

enum {
SHADER_0,
SHADER_INPUT_1,
SHADER_INPUT_2,
SHADER_INPUT_3,
SHADER_INPUT_4,
SHADER_INPUT_5,
SHADER_INPUT_6,
SHADER_INPUT_7,
SHADER_TEXEL0,
SHADER_TEXEL0A,
SHADER_TEXEL1
SHADER_TEXEL1,
SHADER_TEXEL1A,
SHADER_1,
SHADER_COMBINED,
SHADER_NOISE
};

#define SHADER_OPT_ALPHA (1 << 24)
#define SHADER_OPT_FOG (1 << 25)
#define SHADER_OPT_TEXTURE_EDGE (1 << 26)
#define SHADER_OPT_NOISE (1 << 27)
#define SHADER_OPT_ALPHA (1 << 0)
#define SHADER_OPT_FOG (1 << 1)
#define SHADER_OPT_TEXTURE_EDGE (1 << 2)
#define SHADER_OPT_NOISE (1 << 3)
#define SHADER_OPT_2CYC (1 << 4)
#define SHADER_OPT_ALPHA_THRESHOLD (1 << 5)
#define SHADER_OPT_INVISIBLE (1 << 6)
#define SHADER_OPT_GRAYSCALE (1 << 7)
#define SHADER_OPT_TEXEL0_CLAMP_S (1 << 8)
#define SHADER_OPT_TEXEL0_CLAMP_T (1 << 9)
#define SHADER_OPT_TEXEL1_CLAMP_S (1 << 10)
#define SHADER_OPT_TEXEL1_CLAMP_T (1 << 11)
#define CC_SHADER_OPT_POS 56

struct CCFeatures {
uint8_t c[2][4];
uint8_t c[2][2][4];
bool opt_alpha;
bool opt_fog;
bool opt_texture_edge;
bool opt_noise;
bool opt_2cyc;
bool opt_alpha_threshold;
bool opt_invisible;
bool opt_grayscale;
bool used_textures[2];
bool clamp[2][2];
int num_inputs;
bool do_single[2];
bool do_multiply[2];
bool do_mix[2];
bool color_alpha_same;
bool do_single[2][2];
bool do_multiply[2][2];
bool do_mix[2][2];
bool color_alpha_same[2];
};

#ifdef __cplusplus
extern "C" {
#endif

void gfx_cc_get_features(uint32_t shader_id, struct CCFeatures *cc_features);

#ifdef __cplusplus
}
#endif
void gfx_cc_get_features(uint64_t shader_id0, uint32_t shader_id1, struct CCFeatures* cc_features);

#endif
12 changes: 12 additions & 0 deletions src/pc/gfx/gfx_defines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#define LEGACY_GFX_WIDOW_API

//#define LEGACY_GFX_RENDER_API

/* Essential, do not edit unless you know what are you doing */

// SoH uses ImGui to set window dimensions, which are separate to render dimensions
// so options like resolution scale and msaa can work properly
// For now we set these the same if framebuffers are enabled to simply render on screen independently
#define ENABLE_FRAMEBUFFER 1
Loading