Commit 68afc21a authored by Jonas Karlsson's avatar Jonas Karlsson
Browse files

test app

parent e3e34b67
......@@ -198,3 +198,15 @@ PUBLIC
)
add_subdirectory(interface/basisu_c_binding)
# Build test app
add_executable(helloktx main.cpp)
target_link_libraries(helloktx ${lib})
target_include_directories(helloktx PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_include_directories(helloktx PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib>
$<INSTALL_INTERFACE:lib>
)
#include <ktx.h>
#include <vkformat_enum.h>
#include <gl_format.h>
#include <unistd.h>
#include <cassert>
#include <vector>
#include <iostream>
#include <string>
#include <fstream>
#include <streambuf>
#if 0
int main() {
ktxTexture* texture;
KTX_error_code result;
ktx_size_t offset;
ktx_uint8_t* image;
ktx_uint32_t level, layer, faceSlice;
assert( access( "test.ktx", F_OK ) == 0 );
result = ktxTexture_CreateFromNamedFile("test.ktx",
KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT,
&texture);
// Retrieve information about the texture from fields in the ktxTexture
// such as:
auto numLevels = texture->numLevels;
auto baseWidth = texture->baseWidth;
ktx_bool_t isArray = texture->isArray;
// Retrieve a pointer to the image for a specific mip level, array layer
// & face or depth slice.
level = 1; layer = 0; faceSlice = 3;
result = ktxTexture_GetImageOffset(texture, level, layer, faceSlice, &offset);
image = ktxTexture_GetData(texture) + offset;
// ...
// Do something with the texture image.
// ...
std::cout << "numLevels " << numLevels << std::endl;
std::cout << "baseWidth " << baseWidth << std::endl;
std::cout << "isArray " << isArray << std::endl;
ktxTexture_Destroy(texture);
}
#endif
#if 1
int main() {
ktxTexture2* texture; // For KTX2
//ktxTexture1* texture; // For KTX
ktxTextureCreateInfo createInfo;
KTX_error_code result;
ktx_uint32_t level, layer, faceSlice;
FILE* src;
ktx_size_t srcSize;
//createInfo.glInternalformat = GL_RGB8; // Ignored if creating a ktxTexture2.
createInfo.vkFormat = VK_FORMAT_R8G8B8_UNORM; // Ignored if creating a ktxTexture1.
createInfo.baseWidth = 800;
createInfo.baseHeight = 600;
createInfo.baseDepth = 1;
createInfo.numDimensions = 2;
// Note: it is not necessary to provide a full mipmap pyramid.
createInfo.numLevels = 1; //log2(createInfo.baseWidth) + 1;
createInfo.numLayers = 1;
createInfo.numFaces = 1;
createInfo.isArray = KTX_FALSE;
createInfo.generateMipmaps = KTX_FALSE;
// Call ktxTexture1_Create to create a KTX texture.
result = ktxTexture2_Create(&createInfo,
KTX_TEXTURE_CREATE_ALLOC_STORAGE,
&texture);
//std::ifstream t("file.png");
//std::string image((std::istreambuf_iterator<char>(t)),
// std::istreambuf_iterator<char>());
//
std::vector<ktx_uint8_t> image;
const size_t dims = createInfo.baseDepth*createInfo.baseHeight*createInfo.baseWidth;
image.resize(dims*3);
const float quotient = 1.0f/float(dims);
for (size_t i = 0; i < dims; ++i) {
const float t = float(i)*quotient;
image[i*3]= 255*t;
image[i*3 + 1] = 125;
image[i*3 + 2] = 255 - 255*t;
}
level = 0;
layer = 0;
faceSlice = 0;
result = ktxTexture_SetImageFromMemory(ktxTexture(texture),
level, layer, faceSlice,
reinterpret_cast<const ktx_uint8_t*>(image.data()), image.size());
// Repeat for the other 15 slices of the base level and all other levels
// up to createInfo.numLevels.
ktxTexture_WriteToNamedFile(ktxTexture(texture), "mytex3d.ktx");
ktxTexture_Destroy(ktxTexture(texture));
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment