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 @@ -8,6 +8,8 @@ static DXGI_FORMAT convertRenderTargetFormat(kinc_g4_render_target_format_t form
return DXGI_FORMAT_R32G32B32A32_FLOAT;
case KINC_G4_RENDER_TARGET_FORMAT_64BIT_FLOAT:
return DXGI_FORMAT_R16G16B16A16_FLOAT;
case KINC_G4_RENDER_TARGET_FORMAT_64BIT_INTEGER:
return DXGI_FORMAT_R16G16B16A16_UINT;
case KINC_G4_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT:
return DXGI_FORMAT_R32_FLOAT;
case KINC_G4_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT:
Expand All @@ -25,6 +27,7 @@ static int formatRenderTargetByteSize(kinc_g4_render_target_format_t format) {
case KINC_G4_RENDER_TARGET_FORMAT_128BIT_FLOAT:
return 16;
case KINC_G4_RENDER_TARGET_FORMAT_64BIT_FLOAT:
case KINC_G4_RENDER_TARGET_FORMAT_64BIT_INTEGER:
return 8;
case KINC_G4_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT:
return 4;
Expand Down
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 @@ -41,6 +41,8 @@ static int convertInternalRTFormat(kinc_g4_render_target_format_t format) {
switch (format) {
case KINC_G4_RENDER_TARGET_FORMAT_64BIT_FLOAT:
return GL_RGBA16F;
case KINC_G4_RENDER_TARGET_FORMAT_64BIT_INTEGER:
return GL_RGBA16UI;
case KINC_G4_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT:
return GL_R32F;
case KINC_G4_RENDER_TARGET_FORMAT_128BIT_FLOAT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 @@ -201,6 +213,12 @@ void kinc_g4_render_target_init_with_multisampling(kinc_g4_render_target_t *rend
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, renderTarget->texWidth, renderTarget->texHeight, 0, GL_RGBA, GL_HALF_FLOAT, 0);
#endif
break;
case KINC_G4_RENDER_TARGET_FORMAT_64BIT_INTEGER:
// Integer formats require GL_NEAREST
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16UI, renderTarget->texWidth, renderTarget->texHeight, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, 0);
break;
case KINC_G4_RENDER_TARGET_FORMAT_16BIT_DEPTH:
#ifdef KINC_OPENGL_ES
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Expand Down Expand Up @@ -307,6 +325,14 @@ void kinc_g4_render_target_init_cube_with_multisampling(kinc_g4_render_target_t
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA16F, renderTarget->texWidth, renderTarget->texHeight, 0, GL_RGBA, GL_HALF_FLOAT, 0);
#endif
break;
case KINC_G4_RENDER_TARGET_FORMAT_64BIT_INTEGER:
// Integer formats require GL_NEAREST
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
for (int i = 0; i < 6; i++)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA16UI, renderTarget->texWidth, renderTarget->texHeight, 0, GL_RGBA_INTEGER,
GL_UNSIGNED_SHORT, 0);
break;
case KINC_G4_RENDER_TARGET_FORMAT_16BIT_DEPTH:
#ifdef KINC_OPENGL_ES
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Expand Down Expand Up @@ -389,6 +415,9 @@ void kinc_g4_render_target_get_pixels(kinc_g4_render_target_t *renderTarget, uin
case KINC_G4_RENDER_TARGET_FORMAT_64BIT_FLOAT:
glReadPixels(0, 0, renderTarget->texWidth, renderTarget->texHeight, GL_RGBA, GL_HALF_FLOAT, data);
break;
case KINC_G4_RENDER_TARGET_FORMAT_64BIT_INTEGER:
glReadPixels(0, 0, renderTarget->texWidth, renderTarget->texHeight, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, data);
break;
case KINC_G4_RENDER_TARGET_FORMAT_8BIT_RED:
glReadPixels(0, 0, renderTarget->texWidth, renderTarget->texHeight, GL_RED, GL_UNSIGNED_BYTE, data);
break;
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 @@ -285,6 +285,8 @@ static DXGI_FORMAT convert_format(kinc_g5_render_target_format_t format) {
return DXGI_FORMAT_R32G32B32A32_FLOAT;
case KINC_G5_RENDER_TARGET_FORMAT_64BIT_FLOAT:
return DXGI_FORMAT_R16G16B16A16_FLOAT;
case KINC_G5_RENDER_TARGET_FORMAT_64BIT_INTEGER:
return DXGI_FORMAT_R16G16B16A16_UINT;
case KINC_G5_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT:
return DXGI_FORMAT_R32_FLOAT;
case KINC_G5_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ static DXGI_FORMAT convertFormat(kinc_g5_render_target_format_t format) {
return DXGI_FORMAT_R32G32B32A32_FLOAT;
case KINC_G5_RENDER_TARGET_FORMAT_64BIT_FLOAT:
return DXGI_FORMAT_R16G16B16A16_FLOAT;
case KINC_G5_RENDER_TARGET_FORMAT_64BIT_INTEGER:
return DXGI_FORMAT_R16G16B16A16_UINT;
case KINC_G5_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT:
return DXGI_FORMAT_R32_FLOAT;
case KINC_G5_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT:
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 @@ -93,6 +93,8 @@ static MTLPixelFormat convert_render_target_format(kinc_g5_render_target_format_
return MTLPixelFormatRGBA32Float;
case KINC_G5_RENDER_TARGET_FORMAT_64BIT_FLOAT:
return MTLPixelFormatRGBA16Float;
case KINC_G5_RENDER_TARGET_FORMAT_64BIT_INTEGER:
return MTLPixelFormatRGBA16Uint;
case KINC_G5_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT:
return MTLPixelFormatR32Float;
case KINC_G5_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ static MTLPixelFormat convert_format(kinc_g5_render_target_format_t format) {
return MTLPixelFormatRGBA32Float;
case KINC_G5_RENDER_TARGET_FORMAT_64BIT_FLOAT:
return MTLPixelFormatRGBA16Float;
case KINC_G5_RENDER_TARGET_FORMAT_64BIT_INTEGER:
return MTLPixelFormatRGBA16Uint;
case KINC_G5_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT:
return MTLPixelFormatR32Float;
case KINC_G5_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT:
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 @@ -248,6 +248,8 @@ static VkFormat convert_format(kinc_g5_render_target_format_t format) {
return VK_FORMAT_R32G32B32A32_SFLOAT;
case KINC_G5_RENDER_TARGET_FORMAT_64BIT_FLOAT:
return VK_FORMAT_R16G16B16A16_SFLOAT;
case KINC_G5_RENDER_TARGET_FORMAT_64BIT_INTEGER:
return VK_FORMAT_R16G16B16A16_UINT;
case KINC_G5_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT:
return VK_FORMAT_R32_SFLOAT;
case KINC_G5_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT:
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
3 changes: 2 additions & 1 deletion Sources/kinc/graphics4/rendertarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ typedef enum kinc_g4_render_target_format {
KINC_G4_RENDER_TARGET_FORMAT_128BIT_FLOAT,
KINC_G4_RENDER_TARGET_FORMAT_16BIT_DEPTH,
KINC_G4_RENDER_TARGET_FORMAT_8BIT_RED,
KINC_G4_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT
KINC_G4_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT,
KINC_G4_RENDER_TARGET_FORMAT_64BIT_INTEGER
} kinc_g4_render_target_format_t;

typedef struct kinc_g4_render_target {
Expand Down
3 changes: 2 additions & 1 deletion Sources/kinc/graphics5/rendertarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ typedef enum kinc_g5_render_target_format {
KINC_G5_RENDER_TARGET_FORMAT_128BIT_FLOAT,
KINC_G5_RENDER_TARGET_FORMAT_16BIT_DEPTH,
KINC_G5_RENDER_TARGET_FORMAT_8BIT_RED,
KINC_G5_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT
KINC_G5_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT,
KINC_G5_RENDER_TARGET_FORMAT_64BIT_INTEGER
} kinc_g5_render_target_format_t;

typedef struct kinc_g5_render_target {
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