Kore sync

This commit is contained in:
2026-07-17 19:57:42 -07:00
parent 157b7220d9
commit 2296afc885
12 changed files with 90 additions and 83 deletions

View File

@ -122,9 +122,6 @@ void kinc_internal_resize(int window, int width, int height) {
glViewport(0, 0, width, height);
}
#ifdef __cplusplus
extern "C" {
#endif
void kinc_internal_change_framebuffer(int window, kinc_framebuffer_options_t *frame) {
#ifdef KINC_WINDOWS
if (window == 0) {
@ -136,9 +133,6 @@ void kinc_internal_change_framebuffer(int window, kinc_framebuffer_options_t *fr
}
#endif
}
#ifdef __cplusplus
}
#endif
#ifdef KINC_EGL
static EGLDisplay egl_display = EGL_NO_DISPLAY;
@ -827,8 +821,19 @@ int kinc_g4_max_bound_textures(void) {
return units;
}
static int getUnitStage(kinc_g4_texture_unit_t unit) {
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
if (unit.stages[i] >= 0) {
return unit.stages[i];
}
}
return -1;
}
static void setTextureAddressingInternal(GLenum target, kinc_g4_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {
glActiveTexture(GL_TEXTURE0 + unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
int stage = getUnitStage(unit);
if (stage < 0) return;
glActiveTexture(GL_TEXTURE0 + stage);
GLenum texDir;
switch (dir) {
case KINC_G4_TEXTURE_DIRECTION_U:
@ -847,39 +852,39 @@ static void setTextureAddressingInternal(GLenum target, kinc_g4_texture_unit_t u
case KINC_G4_TEXTURE_ADDRESSING_CLAMP:
glTexParameteri(target, texDir, GL_CLAMP_TO_EDGE);
if (dir == KINC_G4_TEXTURE_DIRECTION_U) {
texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_CLAMP_TO_EDGE;
texModesU[stage] = GL_CLAMP_TO_EDGE;
}
else {
texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_CLAMP_TO_EDGE;
texModesV[stage] = GL_CLAMP_TO_EDGE;
}
break;
case KINC_G4_TEXTURE_ADDRESSING_REPEAT:
glTexParameteri(target, texDir, GL_REPEAT);
if (dir == KINC_G4_TEXTURE_DIRECTION_U) {
texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_REPEAT;
texModesU[stage] = GL_REPEAT;
}
else {
texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_REPEAT;
texModesV[stage] = GL_REPEAT;
}
break;
case KINC_G4_TEXTURE_ADDRESSING_BORDER:
// unsupported
glTexParameteri(target, texDir, GL_CLAMP_TO_EDGE);
if (dir == KINC_G4_TEXTURE_DIRECTION_U) {
texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_CLAMP_TO_EDGE;
texModesU[stage] = GL_CLAMP_TO_EDGE;
}
else {
texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_CLAMP_TO_EDGE;
texModesV[stage] = GL_CLAMP_TO_EDGE;
}
break;
case KINC_G4_TEXTURE_ADDRESSING_MIRROR:
// unsupported
glTexParameteri(target, texDir, GL_REPEAT);
if (dir == KINC_G4_TEXTURE_DIRECTION_U) {
texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_REPEAT;
texModesU[stage] = GL_REPEAT;
}
else {
texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = GL_REPEAT;
texModesV[stage] = GL_REPEAT;
}
break;
}
@ -887,11 +892,15 @@ static void setTextureAddressingInternal(GLenum target, kinc_g4_texture_unit_t u
}
int Kinc_G4_Internal_TextureAddressingU(kinc_g4_texture_unit_t unit) {
return texModesU[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]];
int stage = getUnitStage(unit);
if (stage < 0) return GL_CLAMP_TO_EDGE;
return texModesU[stage];
}
int Kinc_G4_Internal_TextureAddressingV(kinc_g4_texture_unit_t unit) {
return texModesV[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]];
int stage = getUnitStage(unit);
if (stage < 0) return GL_CLAMP_TO_EDGE;
return texModesV[stage];
}
void kinc_g4_set_texture_addressing(kinc_g4_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing) {
@ -905,7 +914,9 @@ void kinc_g4_set_texture3d_addressing(kinc_g4_texture_unit_t unit, kinc_g4_textu
}
static void setTextureMagnificationFilterInternal(GLenum target, kinc_g4_texture_unit_t texunit, kinc_g4_texture_filter_t filter) {
glActiveTexture(GL_TEXTURE0 + texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
int stage = getUnitStage(texunit);
if (stage < 0) return;
glActiveTexture(GL_TEXTURE0 + stage);
glCheckErrors();
switch (filter) {
case KINC_G4_TEXTURE_FILTER_POINT:
@ -970,26 +981,34 @@ static void setMinMipFilters(GLenum target, int unit) {
}
void kinc_g4_set_texture_minification_filter(kinc_g4_texture_unit_t texunit, kinc_g4_texture_filter_t filter) {
minFilters[texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = filter;
setMinMipFilters(GL_TEXTURE_2D, texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
int stage = getUnitStage(texunit);
if (stage < 0) return;
minFilters[stage] = filter;
setMinMipFilters(GL_TEXTURE_2D, stage);
}
void kinc_g4_set_texture3d_minification_filter(kinc_g4_texture_unit_t texunit, kinc_g4_texture_filter_t filter) {
minFilters[texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = filter;
int stage = getUnitStage(texunit);
if (stage < 0) return;
minFilters[stage] = filter;
#ifndef KINC_OPENGL_ES
setMinMipFilters(GL_TEXTURE_3D, texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
setMinMipFilters(GL_TEXTURE_3D, stage);
#endif
}
void kinc_g4_set_texture_mipmap_filter(kinc_g4_texture_unit_t texunit, kinc_g4_mipmap_filter_t filter) {
mipFilters[texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = filter;
setMinMipFilters(GL_TEXTURE_2D, texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
int stage = getUnitStage(texunit);
if (stage < 0) return;
mipFilters[stage] = filter;
setMinMipFilters(GL_TEXTURE_2D, stage);
}
void kinc_g4_set_texture3d_mipmap_filter(kinc_g4_texture_unit_t texunit, kinc_g4_mipmap_filter_t filter) {
mipFilters[texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]] = filter;
int stage = getUnitStage(texunit);
if (stage < 0) return;
mipFilters[stage] = filter;
#ifndef KINC_OPENGL_ES
setMinMipFilters(GL_TEXTURE_3D, texunit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
setMinMipFilters(GL_TEXTURE_3D, stage);
#endif
}

View File

@ -190,6 +190,17 @@ void kinc_g4_set_compute_shader(kinc_g4_compute_shader *shader) {
#endif
}
void kinc_g4_set_image_render_target(kinc_g4_texture_unit_t unit, kinc_g4_render_target_t *render_target) {
#if defined(KINC_WINDOWS) || (defined(KINC_LINUX) && defined(GL_VERSION_4_4))
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
if (unit.stages[i] >= 0) {
glBindImageTexture(unit.stages[i], render_target->impl._texture, 0, GL_FALSE, 0, GL_READ_WRITE, convertInternalRTFormat((kinc_g4_render_target_format_t)render_target->impl.format));
}
}
glCheckErrors();
#endif
}
void kinc_g4_compute(int x, int y, int z) {
#ifdef HAS_COMPUTE
glDispatchCompute(x, y, z);

View File

@ -360,17 +360,23 @@ void kinc_g4_render_target_destroy(kinc_g4_render_target_t *renderTarget) {
}
void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit) {
glActiveTexture(GL_TEXTURE0 + unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
glCheckErrors();
glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._texture);
glCheckErrors();
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
if (unit.stages[i] >= 0) {
glActiveTexture(GL_TEXTURE0 + unit.stages[i]);
glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._texture);
glCheckErrors();
}
}
}
void kinc_g4_render_target_use_depth_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit) {
glActiveTexture(GL_TEXTURE0 + unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]);
glCheckErrors();
glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._depthTexture);
glCheckErrors();
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
if (unit.stages[i] >= 0) {
glActiveTexture(GL_TEXTURE0 + unit.stages[i]);
glBindTexture(renderTarget->isCubeMap ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D, renderTarget->impl._depthTexture);
glCheckErrors();
}
}
}
void kinc_g4_render_target_set_depth_stencil_from(kinc_g4_render_target_t *renderTarget, kinc_g4_render_target_t *source) {

View File

@ -99,6 +99,8 @@ static int convertFormat(kinc_image_format_t format) {
case KINC_IMAGE_FORMAT_A16:
case KINC_IMAGE_FORMAT_GREY8:
return GL_RED;
case KINC_IMAGE_FORMAT_R32UI:
return GL_RED_INTEGER;
}
}
@ -132,6 +134,8 @@ static int convertInternalFormat(kinc_image_format_t format) {
#else
return GL_R8;
#endif
case KINC_IMAGE_FORMAT_R32UI:
return GL_R32UI;
}
}
@ -145,6 +149,8 @@ static int convertType(kinc_image_format_t format) {
case KINC_IMAGE_FORMAT_RGBA32:
default:
return GL_UNSIGNED_BYTE;
case KINC_IMAGE_FORMAT_R32UI:
return GL_UNSIGNED_INT;
}
}
@ -483,7 +489,7 @@ void kinc_g4_texture_init3d(kinc_g4_texture_t *texture, int width, int height, i
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glCheckErrors();
glTexImage3D(GL_TEXTURE_3D, 0, convertInternalFormat(format), width, height, depth, 0, convertFormat(format), GL_UNSIGNED_BYTE, NULL);
glTexImage3D(GL_TEXTURE_3D, 0, convertInternalFormat(format), width, height, depth, 0, convertFormat(format), convertType(format), NULL);
glCheckErrors();
#endif
}
@ -523,8 +529,8 @@ void Kinc_G4_Internal_TextureSet(kinc_g4_texture_t *texture, kinc_g4_texture_uni
#else
glBindTexture(target, texture->impl.texture);
glCheckErrors();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, Kinc_G4_Internal_TextureAddressingU(unit));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, Kinc_G4_Internal_TextureAddressingV(unit));
glTexParameteri(target, GL_TEXTURE_WRAP_S, Kinc_G4_Internal_TextureAddressingU(unit));
glTexParameteri(target, GL_TEXTURE_WRAP_T, Kinc_G4_Internal_TextureAddressingV(unit));
#endif
}
@ -532,7 +538,7 @@ void Kinc_G4_Internal_TextureImageSet(kinc_g4_texture_t *texture, kinc_g4_textur
#if defined(KINC_WINDOWS) || (defined(KINC_LINUX) && defined(GL_VERSION_4_4))
for (int i = 0; i < KINC_G4_SHADER_TYPE_COUNT; ++i) {
if (unit.stages[i] >= 0) {
glBindImageTexture(unit.stages[i], texture->impl.texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, convertInternalFormat(texture->format));
glBindImageTexture(unit.stages[i], texture->impl.texture, 0, GL_FALSE, 0, GL_READ_WRITE, convertInternalFormat(texture->format));
}
}
glCheckErrors();

View File

@ -34,13 +34,7 @@ void kinc_g5_internal_destroy_window(int window) {}
void kinc_g5_internal_destroy(void) {}
#ifdef __cplusplus
extern "C" {
#endif
extern void kinc_g4_on_g5_internal_resize(int, int, int);
#ifdef __cplusplus
}
#endif
void kinc_internal_resize(int window, int width, int height) {
kinc_g4_on_g5_internal_resize(window, width, height);

View File

@ -115,13 +115,7 @@ bool memory_type_from_properties(uint32_t typeBits, VkFlags requirements_mask, u
return false;
}
#ifdef __cplusplus
extern "C" {
#endif
extern void kinc_g4_on_g5_internal_resize(int, int, int);
#ifdef __cplusplus
}
#endif
void kinc_internal_resize(int window_index, int width, int height) {
struct vk_window *window = &vk_ctx.windows[window_index];

View File

@ -10,14 +10,8 @@
#include <stdlib.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
extern const char *iphonegetresourcepath(void);
extern const char *macgetresourcepath(void);
#ifdef __cplusplus
}
#endif
void kinc_internal_video_sound_stream_init(kinc_internal_video_sound_stream_t *stream, int channel_count, int frequency) {
stream->bufferSize = 1024 * 100;

View File

@ -13,21 +13,17 @@
#include <kinc/backend/windowdata.h>
#ifdef __cplusplus
extern "C" {
#endif
bool withAutoreleasepool(bool (*f)(void)) {
@autoreleasepool {
return f();
}
}
extern const char *macgetresourcepath(void);
const char *macgetresourcepath(void) {
return [[[NSBundle mainBundle] resourcePath] cStringUsingEncoding:NSUTF8StringEncoding];
}
#ifdef __cplusplus
}
#endif
@interface KincApplication : NSApplication {
}
@ -95,17 +91,11 @@ bool kinc_internal_handle_messages(void) {
return true;
}
#ifdef __cplusplus
extern "C" {
#endif
void swapBuffersMac(int windowId) {
#ifndef KINC_METAL
[windows[windowId].view switchBuffers];
#endif
}
#ifdef __cplusplus
}
#endif
static int createWindow(kinc_window_options_t *options) {
int width = options->width / [[NSScreen mainScreen] backingScaleFactor];

View File

@ -14,26 +14,14 @@ void kinc_window_resize(int window, int width, int height) {}
void kinc_window_move(int window, int x, int y) {}
#ifdef __cplusplus
extern "C" {
#endif
void kinc_internal_change_framebuffer(int window, struct kinc_framebuffer_options *frame);
#ifdef __cplusplus
}
#endif
void kinc_window_change_framebuffer(int window, struct kinc_framebuffer_options *frame) {
kinc_internal_change_framebuffer(0, frame);
}
#ifdef KINC_METAL
#ifdef __cplusplus
extern "C" {
#endif
void kinc_internal_change_framebuffer(int window, struct kinc_framebuffer_options *frame) {}
#ifdef __cplusplus
}
#endif
#endif
void kinc_window_change_features(int window, int features) {}

View File

@ -376,6 +376,8 @@ KINC_FUNC void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, struct kinc_g4_t
/// <param name="texture">The texture to assign to the unit</param>
KINC_FUNC void kinc_g4_set_image_texture(kinc_g4_texture_unit_t unit, struct kinc_g4_texture *texture);
KINC_FUNC void kinc_g4_set_image_render_target(kinc_g4_texture_unit_t unit, struct kinc_g4_render_target *render_target);
KINC_FUNC bool kinc_g4_init_occlusion_query(unsigned *occlusionQuery);
KINC_FUNC void kinc_g4_delete_occlusion_query(unsigned occlusionQuery);

View File

@ -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_R32UI
} kinc_image_format_t;
typedef struct kinc_image {
@ -608,6 +609,8 @@ int kinc_image_format_sizeof(kinc_image_format_t format) {
return 1;
case KINC_IMAGE_FORMAT_RGB24:
return 3;
case KINC_IMAGE_FORMAT_R32UI:
return 4;
}
return -1;
}

View File

@ -10,7 +10,7 @@ let flags = {
with_compute: true,
with_networking: true,
with_viewport: true,
with_webview: true,
with_webview: false,
with_uws: false,
with_ssl: true,
debug_network: true
@ -142,7 +142,7 @@ if (platform === Platform.Windows) {
project.addLib(libdir + 'v8_monolith');
if (flags.with_webview) {
project.addIncludeDir('webview2/include');
project.addLib('WebView2Loader.lib');
project.addLib('WebView2Loader');
}
if (!flags.release) {
project.addDefine('_HAS_ITERATOR_DEBUGGING=0');