Skip to content

Commit

Permalink
Texture should be loaded. I'd test it but the ps3 is all the way in t…
Browse files Browse the repository at this point in the history
…he lounge.
  • Loading branch information
phire committed Nov 16, 2010
1 parent dc68c65 commit 500bec4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion samples/rsxTest/Makefile
Expand Up @@ -10,7 +10,7 @@ BUILD := build
SOURCE := source
INCLUDE := include
DATA := data
LIBS := -lgcm_sys -lreality -lsysutil -lio -lm -lpngdec
LIBS := -lgcm_sys -lreality -lsysutil -lio -lm -lpngdec -lsysmodule

TITLE := Template - PSL1GHT
APPID := TEST00003
Expand Down
4 changes: 4 additions & 0 deletions samples/rsxTest/include/texture.h
@@ -0,0 +1,4 @@
#pragma once

// Simple Texure loading function, to hide uglyness
realityTexture *loadTexture(const uint8_t *pngData);
46 changes: 37 additions & 9 deletions samples/rsxTest/source/main.c
@@ -1,7 +1,3 @@
/* Now double buffered with animation.
*/

#include <psl1ght/lv2.h>

#include <stdio.h>
#include <malloc.h>
Expand All @@ -17,15 +13,22 @@

#include <io/pad.h>

#include <psl1ght/lv2.h>
#include <sysmodule/sysmodule.h>

#include "ball.bin.h"
#include "texture.h"

gcmContextData *context; // Context to keep track of the RSX buffer.

VideoResolution res; // Screen Resolution

int currentBuffer = 0;
s32 *buffer[2]; // The buffer we will be drawing into
u32 *buffer[2]; // The buffer we will be drawing into
u32 offset[2]; // The offset of the buffers in RSX memory
u32 *depth_buffer; // Depth buffer. We aren't using it but the ps3 crashes if we don't have it
realityTexture *ball; // Texture.


int pitch;

void waitFlip() { // Block the PPU thread untill the previous flip operation has finished.
Expand Down Expand Up @@ -58,6 +61,7 @@ void init_screen() {
assert(videoGetResolution(state.displayMode.resolution, &res) == 0);

pitch = 4 * res.width; // each pixel is 4 bytes
int depth_pitch = 2 * res.width; // And each value in the depth buffer is a 16 bit float

// Configure the buffer format to xRGB
VideoConfiguration vconfig;
Expand All @@ -70,6 +74,7 @@ void init_screen() {
assert(videoGetState(0, 0, &state) == 0);

s32 buffer_size = pitch * res.height;
s32 depth_buffer_size = depth_pitch * res.height;
printf("buffers will be 0x%x bytes\n", buffer_size);

gcmSetFlipMode(GCM_FLIP_VSYNC); // Wait for VSYNC to flip
Expand All @@ -79,23 +84,31 @@ void init_screen() {
buffer[1] = rsxMemAlign(16, buffer_size);
assert(buffer[0] != NULL && buffer[1] != NULL);

depth_buffer = rsxMemAlign(16, depth_buffer_size);

assert(realityAddressToOffset(buffer[0], &offset[0]) == 0);
assert(realityAddressToOffset(buffer[1], &offset[1]) == 0);
// Setup the display buffers
assert(gcmSetDisplayBuffer(0, offset[0], pitch, res.width, res.height) == 0);
assert(gcmSetDisplayBuffer(1, offset[1], pitch, res.width, res.height) == 0);

// Setup depth buffer
realitySetRenderSurface(context, REALITY_SURFACE_ZETA, REALITY_RSX_MEMORY,
offset[currentBuffer], depth_pitch);

gcmResetFlipStatus();
flip(1);
}

void drawFrame(int *buffer, long frame) {
void drawFrame(u32 *buffer, long frame) {
// Set the color0 target to point at the offset of our current surface
realitySetRenderSurface(context, REALITY_SURFACE_COLOR0, REALITY_RSX_MEMORY,
offset[currentBuffer], pitch);
// Choose color0 as the render target and tell the rsx about the surface format.
realitySelectRenderTarget(context, REALITY_TARGET_0,
REALITY_TARGET_FORMAT_COLOR_X8R8G8B8 | REALITY_TARGET_FORMAT_ZETA_Z24S8 | REALITY_TARGET_FORMAT_TYPE_LINEAR,
REALITY_TARGET_FORMAT_COLOR_X8R8G8B8 |
REALITY_TARGET_FORMAT_ZETA_Z16 |
REALITY_TARGET_FORMAT_TYPE_LINEAR,
res.width, res.height, 0, 0);

// Just because we can only set the clear color, dosen't mean it has to be boring
Expand All @@ -107,7 +120,13 @@ void drawFrame(int *buffer, long frame) {
// Clear the buffers
realityClearBuffers(context, REALITY_CLEAR_BUFFERS_COLOR_R |
REALITY_CLEAR_BUFFERS_COLOR_G |
REALITY_CLEAR_BUFFERS_COLOR_B);
REALITY_CLEAR_BUFFERS_COLOR_B |
REALITY_CLEAR_BUFFERS_DEPTH);
}

void unload_modules() {
SysUnloadModule(SYSMODULE_PNGDEC);
SysUnloadModule(SYSMODULE_FS);
}

s32 main(s32 argc, const char* argv[])
Expand All @@ -119,6 +138,15 @@ s32 main(s32 argc, const char* argv[])
init_screen();
ioPadInit(7);

atexit(unload_modules);

// Load png decoder
assert(SysLoadModule(SYSMODULE_FS) != 0);
assert(SysLoadModule(SYSMODULE_PNGDEC) != 0);

// Load texture
ball = loadTexture(ball_bin);

long frame = 0; // To keep track of how many frames we have rendered.

// Ok, everything is setup. Now for the main loop.
Expand Down
7 changes: 5 additions & 2 deletions samples/rsxTest/source/texture.c
Expand Up @@ -2,13 +2,14 @@
#include <string.h>

#include <pngdec/loadpng.h>
#include "ball.bin.h"

#include <rsx/reality.h>
#include <rsx/commands.h>
#include <rsx/nv40.h>

realityTexture *loadTexture(uint8_t *pngData) {
#include "texture.h"

realityTexture *loadTexture(const uint8_t *pngData) {
PngDatas png;
png.png_in= (void *) pngData;
png.png_size= sizeof(pngData);
Expand Down Expand Up @@ -46,5 +47,7 @@ realityTexture *loadTexture(uint8_t *pngData) {
tex->height = png.height;
tex->stride = png.width * 4;

free(png.bmp_out);

return tex;
}

0 comments on commit 500bec4

Please sign in to comment.