mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 00:56:40 -04:00
PS3: Rendering mostly works now
This commit is contained in:
parent
57c05867d6
commit
4c60ceda46
15
misc/ps3/vs_offset.vcg
Normal file
15
misc/ps3/vs_offset.vcg
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
void main(
|
||||||
|
float4 in_position : POSITION,
|
||||||
|
float4 in_color : DIFFUSE,
|
||||||
|
float4 in_tex : TEXCOORD,
|
||||||
|
uniform float4x4 mvp,
|
||||||
|
uniform float4 uv_offset,
|
||||||
|
out float4 out_pos : POSITION,
|
||||||
|
out float4 out_color : COLOR,
|
||||||
|
out float2 out_tex : TEXCOORD0)
|
||||||
|
{
|
||||||
|
float4 pos = float4(in_position.xyz, 1.0f);
|
||||||
|
out_pos = mul(pos, mvp);
|
||||||
|
out_color = in_color;
|
||||||
|
out_tex = in_tex + uv_offset;
|
||||||
|
}
|
@ -26,30 +26,39 @@ typedef struct CCVertexProgram {
|
|||||||
rsxVertexProgram* prog;
|
rsxVertexProgram* prog;
|
||||||
void* ucode;
|
void* ucode;
|
||||||
rsxProgramConst* mvp;
|
rsxProgramConst* mvp;
|
||||||
|
rsxProgramConst* uv_offset;
|
||||||
} VertexProgram;
|
} VertexProgram;
|
||||||
|
|
||||||
extern const u8 vs_textured_vpo[];
|
|
||||||
extern const u8 vs_coloured_vpo[];
|
extern const u8 vs_coloured_vpo[];
|
||||||
|
extern const u8 vs_textured_vpo[];
|
||||||
|
extern const u8 vs_offset_vpo[];
|
||||||
|
|
||||||
static VertexProgram VP_list[2];
|
static VertexProgram VP_list[3];
|
||||||
static VertexProgram* VP_active;
|
static VertexProgram* VP_active;
|
||||||
|
|
||||||
|
static cc_bool textureOffseting;
|
||||||
|
static float textureOffset[4] __attribute__((aligned(16)));
|
||||||
|
static struct Matrix mvp __attribute__((aligned(64)));
|
||||||
|
|
||||||
|
|
||||||
static void VP_Load(VertexProgram* vp, const u8* source) {
|
static void VP_Load(VertexProgram* vp, const u8* source) {
|
||||||
vp->prog = (rsxVertexProgram*)source;
|
vp->prog = (rsxVertexProgram*)source;
|
||||||
u32 size = 0;
|
u32 size = 0;
|
||||||
rsxVertexProgramGetUCode(vp->prog, &vp->ucode, &size);
|
rsxVertexProgramGetUCode(vp->prog, &vp->ucode, &size);
|
||||||
|
|
||||||
vp->mvp = rsxVertexProgramGetConst(vp->prog, "mvp");
|
vp->mvp = rsxVertexProgramGetConst(vp->prog, "mvp");
|
||||||
|
vp->uv_offset = rsxVertexProgramGetConst(vp->prog, "uv_offset");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadVertexPrograms(void) {
|
static void LoadVertexPrograms(void) {
|
||||||
VP_Load(&VP_list[0], vs_coloured_vpo);
|
VP_Load(&VP_list[0], vs_coloured_vpo);
|
||||||
VP_Load(&VP_list[1], vs_textured_vpo);
|
VP_Load(&VP_list[1], vs_textured_vpo);
|
||||||
|
VP_Load(&VP_list[2], vs_offset_vpo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void VP_SwitchActive(void) {
|
static void VP_SwitchActive(void) {
|
||||||
int index = gfx_format == VERTEX_FORMAT_TEXTURED ? 1 : 0;
|
int index = gfx_format == VERTEX_FORMAT_TEXTURED ? 1 : 0;
|
||||||
|
if (textureOffseting) index = 2;
|
||||||
|
|
||||||
VertexProgram* VP = &VP_list[index];
|
VertexProgram* VP = &VP_list[index];
|
||||||
if (VP == VP_active) return;
|
if (VP == VP_active) return;
|
||||||
@ -58,6 +67,20 @@ static void VP_SwitchActive(void) {
|
|||||||
rsxLoadVertexProgram(context, VP->prog, VP->ucode);
|
rsxLoadVertexProgram(context, VP->prog, VP->ucode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void VP_UpdateUniforms() {
|
||||||
|
// TODO: dirty uniforms instead
|
||||||
|
for (int i = 0; i < Array_Elems(VP_list); i++)
|
||||||
|
{
|
||||||
|
VertexProgram* vp = &VP_list[i];
|
||||||
|
rsxSetVertexProgramParameter(context, vp->prog, vp->mvp, (float*)&mvp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VP_active == &VP_list[2]) {
|
||||||
|
VertexProgram* vp = &VP_list[2];
|
||||||
|
rsxSetVertexProgramParameter(context, vp->prog, vp->uv_offset, textureOffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------- Fragment Shaders ---------------------------------------------------*
|
*---------------------------------------------------- Fragment Shaders ---------------------------------------------------*
|
||||||
@ -113,28 +136,6 @@ static u32 depth_pitch;
|
|||||||
static u32 depth_offset;
|
static u32 depth_offset;
|
||||||
static u32* depth_buffer;
|
static u32* depth_buffer;
|
||||||
|
|
||||||
static void Gfx_FreeState(void) { FreeDefaultResources(); }
|
|
||||||
static void Gfx_RestoreState(void) {
|
|
||||||
InitDefaultResources();
|
|
||||||
gfx_format = -1;/* TODO */
|
|
||||||
|
|
||||||
rsxSetColorMaskMrt(context, 0);
|
|
||||||
rsxSetDepthFunc(context, GCM_LEQUAL);
|
|
||||||
rsxSetClearDepthStencil(context, 0xFFFFFFFF);
|
|
||||||
//rsxSetFrontFace(context, GCM_FRONTFACE_CCW);
|
|
||||||
|
|
||||||
rsxSetAlphaFunc(context, GCM_GREATER, 0.5f);
|
|
||||||
rsxSetBlendFunc(context, GCM_SRC_ALPHA, GCM_ONE_MINUS_SRC_ALPHA, GCM_SRC_ALPHA, GCM_ONE_MINUS_SRC_ALPHA);
|
|
||||||
rsxSetBlendEquation(context, GCM_FUNC_ADD, GCM_FUNC_ADD);
|
|
||||||
|
|
||||||
rsxSetUserClipPlaneControl(context,GCM_USER_CLIP_PLANE_DISABLE,
|
|
||||||
GCM_USER_CLIP_PLANE_DISABLE,
|
|
||||||
GCM_USER_CLIP_PLANE_DISABLE,
|
|
||||||
GCM_USER_CLIP_PLANE_DISABLE,
|
|
||||||
GCM_USER_CLIP_PLANE_DISABLE,
|
|
||||||
GCM_USER_CLIP_PLANE_DISABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CreateContext(void) {
|
static void CreateContext(void) {
|
||||||
void* host_addr = memalign(1024 * 1024, HOST_SIZE);
|
void* host_addr = memalign(1024 * 1024, HOST_SIZE);
|
||||||
rsxInit(&context, CB_SIZE, HOST_SIZE, host_addr);
|
rsxInit(&context, CB_SIZE, HOST_SIZE, host_addr);
|
||||||
@ -211,11 +212,8 @@ void SetRenderTarget(u32 index) {
|
|||||||
|
|
||||||
rsxSetSurface(context,&sf);
|
rsxSetSurface(context,&sf);
|
||||||
}
|
}
|
||||||
static GfxResourceID white_square;
|
|
||||||
|
|
||||||
void Gfx_Create(void) {
|
static void InitGfxContext(void) {
|
||||||
// TODO rethink all this
|
|
||||||
if (Gfx.Created) return;
|
|
||||||
Gfx.MaxTexWidth = 1024;
|
Gfx.MaxTexWidth = 1024;
|
||||||
Gfx.MaxTexHeight = 1024;
|
Gfx.MaxTexHeight = 1024;
|
||||||
Gfx.Created = true;
|
Gfx.Created = true;
|
||||||
@ -231,11 +229,29 @@ void Gfx_Create(void) {
|
|||||||
gcmResetFlipStatus();
|
gcmResetFlipStatus();
|
||||||
|
|
||||||
SetupBlendingState();
|
SetupBlendingState();
|
||||||
Gfx_RestoreState();
|
|
||||||
SetRenderTarget(cur_fb);
|
SetRenderTarget(cur_fb);
|
||||||
|
|
||||||
LoadVertexPrograms();
|
LoadVertexPrograms();
|
||||||
LoadFragmentPrograms();
|
LoadFragmentPrograms();
|
||||||
|
}
|
||||||
|
static GfxResourceID white_square;
|
||||||
|
|
||||||
|
void Gfx_Create(void) {
|
||||||
|
// TODO rethink all this
|
||||||
|
if (!Gfx.Created) InitGfxContext();
|
||||||
|
|
||||||
|
Gfx_RestoreState();
|
||||||
|
gfx_format = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Gfx_Free(void) { Gfx_FreeState(); }
|
||||||
|
|
||||||
|
|
||||||
|
cc_bool Gfx_TryRestoreContext(void) { return true; }
|
||||||
|
cc_bool Gfx_WarnIfNecessary(void) { return false; }
|
||||||
|
|
||||||
|
void Gfx_RestoreState(void) {
|
||||||
|
InitDefaultResources();
|
||||||
|
|
||||||
// 1x1 dummy white texture
|
// 1x1 dummy white texture
|
||||||
struct Bitmap bmp;
|
struct Bitmap bmp;
|
||||||
@ -244,14 +260,12 @@ void Gfx_Create(void) {
|
|||||||
white_square = Gfx_CreateTexture(&bmp, 0, false);
|
white_square = Gfx_CreateTexture(&bmp, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_bool Gfx_TryRestoreContext(void) { return true; }
|
void Gfx_FreeState(void) {
|
||||||
|
FreeDefaultResources();
|
||||||
cc_bool Gfx_WarnIfNecessary(void) { return false; }
|
Gfx_DeleteTexture(&white_square);
|
||||||
|
|
||||||
void Gfx_Free(void) {
|
|
||||||
Gfx_FreeState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
u32* Gfx_AllocImage(u32* offset, s32 w, s32 h) {
|
u32* Gfx_AllocImage(u32* offset, s32 w, s32 h) {
|
||||||
u32* pixels = (u32*)rsxMemalign(64, w * h * 4);
|
u32* pixels = (u32*)rsxMemalign(64, w * h * 4);
|
||||||
rsxAddressToOffset(pixels, offset);
|
rsxAddressToOffset(pixels, offset);
|
||||||
@ -269,6 +283,8 @@ void Gfx_TransferImage(u32 offset, s32 w, s32 h) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------State management----------------------------------------------------*
|
*-----------------------------------------------------State management----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
static cc_uint32 clearColor;
|
||||||
|
|
||||||
void Gfx_SetFaceCulling(cc_bool enabled) {
|
void Gfx_SetFaceCulling(cc_bool enabled) {
|
||||||
rsxSetCullFaceEnable(context, enabled);
|
rsxSetCullFaceEnable(context, enabled);
|
||||||
}
|
}
|
||||||
@ -279,7 +295,11 @@ void Gfx_SetAlphaBlending(cc_bool enabled) {
|
|||||||
void Gfx_SetAlphaArgBlend(cc_bool enabled) { }
|
void Gfx_SetAlphaArgBlend(cc_bool enabled) { }
|
||||||
|
|
||||||
void Gfx_ClearCol(PackedCol color) {
|
void Gfx_ClearCol(PackedCol color) {
|
||||||
rsxSetClearColor(context, color);
|
cc_uint32 R = PackedCol_R(color);
|
||||||
|
cc_uint32 G = PackedCol_G(color);
|
||||||
|
cc_uint32 B = PackedCol_B(color);
|
||||||
|
|
||||||
|
clearColor = B | (G << 8) | (R << 16) | (0xFF << 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_SetColWriteMask(cc_bool r, cc_bool g, cc_bool b, cc_bool a) {
|
void Gfx_SetColWriteMask(cc_bool r, cc_bool g, cc_bool b, cc_bool a) {
|
||||||
@ -373,6 +393,29 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
|
|||||||
gfx_vsync = vsync;
|
gfx_vsync = vsync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ResetFrameState(void) {
|
||||||
|
// Seems these states aren't persisted across frames
|
||||||
|
// TODO: Why is that
|
||||||
|
rsxSetAlphaFunc(context, GCM_GREATER, 0.5f);
|
||||||
|
rsxSetBlendFunc(context, GCM_SRC_ALPHA, GCM_ONE_MINUS_SRC_ALPHA, GCM_SRC_ALPHA, GCM_ONE_MINUS_SRC_ALPHA);
|
||||||
|
rsxSetBlendEquation(context, GCM_FUNC_ADD, GCM_FUNC_ADD);
|
||||||
|
|
||||||
|
rsxSetColorMaskMrt(context, 0);
|
||||||
|
rsxSetDepthFunc(context, GCM_LEQUAL);
|
||||||
|
rsxSetClearColor(context, clearColor);
|
||||||
|
rsxSetClearDepthStencil(context, 0xFFFFFFFF);
|
||||||
|
rsxSetFrontFace(context, GCM_FRONTFACE_CCW);
|
||||||
|
|
||||||
|
rsxSetUserClipPlaneControl(context, GCM_USER_CLIP_PLANE_DISABLE,
|
||||||
|
GCM_USER_CLIP_PLANE_DISABLE,
|
||||||
|
GCM_USER_CLIP_PLANE_DISABLE,
|
||||||
|
GCM_USER_CLIP_PLANE_DISABLE,
|
||||||
|
GCM_USER_CLIP_PLANE_DISABLE,
|
||||||
|
GCM_USER_CLIP_PLANE_DISABLE);
|
||||||
|
|
||||||
|
// NOTE: Must be called each frame, otherwise renders upside down at 4x zoom
|
||||||
|
Gfx_OnWindowResize();
|
||||||
|
}
|
||||||
|
|
||||||
// https://github.com/ps3dev/PSL1GHT/blob/master/ppu/include/rsx/rsx.h#L30
|
// https://github.com/ps3dev/PSL1GHT/blob/master/ppu/include/rsx/rsx.h#L30
|
||||||
static cc_bool everFlipped;
|
static cc_bool everFlipped;
|
||||||
@ -382,6 +425,7 @@ void Gfx_BeginFrame(void) {
|
|||||||
while (gcmGetFlipStatus() != 0) usleep(200);
|
while (gcmGetFlipStatus() != 0) usleep(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResetFrameState();
|
||||||
everFlipped = true;
|
everFlipped = true;
|
||||||
gcmResetFlipStatus();
|
gcmResetFlipStatus();
|
||||||
}
|
}
|
||||||
@ -398,8 +442,6 @@ void Gfx_EndFrame(void) {
|
|||||||
|
|
||||||
cur_fb ^= 1;
|
cur_fb ^= 1;
|
||||||
SetRenderTarget(cur_fb);
|
SetRenderTarget(cur_fb);
|
||||||
// NOTE: Must be called, otherwise renders upside down at 4x zoom
|
|
||||||
Gfx_OnWindowResize();
|
|
||||||
|
|
||||||
if (gfx_minFrameMs) LimitFPS();
|
if (gfx_minFrameMs) LimitFPS();
|
||||||
}
|
}
|
||||||
@ -621,16 +663,9 @@ static struct Matrix _view, _proj;
|
|||||||
void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {
|
void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {
|
||||||
struct Matrix* dst = type == MATRIX_PROJECTION ? &_proj : &_view;
|
struct Matrix* dst = type == MATRIX_PROJECTION ? &_proj : &_view;
|
||||||
*dst = *matrix;
|
*dst = *matrix;
|
||||||
|
|
||||||
struct Matrix mvp;
|
|
||||||
Matrix_Mul(&mvp, &_view, &_proj);
|
Matrix_Mul(&mvp, &_view, &_proj);
|
||||||
|
VP_UpdateUniforms();
|
||||||
// TODO: dirty uniforms instead
|
|
||||||
for (int i = 0; i < Array_Elems(VP_list); i++)
|
|
||||||
{
|
|
||||||
VertexProgram* vp = &VP_list[i];
|
|
||||||
rsxSetVertexProgramParameter(context, vp->prog, vp->mvp, (float*)&mvp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_LoadIdentityMatrix(MatrixType type) {
|
void Gfx_LoadIdentityMatrix(MatrixType type) {
|
||||||
@ -638,11 +673,17 @@ void Gfx_LoadIdentityMatrix(MatrixType type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_EnableTextureOffset(float x, float y) {
|
void Gfx_EnableTextureOffset(float x, float y) {
|
||||||
/* TODO */
|
textureOffseting = true;
|
||||||
|
textureOffset[0] = x;
|
||||||
|
textureOffset[1] = y;
|
||||||
|
|
||||||
|
VP_SwitchActive();
|
||||||
|
VP_UpdateUniforms();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_DisableTextureOffset(void) {
|
void Gfx_DisableTextureOffset(void) {
|
||||||
/* TODO */
|
textureOffseting = false;
|
||||||
|
VP_SwitchActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
typedef cc_uint32 PackedCol;
|
typedef cc_uint32 PackedCol;
|
||||||
#if defined CC_BUILD_D3D9 || defined CC_BUILD_XBOX || defined CC_BUILD_DREAMCAST || defined CC_BUILD_PS3
|
#if defined CC_BUILD_D3D9 || defined CC_BUILD_XBOX || defined CC_BUILD_DREAMCAST
|
||||||
#define PACKEDCOL_B_SHIFT 0
|
#define PACKEDCOL_B_SHIFT 0
|
||||||
#define PACKEDCOL_G_SHIFT 8
|
#define PACKEDCOL_G_SHIFT 8
|
||||||
#define PACKEDCOL_R_SHIFT 16
|
#define PACKEDCOL_R_SHIFT 16
|
||||||
|
@ -721,38 +721,6 @@ int SysFont_TextWidth(struct DrawTextArgs* args) {
|
|||||||
void SysFont_DrawText(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow) {
|
void SysFont_DrawText(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow) {
|
||||||
interop_SysTextDraw(args, bmp, x, y, shadow);
|
interop_SysTextDraw(args, bmp, x, y, shadow);
|
||||||
}
|
}
|
||||||
#elif defined CC_BUILD_PSP || defined CC_BUILD_XBOX
|
|
||||||
void SysFonts_Register(const cc_string* path) { }
|
|
||||||
|
|
||||||
const cc_string* SysFonts_UNSAFE_GetDefault(void) { return &String_Empty; }
|
|
||||||
|
|
||||||
void SysFonts_GetNames(struct StringsBuffer* buffer) { }
|
|
||||||
|
|
||||||
cc_result SysFont_Make(struct FontDesc* desc, const cc_string* fontName, int size, int flags) {
|
|
||||||
desc->size = size;
|
|
||||||
desc->flags = flags;
|
|
||||||
desc->height = Drawer2D_AdjHeight(size);
|
|
||||||
|
|
||||||
desc->handle = (void*)1;
|
|
||||||
|
|
||||||
// TODO: Actually implement native font APIs
|
|
||||||
Font_MakeBitmapped(desc, size, flags);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SysFont_MakeDefault(struct FontDesc* desc, int size, int flags) {
|
|
||||||
SysFont_Make(desc, NULL, size, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SysFont_Free(struct FontDesc* desc) {
|
|
||||||
}
|
|
||||||
|
|
||||||
int SysFont_TextWidth(struct DrawTextArgs* args) {
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SysFont_DrawText(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow) {
|
|
||||||
}
|
|
||||||
#elif defined CC_BUILD_GCWII
|
#elif defined CC_BUILD_GCWII
|
||||||
#include <ogc/system.h>
|
#include <ogc/system.h>
|
||||||
void SysFonts_Register(const cc_string* path) { }
|
void SysFonts_Register(const cc_string* path) { }
|
||||||
|
@ -115,12 +115,12 @@ static void HandleJoystick_Left(int x, int y) {
|
|||||||
Input.JoystickAngle = Math_Atan2(x, -y);
|
Input.JoystickAngle = Math_Atan2(x, -y);
|
||||||
}
|
}
|
||||||
static void HandleJoystick_Right(int x, int y, double delta) {
|
static void HandleJoystick_Right(int x, int y, double delta) {
|
||||||
float scale = (delta * 60.0) / 128.0f;
|
float scale = (delta * 60.0) / 64.0f;
|
||||||
|
|
||||||
if (Math_AbsI(x) <= 32) x = 0;
|
if (Math_AbsI(x) <= 32) x = 0;
|
||||||
if (Math_AbsI(y) <= 32) y = 0;
|
if (Math_AbsI(y) <= 32) y = 0;
|
||||||
|
|
||||||
Event_RaiseRawMove(&PointerEvents.RawMoved, x * scale, -y * scale);
|
Event_RaiseRawMove(&PointerEvents.RawMoved, x * scale, y * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ProcessPadInput(double delta, padData* pad) {
|
static void ProcessPadInput(double delta, padData* pad) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user