Merge branch 'master' into ModernLighting

This commit is contained in:
Goodlyay 2024-05-18 00:20:58 -07:00
commit 64c4582b01
47 changed files with 985 additions and 796 deletions

View File

@ -3,6 +3,7 @@ name: Build latest (3DS)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (Dreamcast)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (FreeBSD)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (Haiku)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (iOS)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (Linux)
on:
push:
branches:
- main
- master
- ModernLighting
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (macOS 64 bit)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (N64)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (NDS)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (NetBSD)
on:
push:
branches:
- main
- master
workflow_dispatch:
@ -14,7 +15,7 @@ jobs:
build:
runs-on: ubuntu-latest
container:
image: ghcr.io/cross-rs/x86_64-unknown-netbsd
image: ghcr.io/cross-rs/x86_64-unknown-netbsd:edge
steps:
- uses: actions/checkout@v3
- name: Install prerequisites

View File

@ -3,6 +3,7 @@ name: Build latest (PS2)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (PS3)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (PSP)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (RPI)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (Saturn)
on:
push:
branches:
- main
- master
workflow_dispatch:
@ -20,6 +21,8 @@ jobs:
- name: Compile Saturn build
id: compile
run: |
apt-get update
apt-get -y install curl
make saturn
- uses: ./.github/actions/notify_failure

View File

@ -3,6 +3,7 @@ name: Build latest (Switch)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (Vita)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (Webclient)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (Wii/GameCube)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (WiiU)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (Windows ARM32/64)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (Windows)
on:
push:
branches:
- main
- master
- ModernLighting
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (Xbox)
on:
push:
branches:
- main
- master
workflow_dispatch:

View File

@ -3,6 +3,7 @@ name: Build latest (Xbox 360)
on:
push:
branches:
- main
- master
workflow_dispatch:

2
.gitignore vendored
View File

@ -97,6 +97,8 @@ CMakeCache.txt
#GCC object files
*.o
# Build dependency files
*.d
# Roslyn cache directories
*.ide/

View File

@ -1,126 +1,93 @@
!r0 = prefetch address
!r1 = GPU VERT command
!r2 = GPU EOS command
!r3 = colour
!r0 = clip flags
!r1 = GPU command
!r2 = temp
!r3 = prefetch address
!r4 = src pointer ARG
!r5 = dst pointer ARG
!r6 = quads count ARG
!r7 = ?
!fr0 = temp
!fr1 = u (0.0)
!fr2 = v (0.0)
!fr3 = c
!fr4 = x
!fr5 = y
!fr6 = z
!fr7 = w
!fr9 = 0
!fr10 = ?
!fr11 = ?
!fr8 = VIEWPORT_HWIDTH
!fr9 = VIEWPORT_HHEIGHT
!fr10 = VIEWPORT_X_PLUS_HWIDTH
!fr11 = VIEWPORT_Y_PLUS_HHEIGHT
!fv4 = XYZW
.globl _DrawColouredQuads
#include "ViewportTransform.S"
.global _DrawColouredQuads
.align 4
.type _DrawColouredQuads,%function
! See https://shared-ptr.com/sh_insns.html
! Although there is fmov.s @Rm+,FRn, there isn't fmov.s FRn,@Rm+
! So have to use fmov.s FRn,@-Rm instead
_DrawColouredQuads:
! Setup
mov.l CMD_COL_VERT, r1 ! r1 = GPU VERT command
mov.l CMD_COL_EOS, r2 ! r2 = GPU EOS command
fldi0 fr9 ! fr9 = 0
mov r4,r0 ! r0 = src
add #-32, r5 ! r5 -= sizeof(VERTEX)
nop ! align loop
fldi0 fr1 ! U = 0
fldi0 fr2 ! V = 0
mov r4,r3 ! r3 = src
add #-32, r5 ! r5 -= sizeof(VERTEX)
ViewportTransformSetup _VP_COL_HWIDTH
.TRANSFORM_QUAD:
! TRANSFORM VERTEX 1
add #16, r0 ! r0 += VERTEX_STRIDE
add #64, r5 ! r5 += 2 * sizeof(VERTEX)
pref @r0 ! PREFETCH r0 (next vertex)
fmov @r4+, fr4 ! fr4 = src->x
fmov @r4+, fr5 ! fr5 = src->y
fmov @r4+, fr6 ! fr6 = src->z
fldi1 fr7 ! fr7 = 1.0
ftrv xmtrx, fv4 ! TRANSFORM(fr4..fr7)
mov.l CMD_COL_VERT, r1 ! r1 = GPU VERT command
mov.l @r4+,r3 ! r3 = src->color
fmov.s fr7,@-r5 ! dst->w = fr7
mov.l r3,@-r5 ! dst->bgra = r3
fmov.s fr9,@-r5 ! dst->v = 0.0
fmov.s fr9,@-r5 ! dst->u = 0.0
fmov.s fr6,@-r5 ! dst->z = fr6
fmov.s fr5,@-r5 ! dst->y = fr5
fmov.s fr4,@-r5 ! dst->x = fr4
mov.l r1,@-r5 ! dst->flags = CMD_VERT
LoadColouredVertex
ProcessVertex1
! TRANSFORM VERTEX 2
add #16, r0 ! r0 += VERTEX_STRIDE
add #64, r5 ! r5 += 2 * sizeof(VERTEX)
pref @r0 ! PREFETCH r0 (next vertex)
fmov @r4+, fr4 ! fr4 = src->x
fmov @r4+, fr5 ! fr5 = src->y
fmov @r4+, fr6 ! fr6 = src->z
fldi1 fr7 ! fr7 = 1.0
ftrv xmtrx, fv4 ! TRANSFORM(fr4..fr7)
LoadColouredVertex
ProcessVertex2
mov.l @r4+,r3 ! r3 = src->color
fmov.s fr7,@-r5 ! dst->w = fr7
mov.l r3,@-r5 ! dst->bgra = r3
fmov.s fr9,@-r5 ! dst->v = 0.0
fmov.s fr9,@-r5 ! dst->u = 0.0
fmov.s fr6,@-r5 ! dst->z = fr6
fmov.s fr5,@-r5 ! dst->y = fr5
fmov.s fr4,@-r5 ! dst->x = fr4
mov.l r1,@-r5 ! dst->flags = CMD_VERT
LoadColouredVertex
ProcessVertex3
! TRANSFORM VERTEX 3
add #16, r0 ! r0 += VERTEX_STRIDE
add #64, r5 ! r5 += 2 * sizeof(VERTEX)
pref @r0 ! PREFETCH r0 (next vertex)
fmov @r4+, fr4 ! fr4 = src->x
fmov @r4+, fr5 ! fr5 = src->y
fmov @r4+, fr6 ! fr6 = src->z
fldi1 fr7 ! fr7 = 1.0
ftrv xmtrx, fv4 ! TRANSFORM(fr4..fr7)
LoadColouredVertex
ProcessVertex4 CMD_COL_EOS
mov.l @r4+,r3 ! r3 = src->color
fmov.s fr7,@-r5 ! dst->w = fr7
mov.l r3,@-r5 ! dst->bgra = r3
fmov.s fr9,@-r5 ! dst->v = 0.0
fmov.s fr9,@-r5 ! dst->u = 0.0
fmov.s fr6,@-r5 ! dst->z = fr6
fmov.s fr5,@-r5 ! dst->y = fr5
fmov.s fr4,@-r5 ! dst->x = fr4
mov.l r1,@-r5 ! dst->flags = CMD_VERT
! CLIPFLAGS TESTING
cmp/eq #0,r0 ! T = r0 == 0 (all points invisible)
bt/s .NO_POINTS_VISIBLE ! if T goto NO_POINTS_VISIBLE
nop
bra .SOME_POINTS_VISIBLE
nop
! TRANSFORM VERTEX 4
add #16, r0 ! r0 += VERTEX_STRIDE
add #64, r5 ! r5 += 2 * sizeof(VERTEX)
pref @r0 ! PREFETCH r0 (next vertex)
fmov @r4+, fr4 ! fr4 = src->x
fmov @r4+, fr5 ! fr5 = src->y
fmov @r4+, fr6 ! fr6 = src->z
fldi1 fr7 ! fr7 = 1.0
ftrv xmtrx, fv4 ! TRANSFORM(fr4..fr7)
.NO_POINTS_VISIBLE:
bra .LOOP_END ! jump to loop end after executing instruction in delay slot
add #-128, r5 ! r5 -= 4 * sizeof(VERTEX), move back to 1 vertex before start of quad
mov.l @r4+,r3 ! r3 = src->color
fmov.s fr7,@-r5 ! dst->w = fr7
mov.l r3,@-r5 ! dst->bgra = r3
fmov.s fr9,@-r5 ! dst->v = 0.0
fmov.s fr9,@-r5 ! dst->u = 0.0
fmov.s fr6,@-r5 ! dst->z = fr6
fmov.s fr5,@-r5 ! dst->y = fr5
fmov.s fr4,@-r5 ! dst->x = fr4
mov.l r2,@-r5 ! dst->flags = CMD_EOS
.SOME_POINTS_VISIBLE:
dt r6 ! r6--; T = 1 if r6 == 0, else 0
bf .TRANSFORM_QUAD ! if T == 0 then goto TRANSFORM_QUAD
.LOOP_END:
dt r6 ! r6--; T = r6 == 0
bf .TRANSFORM_QUAD ! if !T then goto TRANSFORM_QUAD
nop
rts ! return
nop
add #32, r5 ! r5 += sizeof(VERTEX)
rts ! return after executing instruction in delay slot
mov r5,r0 ! r0 = r5
.align 2
CMD_COL_VERT: .long 0xe0000000
CMD_COL_EOS: .long 0xf0000000
.global _VP_COL_HWIDTH
.type _VP_COL_HWIDTH,%object
_VP_COL_HWIDTH: .long 0
.global _VP_COL_HHEIGHT
.type _VP_COL_HHEIGHT,%object
_VP_COL_HHEIGHT: .long 0
.global _VP_COL_X_PLUS_HWIDTH
.type _VP_COL_X_PLUS_HWIDTH,%object
_VP_COL_X_PLUS_HWIDTH: .long 0
.global _VP_COL_Y_PLUS_HHEIGHT
.type _VP_COL_Y_PLUS_HHEIGHT,%object
_VP_COL_Y_PLUS_HHEIGHT: .long 0

View File

