Render_LoadTextureTGA.cpp
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 Filename    :   Render_LoadeTextureTGA.cpp
00004 Content     :   Loading of TGA implementation
00005 Created     :   October, 2012
00006 Authors     :   Andrew Reisse
00007 
00008 Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.
00009 
00010 Licensed under the Apache License, Version 2.0 (the "License");
00011 you may not use this file except in compliance with the License.
00012 You may obtain a copy of the License at
00013 
00014 http://www.apache.org/licenses/LICENSE-2.0
00015 
00016 Unless required by applicable law or agreed to in writing, software
00017 distributed under the License is distributed on an "AS IS" BASIS,
00018 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019 See the License for the specific language governing permissions and
00020 limitations under the License.
00021 
00022 ************************************************************************************/
00023 
00024 
00025 #include "Render_Device.h"
00026 
00027 namespace OVR { namespace Render {
00028 
00029 Texture* LoadTextureTga(RenderDevice* ren, File* f, unsigned char alpha)
00030 {
00031     f->SeekToBegin();
00032     
00033     int desclen = f->ReadUByte();
00034     int palette = f->ReadUByte();
00035     OVR_UNUSED(palette);
00036     int imgtype = f->ReadUByte();
00037     f->ReadUInt16();
00038     int palCount = f->ReadUInt16();
00039     int palSize = f->ReadUByte();
00040     f->ReadUInt16();
00041     f->ReadUInt16();
00042     int width = f->ReadUInt16();
00043     int height = f->ReadUInt16();
00044     int bpp = f->ReadUByte();
00045     f->ReadUByte();
00046     int imgsize = width * height * 4;
00047     unsigned char* imgdata = (unsigned char*) OVR_ALLOC(imgsize);
00048     unsigned char buf[16];
00049     f->Read(imgdata, desclen);
00050     f->Read(imgdata, palCount * (palSize + 7) >> 3);
00051     int bpl = width * 4;
00052 
00053     switch (imgtype)
00054     {
00055     case 2:
00056         switch (bpp)
00057         {
00058         case 24:
00059             for (int y = 0; y < height; y++)
00060                 for (int x = 0; x < width; x++)
00061                 {
00062                     f->Read(buf, 3);
00063                     imgdata[y*bpl+x*4+0] = buf[2];
00064                     imgdata[y*bpl+x*4+1] = buf[1];
00065                     imgdata[y*bpl+x*4+2] = buf[0];
00066                     imgdata[y*bpl+x*4+3] = alpha;
00067                 }
00068             break;
00069         case 32:
00070             for (int y = 0; y < height; y++)
00071                 for (int x = 0; x < width; x++)
00072                 {
00073                     f->Read(buf, 4);
00074                     imgdata[y*bpl+x*4+0] = buf[2];
00075                     imgdata[y*bpl+x*4+1] = buf[1];
00076                     imgdata[y*bpl+x*4+2] = buf[0];
00077                     if (buf[3] == 255)
00078                         imgdata[y*bpl+x*4+3] = alpha;
00079                     else
00080                     imgdata[y*bpl+x*4+3] = buf[3];
00081                 }
00082             break;
00083 
00084         default:
00085             OVR_FREE(imgdata);
00086             return NULL;
00087         }
00088         break;
00089 
00090     default:
00091         OVR_FREE(imgdata);
00092         return NULL;
00093     }
00094 
00095         Texture* out = ren->CreateTexture(Texture_RGBA|Texture_GenMipmaps, width, height, imgdata);
00096 
00097         // check for clamp based on texture name
00098         if(strstr(f->GetFilePath(), "_c."))
00099         {
00100                 out->SetSampleMode(Sample_Clamp);
00101         }
00102 
00103     OVR_FREE(imgdata);
00104     return out;
00105 }
00106 
00107 }}


oculus_sdk
Author(s):
autogenerated on Fri Aug 28 2015 11:53:11