Skip to content

Commit

Permalink
Added jsoncpp to build script
Browse files Browse the repository at this point in the history
  • Loading branch information
EPICGameGuy committed Dec 15, 2023
1 parent bcf4b2c commit 0f722f2
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 34 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ jobs:
cmake ..
make clean all install -j$(getconf _NPROCESSORS_ONLN)
- name: Install jsoncpp
run: |
git clone https://github.com/open-source-parsers/jsoncpp.git dependencies/jsoncpp
cd dependencies/jsoncpp
mkdir -p build
cd build
cmake ..
make clean all install -j$(getconf _NPROCESSORS_ONLN)
- name: Compile egg-library
run: |
cd dependencies/egg-library
Expand Down
Binary file modified assets/levels/new_level.lvl
Binary file not shown.
Binary file modified assets/models/plane.fbx
Binary file not shown.
Binary file modified assets/models/plant.fbx
Binary file not shown.
1 change: 1 addition & 0 deletions include/renderer/ps2gl_renderers/custom_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CCustomRendererBase: public CLinearRenderer
virtual void InitContext(GLenum primType, tU32 rcChanges, bool userRcChanged) override;
virtual void DrawLinearArrays(CGeometryBlock& block) override;
virtual bool GetCachePackets(const CGeometryBlock& geometry) { return true; }
void AddVu1RendererContext(CVifSCDmaPacket& packet, GLenum primType, int vu1Offset);

// This is the prim type passed to the gs
u32 PrimType = 0x7; // 0x7 = triangle strip
Expand Down
2 changes: 1 addition & 1 deletion src/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "graph.h"

#ifndef FILESYSTEM_TYPE
#define FILESYSTEM_TYPE Filesystem::Type::host
#define FILESYSTEM_TYPE Filesystem::Type::cdrom
#endif

namespace Engine
Expand Down
4 changes: 2 additions & 2 deletions src/objects/teapot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static class teapot_render_proxy: public Renderable, public Debuggable

virtual void on_gs_init() override
{
//teapot_mesh = new Mesh("assets/models/kettle.mdl"_asset);
teapot_mesh = new Mesh("assets/models/kettle.mdl"_asset);
}

virtual void render(const GS::GSState& gs_state) override
Expand All @@ -43,7 +43,7 @@ static class teapot_render_proxy: public Renderable, public Debuggable
ScopedMatrix sm(local_world);

//printf("Drawing teapot\n");
//teapot_mesh->draw(false);
teapot_mesh->draw(false);
}

AABB get_bounds() const
Expand Down
162 changes: 156 additions & 6 deletions src/renderer/ps2gl_renderers/custom_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "ps2gl/metrics.h"
#include "ps2gl/texture.h"

#include "vu1_context.h"