@ -1,128 +1,91 @@
!r0 = prefetch address
!r1 = GPU VERT command
!r2 = GPU EOS command
!r3 = colour
!r0 = clip flags
!r1 = GPU command
!r2 = temp
!r3 = prefetch address
!r4 = src pointer ARG
!r5 = dst pointer ARG
!r6 = quads count ARG
!r7 = ?
!fr0 = temp
!fr1 = u
!fr2 = v
!fr3 = c
!fr4 = x
!fr5 = y
!fr6 = z
!fr7 = w
!fr9 = ?
!fr10 = u
!fr11 = v
!fr8 = VIEWPORT_HWIDTH
!fr9 = VIEWPORT_HHEIGHT
!fr10 = VIEWPORT_X_PLUS_HWIDTH
!fr11 = VIEWPORT_Y_PLUS_HHEIGHT
!fv4 = XYZW
.globl _DrawTexturedQuads
#include "ViewportTransform.S"
.global _DrawTexturedQuads
.align 4
.type _DrawTexturedQuads,%function
_DrawTexturedQuads:
! Setup
mov.l CMD_TEX_VERT, r1 ! r1 = GPU VERT command
mov.l CMD_TEX_EOS, r2 ! r2 = GPU EOS command
mov r4,r0 ! r0 = src
add #-32, r5 ! r5 -= sizeof(VERTEX)
mov r4,r3 ! r3 = src
add #-32, r5 ! r5 -= sizeof(VERTEX)
ViewportTransformSetup _VP_TEX_HWIDTH
.TRANSFORM_QUAD:
! TRANSFORM VERTEX 1
add #24, r0 ! r0 += VERTEX_STRIDE
add #64, r5 ! r5 += 2 * sizeof(VERTEX)
pref @r0 ! PREFETCH r0 (next vertex)
fmov @r4+, fr4 ! fr4 = src->x
fmov @r4+, fr5 ! fr5 = src->y
fmov @r4+, fr6 ! fr6 = src->z
fldi1 fr7 ! fr7 = 1.0
ftrv xmtrx, fv4 ! TRANSFORM(fr4..fr7)
mov.l CMD_TEX_VERT, r1 ! r1 = GPU VERT command
mov.l @r4+,r3 ! r3 = src->color
fmov @r4+,fr10! fr10 = src->u
fmov @r4+,fr11! fr11 = src->v
fmov.s fr7,@-r5 ! dst->w = fr7
mov.l r3,@-r5 ! dst->bgra = r3
fmov.s fr11,@-r5 ! dst->v = fr11
fmov.s fr10,@-r5 ! dst->u = fr10
fmov.s fr6,@-r5 ! dst->z = fr6
fmov.s fr5,@-r5 ! dst->y = fr5
fmov.s fr4,@-r5 ! dst->x = fr4
mov.l r1,@-r5 ! dst->flags = CMD_VERT
LoadTexturedVertex
ProcessVertex1
! TRANSFORM VERTEX 2
add #24, r0 ! r0 += VERTEX_STRIDE
add #64, r5 ! r5 += 2 * sizeof(VERTEX)
pref @r0 ! PREFETCH r0 (next vertex)
fmov @r4+, fr4 ! fr4 = src->x
fmov @r4+, fr5 ! fr5 = src->y
fmov @r4+, fr6 ! fr6 = src->z
fldi1 fr7 ! fr7 = 1.0
ftrv xmtrx, fv4 ! TRANSFORM(fr4..fr7)
LoadTexturedVertex
ProcessVertex2
mov.l @r4+,r3 ! r3 = src->color
fmov @r4+,fr10! fr10 = src->u
fmov @r4+,fr11! fr11 = src->v
fmov.s fr7,@-r5 ! dst->w = fr7
mov.l r3,@-r5 ! dst->bgra = r3
fmov.s fr11,@-r5 ! dst->v = fr11
fmov.s fr10,@-r5 ! dst->u = fr10
fmov.s fr6,@-r5 ! dst->z = fr6
fmov.s fr5,@-r5 ! dst->y = fr5
fmov.s fr4,@-r5 ! dst->x = fr4
mov.l r1,@-r5 ! dst->flags = CMD_VERT
LoadTexturedVertex
ProcessVertex3
! TRANSFORM VERTEX 3
add #24, r0 ! r0 += VERTEX_STRIDE
add #64, r5 ! r5 += 2 * sizeof(VERTEX)
pref @r0 ! PREFETCH r0 (next vertex)
fmov @r4+, fr4 ! fr4 = src->x
fmov @r4+, fr5 ! fr5 = src->y
fmov @r4+, fr6 ! fr6 = src->z
fldi1 fr7 ! fr7 = 1.0
ftrv xmtrx, fv4 ! TRANSFORM(fr4..fr7)
LoadTexturedVertex
ProcessVertex4 CMD_TEX_EOS
mov.l @r4+,r3 ! r3 = src->color
fmov @r4+,fr10! fr10 = src->u
fmov @r4+,fr11! fr11 = src->v
fmov.s fr7,@-r5 ! dst->w = fr7
mov.l r3,@-r5 ! dst->bgra = r3
fmov.s fr11,@-r5 ! dst->v = fr11
fmov.s fr10,@-r5 ! dst->u = fr10
fmov.s fr6,@-r5 ! dst->z = fr6
fmov.s fr5,@-r5 ! dst->y = fr5
fmov.s fr4,@-r5 ! dst->x = fr4
mov.l r1,@-r5 ! dst->flags = CMD_VERT
! CLIPFLAGS TESTING
cmp/eq #0,r0 ! T = r0 == 0 (all points invisible)
bt/s .NO_POINTS_VISIBLE ! if T goto NO_POINTS_VISIBLE
nop
bra .SOME_POINTS_VISIBLE
nop
! TRANSFORM VERTEX 4
add #24, r0 ! r0 += VERTEX_STRIDE
add #64, r5 ! r5 += 2 * sizeof(VERTEX)
pref @r0 ! PREFETCH r0 (next vertex)
fmov @r4+, fr4 ! fr4 = src->x
fmov @r4+, fr5 ! fr5 = src->y
fmov @r4+, fr6 ! fr6 = src->z
fldi1 fr7 ! fr7 = 1.0
ftrv xmtrx, fv4 ! TRANSFORM(fr4..fr7)
.NO_POINTS_VISIBLE:
bra .LOOP_END ! jump to loop end after executing instruction in delay slot
add #-128, r5 ! r5 -= 4 * sizeof(VERTEX), move back to prior quad, so that this invisible quad gets overwritten in next iteration
mov.l @r4+,r3 ! r3 = src->color
fmov @r4+,fr10! fr10 = src->u
fmov @r4+,fr11! fr11 = src->v
fmov.s fr7,@-r5 ! dst->w = fr7
mov.l r3,@-r5 ! dst->bgra = r3
fmov.s fr11,@-r5 ! dst->v = fr11
fmov.s fr10,@-r5 ! dst->u = fr10
fmov.s fr6,@-r5 ! dst->z = fr6
fmov.s fr5,@-r5 ! dst->y = fr5
fmov.s fr4,@-r5 ! dst->x = fr4
mov.l r2,@-r5 ! dst->flags = CMD_EOS
.SOME_POINTS_VISIBLE:
dt r6 ! r6--; T = 1 if r6 == 0, else 0
bf .TRANSFORM_QUAD ! if T == 0 then goto TRANSFORM_QUAD
.LOOP_END:
dt r6 ! r6--; T = r6 == 0
bf .TRANSFORM_QUAD ! if !T then goto TRANSFORM_QUAD
nop
rts ! return
nop
add #32, r5 ! r5 += sizeof(VERTEX)
rts ! return after executing instruction in delay slot
mov r5,r0 ! r0 = r5
.align 2
CMD_TEX_VERT: .long 0xe0000000
CMD_TEX_EOS: .long 0xf0000000
.global _VP_TEX_HWIDTH
.type _VP_TEX_HWIDTH,%object
_VP_TEX_HWIDTH: .long 0
.global _VP_TEX_HHEIGHT
.type _VP_TEX_HHEIGHT,%object
_VP_TEX_HHEIGHT: .long 0
.global _VP_TEX_X_PLUS_HWIDTH
.type _VP_TEX_X_PLUS_HWIDTH,%object
_VP_TEX_X_PLUS_HWIDTH: .long 0
.global _VP_TEX_Y_PLUS_HHEIGHT
.type _VP_TEX_Y_PLUS_HHEIGHT,%object
_VP_TEX_Y_PLUS_HHEIGHT: .long 0

View File

@ -11,7 +11,7 @@ LDFLAGS=-g
LIBS=-lm $(GLDC_LIB) -lppp -lkosfat
TARGET := ClassiCube-dc
CC_TEXTURES = classicube.zip
CC_TEXTURES = misc/dreamcast/classicube.zip
ifeq ($(strip $(KOS_BASE)),)
$(error "Please set KOS variables in your environment.")

View File

