Ordering Tables

Post a topic about yourself to let others know your skills, hobbies, etc.
Post Reply
Pantofa
What is PSXDEV?
What is PSXDEV?
Posts: 2
Joined: Jun 08, 2024
PlayStation Model: SCPH-1002
Discord: therealpantofa
Location: usa

Ordering Tables

Post by Pantofa » November 1st, 2024, 11:21 am

Hello guys , i'm new to this forum. I'm trying to understand ordering tables , i know the general idea is just ordering z values in a linked list so that the farthest object is rendered first but what i don't understand in some code examples is the usage of double buffer ordering tables ??

Code: Select all

u_long OT[2][OTlen]
and why we use these

Code: Select all

long Otz;
long p;
long flag;char primbuff[2][32768];     // double primitive buffer of length 32768 * 8 =  262.144 bits / 32,768 Kbytes
char *nextpri = primbuff[0];       // pointer to the next primitive in primbuff. Initially, points to the first bit of primbuff[0]
....
...
...
        Otz = RotTransPers3(&Vertexpos[0],&Vertexpos[1],&Vertexpos[2],(long*)&f3->x0,(long*)&f3->x1,(long*)&f3->x2,&p,&flag);
        rotate.vz += 4;                              // Apply rotation on Z-axis. On PSX, the Z-axis is pointing away from the screen.  
        addPrim(OT[db][8], &f3);                    // add poly to the Ordering table
        nextpri += sizeof(POLY_F3);                     // increment nextpri address with size of a POLY_F4 struct 
if you want the whole code , i'm trying to make a flat triangle rotate around the z axis here is the code :

Code: Select all

#include <sys/types.h>
#include <stdio.h>
#include <libgte.h>
#include <libetc.h>
#include <libgpu.h>
#include <libapi.h>

#define VMODE 0
#define SCREENX 320
#define SCREENY 240
#define OTlen 9
int db;
DRAWENV drawenv[2];
DISPENV dispenv[2];
long printid1;
long printid2;
MATRIX transm;
char primbuff[2][32768];     // double primitive buffer of length 32768 * 8 =  262.144 bits / 32,768 Kbytes
char *nextpri = primbuff[0];       // pointer to the next primitive in primbuff. Initially, points to the first bit of primbuff[0]
SVECTOR rotate = {0,0,0};
SVECTOR Vertexpos[4];
u_long OT[2][OTlen];
long Otz;
long p;
long flag;
VECTOR  MovVector;
VECTOR  ScaleVector;
void init(){
    //RESET GPU AND ENABLE INTERRUPTS
    ResetGraph(VMODE);

    //SET DISP AND DRAW ENV

    SetDefDispEnv(&dispenv[0],0,0,SCREENX,SCREENY); //upper frame buffer
    SetDefDrawEnv(&drawenv[1],0,240,SCREENX,SCREENY); //bottom frame buffer

    SetDefDrawEnv(&drawenv[0],0,0,SCREENX,SCREENY);// upper frame buffer
    SetDefDispEnv(&dispenv[1],0,240,SCREENX,SCREENY); //upper frame buffer
    
    setRGB0(&drawenv[0], 49, 177, 255); // Set the first DRAWENV primitive's color
	setRGB0(&drawenv[1], 49, 177, 255); // Set the second "			
    drawenv[0].isbg = 1; 
	drawenv[1].isbg = 1;

    PutDispEnv(&dispenv[0]); // Set disp env for first time
    PutDrawEnv(&drawenv[0]); // Set draw env for first time

    db = 0;
    // initialize font and font cords in display 
    FntLoad(960,0);
    printid1 = FntOpen(10,200,100,100,0,100);
    printid2 = FntOpen(25,25,100,100,0,100);
}

void display(){
    DrawSync(0);
    VSync(0);

    PutDispEnv(&dispenv[db]);
    PutDrawEnv(&drawenv[db]);
    DrawOTag(&OT[db][OTlen - 1]);
    db = !db;
    nextpri = primbuff[db];
    SetDispMask(1);
}

int main(){
    POLY_F3 *f3;
    SetPolyF3(f3); /*initialize primitive*/
    setRGB0(f3, 0, 0, 255); /*R,G,B = 0, 0, 255*/
    Vertexpos[0] = (SVECTOR){f3->x0,f3->y0,0};
    Vertexpos[1] = (SVECTOR){f3->x1,f3->y1,0};
    Vertexpos[2] = (SVECTOR){f3->x2,f3->y2,0};
    MovVector.vx = 0;
    MovVector.vy = 0;
    MovVector.vz = 0;
    ScaleVector.vx = 0;
    ScaleVector.vy = 0;
    ScaleVector.vz = 0;
    init();
    setXY3(f3, SCREENX/2, SCREENY/2, 100, 0, 0, 100);
    while(1){
        f3 = (POLY_F3*)nextpri;
        ClearOTag(OT[db],OTlen);
        RotMatrix(&rotate,&transm);  
        TransMatrix(&transm, &MovVector);
        ScaleMatrix(&transm,&ScaleVector);
        SetTransMatrix(&transm);
        SetRotMatrix(&transm);
        if(VMODE==0){
        FntPrint(printid1,"NTSC MODE");
    }
    else{
        FntPrint(printid1,"PAL MODE");
    }
        Otz = RotTransPers3(&Vertexpos[0],&Vertexpos[1],&Vertexpos[2],(long*)&f3->x0,(long*)&f3->x1,(long*)&f3->x2,&p,&flag);
        rotate.vz += 4;                              // Apply rotation on Z-axis. On PSX, the Z-axis is pointing away from the screen.  
        addPrim(OT[db][8], &f3);                    // add poly to the Ordering table
        nextpri += sizeof(POLY_F3);                     // increment nextpri address with size of a POLY_F4 struct 
        FntPrint(printid2,"MADE BY ABDESSALAM");
        FntFlush(printid1);
        FntFlush(printid2);
        
        display();
    }

}
it would be really helpful , thanks in advance

User avatar
nocash
Verified
PSX Aficionado
PSX Aficionado
Posts: 614
Joined: Nov 12, 2012
Contact:

Post by nocash » November 1st, 2024, 12:31 pm

Using two tables allows the CPU to start updating the table for the next frame while the GPU is still busy with rendering the previous table. That gets you a higher framerate.

Alongsides, you do usually have two framebuffers, one being rendered to, and the other being displayed. That gets you a flicker-free picture, without incomplete half-drawn frames appearing on the screen.

Pantofa
What is PSXDEV?
What is PSXDEV?
Posts: 2
Joined: Jun 08, 2024
PlayStation Model: SCPH-1002
Discord: therealpantofa
Location: usa

Post by Pantofa » November 1st, 2024, 9:22 pm

nocash wrote: November 1st, 2024, 12:31 pm Using two tables allows the CPU to start updating the table for the next frame while the GPU is still busy with rendering the previous table. That gets you a higher framerate.

Alongsides, you do usually have two framebuffers, one being rendered to, and the other being displayed. That gets you a flicker-free picture, without incomplete half-drawn frames appearing on the screen.
oh i understand now . What about the other variables like primbuff Otz and nextpri what are they used for?

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests