Skip to content
Open
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
81 changes: 74 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ RENDERERS = \
general_tri \
general \
indexed \
scei
indexed_constant_color \
indexed_no_lights_pvc \
scei \
fast_no_lights_pvc_tri

EE_OBJS += $(addsuffix .vo, $(addprefix vu1/, $(RENDERERS)))

Expand All @@ -66,6 +69,7 @@ install: all
cp -f $(EE_LIB) $(PS2SDK)/ports/lib

clean:
rm -rf ./GS_DUMP/hard/*
rm -f $(EE_OBJS_LIB) $(EE_OBJS) $(EE_BIN) $(EE_LIB)

realclean: clean
Expand All @@ -76,23 +80,86 @@ realclean: clean
include $(PS2SDK)/Defs.make
include $(PS2SDK)/samples/Makefile.eeglobal

.PHONY: one
one:
@test -n "$(VCL)" || (echo "Usage: make $@ VCL=path/to/foo.vcl"; exit 1)
$(MAKE) $(VCL:.vcl=_vcl.vsm) $(VCL:.vcl=.vo)

## dvp-as origin in ps2dev toolchain: https://github.com/ps2dev/ps2toolchain/blob/master/scripts/001-dvp.sh
## Build .vo (VU object) from a compiled .vsm
%.vo: %_vcl.vsm
dvp-as -o $@ $<

# VCL (Vector Command Language): https://ps2linux.no-ip.info/playstation2-linux.com/projects/vcl.html
# for documentation download the x86 or win32 tar above and read the VCL_User_Manual_E_v1.4_1.pdf
# more resources on vsm: http://lukasz.dk/files/vu-instruction-manual.pdf
%_vcl.vsm: %_pp4.vcl
vcl -o$@ $<

%indexed_pp4.vcl: %indexed_pp3.vcl
cat $< | cc -E -P -imacros vu1/vu1_mem_indexed.h -o $@ -

%_pp4.vcl: %_pp3.vcl
cat $< | cc -E -P -imacros vu1/vu1_mem_linear.h -o $@ -

# GCC / CPP flags (-E, -P, -imacros): https://gcc.gnu.org/onlinedocs/cpp/Invocation.html#Invocation
# -E = preprocess only, -P = strip #line, -imacros includes macros without writing #include
vu1/%_pp4.vcl: vu1/%_pp3.vcl
@hdr=vu1/vu1_mem_linear.h; \
case "$*" in \
indexed|indexed_*) hdr=vu1/vu1_mem_indexed.h ;; \
esac; \
cat $< | cc -E -P -imacros $$hdr -o $@ -

#TODO: remove this step? This could be covered simply from writing correct vcl code... unless intending to allow new and old syntax?
# you can standardize syntax by using ".syntax old" or ".syntax new" or by passing `-n` to VCL for "new" and writing sources
# accordingly, it might be better to allow for correcting towards that to avoid confusion...
%_pp3.vcl: %_pp2.vcl
cat $< | sed 's/\[\([0-9]\)\]/_\1/g ; s/\[\([w-zW-Z]\)\]/\1/g' - > $@

# Expand assembly-style macros and .include with GASP
# -c ';' uses ';' as the comment char; -Ivu1 resolves local .include files.
# GASP (GNU assembler preprocessor) manpage: https://manpages.debian.org/unstable/binutils-m68hc1x/gasp.1.en.html
%_pp2.vcl: %_pp1.vcl
gasp -c ';' -Ivu1 -o $@ $<

# this is in order to normalize sources for GASP by removing C preprocessor stuff (#include/#define),
# and then fix local .include paths so GASP can resolve them relative to the source dir.
# if the .vcl file ALREADY avoids #include/#define and only use .include/.macro etc
# and wire %.vcl -> %_pp2.vcl directly and drop this rule??
%_pp1.vcl: %.vcl
cat $< | sed 's/#include[ ]\+.\+// ; s/#define[ ]\+.\+// ; s|\(\.include[ ]\+\)"\([^/].\+\)"|\1"$(<D)/\2"|' - > $@

# ---- build examples and create ./bin launchers ---------------------

SHELL := /bin/bash
EXAMPLES_DIR := examples
BIN_DIR := bin
PCSX2_BIN ?= pcsx2
PCSX2_FLAGS ?= -nogui -batch -fastboot -earlyconsolelog -logfile /dev/null

.PHONY: examples clean-examples

examples:
mkdir -p $(BIN_DIR)
# build each example (skip shared_code)
find $(EXAMPLES_DIR) -type f -name Makefile ! -path '*/shared_code/*' -print0 \
| while IFS= read -r -d '' mf; do \
dir=$$(dirname "$$mf"); \
echo "==> make -C $$dir"; \
$(MAKE) -C "$$dir"; \
done; \
# create launchers for every .elf (absolute path!)
find $(EXAMPLES_DIR) -type f -name '*.elf' -print0 \
| while IFS= read -r -d '' elf; do \
name=$$(basename "$${elf%.elf}"); \
abs=$$(readlink -f "$$elf"); \
echo "==> writing $(BIN_DIR)/$$name -> $$abs"; \
printf '#!/usr/bin/env bash\n%s %s -elf %s "$$@"\n' \
'$(PCSX2_BIN)' '$(PCSX2_FLAGS)' "$$abs" > "$(BIN_DIR)/$$name"; \
chmod +x "$(BIN_DIR)/$$name"; \
done

clean-examples:
rm -rf ./GS_DUMP/hard/*
rm -rf $(BIN_DIR)
find $(EXAMPLES_DIR) -type f -name Makefile ! -path '*/shared_code/*' -print0 \
| while IFS= read -r -d '' mf; do \
dir=$$(dirname "$$mf"); \
echo "==> clean $$dir"; \
$(MAKE) -C "$$dir" clean || true; \
done
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ Bug reports should be submitted to the appropriate homepage, which hosts a bug t

## Changelog

### 0.3.x (beginning revival attempts)
- Added documentation to Makefile for references to using vcl and other tools in 2025 (also updated some vcl for potential deprecation of vcl preprocess step 2:
`cat $< | sed 's/\[\([0-9]\)\]/_\1/g ; s/\[\([w-zW-Z]\)\]/\1/g' - > $@ `
- Added a fast no lights per vertex color renderer with pvc_box examples (lit with `general_pv_diff_tri` and unlit `fast_no_lights_pvc_tri`) -- WIP, could be very slow for some reason
- begin testing against https://github.com/raylib4Consoles/raylib4PlayStation2 integration (will be useful for testing expected OpenGL1.1 behavior)

### 0.3
- Can now define custom prim types and attributes, tying them to custom renderers and override default renderers.
- Lots of bug fixes!
Expand Down
6 changes: 0 additions & 6 deletions examples/nehe/lesson03/lesson3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ void init(GLvoid) // Create Some Everyday Functions
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

// ps2gl needs lighting + color_material for per-vertex colors
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}

void display(void) // Create The Display Function
Expand Down
6 changes: 0 additions & 6 deletions examples/nehe/lesson04/lesson4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ void init(GLvoid) // Create Some Everyday Functions
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

// ps2gl needs lighting + color_material for per-vertex colors
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}

void idle(void) {
Expand Down
20 changes: 14 additions & 6 deletions examples/nehe/lesson05/lesson5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ void InitGL(GLvoid) // Create Some Everyday Functions
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

// ps2gl needs lighting + color_material for per-vertex colors
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}

void idle(void) {
Expand All @@ -41,6 +35,10 @@ void idle(void) {

void display(void) // Create The Display Function
{
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glPushMatrix();
Expand Down Expand Up @@ -73,10 +71,20 @@ void display(void) // Create The Display Fu
glVertex3f(-1.0f, -1.0f, 1.0f); // Right Of Triangle (Left)
glEnd(); // Finished Drawing The Triangle



glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(1.5f, 0.0f, -6.0f); // Move Right 1.5 Units And Into The Screen 6.0
glRotatef(rquad, 1.0f, 0.0f, 0.0f); // Rotate The Quad On The X axis
glColor3f(0.5f, 0.5f, 1.0f); // Set The Color To Blue One Time Only
// TODO: next make a fast no lights for QUADS
// for now its interesting to see the lighting based one for quads only here:
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
constexpr float default_normal_direction_alignment[4] = {0.f, 0.f, 1.f, 0.f};
glLightfv(GL_LIGHT0, GL_POSITION, default_normal_direction_alignment);
glBegin(GL_QUADS); // Draw A Quad
glColor3f(0.0f, 1.0f, 0.0f); // Set The Color To Blue
glVertex3f(1.0f, 1.0f, -1.0f); // Top Right Of The Quad (Top)
Expand Down
37 changes: 37 additions & 0 deletions examples/pvc_box/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
EE_BIN = pvc_box.elf
EE_CFLAGS := -I$(PS2SDK)/ports/include -I../shared_code/ $(EE_CFLAGS)
EE_CXXFLAGS := -I$(PS2SDK)/ports/include -I../shared_code/ $(EE_CXXFLAGS)
#EE_OBJS = lit_pvc_box.o ../shared_code/text_stuff.o
EE_OBJS = unlit_pvc_box.o ../shared_code/text_stuff.o
EE_LDFLAGS += -L$(PS2SDK)/ports/lib
EE_LIBS = -lps2glut -lps2gl -lps2stuff -lpad -ldma

ifeq ($(DEBUG), 1)
EE_CFLAGS += -D_DEBUG
EE_CXXFLAGS += -D_DEBUG
endif

# Disabling warnings
WARNING_FLAGS = -Wno-strict-aliasing -Wno-conversion-null

# VU0 code is broken so disable for now
EE_CFLAGS += $(WARNING_FLAGS) -DNO_VU0_VECTORS -DNO_ASM
EE_CXXFLAGS += $(WARNING_FLAGS) -DNO_VU0_VECTORS -DNO_ASM

all: $(EE_BIN)
$(EE_STRIP) --strip-all $(EE_BIN)

clean:
rm -f $(EE_BIN) $(EE_OBJS)

run: $(EE_BIN)
ps2client -h 192.168.1.10 execee host:$(EE_BIN)

reset:
ps2client -h 192.168.1.10 reset

sim: $(EE_BIN)
PCSX2 --elf=$(PWD)/$(EE_BIN)

include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal_cpp
150 changes: 150 additions & 0 deletions examples/pvc_box/lit_pvc_box.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#include <GL/gl.h>
#include <GL/glut.h>
#include <math.h>
#include <fcntl.h>
#include <unistd.h>
#include "ps2gl/renderermanager.h"
#include <ps2s/debug_macros.h>

void init_lights_and_color();
void display();
void cube_position_and_rotation();
void draw_rgb_cube();
static void colored_vertex(float r, float g, float b, float x, float y, float z);
void reshape(int width, int height);
void perspective(float fov, float aspect, float nearClip, float farClip);

static float cube_spin_angle = 0.0f;
static float cube_z = -6.0f, cube_forward_rotation = -18.0f;

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(640, 448);
glutCreateWindow("RGB Cube");
init_lights_and_color();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

void init_lights_and_color()
{
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_DIFFUSE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
mDebugPrint("[display() function] Renderer = %s\n", pglGetCurRendererName());
cube_spin_angle += 0.2f;
draw_rgb_cube();
glLoadIdentity();
}

void draw_rgb_cube()
{
cube_position_and_rotation();
//See gmanager.cpp
constexpr float default_normal_direction_alignment[4] = {0.f, 0.f, 1.f, 0.f};
glLightfv(GL_LIGHT0, GL_POSITION, default_normal_direction_alignment);
glBegin(GL_TRIANGLES);
{
// +Z (front): A(1,1,1) B(-1,1,1) C(-1,-1,1) D(1,-1,1)
// tri1: (A,B,C) = (R,G,B)
colored_vertex(1, 0, 0, 1, 1, 1);
colored_vertex(0, 1, 0,-1, 1, 1);
colored_vertex(0, 0, 1, -1, -1, 1);
// tri2: (A,C,D) = (R,B,G)
colored_vertex(1, 0, 0, 1, 1, 1);
colored_vertex(0, 0, 1, -1, -1, 1);
colored_vertex(0, 1, 0, 1, -1, 1);

// -Z (back): A(1,-1,-1) B(-1,-1,-1) C(-1,1,-1) D(1,1,-1)
// tri1: (A,B,C) = (R,G,B)
colored_vertex(1, 0, 0, 1, -1, -1);
colored_vertex(0, 1, 0,-1, -1, -1);
colored_vertex(0, 0, 1,-1, 1, -1);
// tri2: (A,C,D) = (R,B,G)
colored_vertex(1, 0, 0, 1, -1, -1);
colored_vertex(0, 0, 1,-1, 1, -1);
colored_vertex(0, 1, 0, 1, 1, -1);

// +Y (top): A(1,1,-1) B(-1,1,-1) C(-1,1,1) D(1,1,1)
// tri1: (A,B,C) = (R,G,B)
colored_vertex(1, 0, 0, 1, 1, -1);
colored_vertex(0, 1, 0,-1, 1, -1);
colored_vertex(0, 0, 1,-1, 1, 1);
// tri2: (A,C,D) = (R,B,G)
colored_vertex(1, 0, 0, 1, 1, -1);
colored_vertex(0, 0, 1,-1, 1, 1);
colored_vertex(0, 1, 0, 1, 1, 1);

// -Y (bottom): A(1,-1,1) B(-1,-1,1) C(-1,-1,-1) D(1,-1,-1)
// tri1: (A,B,C) = (R,G,B)
colored_vertex(1, 0, 0, 1, -1, 1);
colored_vertex(0, 1, 0,-1, -1, 1);
colored_vertex(0, 0, 1,-1, -1, -1);
// tri2: (A,C,D) = (R,B,G)
colored_vertex(1, 0, 0, 1, -1, 1);
colored_vertex(0, 0, 1,-1, -1, -1);
colored_vertex(0, 1, 0, 1, -1, -1);

// -X (left): A(-1,1,1) B(-1,1,-1) C(-1,-1,-1) D(-1,-1,1)
// tri1: (A,B,C) = (R,G,B)
colored_vertex(1, 0, 0,-1, 1, 1);
colored_vertex(0, 1, 0,-1, 1, -1);
colored_vertex(0, 0, 1,-1, -1, -1);
// tri2: (A,C,D) = (R,B,G)
colored_vertex(1, 0, 0,-1, 1, 1);
colored_vertex(0, 0, 1,-1, -1, -1);
colored_vertex(0, 1, 0,-1, -1, 1);

// +X (right): A(1,1,-1) B(1,1,1) C(1,-1,1) D(1,-1,-1)
// tri1: (A,B,C) = (R,G,B)
colored_vertex(1, 0, 0, 1, 1, -1);
colored_vertex(0, 1, 0, 1, 1, 1);
colored_vertex(0, 0, 1, 1, -1, 1);
// tri2: (A,C,D) = (R,B,G)
colored_vertex(1, 0, 0, 1, 1, -1);
colored_vertex(0, 0, 1, 1, -1, 1);
colored_vertex(0, 1, 0, 1, -1, -1);
}
glEnd();
}

void cube_position_and_rotation()
{
glTranslatef(0.0f, 0.0f, cube_z);
glRotatef(cube_forward_rotation, -1, 0, 0);
glRotatef(cube_spin_angle, 0.0f, 1.0f, 0.0f);
}

static void colored_vertex(const float r, const float g, const float b, const float x, const float y, const float z)
{
glColor3f(r, g, b);
glVertex3f(x, y, z);
}

void reshape(const int width, int height)
{
if (height == 0)
height = 1;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
perspective(40.0f, (float)width / (float)height, 0.1f, 4000.0f);
glMatrixMode(GL_MODELVIEW);
}

void perspective(float fov, const float aspect, const float nearClip, const float farClip)
{
fov *= 3.141592654f / 180.0f;
const float height = 2.0f * nearClip * tanf(fov / 2.0f);
const float width = height * aspect;
glFrustum(-width / 2.0f, width / 2.0f, -height / 2.0f, height / 2.0f, nearClip, farClip);
}
Loading
Loading