@ -1,49 +1,161 @@
! =========================================================
! ========================= VERTEX LOADING ================
! =========================================================
.macro LoadColouredVertex
! PREPARE NEXT VERTEX
add #16, r3 ! r3 += VERTEX_STRIDE
pref @r3 ! PREFETCH r3 (next vertex)
add #64, r5 ! r5 += 2 * sizeof(VERTEX)
! LOAD XYZ
fmov @r4+, fr4 ! X = src->x
fmov @r4+, fr5 ! Y = src->y
fmov @r4+, fr6 ! Z = src->z
fldi1 fr7 ! W = 1.0
! TRANSFORM VERTEX
ftrv xmtrx, fv4 ! TRANSFORM(XYZW)
! LOAD ATTRIBUTES
fmov @r4+,fr3 ! C = src->color
.endm
.macro LoadTexturedVertex
! PREPARE NEXT VERTEX
add #24, r3 ! r3 += VERTEX_STRIDE
pref @r3 ! PREFETCH r3 (next vertex)
add #64, r5 ! r5 += 2 * sizeof(VERTEX)
! LOAD XYZ
fmov @r4+, fr4 ! X = src->x
fmov @r4+, fr5 ! Y = src->y
fmov @r4+, fr6 ! Z = src->z
fldi1 fr7 ! W = 1.0
! TRANSFORM VERTEX
ftrv xmtrx, fv4 ! TRANSFORM(XYZW)
! LOAD ATTRIBUTES
fmov @r4+,fr3 ! C = src->color
fmov @r4+,fr1 ! U = src->u
fmov @r4+,fr2 ! V = src->v
.endm
! =========================================================
! ========================= VERTEX OUTPUT =================
! =========================================================
! To take advantage of SH4 dual instruction processing, interleave
! the clipflag calculation and vertex output instructions
.macro ProcessVertex1
fmov.s fr7,@-r5 ! dst->w = W
fmov.s fr3,@-r5 ! dst->c = C
fneg fr7 ! W = -W
fmov.s fr2,@-r5 ! dst->v = V
fcmp/gt fr7,fr6 ! T = Z > W (i.e. Z > -W)
fmov.s fr1,@-r5 ! dst->u = U
movt r0 ! CLIPFLAGS = T
fmov.s fr6,@-r5 ! dst->z = Z
fmov.s fr5,@-r5 ! dst->y = Y
fmov.s fr4,@-r5 ! dst->x = X
mov.l r1,@-r5 ! dst->flags = CMD_VERT
.endm
.macro ProcessVertex2
fmov.s fr7,@-r5 ! dst->w = W
fmov.s fr3,@-r5 ! dst->c = C
fneg fr7 ! W = -W
fmov.s fr2,@-r5 ! dst->v = V
fcmp/gt fr7,fr6 ! T = Z > W (i.e. Z > -W)
fmov.s fr1,@-r5 ! dst->u = U
movt r2 ! tmp = T
fmov.s fr6,@-r5 ! dst->z = Z
add r2,r2 ! tmp = tmp + tmp
fmov.s fr5,@-r5 ! dst->y = Y
or r2,r0 ! CLIPFLAGS |= tmp (T << 1)
fmov.s fr4,@-r5 ! dst->x = X
mov.l r1,@-r5 ! dst->flags = CMD_VERT
.endm
.macro ProcessVertex3
fmov.s fr7,@-r5 ! dst->w = W
fmov.s fr3,@-r5 ! dst->c = C
fneg fr7 ! W = -W
fmov.s fr2,@-r5 ! dst->v = V
fcmp/gt fr7,fr6 ! T = Z > W (i.e. Z > -W)
fmov.s fr1,@-r5 ! dst->u = U
movt r2 ! tmp = T
fmov.s fr6,@-r5 ! dst->z = Z
fmov.s fr5,@-r5 ! dst->y = Y
shll2 r2 ! tmp = tmp << 2
fmov.s fr4,@-r5 ! dst->x = X
or r2,r0 ! CLIPFLAGS |= tmp (T << 2)
mov.l r1,@-r5 ! dst->flags = CMD_VERT
.endm
.macro ProcessVertex4 eos_addr
fmov.s fr7,@-r5 ! dst->w = W
fmov.s fr3,@-r5 ! dst->c = C
fneg fr7 ! W = -W
fmov.s fr2,@-r5 ! dst->v = V
fcmp/gt fr7,fr6 ! T = Z > W (i.e. Z > -W)
fmov.s fr1,@-r5 ! dst->u = U
movt r2 ! tmp = T
fmov.s fr6,@-r5 ! dst->z = Z
shll2 r2 ! tmp = tmp << 2
fmov.s fr5,@-r5 ! dst->y = Y
add r2,r2 ! tmp = (tmp << 2) + (tmp << 2)
fmov.s fr4,@-r5 ! dst->x = X
mov.l \eos_addr, r1 ! r1 = GPU EOS command
or r2,r0 ! CLIPFLAGS |= tmp (T << 3)
or r0,r1 ! r1 |= CLIPFLAGS
mov.l r1,@-r5 ! dst->flags = GPU EOS | CLIPFLAGS
.endm
! =========================================================
! ====================== VIEWPORT TRANSFORM ===============
! =========================================================
!r2 = return addr
!r0 = temp
!r5 = dst pointer
!fr4 = VIEWPORT_HWIDTH
!fr5 = VIEWPORT_HHEIGHT
!fr6 = VIEWPORT_X_PLUS_HWIDTH
!fr7 = VIEWPORT_Y_PLUS_HHEIGHT
!fr8 = ???
!fr9 = temp
!fr10 = temp
!fr11 = saved fr0
!fr0 = temp
!fr4 = temp
!fr5 = temp
!fr5 = temp
!fr8 = VIEWPORT_HWIDTH
!fr9 = VIEWPORT_HHEIGHT
!fr10 = VIEWPORT_X_PLUS_HWIDTH
!fr11 = VIEWPORT_Y_PLUS_HHEIGHT
.macro ViewportTransformSetup viewport_addr
mova \viewport_addr, r0
fmov.s @r0+,fr4 ! fr4 = VIEWPORT_HWIDTH
fmov.s @r0+,fr5 ! fr5 = VIEWPORT_HHEIGHT
fmov.s @r0+,fr6 ! fr6 = VIEWPORT_X_PLUS_HWIDTH
fmov.s @r0+,fr7 ! fr7 = VIEWPORT_Y_PLUS_HHEIGHT
fmov.s @r0+,fr8 ! fr8 = VIEWPORT_HWIDTH
fmov.s @r0+,fr9 ! fr9 = VIEWPORT_HHEIGHT
fmov.s @r0+,fr10 ! fr10 = VIEWPORT_X_PLUS_HWIDTH
fmov.s @r0+,fr11 ! fr11 = VIEWPORT_Y_PLUS_HHEIGHT
nop ! align to even instructions
.endm
.macro ViewportTransformVertex
! INVERSE W CALCULATION
add #28, r5 ! r5 = &vertex[0].w
fmov.s @r5+,fr0 ! fr0 = vertex->w
add #28, r5 ! r5 = &vertex->w
fmov.s @r5,fr0 ! fr0 = vertex->w
fmul fr0,fr0 ! fr0 = fr0 * fr0
add #-32, r5 ! r5 -= sizeof(VERTEX)
add #-24, r5 ! r5 = &vertex->x
fsrra fr0 ! fr0 = 1 / sqrt(fr0) -> 1 / vertex->w
! TRANSFORM X
fmov.s @r5,fr10 ! fr10 = vertex->x
fmov fr6,fr9 ! fr9 = VIEWPORT_X_PLUS_HWIDTH
fmul fr4,fr10 ! fr10 = VIEWPORT_HWIDTH * vertex->x
fmac fr0,fr10,fr9 ! fr9 = fr0 * fr10 + fr9 -- (X * F * hwidth) + x_plus_hwidth
fmov.s fr9,@r5 ! vertex->x = fr9
add #4, r5 ! r5 += 4 (points to vertex->y)
fmov.s @r5,fr4 ! fr4 = vertex->x
fmov fr10,fr5 ! fr5 = VIEWPORT_X_PLUS_HWIDTH
fmul fr8,fr4 ! fr4 = VIEWPORT_HWIDTH * vertex->x
fmac fr0,fr4,fr5 ! fr5 = fr0 * fr4 + fr5 -- (X * F * hwidth) + x_plus_hwidth
fmov.s fr5,@r5 ! vertex->x = fr5
add #4, r5 ! r5 = &vertex->y
! TRANSFORM Y
fmov.s @r5,fr10 ! fr10 = vertex->y
fmov fr7,fr9 ! fr9 = VIEWPORT_Y_PLUS_HHEIGHT
fmul fr5,fr10 ! fr10 = VIEWPORT_HHEIGHT * vertex->y
fmac fr0,fr10,fr9 ! fr9 = fr0 * fr10 + fr9 -- (Y * F * hheight) + y_plus_hheight
fmov.s fr9,@r5 ! vertex->y = fr9
add #4, r5 ! r5 += 4 (points to vertex->z)
fmov.s @r5,fr4 ! fr4 = vertex->y
fmov fr11,fr5 ! fr5 = VIEWPORT_Y_PLUS_HHEIGHT
fmul fr9,fr4 ! fr4 = VIEWPORT_HHEIGHT * vertex->y
fmac fr0,fr4,fr5 ! fr5 = fr0 * fr4 + fr5 -- (Y * F * hheight) + y_plus_hheight
fmov.s fr5,@r5 ! vertex->y = fr5
add #4, r5 ! r5 = &vertex->z
! ASSIGN Z
fmov.s @r5,fr0 ! vertex->z = fr0
add #24, r5 ! r5 += 24 (points to next vertex)
fmov.s fr0,@r5 ! vertex->z = fr0
add #20, r5 ! r5 += 20 (points to start of next vertex)
.endm

View File

