Code: Select all
#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 ?