Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ static DXGI_FORMAT convertFormat(kinc_image_format_t format) {
return DXGI_FORMAT_R32G32B32A32_FLOAT;
case KINC_IMAGE_FORMAT_RGBA64:
return DXGI_FORMAT_R16G16B16A16_FLOAT;
case KINC_IMAGE_FORMAT_RGBA64U:
return DXGI_FORMAT_R16G16B16A16_UINT;
case KINC_IMAGE_FORMAT_RGB24:
return DXGI_FORMAT_R8G8B8A8_UNORM;
case KINC_IMAGE_FORMAT_A32:
Expand All @@ -34,6 +36,7 @@ static int formatByteSize(kinc_image_format_t format) {
case KINC_IMAGE_FORMAT_RGBA128:
return 16;
case KINC_IMAGE_FORMAT_RGBA64:
case KINC_IMAGE_FORMAT_RGBA64U:
return 8;
case KINC_IMAGE_FORMAT_RGB24:
return 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
#define GL_HALF_FLOAT 0x140B
#endif

#ifndef GL_RGBA_INTEGER
#define GL_RGBA_INTEGER 0x8D99
#endif

#ifndef GL_RGBA16UI
#define GL_RGBA16UI 0x8D76
#endif

#ifndef GL_UNSIGNED_SHORT
#define GL_UNSIGNED_SHORT 0x1403
#endif

#ifndef GL_RED
#define GL_RED GL_LUMINANCE
#endif
Expand Down Expand Up @@ -93,6 +105,8 @@ static int convertFormat(kinc_image_format_t format) {
case KINC_IMAGE_FORMAT_RGBA128:
default:
return GL_RGBA;
case KINC_IMAGE_FORMAT_RGBA64U:
return GL_RGBA_INTEGER;
case KINC_IMAGE_FORMAT_RGB24:
return GL_RGB;
case KINC_IMAGE_FORMAT_A32:
Expand All @@ -108,6 +122,8 @@ static int convertInternalFormat(kinc_image_format_t format) {
return GL_RGBA32F_EXT;
case KINC_IMAGE_FORMAT_RGBA64:
return GL_RGBA16F_EXT;
case KINC_IMAGE_FORMAT_RGBA64U:
return GL_RGBA16UI;
case KINC_IMAGE_FORMAT_RGBA32:
return GL_RGBA8;
default:
Expand Down Expand Up @@ -142,6 +158,8 @@ static int convertType(kinc_image_format_t format) {
case KINC_IMAGE_FORMAT_A32:
case KINC_IMAGE_FORMAT_A16:
return GL_FLOAT;
case KINC_IMAGE_FORMAT_RGBA64U:
return GL_UNSIGNED_SHORT;
case KINC_IMAGE_FORMAT_RGBA32:
default:
return GL_UNSIGNED_BYTE;
Expand Down Expand Up @@ -246,6 +264,7 @@ static void convertImageToPow2(kinc_image_format_t format, uint8_t *from, int fw
case KINC_IMAGE_FORMAT_RGB24:
case KINC_IMAGE_FORMAT_RGBA128:
case KINC_IMAGE_FORMAT_RGBA64:
case KINC_IMAGE_FORMAT_RGBA64U:
case KINC_IMAGE_FORMAT_A32:
case KINC_IMAGE_FORMAT_A16:
case KINC_IMAGE_FORMAT_BGRA32:
Expand Down Expand Up @@ -451,14 +470,20 @@ void kinc_g4_texture_init(kinc_g4_texture_t *texture, int width, int height, kin
glCheckErrors();
glBindTexture(GL_TEXTURE_2D, texture->impl.texture);
glCheckErrors();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Integer formats require GL_NEAREST
int texFilter = format == KINC_IMAGE_FORMAT_RGBA64U ? GL_NEAREST : GL_LINEAR;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texFilter);
glCheckErrors();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texFilter);
glCheckErrors();

if (convertType(format) == GL_FLOAT) {
glTexImage2D(GL_TEXTURE_2D, 0, convertInternalFormat(format), texture->tex_width, texture->tex_height, 0, convertFormat(format), GL_FLOAT, NULL);
}
else if (format == KINC_IMAGE_FORMAT_RGBA64U) {
glTexImage2D(GL_TEXTURE_2D, 0, convertInternalFormat(format), texture->tex_width, texture->tex_height, 0, convertFormat(format), GL_UNSIGNED_SHORT,
NULL);
}
else {
glTexImage2D(GL_TEXTURE_2D, 0, convertInternalFormat(format), texture->tex_width, texture->tex_height, 0, convertFormat(format), GL_UNSIGNED_BYTE,
NULL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ static DXGI_FORMAT convertImageFormat(kinc_image_format_t format) {
return DXGI_FORMAT_R32G32B32A32_FLOAT;
case KINC_IMAGE_FORMAT_RGBA64:
return DXGI_FORMAT_R16G16B16A16_FLOAT;
case KINC_IMAGE_FORMAT_RGBA64U:
return DXGI_FORMAT_R16G16B16A16_UINT;
case KINC_IMAGE_FORMAT_RGB24:
return DXGI_FORMAT_R8G8B8A8_UNORM;
case KINC_IMAGE_FORMAT_A32:
Expand All @@ -61,6 +63,7 @@ static int formatByteSize(kinc_image_format_t format) {
case KINC_IMAGE_FORMAT_RGBA128:
return 16;
case KINC_IMAGE_FORMAT_RGBA64:
case KINC_IMAGE_FORMAT_RGBA64U:
return 8;
case KINC_IMAGE_FORMAT_RGB24:
return 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ static MTLPixelFormat convert_image_format(kinc_image_format_t format) {
return MTLPixelFormatBGRA8Unorm;
case KINC_IMAGE_FORMAT_A16:
return MTLPixelFormatR16Float;
case KINC_IMAGE_FORMAT_RGBA64U:
return MTLPixelFormatRGBA16Uint;
}
}

Expand All @@ -47,6 +49,8 @@ static int formatByteSize(kinc_image_format_t format) {
case KINC_IMAGE_FORMAT_BGRA32:
case KINC_IMAGE_FORMAT_RGBA32:
return 4;
case KINC_IMAGE_FORMAT_RGBA64U:
return 8;
default:
assert(false);
return 4;
Expand Down Expand Up @@ -90,7 +94,7 @@ void kinc_g5_texture_init(kinc_g5_texture_t *texture, int width, int height, kin
texture->texWidth = width;
texture->texHeight = height;
texture->format = format;
texture->impl.data = malloc(width * height * (format == KINC_IMAGE_FORMAT_GREY8 ? 1 : 4));
texture->impl.data = malloc(width * height * formatByteSize(format));
create(texture, width, height, format, true);
}

Expand All @@ -115,7 +119,7 @@ void kinc_g5_texture_init_non_sampled_access(kinc_g5_texture_t *texture, int wid
texture->texWidth = width;
texture->texHeight = height;
texture->format = format;
texture->impl.data = malloc(width * height * (format == KINC_IMAGE_FORMAT_GREY8 ? 1 : 4));
texture->impl.data = malloc(width * height * formatByteSize(format));
create(texture, width, height, format, true);
}

Expand Down Expand Up @@ -202,6 +206,8 @@ int kinc_g5_texture_stride(kinc_g5_texture_t *texture) {
return texture->texWidth * 2;
case KINC_IMAGE_FORMAT_A32:
return texture->texWidth * 4;
case KINC_IMAGE_FORMAT_RGBA64U:
return texture->texWidth * 8;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static void prepare_texture_image(uint8_t *tex_colors, uint32_t tex_width, uint3
}
}
}
else if (tex_format == VK_FORMAT_R16G16B16A16_SFLOAT) {
else if (tex_format == VK_FORMAT_R16G16B16A16_SFLOAT || tex_format == VK_FORMAT_R16G16B16A16_UINT) {
uint16_t *data16 = (uint16_t *)data;
uint16_t *tex_colors16 = (uint16_t *)tex_colors;
for (uint32_t y = 0; y < tex_height; y++) {
Expand Down Expand Up @@ -171,6 +171,8 @@ static VkFormat convert_image_format(kinc_image_format_t format) {
return VK_FORMAT_R32G32B32A32_SFLOAT;
case KINC_IMAGE_FORMAT_RGBA64:
return VK_FORMAT_R16G16B16A16_SFLOAT;
case KINC_IMAGE_FORMAT_RGBA64U:
return VK_FORMAT_R16G16B16A16_UINT;
case KINC_IMAGE_FORMAT_RGB24:
return VK_FORMAT_B8G8R8A8_UNORM;
case KINC_IMAGE_FORMAT_A32:
Expand All @@ -193,6 +195,7 @@ static int format_byte_size(kinc_image_format_t format) {
case KINC_IMAGE_FORMAT_RGBA128:
return 16;
case KINC_IMAGE_FORMAT_RGBA64:
case KINC_IMAGE_FORMAT_RGBA64U:
return 8;
case KINC_IMAGE_FORMAT_RGB24:
return 4;
Expand Down
4 changes: 3 additions & 1 deletion Sources/kinc/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ typedef enum kinc_image_format {
KINC_IMAGE_FORMAT_RGBA64,
KINC_IMAGE_FORMAT_A32,
KINC_IMAGE_FORMAT_BGRA32,
KINC_IMAGE_FORMAT_A16
KINC_IMAGE_FORMAT_A16,
KINC_IMAGE_FORMAT_RGBA64U
} kinc_image_format_t;

typedef struct kinc_image {
Expand Down Expand Up @@ -599,6 +600,7 @@ int kinc_image_format_sizeof(kinc_image_format_t format) {
case KINC_IMAGE_FORMAT_BGRA32:
return 4;
case KINC_IMAGE_FORMAT_RGBA64:
case KINC_IMAGE_FORMAT_RGBA64U:
return 8;
case KINC_IMAGE_FORMAT_A32:
return 4;
Expand Down
Loading