90
|
1 #include <iostream>
|
|
2 #include <SDL_image.h>
|
|
3 #include <libxml/parser.h>
|
|
4 #include "polygon.h"
|
|
5 #include "TaskManager.h"
|
|
6 using namespace std;
|
|
7
|
|
8
|
|
9 #define redMask 0x00ff0000
|
|
10 #define greenMask 0x0000ff00
|
|
11 #define blueMask 0x000000ff
|
|
12 #define alphaMask 0
|
|
13 #define width 128
|
|
14 #define height 128
|
|
15 #define bpp 32
|
|
16
|
|
17
|
|
18 extern int get_fbdev_addr();
|
|
19
|
|
20 extern int decode(char *cont, FILE *outfile);
|
|
21
|
96
|
22 #define LOAD_TEXTURE_SIZE 128*128*3
|
90
|
23
|
|
24 void Polygon::set_data(char *file_name)
|
|
25 {
|
|
26 xmlDocPtr doc;
|
|
27 xmlNodePtr cur;
|
|
28 Polygon *tmp;
|
|
29
|
|
30 doc = xmlParseFile(file_name);
|
|
31
|
|
32 cur = xmlDocGetRootElement(doc);
|
|
33
|
|
34 xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D");
|
|
35
|
|
36 tmp = this;
|
|
37
|
|
38 for (cur=cur->children; cur; cur=cur->next) {
|
|
39 if (!xmlStrcmp(cur->name,(xmlChar*)"surface")) {
|
|
40 tmp->create_data(cur);
|
|
41 if(cur->next->next) {
|
|
42 tmp->add_next();
|
|
43 tmp = tmp->next;
|
|
44 }
|
|
45 }
|
|
46 }
|
|
47 xmlFreeDoc(doc);
|
|
48 }
|
|
49
|
|
50 void Polygon::create_data(xmlNodePtr cur)
|
|
51 {
|
|
52 size = atoi((char *)xmlGetProp(cur,(xmlChar *)"size"));
|
|
53 name = (char *)xmlGetProp(cur,(xmlChar *)"name");
|
|
54 parent_name = (char *)xmlGetProp(cur,(xmlChar *)"parent");
|
|
55 next = NULL;
|
|
56
|
|
57 data = new float[size*3*3];
|
|
58
|
|
59 get_data(cur->children);
|
|
60 }
|
|
61
|
|
62 void Polygon::add_next()
|
|
63 {
|
|
64 Polygon *p;
|
|
65 p = new Polygon;
|
|
66
|
|
67 next = p;
|
|
68 }
|
|
69
|
|
70
|
|
71 void Polygon::get_data(xmlNodePtr cur)
|
|
72 {
|
|
73 char *cont;
|
|
74 HTaskPtr task_load_texture = NULL;
|
|
75 unsigned int fbdev_addr;
|
|
76 for(;cur;cur=cur->next) {
|
|
77 if(!xmlStrcmp(cur->name,(xmlChar*)"image")) {
|
|
78 char image_name[20] = "/tmp/image_XXXXXX";
|
|
79 int fd = mkstemp(image_name);
|
|
80 FILE *outfile = fdopen(fd, "wb");
|
|
81 if(NULL == outfile) {
|
|
82 cout << "error open file\n";
|
|
83 }
|
|
84 cont = (char *)xmlNodeGetContent(cur);
|
|
85 decode(cont, outfile);
|
|
86 fclose(outfile);
|
|
87
|
|
88 texture_image = IMG_Load(image_name);
|
|
89 //texture_image = SDL_LoadBMP(image_name);
|
|
90 if(unlink(image_name)) {
|
|
91 cout << "unlink error\n";
|
|
92 }
|
|
93
|
|
94 }
|
|
95 }
|
|
96
|
|
97 //void *_pixels = new Uint32[width*height*32/8];
|
|
98 void *_pixels;
|
|
99 posix_memalign((void**)&_pixels, 16, 3*128*128);
|
|
100
|
|
101 memcpy(_pixels, texture_image->pixels, 3*128*128);
|
|
102
|
|
103 // screen を返すけど、いつか free して
|
|
104 //screen = SDL_CreateRGBSurfaceFrom(_pixels, width, height, 32,
|
|
105 //width*4, redMask, greenMask,
|
|
106 // blueMask,alphaMask);
|
|
107
|
|
108 fbdev_addr = get_fbdev_addr();
|
|
109 task_load_texture
|
|
110 = manager->create_task(0,LOAD_TEXTURE_SIZE,
|
|
111 //(unsigned int)texture_image->pixels
|
|
112 (unsigned int)_pixels ,fbdev_addr,NULL);
|
|
113 task_load_texture->set_cpu(CPU_SPE);
|
|
114 task_load_texture->spawn();
|
|
115 }
|
|
116
|