Render_LoadTextureDDS.cpp
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 Filename    :   WavPlayer_OSX.h
00004 Content     :   A DDS file loader for cross-platform compressed texture support.
00005 Created     :   March 5, 2013
00006 Authors     :   Peter Hoff, Dan Goodman, Bryan Croteau
00007 
00008 Copyright   :   Copyright 2013 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 #include "Render_Device.h"
00024 
00025 #ifdef OVR_DEFINE_NEW
00026 #undef new
00027 #endif
00028 
00029 namespace OVR { namespace Render {
00030 
00031 static const UPInt OVR_DDS_PF_FOURCC = 0x4;
00032 static const UInt32 OVR_DTX1_MAGIC_NUMBER = 827611204;
00033 static const UInt32 OVR_DTX5_MAGIC_NUMBER = 894720068;
00034 
00035 struct OVR_DDS_PIXELFORMAT
00036 {
00037     UInt32 Size;
00038     UInt32 Flags;
00039     UInt32 FourCC;
00040     UInt32 RGBBitCount;
00041     UInt32 RBitMask;
00042     UInt32 GBitMask;
00043     UInt32 BBitMask;
00044     UInt32 ABitMask;
00045 };
00046 
00047 struct OVR_DDS_HEADER
00048 {
00049     UInt32                              Size;
00050     UInt32                              Flags;
00051     UInt32                              Height;
00052     UInt32                              Width;
00053     UInt32                              PitchOrLinearSize;
00054     UInt32                              Depth;
00055     UInt32                              MipMapCount;
00056     UInt32                              Reserved1[11];
00057     OVR_DDS_PIXELFORMAT PixelFormat;
00058     UInt32                              Caps;
00059     UInt32                              Caps2;
00060     UInt32                              Caps3;
00061     UInt32                              Caps4;
00062     UInt32                              Reserved2;
00063 };
00064 
00065 Texture* LoadTextureDDS(RenderDevice* ren, File* f)
00066 {
00067     OVR_DDS_HEADER header;
00068     unsigned char filecode[4];
00069 
00070     f->Read(filecode, 4);
00071     if (strncmp((const char*)filecode, "DDS ", 4) != 0)
00072     {
00073         return NULL;
00074     }
00075 
00076     f->Read((unsigned char*)(&header), sizeof(header));
00077 
00078     int width = header.Width;
00079     int height = header.Height;
00080 
00081     int format = 0;
00082 
00083     UInt32 mipCount = header.MipMapCount;
00084     if(mipCount <= 0)
00085     {
00086         mipCount = 1;
00087     }
00088     if(header.PixelFormat.Flags & OVR_DDS_PF_FOURCC)
00089     {
00090         if(header.PixelFormat.FourCC == OVR_DTX1_MAGIC_NUMBER)
00091         {
00092             format = Texture_DXT1;
00093         }
00094         else if(header.PixelFormat.FourCC == OVR_DTX5_MAGIC_NUMBER)
00095         {
00096             format = Texture_DXT5;
00097         }
00098         else
00099         {
00100             return NULL;
00101         }
00102     }
00103 
00104     int            byteLen = f->BytesAvailable();
00105     unsigned char* bytes   = new unsigned char[byteLen];
00106     f->Read(bytes, byteLen);
00107     Texture* out = ren->CreateTexture(format, (int)width, (int)height, bytes, mipCount);
00108     if(strstr(f->GetFilePath(), "_c."))
00109     {
00110         out->SetSampleMode(Sample_Clamp);
00111     }
00112     OVR_FREE(bytes);
00113     return out;
00114 }
00115 
00116 
00117 }}
00118 
00119 #ifdef OVR_DEFINE_NEW
00120 #define new OVR_DEFINE_NEW
00121 #endif


oculus_sdk
Author(s): Tully Foote
autogenerated on Thu Jun 6 2019 20:13:49