Esempio n. 1
0
// These are GU commands that should always stay the same
inline void MasterGuRenderer::guPreRender() {
	DEBUG_ENTER_FUNC();

#ifdef USE_DISPLAY_CALLBACK
	_renderSema.take(); 		// Take the semaphore to prevent writes
								// to the palette/screen before we're done
	_renderFinished = false;	// set to synchronize with callback thread
#endif

#ifdef ENABLE_RENDER_MEASURE
	_lastRenderTime = g_system->getMillis();
#endif /* ENABLE_RENDER_MEASURE */

	sceGuStart(0, _displayList);

	sceGuClearColor(0xFF000000);
	sceGuClear(GU_COLOR_BUFFER_BIT);

	sceGuAmbientColor(0xFFFFFFFF);
	sceGuColor(0xFFFFFFFF);
	sceGuTexOffset(0, 0);
	sceGuTexFilter(GU_LINEAR, GU_LINEAR);

	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); // Also good enough for all purposes
	sceGuAlphaFunc(GU_GREATER, 0, 0xFF);	   // Also good enough for all purposes
}
Esempio n. 2
0
void psp_init(void)
{
	SceUID thid;
	char buff[128], *r;

	/* fw 1.5 sometimes returns 8002032c, although getcwd works */
	r = getcwd(buff, sizeof(buff));
	if (r) sceIoChdir(buff);

	main_thread_id = sceKernelGetThreadId();

	lprintf("running on %08x kernel\n", sceKernelDevkitVersion()),
	lprintf("entered psp_init, threadId %08x, priority %i\n", main_thread_id,
		sceKernelGetThreadCurrentPriority());

	thid = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, NULL);
	if (thid >= 0)
	{
		sceKernelStartThread(thid, 0, 0);
	}

	/* video */
	sceDisplaySetMode(0, 480, 272);
	sceDisplaySetFrameBuf(VRAM_FB1, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
	current_screen = 1;
	psp_screen = VRAM_FB0;

	/* gu */
	sceGuInit();

	sceGuStart(GU_DIRECT, guCmdList);
	sceGuDrawBuffer(GU_PSM_5650, (void *)VRAMOFFS_FB0, 512);
	sceGuDispBuffer(480, 272, (void *)VRAMOFFS_FB1, 512); // don't care
	sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
	sceGuDepthBuffer((void *)VRAMOFFS_DEPTH, 512);
	sceGuOffset(2048 - (480 / 2), 2048 - (272 / 2));
	sceGuViewport(2048, 2048, 480, 272);
	sceGuDepthRange(0xc350, 0x2710);
	sceGuScissor(0, 0, 480, 272);
	sceGuEnable(GU_SCISSOR_TEST);

	sceGuDepthMask(0xffff);
	sceGuDisable(GU_DEPTH_TEST);

	sceGuFrontFace(GU_CW);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
	sceGuAmbientColor(0xffffffff);
	sceGuColor(0xffffffff);
	sceGuFinish();
	sceGuSync(0, 0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);


	/* input */
	sceCtrlSetSamplingCycle(0);
	sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
}
Esempio n. 3
0
void pgeTextureActivate(pgeTexture *texture)
{		
	if(texture->format == PGE_PIXEL_FORMAT_T4)
	{
		sceGuClutMode(texture->palFormat, 0, 0xff, 0);
		sceGuClutLoad(2, texture->palette);
	}
	else if(texture->format == PGE_PIXEL_FORMAT_T8)
	{
		sceGuClutMode(texture->palFormat, 0, 0xff, 0);
		sceGuClutLoad(32, texture->palette);
	}

	sceGuEnable(GU_TEXTURE_2D);
	sceGuTexWrap(GU_REPEAT, GU_REPEAT);
	sceGuTexFilter(GU_NEAREST, GU_NEAREST);
	sceGuTexFunc(pgeTextureMode, GU_TCC_RGBA);
	sceGuTexEnvColor(0xFFFFFFFF);
	sceGuColor(0xFFFFFFFF);
	sceGuAmbientColor(0xFFFFFFFF);
	sceGuTexOffset(0.0f, 0.0f);
	sceGuTexScale(1.0f/(float)texture->textureWidth, 1.0f/(float)texture->textureHeight);

	sceGuTexMode(texture->format, 0, 0, texture->swizzled);
	sceGuTexImage(0, texture->textureWidth, texture->textureHeight, texture->textureWidth, texture->data);
}
Esempio n. 4
0
void drawCube( Texture* texture, int val )
{
    // setup matrices for cube

    sceGumMatrixMode(GU_PROJECTION);
    sceGumLoadIdentity();
    sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);

    sceGumMatrixMode(GU_VIEW);
    {
        ScePspFVector3 pos = {0.0f,0.0f,-2.5f};

        sceGumLoadIdentity();
        sceGumTranslate(&pos);
    }

    sceGumMatrixMode(GU_MODEL);
    {
        ScePspFVector3 rot = {val * 0.263f * (GU_PI/180.0f), val * 0.32f * (GU_PI/180.0f), val * 0.44f * (GU_PI/180.0f)};

        sceGumLoadIdentity();
        sceGumRotateXYZ(&rot);
    }

    // setup texture

    sceGuTexMode(texture->format,0,0,0);
    sceGuTexImage(texture->mipmap,texture->width,texture->height,texture->stride,texture->data);
    sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGB);
    sceGuTexFilter(GU_LINEAR,GU_LINEAR);
    sceGuTexScale(1.0f,1.0f);
    sceGuTexOffset(0.0f,0.0f);
    sceGuAmbientColor(0xffffffff);

    sceGuEnable(GU_TEXTURE_2D);

    // draw cube

    sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,cube_vertices);

    sceGuDisable(GU_TEXTURE_2D);
}
Esempio n. 5
0
void DrawTilePSP (uint32 Tile, uint32 Offset, uint32 StartLine,
      uint32 LineCount)
{
    TILE_PREAMBLE

    float x = Offset % GFX.Pitch;
    float y = Offset / GFX.Pitch;

#define X 0
#define Y 1

#define U 0
#define V 1

    float pos [3][4];
    float tex [2][4];

    static bool8 init = FALSE;

    if (init == FALSE) {
    sceGuStart(0,list);
    sceGuDrawBufferList(GE_PSM_5551,(void*)0,512);
    sceGuDispBuffer(480,272,(void*)0x88000,512);
    sceGuDepthBuffer((void*)0x110000,512);
    sceGuOffset(0,0);
    sceGuViewport(480/2,272/2,480,272);
    sceGuDepthRange(0xc350,0x2710);
    sceGuScissor(0,0,480,272);
    sceGuEnable(GU_STATE_SCISSOR);
    sceGuDisable(GU_STATE_ATE);
    sceGuDisable(GU_STATE_ZTE);
    sceGuEnable(GU_STATE_CULL);
    sceGuDisable(GU_STATE_ALPHA);
    sceGuDisable(GU_STATE_LIGHTING);
    sceGuFrontFace(GE_FACE_CW);
    sceGuEnable(GU_STATE_TEXTURE);
    sceGuClear(GE_CLEAR_COLOR|GE_CLEAR_DEPTH);
    sceGuFinish();
    sceGuSync(0,0);

    init = TRUE;
    }

    pos [0][X] = 0 + x * 1;
    pos [0][Y] = 0 + y * 1;
    pos [1][X] = 0 + (x + 8.0f) * 1;
    pos [1][Y] = 0 + y * 1;
    pos [2][X] = 0 + (x + 8.0f) * 1;
    pos [2][Y] = 0 + (y + LineCount) * 1;
    pos [3][X] = 0 + x * 1;
    pos [4][Y] = 0 + (y + LineCount) * 1;

    if (!(Tile & (V_FLIP | H_FLIP)))
    {
  // Normal
  tex [0][U] = 0.0f;
  tex [0][V] = StartLine;
  tex [1][U] = 8.0f;
  tex [1][V] = StartLine;
  tex [2][U] = 8.0f;
  tex [2][V] = StartLine + LineCount;
  tex [3][U] = 0.0f;
  tex [3][V] = StartLine + LineCount;
    }
    else
    if (!(Tile & V_FLIP))
    {
  // Flipped
  tex [0][U] = 8.0f;
  tex [0][V] = StartLine;
  tex [1][U] = 0.0f;
  tex [1][V] = StartLine;
  tex [2][U] = 0.0f;
  tex [2][V] = StartLine + LineCount;
  tex [3][U] = 8.0f;
  tex [3][V] = StartLine + LineCount;

    }
    else
    if (Tile & H_FLIP)
    {
  // Horizontal and vertical flip
  tex [0][U] = 8.0f;
  tex [0][V] = StartLine + LineCount;
  tex [1][U] = 0.0f;
  tex [1][V] = StartLine + LineCount;
  tex [2][U] = 0.0f;
  tex [2][V] = StartLine;
  tex [3][U] = 8.0f;
  tex [3][V] = StartLine;

    }
    else
    {
  // Vertical flip only
  tex [0][U] = 0.0f;
  tex [0][V] = StartLine + LineCount;
  tex [1][U] = 8.0f;
  tex [1][V] = StartLine + LineCount;
  tex [2][U] = 8.0f;
  tex [2][V] = StartLine;
  tex [3][U] = 0.0f;
  tex [3][V] = StartLine;

    }

    sceGuStart(0,list);

    sceGuTexMode(GU_PSM_5551,0,0,0);
    sceGuTexFunc(GU_TFX_REPLACE,0);
    sceGuTexOffset(0,0);
    sceGuAmbientColor(0xffffffff);


    sceGuTexImage (0, 8, 8, 8, (void *)pCache);
    sceGuTexScale (1.0/8.0f, 1.0f/8.0f);

    struct Vertex *vertices;
    vertices = (struct Vertex *)sceGuGetMemory (4 * sizeof (struct Vertex));

    vertices[0].u = tex[0][U]; vertices[0].v = tex[0][V];
    vertices[0].x = pos[0][X]; vertices[0].y = pos[0][Y]; vertices[0].z = 0.0f;
    vertices[1].u = tex[1][U]; vertices[1].v = tex[1][V];
    vertices[1].x = pos[1][X]; vertices[1].y = pos[1][Y]; vertices[1].z = 0.0f;
    vertices[2].u = tex[2][U]; vertices[2].v = tex[2][V];
    vertices[2].x = pos[2][X]; vertices[2].y = pos[2][Y]; vertices[2].z = 0.0f;
    vertices[3].u = tex[3][U]; vertices[3].v = tex[3][V];
    vertices[3].x = pos[3][X]; vertices[3].y = pos[3][Y]; vertices[3].z = 0.0f;

    sceGuDrawArray (GU_PRIM_TRIANGLES,GE_SETREG_VTYPE(GE_TT_16BIT,GE_CT_5551,0,GE_MT_16BIT,0,0,0,0,GE_BM_2D),4,0,vertices);

    sceGuFinish ();
}
Esempio n. 6
0
void S9xSceGURenderTex (char *tex, int width, int height, int x, int y, int xscale, int yscale, int xres, int yres)
{
  // If you don't call this, Gu will run into cache problems with
  // reading pixel data...
  sceKernelDcacheWritebackAll ();

  unsigned int j;

  const int slice_scale = ((float)xscale / (float)width) * (float)SLICE_SIZE;
  const int tex_filter  = (PSP_Settings.bBilinearFilter ? GU_LINEAR :
                                                              GU_NEAREST);

  struct Vertex* vertices;
  struct Vertex* vtx_iter;


  // If the x/y scale matches the width/height, we can take a shortcut and
  // merely copy tex into the VRAM at the given (x,y) coordinate.
  //
  //  NOTE: This disables bilinear filtering, but that's not saying a whole
  //        lot, since the image will not require a min / mag filter.
  if ((xscale == width) && (yscale == height)) {
    sceGuStart (0, SceGU.list);
      sceGuCopyImage (SceGU.pixel_format, 0, 0, xres, yres, width, tex, x, y,
                        SceGU.line_size,
                          (void *)(0x04000000 + (uint32)SceGU.vram_offset));
    sceGuFinish ();
  }

  // If the scale doesn't match the width/height, we have to perform a
  // special blit to stretch the image.
  else {
#ifdef SCEGU_DIRECT_COPY
    sceGuStart (0, SceGU.list);

      sceGuCopyImage (SceGU.pixel_format, 0, 0, width, height, width, tex, 0, 0,
                        SceGU.line_size,
                          (void *)(0x04000000 + (uint32)SceGU.vram_offset));
#endif

      sceGuStart (0, SceGU.list);

      sceGuTexMode      (SceGU.texture_format, 0, 0, 0);
#ifndef SCEGU_DIRECT_COPY
      sceGuTexImage     (0, width, height, width, tex);
#else
      sceGuTexImage     (0, width, height, SceGU.line_size, (void *)(0x04000000 + (uint32)SceGU.vram_offset));
#endif
      sceGuTexFunc      (GU_TFX_REPLACE, 0);
      sceGuTexFilter    (tex_filter, tex_filter);
      sceGuTexScale     (1, 1);
      sceGuTexOffset    (0, 0);
      sceGuAmbientColor (0xffffffff);

      sceGuScissor      (x, y, xres, yres);

#ifdef DRAW_SINGLE_BATCH
      // Allocate (memory map) the "vertex array" beforehand
      const int num_verts = (width / SLICE_SIZE) * 2;
      const int vtx_alloc = num_verts * sizeof (struct Vertex);
                 vertices = (struct Vertex *)sceGuGetMemory (vtx_alloc);
                 vtx_iter = vertices;
#endif

      // Do a striped blit (takes the page-cache into account)
      for (j = 0; j < width; j += SLICE_SIZE, x += slice_scale)
      {
#ifndef DRAW_SINGLE_BATCH
        vtx_iter = (struct Vertex *)sceGuGetMemory (sizeof (struct Vertex) * 2);
#endif
        vtx_iter [0].u = j;                 vtx_iter [0].v = 0;
        vtx_iter [0].x = x;                 vtx_iter [0].y = y;            vtx_iter [0].z = 0;
        vtx_iter [1].u = (j + SLICE_SIZE);  vtx_iter [1].v = height;
        vtx_iter [1].x = (x + slice_scale); vtx_iter [1].y = (y + yscale); vtx_iter [1].z = 0;

        vtx_iter [0].color = vtx_iter [1].color = 0;

#ifndef DRAW_SINGLE_BATCH
			  sceGuDrawArray (GU_SPRITES, SceGU.tt | SceGU.ct | SceGU.mt | SceGU.dm, 2, 0, vtx_iter);
        vtx_iter += 2;
#endif
      }

#ifdef DRAW_SINGLE_BATCH
      sceGuDrawArray (GU_SPRITES, GE_SETREG_VTYPE (SceGU.tt,
                                                   SceGU.ct,
                                                   0,
                                                   SceGU.mt,
                                                   0, 0, 0, 0,
                                                   SceGU.dm),
                                            num_verts,
                                               0,
                                            vertices);
#endif
    sceGuFinish ();
  }

#ifdef SCEGU_DOUBLE_BUFFERED
  sceGuSync   (0, 0);

  if (PSP_Settings.bVSync)
    sceDisplayWaitVblankStart ();
#endif

#ifdef SCEGU_DOUBLE_BUFFERED
  S9xSceGUSwapBuffers ();
#endif
}
Esempio n. 7
0
int main(int argc, char* argv[])
{
	unsigned int i,j;

	pspDebugScreenInit();
	SetupCallbacks();

#ifdef ENABLE_PROFILER
	// Enable profiling 
	pspDebugProfilerClear();
	pspDebugProfilerEnable();
#endif

	// initialize global context
	g_context.iterationCount = NUM_VERTEX_BUFFERS * NUM_ITERATIONS;
	g_context.t = 0;
	g_context.sint = 0;

	// initialize torus
	for (i = 0; i < NUM_SLICES; ++i)
	{
		for (j = 0; j < NUM_ROWS; ++j)
		{
			float s = i + 0.5f, t = j;
			float x,y,z;

			x = (RING_SIZE + RING_RADIUS * cosf(s * ((GU_PI*2)/NUM_SLICES))) * cosf(t * ((GU_PI*2)/NUM_ROWS));
			y = (RING_SIZE + RING_RADIUS * cosf(s * ((GU_PI*2)/NUM_SLICES))) * sinf(t * ((GU_PI*2)/NUM_ROWS));
			z = RING_RADIUS * sinf(s * ((GU_PI*2)/NUM_SLICES));

			torus_vertices[j + i * NUM_ROWS].x = x;
			torus_vertices[j + i * NUM_ROWS].y = y;
			torus_vertices[j + i * NUM_ROWS].z = z;
		}
	}

	// initialize torus modifiers

	for (j = 0; j < NUM_ROWS; ++j)
	{
		float t = j;
		torus_modifiers[j].x = 0;
		torus_modifiers[j].y = 0;
		torus_modifiers[j].z = 0.3*cosf( t * 8.0f *((GU_PI*2)/NUM_ROWS) );
	}

	// init GU and set callbacks
	sceGuInit();

	// 0x01 - user callback
	// 0x04 - 'rendering finished' callback
	sceGuSetCallback(1, &mySignalHandler);
	sceGuSetCallback(4, &myFinishHandler);

	// setup GU
	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_8888,(void*)0,BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)0x88000,BUF_WIDTH);
	sceGuDepthBuffer((void*)0x110000,BUF_WIDTH);
	sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
	sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
	sceGuDepthRange(0xc350,0x2710);
	sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuAlphaFunc(GU_GREATER,0,0xff);
	sceGuEnable(GU_ALPHA_TEST);
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuFrontFace(GU_CW);
	sceGuShadeModel(GU_SMOOTH);
	sceGuEnable(GU_CULL_FACE);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);

	// run sample

