This commit is contained in:
richgel99@gmail.com
2011-12-27 21:18:07 +00:00
commit 9f98ea7e22
192 changed files with 77747 additions and 0 deletions
+720
View File
@@ -0,0 +1,720 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="example2"
ProjectGUID="{AF745B42-F996-49EB-859B-970A671DEF5E}"
RootNamespace="comp"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="..\bin"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\inc"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="false"
ExceptionHandling="0"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
RuntimeTypeInfo="false"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;$(SolutionDir)lib\VC9\$(ConfigurationName)\$(PlatformName)\crnlibD_VC9.lib&quot;"
OutputFile="$(OutDir)\$(ProjectName)D.exe"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="..\bin"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\inc"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="false"
ExceptionHandling="0"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
RuntimeTypeInfo="false"
UsePrecompiledHeader="0"
WarningLevel="4"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;$(SolutionDir)lib\VC9\$(ConfigurationName)\$(PlatformName)\crnlibD_x64_VC9.lib&quot;"
OutputFile="$(OutDir)\$(ProjectName)D_x64.exe"
LinkIncremental="2"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="..\bin"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="3"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\inc"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
ExceptionHandling="0"
RuntimeLibrary="0"
BufferSecurityCheck="false"
RuntimeTypeInfo="false"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;$(SolutionDir)lib\VC9\$(ConfigurationName)\$(PlatformName)\crnlib_VC9.lib&quot;"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="..\bin"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="3"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\inc"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
ExceptionHandling="0"
RuntimeLibrary="0"
BufferSecurityCheck="false"
FloatingPointModel="2"
RuntimeTypeInfo="false"
UsePrecompiledHeader="0"
WarningLevel="4"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;$(SolutionDir)lib\VC9\$(ConfigurationName)\$(PlatformName)\crnlib_x64_VC9.lib&quot;"
OutputFile="$(OutDir)\$(ProjectName)_x64.exe"
LinkIncremental="1"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug_DLL|Win32"
OutputDirectory="..\bin"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\inc"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="false"
ExceptionHandling="0"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
RuntimeTypeInfo="false"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;$(SolutionDir)lib\VC9\$(ConfigurationName)\$(PlatformName)\crnlibD_DLL_VC9.lib&quot;"
OutputFile="$(OutDir)\$(ProjectName)D_DLL.exe"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug_DLL|x64"
OutputDirectory="..\bin"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\inc"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="false"
ExceptionHandling="0"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
RuntimeTypeInfo="false"
UsePrecompiledHeader="0"
WarningLevel="4"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;$(SolutionDir)lib\VC9\$(ConfigurationName)\$(PlatformName)\crnlibD_DLL_x64_VC9.lib&quot;"
OutputFile="$(OutDir)\$(ProjectName)D_DLL_x64.exe"
LinkIncremental="2"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release_DLL|Win32"
OutputDirectory="..\bin"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="3"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\inc"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
ExceptionHandling="0"
RuntimeLibrary="2"
BufferSecurityCheck="false"
RuntimeTypeInfo="false"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;$(SolutionDir)lib\VC9\$(ConfigurationName)\$(PlatformName)\crnlib_DLL_VC9.lib&quot;"
OutputFile="$(OutDir)\$(ProjectName)_DLL.exe"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release_DLL|x64"
OutputDirectory="..\bin"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="3"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\inc"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
ExceptionHandling="0"
RuntimeLibrary="2"
BufferSecurityCheck="false"
FloatingPointModel="2"
RuntimeTypeInfo="false"
UsePrecompiledHeader="0"
WarningLevel="4"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;$(SolutionDir)lib\VC9\$(ConfigurationName)\$(PlatformName)\crnlib_DLL_x64_VC9.lib&quot;"
OutputFile="$(OutDir)\$(ProjectName)_DLL_x64.exe"
LinkIncremental="1"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F2-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\example2.cpp"
>
</File>
<File
RelativePath=".\timer.cpp"
>
</File>
<File
RelativePath=".\timer.h"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995384-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{61DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
+277
View File
@@ -0,0 +1,277 @@
// File: example2.cpp - This example uses the crn_decomp.h stand-alone header file library
// to transcode .CRN files directly to .DDS, with no intermediate recompression step to DXTn.
// This tool does NOT depend on the crnlib library at all. It only needs the low-level
// decompression/transcoding functionality defined in inc/crn_decomp.h.
// This is the basic functionality a game engine would need to employ at runtime to utilize
// .CRN textures.
// See Copyright Notice and license at the end of inc/crnlib.h
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <algorithm>
// CRN transcoder library.
#include "crn_decomp.h"
// .DDS file format definitions.
#include "dds_defs.h"
// A simple high-precision, platform independent timer class.
#include "timer.h"
using namespace crnlib;
static int print_usage()
{
printf("Description: Transcodes .CRN to .DDS files using crn_decomp.h.\n");
printf("Copyright (c) 2010-2011 Tenacious Software LLC\n");
printf("Usage: example2 [source_file] [options]\n");
printf("\nOptions:\n");
printf("-out filename - Force output filename.\n");
return EXIT_FAILURE;
}
static int error(const char* pMsg, ...)
{
va_list args;
va_start(args, pMsg);
char buf[512];
vsprintf_s(buf, sizeof(buf), pMsg, args);
va_end(args);
printf("%s", buf);
return EXIT_FAILURE;
}
// Loads an entire file into an allocated memory block.
static crn_uint8 *read_file_into_buffer(const char *pFilename, crn_uint32 &size)
{
size = 0;
FILE* pFile = NULL;
fopen_s(&pFile, pFilename, "rb");
if (!pFile)
return NULL;
fseek(pFile, 0, SEEK_END);
size = ftell(pFile);
fseek(pFile, 0, SEEK_SET);
crn_uint8 *pSrc_file_data = static_cast<crn_uint8*>(malloc(std::max(1U, size)));
if ((!pSrc_file_data) || (fread(pSrc_file_data, size, 1, pFile) != 1))
{
fclose(pFile);
free(pSrc_file_data);
size = 0;
return NULL;
}
fclose(pFile);
return pSrc_file_data;
}
int main(int argc, char *argv[])
{
printf("example2 - Version v%u.%02u Built " __DATE__ ", " __TIME__ "\n", CRNLIB_VERSION / 100, CRNLIB_VERSION % 100);
if (argc < 2)
return print_usage();
// Parse command line options
const char *pSrc_filename = argv[1];
char out_filename[FILENAME_MAX] = { '\0' };
for (int i = 2; i < argc; i++)
{
if (argv[i][0] == '/')
argv[i][0] = '-';
if (!_stricmp(argv[i], "-out"))
{
if (++i >= argc)
return error("Expected output filename!");
strcpy_s(out_filename, sizeof(out_filename), argv[i]);
}
else
return error("Invalid option: %s\n", argv[i]);
}
// Split the source filename into its various components.
char drive_buf[_MAX_DRIVE], dir_buf[_MAX_DIR], fname_buf[_MAX_FNAME], ext_buf[_MAX_EXT];
if (_splitpath_s(pSrc_filename, drive_buf, _MAX_DRIVE, dir_buf, _MAX_DIR, fname_buf, _MAX_FNAME, ext_buf, _MAX_EXT))
return error("Invalid source filename!\n");
// Load the source file into memory.
printf("Loading source file: %s\n", pSrc_filename);
crn_uint32 src_file_size;
crn_uint8 *pSrc_file_data = read_file_into_buffer(pSrc_filename, src_file_size);
if (!pSrc_file_data)
return error("Unable to read source file\n");
// Decompress/transcode CRN to DDS.
// DDS files are organized in face-major order, like this:
// Face0: Mip0, Mip1, Mip2, etc.
// Face1: Mip0, Mip1, Mip2, etc.
// etc.
// While CRN files are organized in mip-major order, like this:
// Mip0: Face0, Face1, Face2, Face3, Face4, Face5
// Mip1: Face0, Face1, Face2, Face3, Face4, Face5
// etc.
printf("Transcoding CRN to DDS\n");
crnd::crn_texture_info tex_info;
if (!crnd::crnd_get_texture_info(pSrc_file_data, src_file_size, &tex_info))
{
free(pSrc_file_data);
return error("crnd_get_texture_info() failed!\n");
}
timer tm;
tm.start();
crnd::crnd_unpack_context pContext = crnd::crnd_unpack_begin(pSrc_file_data, src_file_size);
double total_unpack_begin_time = tm.get_elapsed_ms();
if (!pContext)
{
free(pSrc_file_data);
return error("crnd_unpack_begin() failed!\n");
}
// Now create the DDS file.
char dst_filename[FILENAME_MAX];
sprintf_s(dst_filename, sizeof(dst_filename), "%s%s%s.dds", drive_buf, dir_buf, fname_buf);
if (out_filename[0]) strcpy(dst_filename, out_filename);
printf("Writing DDS file: %s\n", dst_filename);
FILE *pDDS_file = fopen(dst_filename, "wb");
if (!pDDS_file)
{
crnd::crnd_unpack_end(pContext);
free(pSrc_file_data);
return error("Failed creating destination file!\n");
}
// Write the 4-byte DDS signature (not endian safe, but whatever this is a sample).
fwrite(&crnlib::cDDSFileSignature, sizeof(crnlib::cDDSFileSignature), 1, pDDS_file);
// Prepare the DDS header.
crnlib::DDSURFACEDESC2 dds_desc;
memset(&dds_desc, 0, sizeof(dds_desc));
dds_desc.dwSize = sizeof(dds_desc);
dds_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | ((tex_info.m_levels > 1) ? DDSD_MIPMAPCOUNT : 0);
dds_desc.dwWidth = tex_info.m_width;
dds_desc.dwHeight = tex_info.m_height;
dds_desc.dwMipMapCount = (tex_info.m_levels > 1) ? tex_info.m_levels : 0;
dds_desc.ddpfPixelFormat.dwSize = sizeof(crnlib::DDPIXELFORMAT);
dds_desc.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
crn_format fundamental_fmt = crnd::crnd_get_fundamental_dxt_format(tex_info.m_format);
dds_desc.ddpfPixelFormat.dwFourCC = crnd::crnd_crn_format_to_fourcc(fundamental_fmt);
if (fundamental_fmt != tex_info.m_format)
{
dds_desc.ddpfPixelFormat.dwRGBBitCount = crnd::crnd_crn_format_to_fourcc(tex_info.m_format);
}
dds_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
if (tex_info.m_levels > 1)
{
dds_desc.ddsCaps.dwCaps |= (DDSCAPS_COMPLEX | DDSCAPS_MIPMAP);
}
if (tex_info.m_faces == 6)
{
dds_desc.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP |
DDSCAPS2_CUBEMAP_POSITIVEX | DDSCAPS2_CUBEMAP_NEGATIVEX | DDSCAPS2_CUBEMAP_POSITIVEY |
DDSCAPS2_CUBEMAP_NEGATIVEY | DDSCAPS2_CUBEMAP_POSITIVEZ | DDSCAPS2_CUBEMAP_NEGATIVEZ;
}
// Write the DDS header to the output file.
fwrite(&dds_desc, sizeof(dds_desc), 1, pDDS_file);
// Now transcode all face and mipmap levels into memory, one mip level at a time.
void *pImages[cCRNMaxFaces][cCRNMaxLevels];
crn_uint32 image_size_in_bytes[cCRNMaxLevels];
memset(pImages, 0, sizeof(pImages));
memset(image_size_in_bytes, 0, sizeof(image_size_in_bytes));
crn_uint32 total_unpacked_texels = 0;
double total_unpack_time = 0.0f;
for (crn_uint32 level_index = 0; level_index < tex_info.m_levels; level_index++)
{
// Compute the face's width, height, number of DXT blocks per row/col, etc.
const crn_uint32 width = std::max(1U, tex_info.m_width >> level_index);
const crn_uint32 height = std::max(1U, tex_info.m_height >> level_index);
const crn_uint32 blocks_x = std::max(1U, (width + 3) >> 2);
const crn_uint32 blocks_y = std::max(1U, (height + 3) >> 2);
const crn_uint32 row_pitch = blocks_x * crnd::crnd_get_bytes_per_dxt_block(tex_info.m_format);
const crn_uint32 total_face_size = row_pitch * blocks_y;
image_size_in_bytes[level_index] = total_face_size;
for (crn_uint32 face_index = 0; face_index < tex_info.m_faces; face_index++)
{
void *p = malloc(total_face_size);
if (!p)
{
for (crn_uint32 f = 0; f < cCRNMaxFaces; f++)
for (crn_uint32 l = 0; l < cCRNMaxLevels; l++)
free(pImages[f][l]);
crnd::crnd_unpack_end(pContext);
free(pSrc_file_data);
return error("Out of memory!");
}
pImages[face_index][level_index] = p;
}
// Prepare the face pointer array needed by crnd_unpack_level().
void *pDecomp_images[cCRNMaxFaces];
for (crn_uint32 face_index = 0; face_index < tex_info.m_faces; face_index++)
pDecomp_images[face_index] = pImages[face_index][level_index];
// Now transcode the level to raw DXTn
tm.start();
if (!crnd::crnd_unpack_level(pContext, pDecomp_images, total_face_size, row_pitch, level_index))
{
for (crn_uint32 f = 0; f < cCRNMaxFaces; f++)
for (crn_uint32 l = 0; l < cCRNMaxLevels; l++)
free(pImages[f][l]);
crnd::crnd_unpack_end(pContext);
free(pSrc_file_data);
return error("Failed transcoding texture!");
}
total_unpack_time += tm.get_elapsed_ms();
total_unpacked_texels += (blocks_x * blocks_y * 16);
}
printf("crnd_unpack_begin time: %3.3fms\n", total_unpack_begin_time);
printf("Total crnd_unpack_level time: %3.3fms\n", total_unpack_time);
double total_time = total_unpack_begin_time + total_unpack_time;
printf("Total transcode time: %3.3fms\n", total_time);
printf("Total texels transcoded: %u\n", total_unpacked_texels);
printf("Overall transcode throughput: %3.3f million texels/sec\n", (total_unpacked_texels / (total_time / 1000.0f)) / 1000000.0f);
// Now write the DXTn data to the DDS file in face-major order.
for (crn_uint32 face_index = 0; face_index < tex_info.m_faces; face_index++)
for (crn_uint32 level_index = 0; level_index < tex_info.m_levels; level_index++)
fwrite(pImages[face_index][level_index], image_size_in_bytes[level_index], 1, pDDS_file);
for (crn_uint32 f = 0; f < cCRNMaxFaces; f++)
for (crn_uint32 l = 0; l < cCRNMaxLevels; l++)
free(pImages[f][l]);
crnd::crnd_unpack_end(pContext);
free(pSrc_file_data);
if (fclose(pDDS_file) == EOF)
{
return error("Failed writing to DDS file!\n");
}
return EXIT_SUCCESS;
}
+153
View File
@@ -0,0 +1,153 @@
// File: timer.cpp
// A simple high-precision, platform independent timer class.
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <time.h>
#include "timer.h"
#if defined(WIN32)
#include <windows.h>
#elif defined(_XBOX)
#include <xtl.h>
#endif
unsigned long long timer::g_init_ticks;
unsigned long long timer::g_freq;
double timer::g_inv_freq;
#if defined(WIN32) || defined(_XBOX)
inline void query_counter(timer_ticks *pTicks)
{
QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(pTicks));
}
inline void query_counter_frequency(timer_ticks *pTicks)
{
QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(pTicks));
}
#elif defined(__GNUC__)
#include <sys/timex.h>
inline void query_counter(timer_ticks *pTicks)
{
struct timeval cur_time;
gettimeofday(&cur_time, NULL);
*pTicks = static_cast<unsigned long long>(cur_time.tv_sec)*1000000ULL + static_cast<unsigned long long>(cur_time.tv_usec);
}
inline void query_counter_frequency(timer_ticks *pTicks)
{
*pTicks = 1000000;
}
#endif
timer::timer() :
m_start_time(0),
m_stop_time(0),
m_started(false),
m_stopped(false)
{
if (!g_inv_freq)
init();
}
timer::timer(timer_ticks start_ticks)
{
if (!g_inv_freq)
init();
m_start_time = start_ticks;
m_started = true;
m_stopped = false;
}
void timer::start(timer_ticks start_ticks)
{
m_start_time = start_ticks;
m_started = true;
m_stopped = false;
}
void timer::start()
{
query_counter(&m_start_time);
m_started = true;
m_stopped = false;
}
void timer::stop()
{
assert(m_started);
query_counter(&m_stop_time);
m_stopped = true;
}
double timer::get_elapsed_secs() const
{
assert(m_started);
if (!m_started)
return 0;
timer_ticks stop_time = m_stop_time;
if (!m_stopped)
query_counter(&stop_time);
timer_ticks delta = stop_time - m_start_time;
return delta * g_inv_freq;
}
timer_ticks timer::get_elapsed_us() const
{
assert(m_started);
if (!m_started)
return 0;
timer_ticks stop_time = m_stop_time;
if (!m_stopped)
query_counter(&stop_time);
timer_ticks delta = stop_time - m_start_time;
return (delta * 1000000ULL + (g_freq >> 1U)) / g_freq;
}
void timer::init()
{
if (!g_inv_freq)
{
query_counter_frequency(&g_freq);
g_inv_freq = 1.0f / g_freq;
query_counter(&g_init_ticks);
}
}
timer_ticks timer::get_init_ticks()
{
if (!g_inv_freq)
init();
return g_init_ticks;
}
timer_ticks timer::get_ticks()
{
if (!g_inv_freq)
init();
timer_ticks ticks;
query_counter(&ticks);
return ticks - g_init_ticks;
}
double timer::ticks_to_secs(timer_ticks ticks)
{
if (!g_inv_freq)
init();
return ticks * g_inv_freq;
}
+41
View File
@@ -0,0 +1,41 @@
// File: timer.h
// A simple high-precision, platform independent timer class.
#pragma once
typedef unsigned long long timer_ticks;
class timer
{
public:
timer();
timer(timer_ticks start_ticks);
void start();
void start(timer_ticks start_ticks);
void stop();
double get_elapsed_secs() const;
inline double get_elapsed_ms() const { return get_elapsed_secs() * 1000.0f; }
timer_ticks get_elapsed_us() const;
static void init();
static inline timer_ticks get_ticks_per_sec() { return g_freq; }
static timer_ticks get_init_ticks();
static timer_ticks get_ticks();
static double ticks_to_secs(timer_ticks ticks);
static inline double ticks_to_ms(timer_ticks ticks) { return ticks_to_secs(ticks) * 1000.0f; }
static inline double get_secs() { return ticks_to_secs(get_ticks()); }
static inline double get_ms() { return ticks_to_ms(get_ticks()); }
private:
static timer_ticks g_init_ticks;
static timer_ticks g_freq;
static double g_inv_freq;
timer_ticks m_start_time;
timer_ticks m_stop_time;
bool m_started : 1;
bool m_stopped : 1;
};