-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
EPICGameGuy
committed
Dec 13, 2023
1 parent
6774f60
commit 0c0fcd4
Showing
7 changed files
with
280 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
#include "ps2gl/renderer.h" | ||
#include "ps2gl/linear_renderer.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) | ||
|
||
static constexpr CRendererProps no_reqs = static_cast<CRendererProps>(0LL); | ||
static_assert(sizeof(0LL) == sizeof(CRendererProps)); | ||
|
||
// The 31st bit is the custom primitive flag, 1 is the custom renderer type | ||
// static constexpr u32 kVCRPrimType = ((tU32)1 << 31) | 1; | ||
// static constexpr u64 kVCRPrimTypeFlag = ((tU64)1 << 32); | ||
|
||
class CCustomRendererBase: public CLinearRenderer | ||
{ | ||
public: | ||
CCustomRendererBase(void* packet, int packetSize, | ||
int inQuadsPerVert, int outQuadsPerVert, | ||
int inGeomOffset, int inGeomBufSize, | ||
const char* name); | ||
|
||
virtual void InitContext(GLenum primType, tU32 rcChanges, bool userRcChanged) override; | ||
virtual void DrawLinearArrays(CGeometryBlock& block) override; | ||
|
||
// This is the prim type passed to the gs | ||
u32 PrimType = 0x7; // 0x7 = triangle strip | ||
u32 CustomPrimType = 0; | ||
u64 CustomPrimTypeFlag = 0; | ||
|
||
u32 ContextStart = 0; | ||
u32 DoubleBufBase = 0; | ||
u32 DoubleBufOffset = 0; | ||
u32 DoubleBufSize = 0; | ||
}; |
16 changes: 5 additions & 11 deletions
16
include/renderer/ps2gl_renderers/vertex_color_renderer.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
#pragma once | ||
|
||
#include "GL/gl.h" | ||
#include "ps2gl/immgmanager.h" | ||
#include "ps2gl/linear_renderer.h" | ||
#include "ps2gl/renderer.h" | ||
#include "renderer/ps2gl_renderers/custom_renderer.hpp" | ||
|
||
// The 31st bit is the custom primitive flag, 1 is the custom renderer type | ||
static constexpr u32 kVCRPrimType = ((tU32)1 << 31) | 1; | ||
static constexpr u64 kVCRPrimTypeFlag = ((tU64)1 << 32); | ||
static constexpr u32 VCRPrimType = ((tU32)1 << 31) | 1; | ||
static constexpr u64 VCRPrimTypeFlag = ((tU64)1 << 32); | ||
|
||
//#define kVCRPrimType (((tU32)1 << 31) | 1) | ||
//#define kVCRPrimTypeFlag ((tU64)1 << 32) | ||
|
||
class CVertexColorRenderer: public CLinearRenderer | ||
class CVertexColorRenderer: public CCustomRendererBase | ||
{ | ||
public: | ||
CVertexColorRenderer(); | ||
|
||
static CVertexColorRenderer* Register(); | ||
virtual void InitContext(GLenum primType, tU32 rcChanges, bool userRcChanged) override; | ||
//virtual bool GetCachePackets(const CGeometryBlock& geometry) { return true; }; | ||
virtual void DrawLinearArrays(CGeometryBlock& block) override; | ||
static CVertexColorRenderer* Register(); | ||
}; |
23 changes: 23 additions & 0 deletions
23
include/renderer/ps2gl_renderers/vertex_color_vegetation_renderer.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "GL/gl.h" | ||
#include "ps2gl/immgmanager.h" | ||
#include "ps2gl/linear_renderer.h" | ||
#include "ps2gl/renderer.h" | ||
#include "renderer/ps2gl_renderers/custom_renderer.hpp" | ||
|
||
// The 31st bit is the custom primitive flag, 1 is the custom renderer type | ||
static constexpr u32 VCVRPrimType = ((tU32)1 << 31) | 2; | ||
static constexpr u64 VCVRPrimTypeFlag = ((tU64)1 << 33); | ||
|
||
//#define kVCRPrimType (((tU32)1 << 31) | 1) | ||
//#define kVCRPrimTypeFlag ((tU64)1 << 32) | ||
|
||
class CVertexColorVegetationRenderer: public CCustomRendererBase | ||
{ | ||
public: | ||
CVertexColorVegetationRenderer(); | ||
|
||
static CVertexColorVegetationRenderer* Register(); | ||
virtual void InitContext(GLenum primType, tU32 rcChanges, bool userRcChanged) override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include "renderer/ps2gl_renderers/custom_renderer.hpp" | ||
|
||
#include "ps2s/cpu_matrix.h" | ||
#include "ps2s/math.h" | ||
#include "ps2s/packet.h" | ||
|
||
#include "ps2gl/drawcontext.h" | ||
#include "ps2gl/glcontext.h" | ||
#include "ps2gl/immgmanager.h" | ||
#include "ps2gl/lighting.h" | ||
#include "ps2gl/linear_renderer.h" | ||
#include "ps2gl/material.h" | ||
#include "ps2gl/matrix.h" | ||
#include "ps2gl/metrics.h" | ||
#include "ps2gl/texture.h" | ||
|
||
CCustomRendererBase::CCustomRendererBase(void* packet, int packetSize, | ||
int inQuadsPerVert, int outQuadsPerVert, | ||
int inGeomOffset, int inGeomBufSize, | ||
const char* name) | ||
: CLinearRenderer(packet, packetSize, inQuadsPerVert, outQuadsPerVert, | ||
inGeomOffset, | ||
inGeomBufSize, | ||
name) | ||
{ | ||
Requirements = 0; | ||
Capabilities = CustomPrimTypeFlag; | ||
} | ||
|
||
void CCustomRendererBase::InitContext(GLenum, tU32 rcChanges, bool userRcChanged) | ||
{ | ||
CGLContext& glContext = *pGLContext; | ||
CVifSCDmaPacket& packet = glContext.GetVif1Packet(); | ||
CImmDrawContext& drawContext = glContext.GetImmDrawContext(); | ||
|
||
packet.Cnt(); | ||
{ | ||
AddVu1RendererContext(packet, PrimType, ContextStart); // kContextStart | ||
|
||
// overwrite the giftag built by CBaseRenderer::AddVu1RendererContext()... | ||
// ..it knows not what it does. | ||
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.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(); | ||
|
||
packet.Base(DoubleBufBase); | ||
packet.Offset(DoubleBufOffset); | ||
|
||
packet.Pad128(); | ||
} | ||
packet.CloseTag(); | ||
|
||
CacheRendererState(); | ||
} | ||
|
||
void CCustomRendererBase::DrawLinearArrays(CGeometryBlock& block) | ||
{ | ||
block.SetNumVertsPerPrim(2); | ||
block.SetNumVertsToRestartStrip(2); | ||
|
||
int wordsPerVert = block.GetWordsPerVertex(); | ||
int wordsPerNormal = (block.GetNormalsAreValid()) ? block.GetWordsPerNormal() : 0; | ||
int wordsPerTex = (block.GetTexCoordsAreValid()) ? block.GetWordsPerTexCoord() : 0; | ||
int wordsPerColor = (block.GetColorsAreValid()) ? block.GetWordsPerColor() : 0; | ||
|
||
CVifSCDmaPacket& packet = pGLContext->GetVif1Packet(); | ||
InitXferBlock(packet, wordsPerVert, wordsPerNormal, wordsPerTex, wordsPerColor); | ||
|
||
// get max number of vertices per vu1 buffer | ||
|
||
// let's assume separate unpacks for vertices, normals, tex uvs.. | ||
int maxUnpackVerts = 256; | ||
// max number of vertex data in vu1 memory | ||
int vu1QuadsPerVert = InputQuadsPerVert; | ||
int inputBufSize = InputGeomBufSize; | ||
int maxVu1VertsPerBuffer = inputBufSize / vu1QuadsPerVert; | ||
// max vertices per buffer | ||
int maxVertsPerBuffer = std::min(maxUnpackVerts, maxVu1VertsPerBuffer); | ||
maxVertsPerBuffer -= 3; | ||
// make sure we don't end in the middle of a polygon | ||
maxVertsPerBuffer -= maxVertsPerBuffer % block.GetNumVertsPerPrim(); | ||
|
||
// draw | ||
|
||
DrawBlock(packet, block, maxVertsPerBuffer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.