 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
pegasus2000
Joined: 12 Jul 2006 Posts: 160
|
Posted: Mon Aug 04, 2008 2:47 am Post subject: GU troubles #1 |
|
|
For all users that are experts of PSP GU. Please see this code:
| Code: | #define ND_NO_INITIAL_MINWINDOWSBAR
#include <nanodesktop.h>
void *fbp0, *fbp1, *zbp;
extern unsigned int __attribute__((aligned(16))) ndlist[262144];
char ndGFXRenderingInProgress = 0;
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
static unsigned int staticOffset = 0;
static unsigned int getMemorySize(unsigned int width, unsigned int height, unsigned int psm)
{
switch (psm)
{
case GU_PSM_T4:
return (width * height) >> 1;
case GU_PSM_T8:
return width * height;
case GU_PSM_5650:
case GU_PSM_5551:
case GU_PSM_4444:
case GU_PSM_T16:
return 2 * width * height;
case GU_PSM_8888:
case GU_PSM_T32:
return 4 * width * height;
default:
return 0;
}
}
void* getStaticVramBuffer(unsigned int width, unsigned int height, unsigned int psm)
{
unsigned int memSize = getMemorySize(width,height,psm);
void* result = (void*)staticOffset;
staticOffset += memSize;
return result;
}
void* getStaticVramTexture(unsigned int width, unsigned int height, unsigned int psm)
{
void* result = getStaticVramBuffer(width,height,psm);
return (void*)(((unsigned int)result) + ((unsigned int)sceGeEdramGetAddr()));
}
struct Vertex
{
float x,y,z;
};
struct Vertex __attribute__((aligned(16))) vertices [1];
int ndHAL_EnableGFXEngine ()
{
// setup GU
fbp0 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_5551);
fbp1 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_5551);
zbp = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_4444);
sceGuInit();
sceGuStart(GU_DIRECT,ndlist);
sceGuDrawBuffer(GU_PSM_5551,fbp0,BUF_WIDTH);
sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,fbp1,BUF_WIDTH);
sceGuDepthBuffer(zbp,BUF_WIDTH);
sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
sceGuDepthRange(65535,0);
sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
sceGuEnable(GU_SCISSOR_TEST);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(GU_TRUE);
ndGFXRenderingInProgress=0;
}
int ndHAL_TerminateGFXEngine ()
{
sceGuTerm();
}
int ndGFX_ClearScreen ()
{
sceGuClearColor(0);
sceGuClear(GU_COLOR_BUFFER_BIT);
}
inline void ndGFX_BeginRender ()
{
if (!ndGFXRenderingInProgress)
{
sceGuStart(GU_DIRECT,ndlist);
ndGFXRenderingInProgress=1;
}
}
inline void ndGFX_CompleteRender ()
{
if (ndGFXRenderingInProgress)
{
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
ndGFXRenderingInProgress=0;
}
}
int ndGFX_DrawPixel (short int PosX, short int PosY, short int PosZ, TypeColor Color, char RenderNow)
{
if (RenderNow) ndGFX_BeginRender();
sceGuColor(0xFFFFFFFF);
vertices [0].x = PosX;
vertices [0].y = PosY;
vertices [0].z = PosZ;
sceGuDrawArray(GU_POINTS,GU_VERTEX_32BITF|GU_TRANSFORM_2D,1,0,vertices);
if (RenderNow) ndGFX_CompleteRender ();
}
int ndMain ()
{
ndInitSystem ();
ndHAL_EnableGFXEngine ();
ndGFX_ClearScreen ();
int Counter;
for (Counter=0; Counter<100; Counter++)
{
ndGFX_DrawPixel (Counter, 50, 0, COLOR_WHITE, 1);
}
} |
I'm expecting a single orizzontal line of the screen.
Instead, the system gives me a set of **separated** points.
Why ?
A second thing. It seems that GU is a 3d engine only, so all pixel
has always 3 dimensions-coordinates (x,y,z). Am I wrong ?
There isn't a 2D mode in PSP-GU ? |
|
| Back to top |
|
 |
