void oslDrawImageSimple(OSL_IMAGE *img) { OSL_UVFLOAT_VERTEX *vertices; int x = img->x, y = img->y; //Very little overhead to support the rotation center but anyway... this routine was meant to be very simple :p // int x = img->x - img->centerX, y = img->y - img->centerY; // do a striped blit (takes the page-cache into account) oslSetTexture(img); if (oslImageGetAutoStrip(img)) { if (oslVerifyStripBlit(img)) return; } vertices = (OSL_UVFLOAT_VERTEX*)sceGuGetMemory(2 * sizeof(OSL_UVFLOAT_VERTEX)); vertices[0].u = img->offsetX0; vertices[0].v = img->offsetY0; vertices[0].x = x; vertices[0].y = y; vertices[0].z = 0; vertices[1].u = img->offsetX1; vertices[1].v = img->offsetY1; vertices[1].x = x + img->stretchX; vertices[1].y = y + img->stretchY; vertices[1].z = 0; sceGuDrawArray(GU_SPRITES,GU_TEXTURE_32BITF|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices); }
static void LogoDrawTiles(OSL_IMAGE *img, float positions[TABH][TABW]) { OSL_FAST_VERTEX *vertices, *vptr; int nbVertices, x, y; oslSetTexture(img); for (y=0;y<HAUT/TILE;y++) { vertices = (OSL_FAST_VERTEX*)sceGuGetMemory((LARG/TILE) * 2 * sizeof(OSL_FAST_VERTEX)); vptr = vertices; nbVertices = 0; for (x=0;x<LARG/TILE;x++) { vertices[nbVertices].u = x * TILE; vertices[nbVertices].v = y * TILE; vertices[nbVertices].x = x * TILE; vertices[nbVertices].y = positions[y][x]; vertices[nbVertices].z = 0; nbVertices ++; vertices[nbVertices].u = x * TILE + TILE; vertices[nbVertices].v = y * TILE + TILE; vertices[nbVertices].x = x * TILE + TILE; vertices[nbVertices].y = positions[y][x] + TILE; vertices[nbVertices].z = 0; nbVertices ++; } //Dessine if (nbVertices > 0) sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D, nbVertices, 0, vertices); } }
void _gEndQuads() { // Define vertices properties int prim = GU_TRIANGLES, v_obj_nbr = 6, v_nbr = v_obj_nbr * (obj_list_size / 4), v_coord_size = 3, v_tex_size = (obj_use_tex) ? 2 : 0, v_color_size = (obj_use_vert_color) ? 1 : 0, v_size = v_tex_size * sizeof(short) + v_color_size * sizeof(gColor) + v_coord_size * sizeof(float), v_type = GU_VERTEX_32BITF | GU_TRANSFORM_2D, i; if (obj_use_tex) v_type |= GU_TEXTURE_16BIT; if (obj_use_vert_color) v_type |= GU_COLOR_8888; // Allocate vertex list memory void *v = sceGuGetMemory(v_nbr * v_size), *vi = v; // Build the vertex list for (i=0; i+3<obj_list_size; i+=4) { vi = _gSetVertex(vi,i ,0.f,0.f); vi = _gSetVertex(vi,i+1,1.f,0.f); vi = _gSetVertex(vi,i+3,0.f,1.f); vi = _gSetVertex(vi,i+3,0.f,1.f); vi = _gSetVertex(vi,i+1,1.f,0.f); vi = _gSetVertex(vi,i+2,1.f,1.f); } // Then put it in the display list. sceGuDrawArray(prim,v_type,v_nbr,NULL,v); }
void vidgu_render_nostretch(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh) { int start, end; sceGuStart(GU_DIRECT,list); sceGuTexMode(GU_PSM_5650,0,0,0); // 16-bit RGBA sceGuTexImage(0,512,512,512,g_pBlitBuff); // setup texture as a 256x256 texture //sceKernelDcacheWritebackAll(); sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGBA); // don't get influenced by any vertex colors sceGuTexFilter(GU_NEAREST,GU_NEAREST); // point-filtered sampling for (start = sx, end = sx+sw; start < end; start += SLICE_SIZE, dx += SLICE_SIZE) { struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex)); int width = (start + SLICE_SIZE) < end ? SLICE_SIZE : end-start; vertices[0].u = start; vertices[0].v = sy; vertices[0].color = 0; vertices[0].x = dx; vertices[0].y = dy; vertices[0].z = 0; vertices[1].u = start + width; vertices[1].v = sy + sh; vertices[1].color = 0; vertices[1].x = dx + width; vertices[1].y = dy + sh; vertices[1].z = 0; sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_COLOR_5650|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices); } sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuSwapBuffers(); //sceGuSwapBuffers(); }
void ya2d_drawRotateTexture(ya2d_Texture *texp, int x, int y, float angle) { if(!texp->data) return; sceGuEnable(GU_TEXTURE_2D); sceGuTexMode(texp->texPSM, 0, 0, texp->isSwizzled); sceGuTexFunc(GU_TFX_REPLACE, texp->hasAlpha ? GU_TCC_RGBA : GU_TCC_RGB); ya2d_setTexture(texp); sceGumPushMatrix(); sceGumLoadIdentity(); { ScePspFVector3 pos = {x + (float)texp->centerX, y + (float)texp->centerY, 0.0f}; sceGumTranslate(&pos); sceGumRotateZ(angle); } ya2d_FloatTextureVertex *vertices = (ya2d_FloatTextureVertex *)sceGuGetMemory(4 * sizeof(ya2d_FloatTextureVertex)); vertices[0] = (ya2d_FloatTextureVertex){0.0f, 0.0f, (float)-texp->centerX, (float)-texp->centerY, 0.0f}; vertices[1] = (ya2d_FloatTextureVertex){0.0f, 1.0f, (float)-texp->centerX, (float)texp->centerY, 0.0f}; vertices[2] = (ya2d_FloatTextureVertex){1.0f, 0.0f, (float)texp->centerX, (float)-texp->centerY, 0.0f}; vertices[3] = (ya2d_FloatTextureVertex){1.0f, 1.0f, (float)texp->centerX, (float)texp->centerY, 0.0f}; sceGumDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D, 4, 0, vertices); sceKernelDcacheWritebackRange(vertices, 4 * sizeof(ya2d_FloatTextureVertex)); sceGumPopMatrix(); }
void drawSprite(int sx, int sy, int width, int height, gwTextureS* source, int dx, int dy) { //sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGBA); //sceGuTexMode(source->format, 0, 0, source->swizzled); //sceGuTexImage(0, source->textureWidth, source->textureHeight, source->textureWidth, source->data); // float u = 1.0f / ((float)source->textureWidth); //float v = 1.0f / ((float)source->textureHeight); //sceGuTexScale(u, v); // sceGuDisable(GU_DEPTH_TEST); int j = 0; while (j < width) { struct BlitVertex { unsigned short u,v; short x,y,z; } *vertices = (struct BlitVertex*) sceGuGetMemory(2 * sizeof(struct BlitVertex)); int sliceWidth = 64; if (j + sliceWidth > width) sliceWidth = width - j; vertices[0].u = sx + j; vertices[0].v = sy; vertices[0].x = dx + j; vertices[0].y = dy; vertices[0].z = 1; vertices[1].u = sx + j + sliceWidth; vertices[1].v = sy + height; vertices[1].x = dx + j + sliceWidth; vertices[1].y = dy + height; vertices[1].z = 1; sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices); j += sliceWidth; } // sceGuEnable(GU_DEPTH_TEST); // sceGuTexScale(1.0f, 1.0f); }
void oslDrawTextTileBack(int x, int y, int tX, int tY) { int color = oslBlendColor(osl_textBkColor); OSL_LINE_VERTEX_COLOR32 *vertices; vertices = (OSL_LINE_VERTEX_COLOR32*)sceGuGetMemory(2 * sizeof(OSL_LINE_VERTEX_COLOR32)); // x += osl_curFont->addedSpace; //<-- STAS: tX seems to be more appropiate here :-) tX += osl_curFont->addedSpace; //<-- STAS END --> vertices[0].color = color; vertices[0].x = x; vertices[0].y = y; vertices[0].z = 0; vertices[1].color = color; vertices[1].x = x+tX; vertices[1].y = y+tY; vertices[1].z = 0; int wasEnable = osl_textureEnabled; oslDisableTexturing(); sceGuDrawArray(GU_SPRITES,GU_COLOR_8888|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices); sceKernelDcacheWritebackRange(vertices, 2 * sizeof(OSL_LINE_VERTEX_COLOR32)); //SAKYA if (wasEnable) oslEnableTexturing(); }
void _gEndLines() { // Define vertices properties int prim = GU_LINES, v_obj_nbr = 2, v_nbr = v_obj_nbr * (obj_list_size / 2), v_coord_size = 3, v_color_size = (obj_use_vert_color) ? 1 : 0, v_size = v_color_size * sizeof(gColor) + v_coord_size * sizeof(float), v_type = GU_VERTEX_32BITF | GU_TRANSFORM_2D, i; if (obj_use_vert_color) v_type |= GU_COLOR_8888; // Allocate vertex list memory void *v = sceGuGetMemory(v_nbr * v_size), *vi = v; // Build the vertex list for (i=0; i+1<obj_list_size; i+=2) { vi = _gSetVertex(vi,i ,0.f,0.f); vi = _gSetVertex(vi,i+1,0.f,0.f); } // Then put it in the display list. sceGuDrawArray(prim,v_type,v_nbr,NULL,v); }
//Dessine une tile de la texture sélectionnée. Eviter d'utiliser à l'extérieur. void oslDrawTextTile(int u, int v, int x, int y, int tX, int tY) { int color = oslBlendColor(osl_textColor); //If enabled, draw the background if (osl_textBkColor & 0xff000000) oslDrawTextTileBack(x, y, tX, tY); tX += osl_curFont->addedSpace; OSL_FAST_VERTEX_COLOR32 *vertices; vertices = (OSL_FAST_VERTEX_COLOR32*)sceGuGetMemory(2 * sizeof(OSL_FAST_VERTEX_COLOR32)); vertices[0].u = u; vertices[0].v = v; vertices[0].color = color; vertices[0].x = x; vertices[0].y = y; vertices[0].z = 0; vertices[1].u = u+tX; vertices[1].v = v+tY; vertices[1].color = color; vertices[1].x = x+tX; vertices[1].y = y+tY; vertices[1].z = 0; int wasEnable = osl_textureEnabled; oslEnableTexturing(); sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_COLOR_8888|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices); sceKernelDcacheWritebackRange(vertices, 2 * sizeof(OSL_FAST_VERTEX_COLOR32)); //SAKYA if (!wasEnable) oslDisableTexturing(); }
void ya2d_drawTexture(ya2d_Texture *texp, int x, int y) { if(!texp->data) return; sceGuEnable(GU_TEXTURE_2D); sceGuTexMode(texp->texPSM, 0, 0, texp->isSwizzled); sceGuTexFunc(GU_TFX_REPLACE, texp->hasAlpha ? GU_TCC_RGBA : GU_TCC_RGB); ya2d_setTexture(texp); if(texp->textureWidth <= YA2D_TEXTURE_SLICE) { ya2d_TextureVertex *vertices = (ya2d_TextureVertex *)sceGuGetMemory(4 * sizeof(ya2d_TextureVertex)); vertices[0] = (ya2d_TextureVertex){0, 0, x, y, 0}; vertices[1] = (ya2d_TextureVertex){0, texp->textureHeight, x, y+texp->textureHeight, 0}; vertices[2] = (ya2d_TextureVertex){texp->textureWidth, 0, x+texp->textureWidth, y, 0}; vertices[3] = (ya2d_TextureVertex){texp->textureWidth, texp->textureHeight, x+texp->textureWidth, y+texp->textureHeight, 0}; sceGumDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D, 4, 0, vertices); sceKernelDcacheWritebackRange(vertices, 4 * sizeof(ya2d_TextureVertex)); } else //Fast draw for big textures { int i; for(i = 0; i < texp->textureWidth; i+= YA2D_TEXTURE_SLICE) { /* ya2d_TextureVertex *vertices = (ya2d_TextureVertex *)sceGuGetMemory(4 * sizeof(ya2d_TextureVertex)); vertices[0] = (ya2d_TextureVertex){i, 0, x+i, y, 0}; vertices[1] = (ya2d_TextureVertex){i+YA2D_TEXTURE_SLICE, 0, x+i+YA2D_TEXTURE_SLICE, y, 0}; vertices[2] = (ya2d_TextureVertex){i, texp->textureHeight, x+i, y+texp->textureHeight, 0}; vertices[3] = (ya2d_TextureVertex){i+YA2D_TEXTURE_SLICE, texp->textureHeight, x+i+YA2D_TEXTURE_SLICE, y+texp->textureHeight, 0}; sceGumDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D, 4, 0, vertices); sceKernelDcacheWritebackRange(vertices, 4 * sizeof(ya2d_TextureVertex)); */ ya2d_TextureVertex *vertices = (ya2d_TextureVertex *)sceGuGetMemory(2 * sizeof(ya2d_TextureVertex)); vertices[0] = (ya2d_TextureVertex){i, 0, x+i, y, 0}; vertices[1] = (ya2d_TextureVertex){i+YA2D_TEXTURE_SLICE, texp->textureHeight, x+i+YA2D_TEXTURE_SLICE, y+texp->textureHeight, 0}; sceGumDrawArray(GU_SPRITES, GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D, 2, 0, vertices); sceKernelDcacheWritebackRange(vertices, 2 * sizeof(ya2d_TextureVertex)); } } }
int xTextPrint(int x, int y, char* text) { if (!x_current_font) return 0; if (!x_current_font->texture) return 0; float pos = (float)x; int len = strlen(text); int text_length = xTextLength(text, len); if (x_font_align == X_ALIGN_CENTER) pos -= 0.5f*text_length; else if (x_font_align == X_ALIGN_RIGHT) pos -= text_length; u16 char_width = x_current_font->texture->width/16; Text_Vert* vertices = (Text_Vert*)sceGuGetMemory(2*len*sizeof(Text_Vert)); Text_Vert* vert_ptr = vertices; int i = 0; while (/* *text != '\0' && num >= 0 */ i < len) { int tx = (((u8)*text >> 0) & 0x0f) * char_width; int ty = (((u8)*text >> 4) & 0x0f) * char_width; vert_ptr->u = (s16)(tx); vert_ptr->v = (s16)(x_current_font->texture->height - ty); vert_ptr->color = x_font_color; vert_ptr->x = (int)(pos); vert_ptr->y = (int)(y); vert_ptr->z = 0.0f; vert_ptr += 1; pos += x_font_scale*x_current_font->widths[(u8)*text]; vert_ptr->u = (s16)(tx + x_current_font->widths[(u8)*text]); vert_ptr->v = (s16)(x_current_font->texture->height - ty - char_width); vert_ptr->color = x_font_color; vert_ptr->x = (int)(pos); vert_ptr->y = (int)(y + x_font_scale*char_width); vert_ptr->z = 0.0f; vert_ptr += 1; text += 1; //num -= 1; i += 1; } xTexSetImage(x_current_font->texture); xGuSaveStates(); sceGuEnable(GU_TEXTURE_2D); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuDisable(GU_DEPTH_TEST); sceGuDrawArray(GU_SPRITES, Text_Vert_vtype|GU_TRANSFORM_2D, 2*len, 0, vertices); xGuLoadStates(); return (int)text_length; }
void vidgu_render(int sx, int sy, int sw,int sh,int dx, int dy, int dw,int dh) { unsigned int j,cx,cy; struct Vertex* vertices; cx=(480-dw)/2; cy=(272-dh)/2; sceGuStart(GU_DIRECT,list); sceGuTexMode(GU_PSM_5650,0,0,0); // 16-bit RGBA sceGuTexImage(0,512,512,512,g_pBlitBuff); // setup texture as a 256x256 texture //sceKernelDcacheWritebackAll(); sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGBA); // don't get influenced by any vertex colors sceGuTexFilter(GU_LINEAR,GU_LINEAR); // point-filtered sampling int start, end; float ustart = (float)sx; float ustep = (float)sw / (float)(dw / SLICE_SIZE); // blit maximizing the use of the texture-cache for (start = sx, end = sx+dw; start < end; start += SLICE_SIZE, dx += SLICE_SIZE) { struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex)); int width = (start + SLICE_SIZE) < end ? SLICE_SIZE : end-start; vertices[0].u = ustart; vertices[0].v = (float)sy; vertices[0].color = 0; vertices[0].x = dx; vertices[0].y = dy; vertices[0].z = 0; vertices[1].u = ustart + ustep; vertices[1].v = (float)(sy + sh); vertices[1].color = 0; vertices[1].x = dx + width; vertices[1].y = dy + dh; vertices[1].z = 0; sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_COLOR_5650|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices); ustart += ustep; } sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuSwapBuffers(); }
void ya2d_drawFillRect(int x, int y, int w, int h, u32 color) { sceGuDisable(GU_TEXTURE_2D); ya2d_FastVertex *vertices = (ya2d_FastVertex *)sceGuGetMemory(4 * sizeof(ya2d_FastVertex)); vertices[0] = (ya2d_FastVertex){color, x, y}; vertices[1] = (ya2d_FastVertex){color, x, y+h}; vertices[2] = (ya2d_FastVertex){color, x+w, y}; vertices[3] = (ya2d_FastVertex){color, x+w, y+h}; sceGuDrawArray(GU_TRIANGLE_STRIP, GU_COLOR_8888|GU_VERTEX_16BIT|GU_TRANSFORM_2D, 4, 0, vertices); sceKernelDcacheWritebackRange(vertices, 4 * sizeof(ya2d_FastVertex)); }
static void draw_bg_map_256(BGMAP_TEXT_t* map_data, unsigned character_base_block, unsigned offsetX, unsigned offsetY) { return; psp1_sprite_t* tile_coords = sceGuGetMemory(32*32*sizeof(psp1_sprite_t)); unsigned int i; sceGuClutLoad(32, palette_ram_8bit); sceGuClutMode(GU_PSM_5551,0,0xFF,0); sceGuTexImage(0, 128, 256, 128, GBA_VRAMTEXTURE_8bit + character_base_block * 16 * 1024); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 32 * 32 * 2, NULL,(void*)tile_coords); }
void psp_renderSprite(int flags, int x, int y, int w, int h) { log("%d %d %d %d %d\n",flags,x,y,w,h); SpriteVertex *vertices = (SpriteVertex*)sceGuGetMemory(2*sizeof(SpriteVertex)); vertices[0].u = 0; vertices[0].v = 0; vertices[0].x = x; vertices[0].y = y; vertices[0].z = 0; vertices[1].u = w; vertices[1].v = h; vertices[1].x = x+w; vertices[1].y = y+h; vertices[1].z = 0; if(flags & SPRITE_HFLIP) { vertices[0].u = w; vertices[1].u = 0; } sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_COLOR_4444|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices); }
virtual void draw() { sceGuEnable(GU_TEXTURE_2D); sceGuTexMode(GU_PSM_8888, 0, 0, GU_FALSE); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuTexImage(0, 256, 256, 256, data_.get().data()); sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); sceGuTexFilter(GU_LINEAR, GU_LINEAR); bright_texture_vertex * const vertex = static_cast<bright_texture_vertex *>(sceGuGetMemory(2 * sizeof(*vertex))); vertex[0].u = u_; vertex[0].v = v_; vertex[0].color = color_ | static_cast<boost::uint32_t>(alpha_) << 24; vertex[0].x = x_; vertex[0].y = y_; vertex[0].z = 0.f; vertex[1].u = u_ + u_size_; vertex[1].v = v_ + v_size_; vertex[1].color = color_ | static_cast<boost::uint32_t>(alpha_) << 24; vertex[1].x = x_ + width_; vertex[1].y = y_ + height_; vertex[1].z = 0.f; sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, vertex); }
void _gEndRects() { // Horror : we need to sort the vertices. if (obj_use_z && obj_use_blend) _gVertexSort(); // Define vertices properties int prim = (obj_use_rot) ? GU_TRIANGLES : GU_SPRITES, v_obj_nbr = (obj_use_rot) ? 6 : 2, v_nbr, v_coord_size = 3, v_tex_size = (obj_use_tex) ? 2 : 0, v_color_size = (obj_use_vert_color) ? 1 : 0, v_size = v_tex_size * sizeof(short) + v_color_size * sizeof(gColor) + v_coord_size * sizeof(float), v_type = GU_VERTEX_32BITF | GU_TRANSFORM_2D, n_slices = -1, i; if (obj_use_tex) v_type |= GU_TEXTURE_16BIT; if (obj_use_vert_color) v_type |= GU_COLOR_8888; // Count how many vertices to allocate. if (!obj_use_tex || obj_use_rot) // No slicing { v_nbr = v_obj_nbr * obj_list_size; } else // Can use texture slicing for tremendous performance :) { for (n_slices=0, i=0; i!=obj_list_size; i++) { n_slices += (int)(I_OBJ.crop_w/SLICE_WIDTH)+1; } v_nbr = v_obj_nbr * n_slices; } // Allocate vertex list memory void *v = sceGuGetMemory(v_nbr * v_size), *vi = v; // Build the vertex list for (i=0; i<obj_list_size; i+=1) { if (!obj_use_rot) { if (!obj_use_tex) { vi = _gSetVertex(vi,i,0.f,0.f); vi = _gSetVertex(vi,i,1.f,1.f); } else // Use texture slicing { float u, step = (float)SLICE_WIDTH/I_OBJ.crop_w; for (u=0.f; u<1.f; u+=step) { vi = _gSetVertex(vi,i,u,0.f); vi = _gSetVertex(vi,i,((u+step) > 1.f ? 1.f : u+step),1.f); } } } else // Rotation : draw 2 triangles per obj { vi = _gSetVertex(vi,i,0.f,0.f); vi = _gSetVertex(vi,i,1.f,0.f); vi = _gSetVertex(vi,i,0.f,1.f); vi = _gSetVertex(vi,i,0.f,1.f); vi = _gSetVertex(vi,i,1.f,0.f); vi = _gSetVertex(vi,i,1.f,1.f); } } // Then put it in the display list. sceGuDrawArray(prim,v_type,v_nbr,NULL,v); }
static void draw_sprites(void) { int i; psp1_sprite_t* tile_coords = sceGuGetMemory(128*sizeof(psp1_sprite_t)); // sceGuClutLoad(32, palette_ram + 256); int mapping_mode_1D = gba_video_registers->lcd_control.obj_character_vram_mapping; typedef struct { int w; int h; }obj_size_t; static const obj_size_t obj_size[4][4]= { {{8,8},{16,16},{32,32},{64,64}}, {{16,8},{32,8},{32,16},{64,32}}, {{8,16},{8,32},{16,32},{32,64}}, {{0,0},{0,0},{0,0},{0,0}} }; sceGuTexMode(GU_PSM_T16, 0, 0, GU_TRUE); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); sceGuTexScale_8bit(1.0,1.0); sceGuClutLoad(32, palette_ram_4bit+256); // for (i=0; i < 128; i++) for (i=127; i >= 0; i--) { if (oam_attributes[i].obj_disable_flag) continue; if (oam_attributes[i].mode > 1) continue; if (oam_attributes[i].palette_mode_256) { sceGuClutLoad(32, palette_ram_8bit+256); printf("256!\n"); sceGuClutLoad(32, palette_ram_4bit+256); } else { // printf("16!\n"); int size_id = oam_attributes[i].size; int shape_id = oam_attributes[i].shape; if (shape_id>3) continue; int width = obj_size[shape_id][size_id].w; int height = obj_size[shape_id][size_id].h; psp1_sprite_t temp; temp = sprite_tiles[oam_attributes[i].flip_XY]; // temp = sprite_tiles[0]; temp.v1.x = width; temp.v1.y = height; *tile_coords = temp; sceGuOffset_(-oam_attributes[i].X, -oam_attributes[i].Y); if (mapping_mode_1D) { sceGuTexImage(0, width, height, width, GBA_VRAMTEXTURE_4bit + 256*256*2 + oam_attributes[i].id * 64); } else { // printf("2d!!\n"); sceGuTexImage(0, width, height, 256, GBA_VRAMTEXTURE_4bit + 256*256*2 + oam_attributes[i].id * 64); } sceGuClutMode(GU_PSM_5551,0,0x0F,oam_attributes[i].palette_id); sceGuDrawArray(GU_SPRITES, GU_TEXTURE_8BIT | GU_VERTEX_16BIT | GU_TRANSFORM_3D, 2, NULL,(void*)(tile_coords++)); } } }
void oslDrawMap(OSL_MAP *m) { int x, y, v, sX, sY, mX, mY, dX, bY, dsX, dsY, xTile, yTile, i; u32 tilesPerLine = m->img->sizeX / m->tileX, tilesPerLineOpt = 0; u32 firstTileOpaque = !(m->flags & OSL_MF_TILE1_TRANSPARENT); u16 *map = (u16*)m->map; OSL_FAST_VERTEX *vertices, *vptr; int nbVertices; oslSetTexture(m->img); if (m->drawSizeX < 0 || m->drawSizeY < 0) { dsX = osl_curBuf->sizeX/m->tileX+1; if (osl_curBuf->sizeX%m->tileX) dsX++; dsY = osl_curBuf->sizeY/m->tileY+1; if (osl_curBuf->sizeY%m->tileY) dsY++; } else dsX = m->drawSizeX, dsY = m->drawSizeY; //Try to optimize for shifting. From 1 to 256 tiles per line, should be a wide enough range. for (i=1;i<=8;i++) { if (tilesPerLine >= 1<<i) tilesPerLineOpt = i; } sX = m->scrollX%m->tileX; sY = m->scrollY%m->tileY; //Pour parer au modulo négatif if (sX < 0) sX += m->tileX; if (sY < 0) sY += m->tileY; dX = (((m->scrollX)<0?(m->scrollX-m->tileX+1):(m->scrollX))/m->tileX)%m->mapSizeX; mY = (((m->scrollY)<0?(m->scrollY-m->tileY+1):(m->scrollY))/m->tileY)%m->mapSizeY; //Pour parer au modulo négatif if (dX < 0) dX += m->mapSizeX; if (mY < 0) mY += m->mapSizeY; yTile = -sY; switch (m->format) { case OSL_MF_U16: for (y=0;y<dsY;y++) { bY = m->mapSizeX * mY; mX = dX; xTile = -sX; vertices = (OSL_FAST_VERTEX*)sceGuGetMemory(dsX * 2 * sizeof(OSL_FAST_VERTEX)); vptr = vertices; nbVertices = 0; if (tilesPerLineOpt) { for (x=0;x<dsX;x++) { v = map[bY+mX]; //Plus compréhensible if (v || firstTileOpaque) { //Optimized with shift & and. Multiplication doesn't need to be optimized as it requires 12 cycles (2 cycles + 10 overlap). Division requires 75 cycles instead. DDIV is 135, and DMULT is 2 + 18. vertices[nbVertices].u = (v & ((1 << tilesPerLineOpt) - 1)) * m->tileX; vertices[nbVertices].v = (v >> tilesPerLineOpt) * m->tileY; vertices[nbVertices].x = xTile; vertices[nbVertices].y = yTile; vertices[nbVertices].z = 0; vertices[nbVertices+1].u = vertices[nbVertices].u + m->tileX; vertices[nbVertices+1].v = vertices[nbVertices].v + m->tileY; vertices[nbVertices+1].x = vertices[nbVertices].x + m->tileX; vertices[nbVertices+1].y = vertices[nbVertices].y + m->tileY; vertices[nbVertices+1].z = 0; nbVertices += 2; } xTile += m->tileX; mX++; if (mX >= m->mapSizeX) mX -= m->mapSizeX; } } else { for (x=0;x<dsX;x++) { v = map[bY+mX]; //Plus compréhensible if (v || firstTileOpaque) { //Unoptimized method vertices[nbVertices].u = (v % tilesPerLine) * m->tileX; vertices[nbVertices].v = (v / tilesPerLine) * m->tileY; vertices[nbVertices].x = xTile; vertices[nbVertices].y = yTile; vertices[nbVertices].z = 0; vertices[nbVertices+1].u = vertices[nbVertices].u + m->tileX; vertices[nbVertices+1].v = vertices[nbVertices].v + m->tileY; vertices[nbVertices+1].x = vertices[nbVertices].x + m->tileX; vertices[nbVertices+1].y = vertices[nbVertices].y + m->tileY; vertices[nbVertices+1].z = 0; nbVertices += 2; } xTile += m->tileX; mX++; if (mX >= m->mapSizeX) mX -= m->mapSizeX; } } //Dessine if (nbVertices > 0) sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D, nbVertices, 0, vertices); mY++; if (mY >= m->mapSizeY) mY -= m->mapSizeY; yTile += m->tileY; }
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 (); }
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 }
//------------------------------------------------------------------------------------------------- // render a single frame of a MD2 model void JMD2Model::Render(int frameNum) { Vector3D *pointList; int i; // create a pointer to the frame we want to show pointList = &mModel->pointList[mModel->numPoints * frameNum]; // set the texture mRenderer->BindTexture(mModel->modelTex); #if !defined (PSP) // display the textured model with proper lighting normals #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) #elif (defined GL_ES_VERSION_1_1) || (defined GL_VERSION_1_1) || (defined GL_VERSION_ES_CM_1_1) || (defined GL_OES_VERSION_1_1) glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); #else glBegin(GL_TRIANGLES); #endif //(defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) for(i = 0; i < mModel->numTriangles; i++) { CalculateNormal(pointList[mModel->triIndex[i].meshIndex[0]].v, pointList[mModel->triIndex[i].meshIndex[2]].v, pointList[mModel->triIndex[i].meshIndex[1]].v); #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) #elif (defined GL_ES_VERSION_1_1) || (defined GL_VERSION_1_1)|| (defined GL_VERSION_ES_CM_1_1) || (defined GL_OES_VERSION_1_1) float vertex_data[]={ pointList[mModel->triIndex[i].meshIndex[0]].x, pointList[mModel->triIndex[i].meshIndex[0]].y, pointList[mModel->triIndex[i].meshIndex[0]].z, pointList[mModel->triIndex[i].meshIndex[2]].x, pointList[mModel->triIndex[i].meshIndex[2]].y, pointList[mModel->triIndex[i].meshIndex[2]].z, pointList[mModel->triIndex[i].meshIndex[1]].x, pointList[mModel->triIndex[i].meshIndex[1]].y, pointList[mModel->triIndex[i].meshIndex[1]].z, }; float texcoord_data[] = { mModel->st[mModel->triIndex[i].stIndex[0]].s, mModel->st[mModel->triIndex[i].stIndex[0]].t, mModel->st[mModel->triIndex[i].stIndex[2]].s, mModel->st[mModel->triIndex[i].stIndex[2]].t, mModel->st[mModel->triIndex[i].stIndex[1]].s, mModel->st[mModel->triIndex[i].stIndex[1]].t, }; glVertexPointer(3,GL_FLOAT,0,vertex_data); glTexCoordPointer(2,GL_FLOAT,0,texcoord_data); #else glTexCoord2f(mModel->st[mModel->triIndex[i].stIndex[0]].s, mModel->st[mModel->triIndex[i].stIndex[0]].t); glVertex3fv(pointList[mModel->triIndex[i].meshIndex[0]].v); glTexCoord2f(mModel->st[mModel->triIndex[i].stIndex[2]].s , mModel->st[mModel->triIndex[i].stIndex[2]].t); glVertex3fv(pointList[mModel->triIndex[i].meshIndex[2]].v); glTexCoord2f(mModel->st[mModel->triIndex[i].stIndex[1]].s, mModel->st[mModel->triIndex[i].stIndex[1]].t); glVertex3fv(pointList[mModel->triIndex[i].meshIndex[1]].v); #endif //#if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0) } #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) #elif (defined GL_ES_VERSION_1_1) || (defined GL_VERSION_1_1) || (defined GL_VERSION_ES_CM_1_1) || (defined GL_OES_VERSION_1_1) glDrawArrays(GL_TRIANGLES,0,3); // seems suspicious to put that here, should probably be in the loop #else glEnd(); #endif //(defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) #else PSPVertex3D* vertices = (PSPVertex3D*) sceGuGetMemory(mModel->numTriangles * 3 * sizeof(PSPVertex3D)); int n = 0; for(i = 0; i < mModel->numTriangles; i++) { //CalculateNormal(&vertices[n].normal, // pointList[mModel->triIndex[i].meshIndex[0]].v, // pointList[mModel->triIndex[i].meshIndex[2]].v, // pointList[mModel->triIndex[i].meshIndex[1]].v); vertices[n].texture.x = mModel->st[mModel->triIndex[i].stIndex[0]].s; vertices[n].texture.y = mModel->st[mModel->triIndex[i].stIndex[0]].t; vertices[n].pos.x = pointList[mModel->triIndex[i].meshIndex[0]].x; vertices[n].pos.y = pointList[mModel->triIndex[i].meshIndex[0]].y; vertices[n].pos.z = pointList[mModel->triIndex[i].meshIndex[0]].z; n++; //vertices[n].normal.x = vertices[n-1].normal.x; //vertices[n].normal.y = vertices[n-1].normal.y; //vertices[n].normal.z = vertices[n-1].normal.z; vertices[n].texture.x = mModel->st[mModel->triIndex[i].stIndex[2]].s; vertices[n].texture.y = mModel->st[mModel->triIndex[i].stIndex[2]].t; vertices[n].pos.x = pointList[mModel->triIndex[i].meshIndex[2]].x; vertices[n].pos.y = pointList[mModel->triIndex[i].meshIndex[2]].y; vertices[n].pos.z = pointList[mModel->triIndex[i].meshIndex[2]].z; n++; //vertices[n].normal.x = vertices[n-1].normal.x; //vertices[n].normal.y = vertices[n-1].normal.y; //vertices[n].normal.z = vertices[n-1].normal.z; vertices[n].texture.x = mModel->st[mModel->triIndex[i].stIndex[1]].s; vertices[n].texture.y = mModel->st[mModel->triIndex[i].stIndex[1]].t; vertices[n].pos.x = pointList[mModel->triIndex[i].meshIndex[1]].x; vertices[n].pos.y = pointList[mModel->triIndex[i].meshIndex[1]].y; vertices[n].pos.z = pointList[mModel->triIndex[i].meshIndex[1]].z; n++; } sceGuColor(0xff000000); sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,mModel->numTriangles*3,0,vertices); #endif }
void psp_sdl_gu_stretch(SDL_Rect* srcrect, SDL_Rect* dstrect) { SDL_Surface* src = blit_surface; unsigned short old_slice = 0; /* set when we load 2nd tex */ unsigned int slice, num_slices, width, height, tbw, off_x, off_bytes; struct texVertex *vertices; char *pixels; sceKernelDcacheWritebackAll(); off_bytes = (long)(((char*)src->pixels) + srcrect->x * src->format->BytesPerPixel) & 0xf; off_x = off_bytes / src->format->BytesPerPixel; width = roundUpToPowerOfTwo(srcrect->w + off_bytes); height = roundUpToPowerOfTwo(srcrect->h); tbw = src->pitch / src->format->BytesPerPixel; /* Align the texture prior to srcrect->x */ pixels = ((char*)src->pixels) + (srcrect->x - off_x) * src->format->BytesPerPixel + src->pitch * srcrect->y; num_slices = (srcrect->w + (PSP_SLICE_SIZE - 1)) / PSP_SLICE_SIZE; /* GE doesn't appreciate textures wider than 512 */ if (width > 512) width = 512; sceGuStart(GU_DIRECT,list); sceGuEnable(GU_TEXTURE_2D); sceGuTexMode(GU_PSM_5650, 0, 0, GU_FALSE); sceGuTexImage(0, width, height, tbw, pixels); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); sceGuTexFilter(GU_LINEAR, GU_LINEAR); for (slice = 0; slice < num_slices; slice++) { vertices = (struct texVertex*)sceGuGetMemory(2 * sizeof(struct texVertex)); if ((slice * PSP_SLICE_SIZE) < width) { vertices[0].u = slice * PSP_SLICE_SIZE + off_x; } else { if (!old_slice) { /* load another texture (src width > 512) */ pixels += width * src->format->BytesPerPixel; sceGuTexImage(0, roundUpToPowerOfTwo(srcrect->w - width), height, tbw, pixels); sceGuTexSync(); old_slice = slice; } vertices[0].u = (slice - old_slice) * PSP_SLICE_SIZE + off_x; } vertices[1].u = vertices[0].u + PSP_SLICE_SIZE; if (vertices[1].u > (off_x + srcrect->w)) vertices[1].u = off_x + srcrect->w; vertices[0].v = 0; vertices[1].v = vertices[0].v + srcrect->h; vertices[0].x = dstrect->x + (slice * PSP_SLICE_SIZE * dstrect->w + (srcrect->w - 1)) / srcrect->w; vertices[1].x = vertices[0].x + (PSP_SLICE_SIZE * dstrect->w + (srcrect->w - 1)) / srcrect->w; if (vertices[1].x > (dstrect->x + dstrect->w)) vertices[1].x = dstrect->x + dstrect->w; vertices[0].y = dstrect->y; vertices[1].y = vertices[0].y + dstrect->h; vertices[0].z = 0; vertices[1].z = 0; sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D, 2,0,vertices); } sceGuFinish(); sceGuSync(0, 0); }
//------------------------------------------------------------------------------------------------- // displays a frame of the model between startFrame and endFrame with an interpolation percent void JMD2Model::Render() { CheckNextState(); Vector3D *pointList; // current frame vertices Vector3D *nextPointList; // next frame vertices int i; float x1, y1, z1; // current frame point values float x2, y2, z2; // next frame point values Vector3D vertex[3]; if (mModel == NULL) return; pointList = &mModel->pointList[mModel->numPoints*mModel->currentFrame]; nextPointList = &mModel->pointList[mModel->numPoints*mModel->nextFrame]; mRenderer->BindTexture(mModel->modelTex); #if !defined (PSP) #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) // FIXME #elif (defined GL_ES_VERSION_1_1) || (defined GL_VERSION_1_1) || (defined GL_VERSION_ES_CM_1_1) || (defined GL_OES_VERSION_1_1) glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); #else glBegin(GL_TRIANGLES); #endif //(defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) for (i = 0; i < mModel->numTriangles; i++) { // get first points of each frame x1 = pointList[mModel->triIndex[i].meshIndex[0]].x; y1 = pointList[mModel->triIndex[i].meshIndex[0]].y; z1 = pointList[mModel->triIndex[i].meshIndex[0]].z; x2 = nextPointList[mModel->triIndex[i].meshIndex[0]].x; y2 = nextPointList[mModel->triIndex[i].meshIndex[0]].y; z2 = nextPointList[mModel->triIndex[i].meshIndex[0]].z; // store first interpolated vertex of triangle vertex[0].x = x1 + mModel->interpol * (x2 - x1); vertex[0].y = y1 + mModel->interpol * (y2 - y1); vertex[0].z = z1 + mModel->interpol * (z2 - z1); // get second points of each frame x1 = pointList[mModel->triIndex[i].meshIndex[2]].x; y1 = pointList[mModel->triIndex[i].meshIndex[2]].y; z1 = pointList[mModel->triIndex[i].meshIndex[2]].z; x2 = nextPointList[mModel->triIndex[i].meshIndex[2]].x; y2 = nextPointList[mModel->triIndex[i].meshIndex[2]].y; z2 = nextPointList[mModel->triIndex[i].meshIndex[2]].z; // store second interpolated vertex of triangle vertex[2].x = x1 + mModel->interpol * (x2 - x1); vertex[2].y = y1 + mModel->interpol * (y2 - y1); vertex[2].z = z1 + mModel->interpol * (z2 - z1); // get third points of each frame x1 = pointList[mModel->triIndex[i].meshIndex[1]].x; y1 = pointList[mModel->triIndex[i].meshIndex[1]].y; z1 = pointList[mModel->triIndex[i].meshIndex[1]].z; x2 = nextPointList[mModel->triIndex[i].meshIndex[1]].x; y2 = nextPointList[mModel->triIndex[i].meshIndex[1]].y; z2 = nextPointList[mModel->triIndex[i].meshIndex[1]].z; // store third interpolated vertex of triangle vertex[1].x = x1 + mModel->interpol * (x2 - x1); vertex[1].y = y1 + mModel->interpol * (y2 - y1); vertex[1].z = z1 + mModel->interpol * (z2 - z1); // calculate the normal of the triangle //CalculateNormal(vertex[0].v, vertex[2].v, vertex[1].v); // render properly textured triangle #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) // FIXME #elif (defined GL_ES_VERSION_1_1) || (defined GL_VERSION_1_1) || (defined GL_VERSION_ES_CM_1_1) || (defined GL_OES_VERSION_1_1) float vertex_data[]={ vertex[0].x, vertex[0].y, vertex[0].z, vertex[2].x, vertex[2].y, vertex[2].z, vertex[1].x, vertex[1].y, vertex[1].z, }; float texcoord_data[] = { mModel->st[mModel->triIndex[i].stIndex[0]].s, mModel->st[mModel->triIndex[i].stIndex[0]].t, mModel->st[mModel->triIndex[i].stIndex[2]].s, mModel->st[mModel->triIndex[i].stIndex[2]].t, mModel->st[mModel->triIndex[i].stIndex[1]].s, mModel->st[mModel->triIndex[i].stIndex[1]].t, }; glVertexPointer(3,GL_FLOAT,0,vertex_data); glTexCoordPointer(2,GL_FLOAT,0,texcoord_data); #else glTexCoord2f(mModel->st[mModel->triIndex[i].stIndex[0]].s, mModel->st[mModel->triIndex[i].stIndex[0]].t); glVertex3fv(vertex[0].v); glTexCoord2f(mModel->st[mModel->triIndex[i].stIndex[2]].s , mModel->st[mModel->triIndex[i].stIndex[2]].t); glVertex3fv(vertex[2].v); glTexCoord2f(mModel->st[mModel->triIndex[i].stIndex[1]].s, mModel->st[mModel->triIndex[i].stIndex[1]].t); glVertex3fv(vertex[1].v); #endif //(defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) } #if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) // FIXME #elif (defined GL_ES_VERSION_1_1) || (defined GL_VERSION_1_1) || (defined GL_VERSION_ES_CM_1_1) || (defined GL_OES_VERSION_1_1) glDrawArrays(GL_TRIANGLES,0,3); // seems suspicious to put that here, should probably be in the loop #else glEnd(); #endif //(defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0) #else PSPVertex3D* vertices = (PSPVertex3D*) sceGuGetMemory(mModel->numTriangles * 3 * sizeof(PSPVertex3D)); int n = 0; for (i = 0; i < mModel->numTriangles; i++) { // get first points of each frame x1 = pointList[mModel->triIndex[i].meshIndex[0]].x; y1 = pointList[mModel->triIndex[i].meshIndex[0]].y; z1 = pointList[mModel->triIndex[i].meshIndex[0]].z; x2 = nextPointList[mModel->triIndex[i].meshIndex[0]].x; y2 = nextPointList[mModel->triIndex[i].meshIndex[0]].y; z2 = nextPointList[mModel->triIndex[i].meshIndex[0]].z; // store first interpolated vertex of triangle vertex[0].x = x1 + mModel->interpol * (x2 - x1); vertex[0].y = y1 + mModel->interpol * (y2 - y1); vertex[0].z = z1 + mModel->interpol * (z2 - z1); // get second points of each frame x1 = pointList[mModel->triIndex[i].meshIndex[2]].x; y1 = pointList[mModel->triIndex[i].meshIndex[2]].y; z1 = pointList[mModel->triIndex[i].meshIndex[2]].z; x2 = nextPointList[mModel->triIndex[i].meshIndex[2]].x; y2 = nextPointList[mModel->triIndex[i].meshIndex[2]].y; z2 = nextPointList[mModel->triIndex[i].meshIndex[2]].z; // store second interpolated vertex of triangle vertex[2].x = x1 + mModel->interpol * (x2 - x1); vertex[2].y = y1 + mModel->interpol * (y2 - y1); vertex[2].z = z1 + mModel->interpol * (z2 - z1); // get third points of each frame x1 = pointList[mModel->triIndex[i].meshIndex[1]].x; y1 = pointList[mModel->triIndex[i].meshIndex[1]].y; z1 = pointList[mModel->triIndex[i].meshIndex[1]].z; x2 = nextPointList[mModel->triIndex[i].meshIndex[1]].x; y2 = nextPointList[mModel->triIndex[i].meshIndex[1]].y; z2 = nextPointList[mModel->triIndex[i].meshIndex[1]].z; // store third interpolated vertex of triangle vertex[1].x = x1 + mModel->interpol * (x2 - x1); vertex[1].y = y1 + mModel->interpol * (y2 - y1); vertex[1].z = z1 + mModel->interpol * (z2 - z1); //CalculateNormal(&vertices[n].normal, // vertex[0].v, // vertex[2].v, // vertex[1].v); vertices[n].texture.x = mModel->st[mModel->triIndex[i].stIndex[0]].s; vertices[n].texture.y = mModel->st[mModel->triIndex[i].stIndex[0]].t; vertices[n].pos.x = vertex[0].x; vertices[n].pos.y = vertex[0].y; vertices[n].pos.z = vertex[0].z; n++; //vertices[n].normal.x = vertices[n-1].normal.x; //vertices[n].normal.y = vertices[n-1].normal.y; //vertices[n].normal.z = vertices[n-1].normal.z; vertices[n].texture.x = mModel->st[mModel->triIndex[i].stIndex[2]].s; vertices[n].texture.y = mModel->st[mModel->triIndex[i].stIndex[2]].t; vertices[n].pos.x = vertex[2].x; vertices[n].pos.y = vertex[2].y; vertices[n].pos.z = vertex[2].z; n++; //vertices[n].normal.x = vertices[n-1].normal.x; //vertices[n].normal.y = vertices[n-1].normal.y; //vertices[n].normal.z = vertices[n-1].normal.z; vertices[n].texture.x = mModel->st[mModel->triIndex[i].stIndex[1]].s; vertices[n].texture.y = mModel->st[mModel->triIndex[i].stIndex[1]].t; vertices[n].pos.x = vertex[1].x; vertices[n].pos.y = vertex[1].y; vertices[n].pos.z = vertex[1].z; n++; } sceGuColor(0xff000000); sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,mModel->numTriangles*3,0,vertices); #endif // mModel->interpol += percent; // increase percentage of interpolation between frames }
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; }
int main(int argc, char* argv[]) { pspDebugScreenInit(); 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); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); int val = 0; gettimeofday(&base_time,0); while(running()) { struct Vertex* vertices; struct timeval tv; sceGuStart(GU_DIRECT,list); // clear screen sceGuClearColor(0); sceGuClearDepth(0); sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); // draw triangle 1 (normal) sceGuColor(0xffffffff); vertices = (struct Vertex*)sceGuGetMemory(3*sizeof(struct Vertex)); vertices[0].x = (SCR_WIDTH/2) + cosf(val * (GU_PI/180)) * (SCR_HEIGHT/2); vertices[0].y = (SCR_HEIGHT/2) + sinf(val * (GU_PI/180)) * (SCR_HEIGHT/2); vertices[0].z = 0; vertices[1].x = (SCR_WIDTH/2) + cosf((val+120) * (GU_PI/180)) * (SCR_HEIGHT/2); vertices[1].y = (SCR_HEIGHT/2) + sinf((val+120) * (GU_PI/180)) * (SCR_HEIGHT/2); vertices[1].z = 0; vertices[2].x = (SCR_WIDTH/2) + cosf((val+240) * (GU_PI/180)) * (SCR_HEIGHT/2); vertices[2].y = (SCR_HEIGHT/2) + sinf((val+240) * (GU_PI/180)) * (SCR_HEIGHT/2); vertices[2].z = 0; sceGuDrawArray(GU_TRIANGLES,GU_VERTEX_32BITF|GU_TRANSFORM_2D,3,0,vertices); // draw triangle 2 (affected by logic op) sceGuEnable(GU_COLOR_LOGIC_OP); sceGuLogicalOp(curr_state); sceGuColor(0xffff00ff); vertices = (struct Vertex*)sceGuGetMemory(3*sizeof(struct Vertex)); vertices[0].x = (SCR_WIDTH/2) + cosf((val*1.1f) * (GU_PI/180)) * (SCR_HEIGHT/2); vertices[0].y = (SCR_HEIGHT/2) + sinf((val*1.1f) * (GU_PI/180)) * (SCR_HEIGHT/2); vertices[0].z = 0; vertices[1].x = (SCR_WIDTH/2) + cosf((val*1.1f+120) * (GU_PI/180)) * (SCR_HEIGHT/2); vertices[1].y = (SCR_HEIGHT/2) + sinf((val*1.1f+120) * (GU_PI/180)) * (SCR_HEIGHT/2); vertices[1].z = 0; vertices[2].x = (SCR_WIDTH/2) + cosf((val*1.1f+240) * (GU_PI/180)) * (SCR_HEIGHT/2); vertices[2].y = (SCR_HEIGHT/2) + sinf((val*1.1f+240) * (GU_PI/180)) * (SCR_HEIGHT/2); vertices[2].z = 0; sceGuDrawArray(GU_TRIANGLES,GU_VERTEX_32BITF|GU_TRANSFORM_2D,3,0,vertices); sceGuDisable(GU_COLOR_LOGIC_OP); sceGuFinish(); sceGuSync(0,0); gettimeofday(&tv,0); if ((tv.tv_sec-base_time.tv_sec) > TIME_SLICE) { curr_state = (curr_state + 1) & 15; base_time = tv; } sceDisplayWaitVblankStart(); sceGuSwapBuffers(); pspDebugScreenSetXY(0,0); pspDebugScreenPrintf("%s",names[curr_state]); val++; } sceGuTerm(); sceKernelExitGame(); return 0; }
//-------------------------------------------------------------------- // Función: CFade::Update // Creador: Nacho (AMD) // Fecha: Thursday 14/06/2007 11:56:53 //-------------------------------------------------------------------- void CFade::Update(float dt) { if (m_fFadeTime > 0.0f) { m_fFadeState += dt; if (m_fFadeState >= m_fFadeTime) { m_bFadeActive = false; } float alpha = 0.0f; ///--- fade in if (m_bFadeIn) { alpha = 255.0f - ((m_fFadeState * 255.0f) / m_fFadeTime); } ///--- fade out else { alpha = ((m_fFadeState * 255.0f) / m_fFadeTime); } alpha = MAT_Clampf(alpha, 0.0f, m_fTarget); if (alpha > 0.0f) { VERT* v = (VERT*)sceGuGetMemory(sizeof(VERT) * 2); VERT* v0 = &v[0]; VERT* v1 = &v[1]; int alpha_integer = (((int)alpha) & 0xFF) << 24; v0->x = -1.0f; v0->y = -1.0f; v0->z = 0.0f; v1->x = 481.0f; v1->y = 273.0f; v1->z = 0.0f; sceGuColor((m_iColor & 0x00ffffff) | alpha_integer); sceGuDisable(GU_TEXTURE_2D); sceGuDisable(GU_DEPTH_TEST); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGumDrawArray(GU_SPRITES, GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, v); sceGuEnable(GU_DEPTH_TEST); sceGuDisable(GU_BLEND); sceGuEnable(GU_TEXTURE_2D); sceGuColor(0xffffffff); } } }