@ -31,6 +31,7 @@ static void InitGLState(void) {
void Gfx_Create(void) {
if (!Gfx.Created) glKosInit();
Gfx_SetViewport(0, 0, Game.Width, Game.Height);
InitGLState();
@ -467,19 +468,34 @@ cc_bool Gfx_WarnIfNecessary(void) {
*#########################################################################################################################*/
#define VB_PTR gfx_vertices
static const void* VERTEX_PTR;
extern void apply_poly_header(PolyHeader* header, PolyList* activePolyList);
extern void DrawColouredQuads(const void* src, Vertex* dst, int numQuads);
extern void DrawTexturedQuads(const void* src, Vertex* dst, int numQuads);
extern Vertex* DrawColouredQuads(const void* src, Vertex* dst, int numQuads);
extern Vertex* DrawTexturedQuads(const void* src, Vertex* dst, int numQuads);
void DrawQuads(int count) {
if (!count) return;
Vertex* start = submitVertices(count);
PolyList* output = _glActivePolyList();
AlignedVectorHeader* hdr = &output->vector.hdr;
uint32_t header_required = (hdr->size == 0) || STATE_DIRTY;
// Reserve room for the vertices and header
Vertex* beg = aligned_vector_reserve(&output->vector, hdr->size + (header_required) + count);
if (header_required) {
apply_poly_header((PolyHeader*)beg, output);
STATE_DIRTY = GL_FALSE;
beg++;
hdr->size += 1;
}
Vertex* end;
if (TEXTURES_ENABLED) {
DrawTexturedQuads(VERTEX_PTR, start, count >> 2);
end = DrawTexturedQuads(VERTEX_PTR, beg, count >> 2);
} else {
DrawColouredQuads(VERTEX_PTR, start, count >> 2);
end = DrawColouredQuads(VERTEX_PTR, beg, count >> 2);
}
hdr->size += (end - beg);
}
void Gfx_SetVertexFormat(VertexFormat fmt) {
@ -569,6 +585,11 @@ void Gfx_OnWindowResize(void) {
Gfx_SetViewport(0, 0, Game.Width, Game.Height);
}
extern float VP_COL_HWIDTH, VP_TEX_HWIDTH;
extern float VP_COL_HHEIGHT, VP_TEX_HHEIGHT;
extern float VP_COL_X_PLUS_HWIDTH, VP_TEX_X_PLUS_HWIDTH;
extern float VP_COL_Y_PLUS_HHEIGHT, VP_TEX_Y_PLUS_HHEIGHT;
void Gfx_SetViewport(int x, int y, int w, int h) {
if (x == 0 && y == 0 && w == Game.Width && h == Game.Height) {
glDisable(GL_SCISSOR_TEST);
@ -578,5 +599,11 @@ void Gfx_SetViewport(int x, int y, int w, int h) {
glViewport(x, y, w, h);
glScissor (x, y, w, h);
VP_COL_HWIDTH = VP_TEX_HWIDTH = w * 0.5f;
VP_COL_HHEIGHT = VP_TEX_HHEIGHT = h * -0.5f;
VP_COL_X_PLUS_HWIDTH = VP_TEX_X_PLUS_HWIDTH = x + w * 0.5f;
VP_COL_Y_PLUS_HHEIGHT = VP_TEX_Y_PLUS_HHEIGHT = y + h * 0.5f;
}
#endif

View File

@ -36,7 +36,6 @@ static RenderBuffer buffers[2];
static cc_uint8* next_packet;
static int active_buffer;
static RenderBuffer* buffer;
static cc_bool rendering2D;
static void* lastPoly;
static cc_bool cullingEnabled;
@ -672,7 +671,6 @@ static void DrawColouredQuads3D(int verticesCount, int startVertex) {
poly->b0 = PackedCol_B(v->Col);
//if (VERTEX_LOGGING) Platform_Log4("OUT: %i, %i, %i (%i)", &X, &Y, &Z, &p);
// TODO: 2D shouldn't use AddPrim, draws in the wrong way
addPrim(&buffer->ot[p >> 2], poly);
}
}
@ -805,9 +803,9 @@ static void DrawTexturedQuads3D(int verticesCount, int startVertex) {
}*/
static void DrawQuads(int verticesCount, int startVertex) {
if (rendering2D && gfx_format == VERTEX_FORMAT_TEXTURED) {
if (gfx_rendering2D && gfx_format == VERTEX_FORMAT_TEXTURED) {
DrawTexturedQuads2D(verticesCount, startVertex);
} else if (rendering2D) {
} else if (gfx_rendering2D) {
DrawColouredQuads2D(verticesCount, startVertex);
} else if (gfx_format == VERTEX_FORMAT_TEXTURED) {
DrawTexturedQuads3D(verticesCount, startVertex);
@ -869,12 +867,12 @@ void Gfx_GetApiInfo(cc_string* info) {
cc_bool Gfx_TryRestoreContext(void) { return true; }
void Gfx_Begin2D(int width, int height) {
rendering2D = true;
gfx_rendering2D = true;
Gfx_SetAlphaBlending(true);
}
void Gfx_End2D(void) {
rendering2D = false;
gfx_rendering2D = false;
Gfx_SetAlphaBlending(false);
}
#endif

View File

@ -1,446 +1,498 @@
#include "Core.h"
#if defined CC_BUILD_SATURN
#include "_GraphicsBase.h"
#include "Errors.h"
#include "Window.h"
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <yaul.h>
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 224
#define PRIMITIVE_DRAW_MODE_NORMAL (0)
#define PRIMITIVE_DRAW_MODE_MESH (1)
#define PRIMITIVE_DRAW_MODE_SHADOW (2)
#define PRIMITIVE_DRAW_MODE_HALF_LUMINANCE (3)
#define PRIMITIVE_DRAW_MODE_HALF_TRANSPARENT (4)
#define PRIMITIVE_DRAW_MODE_GOURAUD_SHADING (5)
#define PRIMITIVE_DRAW_MODE_GOURAUD_HALF_LUM (6)
#define PRIMITIVE_DRAW_MODE_GOURAUD_HALF_TRANS (7)
#define PRIMITIVE_DRAW_MODE_COUNT (8)
#define PRIMITIVE_COLOR RGB1555(1, 31, 0, 31)
#define CMDS_COUNT 400
static PackedCol clear_color;
static vdp1_cmdt_t cmdts_all[CMDS_COUNT];
static int cmdts_count;
static vdp1_vram_partitions_t _vdp1_vram_partitions;
static vdp1_cmdt_t* NextPrimitive(void) {
if (cmdts_count >= CMDS_COUNT) Logger_Abort("Too many VDP1 commands");
return &cmdts_all[cmdts_count++];
}
static vdp1_cmdt_draw_mode_t _primitive_draw_mode = {
.raw = 0x0000
};
static int16_vec2_t clear_points[4];
// TODO: how to use VDP1 erase ??
static void UpdateVDP1Env(void) {
vdp1_env_t env;
vdp1_env_default_init(&env);
int R = PackedCol_R(clear_color);
int G = PackedCol_G(clear_color);
int B = PackedCol_B(clear_color);
env.erase_color = RGB1555(1, R >> 3, G >> 3, B >> 3);
vdp1_env_set(&env);
}
// TODO: should be SCREEN_WIDTH/2 instead ?
static void _primitive_init(void) {
clear_points[0].x = 0;
clear_points[0].y = SCREEN_WIDTH - 1;
clear_points[1].x = SCREEN_WIDTH - 1;
clear_points[1].y = SCREEN_HEIGHT - 1;
clear_points[2].x = SCREEN_HEIGHT - 1;
clear_points[2].y = 0;
clear_points[3].x = 0;
clear_points[3].y = 0;
}
static GfxResourceID white_square;
void Gfx_RestoreState(void) {
InitDefaultResources();
// 2x2 dummy white texture
struct Bitmap bmp;
BitmapCol pixels[4] = { BitmapColor_RGB(255, 0, 0), BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE };
Bitmap_Init(bmp, 2, 2, pixels);
white_square = Gfx_CreateTexture(&bmp, 0, false);
}
void Gfx_FreeState(void) {
FreeDefaultResources();
Gfx_DeleteTexture(&white_square);
}
void Gfx_Create(void) {
if (!Gfx.Created) {
vdp1_vram_partitions_get(&_vdp1_vram_partitions);
// TODO less ram for gourad base
vdp2_scrn_back_color_set(VDP2_VRAM_ADDR(3, 0x01FFFE),
RGB1555(1, 0, 3, 15));
vdp2_sprite_priority_set(0, 6);
UpdateVDP1Env();
_primitive_init();
}
Gfx.MaxTexWidth = 128;
Gfx.MaxTexHeight = 128;
Gfx.Created = true;
}
void Gfx_Free(void) {
Gfx_FreeState();
}
/*########################################################################################################################*
*---------------------------------------------------------Textures--------------------------------------------------------*
*#########################################################################################################################*/
static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) {
return NULL;
}
void Gfx_BindTexture(GfxResourceID texId) {
}
void Gfx_DeleteTexture(GfxResourceID* texId) {
}
void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) {
// TODO
}
void Gfx_EnableMipmaps(void) { }
void Gfx_DisableMipmaps(void) { }
/*########################################################################################################################*
*------------------------------------------------------State management---------------------------------------------------*
*#########################################################################################################################*/
void Gfx_SetFog(cc_bool enabled) { }
void Gfx_SetFogCol(PackedCol col) { }
void Gfx_SetFogDensity(float value) { }
void Gfx_SetFogEnd(float value) { }
void Gfx_SetFogMode(FogFunc func) { }
void Gfx_SetFaceCulling(cc_bool enabled) {
// TODO
}
static void SetAlphaTest(cc_bool enabled) {
}
static void SetAlphaBlend(cc_bool enabled) {
}
void Gfx_SetAlphaArgBlend(cc_bool enabled) { }
void Gfx_ClearBuffers(GfxBuffers buffers) {
}
void Gfx_ClearColor(PackedCol color) {
if (color == clear_color) return;
clear_color = color;
UpdateVDP1Env();
}
void Gfx_SetDepthTest(cc_bool enabled) {
}
void Gfx_SetDepthWrite(cc_bool enabled) {
// TODO
}
static void SetColorWrite(cc_bool r, cc_bool g, cc_bool b, cc_bool a) {
// TODO
}
void Gfx_DepthOnlyRendering(cc_bool depthOnly) {
cc_bool enabled = !depthOnly;
SetColorWrite(enabled & gfx_colorMask[0], enabled & gfx_colorMask[1],
enabled & gfx_colorMask[2], enabled & gfx_colorMask[3]);
}
/*########################################################################################################################*
*-------------------------------------------------------Index buffers-----------------------------------------------------*
*#########################################################################################################################*/
GfxResourceID Gfx_CreateIb2(int count, Gfx_FillIBFunc fillFunc, void* obj) {
return (void*)1;
}
void Gfx_BindIb(GfxResourceID ib) { }
void Gfx_DeleteIb(GfxResourceID* ib) { }
/*########################################################################################################################*
*-------------------------------------------------------Vertex buffers----------------------------------------------------*
*#########################################################################################################################*/
static void* gfx_vertices;
static GfxResourceID Gfx_AllocStaticVb(VertexFormat fmt, int count) {
return Mem_TryAlloc(count, strideSizes[fmt]);
}
void Gfx_BindVb(GfxResourceID vb) { gfx_vertices = vb; }
void Gfx_DeleteVb(GfxResourceID* vb) {
GfxResourceID data = *vb;
if (data) Mem_Free(data);
*vb = 0;
}
void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count) {
return vb;
}
void Gfx_UnlockVb(GfxResourceID vb) {
gfx_vertices = vb;
}
static GfxResourceID Gfx_AllocDynamicVb(VertexFormat fmt, int maxVertices) {
return Mem_TryAlloc(maxVertices, strideSizes[fmt]);
}
void Gfx_BindDynamicVb(GfxResourceID vb) { Gfx_BindVb(vb); }
void* Gfx_LockDynamicVb(GfxResourceID vb, VertexFormat fmt, int count) {
return vb;
}
void Gfx_UnlockDynamicVb(GfxResourceID vb) {
gfx_vertices = vb;
}
void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); }
/*########################################################################################################################*
*---------------------------------------------------------Matrices--------------------------------------------------------*
*#########################################################################################################################*/
static struct Matrix _view, _proj, mvp;
void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {
if (type == MATRIX_VIEW) _view = *matrix;
if (type == MATRIX_PROJECTION) _proj = *matrix;
Matrix_Mul(&mvp, &_view, &_proj);
}
void Gfx_LoadIdentityMatrix(MatrixType type) {
Gfx_LoadMatrix(type, &Matrix_Identity);
}
void Gfx_EnableTextureOffset(float x, float y) {
// TODO
}
void Gfx_DisableTextureOffset(void) {
// TODO
}
void Gfx_CalcOrthoMatrix(struct Matrix* matrix, float width, float height, float zNear, float zFar) {
/* Source https://learn.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixorthooffcenterrh */
/* The simplified calculation below uses: L = 0, R = width, T = 0, B = height */
/* NOTE: This calculation is shared with Direct3D 11 backend */
*matrix = Matrix_Identity;
matrix->row1.x = 2.0f / width;
matrix->row2.y = -2.0f / height;
matrix->row3.z = 1.0f / (zNear - zFar);
matrix->row4.x = -1.0f;
matrix->row4.y = 1.0f;
matrix->row4.z = zNear / (zNear - zFar);
}
static float Cotangent(float x) { return Math_CosF(x) / Math_SinF(x); }
void Gfx_CalcPerspectiveMatrix(struct Matrix* matrix, float fov, float aspect, float zFar) {
float zNear = 0.01f;
/* Source https://learn.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixperspectivefovrh */
float c = Cotangent(0.5f * fov);
*matrix = Matrix_Identity;
matrix->row1.x = c / aspect;
matrix->row2.y = c;
matrix->row3.z = zFar / (zNear - zFar);
matrix->row3.w = -1.0f;
matrix->row4.z = (zNear * zFar) / (zNear - zFar);
matrix->row4.w = 0.0f;
}
/*########################################################################################################################*
*---------------------------------------------------------Rendering-------------------------------------------------------*
*#########################################################################################################################*/
void Gfx_SetVertexFormat(VertexFormat fmt) {
gfx_format = fmt;
gfx_stride = strideSizes[fmt];
}
void Gfx_DrawVb_Lines(int verticesCount) {
}
static void Transform(Vec3* result, struct VertexTextured* a, const struct Matrix* mat) {
/* a could be pointing to result - therefore can't directly assign X/Y/Z */
float x = a->x * mat->row1.x + a->y * mat->row2.x + a->z * mat->row3.x + mat->row4.x;
float y = a->x * mat->row1.y + a->y * mat->row2.y + a->z * mat->row3.y + mat->row4.y;
float z = a->x * mat->row1.z + a->y * mat->row2.z + a->z * mat->row3.z + mat->row4.z;
float w = a->x * mat->row1.w + a->y * mat->row2.w + a->z * mat->row3.w + mat->row4.w;
result->x = (x/w) * (320/2);
result->y = (y/w) * -(224/2);
result->z = (z/w) * 1024;
}
#define IsPointCulled(vec) vec.x < -10000 || vec.x > 10000 || vec.y < -10000 || vec.y > 10000 || vec.z < 0 || vec.z > 1024
static void DrawTexturedQuads(int verticesCount, int startVertex) {
for (int i = 0; i < verticesCount; i += 4)
{
struct VertexTextured* v = (struct VertexTextured*)gfx_vertices + startVertex + i;
Vec3 coords[4];
Transform(&coords[0], &v[0], &mvp);
Transform(&coords[1], &v[1], &mvp);
Transform(&coords[2], &v[2], &mvp);
Transform(&coords[3], &v[3], &mvp);
int16_vec2_t points[4];
points[0].x = coords[0].x; points[0].y = coords[0].y;
points[1].x = coords[1].x; points[1].y = coords[1].y;
points[2].x = coords[2].x; points[2].y = coords[2].y;
points[3].x = coords[3].x; points[3].y = coords[3].y;
if (IsPointCulled(coords[0])) continue;
if (IsPointCulled(coords[1])) continue;
if (IsPointCulled(coords[2])) continue;
if (IsPointCulled(coords[3])) continue;
int R = PackedCol_R(v->Col);
int G = PackedCol_G(v->Col);
int B = PackedCol_B(v->Col);
vdp1_cmdt_t* cmd;
cmd = NextPrimitive();
vdp1_cmdt_polygon_set(cmd);
vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3));
vdp1_cmdt_draw_mode_set(cmd, _primitive_draw_mode);
vdp1_cmdt_vtx_set(cmd, points);
}
}
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) {
if (gfx_format == VERTEX_FORMAT_TEXTURED) {
DrawTexturedQuads(verticesCount, startVertex);
}
}
void Gfx_DrawVb_IndexedTris(int verticesCount) {
if (gfx_format == VERTEX_FORMAT_TEXTURED) {
DrawTexturedQuads(verticesCount, 0);
}
}
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
DrawTexturedQuads(verticesCount, startVertex);
}
/*########################################################################################################################*
*---------------------------------------------------------Other/Misc------------------------------------------------------*
*#########################################################################################################################*/
cc_result Gfx_TakeScreenshot(struct Stream* output) {
return ERR_NOT_SUPPORTED;
}
cc_bool Gfx_WarnIfNecessary(void) {
return false;
}
void Gfx_BeginFrame(void) {
Platform_LogConst("FRAME BEG");
cmdts_count = 0;
static const int16_vec2_t system_clip_coord = { SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1 };
static const int16_vec2_t local_coord_center = { SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 };
vdp1_cmdt_t* cmd;
cmd = NextPrimitive();
vdp1_cmdt_system_clip_coord_set(cmd);
vdp1_cmdt_vtx_system_clip_coord_set(cmd, system_clip_coord);
cmd = NextPrimitive();
vdp1_cmdt_local_coord_set(cmd);
vdp1_cmdt_vtx_local_coord_set(cmd, local_coord_center);
int R = PackedCol_R(clear_color);
int G = PackedCol_G(clear_color);
int B = PackedCol_B(clear_color);
cmd = NextPrimitive();
vdp1_cmdt_polygon_set(cmd);
vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3)); // TODO VDP1 erase
vdp1_cmdt_draw_mode_set(cmd, _primitive_draw_mode);
vdp1_cmdt_vtx_set(cmd, clear_points);
}
void Gfx_EndFrame(void) {
Platform_LogConst("FRAME END");
vdp1_cmdt_t* cmd;
cmd = NextPrimitive();
vdp1_cmdt_end_set(cmd);
vdp1_cmdt_list_t cmdt_list;
cmdt_list.cmdts = cmdts_all;
cmdt_list.count = cmdts_count;
vdp1_sync_cmdt_list_put(&cmdt_list, 0);
vdp1_sync_render();
vdp1_sync();
vdp2_sync();
vdp2_sync_wait();
if (gfx_minFrameMs) LimitFPS();
}
void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
gfx_minFrameMs = minFrameMs;
gfx_vsync = vsync;
}
void Gfx_OnWindowResize(void) {
// TODO
}
void Gfx_SetViewport(int x, int y, int w, int h) { }
void Gfx_GetApiInfo(cc_string* info) {
String_AppendConst(info, "-- Using Saturn --\n");
PrintMaxTextureInfo(info);
}
cc_bool Gfx_TryRestoreContext(void) { return true; }
#endif
#include "Core.h"
#if defined CC_BUILD_SATURN
#include "_GraphicsBase.h"
#include "Errors.h"
#include "Window.h"
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <yaul.h>
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 224
#define PRIMITIVE_DRAW_MODE_NORMAL (0)
#define PRIMITIVE_DRAW_MODE_MESH (1)
#define PRIMITIVE_DRAW_MODE_SHADOW (2)
#define PRIMITIVE_DRAW_MODE_HALF_LUMINANCE (3)
#define PRIMITIVE_DRAW_MODE_HALF_TRANSPARENT (4)
#define PRIMITIVE_DRAW_MODE_GOURAUD_SHADING (5)
#define PRIMITIVE_DRAW_MODE_GOURAUD_HALF_LUM (6)
#define PRIMITIVE_DRAW_MODE_GOURAUD_HALF_TRANS (7)
#define PRIMITIVE_DRAW_MODE_COUNT (8)
#define PRIMITIVE_COLOR RGB1555(1, 31, 0, 31)
#define CMDS_COUNT 400
static PackedCol clear_color;
static vdp1_cmdt_t cmdts_all[CMDS_COUNT];
static int cmdts_count;
static vdp1_vram_partitions_t _vdp1_vram_partitions;
static vdp1_cmdt_t* NextPrimitive(void) {
if (cmdts_count >= CMDS_COUNT) Logger_Abort("Too many VDP1 commands");
return &cmdts_all[cmdts_count++];
}
static vdp1_cmdt_draw_mode_t _primitive_draw_mode = {
.raw = 0x0000
};
static int16_vec2_t clear_points[4];
// TODO: how to use VDP1 erase ??
static void UpdateVDP1Env(void) {
vdp1_env_t env;
vdp1_env_default_init(&env);
int R = PackedCol_R(clear_color);
int G = PackedCol_G(clear_color);
int B = PackedCol_B(clear_color);
env.erase_color = RGB1555(1, R >> 3, G >> 3, B >> 3);
vdp1_env_set(&env);
}
// TODO: should be SCREEN_WIDTH/2 instead ?
static void _primitive_init(void) {
clear_points[0].x = 0;
clear_points[0].y = SCREEN_WIDTH - 1;
clear_points[1].x = SCREEN_WIDTH - 1;
clear_points[1].y = SCREEN_HEIGHT - 1;
clear_points[2].x = SCREEN_HEIGHT - 1;
clear_points[2].y = 0;
clear_points[3].x = 0;
clear_points[3].y = 0;
}
static GfxResourceID white_square;
void Gfx_RestoreState(void) {
InitDefaultResources();
// 2x2 dummy white texture
struct Bitmap bmp;
BitmapCol pixels[4] = { BitmapColor_RGB(255, 0, 0), BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE };
Bitmap_Init(bmp, 2, 2, pixels);
white_square = Gfx_CreateTexture(&bmp, 0, false);
}
void Gfx_FreeState(void) {
FreeDefaultResources();
Gfx_DeleteTexture(&white_square);
}
void Gfx_Create(void) {
if (!Gfx.Created) {
vdp1_vram_partitions_get(&_vdp1_vram_partitions);
// TODO less ram for gourad base
vdp2_scrn_back_color_set(VDP2_VRAM_ADDR(3, 0x01FFFE),
RGB1555(1, 0, 3, 15));
vdp2_sprite_priority_set(0, 6);
UpdateVDP1Env();
_primitive_init();
}
Gfx.MinTexWidth = 8;
Gfx.MinTexHeight = 8;
Gfx.MaxTexWidth = 128;
Gfx.MaxTexHeight = 128;
Gfx.Created = true;
}
void Gfx_Free(void) {
Gfx_FreeState();
}
/*########################################################################################################################*
*---------------------------------------------------------Textures--------------------------------------------------------*
*#########################################################################################################################*/
#define BGRA8_to_SATURN(src) \
((src[2] & 0xF8) >> 3) | ((src[1] & 0xF8) << 2) | ((src[0] & 0xF8) << 7) | ((src[3] & 0x80) << 8)
static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) {
cc_uint16* tmp = Mem_TryAlloc(bmp->width * bmp->height, 2);
if (!tmp) return NULL;
for (int y = 0; y < bmp->height; y++)
{
cc_uint32* src = bmp->scan0 + y * rowWidth;
cc_uint16* dst = tmp + y * bmp->width;
for (int x = 0; x < bmp->width; x++)
{
cc_uint8* color = (cc_uint8*)&src[x];
dst[x] = BGRA8_to_SATURN(color);
}
}
scu_dma_transfer(0, _vdp1_vram_partitions.texture_base, tmp, bmp->width * bmp->height * 2);
scu_dma_transfer_wait(0);
Mem_Free(tmp);
return (void*)1;
}
void Gfx_BindTexture(GfxResourceID texId) {
}
void Gfx_DeleteTexture(GfxResourceID* texId) {
}
void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) {
// TODO
}
void Gfx_EnableMipmaps(void) { }
void Gfx_DisableMipmaps(void) { }
/*########################################################################################################################*
*------------------------------------------------------State management---------------------------------------------------*
*#########################################################################################################################*/
void Gfx_SetFog(cc_bool enabled) { }
void Gfx_SetFogCol(PackedCol col) { }
void Gfx_SetFogDensity(float value) { }
void Gfx_SetFogEnd(float value) { }
void Gfx_SetFogMode(FogFunc func) { }
void Gfx_SetFaceCulling(cc_bool enabled) {
// TODO
}
static void SetAlphaTest(cc_bool enabled) {
}
static void SetAlphaBlend(cc_bool enabled) {
}
void Gfx_SetAlphaArgBlend(cc_bool enabled) { }
void Gfx_ClearBuffers(GfxBuffers buffers) {
}
void Gfx_ClearColor(PackedCol color) {
if (color == clear_color) return;
clear_color = color;
UpdateVDP1Env();
}
void Gfx_SetDepthTest(cc_bool enabled) {
}
void Gfx_SetDepthWrite(cc_bool enabled) {
// TODO
}
static void SetColorWrite(cc_bool r, cc_bool g, cc_bool b, cc_bool a) {
// TODO
}
void Gfx_DepthOnlyRendering(cc_bool depthOnly) {
cc_bool enabled = !depthOnly;
SetColorWrite(enabled & gfx_colorMask[0], enabled & gfx_colorMask[1],
enabled & gfx_colorMask[2], enabled & gfx_colorMask[3]);
}
/*########################################################################################################################*
*-------------------------------------------------------Index buffers-----------------------------------------------------*
*#########################################################################################################################*/
GfxResourceID Gfx_CreateIb2(int count, Gfx_FillIBFunc fillFunc, void* obj) {
return (void*)1;
}
void Gfx_BindIb(GfxResourceID ib) { }
void Gfx_DeleteIb(GfxResourceID* ib) { }
/*########################################################################################################################*
*-------------------------------------------------------Vertex buffers----------------------------------------------------*
*#########################################################################################################################*/
static void* gfx_vertices;
static GfxResourceID Gfx_AllocStaticVb(VertexFormat fmt, int count) {
return Mem_TryAlloc(count, strideSizes[fmt]);
}
void Gfx_BindVb(GfxResourceID vb) { gfx_vertices = vb; }
void Gfx_DeleteVb(GfxResourceID* vb) {
GfxResourceID data = *vb;
if (data) Mem_Free(data);
*vb = 0;
}
void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count) {
return vb;
}
void Gfx_UnlockVb(GfxResourceID vb) {
gfx_vertices = vb;
}
static GfxResourceID Gfx_AllocDynamicVb(VertexFormat fmt, int maxVertices) {
return Mem_TryAlloc(maxVertices, strideSizes[fmt]);
}
void Gfx_BindDynamicVb(GfxResourceID vb) { Gfx_BindVb(vb); }
void* Gfx_LockDynamicVb(GfxResourceID vb, VertexFormat fmt, int count) {
return vb;
}
void Gfx_UnlockDynamicVb(GfxResourceID vb) {
gfx_vertices = vb;
}
void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); }
/*########################################################################################################################*
*---------------------------------------------------------Matrices--------------------------------------------------------*
*#########################################################################################################################*/
static struct Matrix _view, _proj, mvp;
void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {
if (type == MATRIX_VIEW) _view = *matrix;
if (type == MATRIX_PROJECTION) _proj = *matrix;
Matrix_Mul(&mvp, &_view, &_proj);
}
void Gfx_LoadIdentityMatrix(MatrixType type) {
Gfx_LoadMatrix(type, &Matrix_Identity);
}
void Gfx_EnableTextureOffset(float x, float y) {
// TODO
}
void Gfx_DisableTextureOffset(void) {
// TODO
}
void Gfx_CalcOrthoMatrix(struct Matrix* matrix, float width, float height, float zNear, float zFar) {
/* Source https://learn.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixorthooffcenterrh */
/* The simplified calculation below uses: L = 0, R = width, T = 0, B = height */
/* NOTE: This calculation is shared with Direct3D 11 backend */
*matrix = Matrix_Identity;
matrix->row1.x = 2.0f / width;
matrix->row2.y = -2.0f / height;
matrix->row3.z = 1.0f / (zNear - zFar);
matrix->row4.x = -1.0f;
matrix->row4.y = 1.0f;
matrix->row4.z = zNear / (zNear - zFar);
}
static float Cotangent(float x) { return Math_CosF(x) / Math_SinF(x); }
void Gfx_CalcPerspectiveMatrix(struct Matrix* matrix, float fov, float aspect, float zFar) {
float zNear = 0.01f;
/* Source https://learn.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixperspectivefovrh */
float c = Cotangent(0.5f * fov);
*matrix = Matrix_Identity;
matrix->row1.x = c / aspect;
matrix->row2.y = c;
matrix->row3.z = zFar / (zNear - zFar);
matrix->row3.w = -1.0f;
matrix->row4.z = (zNear * zFar) / (zNear - zFar);
matrix->row4.w = 0.0f;
}
/*########################################################################################################################*
*---------------------------------------------------------Rendering-------------------------------------------------------*
*#########################################################################################################################*/
void Gfx_SetVertexFormat(VertexFormat fmt) {
gfx_format = fmt;
gfx_stride = strideSizes[fmt];
}
void Gfx_DrawVb_Lines(int verticesCount) {
}
static void Transform(Vec3* result, struct VertexTextured* a, const struct Matrix* mat) {
/* a could be pointing to result - therefore can't directly assign X/Y/Z */
float x = a->x * mat->row1.x + a->y * mat->row2.x + a->z * mat->row3.x + mat->row4.x;
float y = a->x * mat->row1.y + a->y * mat->row2.y + a->z * mat->row3.y + mat->row4.y;
float z = a->x * mat->row1.z + a->y * mat->row2.z + a->z * mat->row3.z + mat->row4.z;
float w = a->x * mat->row1.w + a->y * mat->row2.w + a->z * mat->row3.w + mat->row4.w;
result->x = (x/w) * (SCREEN_WIDTH / 2);
result->y = (y/w) * -(SCREEN_HEIGHT / 2);
result->z = (z/w) * 1024;
}
#define IsPointCulled(vec) vec.x < -10000 || vec.x > 10000 || vec.y < -10000 || vec.y > 10000 || vec.z < 0 || vec.z > 1024
static void DrawTexturedQuads2D(int verticesCount, int startVertex) {
for (int i = 0; i < verticesCount; i += 4)
{
struct VertexTextured* v = (struct VertexTextured*)gfx_vertices + startVertex + i;
int16_vec2_t points[4];
points[0].x = (int)v[0].x - SCREEN_WIDTH / 2; points[0].y = (int)v[0].y - SCREEN_HEIGHT / 2;
points[1].x = (int)v[1].x - SCREEN_WIDTH / 2; points[1].y = (int)v[1].y - SCREEN_HEIGHT / 2;
points[2].x = (int)v[2].x - SCREEN_WIDTH / 2; points[2].y = (int)v[2].y - SCREEN_HEIGHT / 2;
points[3].x = (int)v[3].x - SCREEN_WIDTH / 2; points[3].y = (int)v[3].y - SCREEN_HEIGHT / 2;
int R = PackedCol_R(v->Col);
int G = PackedCol_G(v->Col);
int B = PackedCol_B(v->Col);
vdp1_cmdt_t* cmd;
cmd = NextPrimitive();
vdp1_cmdt_polygon_set(cmd);
vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3));
vdp1_cmdt_draw_mode_set(cmd, _primitive_draw_mode);
vdp1_cmdt_vtx_set(cmd, points);
}
}
static void DrawTexturedQuads3D(int verticesCount, int startVertex) {
for (int i = 0; i < verticesCount; i += 4)
{
struct VertexTextured* v = (struct VertexTextured*)gfx_vertices + startVertex + i;
Vec3 coords[4];
Transform(&coords[0], &v[0], &mvp);
Transform(&coords[1], &v[1], &mvp);
Transform(&coords[2], &v[2], &mvp);
Transform(&coords[3], &v[3], &mvp);
int16_vec2_t points[4];
points[0].x = coords[0].x; points[0].y = coords[0].y;
points[1].x = coords[1].x; points[1].y = coords[1].y;
points[2].x = coords[2].x; points[2].y = coords[2].y;
points[3].x = coords[3].x; points[3].y = coords[3].y;
if (IsPointCulled(coords[0])) continue;
if (IsPointCulled(coords[1])) continue;
if (IsPointCulled(coords[2])) continue;
if (IsPointCulled(coords[3])) continue;
int R = PackedCol_R(v->Col);
int G = PackedCol_G(v->Col);
int B = PackedCol_B(v->Col);
vdp1_cmdt_t* cmd;
cmd = NextPrimitive();
vdp1_cmdt_polygon_set(cmd);
vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3));
vdp1_cmdt_draw_mode_set(cmd, _primitive_draw_mode);
vdp1_cmdt_vtx_set(cmd, points);
}
}
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) {
if (gfx_rendering2D && gfx_format == VERTEX_FORMAT_TEXTURED) {
DrawTexturedQuads2D(verticesCount, startVertex);
} else if (gfx_format == VERTEX_FORMAT_TEXTURED) {
DrawTexturedQuads3D(verticesCount, startVertex);
}
}
void Gfx_DrawVb_IndexedTris(int verticesCount) {
if (gfx_rendering2D && gfx_format == VERTEX_FORMAT_TEXTURED) {
DrawTexturedQuads2D(verticesCount, 0);
} else if (gfx_format == VERTEX_FORMAT_TEXTURED) {
DrawTexturedQuads3D(verticesCount, 0);
}
}
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
DrawTexturedQuads3D(verticesCount, startVertex);
}
/*########################################################################################################################*
*---------------------------------------------------------Other/Misc------------------------------------------------------*
*#########################################################################################################################*/
cc_result Gfx_TakeScreenshot(struct Stream* output) {
return ERR_NOT_SUPPORTED;
}
cc_bool Gfx_WarnIfNecessary(void) {
return false;
}
void Gfx_BeginFrame(void) {
Platform_LogConst("FRAME BEG");
cmdts_count = 0;
static const int16_vec2_t system_clip_coord = { SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1 };
static const int16_vec2_t local_coord_center = { SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 };
vdp1_cmdt_t* cmd;
cmd = NextPrimitive();
vdp1_cmdt_system_clip_coord_set(cmd);
vdp1_cmdt_vtx_system_clip_coord_set(cmd, system_clip_coord);
cmd = NextPrimitive();
vdp1_cmdt_local_coord_set(cmd);
vdp1_cmdt_vtx_local_coord_set(cmd, local_coord_center);
int R = PackedCol_R(clear_color);
int G = PackedCol_G(clear_color);
int B = PackedCol_B(clear_color);
cmd = NextPrimitive();
vdp1_cmdt_polygon_set(cmd);
vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3)); // TODO VDP1 erase
vdp1_cmdt_draw_mode_set(cmd, _primitive_draw_mode);
vdp1_cmdt_vtx_set(cmd, clear_points);
}
void Gfx_EndFrame(void) {
Platform_LogConst("FRAME END");
vdp1_cmdt_t* cmd;
cmd = NextPrimitive();
vdp1_cmdt_end_set(cmd);
vdp1_cmdt_list_t cmdt_list;
cmdt_list.cmdts = cmdts_all;
cmdt_list.count = cmdts_count;
vdp1_sync_cmdt_list_put(&cmdt_list, 0);
vdp1_sync_render();
vdp1_sync();
vdp2_sync();
vdp2_sync_wait();
if (gfx_minFrameMs) LimitFPS();
}
void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
gfx_minFrameMs = minFrameMs;
gfx_vsync = vsync;
}
void Gfx_OnWindowResize(void) {
// TODO
}
void Gfx_SetViewport(int x, int y, int w, int h) { }
void Gfx_GetApiInfo(cc_string* info) {
String_AppendConst(info, "-- Using Saturn --\n");
PrintMaxTextureInfo(info);
}
cc_bool Gfx_TryRestoreContext(void) { return true; }
#endif

