-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from BredaUniversityGames/dds-cleanup
Cleaned up DDS texture loading implementation
- Loading branch information
Showing
21 changed files
with
823 additions
and
591 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
import sys | ||
|
||
dirName = sys.argv[1] # Get the name of the folder passed to this script | ||
print(f'Creating batch script for directory {dirName}') | ||
|
||
filesInDir = os.listdir(dirName) # Get all files in the directory | ||
filesInDir = [f for f in filesInDir if f.lower().endswith('png')] # Get only PNG files | ||
filesInDir = [os.path.join(dirName, f) for f in filesInDir] # Get absolute paths | ||
filesInDir = [f for f in filesInDir if os.path.isfile(f)] # Ignore directories | ||
|
||
outScript = open('DXX_Raytracer_Convert_PNG_To_DDS.nvtt', 'w') # Start a new script | ||
|
||
baseColorTexturesInDir = [f for f in filesInDir if f.find("basecolor")] | ||
|
||
for file in baseColorTexturesInDir: | ||
newFileName = file.rpartition('.')[0] + '.dds' # Replace .png with .dds | ||
outScript.write(f'{file} --format bc7 --dx10 --mips --output {newFileName}\n') | ||
|
||
metallicTexturesInDir = [f for f in filesInDir if f.find("metallic")] | ||
|
||
for file in metallicTexturesInDir: | ||
newFileName = file.rpartition('.')[0] + '.dds' # Replace .png with .dds | ||
outScript.write(f'{file} --format bc4 --dx10 --mips --output {newFileName}\n') | ||
|
||
roughnessTexturesInDir = [f for f in filesInDir if f.find("roughness")] | ||
|
||
for file in roughnessTexturesInDir: | ||
newFileName = file.rpartition('.')[0] + '.dds' # Replace .png with .dds | ||
outScript.write(f'{file} --format bc4 --dx10 --mips --output {newFileName}\n') | ||
|
||
normalTexturesInDir = [f for f in filesInDir if f.find("normal")] | ||
|
||
for file in normalTexturesInDir: | ||
newFileName = file.rpartition('.')[0] + '.dds' # Replace .png with .dds | ||
outScript.write(f'{file} --format bc7 --dx10 --mips --output {newFileName}\n') | ||
|
||
emissiveTexturesInDir = [f for f in filesInDir if f.find("emissive")] | ||
|
||
for file in emissiveTexturesInDir: | ||
newFileName = file.rpartition('.')[0] + '.dds' # Replace .png with .dds | ||
outScript.write(f'{file} --format bc7 --export-pre-alpha --dx10 --mips --output {newFileName}\n') | ||
|
||
outScript.close() | ||
print('Done') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "FileIO.h" | ||
|
||
#include "Core/Arena.h" | ||
#include "Core/String.h" | ||
|
||
#include <stdio.h> | ||
|
||
bool RT_ReadEntireFile(RT_Arena *arena, RT_String path, RT_String *result) | ||
{ | ||
const char *path_c = RT_CopyStringNullTerm(&g_thread_arena, path); | ||
|
||
FILE *f = fopen(path_c, "rb"); | ||
|
||
if (!f) | ||
{ | ||
// fprintf(stderr, "Failed to open file '%s'.\n", path_c); | ||
return false; | ||
} | ||
|
||
defer { fclose(f); }; | ||
|
||
fseek(f, 0, SEEK_END); | ||
size_t file_size = ftell(f); | ||
fseek(f, 0, SEEK_SET); | ||
|
||
RT_String file; | ||
file.bytes = (char *)RT_ArenaAllocNoZero(arena, file_size + 1, 16); | ||
file.count = file_size; | ||
|
||
size_t bytes_read = fread(file.bytes, 1, file_size, f); | ||
|
||
if (bytes_read != file_size) | ||
{ | ||
return false; | ||
} | ||
|
||
// Null terminate for good measure | ||
file.bytes[file.count] = 0; | ||
|
||
*result = file; | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include "ApiTypes.h" | ||
|
||
// The descent code likes to mess with padding, so public headers should use pragma pack to | ||
// restore expected packing! | ||
#pragma pack(push, 8) | ||
|
||
RT_API bool RT_ReadEntireFile(RT_Arena *arena, RT_String path, RT_String *result); | ||
|
||
// Don't forget to pop. | ||
#pragma pack(pop) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.