Skip to content

Commit

Permalink
Trying out a custom renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
EPICGameGuy committed Nov 27, 2023
1 parent 0047d11 commit e54e045
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 38 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ jobs:
- uses: actions/checkout@v3
- name: Get dependencies
run: |
apk add build-base git cmake xorriso assimp-dev
apk add build-base binutils-dev git cmake xorriso assimp-dev musl-obstack-dev
- name: Install openvcl/MASP
run:
git clone https://github.com/nicholas477/openvcl.git dependencies/openvcl
cd dependencies/openvcl/contrib/masp
chmod +x ./configure && ./configure LIBS="-lobstack"
make clean install -j$(getconf _NPROCESSORS_ONLN)
cd ../../
make clean install -j$(getconf _NPROCESSORS_ONLN)


- name: Install ps2stuff
run: |
Expand Down
17 changes: 17 additions & 0 deletions include/renderer/ps2gl_renderers/vertex_color_renderer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include "GL/gl.h"
#include "ps2gl/immgmanager.h"
#include "ps2gl/linear_renderer.h"
#include "ps2gl/renderer.h"

#define kVCRPrimType (((tU32)1 << 31) | 1)
#define kVCRPrimTypeFlag ((tU64)1 << 32)

class VertexColorRenderer: public CLinearRenderer
{
public:
VertexColorRenderer();

static VertexColorRenderer* Register();
};
27 changes: 12 additions & 15 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ ISO_FOLDER_DIR = build/iso
VU_OUTPUT_DIR = vu
VU_PROGS = $(addprefix $(OUTPUT_DIR)/$(VU_OUTPUT_DIR)/, $(patsubst %.vcl, %.o, $(VCL_FILES)))

PS2GL_DIR = dependencies/ps2gl
EE_INCS += -I$(PS2GL_DIR)/vu1

#
# Vector Unit assembler:
#
Expand All @@ -37,12 +40,14 @@ PS2_VCLPP = vclpp
#
# VCL/VU microprograms:
#
VCL_PATH = $(PREFIX)vu1progs
VCL_FILES =

EE_OBJS := $(VU_PROGS) $(EE_OBJS)
VCL_PATH = $(PREFIX)
VCL_FILES = renderer/ps2gl_renderers/vuprogs/general_pv_diff.vcl

include src/Makefile.iso
include src/Makefile.vuprogs

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

.PHONY: compile cleancompile
compile: $(EE_BIN)
Expand All @@ -53,18 +58,10 @@ cleancompile:

clean: cleaniso cleancompile

all: $(ISO_TGT)

#
# VU microprograms:
#
$(VU_PROGS): $(OUTPUT_DIR)/$(VU_OUTPUT_DIR)/%.o: $(OUTPUT_DIR)/$(VU_OUTPUT_DIR)/%.vsm
$(PS2_VU_DVP) $< -o $@
realclean: clean
rm -f $(VSM_SOURCES)

$(OUTPUT_DIR)/$(VU_OUTPUT_DIR)/%.vsm:
$(MKDIR) -p $(dir $@)
$(PS2_VCLPP) $(VCL_PATH)/$*.vcl $(dir $@)$*.pp.vcl -j
$(PS2_VCL) -o$@ $(dir $@)$*.pp.vcl
all: $(ISO_TGT)

run: $(EE_BIN)
cd $(dir $(EE_BIN))
Expand Down
26 changes: 26 additions & 0 deletions src/Makefile.vuprogs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
RENDERERS = \
vertex_color_renderer

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

%.vo: %_vcl.vsm
dvp-as -o $@ $<

%_vcl.vsm: %_pp4.vcl
vcl -o$@ $<

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

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

%_pp3.vcl: %_pp2.vcl
cat $< | sed 's/\[\([0-9]\)\]/_\1/g ; s/\[\([w-zW-Z]\)\]/\1/g' - > $@

%_pp2.vcl: %_pp1.vcl
masp -c ';' -I$(PS2GL_DIR) -o $@ $<

