From patchwork Thu Jul 21 12:36:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandros Frantzis X-Patchwork-Id: 2945 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id B749923F4D for ; Thu, 21 Jul 2011 12:42:31 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id 6F627A18287 for ; Thu, 21 Jul 2011 12:42:31 +0000 (UTC) Received: by mail-qw0-f52.google.com with SMTP id 8so853237qwb.11 for ; Thu, 21 Jul 2011 05:42:31 -0700 (PDT) Received: by 10.229.25.212 with SMTP id a20mr174055qcc.148.1311252151215; Thu, 21 Jul 2011 05:42:31 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs139501qcb; Thu, 21 Jul 2011 05:42:31 -0700 (PDT) Received: by 10.216.62.195 with SMTP id y45mr216343wec.15.1311251795117; Thu, 21 Jul 2011 05:36:35 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id y42si2384146weq.81.2011.07.21.05.36.34; Thu, 21 Jul 2011 05:36:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QjsUS-0000Cj-Q0 for ; Thu, 21 Jul 2011 12:36:33 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 026B72E895B for ; Thu, 21 Jul 2011 12:36:31 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: glmark2 X-Launchpad-Branch: ~glmark2-dev/glmark2/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 15 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 15: Clean up code. Message-Id: <20110721123631.17019.57669.launchpad@loganberry.canonical.com> Date: Thu, 21 Jul 2011 12:36:31 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13475"; Instance="initZopeless config overlay" X-Launchpad-Hash: 0585ba4e6f5bd929e75d43daf615d3e0d4a1faf6 ------------------------------------------------------------ revno: 15 committer: Alexandros Frantzis timestamp: Thu 2010-07-08 13:39:44 +0300 message: Clean up code. modified: model.cpp texture.cpp --- lp:glmark2 https://code.launchpad.net/~glmark2-dev/glmark2/trunk You are subscribed to branch lp:glmark2. To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription === modified file 'model.cpp' --- model.cpp 2010-07-07 10:32:18 +0000 +++ model.cpp 2010-07-08 10:39:44 +0000 @@ -29,15 +29,15 @@ pMesh->mVertexQty = 3 * mPolygonQty; pMesh->mPolygonQty = mPolygonQty; pMesh->mMode = GL_TRIANGLES; - + pMesh->mVertex = new Vertex[pMesh->mVertexQty]; - + for(unsigned i = 0; i < pMesh->mVertexQty; i += 3) { pMesh->mVertex[i + 0].v = mVertex[mPolygon[i / 3].mA].v; pMesh->mVertex[i + 1].v = mVertex[mPolygon[i / 3].mB].v; pMesh->mVertex[i + 2].v = mVertex[mPolygon[i / 3].mC].v; - + pMesh->mVertex[i + 0].n = mVertex[mPolygon[i / 3].mA].n; pMesh->mVertex[i + 1].n = mVertex[mPolygon[i / 3].mB].n; pMesh->mVertex[i + 2].n = mVertex[mPolygon[i / 3].mC].n; @@ -46,7 +46,7 @@ pMesh->mVertex[i + 1].t = mVertex[mPolygon[i / 3].mB].t; pMesh->mVertex[i + 2].t = mVertex[mPolygon[i / 3].mC].t; } - + #ifdef _DEBUG printf("[ Done ]\n"); #endif @@ -79,7 +79,7 @@ { Vector3f center; Vector3f max = mVertex[0].v, min = mVertex[0].v; - + for(unsigned i = 1; i < mVertexQty; i++) { if(mVertex[i].v.x > max.x) max.x = mVertex[i].v.x; @@ -105,150 +105,143 @@ int Model::load_3ds(const char *pFileName) { + int i; + FILE *l_file; + unsigned short l_chunk_id; + unsigned int l_chunk_length; + unsigned char l_char; + unsigned short l_qty; + size_t nread; + #ifdef _DEBUG printf("Loading model from 3ds file... "); #endif - int i; //Index variable - - FILE *l_file; //File pointer - - unsigned short l_chunk_id; //Chunk identifier - unsigned int l_chunk_lenght; //Chunk lenght - - unsigned char l_char; //Char variable - unsigned short l_qty; //Number of elements in each chunk - - if ((l_file=fopen (pFileName, "rb"))== NULL) - { + + if ((l_file=fopen (pFileName, "rb"))== NULL) { #ifdef _DEBUG - printf("[ Fail ]\n"); + printf("[ Fail ]\n"); #else printf("Could not open 3ds file\n"); #endif - return 0; - } - - while (ftell (l_file) < filelength (fileno (l_file))) //Loop to scan the whole file - //while(!EOF) - { - //getch(); //Insert this command for debug (to wait for keypress for each chuck reading) - - fread (&l_chunk_id, 2, 1, l_file); //Read the chunk header - fread (&l_chunk_lenght, 4, 1, l_file); //Read the lenght of the chunk - - switch (l_chunk_id) + return 0; + } + + // Loop to scan the whole file + while (ftell (l_file) < filelength (fileno (l_file))) { + // Read the chunk header + nread = fread (&l_chunk_id, 2, 1, l_file); + //Read the lenght of the chunk + nread = fread (&l_chunk_length, 4, 1, l_file); + + switch (l_chunk_id) { - //----------------- MAIN3DS ----------------- - // Description: Main chunk, contains all the other chunks - // Chunk ID: 4d4d - // Chunk Lenght: 0 + sub chunks - //------------------------------------------- - case 0x4d4d: - break; - - //----------------- EDIT3DS ----------------- - // Description: 3D Editor chunk, objects layout info - // Chunk ID: 3d3d (hex) - // Chunk Lenght: 0 + sub chunks - //------------------------------------------- - case 0x3d3d: - break; - - //--------------- EDIT_OBJECT --------------- - // Description: Object block, info for each object - // Chunk ID: 4000 (hex) - // Chunk Lenght: len(object name) + sub chunks - //------------------------------------------- - case 0x4000: - i=0; - do - { - fread (&l_char, 1, 1, l_file); + //----------------- MAIN3DS ----------------- + // Description: Main chunk, contains all the other chunks + // Chunk ID: 4d4d + // Chunk Lenght: 0 + sub chunks + //------------------------------------------- + case 0x4d4d: + break; + + //----------------- EDIT3DS ----------------- + // Description: 3D Editor chunk, objects layout info + // Chunk ID: 3d3d (hex) + // Chunk Lenght: 0 + sub chunks + //------------------------------------------- + case 0x3d3d: + break; + + //--------------- EDIT_OBJECT --------------- + // Description: Object block, info for each object + // Chunk ID: 4000 (hex) + // Chunk Lenght: len(object name) + sub chunks + //------------------------------------------- + case 0x4000: + i = 0; + do { + nread = fread (&l_char, 1, 1, l_file); mName[i] = l_char; - i++; + i++; } while(l_char != '\0' && i<20); - break; - - //--------------- OBJ_TRIMESH --------------- - // Description: Triangular mesh, contains chunks for 3d mesh info - // Chunk ID: 4100 (hex) - // Chunk Lenght: 0 + sub chunks - //------------------------------------------- - case 0x4100: - break; - - //--------------- TRI_VERTEXL --------------- - // Description: Vertices list - // Chunk ID: 4110 (hex) - // Chunk Lenght: 1 x unsigned short (number of vertices) - // + 3 x float (vertex coordinates) x (number of vertices) - // + sub chunks - //------------------------------------------- - case 0x4110: - fread (&l_qty, sizeof (unsigned short), 1, l_file); + break; + + //--------------- OBJ_TRIMESH --------------- + // Description: Triangular mesh, contains chunks for 3d mesh info + // Chunk ID: 4100 (hex) + // Chunk Lenght: 0 + sub chunks + //------------------------------------------- + case 0x4100: + break; + + //--------------- TRI_VERTEXL --------------- + // Description: Vertices list + // Chunk ID: 4110 (hex) + // Chunk Lenght: 1 x unsigned short (number of vertices) + // + 3 x float (vertex coordinates) x (number of vertices) + // + sub chunks + //------------------------------------------- + case 0x4110: + nread = fread (&l_qty, sizeof (unsigned short), 1, l_file); mVertexQty = l_qty; mVertex = new Vertex[mVertexQty]; - for (i=0; iw & (surface->w - 1)) != 0) printf("warning: image.bmp's width is not a power of 2\n"); @@ -15,24 +14,20 @@ printf("warning: image.bmp's height is not a power of 2\n"); nOfColors = surface->format->BytesPerPixel; - if (nOfColors == 4) - { + if (nOfColors == 4) { if (surface->format->Rmask == 0x000000ff) texture_format = GL_RGBA; else texture_format = GL_BGRA; } - else - { - if (nOfColors == 3) - { + else { + if (nOfColors == 3) { if (surface->format->Rmask == 0x000000ff) texture_format = GL_RGB; else texture_format = GL_BGR; } - else - { + else { printf("warning: the image is not truecolor.. this will probably break\n"); } } @@ -40,49 +35,28 @@ glGenTextures(3, pTexture); // Create Nearest Filtered Texture - glBindTexture(GL_TEXTURE_2D, pTexture[0]); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels); - - // Create Linear Filtered Texture - glBindTexture(GL_TEXTURE_2D, pTexture[1]); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels); + glBindTexture(GL_TEXTURE_2D, pTexture[0]); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0, + texture_format, GL_UNSIGNED_BYTE, surface->pixels); + + // Create Linear Filtered Texture + glBindTexture(GL_TEXTURE_2D, pTexture[1]); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0, + texture_format, GL_UNSIGNED_BYTE, surface->pixels); // Create MipMapped Texture - glBindTexture(GL_TEXTURE_2D, pTexture[2]); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); - - gluBuild2DMipmaps(GL_TEXTURE_2D, 3, surface->w, surface->h, texture_format, GL_UNSIGNED_BYTE, surface->pixels); - -/* - switch (filter) - { - case 0: - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels); - break; - - case 1: - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels); - break; - - case 2: - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - gluBuild2DMipmaps(GL_TEXTURE_2D, 3, surface->w, surface->h, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels); - break; - } -*/ + glBindTexture(GL_TEXTURE_2D, pTexture[2]); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); + + gluBuild2DMipmaps(GL_TEXTURE_2D, 3, surface->w, surface->h, + texture_format, GL_UNSIGNED_BYTE, surface->pixels); } - else - { + else { fprintf(stderr, "SDL could not load image.bmp: %s\n", SDL_GetError()); return 0; }