Mercurial > hg > Game > Cerium
changeset 120:13b43de5ef5d draft
fix Load Texture
author | gongo@gendarme.local |
---|---|
date | Tue, 25 Nov 2008 00:18:49 +0900 |
parents | cc6ec1a10607 |
children | 5be15e10a7f8 08e47bbca4f5 |
files | TaskManager/Test/test_render/Makefile.def TaskManager/Test/test_render/polygon.cpp TaskManager/Test/test_render/spe/CreatePolygon.cpp TaskManager/Test/test_render/spe/DrawSpan.cpp TaskManager/Test/test_render/spe/Load_Texture.cpp TaskManager/Test/test_render/spe/Set_Texture.cpp TaskManager/Test/test_render/spe/texture.h TaskManager/Test/test_render/task/DrawSpan.cpp TaskManager/Test/test_render/task/Load_Texture.cpp TaskManager/Test/test_render/task/Set_Texture.cpp TaskManager/Test/test_render/task/texture.h TaskManager/Test/test_render/viewer.cpp |
diffstat | 12 files changed, 139 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Makefile.def Thu Nov 13 11:12:29 2008 +0900 +++ b/TaskManager/Test/test_render/Makefile.def Tue Nov 25 00:18:49 2008 +0900 @@ -3,7 +3,7 @@ # include/library path # ex: macosx #CERIUM = /Users/gongo/Source/Concurrency/Game_project/Cerium -CERIUM = /Users/gongo/Source/Cerium +CERIUM = /Users/gongo/Source/hg/Cerium # ex: linux/ps3 #CERIUM = /home/gongo/Cerium @@ -11,7 +11,7 @@ #CERIUM = ../../.. CC = g++ -CFLAGS = -O9 -g -Wall# -DDEBUG +CFLAGS = -O0 -g -Wall# -DDEBUG INCLUDE = -I$(CERIUM)/include/TaskManager -I. LIBS = -L$(CERIUM)/TaskManager
--- a/TaskManager/Test/test_render/polygon.cpp Thu Nov 13 11:12:29 2008 +0900 +++ b/TaskManager/Test/test_render/polygon.cpp Tue Nov 25 00:18:49 2008 +0900 @@ -13,6 +13,7 @@ #include "SpanC.h" #include "scene_graph_pack.h" #include "error.h" +#include "viewer_types.h" using namespace std; //extern int decode(char *cont, char *file_name); @@ -651,6 +652,18 @@ fclose(outfile); texture_image = IMG_Load(image_name); + + SDL_Surface *tmpImage + = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w, + texture_image->h, 32, + redMask, greenMask, blueMask, alphaMask); + SDL_Surface *converted; + converted = SDL_ConvertSurface(texture_image, + tmpImage->format, SDL_HWSURFACE); + if( converted != NULL){ + SDL_FreeSurface(texture_image); + texture_image = converted; + } //load_texture(image_name); if(unlink(image_name))
--- a/TaskManager/Test/test_render/spe/CreatePolygon.cpp Thu Nov 13 11:12:29 2008 +0900 +++ b/TaskManager/Test/test_render/spe/CreatePolygon.cpp Tue Nov 25 00:18:49 2008 +0900 @@ -76,7 +76,6 @@ if (node->next != NULL) { smanager->dma_load(next_node, (uint32)node->next, sizeof(SceneGraphNode), SG_NODE_LOAD); - printf("[1] %p, %d\n", node->next, sizeof(SceneGraphNode)); } else { next_node = NULL; }
--- a/TaskManager/Test/test_render/spe/DrawSpan.cpp Thu Nov 13 11:12:29 2008 +0900 +++ b/TaskManager/Test/test_render/spe/DrawSpan.cpp Tue Nov 25 00:18:49 2008 +0900 @@ -7,9 +7,12 @@ #include "viewer_types.h" #define SPAN_PACK_LOAD 0 +#define TEX_LOAD 1 SchedDefineTask(DrawSpan); +unsigned char *tex; + void DrawSpan::linebuf_init(int *buf, int x, int rgb) { @@ -38,7 +41,11 @@ char* DrawSpan::get_pixel(int tx, int ty, void *texture_image) { +#if 0 return (char*)texture_image+(3*((128)*ty+tx)); +#else + return (char*)texture_image+(4*((8)*ty+tx)); +#endif } Uint32 @@ -51,8 +58,22 @@ if (ty<0) ty = 0; if (128-1< ty) ty = 128-1 ; +#if 0 char *p = get_pixel(tx,ty,texture); +#else + void *texture_addr; + int blockX = tx / 8; + int blockY = ty / 8; + void** addrList = (void**)global_get(TEXTURE2_ID); + + texture_addr = addrList[blockX + 16*blockY]; + smanager->dma_load(tex, (uint32)texture_addr, sizeof(uint32)*64, TEX_LOAD); + smanager->dma_wait(TEX_LOAD); + + char *p = get_pixel(tx%8, ty%8, tex); +#endif + blue = (Uint8) p[0]; green = (Uint8) p[1]; red = (Uint8) p[2]; @@ -84,6 +105,8 @@ int **linebuf = (int**)smanager->allocate(sizeof(int*)*rangey); + tex = (unsigned char*)smanager->allocate(sizeof(unsigned char)*64*4); + for (int i = 0; i < rangey; i++) { linebuf[i] = (int*)smanager->get_output(i); linebuf_init(linebuf[i], rangex, 0x00ff00ff); @@ -169,8 +192,6 @@ next_sp = tmp_sp; } while (sp); - -FINISH: free(free_sp); free(linebuf); free(zRow);
--- a/TaskManager/Test/test_render/spe/Load_Texture.cpp Thu Nov 13 11:12:29 2008 +0900 +++ b/TaskManager/Test/test_render/spe/Load_Texture.cpp Tue Nov 25 00:18:49 2008 +0900 @@ -1,7 +1,7 @@ #include <stdlib.h> +#include <string.h> #include "Load_Texture.h" -#include "SchedTask.h" -#include "../spe/texture.h" +#include "texture.h" #include "Func.h" /** @@ -21,8 +21,15 @@ int LoadTexture::run(void *rbuf , void *wbuf) { - int addr = get_param(0); - + int addr = smanager->get_param(0); + int addrNum = smanager->get_param(1); + + void **addrList = (void**)smanager->get_input(0); + void **list = (void**)global_alloc(TEXTURE2_ID, addrNum*sizeof(void*)); + + memcpy(list, addrList, addrNum*sizeof(void*)); + +#if 0 //タスクからタスクを生成 TaskPtr task = create_task(TASK_SET_TEXTURE); @@ -30,8 +37,10 @@ task->add_inData(addr, MAX_LOAD_SIZE); task->add_inData(addr + MAX_LOAD_SIZE, MAX_LOAD_SIZE); task->add_inData(addr + MAX_LOAD_SIZE*2, MAX_LOAD_SIZE); + task->add_inData(addr + MAX_LOAD_SIZE*3, MAX_LOAD_SIZE); wait_task(task); - +#endif + return 0; }
--- a/TaskManager/Test/test_render/spe/Set_Texture.cpp Thu Nov 13 11:12:29 2008 +0900 +++ b/TaskManager/Test/test_render/spe/Set_Texture.cpp Tue Nov 25 00:18:49 2008 +0900 @@ -8,18 +8,24 @@ int SetTexture::run(void *rbuf, void *wbuf) { - void *src[3]; + void *src[4]; src[0] = get_input(rbuf, 0); src[1] = get_input(rbuf, 1); src[2] = get_input(rbuf, 2); + src[3] = get_input(rbuf, 3); - //タスクが共有できる領域確保 - void *data = global_alloc(TEXTURE_ID, MAX_LOAD_SIZE*3); + if (global_get(TEXTURE_ID)) { + return 0; + } else { + //タスクが共有できる領域確保 + void *data = global_alloc(TEXTURE_ID, MAX_LOAD_SIZE*4); - memcpy(data, src[0], MAX_LOAD_SIZE); - memcpy((void*)((int)data + MAX_LOAD_SIZE), src[1], MAX_LOAD_SIZE); - memcpy((void*)((int)data + MAX_LOAD_SIZE*2), src[2], MAX_LOAD_SIZE); + memcpy(data, src[0], MAX_LOAD_SIZE); + memcpy((void*)((int)data + MAX_LOAD_SIZE), src[1], MAX_LOAD_SIZE); + memcpy((void*)((int)data + MAX_LOAD_SIZE*2), src[2], MAX_LOAD_SIZE); + memcpy((void*)((int)data + MAX_LOAD_SIZE*3), src[3], MAX_LOAD_SIZE); + } return 0; }
--- a/TaskManager/Test/test_render/spe/texture.h Thu Nov 13 11:12:29 2008 +0900 +++ b/TaskManager/Test/test_render/spe/texture.h Tue Nov 25 00:18:49 2008 +0900 @@ -1,2 +1,3 @@ #define MAX_LOAD_SIZE 16384 #define TEXTURE_ID 0 +#define TEXTURE2_ID 13
--- a/TaskManager/Test/test_render/task/DrawSpan.cpp Thu Nov 13 11:12:29 2008 +0900 +++ b/TaskManager/Test/test_render/task/DrawSpan.cpp Tue Nov 25 00:18:49 2008 +0900 @@ -7,9 +7,12 @@ #include "viewer_types.h" #define SPAN_PACK_LOAD 0 +#define TEX_LOAD 1 SchedDefineTask(DrawSpan); +unsigned char *tex; + void DrawSpan::linebuf_init(int *buf, int x, int rgb) { @@ -38,7 +41,11 @@ char* DrawSpan::get_pixel(int tx, int ty, void *texture_image) { +#if 0 return (char*)texture_image+(3*((128)*ty+tx)); +#else + return (char*)texture_image+(4*((8)*ty+tx)); +#endif } Uint32 @@ -51,8 +58,22 @@ if (ty<0) ty = 0; if (128-1< ty) ty = 128-1 ; +#if 0 char *p = get_pixel(tx,ty,texture); +#else + void *texture_addr; + int blockX = tx / 8; + int blockY = ty / 8; + void** addrList = (void**)global_get(TEXTURE2_ID); + + texture_addr = addrList[blockX + 16*blockY]; + smanager->dma_load(tex, (uint32)texture_addr, sizeof(uint32)*64, TEX_LOAD); + smanager->dma_wait(TEX_LOAD); + + char *p = get_pixel(tx%8, ty%8, tex); +#endif + blue = (Uint8) p[0]; green = (Uint8) p[1]; red = (Uint8) p[2]; @@ -84,6 +105,8 @@ int **linebuf = (int**)smanager->allocate(sizeof(int*)*rangey); + tex = (unsigned char*)smanager->allocate(sizeof(unsigned char)*64*4); + for (int i = 0; i < rangey; i++) { linebuf[i] = (int*)smanager->get_output(i); linebuf_init(linebuf[i], rangex, 0x00ff00ff); @@ -169,8 +192,6 @@ next_sp = tmp_sp; } while (sp); - -FINISH: free(free_sp); free(linebuf); free(zRow);
--- a/TaskManager/Test/test_render/task/Load_Texture.cpp Thu Nov 13 11:12:29 2008 +0900 +++ b/TaskManager/Test/test_render/task/Load_Texture.cpp Tue Nov 25 00:18:49 2008 +0900 @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <string.h> #include "Load_Texture.h" #include "texture.h" #include "Func.h" @@ -20,8 +21,15 @@ int LoadTexture::run(void *rbuf , void *wbuf) { - int addr = get_param(0); - + int addr = smanager->get_param(0); + int addrNum = smanager->get_param(1); + + void **addrList = (void**)smanager->get_input(0); + void **list = (void**)global_alloc(TEXTURE2_ID, addrNum*sizeof(void*)); + + memcpy(list, addrList, addrNum*sizeof(void*)); + +#if 0 //タスクからタスクを生成 TaskPtr task = create_task(TASK_SET_TEXTURE); @@ -29,8 +37,10 @@ task->add_inData(addr, MAX_LOAD_SIZE); task->add_inData(addr + MAX_LOAD_SIZE, MAX_LOAD_SIZE); task->add_inData(addr + MAX_LOAD_SIZE*2, MAX_LOAD_SIZE); + task->add_inData(addr + MAX_LOAD_SIZE*3, MAX_LOAD_SIZE); wait_task(task); - +#endif + return 0; }
--- a/TaskManager/Test/test_render/task/Set_Texture.cpp Thu Nov 13 11:12:29 2008 +0900 +++ b/TaskManager/Test/test_render/task/Set_Texture.cpp Tue Nov 25 00:18:49 2008 +0900 @@ -8,21 +8,23 @@ int SetTexture::run(void *rbuf, void *wbuf) { - void *src[3]; + void *src[4]; src[0] = get_input(rbuf, 0); src[1] = get_input(rbuf, 1); src[2] = get_input(rbuf, 2); + src[3] = get_input(rbuf, 3); if (global_get(TEXTURE_ID)) { return 0; } else { //タスクが共有できる領域確保 - void *data = global_alloc(TEXTURE_ID, MAX_LOAD_SIZE*3); + void *data = global_alloc(TEXTURE_ID, MAX_LOAD_SIZE*4); memcpy(data, src[0], MAX_LOAD_SIZE); memcpy((void*)((int)data + MAX_LOAD_SIZE), src[1], MAX_LOAD_SIZE); memcpy((void*)((int)data + MAX_LOAD_SIZE*2), src[2], MAX_LOAD_SIZE); + memcpy((void*)((int)data + MAX_LOAD_SIZE*3), src[3], MAX_LOAD_SIZE); } return 0;
--- a/TaskManager/Test/test_render/task/texture.h Thu Nov 13 11:12:29 2008 +0900 +++ b/TaskManager/Test/test_render/task/texture.h Tue Nov 25 00:18:49 2008 +0900 @@ -1,2 +1,3 @@ #define MAX_LOAD_SIZE 16384 #define TEXTURE_ID 0 +#define TEXTURE2_ID 13
--- a/TaskManager/Test/test_render/viewer.cpp Thu Nov 13 11:12:29 2008 +0900 +++ b/TaskManager/Test/test_render/viewer.cpp Tue Nov 25 00:18:49 2008 +0900 @@ -1,4 +1,5 @@ #include "viewer.h" +#include "viewer_types.h" #include "polygon.h" #include "sys.h" #include "Func.h" @@ -106,9 +107,6 @@ spackList_ptr[i] = &spackList[i]; } - __texture = (void*)manager->malloc(128*128*3); - memcpy(__texture, polygon->texture_image->pixels, 128*128*3); - task_next = manager->create_task(TASK_DUMMY); task_next->set_post(&post2runLoop, NULL); @@ -119,11 +117,41 @@ task_next->wait_for(task_sgp); task_sgp->spawn(); + __texture = (void*)manager->malloc(128*128*4); + memcpy(__texture, polygon->texture_image->pixels, 128*128*4); + + + uint32 *tex_src = (uint32*)polygon->texture_image->pixels; + uint32 *tex_dest = (uint32*)manager->malloc(sizeof(uint32)*128*128); + int tile_size = TEXTURE_SPLIT_PIXEL*TEXTURE_SPLIT_PIXEL; + int tile_num = 128*128/tile_size; + void **tex_addrList = (void**)manager->malloc(sizeof(void*)*tile_num); + + { + int t = 0; + + for (int y = 0; y < 128; y += TEXTURE_SPLIT_PIXEL) { + for (int x = 0; x < 128; x += TEXTURE_SPLIT_PIXEL) { + for (int j = 0; j < TEXTURE_SPLIT_PIXEL; j++) { + for (int i = 0; i < TEXTURE_SPLIT_PIXEL; i++) { + tex_dest[t++] = tex_src[(x+i) + 128*(y+j)]; + } + } + } + } + + t = 0; + + for (int i = 0, t = 0; i < 128*128; i += tile_size, t++) { + tex_addrList[t] = (void*)&tex_dest[i]; + } + } + for (int i = 0; i < spe_num; i++) { - //アドレスを送ってる、サイズが0なのは送った先で計算するので不要 task_init_tex = manager->create_task(TASK_INIT_TEXTURE); + task_init_tex->add_inData(tex_addrList, sizeof(void*)*tile_num); task_init_tex->add_param((int)__texture); - + task_init_tex->add_param(tile_num); task_init_tex->set_cpu(SPE_ANY); task_next->wait_for(task_init_tex); task_init_tex->spawn();