00001 #include <cl.h>
00002
00008 bool clPrintEnum(const CLenum* e)
00009 {
00010 unsigned int i;
00011 unsigned int j;
00012
00013 char* x;
00014
00015 for (i = 0 ; i < sizeof(CLenum) ; i++)
00016 {
00017 x = (char *) e;
00018
00019 printf("%u:", i);
00020
00021 for (j = 0 ; j < 8 ; j++)
00022 {
00023 if(*x & (1<<j))
00024 printf("1");
00025 else
00026 printf("0");
00027 }
00028 printf("\t");
00029 x++;
00030 }
00031
00032 printf("\n");
00033
00034 return GL_TRUE;
00035 }
00036
00037
00038 bool clPrintColour(const CLcolour* colour)
00039 {
00040 CL_PRINTF("CLcolour{r = %f, g = %f, b = %f, a = %f}\n",
00041 colour->r, colour->g, colour->b, colour->a);
00042
00043 return GL_TRUE;
00044 }
00045
00046 bool clPrintVertex(const CLvertex* vertex)
00047 {
00048 CL_PRINTF("CLvertex{x = %f, y = %f, z = %f}\n",
00049 vertex->x, vertex->y, vertex->z);
00050
00051 return GL_TRUE;
00052 }
00053
00054 bool clPrintNormal(const CLnormal* normal)
00055 {
00056 CL_PRINTF("CLnormal{i = %f, j = %f, k = %f}\n",
00057 normal->i, normal->j, normal->k);
00058
00059 return GL_TRUE;
00060 }
00061
00062 bool clPrintTexCoord(const CLtexcoord* texcoord)
00063 {
00064 CL_PRINTF("CLtexcoord{s = %f, t = %f}\n", texcoord->s, texcoord->t);
00065
00066 return GL_TRUE;
00067 }
00068
00069 bool clPrintEdgeFlag(const CLedgeflag* edgeflag)
00070 {
00071 CL_PRINTF("CLedgeflag{%u}\n", *edgeflag);
00072
00073 return GL_TRUE;
00074 }
00075
00076 bool clPrintMatrix(const CLmatrix* matrix)
00077 {
00078 CL_PRINTF("CLmatrix{m00 = %f, m10 = %f, m20 = %f, m30 = %f,\n",
00079 matrix->m00, matrix->m10, matrix->m20, matrix->m30);
00080 CL_PRINTF(" m01 = %f, m11 = %f, m21 = %f, m31 = %f,\n",
00081 matrix->m01, matrix->m11, matrix->m21, matrix->m31);
00082 CL_PRINTF(" m02 = %f, m12 = %f, m22 = %f, m32 = %f,\n",
00083 matrix->m02, matrix->m12, matrix->m22, matrix->m32);
00084 CL_PRINTF(" m03 = %f, m13 = %f, m23 = %f, m33 = %f}\n",
00085 matrix->m03, matrix->m13, matrix->m23, matrix->m33);
00086
00087 return GL_TRUE;
00088 }
00089
00090 bool clPrintImage(const CLimage* image)
00091 {
00092 CL_PRINTF("CLimage\n{\n");
00093
00094 CL_PRINTF("width = %u\n", (unsigned int) image->width);
00095 CL_PRINTF("height = %u,\n", (unsigned int) image->height);
00096 CL_PRINTF("format = 0x%x,\n", (int) image->format);
00097 CL_PRINTF("type = 0x%x,\n", (int) image->type);
00098 CL_PRINTF("data = (not listed)\n}\n");
00099
00100 return GL_TRUE;
00101 }
00102
00103 bool clPrintLight(const CLlight* light)
00104 {
00105 CL_PRINTF("CLlight{\n");
00106
00107 CL_PRINTF("id = %u\n", (unsigned int) light->id);
00108
00109 CL_PRINTF("ambient = "); clPrintColour(&light->ambient);
00110 CL_PRINTF("diffuse = "); clPrintColour(&light->diffuse);
00111 CL_PRINTF("specular = "); clPrintColour(&light->specular);
00112 CL_PRINTF("position = [%f %f %f %f]\n", light->position[0],
00113 light->position[1], light->position[2], light->position[3]);
00114 CL_PRINTF("spot_direction = "); clPrintNormal(&light->spot_direction);
00115 CL_PRINTF("spot_exponent = %f\n", light->spot_exponent);
00116 CL_PRINTF("spot_cutoff = %f\n", light->spot_cutoff);
00117 CL_PRINTF("constant_attenuation = %f\n", light->constant_attenuation);
00118 CL_PRINTF("linear_attenuation = %f\n", light->linear_attenuation);
00119 CL_PRINTF("quadratic_attenuation = %f\n", light->quadratic_attenuation);
00120
00121 CL_PRINTF("display_list = %u\n}\n", (unsigned int) light->display_list);
00122
00123 return GL_TRUE;
00124 }
00125
00126 bool clPrintMaterial(const CLmaterial* material)
00127 {
00128 CL_PRINTF("CLmaterial{\n");
00129
00130 CL_PRINTF("face = %u\n", (unsigned int) material->face);
00131
00132 CL_PRINTF("ambient = "); clPrintColour(&material->ambient);
00133 CL_PRINTF("diffuse = "); clPrintColour(&material->diffuse);
00134 CL_PRINTF("specular = "); clPrintColour(&material->specular);
00135 CL_PRINTF("emission = "); clPrintColour(&material->emission);
00136 CL_PRINTF("shininess = %f\n", material->shininess);
00137
00138 CL_PRINTF("display_list = %u\n}\n", (unsigned int) material->display_list);
00139
00140 return GL_TRUE;
00141 }
00142
00143 bool clPrintTexture(const CLtexture* texture)
00144 {
00145 CL_PRINTF("CLtexture{\n");
00146
00147 CL_PRINTF("image = "); clPrintImage(&texture->image);
00148
00149 CL_PRINTF("min_filter = 0x%x\n", (unsigned int) texture->min_filter);
00150 CL_PRINTF("mag_filter = 0x%x\n", (unsigned int) texture->mag_filter);
00151
00152 CL_PRINTF("wrap_s = 0x%x\n", (unsigned int) texture->wrap_s);
00153 CL_PRINTF("wrap_t = 0x%x\n", (unsigned int) texture->wrap_t);
00154
00155 CL_PRINTF("texture_object = %u\n}\n", (unsigned int) texture->texture_object);
00156
00157 return GL_TRUE;
00158 }
00159
00160 bool clPrintPrimitiveSet(const CLprimitiveset* primitiveset)
00161 {
00162 unsigned int i;
00163
00164 CL_PRINTF("CLprimitiveset{\n");
00165
00166 CL_PRINTF("mode = %u\n", (unsigned int) primitiveset->mode);
00167
00168 CL_PRINTF("num_indices = %u\n", (unsigned int) primitiveset->num_indices);
00169
00170 if (primitiveset->num_indices == 0)
00171 {
00172 CL_PRINTF("indices = [(empty)]\n");
00173 }
00174 else
00175 {
00176 CL_PRINTF("indices = [%u, ", (unsigned int) primitiveset->indices[0]);
00177
00178 for (i = 1; i < primitiveset->num_indices - 1; i++)
00179 CL_PRINTF("%u, ", (unsigned int) primitiveset->indices[i]);
00180
00181 CL_PRINTF("%u]\n",
00182 (unsigned int) primitiveset->indices[primitiveset->num_indices - 1]);
00183 }
00184
00185 return GL_TRUE;
00186 }
00187
00188 bool clPrintMesh(const CLmesh* mesh)
00189 {
00190 unsigned int i;
00191
00192 CL_PRINTF("CLmesh{\n");
00193
00194 CL_PRINTF("context = %p\n", (void*)mesh->context);
00195
00196 if (!mesh->colour)
00197 {
00198 CL_PRINTF("colour = [(empty)]\n");
00199 }
00200 else
00201 {
00202 CL_PRINTF("colour = "); clPrintColour(mesh->colour);
00203 }
00204
00205 CL_PRINTF("material_index = %u\n", (unsigned int) mesh->material_index);
00206 CL_PRINTF("texture_index = %u\n", (unsigned int) mesh->texture_index);
00207 CL_PRINTF("texture_env_mode = %u\n", (unsigned int) mesh->texture_env_mode);
00208
00209 CL_PRINTF("num_vertices = %u\n", (unsigned int) mesh->num_vertices);
00210
00211 if (mesh->num_vertices == 0)
00212 {
00213 CL_PRINTF("vertices = [(empty)]\n");
00214 CL_PRINTF("colours = [(empty)]\n");
00215 CL_PRINTF("normals = [(empty)]\n");
00216 CL_PRINTF("texcoords = [(empty)]\n");
00217 CL_PRINTF("edgeflags = [(empty)]\n");
00218 }
00219 else
00220 {
00221 CL_PRINTF("vertices =\n[\n "); clPrintVertex(&mesh->vertices[0]);
00222
00223 for (i = 1; i < mesh->num_vertices; i++)
00224 {
00225 CL_PRINTF(", ");
00226 clPrintVertex(&mesh->vertices[i]);
00227 }
00228
00229 CL_PRINTF("]\n");
00230
00231 CL_PRINTF("colours = ");
00232
00233 if (!mesh->colours)
00234 {
00235 CL_PRINTF("[(empty)]\n");
00236 }
00237 else
00238 {
00239 CL_PRINTF("\n[\n "); clPrintColour(&mesh->colours[0]);
00240
00241 for (i = 1; i < mesh->num_vertices; i++)
00242 {
00243 CL_PRINTF(", ");
00244 clPrintColour(&mesh->colours[i]);
00245 }
00246
00247 CL_PRINTF("]\n");
00248 }
00249
00250 CL_PRINTF("normals = ");
00251
00252 if (!mesh->normals)
00253 {
00254 CL_PRINTF("[(empty)]\n");
00255 }
00256 else
00257 {
00258 CL_PRINTF("\n[\n "); clPrintNormal(&mesh->normals[0]);
00259
00260 for (i = 1; i < mesh->num_vertices; i++)
00261 {
00262 CL_PRINTF(", ");
00263 clPrintNormal(&mesh->normals[i]);
00264 }
00265
00266 CL_PRINTF("]\n");
00267 }
00268
00269 CL_PRINTF("texcoords = ");
00270
00271 if (!mesh->texcoords)
00272 {
00273 CL_PRINTF("[(empty)]\n");
00274 }
00275 else
00276 {
00277 CL_PRINTF("\n[\n "); clPrintTexCoord(&mesh->texcoords[0]);
00278
00279 for (i = 1; i < mesh->num_vertices; i++)
00280 {
00281 CL_PRINTF(", ");
00282 clPrintTexCoord(&mesh->texcoords[i]);
00283 }
00284
00285 CL_PRINTF("]\n");
00286 }
00287
00288 CL_PRINTF("edgeflags = ");
00289
00290 if (!mesh->edgeflags)
00291 {
00292 CL_PRINTF("[(empty)]\n");
00293 }
00294 else
00295 {
00296 CL_PRINTF("\n[\n "); clPrintEdgeFlag(&mesh->edgeflags[0]);
00297
00298 for (i = 1; i < mesh->num_vertices; i++)
00299 {
00300 CL_PRINTF(", ");
00301 clPrintEdgeFlag(&mesh->edgeflags[i]);
00302 }
00303
00304 CL_PRINTF("]\n");
00305 }
00306 }
00307
00308 CL_PRINTF("num_primitivesets = %u\n", (unsigned int) mesh->num_primitivesets);
00309
00310 if (mesh->num_primitivesets == 0)
00311 {
00312 CL_PRINTF("primitivesets = [(empty)]\n");
00313 }
00314 else
00315 {
00316 CL_PRINTF("primitivesets =\n[\n ");
00317 clPrintPrimitiveSet(mesh->primitivesets[0]);
00318
00319 for (i = 1; i < mesh->num_primitivesets; i++)
00320 {
00321 CL_PRINTF(", ");
00322 clPrintPrimitiveSet(mesh->primitivesets[i]);
00323 }
00324
00325 CL_PRINTF("]\n");
00326 }
00327
00328 CL_PRINTF("display_list = %u\n}\n", (unsigned int) mesh->display_list);
00329
00330 return GL_TRUE;
00331 }
00332
00333 bool clPrintContext(const CLcontext* context)
00334 {
00335 unsigned int i;
00336
00337 CL_PRINTF("CLcontext{\n");
00338
00339 CL_PRINTF("num_materials = %u\n", (unsigned int) context->num_materials);
00340
00341 if (context->num_materials == 0)
00342 {
00343 CL_PRINTF("materials = [(empty)]\n");
00344 }
00345 else
00346 {
00347 CL_PRINTF("materials =\n[\n "); clPrintMaterial(context->materials[0]);
00348
00349 for (i = 1; i < context->num_materials; i++)
00350 {
00351 CL_PRINTF(", ");
00352 clPrintMaterial(context->materials[i]);
00353 }
00354
00355 CL_PRINTF("]\n");
00356 }
00357
00358 CL_PRINTF("num_textures = %u\n", (unsigned int) context->num_textures);
00359
00360 if (context->num_textures == 0)
00361 {
00362 CL_PRINTF("textures = [(empty)]\n");
00363 }
00364 else
00365 {
00366 CL_PRINTF("textures =\n[\n "); clPrintTexture(context->textures[0]);
00367
00368 for (i = 1; i < context->num_textures; i++)
00369 {
00370 CL_PRINTF(", ");
00371 clPrintTexture(context->textures[i]);
00372 }
00373
00374 CL_PRINTF("]\n");
00375 }
00376
00377 CL_PRINTF("num_lights = %u\n", (unsigned int) context->num_lights);
00378
00379 if (context->num_lights == 0)
00380 {
00381 CL_PRINTF("lights = [(empty)]\n");
00382 }
00383 else
00384 {
00385 CL_PRINTF("lights =\n[\n "); clPrintLight(context->lights[0]);
00386
00387 for (i = 1; i < context->num_lights; i++)
00388 {
00389 CL_PRINTF(", ");
00390 clPrintLight(context->lights[i]);
00391 }
00392
00393 CL_PRINTF("]\n");
00394 }
00395
00396 CL_PRINTF("num_models = %u\n", (unsigned int) context->num_models);
00397
00398 if (context->num_models == 0)
00399 {
00400 CL_PRINTF("models = [(empty)]\n}\n");
00401 }
00402 else
00403 {
00404 CL_PRINTF("models =\n[\n "); clPrintModel(context->models[0]);
00405
00406 for (i = 1; i < context->num_models; i++)
00407 {
00408 CL_PRINTF(", ");
00409 clPrintModel(context->models[i]);
00410 }
00411
00412 CL_PRINTF("]\n}\n");
00413 }
00414
00415 return GL_TRUE;
00416 }
00417
00418 bool clPrintModel(const CLmodel* model)
00419 {
00420 unsigned int i;
00421
00422 CL_PRINTF("CLmodel{\n");
00423
00424 CL_PRINTF("context = %p\n", (void*)model->context);
00425
00426 CL_PRINTF("num_meshes = %u\n", (unsigned int) model->num_meshes);
00427
00428 if (model->num_meshes == 0)
00429 {
00430 CL_PRINTF("meshes = [(empty)]\n");
00431 }
00432 else
00433 {
00434 CL_PRINTF("meshes = \n[\n "); clPrintMesh(model->meshes[0]);
00435
00436 for (i = 1; i < model->num_meshes; i++)
00437 {
00438 CL_PRINTF(", ");
00439 clPrintMesh(model->meshes[i]);
00440 }
00441
00442 CL_PRINTF("]\n}\n");
00443 }
00444
00445 return GL_TRUE;
00446 }
00447
00453 bool clPrintModelSummary(const CLmodel* model)
00454 {
00455 unsigned int i;
00456 unsigned int j;
00457 unsigned int zero_vertices = 0;
00458 unsigned int num_colours = 0;
00459 unsigned int zero_colours = 0;
00460 unsigned int num_normals = 0;
00461 unsigned int zero_normals = 0;
00462 unsigned int num_texcoords = 0;
00463 unsigned int zero_texcoords = 0;
00464
00465 CL_PRINTF("Model Summary\n");
00466
00467 CL_PRINTF("context = %p\n", (void*)model->context);
00468
00469 CL_PRINTF("num_meshes = %u\n", (unsigned int) model->num_meshes);
00470
00471 for (j = 0 ; j < model->num_meshes ; j++)
00472 {
00473
00474 zero_vertices = 0;
00475 for (i = 0 ; i < model->meshes[j]->num_vertices ; i++)
00476 {
00477 if (model->meshes[j]->vertices[i].x == 0 && model->meshes[j]->vertices[i].y == 0 && model->meshes[j]->vertices[i].z == 0)
00478 {
00479 zero_vertices++;
00480 }
00481 }
00482
00483
00484 if (model->meshes[j]->colours)
00485 {
00486 num_colours = model->meshes[j]->num_vertices;
00487 }
00488 else
00489 {
00490 num_colours = 0;
00491 }
00492
00493 zero_colours = 0;
00494 for (i = 0 ; i < num_colours ; i++)
00495 {
00496 if (model->meshes[j]->colours[i].r == 0 && model->meshes[j]->colours[i].g == 0 && model->meshes[j]->colours[i].b == 0 && model->meshes[j]->colours[i].a == 0)
00497 {
00498 zero_colours++;
00499 }
00500 }
00501
00502
00503 if (model->meshes[j]->normals)
00504 {
00505 num_normals = model->meshes[j]->num_vertices;
00506 }
00507 else
00508 {
00509 num_normals = 0;
00510 }
00511
00512 zero_normals = 0;
00513 for (i = 0 ; i < num_normals ; i++)
00514 {
00515 if (model->meshes[j]->normals[i].i == 0 && model->meshes[j]->normals[i].j == 0 && model->meshes[j]->normals[i].k == 0);
00516 {
00517 zero_normals++;
00518 }
00519 }
00520
00521
00522 if (model->meshes[j]->texcoords)
00523 {
00524 num_texcoords = model->meshes[j]->num_vertices;
00525 }
00526 else
00527 {
00528 num_texcoords = 0;
00529 }
00530
00531 zero_texcoords = 0;
00532 for (i = 0 ; i < num_texcoords ; i++)
00533 {
00534
00535 if ((model->meshes[j]->texcoords[i].s == 0.0f) && (model->meshes[j]->texcoords[i].t == 0.0f))
00536 {
00537 zero_texcoords++;
00538
00539 }
00540 }
00541
00542 printf("mesh %u has %u verts (%u zero)\t%u colours(%u zero)\t%u normals (%u zero)\t%u texcoords (%u zero), tex_index %u\n", j, (unsigned int) model->meshes[j]->num_vertices, zero_vertices, num_colours, zero_colours, num_normals, zero_normals, num_texcoords, zero_texcoords, (unsigned int) model->meshes[j]->texture_index);
00543 }
00544 return GL_TRUE;
00545 }
00546
00550 bool clPrintContextSummary(const CLcontext* context)
00551 {
00552 unsigned int i;
00553
00554 printf("context has %u materials\n", (unsigned int) context->num_materials);
00555 for (i = 0 ; i < context->num_materials ; i++)
00556 {
00557 printf(" - material %u : %p\n", i, (void*)context->materials[i]);
00558 }
00559
00560 return GL_TRUE;
00561 }