summaryrefslogtreecommitdiffstats
path: root/src/render/Sprite2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/Sprite2d.cpp')
-rw-r--r--src/render/Sprite2d.cpp156
1 files changed, 83 insertions, 73 deletions
diff --git a/src/render/Sprite2d.cpp b/src/render/Sprite2d.cpp
index 2675c95f..d3d90964 100644
--- a/src/render/Sprite2d.cpp
+++ b/src/render/Sprite2d.cpp
@@ -5,13 +5,13 @@
#include "Camera.h"
#include "Sprite2d.h"
#include "Font.h"
+#include "RenderBuffer.h"
-RwIm2DVertex CSprite2d::maVertices[8];
float CSprite2d::RecipNearClip;
-int32 CSprite2d::mCurrentBank;
-int32 CSprite2d::mCurrentSprite[10];
-int32 CSprite2d::mBankStart[10];
-RwIm2DVertex CSprite2d::maBankVertices[500];
+float CSprite2d::NearScreenZ;
+int CSprite2d::nextBufferVertex;
+int CSprite2d::nextBufferIndex;
+RwIm2DVertex CSprite2d::maVertices[8];
void
CSprite2d::SetRecipNearClip(void)
@@ -22,52 +22,11 @@ CSprite2d::SetRecipNearClip(void)
void
CSprite2d::InitPerFrame(void)
{
- int i;
-
+ nextBufferVertex = 0;
+ nextBufferIndex = 0;
RecipNearClip = 1.0f / RwCameraGetNearClipPlane(Scene.camera);
- mCurrentBank = 0;
- for(i = 0; i < 10; i++)
- mCurrentSprite[i] = 0;
+ NearScreenZ = RwIm2DGetNearScreenZ();
}
-
-int32
-CSprite2d::GetBank(int32 n, RwTexture *tex)
-{
- mCurrentSprite[mCurrentBank] = 0;
- mBankStart[mCurrentBank+1] = mBankStart[mCurrentBank] + n;
- return mCurrentBank++;
-}
-
-void
-CSprite2d::AddSpriteToBank(int32 bank, const CRect &rect, const CRGBA &col,
- float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2)
-{
- SetVertices(&maBankVertices[6 * (mCurrentSprite[bank] + mBankStart[bank])],
- rect, col, col, col, col,
- u0, v0, u1, v1, u2, v2, u3, v3);
- mCurrentSprite[bank]++;
- if(mCurrentSprite[bank] + mBankStart[bank] >= mBankStart[bank+1]){
- DrawBank(bank);
- mCurrentSprite[bank] = 0;
- }
-}
-
-void
-CSprite2d::DrawBank(int32 bank)
-{
- if(mCurrentSprite[bank] == 0)
- return;
-
- // This is hacked III function to make it work with VC frontend.
- CFont::Sprite[bank].SetRenderState();
- RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
- RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR);
- RwIm2DRenderPrimitive(rwPRIMTYPETRILIST, &maBankVertices[6*mBankStart[bank]], 6*mCurrentSprite[bank]);
- mCurrentSprite[bank] = 0;
- //RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE);
-}
-
-
void
CSprite2d::Delete(void)
{
@@ -163,7 +122,7 @@ CSprite2d::SetVertices(const CRect &r, const CRGBA &c0, const CRGBA &c1, const C
screenz = RwIm2DGetFarScreenZ();
z = RwCameraGetFarClipPlane(Scene.camera);
}else{
- screenz = RwIm2DGetNearScreenZ();
+ screenz = NearScreenZ;
z = 1.0f/RecipNearClip;
}
recipz = 1.0f/z;
@@ -215,7 +174,7 @@ CSprite2d::SetVertices(const CRect &r, const CRGBA &c0, const CRGBA &c1, const C
{
float screenz, z, recipz;
- screenz = RwIm2DGetNearScreenZ();
+ screenz = NearScreenZ;
z = 1.0f/RecipNearClip;
recipz = 1.0f/z;
@@ -267,7 +226,7 @@ CSprite2d::SetVertices(float x1, float y1, float x2, float y2, float x3, float y
float screenz, recipz;
float z = RwCameraGetNearClipPlane(Scene.camera); // not done by game
- screenz = RwIm2DGetNearScreenZ();
+ screenz = NearScreenZ;
recipz = RecipNearClip;
RwIm2DVertexSetScreenX(&maVertices[0], x3);
@@ -313,7 +272,7 @@ CSprite2d::SetVertices(int n, float *positions, float *uvs, const CRGBA &col)
int i;
float screenz, recipz, z;
- screenz = RwIm2DGetNearScreenZ();
+ screenz = NearScreenZ;
recipz = RecipNearClip;
z = RwCameraGetNearClipPlane(Scene.camera); // not done by game
@@ -336,7 +295,7 @@ CSprite2d::SetMaskVertices(int n, float *positions)
int i;
float screenz, recipz, z;
- screenz = RwIm2DGetNearScreenZ();
+ screenz = NearScreenZ;
recipz = RecipNearClip;
z = RwCameraGetNearClipPlane(Scene.camera); // not done by game
@@ -356,47 +315,47 @@ CSprite2d::SetVertices(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, con
{
float screenz, recipz, z;
- screenz = RwIm2DGetNearScreenZ();
+ screenz = NearScreenZ;
recipz = RecipNearClip;
- z = RwCameraGetNearClipPlane(Scene.camera); // not done by game
+ //z = RwCameraGetNearClipPlane(Scene.camera); // not done by game
RwIm2DVertexSetScreenX(&verts[0], r.left);
RwIm2DVertexSetScreenY(&verts[0], r.top);
RwIm2DVertexSetScreenZ(&verts[0], screenz);
- RwIm2DVertexSetCameraZ(&verts[0], z);
+ //RwIm2DVertexSetCameraZ(&verts[0], z);
RwIm2DVertexSetRecipCameraZ(&verts[0], recipz);
RwIm2DVertexSetIntRGBA(&verts[0], c2.r, c2.g, c2.b, c2.a);
RwIm2DVertexSetU(&verts[0], u0, recipz);
RwIm2DVertexSetV(&verts[0], v0, recipz);
- RwIm2DVertexSetScreenX(&verts[1], r.left);
- RwIm2DVertexSetScreenY(&verts[1], r.bottom);
+ RwIm2DVertexSetScreenX(&verts[1], r.right);
+ RwIm2DVertexSetScreenY(&verts[1], r.top);
RwIm2DVertexSetScreenZ(&verts[1], screenz);
- RwIm2DVertexSetCameraZ(&verts[1], z);
+ //RwIm2DVertexSetCameraZ(&verts[1], z);
RwIm2DVertexSetRecipCameraZ(&verts[1], recipz);
- RwIm2DVertexSetIntRGBA(&verts[1], c0.r, c0.g, c0.b, c0.a);
- RwIm2DVertexSetU(&verts[1], u2, recipz);
- RwIm2DVertexSetV(&verts[1], v2, recipz);
+ RwIm2DVertexSetIntRGBA(&verts[1], c3.r, c3.g, c3.b, c3.a);
+ RwIm2DVertexSetU(&verts[1], u1, recipz);
+ RwIm2DVertexSetV(&verts[1], v1, recipz);
RwIm2DVertexSetScreenX(&verts[2], r.right);
RwIm2DVertexSetScreenY(&verts[2], r.bottom);
RwIm2DVertexSetScreenZ(&verts[2], screenz);
- RwIm2DVertexSetCameraZ(&verts[2], z);
+ //RwIm2DVertexSetCameraZ(&verts[2], z);
RwIm2DVertexSetRecipCameraZ(&verts[2], recipz);
RwIm2DVertexSetIntRGBA(&verts[2], c1.r, c1.g, c1.b, c1.a);
- RwIm2DVertexSetU(&verts[2], u3, recipz);
- RwIm2DVertexSetV(&verts[2], v3, recipz);
+ RwIm2DVertexSetU(&verts[2], u2, recipz);
+ RwIm2DVertexSetV(&verts[2], v2, recipz);
RwIm2DVertexSetScreenX(&verts[3], r.left);
- RwIm2DVertexSetScreenY(&verts[3], r.top);
+ RwIm2DVertexSetScreenY(&verts[3], r.bottom);
RwIm2DVertexSetScreenZ(&verts[3], screenz);
- RwIm2DVertexSetCameraZ(&verts[3], z);
+ //RwIm2DVertexSetCameraZ(&verts[3], z);
RwIm2DVertexSetRecipCameraZ(&verts[3], recipz);
- RwIm2DVertexSetIntRGBA(&verts[3], c2.r, c2.g, c2.b, c2.a);
- RwIm2DVertexSetU(&verts[3], u0, recipz);
- RwIm2DVertexSetV(&verts[3], v0, recipz);
+ RwIm2DVertexSetIntRGBA(&verts[3], c0.r, c0.g, c0.b, c0.a);
+ RwIm2DVertexSetU(&verts[3], u3, recipz);
+ RwIm2DVertexSetV(&verts[3], v3, recipz);
- RwIm2DVertexSetScreenX(&verts[4], r.right);
+ /*RwIm2DVertexSetScreenX(&verts[4], r.right);
RwIm2DVertexSetScreenY(&verts[4], r.bottom);
RwIm2DVertexSetScreenZ(&verts[4], screenz);
RwIm2DVertexSetCameraZ(&verts[4], z);
@@ -412,7 +371,7 @@ CSprite2d::SetVertices(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, con
RwIm2DVertexSetRecipCameraZ(&verts[5], recipz);
RwIm2DVertexSetIntRGBA(&verts[5], c3.r, c3.g, c3.b, c3.a);
RwIm2DVertexSetU(&verts[5], u1, recipz);
- RwIm2DVertexSetV(&verts[5], v1, recipz);
+ RwIm2DVertexSetV(&verts[5], v1, recipz);*/
}
@@ -488,3 +447,54 @@ void CSprite2d::Draw2DPolygon(float x1, float y1, float x2, float y2, float x3,
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEGOURAUD);
}
+
+void
+CSprite2d::AddToBuffer(const CRect &r, const CRGBA &c, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10)
+{
+ RwIm2DVertex* v = TempVertexBuffer;
+ SetVertices(
+ &v[nextBufferVertex],
+ r,
+ c,
+ c,
+ c,
+ c,
+ a3,
+ a4,
+ a5,
+ a6,
+ a7,
+ a8,
+ a9,
+ a10);
+ RwImVertexIndex *v12 = &TempBufferRenderIndexList[nextBufferIndex];
+ v12[0] = nextBufferVertex;
+ v12[1] = nextBufferVertex + 1;
+ v12[2] = nextBufferVertex + 2;
+ v12[3] = nextBufferVertex + 3;
+ v12[4] = nextBufferVertex;
+ v12[5] = nextBufferVertex + 2;
+ nextBufferIndex += 6;
+ nextBufferVertex += 4;
+ if (IsVertexBufferFull())
+ RenderVertexBuffer();
+}
+
+bool CSprite2d::IsVertexBufferFull()
+{
+ bool result = true;
+ if (nextBufferVertex <= 380 && nextBufferIndex <= 1018)
+ result = false;
+ return result;
+}
+
+void
+CSprite2d::RenderVertexBuffer()
+{
+ if (nextBufferVertex > 0) {
+ RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR);
+ RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempVertexBuffer, nextBufferVertex, TempBufferRenderIndexList, nextBufferIndex);
+ nextBufferVertex = 0;
+ nextBufferIndex = 0;
+ }
+} \ No newline at end of file