View File

@ -215,8 +215,13 @@ static const char* const storageNames[INPUT_COUNT] = {
"Keypad0", "Keypad1", "Keypad2", "Keypad3", "Keypad4",
"Keypad5", "Keypad6", "Keypad7", "Keypad8", "Keypad9",
"KeypadDivide", "KeypadMultiply", "KeypadSubtract",
"KeypadAdd", "KeypadDecimal", "KeypadEnter",
"XButton1", "XButton2", "LeftMouse", "RightMouse", "MiddleMouse",
"KeypadAdd", "KeypadDecimal", "KeypadEnter",
"VolumeMute", "VolumeUp", "VolumeDown",
"MediaNext", "MediaPrev", "MediaPlay", "MediaStop",
"XButton1", "XButton2", "XButton3", "XButton4", "XButton5", "XButton6",
"LeftMouse", "RightMouse", "MiddleMouse",
Pad_Names
};
@ -239,7 +244,12 @@ const char* const Input_DisplayNames[INPUT_COUNT] = {
"NUMPAD5", "NUMPAD6", "NUMPAD7", "NUMPAD8", "NUMPAD9",
"DIVIDE", "MULTIPLY", "SUBTRACT",
"ADD", "DECIMAL", "NUMPADENTER",
"XBUTTON1", "XBUTTON2", "LMOUSE", "RMOUSE", "MMOUSE",
"VOLUMEMUTE", "VOLUMEUP", "VOLUMEDOWN",
"MEDIANEXT", "MEDIAPREV", "MEDIAPLAY", "MEDIASTOP",
"XBUTTON1", "XBUTTON2", "XBUTTON3", "XBUTTON4", "XBUTTON5", "XBUTTON6",
"LMOUSE", "RMOUSE", "MMOUSE",
Pad_Names
};