%_pp1.vcl: %.vcl
cat $< | sed 's/#include[ ]\+.\+// ; s/#define[ ]\+.\+// ; s|\(\.include[ ]\+\)"\([^/].\+\)"|\1"$(<D)/\2"|' - > $@
3 changes: 3 additions & 0 deletions src/renderer/gs.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "objects/camera.hpp"
#include "renderer/gs.hpp"
#include "renderer/renderable.hpp"
#include "renderer/ps2gl_renderers/vertex_color_renderer.hpp"
#include "stats.hpp"
#include "egg/assert.hpp"

Expand Down Expand Up @@ -109,6 +110,8 @@ static void init_renderer()

init_lights();

VertexColorRenderer::Register();

for (Renderable::TIterator Itr = Renderable::Itr(); Itr; ++Itr)
{
Itr->on_gs_init();
Expand Down
24 changes: 2 additions & 22 deletions src/renderer/mesh.cc
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
#include "renderer/mesh.hpp"
#include "renderer/renderable.hpp"
#include "renderer/ps2gl_renderers/vertex_color_renderer.hpp"

#include "egg/filesystem.hpp"
#include <egg/mesh_header.hpp>
#include <GL/gl.h>
#include <GL/ps2gl.h>
#include <egg/assert.hpp>

//std::unordered_map<Filesystem::Path, Mesh> Mesh::loaded_meshes;
static GLint num_lists = 0;

// static class MeshLoader: public renderable
// {
// public:
// MeshLoader()
// : renderable(true)
// {
// }

// virtual void on_gs_init() override
// {
// //Mesh::loaded_meshes["/assets/models/kettle.ps2_model"_p] = Mesh("/assets/models/kettle.ps2_model"_p);
// //Mesh::loaded_meshes["/assets/models/shopping_cart.ps2_model"_p] = Mesh("/assets/models/shopping_cart.ps2_model"_p);

// for (auto& [path, mesh] : Mesh::loaded_meshes)
// {
// mesh.compile();
// }
// }
// } mesh_loader;

Mesh::Mesh()
{
list = -1;
Expand Down Expand Up @@ -96,7 +76,7 @@ void Mesh::compile()
printf("Compiling mesh strip: %d\n", i);
const auto start_index = strip.strip_start_index;
const auto count = strip.strip_end_index - start_index;
glDrawArrays(GL_TRIANGLE_STRIP, start_index, count);
glDrawArrays(kVCRPrimType, start_index, count);

++i;
}
Expand Down
40 changes: 40 additions & 0 deletions src/renderer/ps2gl_renderers/vertex_color_renderer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "renderer/ps2gl_renderers/vertex_color_renderer.hpp"
#include "vu1_mem_linear.h"

#define VU_FUNCTIONS(name) \
void vsm##name##_CodeStart(); \
void vsm##name##_CodeEnd()

#define mVsmAddr(name) ((void*)vsm##name##_CodeStart)
#define mVsmSize(name) ((u8*)vsm##name##_CodeEnd - (u8*)vsm##name##_CodeStart)

extern "C" {
VU_FUNCTIONS(VertexColorRenderer);
}

VertexColorRenderer::VertexColorRenderer()
: CLinearRenderer(mVsmAddr(VertexColorRenderer), mVsmSize(VertexColorRenderer), 4, 3,
kInputStart,
kInputBufSize - kInputStart,
"Vertex color renderer")
{
Requirements = 0; // no requirements
Capabilities = kVCRPrimTypeFlag; // provides the "kVCRPrimType" capability
}

VertexColorRenderer* VertexColorRenderer::Register()
{
// create a renderer and register it

VertexColorRenderer* renderer = new VertexColorRenderer;
pglRegisterRenderer(renderer);

// register the prim type

pglRegisterCustomPrimType(kVCRPrimType, // the prim type we will pass to ps2gl (glBegin...)
kVCRPrimTypeFlag, // the corresponding renderer requirement
~(tU64)0xffffffff, // we only care about the custom stuff (upper 32 bits)
true); // ok to merge multiple calls when possible

return renderer;
}
Loading

0 comments on commit e54e045

Please sign in to comment.