From 53e761a9a8719cc5d62322500e7d1d5c09de2e4e Mon Sep 17 00:00:00 2001 From: Crayon2000 Date: Fri, 6 Feb 2009 20:41:33 +0000 Subject: [PATCH] [NEW] Function GRRLIB_FlushTex to flush a texture [CHG] GRRLIB_GrayScale renamed to GRRLIB_BMFX_GrayScale [CHG] GRRLIB_SetPixelTotexImg is not calling DCFlushRange any more --- README.TXT | 4 +++- template/source/GRRLIB/GRRLIB.c | 17 ++++++++++++++--- template/source/GRRLIB/GRRLIB.h | 4 +++- template/source/main.c | 3 ++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.TXT b/README.TXT index 542aa01..7d6be9c 100644 --- a/README.TXT +++ b/README.TXT @@ -54,7 +54,9 @@ ChangeLog : * GRRLIB_GetPixelFromtexImg and GRRLIB_SetPixelTotexImg -* GRRLIB_GrayScale and GRRLIB_CreateEmptyTexture +* GRRLIB_CreateEmptyTexture and GRRLIB_FlushTex + +* New Bitmap FX: GRRLIB_BMFX_GrayScale * add GRRLIB_Exit to free the memory allocated by GRRLIB diff --git a/template/source/GRRLIB/GRRLIB.c b/template/source/GRRLIB/GRRLIB.c index 9197b4d..d4fcbdb 100644 --- a/template/source/GRRLIB/GRRLIB.c +++ b/template/source/GRRLIB/GRRLIB.c @@ -136,9 +136,9 @@ GRRLIB_texImg GRRLIB_LoadTexturePNG(const unsigned char my_png[]) { my_texture.data = memalign (32, imgProp.imgWidth * imgProp.imgHeight * 4); PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, my_texture.data, 255); PNGU_ReleaseImageContext (ctx); - DCFlushRange (my_texture.data, imgProp.imgWidth * imgProp.imgHeight * 4); my_texture.w = imgProp.imgWidth; my_texture.h = imgProp.imgHeight; + GRRLIB_FlushTex(my_texture); return my_texture; } @@ -242,7 +242,6 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) { /* Create a buffer to hold the final texture */ my_texture.data = memalign(32, cinfo.output_width * cinfo.output_height * 4); RawTo4x4RGBA(tempBuffer, my_texture.data, cinfo.output_width, cinfo.output_height); - DCFlushRange(my_texture.data, cinfo.output_width * cinfo.output_height * 4); /* Done - do cleanup and release memory */ jpeg_finish_decompress(&cinfo); @@ -252,6 +251,7 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) { my_texture.w = cinfo.output_width; my_texture.h = cinfo.output_height; + GRRLIB_FlushTex(my_texture); return my_texture; } @@ -275,6 +275,7 @@ GRRLIB_texImg GRRLIB_CreateEmptyTexture(unsigned int w, unsigned int h) { GRRLIB_SetPixelTotexImg(x, y, my_texture, 0x00000000); } } + GRRLIB_FlushTex(my_texture); return my_texture; } @@ -478,6 +479,7 @@ u32 GRRLIB_GetPixelFromtexImg(int x, int y, GRRLIB_texImg tex) { /** * Set the color value of a pixel to a GRRLIB_texImg. + * @see GRRLIB_FlushTex * @param x specifies the x-coordinate of the pixel in the texture. * @param y specifies the y-coordinate of the pixel in the texture. * @param tex texture to set the color to. @@ -493,15 +495,24 @@ void GRRLIB_SetPixelTotexImg(int x, int y, GRRLIB_texImg tex, u32 color) { *(truc+offset+1)=(color>>24) & 0xFF; *(truc+offset+32)=(color>>16) & 0xFF; *(truc+offset+33)=(color>>8) & 0xFF; +} +/** + * Writes the contents of a texture in the data cache down to main memory. + * For performance the CPU holds a data cache where modifications are stored before they get written down to mainmemory. + * @param tex the texture to flush. + */ +void GRRLIB_FlushTex(GRRLIB_texImg tex) +{ DCFlushRange(tex.data, tex.w * tex.h * 4); } /** * Change a texture to gray scale. + * @see GRRLIB_FlushTex * @param tex the texture to change. */ -void GRRLIB_GrayScale(GRRLIB_texImg tex) { +void GRRLIB_BMFX_GrayScale(GRRLIB_texImg tex) { unsigned int x, y; u8 r, g, b, gray; u32 color; diff --git a/template/source/GRRLIB/GRRLIB.h b/template/source/GRRLIB/GRRLIB.h index 9f0a770..ddc85b8 100644 --- a/template/source/GRRLIB/GRRLIB.h +++ b/template/source/GRRLIB/GRRLIB.h @@ -65,7 +65,9 @@ bool GRRLIB_RectOnRect(int rect1x, int rect1y, int rect1w, int rect1h, int rect2 u32 GRRLIB_GetPixelFromtexImg(int x, int y, GRRLIB_texImg tex); void GRRLIB_SetPixelTotexImg(int x, int y, GRRLIB_texImg tex, u32 color); -void GRRLIB_GrayScale(GRRLIB_texImg tex); +void GRRLIB_FlushTex(GRRLIB_texImg tex); + +void GRRLIB_BMFX_GrayScale(GRRLIB_texImg tex); void GRRLIB_GXEngine(Vector v[], u32 color, long count, u8 fmt); diff --git a/template/source/main.c b/template/source/main.c index 74fd994..7faa7d9 100644 --- a/template/source/main.c +++ b/template/source/main.c @@ -122,7 +122,8 @@ int main() { val = (valtmp<<24) | (valtmp<<16) | (valtmp<<8) | 0xFF; GRRLIB_SetPixelTotexImg(x, y, tex_pixeltest, val); } - } + } + GRRLIB_FlushTex(tex_pixeltest); // Draw a sprite GRRLIB_DrawTile(600, 400, tex_sprite_png, 0, 2, 2, GRRLIB_WHITE, 12*4); // Rupee