View File

@ -41,9 +41,13 @@ enum InputButtons {
CCKEY_KP5, CCKEY_KP6, CCKEY_KP7, CCKEY_KP8, CCKEY_KP9,
CCKEY_KP_DIVIDE, CCKEY_KP_MULTIPLY, CCKEY_KP_MINUS,
CCKEY_KP_PLUS, CCKEY_KP_DECIMAL, CCKEY_KP_ENTER,
CCKEY_VOLUME_MUTE, CCKEY_VOLUME_UP, CCKEY_VOLUME_DOWN,
CCKEY_MEDIA_NEXT, CCKEY_MEDIA_PREV, CCKEY_MEDIA_PLAY, CCKEY_MEDIA_STOP,
/* NOTE: RMOUSE must be before MMOUSE for PlayerClick compatibility */
CCMOUSE_X1, CCMOUSE_X2, CCMOUSE_L, CCMOUSE_R, CCMOUSE_M,
CCMOUSE_X1, CCMOUSE_X2, CCMOUSE_X3, CCMOUSE_X4, CCMOUSE_X5, CCMOUSE_X6,
CCMOUSE_L, CCMOUSE_R, CCMOUSE_M,
CCPAD_A, CCPAD_B, CCPAD_X, CCPAD_Y, CCPAD_L, CCPAD_R, CCPAD_Z,
CCPAD_LEFT, CCPAD_RIGHT, CCPAD_UP, CCPAD_DOWN,

View File

@ -516,7 +516,7 @@ static void PauseScreen_CheckHacksAllowed(void* screen) {
struct PauseScreen* s = (struct PauseScreen*)screen;
if (Gui.ClassicMenu) return;
Widget_SetDisabled(&s->btns[4],
Widget_SetDisabled(&s->btns[1],
!Entities.CurPlayer->Hacks.CanAnyHacks); /* select texture pack */
s->dirty = true;
}
@ -543,11 +543,11 @@ static void PauseScreen_Init(void* screen) {
struct PauseScreen* s = (struct PauseScreen*)screen;
static const struct SimpleButtonDesc descs[] = {
{ -160, -50, "Options...", Menu_SwitchOptions },
{ -160, 0, "Change texture pack...", Menu_SwitchTexPacks },
{ -160, 50, "Hotkeys...", Menu_SwitchHotkeys },
{ 160, -50, "Generate new level...", Menu_SwitchGenLevel },
{ 160, 0, "Load level...", Menu_SwitchLoadLevel },
{ 160, 50, "Save level...", Menu_SwitchSaveLevel },
{ -160, 0, "Change texture pack...", Menu_SwitchTexPacks },
{ -160, 50, "Hotkeys...", Menu_SwitchHotkeys }
{ 160, 50, "Save level...", Menu_SwitchSaveLevel }
};
s->widgets = pause_widgets;
s->numWidgets = 0;
@ -561,8 +561,8 @@ static void PauseScreen_Init(void* screen) {
s->maxVertices = Screen_CalcDefaultMaxVertices(s);
if (Server.IsSinglePlayer) return;
s->btns[1].flags = WIDGET_FLAG_DISABLED;
s->btns[2].flags = WIDGET_FLAG_DISABLED;
s->btns[3].flags = WIDGET_FLAG_DISABLED;
s->btns[5].flags = WIDGET_FLAG_DISABLED;
}
static void PauseScreen_Free(void* screen) {

View File

@ -64,13 +64,17 @@ cc_uint64 Stopwatch_Measure(void) {
cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
if (end < beg) return 0;
return (end - beg); // TODO measure time
cc_uint32 delta = end - beg;
// TODO still wrong?? and overflows?? and PAL detection ???
return (delta * 1000) / CPU_FRT_NTSC_320_128_COUNT_1MS;
}
static void ovf_handler(void) { overflow_count++; }
static void Stopwatch_Init(void) {
cpu_frt_init(CPU_FRT_CLOCK_DIV_8);
//cpu_frt_init(CPU_FRT_CLOCK_DIV_8);
cpu_frt_init(CPU_FRT_CLOCK_DIV_128);
cpu_frt_ovi_set(ovf_handler);
cpu_frt_interrupt_priority_set(15);

View File

@ -189,6 +189,15 @@ static int MapNativeKey(SDL_Keycode k) {
case SDLK_RSHIFT: return CCKEY_RSHIFT;
case SDLK_RALT: return CCKEY_RALT;
case SDLK_RGUI: return CCKEY_RWIN;
case SDLK_AUDIONEXT: return CCKEY_MEDIA_NEXT;
case SDLK_AUDIOPREV: return CCKEY_MEDIA_PREV;
case SDLK_AUDIOPLAY: return CCKEY_MEDIA_PLAY;
case SDLK_AUDIOSTOP: return CCKEY_MEDIA_STOP;
case SDLK_AUDIOMUTE: return CCKEY_VOLUME_MUTE;
case SDLK_VOLUMEDOWN: return CCKEY_VOLUME_DOWN;
case SDLK_VOLUMEUP: return CCKEY_VOLUME_UP;
}
return INPUT_NONE;
}

View File

@ -176,6 +176,15 @@ static int MapNativeKey(SDL_Keycode k) {
case SDLK_RSHIFT: return CCKEY_RSHIFT;
case SDLK_RALT: return CCKEY_RALT;
case SDLK_RGUI: return CCKEY_RWIN;
case SDLK_AUDIONEXT: return CCKEY_MEDIA_NEXT;
case SDLK_AUDIOPREV: return CCKEY_MEDIA_PREV;
case SDLK_AUDIOPLAY: return CCKEY_MEDIA_PLAY;
case SDLK_AUDIOSTOP: return CCKEY_MEDIA_STOP;
case SDLK_AUDIOMUTE: return CCKEY_VOLUME_MUTE;
case SDLK_VOLUMEDOWN: return CCKEY_VOLUME_DOWN;
case SDLK_VOLUMEUP: return CCKEY_VOLUME_UP;
}
return INPUT_NONE;
}

View File

@ -20,7 +20,6 @@
#define SCREEN_HEIGHT 224
static cc_bool launcherMode;
static smpc_peripheral_digital_t state;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
@ -109,15 +108,58 @@ static void ProcessButtons(int port, int mods) {
Gamepad_SetButton(port, CCPAD_DOWN, mods & PERIPHERAL_DIGITAL_DOWN);
}
static smpc_peripheral_digital_t dig_state;
static smpc_peripheral_analog_t ana_state;
void Window_ProcessGamepads(float delta) {
smpc_peripheral_digital_port(1, &state);
ProcessButtons(0, state.pressed.raw | state.held.raw);
smpc_peripheral_digital_port(1, &dig_state);
ProcessButtons(0, dig_state.pressed.raw | dig_state.held.raw);
smpc_peripheral_analog_port(1, &ana_state);
}
/*########################################################################################################################*
*------------------------------------------------------Framebuffer--------------------------------------------------------*
*#########################################################################################################################*/
static const vdp2_vram_cycp_t vram_cycp = {
.pt[0].t0 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[0].t1 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[0].t2 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[0].t3 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[0].t4 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[0].t5 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[0].t6 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[0].t7 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t0 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t1 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t2 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t3 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t4 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t5 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t6 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t7 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t0 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t1 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t2 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t3 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t4 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t5 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t6 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t7 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t0 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t1 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t2 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t3 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t4 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t5 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t6 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t7 = VDP2_VRAM_CYCP_CHPNDR_NBG0
};
void Window_Create2D(int width, int height) {
launcherMode = true;
@ -132,46 +174,8 @@ void Window_Create2D(int width, int height) {
vdp2_scrn_bitmap_format_set(&format);
vdp2_scrn_priority_set(VDP2_SCRN_NBG0, 5);
vdp2_scrn_display_set(VDP2_SCRN_DISP_NBG0);
const vdp2_vram_cycp_t vram_cycp = {
.pt[0].t0 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[0].t1 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[0].t2 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[0].t3 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[0].t4 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[0].t5 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[0].t6 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[0].t7 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t0 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t1 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t2 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t3 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t4 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t5 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t6 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[1].t7 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t0 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t1 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t2 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t3 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t4 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t5 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t6 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[2].t7 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t0 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t1 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t2 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t3 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t4 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t5 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t6 = VDP2_VRAM_CYCP_CHPNDR_NBG0,
.pt[3].t7 = VDP2_VRAM_CYCP_CHPNDR_NBG0
};
vdp2_vram_cycp_set(&vram_cycp);
vdp2_vram_cycp_set(&vram_cycp);
}
void Window_AllocFramebuffer(struct Bitmap* bmp) {
@ -192,10 +196,10 @@ void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) {
{
// TODO optimise
BitmapCol col = row[x];
cc_uint8 r = BitmapCol_R(col);
cc_uint8 g = BitmapCol_G(col);
cc_uint8 b = BitmapCol_B(col);
vram[x + (y * 512)] = RGB1555(0, r >> 3, g >> 3, b >> 3);
cc_uint8 R = BitmapCol_R(col);
cc_uint8 G = BitmapCol_G(col);
cc_uint8 B = BitmapCol_B(col);
vram[x + (y * 512)] = RGB1555(0, R >> 3, G >> 3, B >> 3);
}
}

View File

@ -247,12 +247,26 @@ static int MapNativeKey(int k, int l) {
case DOM_VK_BACK_SLASH: return CCKEY_BACKSLASH;
case DOM_VK_CLOSE_BRACKET: return CCKEY_RBRACKET;
case DOM_VK_QUOTE: return CCKEY_QUOTE;
case DOM_VK_VOLUME_MUTE: return CCKEY_VOLUME_MUTE;
case DOM_VK_VOLUME_DOWN: return CCKEY_VOLUME_DOWN;
case DOM_VK_VOLUME_UP: return CCKEY_VOLUME_UP;
/* chrome */
/* Chrome specific keys */
/*case 173: return CCKEY_VOLUME_MUTE; same as DOM_VK_HYPHEN_MINUS */
case 174: return CCKEY_VOLUME_DOWN;
case 175: return CCKEY_VOLUME_UP;
case 176: return CCKEY_MEDIA_NEXT;
case 177: return CCKEY_MEDIA_PREV;
case 178: return CCKEY_MEDIA_STOP;
case 179: return CCKEY_MEDIA_PLAY;
case 186: return CCKEY_SEMICOLON;
case 187: return CCKEY_EQUALS;
case 189: return CCKEY_MINUS;
}
Platform_Log1("Unknown key: %i", &k);
return INPUT_NONE;
}

View File

@ -52,21 +52,21 @@ static int win_totalWidth, win_totalHeight; /* Size of window including titlebar
static cc_bool is_ansiWindow, grabCursor;
static int windowX, windowY;
static const cc_uint8 key_map[14 * 16] = {
0, 0, 0, 0, 0, 0, 0, 0, CCKEY_BACKSPACE, CCKEY_TAB, 0, 0, CCKEY_F5, CCKEY_ENTER, 0, 0,
0, 0, 0, CCKEY_PAUSE, CCKEY_CAPSLOCK, 0, 0, 0, 0, 0, 0, CCKEY_ESCAPE, 0, 0, 0, 0,
CCKEY_SPACE, CCKEY_PAGEUP, CCKEY_PAGEDOWN, CCKEY_END, CCKEY_HOME, CCKEY_LEFT, CCKEY_UP, CCKEY_RIGHT, CCKEY_DOWN, 0, CCKEY_PRINTSCREEN, 0, CCKEY_PRINTSCREEN, CCKEY_INSERT, CCKEY_DELETE, 0,
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 0, 0, 0, 0, 0, 0,
0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', CCKEY_LWIN, CCKEY_RWIN, CCKEY_MENU, 0, 0,
CCKEY_KP0, CCKEY_KP1, CCKEY_KP2, CCKEY_KP3, CCKEY_KP4, CCKEY_KP5, CCKEY_KP6, CCKEY_KP7, CCKEY_KP8, CCKEY_KP9, CCKEY_KP_MULTIPLY, CCKEY_KP_PLUS, 0, CCKEY_KP_MINUS, CCKEY_KP_DECIMAL, CCKEY_KP_DIVIDE,
CCKEY_F1, CCKEY_F2, CCKEY_F3, CCKEY_F4, CCKEY_F5, CCKEY_F6, CCKEY_F7, CCKEY_F8, CCKEY_F9, CCKEY_F10, CCKEY_F11, CCKEY_F12, CCKEY_F13, CCKEY_F14, CCKEY_F15, CCKEY_F16,
CCKEY_F17, CCKEY_F18, CCKEY_F19, CCKEY_F20, CCKEY_F21, CCKEY_F22, CCKEY_F23, CCKEY_F24, 0, 0, 0, 0, 0, 0, 0, 0,
CCKEY_NUMLOCK, CCKEY_SCROLLLOCK, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
CCKEY_LSHIFT, CCKEY_RSHIFT, CCKEY_LCTRL, CCKEY_RCTRL, CCKEY_LALT, CCKEY_RALT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CCKEY_SEMICOLON, CCKEY_EQUALS, CCKEY_COMMA, CCKEY_MINUS, CCKEY_PERIOD, CCKEY_SLASH,
CCKEY_TILDE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CCKEY_LBRACKET, CCKEY_BACKSLASH, CCKEY_RBRACKET, CCKEY_QUOTE, 0,
static const cc_uint8 key_map[] = {
/* 00 */ 0, 0, 0, 0, 0, 0, 0, 0, CCKEY_BACKSPACE, CCKEY_TAB, 0, 0, CCKEY_F5, CCKEY_ENTER, 0, 0,
/* 10 */ 0, 0, 0, CCKEY_PAUSE, CCKEY_CAPSLOCK, 0, 0, 0, 0, 0, 0, CCKEY_ESCAPE, 0, 0, 0, 0,
/* 20 */ CCKEY_SPACE, CCKEY_PAGEUP, CCKEY_PAGEDOWN, CCKEY_END, CCKEY_HOME, CCKEY_LEFT, CCKEY_UP, CCKEY_RIGHT, CCKEY_DOWN, 0, CCKEY_PRINTSCREEN, 0, CCKEY_PRINTSCREEN, CCKEY_INSERT, CCKEY_DELETE, 0,
/* 30 */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 0, 0, 0, 0, 0, 0,
/* 40 */ 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
/* 50 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', CCKEY_LWIN, CCKEY_RWIN, CCKEY_MENU, 0, 0,
/* 60 */ CCKEY_KP0, CCKEY_KP1, CCKEY_KP2, CCKEY_KP3, CCKEY_KP4, CCKEY_KP5, CCKEY_KP6, CCKEY_KP7, CCKEY_KP8, CCKEY_KP9, CCKEY_KP_MULTIPLY, CCKEY_KP_PLUS, 0, CCKEY_KP_MINUS, CCKEY_KP_DECIMAL, CCKEY_KP_DIVIDE,
/* 70 */ CCKEY_F1, CCKEY_F2, CCKEY_F3, CCKEY_F4, CCKEY_F5, CCKEY_F6, CCKEY_F7, CCKEY_F8, CCKEY_F9, CCKEY_F10, CCKEY_F11, CCKEY_F12, CCKEY_F13, CCKEY_F14, CCKEY_F15, CCKEY_F16,
/* 80 */ CCKEY_F17, CCKEY_F18, CCKEY_F19, CCKEY_F20, CCKEY_F21, CCKEY_F22, CCKEY_F23, CCKEY_F24, 0, 0, 0, 0, 0, 0, 0, 0,
/* 90 */ CCKEY_NUMLOCK, CCKEY_SCROLLLOCK, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* A0 */ CCKEY_LSHIFT, CCKEY_RSHIFT, CCKEY_LCTRL, CCKEY_RCTRL, CCKEY_LALT, CCKEY_RALT, 0, 0, 0, 0, 0, 0, 0, CCKEY_VOLUME_MUTE, CCKEY_VOLUME_DOWN, CCKEY_VOLUME_UP,
/* B0 */ CCKEY_MEDIA_NEXT, CCKEY_MEDIA_PREV, CCKEY_MEDIA_STOP, CCKEY_MEDIA_PLAY, 0, 0, 0, 0, 0, 0, CCKEY_SEMICOLON, CCKEY_EQUALS, CCKEY_COMMA, CCKEY_MINUS, CCKEY_PERIOD, CCKEY_SLASH,
/* C0 */ CCKEY_TILDE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* D0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CCKEY_LBRACKET, CCKEY_BACKSLASH, CCKEY_RBRACKET, CCKEY_QUOTE, 0,
};
static int MapNativeKey(WPARAM key, LPARAM meta) {
LPARAM ext = meta & (1UL << 24);

View File

@ -474,8 +474,17 @@ static int MapNativeMouse(int button) {
if (button == 1) return CCMOUSE_L;
if (button == 2) return CCMOUSE_M;
if (button == 3) return CCMOUSE_R;
if (button == 8) return CCMOUSE_X1;
if (button == 9) return CCMOUSE_X2;
if (button == 8) return CCMOUSE_X1;
if (button == 9) return CCMOUSE_X2;
if (button == 10) return CCMOUSE_X3;
if (button == 11) return CCMOUSE_X4;
if (button == 12) return CCMOUSE_X5;
if (button == 13) return CCMOUSE_X6;
/* Mouse horizontal and vertical scroll */
if (button >= 4 && button <= 7) return 0;
Platform_Log1("Unknown mouse button: %i", &button);
return 0;
}

View File

@ -24,6 +24,7 @@ static int gfx_stride, gfx_format = -1;
static cc_bool gfx_vsync, gfx_fogEnabled;
static float gfx_minFrameMs;
static cc_bool gfx_rendering2D;
/*########################################################################################################################*
@ -284,14 +285,18 @@ void Gfx_Begin2D(int width, int height) {
Gfx_SetDepthTest(false);
Gfx_SetAlphaBlending(true);
gfx_hadFog = Gfx_GetFog();
if (gfx_hadFog) Gfx_SetFog(false);
gfx_rendering2D = true;
}
void Gfx_End2D(void) {
Gfx_SetDepthTest(true);
Gfx_SetAlphaBlending(false);
if (gfx_hadFog) Gfx_SetFog(true);
gfx_rendering2D = false;
}
#endif

View File

@ -30,7 +30,7 @@ static const cc_uint8 key_map[8 * 16] = {
/* 0x30 */ CCKEY_TAB, CCKEY_SPACE, CCKEY_TILDE, CCKEY_BACKSPACE, 0, CCKEY_ESCAPE, 0, 0,
/* 0x38 */ 0, CCKEY_CAPSLOCK, 0, 0, 0, 0, 0, 0,
/* 0x40 */ 0, CCKEY_KP_DECIMAL, 0, CCKEY_KP_MULTIPLY, 0, CCKEY_KP_PLUS, 0, CCKEY_NUMLOCK,
/* 0x48 */ 0, 0, 0, CCKEY_KP_DIVIDE, CCKEY_KP_ENTER, 0, CCKEY_KP_MINUS, 0,
/* 0x48 */ CCKEY_VOLUME_UP, CCKEY_VOLUME_DOWN, CCKEY_VOLUME_MUTE, CCKEY_KP_DIVIDE, CCKEY_KP_ENTER, 0, CCKEY_KP_MINUS, 0,
/* 0x50 */ 0, CCKEY_KP_ENTER, CCKEY_KP0, CCKEY_KP1, CCKEY_KP2, CCKEY_KP3, CCKEY_KP4, CCKEY_KP5,
/* 0x58 */ CCKEY_KP6, CCKEY_KP7, 0, CCKEY_KP8, CCKEY_KP9, 'N', 'M', CCKEY_PERIOD,
/* 0x60 */ CCKEY_F5, CCKEY_F6, CCKEY_F7, CCKEY_F3, CCKEY_F8, CCKEY_F9, 0, CCKEY_F11,
@ -434,8 +434,15 @@ static int MapNativeMouse(long button) {
if (button == 0) return CCMOUSE_L;
if (button == 1) return CCMOUSE_R;
if (button == 2) return CCMOUSE_M;
if (button == 3) return CCMOUSE_X1;
if (button == 4) return CCMOUSE_X2;
if (button == 5) return CCMOUSE_X3;
if (button == 6) return CCMOUSE_X4;
if (button == 7) return CCMOUSE_X5;
if (button == 8) return CCMOUSE_X6;
Platform_Log1("Unknown mouse button: %i", &button);
return 0;
}

View File

@ -83,13 +83,12 @@ AV_FORCE_INLINE void* aligned_vector_at(const AlignedVector* vector, const uint3
AV_FORCE_INLINE void* aligned_vector_reserve(AlignedVector* vector, uint32_t element_count) {
AlignedVectorHeader* hdr = &vector->hdr;
uint32_t original_byte_size = (hdr->size * AV_ELEMENT_SIZE);
if(element_count < hdr->capacity) {
return aligned_vector_at(vector, element_count);
return vector->data + original_byte_size;
}
uint32_t original_byte_size = (hdr->size * AV_ELEMENT_SIZE);
/* We overallocate so that we don't make small allocations during push backs */
element_count = ROUND_TO_CHUNK_SIZE(element_count);

View File

@ -1,28 +1,3 @@
#include <stdint.h>
#include "private.h"
#include "platform.h"
extern void apply_poly_header(PolyHeader* header, PolyList* activePolyList);
GL_FORCE_INLINE Vertex* submitVertices(GLuint vertexCount) {
TRACE();
PolyList* output = _glActivePolyList();
uint32_t header_offset;
uint32_t start_offset;
uint32_t vector_size = aligned_vector_size(&output->vector);
GLboolean header_required = (vector_size == 0) || STATE_DIRTY;
header_offset = vector_size;
start_offset = header_offset + (header_required ? 1 : 0);
/* Make room for the vertices and header */
aligned_vector_extend(&output->vector, (header_required) + vertexCount);
gl_assert(header_offset < aligned_vector_size(&output->vector));
if (header_required) {
apply_poly_header(aligned_vector_at(&output->vector, header_offset), output);
STATE_DIRTY = GL_FALSE;
}
return aligned_vector_at(&output->vector, start_offset);
}
#include "platform.h"

View File

@ -465,7 +465,7 @@ void SceneListSubmit(Vertex* v3, int n) {
for(int i = 0; i < n; ++i, ++v3) {
PREFETCH(v3 + 1);
switch(v3->flags) {
switch(v3->flags & 0xFF000000) {
case GPU_CMD_VERTEX_EOL:
break;
case GPU_CMD_VERTEX:
@ -480,12 +480,8 @@ void SceneListSubmit(Vertex* v3, int n) {
Vertex* const v1 = v3 - 2;
Vertex* const v2 = v3 - 1;
visible_mask = (
(v0->xyz[2] > -v0->w) << 0 |
(v1->xyz[2] > -v1->w) << 1 |
(v2->xyz[2] > -v2->w) << 2 |
(v3->xyz[2] > -v3->w) << 3
);
visible_mask = v3->flags & 0xFF;
v3->flags &= ~0xFF;
// Stats gathering found that when testing a 64x64x64 sized world, at most
// ~400-500 triangles needed clipping
@ -505,7 +501,7 @@ void SceneListSubmit(Vertex* v3, int n) {
_glPerspectiveDivideVertex(v2);
_glPushHeaderOrVertex(v2);
_glPerspectiveDivideVertex(v0);
_glPushHeaderOrVertex(v0);
@ -514,9 +510,6 @@ void SceneListSubmit(Vertex* v3, int n) {
}
break;
case 0: // No vertices visible
break;
default: // Some vertices visible
SubmitClipped(v0, v1, v2, v3, visible_mask);
break;