#ifdef USING_SIGNALS
	sceGuCallMode(1);
#endif

	// generate callable command-list with texture setup
	{
		sceGuStart(GU_CALL, smallList1);

		// setup texture
		sceGuTexMode(GU_PSM_5551,0,0,0);
		sceGuTexImage(0,32,32,32,ball_start); // width, height, buffer width, tbp
		sceGuTexFunc(GU_TFX_MODULATE,GU_TCC_RGBA); // NOTE: this enables reads of the alpha-component from the texture, otherwise blend/test won't work
		sceGuTexFilter(GU_NEAREST,GU_NEAREST);
		sceGuTexWrap(GU_CLAMP,GU_CLAMP);
		sceGuTexScale(1,1);
		sceGuTexOffset(0,0);
		sceGuAmbientColor(0xffffffff);

		sceGuFinish();
		sceGuSync(0,0);
	}

	// generate callable command-list for cube rendering
	{
		sceGuStart(GU_CALL, smallList2);

		// draw cube
		sceGuDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,cubeVertices);

		sceGuFinish();
		sceGuSync(0,0);
	}

	for(;;)
	{
		sceGuStart(GU_DIRECT,list);

		unsigned int i = 0;
		for( ; i < NUM_VERTEX_BUFFERS; i++ )
			g_context.vbuffer[i] = sceGuGetMemory((NUM_SLICES/g_context.iterationCount) * 2 * NUM_ROWS * sizeof(Vertex));
		g_context.vertsRendered = 0;

		// clear screen
		sceGuClearColor(0x00334455);
		sceGuClearDepth(0);
		sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

		// setup matrices
		sceGumMatrixMode(GU_PROJECTION);
		sceGumLoadIdentity();
		sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);

		sceGumMatrixMode(GU_VIEW);
		sceGumLoadIdentity();

		sceGumMatrixMode(GU_MODEL);
		{
			ScePspFVector3 pos = {0.0f,0.0f,-3.5f};
			ScePspFVector3 rot = {g_context.t * 0.3f * (GU_PI/180.0f), g_context.t * 0.7f * (GU_PI/180.0f), g_context.t * 1.3f * (GU_PI/180.0f)};

			sceGumLoadIdentity();
			sceGumTranslate(&pos);
			sceGumRotateXYZ(&rot);
		}

		sceGumStoreMatrix(&g_context.world);

		// call pregenerated command-list to setup texture		
		sceGuCallList(smallList1);

		// start billboard rendering
		render_billboards(0);

		// call pregenerated command-list to render cube
		{
			ScePspFVector3 scale = {0.3f, 0.3f, 0.3f};
			sceGumScale(&scale);
		}

		sceGumUpdateMatrix();
		sceGuCallList(smallList2);	

