 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Sarkins
Joined: 25 Jan 2008 Posts: 2
|
Posted: Sat Jan 26, 2008 7:55 am Post subject: Problem with gu cube sample |
|
|
I try to modify the cube code to make my own mesh code .
For the moment i try to copy the vertices tab in to an other tab and render it. With a normal tab it doesn't work may be the data is not aligned, how to work the code whith this solution.
I try with a dynamic tab (with memalign) and it doesn't work to, one face is not render correctly, i don't understand why ?
Thank for your help.
| Code: |
/*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* Copyright (c) 2005 Jesper Svennevid
*/
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <malloc.h>
#include <string.h>
#include <pspgu.h>
#include <pspgum.h>
#include "../common/callbacks.h"
#include "../common/vram.h"
PSP_MODULE_INFO("Cube Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
static unsigned int __attribute__((aligned(16))) list[262144];
extern unsigned char logo_start[];
typedef struct Vertex
{
float u, v;
unsigned int color;
float x,y,z;
}Vertex;
Vertex __attribute__((aligned(16))) vertices[12*3] =
{
{0, 0, 0xff7f0000,-1,-1, 1}, // 0
{1, 0, 0xff7f0000,-1, 1, 1}, // 4
{1, 1, 0xff7f0000, 1, 1, 1}, // 5
{0, 0, 0xff7f0000,-1,-1, 1}, // 0
{1, 1, 0xff7f0000, 1, 1, 1}, // 5
{0, 1, 0xff7f0000, 1,-1, 1}, // 1
{0, 0, 0xff7f0000,-1,-1,-1}, // 3
{1, 0, 0xff7f0000, 1,-1,-1}, // 2
{1, 1, 0xff7f0000, 1, 1,-1}, // 6
{0, 0, 0xff7f0000,-1,-1,-1}, // 3
{1, 1, 0xff7f0000, 1, 1,-1}, // 6
{0, 1, 0xff7f0000,-1, 1,-1}, // 7
{0, 0, 0xff007f00, 1,-1,-1}, // 0
{1, 0, 0xff007f00, 1,-1, 1}, // 3
{1, 1, 0xff007f00, 1, 1, 1}, // 7
{0, 0, 0xff007f00, 1,-1,-1}, // 0
{1, 1, 0xff007f00, 1, 1, 1}, // 7
{0, 1, 0xff007f00, 1, 1,-1}, // 4
{0, 0, 0xff007f00,-1,-1,-1}, // 0
{1, 0, 0xff007f00,-1, 1,-1}, // 3
{1, 1, 0xff007f00,-1, 1, 1}, // 7
{0, 0, 0xff007f00,-1,-1,-1}, // 0
{1, 1, 0xff007f00,-1, 1, 1}, // 7
{0, 1, 0xff007f00,-1,-1, 1}, // 4
{0, 0, 0xff00007f,-1, 1,-1}, // 0
{1, 0, 0xff00007f, 1, 1,-1}, // 1
{1, 1, 0xff00007f, 1, 1, 1}, // 2
{0, 0, 0xff00007f,-1, 1,-1}, // 0
{1, 1, 0xff00007f, 1, 1, 1}, // 2
{0, 1, 0xff00007f,-1, 1, 1}, // 3
{0, 0, 0xff00007f,-1,-1,-1}, // 4
{1, 0, 0xff00007f,-1,-1, 1}, // 7
{1, 1, 0xff00007f, 1,-1, 1}, // 6
{0, 0, 0xff00007f,-1,-1,-1}, // 4
{1, 1, 0xff00007f, 1,-1, 1}, // 6
{0, 1, 0xff00007f, 1,-1,-1}, // 5
};
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
int main(int argc, char* argv[])
{
int i;
//Vertex dataVertex[12*3];
Vertex *dataVertex = (Vertex *)memalign(16, 12*3 * sizeof(Vertex));
setupCallbacks();
// setup GU
void* fbp0 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
void* fbp1 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
void* zbp = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_4444);
sceGuInit();
sceGuStart(GU_DIRECT,list);
sceGuDrawBuffer(GU_PSM_8888,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);
sceGuDepthFunc(GU_GEQUAL);
sceGuEnable(GU_DEPTH_TEST);
sceGuFrontFace(GU_CW);
sceGuShadeModel(GU_SMOOTH);
sceGuEnable(GU_CULL_FACE);
sceGuEnable(GU_TEXTURE_2D);
sceGuEnable(GU_CLIP_PLANES);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(GU_TRUE);
// run sample
int val = 0;
for(i=0;i<12*3;i++){
dataVertex[i].u = vertices[i].u;
dataVertex[i].v = vertices[i].v;
dataVertex[i].color = vertices[i].color;
dataVertex[i].x = vertices[i].x;
dataVertex[i].y = vertices[i].y;
dataVertex[i].z = vertices[i].z;
}
while(running())
{
sceGuStart(GU_DIRECT,list);
// clear screen
sceGuClearColor(0xff554433);
sceGuClearDepth(0);
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
// setup matrices for cube
sceGumMatrixMode(GU_PROJECTION);
sceGumLoadIdentity();
sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);
sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();
sceGumMatrixMode(GU_MODEL);
sceGumLoadIdentity();
{
ScePspFVector3 pos = { 0, 0, -2.5f };
ScePspFVector3 rot = { val * 0.79f * (GU_PI/180.0f), val * 0.98f * (GU_PI/180.0f), val * 1.32f * (GU_PI/180.0f) };
sceGumTranslate(&pos);
sceGumRotateXYZ(&rot);
}
// setup texture
sceGuTexMode(GU_PSM_4444,0,0,0);
sceGuTexImage(0,64,64,64,logo_start);
sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGB);
sceGuTexEnvColor(0xffff00);
sceGuTexFilter(GU_LINEAR,GU_LINEAR);
sceGuTexScale(1.0f,1.0f);
sceGuTexOffset(0.0f,0.0f);
sceGuAmbientColor(0xffffffff);
// draw cube
//sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,vertices);
sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,dataVertex);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
val++;
}
free(dataVertex);
sceGuTerm();
sceKernelExitGame();
return 0;
}
|
makefile
| Code: |
TARGET = cube
OBJS = cube.o logo.o ../common/callbacks.o ../common/vram.o
INCDIR =
CFLAGS = -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS= -lpspgum -lpspgu -lm
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Cube Sample
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
logo.o: logo.raw
bin2o -i logo.raw logo.o logo
|
|
|
| Back to top |
|
 |
