Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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