#ifndef USING_SIGNALS
		// HACK: sceGuFinish() is called inside the signal interupt handler when all rendering job is done
		// this is done in order to stall GPU if it is ahead of CPU
		sceGuFinish();
#endif
		sceGuSync(0,0);

#ifndef ENABLE_FRAMERATE
		// wait for next frame
		sceDisplayWaitVblankStart();
#endif
		sceGuSwapBuffers();

		pspDebugScreenSetXY(0,0);

#ifdef ENABLE_PROFILER
		// Print profile information to the screen
		pspDebugProfilerPrint();
#endif

#ifdef ENABLE_FRAMERATE
		// simple frame rate counter
		static float curr_ms = 1.0f;
		static struct timeval time_slices[16];
		static int t = 0;

		float curr_fps = 1.0f / curr_ms;

		t++;
		
		float vertsPerSec = g_context.vertsRendered*curr_fps;
		float kbPerSec = vertsPerSec * sizeof(Vertex) / 1024.0f;
		gettimeofday(&time_slices[t & 15],0);
		pspDebugScreenPrintf("fps: %d.%03d  ms: %d  vert/s: %dK  MB/s: %d.%03d",(int)curr_fps, ((int)(curr_fps*1000.0f)%1000), (int)(curr_ms*1000.0f),
			(int)(vertsPerSec/1000.0f),
			(int)(kbPerSec/1024.0f), (int)((1000.0f/1024.0f)*((int)kbPerSec%1024)) );

		if (!(t & 15))
		{
			struct timeval last_time = time_slices[0];
			unsigned int i;

			curr_ms = 0;
			for (i = 1; i < 16; ++i)
			{
				struct timeval curr_time = time_slices[i];

				int curr_time_usec = curr_time.tv_usec + curr_time.tv_sec * 1000000;
				int last_time_usec = last_time.tv_usec + last_time.tv_sec * 1000000;

				if( last_time_usec < curr_time_usec )
					curr_ms += (( curr_time_usec - last_time_usec ) * (1.0f/1000000.0f));

				last_time = time_slices[i];
			}
			curr_ms /= 15.0f;
		}