shadow_gg
Joined: 07 Oct 2005 Posts: 3 Location: Paris, France
|
Posted: Sat Jan 26, 2008 7:01 pm Post subject: |
|
|
Bcs the vertices of the face you don't see are not yet physically in the RAM, but still in the cache memory, so the GU didn't have the right data to draw.
You should invalidate the cache each time after you fill your dynamic array.
Me I'm using sceKernelDcacheWritebackAll();
Hope it helps
Cordially |
|
| Back to top |
|
 |
Sarkins
Joined: 25 Jan 2008 Posts: 2
|
Posted: Sun Jan 27, 2008 8:21 am Post subject: |
|
|
| Thank for your help with sceKernelDcacheWritebackAll(); my code work. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sun Jan 27, 2008 10:15 am Post subject: |
|
|
| Has anyone tried only flushing a range of the cache? I know on some processors, flushing the whole cache when you don't need to makes the program half the speed or worse. If you only need to flush 256 bytes (for example), why flush all the rest of the cache? |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Sun Jan 27, 2008 11:35 am Post subject: |
|
|
| J.F. wrote: | | Has anyone tried only flushing a range of the cache? I know on some processors, flushing the whole cache when you don't need to makes the program half the speed or worse. If you only need to flush 256 bytes (for example), why flush all the rest of the cache? |
I guess sceKernelDcacheWritebackRange(buffer, size) is the candidate to test, especially if you don't want to flush the stack for nothing |
|
| Back to top |
|
 |
shadow_gg
Joined: 07 Oct 2005 Posts: 3 Location: Paris, France
|
Posted: Tue Jan 29, 2008 7:49 am Post subject: |
|
|
Sarkins: you welcome
oh I didn't know there was also a function to flush a range of memory.
You definitely right, I'll try it :p
Thx |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Tue Jan 29, 2008 8:24 am Post subject: |
|
|
| shadow_gg wrote: | Sarkins: you welcome
oh I didn't know there was also a function to flush a range of memory.
You definitely right, I'll try it :p
Thx |
I don't know how much difference it would make on a simple cube test (probably none). It would need to be more substantial before you saw a difference... something that was pushing the PSP toward its limits. |
|
| 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
|