Prepping to allow textures to have different render modes/types. Prepping for freetype support
This commit is contained in:
@ -38,15 +38,42 @@ target_link_libraries(texturetool
|
||||
)
|
||||
|
||||
# Tool Function
|
||||
function(tool_texture target in)
|
||||
function(tool_texture target)
|
||||
# Defaults
|
||||
set(FILE "" )
|
||||
set(FILTER_MIN "")
|
||||
set(FILTER_MAG "")
|
||||
set(WRAP_X "")
|
||||
set(WRAP_Y "")
|
||||
|
||||
# Parse Args
|
||||
foreach(_PAIR IN LISTS ARGN)
|
||||
if (_PAIR MATCHES "^([^:]+)=(.*)$")
|
||||
set(${CMAKE_MATCH_1} ${CMAKE_MATCH_2})
|
||||
else()
|
||||
message(FATAL_ERROR "Invalid pair: ${_PAIR}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Check for missing args
|
||||
if(NOT DEFINED FILE)
|
||||
message(FATAL_ERROR "Missing FILE input")
|
||||
endif()
|
||||
|
||||
set(DEPS "")
|
||||
if(DAWN_BUILD_TOOLS)
|
||||
set(DEPS texturetool)
|
||||
endif()
|
||||
|
||||
add_custom_target(${target}
|
||||
COMMAND texturetool --input="${DAWN_ASSETS_SOURCE_DIR}/${in}" --output="${DAWN_ASSETS_BUILD_DIR}/${target}"
|
||||
COMMENT "Generating texture ${target} from ${in}"
|
||||
COMMAND texturetool
|
||||
--input="${DAWN_ASSETS_SOURCE_DIR}/${FILE}"
|
||||
--output="${DAWN_ASSETS_BUILD_DIR}/${target}"
|
||||
--wrapX="${WRAP_X}"
|
||||
--wrapY="${WRAP_Y}"
|
||||
--filterMin="${FILTER_MIN}"
|
||||
--filterMag="${FILTER_MIN}"
|
||||
COMMENT "Generating texture ${target} from ${FILE}"
|
||||
DEPENDS ${DEPS}
|
||||
)
|
||||
add_dependencies(${DAWN_TARGET_NAME} ${target})
|
||||
|
@ -11,6 +11,15 @@ std::vector<std::string> TextureTool::getRequiredFlags() {
|
||||
return std::vector<std::string>{ "input", "output" };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> TextureTool::getOptionalFlags() {
|
||||
return {
|
||||
{ "wrapX", "clamp" },
|
||||
{ "wrapY", "clamp" },
|
||||
{ "filterMin", "linear" },
|
||||
{ "filterMax", "linear" }
|
||||
};
|
||||
}
|
||||
|
||||
int32_t TextureTool::start() {
|
||||
// Finished with XML data, now we can write data out.
|
||||
File fileOut(flags["output"] + ".texture");
|
||||
@ -40,6 +49,38 @@ int32_t TextureTool::start() {
|
||||
}
|
||||
stbi_image_free(imageRaw);
|
||||
|
||||
std::function<int32_t(std::string)> wrapFromString = [&](std::string wr) {
|
||||
if(wr == "repeat") return 0;
|
||||
if(wr == "mirror") return 1;
|
||||
if(wr == "clamp") return 2;
|
||||
if(wr == "border") return 3;
|
||||
return -1;
|
||||
};
|
||||
|
||||
int32_t wrapX = wrapFromString(flags["wrapX"]);
|
||||
if(wrapX == -1) {
|
||||
std::cout << "Invalid wrapX value " << flags["wrapX"] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t wrapY = wrapFromString(flags["wrapY"]);
|
||||
if(wrapY == -1) {
|
||||
std::cout << "Invalid wrapY value " << flags["wrapY"] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Write info
|
||||
char headerBuffer[256];
|
||||
size_t headerBufferLength = sprintf((char *)headerBuffer, "DT_1.00|%i|%i|%i|%i|%i|%i|%i|",
|
||||
w,
|
||||
h,
|
||||
4, // RGBA,
|
||||
wrapX, // WRAPX
|
||||
wrapY, // WRAPY
|
||||
flags["filterMin"] == "nearest" ? 0 : 1,
|
||||
flags["filterMag"] == "nearest" ? 0 : 1
|
||||
);
|
||||
|
||||
// Open and create output
|
||||
File out(flags["output"] + ".texture");
|
||||
if(!out.mkdirp()) {
|
||||
@ -50,10 +91,6 @@ int32_t TextureTool::start() {
|
||||
std::cout << "Failed to open texture file for writing " << out.filename << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Write info
|
||||
char headerBuffer[64];
|
||||
size_t headerBufferLength = sprintf((char *)headerBuffer, "%i|%i|", w, h);
|
||||
if(!out.writeRaw(headerBuffer, headerBufferLength)) {
|
||||
std::cout << "Failed to write texture header for " << out.filename << std::endl;
|
||||
return 1;
|
||||
|
@ -12,6 +12,7 @@ namespace Dawn {
|
||||
class TextureTool : public DawnTool {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredFlags() override;
|
||||
std::map<std::string, std::string> getOptionalFlags() override;
|
||||
|
||||
public:
|
||||
int32_t start();
|
||||
|
Reference in New Issue
Block a user