a_noob
Joined: 17 Sep 2006 Posts: 97 Location: _start: jr 0xDEADBEEF
|
Posted: Mon Aug 04, 2008 6:09 am Post subject: |
|
|
the GU is plenty capable of 2D, but yes draw array must always contain z. (this is due to how the GE works)
For drawing a line you should create 2 points, and use the GU_LINES primitive, as it is much faster than drawing each pixel. Also I may be wrong but the if(RenderNow) may be causing the problem.
Also it is a big mistake to open and close a GU display list every time you render, this causes alot of unneccasary over head. Rather open a display list call all renderings, then close it.
also in the ndGFX_BeginRender the if (ndGFXRenderingInPRogress) is more than likely what is causing the pixel skips as the GU/GE isnt completely in sync with the CPU, so the overhead caused by opening and closing , along with the CPU telling to render things while it is still trying to complete another list is what is causing your pixel drop.
heres the fixed code
| Code: |
#define ND_NO_INITIAL_MINWINDOWSBAR
#include <nanodesktop.h>
void *fbp0, *fbp1, *zbp;
extern unsigned int __attribute__((aligned(16))) ndlist[262144];
char ndGFXRenderingInProgress = 0;
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
static unsigned int staticOffset = 0;
static unsigned int getMemorySize(unsigned int width, unsigned int height, unsigned int psm)
{
switch (psm)
{
case GU_PSM_T4:
return (width * height) >> 1;
case GU_PSM_T8:
return width * height;
case GU_PSM_5650:
case GU_PSM_5551:
case GU_PSM_4444:
case GU_PSM_T16:
return 2 * width * height;
case GU_PSM_8888:
case GU_PSM_T32:
return 4 * width * height;
default:
return 0;
}
}
void* getStaticVramBuffer(unsigned int width, unsigned int height, unsigned int psm)
{
unsigned int memSize = getMemorySize(width,height,psm);
void* result = (void*)staticOffset;
staticOffset += memSize;
return result;
}
void* getStaticVramTexture(unsigned int width, unsigned int height, unsigned int psm)
{
void* result = getStaticVramBuffer(width,height,psm);
return (void*)(((unsigned int)result) + ((unsigned int)sceGeEdramGetAddr()));
}
struct Vertex
{
float x,y,z;
};
struct Vertex __attribute__((aligned(16))) vertices [2];
int ndHAL_EnableGFXEngine ()
{
// setup GU
fbp0 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_5551);
fbp1 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_5551);
zbp = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_4444);
sceGuInit();
sceGuStart(GU_DIRECT,ndlist);
sceGuDrawBuffer(GU_PSM_5551,fbp0,BUF_WIDTH);
sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,fbp1,BUF_WIDTH);
sceGuDepthBuffer(zbp,BUF_WIDTH);
sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
sceGuDepthRange(65535,0);
sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
sceGuEnable(GU_SCISSOR_TEST);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(GU_TRUE);
ndGFXRenderingInProgress=0;
}
int ndHAL_TerminateGFXEngine ()
{
sceGuTerm();
}
int ndGFX_ClearScreen ()
{
sceGuClearColor(0);
sceGuClear(GU_COLOR_BUFFER_BIT);
}
inline void ndGFX_BeginRender ()
{
sceGuStart(GU_DIRECT,ndlist);
}
inline void ndGFX_CompleteRender ()
{
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
}
int ndGFX_DrawPixel (short int PosX, short int PosY, short int PosZ, TypeColor Color, char RenderNow)
{
sceGuColor(0xFFFFFFFF);
vertices [0].x = PosX;
vertices [0].y = PosY;
vertices [0].z = PosZ;
sceGuDrawArray(GU_POINTS,GU_VERTEX_32BITF|GU_TRANSFORM_2D,1,0,vertices);
}
int ndGFX_DrawLine (short int PosX, short int PosY, short int PosZ, short int Pos2X, short int Pos2Y, short int Pos2Z, TypeColor Color, char RenderNow)
{
sceGuColor(0xFFFFFFFF);
vertices [0].x = PosX;
vertices [0].y = PosY;
vertices [0].z = PosZ;
vertices [1].x = Pos2X;
vertices [1].y = Pos2Y;
vertices [1].z = Pos2Z;
sceGuDrawArray(GU_LINES,GU_VERTEX_32BITF|GU_TRANSFORM_2D,2,0,vertices);
}
int ndMain ()
{
ndInitSystem ();
ndHAL_EnableGFXEngine ();
ndGFX_ClearScreen ();
int Counter;
ndGFX_BeginRender();
// per pixel render
for (Counter=0; Counter<100; Counter++)
{
ndGFX_DrawPixel (Counter, 50, 0, COLOR_WHITE, 1);
}
//line render
ndGFX_DrawLine (0,126,0, 480,126,0, COLOR_WHITE, 1);
ndGFX_CompleteRender();
}
|
_________________
| Code: | .øOº'ºOø.
'ºOo.oOº' |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|