#endif
	}

	sceGuTerm();

	sceKernelExitGame();
	return 0;
}
Esempio n. 8
0
int main(int argc, char* argv[]) {
	/* Setup Homebutton Callbacks */
	setupCallbacks();

	sceKernelDcacheWritebackAll();

	// setup GU

	SceCtrlData pad;
    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);

	sceGuInit();

	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_8888,(void*)0,BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)0x88000,BUF_WIDTH);
	sceGuDepthBuffer((void*)0x110000,BUF_WIDTH);
	sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
	sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
	sceGuDepthRange(0xc350,0x2710);
	sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuFrontFace(GU_CCW);
	sceGuColor(0xffffffff);
	sceGuShadeModel(GU_SMOOTH);
//	sceGuEnable(GU_CULL_FACE);
	sceGuEnable(GU_CLIP_PLANES);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuTexMode(GU_PSM_8888, 0, 0, 0);
	sceGuTexImage(0, 16, 16, 16, texture);
	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
	sceGuTexEnvColor(0xffffff);
	sceGuTexFilter(GU_LINEAR, GU_LINEAR);
	sceGuTexWrap(GU_REPEAT, GU_REPEAT);
	sceGuTexScale(1.0f, 1.0f);
	sceGuTexOffset(0.0f, 0.0f);
	sceGuAmbientColor(0xffffffff);

	sceGuFinish();
	sceGuSync(0,0);
	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);
	
	void* buffer = 0;

	pspDebugScreenInit();

	unsigned int old = 0;
	unsigned int flags = PSP_CTRL_CIRCLE | PSP_CTRL_CROSS;

	int tex = 1;

	while(running()) {
		sceGuStart(GU_DIRECT,list);

		sceGuClearColor(0);
		sceGuClearDepth(0);
		sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);

		sceGumMatrixMode(GU_PROJECTION);
		sceGumLoadIdentity();
		sceGumPerspective(90.0f, 480.0/272.0f, 0.1f, 10.0f);

		sceGumMatrixMode(GU_VIEW);
		sceGumLoadIdentity();
		ScePspFVector3 trans = { 0.0f, 0.0f, -1.8f };
		sceGumTranslate(&trans);
		
		sceGumMatrixMode(GU_MODEL);
		sceGumLoadIdentity();

		sceGumDrawArray(objects[o].prim, objects[o].flags, objects[o].count, 0, objects[o].data);

		sceCtrlReadBufferPositive(&pad, 1);
		if(old != pad.Buttons) {
			if(pad.Buttons & PSP_CTRL_CROSS) {
				o++;
				if(o >= sizeof(objects) / sizeof(Object)) {
					o = 0;
				}
			}
			if(pad.Buttons & PSP_CTRL_CIRCLE) {
				tex = !tex;
				if(tex) {
					sceGuEnable(GU_TEXTURE_2D);
				} else {
					sceGuDisable(GU_TEXTURE_2D);
				}
			}
		}
		old = pad.Buttons;

		sceGuFinish();
		sceGuSync(0,0);

		pspDebugScreenSetOffset((int)buffer);
		pspDebugScreenSetXY(0, 0);
		pspDebugScreenPrintf("Mode: %s (X to change)    Texture: %s (O to change)", objects[o].text, tex ? "on " : "off");

		sceDisplayWaitVblankStart();
		buffer = sceGuSwapBuffers();
	}

	sceGuTerm();

	sceKernelExitGame();
	return 0;
}
Esempio n. 9
0
int main(int argc, char* argv[])
{
	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(0xc350,0x2710);
	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_CLIP_PLANES);
	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);

	setupSH();
	indicesSH();

	// run sample

	int val = 0;

	while(running())
	{
		sceGuStart(GU_DIRECT,list);

		// clear screen

		sceGuClearColor(0x000000);
		sceGuClearDepth(0);
		sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

		// light settings

		sceGuEnable(GU_LIGHTING);
		sceGuEnable(GU_LIGHT0);
		sceGuEnable(GU_LIGHT1);
		sceGuEnable(GU_LIGHT2);
		sceGuLightMode(1);
		{
			unsigned int i;

			for (i = 0; i < 3; ++i)
			{
				sceGuLight(i,GU_DIRECTIONAL,GU_DIFFUSE_AND_SPECULAR,&lsettings[i].position);
				sceGuLightColor(i,GU_DIFFUSE,lsettings[i].diffuse);
				sceGuLightColor(i,GU_SPECULAR,lsettings[i].specular);
				sceGuLightAtt(i,0.0f,1.0f,0.0f);
			}
			sceGuSpecular(12.0f);
			sceGuAmbient(0x000000);
		}

		// setup matrices

		sceGumMatrixMode(GU_PROJECTION);
		sceGumLoadIdentity();
		sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);

		sceGumMatrixMode(GU_VIEW);
		{
			ScePspFVector3 pos = { 0, 0, -5.0f };

			sceGumLoadIdentity();
			sceGumTranslate(&pos);
		}

		sceGumMatrixMode(GU_MODEL);
		sceGumLoadIdentity();
		{
			ScePspFVector3 rot = { val * 0.79f * (GU_PI/180.0f), val * 0.98f * (GU_PI/180.0f), val * 1.32f * (GU_PI/180.0f) };
			sceGumRotateXYZ(&rot);
		}

		// setup texture

		sceGuAmbientColor(0xffffffff);

		// draw

		renderSH(parametersSH);

		sceGuFinish();
		sceGuSync(0,0);

		sceDisplayWaitVblankStart();
		sceGuSwapBuffers();

		val++;

		if ((val%600) == 0)
		{
			unsigned int i;
			for (i = 0; i < 8; ++i)
				parametersSH[i] = (int)((rand() / ((float)RAND_MAX)) * 6.0f);
		}
	}

	sceGuTerm();

	sceKernelExitGame();
	return 0;
}
Esempio n. 10
0
//--------------------------------------------------------------------
// Función:    CParticles::Update
// Creador:    Nacho (AMD)
// Fecha:      Wednesday  14/02/2007  19:48:41
//--------------------------------------------------------------------
void CParticles::Update(float dt, CLevel* pTheLevel, CSound* pSoundPlayer)
{	
	CVideo * pVideo = CVideo::GetSingleton();

	m_fAngType3 += (240.0f * dt);
	m_fAngType3 = MAT_NormalizarAngulo360(m_fAngType3);

	CBall* pBall = pTheLevel->GetBall();
	CSmoke* pSmoke = pTheLevel->GetSmoke();

	VECTOR3 vecBallPos = pBall->GetPosition();
	VECTOR2 vecBallVel = pBall->GetVelocity();
	float fBallRadius = pBall->GetRadius();

	sceGuEnable(GU_BLEND);
	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
	sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);

	ENEMY* pEnemies = pTheLevel->GetEnemies();
	int iNumEnemies = pTheLevel->GetNumEnemies();
	
	///--- TIPO 0: Disparo amarillo
	//////////////////////////////////////////////////////////////////////

	pVideo->EnableTexture(m_pTexture[0]);

	for (int i=0; i<MAX_PARTICLES; i++)
	{
		if (m_pParticleArray[0][i].enable)
		{			
			m_pParticleArray[0][i].timeStamp += dt;

			if (m_pParticleArray[0][i].timeStamp >= 5.0f)
			{
				m_pParticleArray[0][i].enable = false;
				m_pParticleArray[0][i].next = m_iFreeSlot[0];
				m_iFreeSlot[0] = i;

				continue;
			}

			m_pParticleArray[0][i].pos.x += m_pParticleArray[0][i].vel.x * dt;
			m_pParticleArray[0][i].pos.y += m_pParticleArray[0][i].vel.y * dt;


			stCollisionData data;

			data.radius = 1.0f;
			data.x = m_pParticleArray[0][i].pos.x;
			data.y = m_pParticleArray[0][i].pos.y;
			data.velX = m_pParticleArray[0][i].vel.x;
			data.velY = m_pParticleArray[0][i].vel.y;

			if (pTheLevel->TestCollision(&data, false))
			{		
				m_pParticleArray[0][i].pos.x = data.x;
				m_pParticleArray[0][i].pos.y = data.y;
				m_pParticleArray[0][i].vel.x = data.velX;
				m_pParticleArray[0][i].vel.y = data.velY;
			}

			for (int a=0; a<iNumEnemies; a++)
			{
				if (pEnemies[a].active)
				{					
					///--- sierra
					///--- rebota
					if ((pEnemies[a].type == 0) || (pEnemies[a].type == 3))
					{
						VECTOR3 vDis;
						VECTOR3 vTemp = {m_pParticleArray[0][i].pos.x, m_pParticleArray[0][i].pos.y, 4.0f};
						VECTOR3 vTemp2 = {pEnemies[a].posX + 4.0f, pEnemies[a].posY + 4.0f, 4.0f};

						MAT_VectorSubtract(&vDis, &vTemp2, &vTemp);

						float length = MAT_VectorQuadraticLength(&vDis);

						if (length < 6.25f)
						{
							m_pParticleArray[0][i].enable = false;
							m_pParticleArray[0][i].next = m_iFreeSlot[0];
							m_iFreeSlot[0] = i;

							pSmoke->AddExplosion(vTemp2, 20.0f, true);

							pEnemies[a].active = false;

							pSoundPlayer->Play(SOUND_ENE_EXPLO);

							break;
						}
					}
					///--- dirigidos
					///--- rectos
					else if ((pEnemies[a].type == 1) || (pEnemies[a].type == 2))
					{	
						VECTOR3 vTemp = {0};

						if (pEnemies[a].rot==0)
						{
							vTemp.x = pEnemies[a].posX+2.0f;
							vTemp.y = pEnemies[a].posY+4.0f;
						}						
						else if (pEnemies[a].rot==3)
						{
							vTemp.x = pEnemies[a].posX+4.0f;
							vTemp.y = pEnemies[a].posY+2.0f;
						}
						else if (pEnemies[a].rot==2)
						{
							vTemp.x = pEnemies[a].posX+6.0f;
							vTemp.y = pEnemies[a].posY+4.0f;
						}
						else if (pEnemies[a].rot==1)
						{
							vTemp.x = pEnemies[a].posX+4.0f;
							vTemp.y = pEnemies[a].posY+6.0f;						
						}	

						vTemp.z = 4.0f;

						VECTOR3 vDis;
						VECTOR3 vTemp2 = {m_pParticleArray[0][i].pos.x, m_pParticleArray[0][i].pos.y, 4.0f};
						
						MAT_VectorSubtract(&vDis, &vTemp, &vTemp2);

						float disx = vecBallPos.x - m_pParticleArray[0][i].pos.x,;

						float length = MAT_VectorQuadraticLength(&vDis);

						if (length < 6.0f)
						{
							m_pParticleArray[0][i].enable = false;
							m_pParticleArray[0][i].next = m_iFreeSlot[0];
							m_iFreeSlot[0] = i;

							pSmoke->AddExplosion(vTemp, 20.0f, true);

							pEnemies[a].active = false;

							pSoundPlayer->Play(SOUND_ENE_EXPLO);

							int pan = 127;

							if (disx < 0.0f)
							{
								if (disx < -32.0f)
								{
									pan = 255;
								}
								else
								{
									pan = MAT_Clamp(128 + (int)(((-disx) / 32.0f) * 127.0f), 128, 255);									
								}
							}
							else

							{
								if (disx > 32.0f)
								{
									pan = 0;
								}
								else
								{ 
									pan = MAT_Clamp((int)(127.0f - ((disx / 32.0f) * 127.0f)), 0, 127);
								}
							}

							pSoundPlayer->Play(SOUND_ENE_EXPLO, pan);

							break;
						}						
					}				
				}
			}

			if (!m_pParticleArray[0][i].enable)
				continue;

			///--- render

			sceGumMatrixMode(GU_MODEL);
			sceGumLoadIdentity();
			{
				VECTOR3 pos =  { m_pParticleArray[0][i].pos.x -1.0f,
					-(m_pParticleArray[0][i].pos.y + 1.0f), 4.0f };
				VECTOR3 scale = { 2.0f, 2.0f, 2.0f };
				sceGumTranslate(&pos);
				sceGumScale(&scale);			
			}			

			if (m_pParticleArray[0][i].timeStamp >= 4.0f)
			{
				int alpha = (int)MAT_Clampf((5.0f - m_pParticleArray[0][i].timeStamp) * 255.0f, 0.0f, 255.0f);

				sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);

				sceGuAmbientColor(COLOR_ARGB(alpha, 255, 255, 255));

				m_pQuad->Render();

				sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, COLOR_ARGB(alpha, alpha, alpha, alpha), 0xffffffff);

				m_pQuad->Render();

				sceGuAmbientColor(0xffffffff);
			}
			else
			{
				sceGuAmbientColor(0xffffffff);

				m_pQuad->Render();

				sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xffffffff, 0xffffffff);

				m_pQuad->Render();
			}

			sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);			
		}