CCustomRendererBase::CCustomRendererBase(void* packet, int packetSize,
int inQuadsPerVert, int outQuadsPerVert,
int inGeomOffset, int inGeomBufSize,
Expand Down Expand Up @@ -48,12 +50,6 @@ void CCustomRendererBase::InitContext(GLenum, tU32 rcChanges, bool userRcChanged
GS::tPrim prim = {prim_type : PrimType, iip : smoothShading, tme : useTexture, fge : 0, abe : alpha, aa1 : 0, fst : 0, ctxt : 0, fix : 0};
tGifTag giftag = {NLOOP : 0, EOP : 1, pad0 : 0, id : 0, PRE : 1, PRIM : *(tU64*)&prim, FLG : 0, NREG : nreg, REGS0 : 2, REGS1 : 1, REGS2 : 4};

// packet.Pad96();

// packet.OpenUnpack(Vifs::UnpackModes::s_32, kTime, Packet::kSingleBuff);
// packet += std::sin(Engine::get_game_time()) * 4.f;
// packet.CloseUnpack(1);

packet.Mscal(0);
packet.Flushe();

Expand Down Expand Up @@ -97,4 +93,158 @@ void CCustomRendererBase::DrawLinearArrays(CGeometryBlock& block)
// draw

DrawBlock(packet, block, maxVertsPerBuffer);
}

#define kContextStart 0 // for the kLightBase stuff below

void CCustomRendererBase::AddVu1RendererContext(CVifSCDmaPacket& packet, GLenum primType, int vu1Offset)
{
CGLContext& glContext = *pGLContext;

packet.Stcycl(1, 1);
packet.Flush();
packet.Pad96();
packet.OpenUnpack(Vifs::UnpackModes::v4_32, vu1Offset, Packet::kSingleBuff);
{
// find light pointers
CImmLighting& lighting = glContext.GetImmLighting();
tLightPtrs lightPtrs[8];

bool doLighting = false;

// transpose of object to world space xfrm (for light directions)
cpu_mat_44 objToWorldXfrmTrans = glContext.GetModelViewStack().GetTop();
// clear any translations.. should be doing a 3x3 transpose..
objToWorldXfrmTrans.set_col3(cpu_vec_xyzw(0, 0, 0, 1));
objToWorldXfrmTrans = objToWorldXfrmTrans.transpose();
// do we need to rescale normals?
cpu_mat_44 normalRescale;
normalRescale.set_identity();
float normalScale = 1.0f;
CImmDrawContext& drawContext = glContext.GetImmDrawContext();
objToWorldXfrmTrans = normalRescale * objToWorldXfrmTrans;

// num lights
packet += (tU64)0;
packet += 0;

// backface culling multiplier -- this is 1.0f or -1.0f, the 6th bit
// also turns on/off culling
float bfc_mult = (float)drawContext.GetCullFaceDir();
unsigned int bfc_word;
asm(" ## nop ## "
: "=r"(bfc_word)
: "0"(bfc_mult));
bool do_culling = drawContext.GetDoCullFace() && (primType > GL_LINE_STRIP);
packet += bfc_word | (unsigned int)do_culling << 5;

// light pointers
packet.Add(&lightPtrs[0], 8);

float maxColorValue = GetMaxColorValue(glContext.GetTexManager().GetTexEnabled());

// add light info
for (int i = 0; i < 8; i++)
{
CImmLight& light = lighting.GetImmLight(i);
packet += light.GetAmbient() * maxColorValue;
packet += light.GetDiffuse() * maxColorValue;
packet += light.GetSpecular() * maxColorValue;

if (light.IsDirectional())
packet += light.GetPosition();
else
{
packet += light.GetPosition();
}

packet += light.GetSpotDir();

// attenuation coeffs for positional light sources
// because we're doing lighting calculations in object space,
// we need to adjust the attenuation of positional light sources
// and all lighting directions to take into account scaling
packet += light.GetConstantAtten();
packet += light.GetLinearAtten() * 1.0f / normalScale;
packet += light.GetQuadAtten() * 1.0f / normalScale;
packet += 0; // padding
}

// global ambient
cpu_vec_4 globalAmb;
if (doLighting)
globalAmb = lighting.GetGlobalAmbient() * maxColorValue;
else
globalAmb = cpu_vec_4(0, 0, 0, 0);
packet.Add((tU32*)&globalAmb, 3);

// stick in the offset to convert clip space depth value to GS
float depthClipToGs = (float)((1 << drawContext.GetDepthBits()) - 1) / 2.0f;
packet += depthClipToGs;

// cur material

CImmMaterial& material = glContext.GetMaterialManager().GetImmMaterial();

// add emissive component
cpu_vec_4 emission;
if (doLighting)
emission = material.GetEmission() * maxColorValue;
else
emission = glContext.GetMaterialManager().GetCurColor() * maxColorValue;
packet += emission;

// ambient
packet += material.GetAmbient();

// diffuse
cpu_vec_4 matDiffuse = material.GetDiffuse();
// the alpha value is set to the alpha of the diffuse in the renderers;
// this should be the current color alpha if lighting is disabled
if (!doLighting)
matDiffuse[3] = glContext.GetMaterialManager().GetCurColor()[3];
packet += matDiffuse;

// specular
packet += material.GetSpecular();

// vertex xform
packet += drawContext.GetVertexXform();

// fixed vertToEye vector for non-local specular
cpu_vec_xyzw vertToEye(0.0f, 0.0f, 1.0f, 0.0f);
packet += objToWorldXfrmTrans * vertToEye;

// transpose of object to world space transform
packet += objToWorldXfrmTrans;

// world to object space xfrm (for light positions)
cpu_mat_44 worldToObjXfrm = glContext.GetModelViewStack().GetInvTop();
packet += worldToObjXfrm;

// giftag - this is down at the bottom to make sure that when switching
// primitives the last buffer will have a chance to copy the giftag before
// it is overwritten with the new one
GLenum newPrimType = drawContext.GetPolygonMode();
if (newPrimType == GL_FILL)
newPrimType = primType;
newPrimType &= 0xff;
tGifTag giftag = BuildGiftag(newPrimType);
packet += giftag;

// add info used by clipping code
// first the dimensions of the framebuffer
float xClip = (float)2048.0f / (drawContext.GetFBWidth() * 2.f);
packet += Math::Max(xClip, 1.0f);
float yClip = (float)2048.0f / (drawContext.GetFBHeight() * 2.f);
packet += Math::Max(yClip, 1.0f);
float depthClip = 2048.0f / depthClipToGs;
// FIXME: maybe these 2048's should be 2047.5s...
depthClip *= 1.003f; // round up a bit for fp error (????)
//printf("depthClip: %f\n", depthClip);
packet += depthClip;
// enable/disable clipping
packet += (drawContext.GetDoClipping()) ? 1 : 0;
}
packet.CloseUnpack();
}
14 changes: 0 additions & 14 deletions src/renderer/ps2gl_renderers/vertex_color_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,11 @@ void CVertexColorRenderer::InitContext(GLenum primType, tU32 rcChanges, bool use
{
AddVu1RendererContext(packet, primType, kContextStart);

// overwrite the giftag built by CBaseRenderer::AddVu1RendererContext()...
// ..it knows not what it does.
primType &= 0x7; // convert from GL #define to gs prim number
CImmDrawContext& drawContext = glContext.GetImmDrawContext();
bool smoothShading = drawContext.GetDoSmoothShading();
bool useTexture = glContext.GetTexManager().GetTexEnabled();
bool alpha = drawContext.GetBlendEnabled();
unsigned int nreg = OutputQuadsPerVert;

GS::tPrim prim = {prim_type : primType, iip : smoothShading, tme : useTexture, fge : 0, abe : alpha, aa1 : 0, fst : 0, ctxt : 0, fix : 0};
tGifTag giftag = {NLOOP : 0, EOP : 1, pad0 : 0, id : 0, PRE : 1, PRIM : *(tU64*)&prim, FLG : 0, NREG : nreg, REGS0 : 2, REGS1 : 1, REGS2 : 4};

packet.Mscal(0);
packet.Flushe();

packet.Base(kDoubleBufBase);
packet.Offset(kDoubleBufOffset);

packet.Pad128();
}
packet.CloseTag();

Expand Down
11 changes: 0 additions & 11 deletions src/renderer/ps2gl_renderers/vertex_color_vegetation_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,6 @@ void CVertexColorVegetationRenderer::InitContext(GLenum primType, tU32 rcChanges
{
AddVu1RendererContext(packet, primType, kContextStart);

// overwrite the giftag built by CBaseRenderer::AddVu1RendererContext()...
// ..it knows not what it does.
primType &= 0x7; // convert from GL #define to gs prim number
bool smoothShading = drawContext.GetDoSmoothShading();
bool useTexture = glContext.GetTexManager().GetTexEnabled();
bool alpha = drawContext.GetBlendEnabled();
unsigned int nreg = OutputQuadsPerVert;

GS::tPrim prim = {prim_type : primType, iip : smoothShading, tme : useTexture, fge : 0, abe : alpha, aa1 : 0, fst : 0, ctxt : 0, fix : 0};
tGifTag giftag = {NLOOP : 0, EOP : 1, pad0 : 0, id : 0, PRE : 1, PRIM : *(tU64*)&prim, FLG : 0, NREG : nreg, REGS0 : 2, REGS1 : 1, REGS2 : 4};

packet.Pad96();

packet.OpenUnpack(Vifs::UnpackModes::s_32, kVegetationParams, Packet::kSingleBuff);
Expand Down
1 change: 1 addition & 0 deletions src/world.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class WorldMesh: public Renderable,
ScopedMatrix m(level->meshes.mesh_transforms[i]);
mesh_render_stats[i].timer.start();
meshes[level->meshes.mesh_files[i]].draw();
//glFlush();
mesh_render_stats[i].timer.end();
}
world_render_stat.timer.end();
Expand Down

0 comments on commit 0f722f2

Please sign in to comment.