Compare commits

..

No commits in common. "main" and "main" have entirely different histories.
main ... main

15 changed files with 1085 additions and 947 deletions

View File

@ -1,268 +1,268 @@
/* /*
* Platform-specific and custom entropy polling functions * Platform-specific and custom entropy polling functions
* *
* Copyright (C) 2006-2016, ARM Limited, All Rights Reserved * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may * Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. * not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
* This file is part of mbed TLS (https://tls.mbed.org) * This file is part of mbed TLS (https://tls.mbed.org)
*/ */
#define _GNU_SOURCE
#if !defined(MBEDTLS_CONFIG_FILE) #if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h" #include "mbedtls/config.h"
#else #else
#include MBEDTLS_CONFIG_FILE #include MBEDTLS_CONFIG_FILE
#endif #endif
#if defined(MBEDTLS_ENTROPY_C) #if defined(MBEDTLS_ENTROPY_C)
#include "mbedtls/entropy.h" #include "mbedtls/entropy.h"
#include "mbedtls/entropy_poll.h" #include "mbedtls/entropy_poll.h"
#if defined(MBEDTLS_TIMING_C) #if defined(MBEDTLS_TIMING_C)
#include <string.h> #include <string.h>
#include "mbedtls/timing.h" #include "mbedtls/timing.h"
#endif #endif
#if defined(MBEDTLS_HAVEGE_C) #if defined(MBEDTLS_HAVEGE_C)
#include "mbedtls/havege.h" #include "mbedtls/havege.h"
#endif #endif
#if defined(MBEDTLS_ENTROPY_NV_SEED) #if defined(MBEDTLS_ENTROPY_NV_SEED)
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
#endif #endif
#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY) #if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
#if !defined(unix) && !defined(__unix__) && !defined(__unix) && \ #if !defined(unix) && !defined(__unix__) && !defined(__unix) && \
!defined(__APPLE__) && !defined(_WIN32) !defined(__APPLE__) && !defined(_WIN32)
#error "Platform entropy sources only work on Unix and Windows, see MBEDTLS_NO_PLATFORM_ENTROPY in config.h" #error "Platform entropy sources only work on Unix and Windows, see MBEDTLS_NO_PLATFORM_ENTROPY in config.h"
#endif #endif
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
#if !defined(_WIN32_WINNT) #if !defined(_WIN32_WINNT)
#define _WIN32_WINNT 0x0400 #define _WIN32_WINNT 0x0400
#endif #endif
#include <windows.h> #include <windows.h>
#include <wincrypt.h> #include <wincrypt.h>
int mbedtls_platform_entropy_poll( void *data, unsigned char *output, size_t len, int mbedtls_platform_entropy_poll( void *data, unsigned char *output, size_t len,
size_t *olen ) size_t *olen )
{ {
HCRYPTPROV provider; HCRYPTPROV provider;
((void) data); ((void) data);
*olen = 0; *olen = 0;
if( CryptAcquireContext( &provider, NULL, NULL, if( CryptAcquireContext( &provider, NULL, NULL,
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) == FALSE ) PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) == FALSE )
{ {
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
} }
if( CryptGenRandom( provider, (DWORD) len, output ) == FALSE ) if( CryptGenRandom( provider, (DWORD) len, output ) == FALSE )
{ {
CryptReleaseContext( provider, 0 ); CryptReleaseContext( provider, 0 );
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
} }
CryptReleaseContext( provider, 0 ); CryptReleaseContext( provider, 0 );
*olen = len; *olen = len;
return( 0 ); return( 0 );
} }
#else /* _WIN32 && !EFIX64 && !EFI32 */ #else /* _WIN32 && !EFIX64 && !EFI32 */
/* /*
* Test for Linux getrandom() support. * Test for Linux getrandom() support.
* Since there is no wrapper in the libc yet, use the generic syscall wrapper * Since there is no wrapper in the libc yet, use the generic syscall wrapper
* available in GNU libc and compatible libc's (eg uClibc). * available in GNU libc and compatible libc's (eg uClibc).
*/ */
#if defined(__linux__) && defined(__GLIBC__) #if defined(__linux__) && defined(__GLIBC__)
#include <unistd.h> #include <unistd.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#if defined(SYS_getrandom) #if defined(SYS_getrandom)
#define HAVE_GETRANDOM #define HAVE_GETRANDOM
static int getrandom_wrapper( void *buf, size_t buflen, unsigned int flags ) static int getrandom_wrapper( void *buf, size_t buflen, unsigned int flags )
{ {
/* MemSan cannot understand that the syscall writes to the buffer */ /* MemSan cannot understand that the syscall writes to the buffer */
#if defined(__has_feature) #if defined(__has_feature)
#if __has_feature(memory_sanitizer) #if __has_feature(memory_sanitizer)
memset( buf, 0, buflen ); memset( buf, 0, buflen );
#endif #endif
#endif #endif
return( syscall( SYS_getrandom, buf, buflen, flags ) ); return( syscall( SYS_getrandom, buf, buflen, flags ) );
} }
#include <sys/utsname.h> #include <sys/utsname.h>
/* Check if version is at least 3.17.0 */ /* Check if version is at least 3.17.0 */
static int check_version_3_17_plus( void ) static int check_version_3_17_plus( void )
{ {
int minor; int minor;
struct utsname un; struct utsname un;
const char *ver; const char *ver;
/* Get version information */ /* Get version information */
uname(&un); uname(&un);
ver = un.release; ver = un.release;
/* Check major version; assume a single digit */ /* Check major version; assume a single digit */
if( ver[0] < '3' || ver[0] > '9' || ver [1] != '.' ) if( ver[0] < '3' || ver[0] > '9' || ver [1] != '.' )
return( -1 ); return( -1 );
if( ver[0] - '0' > 3 ) if( ver[0] - '0' > 3 )
return( 0 ); return( 0 );
/* Ok, so now we know major == 3, check minor. /* Ok, so now we know major == 3, check minor.
* Assume 1 or 2 digits. */ * Assume 1 or 2 digits. */
if( ver[2] < '0' || ver[2] > '9' ) if( ver[2] < '0' || ver[2] > '9' )
return( -1 ); return( -1 );
minor = ver[2] - '0'; minor = ver[2] - '0';
if( ver[3] >= '0' && ver[3] <= '9' ) if( ver[3] >= '0' && ver[3] <= '9' )
minor = 10 * minor + ver[3] - '0'; minor = 10 * minor + ver[3] - '0';
else if( ver [3] != '.' ) else if( ver [3] != '.' )
return( -1 ); return( -1 );
if( minor < 17 ) if( minor < 17 )
return( -1 ); return( -1 );
return( 0 ); return( 0 );
} }
static int has_getrandom = -1; static int has_getrandom = -1;
#endif /* SYS_getrandom */ #endif /* SYS_getrandom */
#endif /* __linux__ */ #endif /* __linux__ */
#include <stdio.h> #include <stdio.h>
int mbedtls_platform_entropy_poll( void *data, int mbedtls_platform_entropy_poll( void *data,
unsigned char *output, size_t len, size_t *olen ) unsigned char *output, size_t len, size_t *olen )
{ {
FILE *file; FILE *file;
size_t read_len; size_t read_len;
((void) data); ((void) data);
#if defined(HAVE_GETRANDOM) #if defined(HAVE_GETRANDOM)
if( has_getrandom == -1 ) if( has_getrandom == -1 )
has_getrandom = ( check_version_3_17_plus() == 0 ); has_getrandom = ( check_version_3_17_plus() == 0 );
if( has_getrandom ) if( has_getrandom )
{ {
int ret; int ret;
if( ( ret = getrandom_wrapper( output, len, 0 ) ) < 0 ) if( ( ret = getrandom_wrapper( output, len, 0 ) ) < 0 )
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
*olen = ret; *olen = ret;
return( 0 ); return( 0 );
} }
#endif /* HAVE_GETRANDOM */ #endif /* HAVE_GETRANDOM */
*olen = 0; *olen = 0;
file = fopen( "/dev/urandom", "rb" ); file = fopen( "/dev/urandom", "rb" );
if( file == NULL ) if( file == NULL )
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
read_len = fread( output, 1, len, file ); read_len = fread( output, 1, len, file );
if( read_len != len ) if( read_len != len )
{ {
fclose( file ); fclose( file );
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
} }
fclose( file ); fclose( file );
*olen = len; *olen = len;
return( 0 ); return( 0 );
} }
#endif /* _WIN32 && !EFIX64 && !EFI32 */ #endif /* _WIN32 && !EFIX64 && !EFI32 */
#endif /* !MBEDTLS_NO_PLATFORM_ENTROPY */ #endif /* !MBEDTLS_NO_PLATFORM_ENTROPY */
#if defined(MBEDTLS_TEST_NULL_ENTROPY) #if defined(MBEDTLS_TEST_NULL_ENTROPY)
int mbedtls_null_entropy_poll( void *data, int mbedtls_null_entropy_poll( void *data,
unsigned char *output, size_t len, size_t *olen ) unsigned char *output, size_t len, size_t *olen )
{ {
((void) data); ((void) data);
((void) output); ((void) output);
*olen = 0; *olen = 0;
if( len < sizeof(unsigned char) ) if( len < sizeof(unsigned char) )
return( 0 ); return( 0 );
*olen = sizeof(unsigned char); *olen = sizeof(unsigned char);
return( 0 ); return( 0 );
} }
#endif #endif
#if defined(MBEDTLS_TIMING_C) #if defined(MBEDTLS_TIMING_C)
int mbedtls_hardclock_poll( void *data, int mbedtls_hardclock_poll( void *data,
unsigned char *output, size_t len, size_t *olen ) unsigned char *output, size_t len, size_t *olen )
{ {
unsigned long timer = mbedtls_timing_hardclock(); unsigned long timer = mbedtls_timing_hardclock();
((void) data); ((void) data);
*olen = 0; *olen = 0;
if( len < sizeof(unsigned long) ) if( len < sizeof(unsigned long) )
return( 0 ); return( 0 );
memcpy( output, &timer, sizeof(unsigned long) ); memcpy( output, &timer, sizeof(unsigned long) );
*olen = sizeof(unsigned long); *olen = sizeof(unsigned long);
return( 0 ); return( 0 );
} }
#endif /* MBEDTLS_TIMING_C */ #endif /* MBEDTLS_TIMING_C */
#if defined(MBEDTLS_HAVEGE_C) #if defined(MBEDTLS_HAVEGE_C)
int mbedtls_havege_poll( void *data, int mbedtls_havege_poll( void *data,
unsigned char *output, size_t len, size_t *olen ) unsigned char *output, size_t len, size_t *olen )
{ {
mbedtls_havege_state *hs = (mbedtls_havege_state *) data; mbedtls_havege_state *hs = (mbedtls_havege_state *) data;
*olen = 0; *olen = 0;
if( mbedtls_havege_random( hs, output, len ) != 0 ) if( mbedtls_havege_random( hs, output, len ) != 0 )
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
*olen = len; *olen = len;
return( 0 ); return( 0 );
} }
#endif /* MBEDTLS_HAVEGE_C */ #endif /* MBEDTLS_HAVEGE_C */
#if defined(MBEDTLS_ENTROPY_NV_SEED) #if defined(MBEDTLS_ENTROPY_NV_SEED)
int mbedtls_nv_seed_poll( void *data, int mbedtls_nv_seed_poll( void *data,
unsigned char *output, size_t len, size_t *olen ) unsigned char *output, size_t len, size_t *olen )
{ {
unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE]; unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE];
size_t use_len = MBEDTLS_ENTROPY_BLOCK_SIZE; size_t use_len = MBEDTLS_ENTROPY_BLOCK_SIZE;
((void) data); ((void) data);
memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE ); memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
if( mbedtls_nv_seed_read( buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) < 0 ) if( mbedtls_nv_seed_read( buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) < 0 )
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
if( len < use_len ) if( len < use_len )
use_len = len; use_len = len;
memcpy( output, buf, use_len ); memcpy( output, buf, use_len );
*olen = use_len; *olen = use_len;
return( 0 ); return( 0 );
} }
#endif /* MBEDTLS_ENTROPY_NV_SEED */ #endif /* MBEDTLS_ENTROPY_NV_SEED */
#endif /* MBEDTLS_ENTROPY_C */ #endif /* MBEDTLS_ENTROPY_C */

View File

@ -1,38 +1,179 @@
#include <kinc/graphics4/compute.h> #include <kinc/compute/compute.h>
#include <kinc/graphics4/texture.h> #include <kinc/graphics4/texture.h>
#include <hl.h> #include <hl.h>
vbyte *hl_kinc_g4_compute_create_shader(vbyte *data, int length) { vbyte *hl_kinc_compute_create_shader(vbyte *data, int length) {
kinc_g4_compute_shader *shader = (kinc_g4_compute_shader *)malloc(sizeof(kinc_g4_compute_shader)); kinc_compute_shader_t *shader = (kinc_compute_shader_t *)malloc(sizeof(kinc_compute_shader_t));
kinc_g4_compute_shader_init(shader, data, length); kinc_compute_shader_init(shader, data, length);
return (vbyte *)shader; return (vbyte *)shader;
} }
void hl_kinc_g4_compute_delete_shader(vbyte *shader) { void hl_kinc_compute_delete_shader(vbyte *shader) {
kinc_g4_compute_shader *sh = (kinc_g4_compute_shader *)shader; kinc_compute_shader_t *sh = (kinc_compute_shader_t *)shader;
kinc_g4_compute_shader_destroy(sh); kinc_compute_shader_destroy(sh);
free(sh); free(sh);
} }
vbyte *hl_kinc_g4_compute_get_constantlocation(vbyte *shader, vbyte *name) { vbyte *hl_kinc_compute_get_constantlocation(vbyte *shader, vbyte *name) {
kinc_g4_compute_shader *sh = (kinc_g4_compute_shader *)shader; kinc_compute_shader_t *sh = (kinc_compute_shader_t *)shader;
kinc_g4_constant_location_t *location = (kinc_g4_constant_location_t *)malloc(sizeof(kinc_g4_constant_location_t)); kinc_compute_constant_location_t *location = (kinc_compute_constant_location_t *)malloc(sizeof(kinc_compute_constant_location_t));
*location = kinc_g4_compute_shader_get_constant_location(sh, (char *)name), sizeof(kinc_g4_constant_location_t); *location = kinc_compute_shader_get_constant_location(sh, (char *)name), sizeof(kinc_compute_constant_location_t);
return (vbyte *)location; return (vbyte *)location;
} }
vbyte *hl_kinc_g4_compute_get_textureunit(vbyte *shader, vbyte *name) { vbyte *hl_kinc_compute_get_textureunit(vbyte *shader, vbyte *name) {
kinc_g4_compute_shader *sh = (kinc_g4_compute_shader *)shader; kinc_compute_shader_t *sh = (kinc_compute_shader_t *)shader;
kinc_g4_texture_unit_t *unit = (kinc_g4_texture_unit_t *)malloc(sizeof(kinc_g4_texture_unit_t)); kinc_compute_texture_unit_t *unit = (kinc_compute_texture_unit_t *)malloc(sizeof(kinc_compute_texture_unit_t));
*unit = kinc_g4_compute_shader_get_texture_unit(sh, (char *)name), sizeof(kinc_g4_texture_unit_t); *unit = kinc_compute_shader_get_texture_unit(sh, (char *)name), sizeof(kinc_compute_texture_unit_t);
return (vbyte *)unit; return (vbyte *)unit;
} }
void hl_kinc_g4_set_compute_shader(vbyte *shader) { void hl_kinc_compute_set_bool(vbyte *location, bool value) {
kinc_g4_set_compute_shader((kinc_g4_compute_shader *)shader); kinc_compute_constant_location_t *loc = (kinc_compute_constant_location_t *)location;
kinc_compute_set_bool(*loc, value);
} }
void hl_kinc_g4_compute(int x, int y, int z) { void hl_kinc_compute_set_int(vbyte *location, int value) {
kinc_g4_compute(x, y, z); kinc_compute_constant_location_t *loc = (kinc_compute_constant_location_t *)location;
kinc_compute_set_int(*loc, value);
}
void hl_kinc_compute_set_float(vbyte *location, float value) {
kinc_compute_constant_location_t *loc = (kinc_compute_constant_location_t *)location;
kinc_compute_set_float(*loc, value);
}
void hl_kinc_compute_set_float2(vbyte *location, float value1, float value2) {
kinc_compute_constant_location_t *loc = (kinc_compute_constant_location_t *)location;
kinc_compute_set_float2(*loc, value1, value2);
}
void hl_kinc_compute_set_float3(vbyte *location, float value1, float value2, float value3) {
kinc_compute_constant_location_t *loc = (kinc_compute_constant_location_t *)location;
kinc_compute_set_float3(*loc, value1, value2, value3);
}
void hl_kinc_compute_set_float4(vbyte *location, float value1, float value2, float value3, float value4) {
kinc_compute_constant_location_t *loc = (kinc_compute_constant_location_t *)location;
kinc_compute_set_float4(*loc, value1, value2, value3, value4);
}
void hl_kinc_compute_set_floats(vbyte *location, vbyte *values, int count) {
kinc_compute_constant_location_t *loc = (kinc_compute_constant_location_t *)location;
kinc_compute_set_floats(*loc, (float *)values, count);
}
void hl_kinc_compute_set_matrix(vbyte *location, float _00, float _10, float _20, float _30, float _01, float _11, float _21, float _31, float _02, float _12,
float _22, float _32, float _03, float _13, float _23, float _33) {
kinc_compute_constant_location_t *loc = (kinc_compute_constant_location_t *)location;
kinc_matrix4x4_t value;
kinc_matrix4x4_set(&value, 0, 0, _00);
kinc_matrix4x4_set(&value, 0, 1, _01);
kinc_matrix4x4_set(&value, 0, 2, _02);
kinc_matrix4x4_set(&value, 0, 3, _03);
kinc_matrix4x4_set(&value, 1, 0, _10);
kinc_matrix4x4_set(&value, 1, 1, _11);
kinc_matrix4x4_set(&value, 1, 2, _12);
kinc_matrix4x4_set(&value, 1, 3, _13);
kinc_matrix4x4_set(&value, 2, 0, _20);
kinc_matrix4x4_set(&value, 2, 1, _21);
kinc_matrix4x4_set(&value, 2, 2, _22);
kinc_matrix4x4_set(&value, 2, 3, _23);
kinc_matrix4x4_set(&value, 3, 0, _30);
kinc_matrix4x4_set(&value, 3, 1, _31);
kinc_matrix4x4_set(&value, 3, 2, _32);
kinc_matrix4x4_set(&value, 3, 3, _33);
kinc_compute_set_matrix4(*loc, &value);
}
void hl_kinc_compute_set_matrix3(vbyte *location, float _00, float _10, float _20, float _01, float _11, float _21, float _02, float _12, float _22) {
kinc_compute_constant_location_t *loc = (kinc_compute_constant_location_t *)location;
kinc_matrix3x3_t value;
kinc_matrix3x3_set(&value, 0, 0, _00);
kinc_matrix3x3_set(&value, 0, 1, _01);
kinc_matrix3x3_set(&value, 0, 2, _02);
kinc_matrix3x3_set(&value, 1, 0, _10);
kinc_matrix3x3_set(&value, 1, 1, _11);
kinc_matrix3x3_set(&value, 1, 2, _12);
kinc_matrix3x3_set(&value, 2, 0, _20);
kinc_matrix3x3_set(&value, 2, 1, _21);
kinc_matrix3x3_set(&value, 2, 2, _22);
kinc_compute_set_matrix3(*loc, &value);
}
void hl_kinc_compute_set_texture(vbyte *unit, vbyte *texture, int access) {
kinc_compute_texture_unit_t *u = (kinc_compute_texture_unit_t *)unit;
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
kinc_compute_set_texture(*u, tex, (kinc_compute_access_t)access);
}
void hl_kinc_compute_set_target(vbyte *unit, vbyte *renderTarget, int access) {
kinc_compute_texture_unit_t *u = (kinc_compute_texture_unit_t *)unit;
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
kinc_compute_set_render_target(*u, rt, (kinc_compute_access_t)access);
}
void hl_kinc_compute_set_sampled_texture(vbyte *unit, vbyte *texture) {
kinc_compute_texture_unit_t *u = (kinc_compute_texture_unit_t *)unit;
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
kinc_compute_set_sampled_texture(*u, tex);
}
void hl_kinc_compute_set_sampled_target(vbyte *unit, vbyte *renderTarget) {
kinc_compute_texture_unit_t *u = (kinc_compute_texture_unit_t *)unit;
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
kinc_compute_set_sampled_render_target(*u, rt);
}
void hl_kinc_compute_set_sampled_depth_target(vbyte *unit, vbyte *renderTarget) {
kinc_compute_texture_unit_t *u = (kinc_compute_texture_unit_t *)unit;
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
kinc_compute_set_sampled_depth_from_render_target(*u, rt);
}
void hl_kinc_compute_set_sampled_cubemap_texture(vbyte *unit, vbyte *texture) {
kinc_compute_texture_unit_t *u = (kinc_compute_texture_unit_t *)unit;
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
kinc_compute_set_sampled_texture(*u, tex);
}
void hl_kinc_compute_set_sampled_cubemap_target(vbyte *unit, vbyte *renderTarget) {
kinc_compute_texture_unit_t *u = (kinc_compute_texture_unit_t *)unit;
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
kinc_compute_set_sampled_render_target(*u, rt);
}
void hl_kinc_compute_set_sampled_cubemap_depth_target(vbyte *unit, vbyte *renderTarget) {
kinc_compute_texture_unit_t *u = (kinc_compute_texture_unit_t *)unit;
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
kinc_compute_set_sampled_depth_from_render_target(*u, rt);
}
void hl_kinc_compute_set_texture_parameters(vbyte *unit, int uAddressing, int vAddressing, int minificationFilter, int magnificationFilter, int mipmapFilter) {
kinc_compute_texture_unit_t *u = (kinc_compute_texture_unit_t *)unit;
kinc_compute_set_texture_addressing(*u, KINC_G4_TEXTURE_DIRECTION_U, (kinc_g4_texture_addressing_t)uAddressing);
kinc_compute_set_texture_addressing(*u, KINC_G4_TEXTURE_DIRECTION_V, (kinc_g4_texture_addressing_t)vAddressing);
kinc_compute_set_texture_minification_filter(*u, (kinc_g4_texture_filter_t)minificationFilter);
kinc_compute_set_texture_magnification_filter(*u, (kinc_g4_texture_filter_t)magnificationFilter);
kinc_compute_set_texture_mipmap_filter(*u, (kinc_g4_mipmap_filter_t)mipmapFilter);
}
void hl_kinc_compute_set_texture3d_parameters(vbyte *unit, int uAddressing, int vAddressing, int wAddressing, int minificationFilter, int magnificationFilter,
int mipmapFilter) {
kinc_compute_texture_unit_t *u = (kinc_compute_texture_unit_t *)unit;
kinc_compute_set_texture3d_addressing(*u, KINC_G4_TEXTURE_DIRECTION_U, (kinc_g4_texture_addressing_t)uAddressing);
kinc_compute_set_texture3d_addressing(*u, KINC_G4_TEXTURE_DIRECTION_V, (kinc_g4_texture_addressing_t)vAddressing);
kinc_compute_set_texture3d_addressing(*u, KINC_G4_TEXTURE_DIRECTION_W, (kinc_g4_texture_addressing_t)wAddressing);
kinc_compute_set_texture3d_minification_filter(*u, (kinc_g4_texture_filter_t)minificationFilter);
kinc_compute_set_texture3d_magnification_filter(*u, (kinc_g4_texture_filter_t)magnificationFilter);
kinc_compute_set_texture3d_mipmap_filter(*u, (kinc_g4_mipmap_filter_t)mipmapFilter);
}
void hl_kinc_compute_set_shader(vbyte *shader) {
kinc_compute_set_shader((kinc_compute_shader_t *)shader);
}
void hl_kinc_compute_compute(int x, int y, int z) {
kinc_compute(x, y, z);
} }

View File

@ -1,129 +1,127 @@
#include <kinc/audio2/audio.h> #include <kinc/audio2/audio.h>
#include <kinc/graphics4/graphics.h> #include <kinc/graphics4/graphics.h>
#include <kinc/io/filereader.h> #include <kinc/io/filereader.h>
#include <kinc/log.h> #include <kinc/log.h>
#include <kinc/system.h> #include <kinc/system.h>
#include <kinc/window.h> #include <kinc/window.h>
#include <hl.h> #include <hl.h>
void frame(); void frame();
static bool visible = true; static bool visible = true;
static bool paused = false; static bool paused = false;
typedef void (*FN_AUDIO_CALL_CALLBACK)(int); typedef void (*FN_AUDIO_CALL_CALLBACK)(int);
typedef float (*FN_AUDIO_READ_SAMPLE)(void); typedef float (*FN_AUDIO_READ_SAMPLE)(void);
void (*audioCallCallback)(int); void (*audioCallCallback)(int);
float (*audioReadSample)(void); float (*audioReadSample)(void);
static void update(void *data) { static void update(void *data) {
if (paused) { if (paused) {
return; return;
} }
kinc_a2_update(); kinc_a2_update();
int windowCount = kinc_count_windows(); int windowCount = kinc_count_windows();
for (int windowIndex = 0; windowIndex < windowCount; ++windowIndex) { for (int windowIndex = 0; windowIndex < windowCount; ++windowIndex) {
if (visible) { if (visible) {
kinc_g4_begin(windowIndex); kinc_g4_begin(windowIndex);
frame(); frame();
kinc_g4_end(windowIndex); kinc_g4_end(windowIndex);
} }
} }
if (!kinc_g4_swap_buffers()) { if (!kinc_g4_swap_buffers()) {
kinc_log(KINC_LOG_LEVEL_ERROR, "Graphics context lost."); kinc_log(KINC_LOG_LEVEL_ERROR, "Graphics context lost.");
} }
} }
static bool mixThreadregistered = false; static bool mixThreadregistered = false;
static void mix(kinc_a2_buffer_t *buffer, uint32_t samples, void *userdata) { static void mix(kinc_a2_buffer_t *buffer, int samples) {
#ifdef KINC_MULTITHREADED_AUDIO #ifdef KORE_MULTITHREADED_AUDIO
if (!mixThreadregistered) { if (!mixThreadregistered) {
vdynamic *ret; vdynamic *ret;
hl_register_thread(&ret); hl_register_thread(&ret);
mixThreadregistered = true; mixThreadregistered = true;
} }
hl_blocking(true); hl_blocking(true);
#endif #endif
audioCallCallback(samples); audioCallCallback(samples);
for (uint32_t i = 0; i < samples; i += 2) { for (int i = 0; i < samples; ++i) {
float left_value = audioReadSample(); float value = audioReadSample();
float right_value = audioReadSample(); *(float *)&buffer->data[buffer->write_location] = value;
*(float *)&buffer->channels[0][buffer->write_location] = left_value; buffer->write_location += 4;
*(float *)&buffer->channels[1][buffer->write_location] = right_value; if (buffer->write_location >= buffer->data_size) {
buffer->write_location += 1; buffer->write_location = 0;
if (buffer->write_location >= buffer->data_size) { }
buffer->write_location = 0; }
}
} #ifdef KORE_MULTITHREADED_AUDIO
hl_blocking(false);
#ifdef KINC_MULTITHREADED_AUDIO #endif
hl_blocking(false); }
#endif
} void hl_init_kore(vbyte *title, int width, int height, int samplesPerPixel, bool vSync, int windowMode, int windowFeatures) {
kinc_log(KINC_LOG_LEVEL_INFO, "Starting KincHL");
void hl_init_kore(vbyte *title, int width, int height, int samplesPerPixel, bool vSync, int windowMode, int windowFeatures) {
kinc_log(KINC_LOG_LEVEL_INFO, "Starting KincHL"); kinc_window_options_t win;
kinc_window_options_set_defaults(&win);
kinc_window_options_t win; win.title = (char *)title;
kinc_window_options_set_defaults(&win); win.width = width;
win.title = (char *)title; win.height = height;
win.width = width; win.x = -1;
win.height = height; win.y = -1;
win.x = -1; win.mode = (kinc_window_mode_t)windowMode;
win.y = -1; win.window_features = windowFeatures;
win.mode = (kinc_window_mode_t)windowMode; kinc_framebuffer_options_t frame;
win.window_features = windowFeatures; kinc_framebuffer_options_set_defaults(&frame);
kinc_framebuffer_options_t frame; frame.vertical_sync = vSync;
kinc_framebuffer_options_set_defaults(&frame); frame.samples_per_pixel = samplesPerPixel;
frame.vertical_sync = vSync; kinc_init((char *)title, width, height, &win, &frame);
frame.samples_per_pixel = samplesPerPixel;
kinc_init((char *)title, width, height, &win, &frame); kinc_set_update_callback(update, NULL);
}
kinc_set_update_callback(update, NULL);
} void hl_kinc_init_audio(vclosure *callCallback, vclosure *readSample, int *outSamplesPerSecond) {
audioCallCallback = *((FN_AUDIO_CALL_CALLBACK *)(&callCallback->fun));
void hl_kinc_init_audio(vclosure *callCallback, vclosure *readSample, int *outSamplesPerSecond) { audioReadSample = *((FN_AUDIO_READ_SAMPLE *)(&readSample->fun));
audioCallCallback = *((FN_AUDIO_CALL_CALLBACK *)(&callCallback->fun)); kinc_a2_set_callback(mix);
audioReadSample = *((FN_AUDIO_READ_SAMPLE *)(&readSample->fun)); kinc_a2_init();
kinc_a2_set_callback(mix, NULL); *outSamplesPerSecond = kinc_a2_samples_per_second;
kinc_a2_init(); }
*outSamplesPerSecond = kinc_a2_samples_per_second();
} void hl_run_kore(void) {
kinc_start();
void hl_run_kore(void) { }
kinc_start();
} vbyte *hl_kinc_file_contents(vbyte *name, int *size) {
int len;
vbyte *hl_kinc_file_contents(vbyte *name, int *size) { int p = 0;
int len; vbyte *content;
int p = 0; kinc_file_reader_t file;
vbyte *content; if (!kinc_file_reader_open(&file, (char *)name, KINC_FILE_TYPE_ASSET)) {
kinc_file_reader_t file; return NULL;
if (!kinc_file_reader_open(&file, (char *)name, KINC_FILE_TYPE_ASSET)) { }
return NULL; hl_blocking(true);
} len = (int)kinc_file_reader_size(&file);
hl_blocking(true); if (size) {
len = (int)kinc_file_reader_size(&file); *size = len;
if (size) { }
*size = len; hl_blocking(false);
} content = (vbyte *)hl_gc_alloc_noptr(size ? len : len + 1);
hl_blocking(false); hl_blocking(true);
content = (vbyte *)hl_gc_alloc_noptr(size ? len : len + 1); if (!size) {
hl_blocking(true); content[len] = 0; // final 0 for UTF8
if (!size) { }
content[len] = 0; // final 0 for UTF8 kinc_file_reader_read(&file, content, len);
} kinc_file_reader_close(&file);
kinc_file_reader_read(&file, content, len); hl_blocking(false);
kinc_file_reader_close(&file); return content;
hl_blocking(false); }
return content;
}

View File

@ -1,265 +1,265 @@
#include <kinc/graphics4/graphics.h> #include <kinc/graphics4/graphics.h>
#include <kinc/graphics4/pipeline.h> #include <kinc/graphics4/pipeline.h>
#include <kinc/graphics4/shader.h> #include <kinc/graphics4/shader.h>
#include <kinc/graphics4/vertexstructure.h> #include <kinc/graphics4/vertexstructure.h>
#include <hl.h> #include <hl.h>
static kinc_g4_compare_mode_t convertCompareMode(int mode) { static kinc_g4_compare_mode_t convertCompareMode(int mode) {
switch (mode) { switch (mode) {
case 0: case 0:
return KINC_G4_COMPARE_ALWAYS; return KINC_G4_COMPARE_ALWAYS;
case 1: case 1:
return KINC_G4_COMPARE_NEVER; return KINC_G4_COMPARE_NEVER;
case 2: case 2:
return KINC_G4_COMPARE_EQUAL; return KINC_G4_COMPARE_EQUAL;
case 3: case 3:
return KINC_G4_COMPARE_NOT_EQUAL; return KINC_G4_COMPARE_NOT_EQUAL;
case 4: case 4:
return KINC_G4_COMPARE_LESS; return KINC_G4_COMPARE_LESS;
case 5: case 5:
return KINC_G4_COMPARE_LESS_EQUAL; return KINC_G4_COMPARE_LESS_EQUAL;
case 6: case 6:
return KINC_G4_COMPARE_GREATER; return KINC_G4_COMPARE_GREATER;
case 7: case 7:
default: default:
return KINC_G4_COMPARE_GREATER_EQUAL; return KINC_G4_COMPARE_GREATER_EQUAL;
} }
} }
static kinc_g4_stencil_action_t convertStencilAction(int action) { static kinc_g4_stencil_action_t convertStencilAction(int action) {
switch (action) { switch (action) {
case 0: case 0:
return KINC_G4_STENCIL_KEEP; return KINC_G4_STENCIL_KEEP;
case 1: case 1:
return KINC_G4_STENCIL_ZERO; return KINC_G4_STENCIL_ZERO;
case 2: case 2:
return KINC_G4_STENCIL_REPLACE; return KINC_G4_STENCIL_REPLACE;
case 3: case 3:
return KINC_G4_STENCIL_INCREMENT; return KINC_G4_STENCIL_INCREMENT;
case 4: case 4:
return KINC_G4_STENCIL_INCREMENT_WRAP; return KINC_G4_STENCIL_INCREMENT_WRAP;
case 5: case 5:
return KINC_G4_STENCIL_DECREMENT; return KINC_G4_STENCIL_DECREMENT;
case 6: case 6:
return KINC_G4_STENCIL_DECREMENT_WRAP; return KINC_G4_STENCIL_DECREMENT_WRAP;
case 7: case 7:
default: default:
return KINC_G4_STENCIL_INVERT; return KINC_G4_STENCIL_INVERT;
} }
} }
static kinc_g4_render_target_format_t convertColorAttachment(int format) { static kinc_g4_render_target_format_t convertColorAttachment(int format) {
switch (format) { switch (format) {
case 0: case 0:
return KINC_G4_RENDER_TARGET_FORMAT_32BIT; return KINC_G4_RENDER_TARGET_FORMAT_32BIT;
case 1: case 1:
return KINC_G4_RENDER_TARGET_FORMAT_8BIT_RED; return KINC_G4_RENDER_TARGET_FORMAT_8BIT_RED;
case 2: case 2:
return KINC_G4_RENDER_TARGET_FORMAT_128BIT_FLOAT; return KINC_G4_RENDER_TARGET_FORMAT_128BIT_FLOAT;
case 3: case 3:
return KINC_G4_RENDER_TARGET_FORMAT_16BIT_DEPTH; return KINC_G4_RENDER_TARGET_FORMAT_16BIT_DEPTH;
case 4: case 4:
return KINC_G4_RENDER_TARGET_FORMAT_64BIT_FLOAT; return KINC_G4_RENDER_TARGET_FORMAT_64BIT_FLOAT;
case 5: case 5:
return KINC_G4_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT; return KINC_G4_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT;
case 6: case 6:
default: default:
return KINC_G4_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT; return KINC_G4_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT;
} }
} }
vbyte *hl_kinc_create_vertexshader(vbyte *data, int length) { vbyte *hl_kinc_create_vertexshader(vbyte *data, int length) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t)); kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_VERTEX); kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_VERTEX);
return (vbyte *)shader; return (vbyte *)shader;
} }
vbyte *hl_kinc_create_fragmentshader(vbyte *data, int length) { vbyte *hl_kinc_create_fragmentshader(vbyte *data, int length) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t)); kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_FRAGMENT); kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_FRAGMENT);
return (vbyte *)shader; return (vbyte *)shader;
} }
vbyte *hl_kinc_create_geometryshader(vbyte *data, int length) { vbyte *hl_kinc_create_geometryshader(vbyte *data, int length) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t)); kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_GEOMETRY); kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_GEOMETRY);
return (vbyte *)shader; return (vbyte *)shader;
} }
vbyte *hl_kinc_create_tesscontrolshader(vbyte *data, int length) { vbyte *hl_kinc_create_tesscontrolshader(vbyte *data, int length) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t)); kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_TESSELLATION_CONTROL); kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_TESSELLATION_CONTROL);
return (vbyte *)shader; return (vbyte *)shader;
} }
vbyte *hl_kinc_create_tessevalshader(vbyte *data, int length) { vbyte *hl_kinc_create_tessevalshader(vbyte *data, int length) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t)); kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_TESSELLATION_EVALUATION); kinc_g4_shader_init(shader, data, length, KINC_G4_SHADER_TYPE_TESSELLATION_EVALUATION);
return (vbyte *)shader; return (vbyte *)shader;
} }
vbyte *hl_kinc_vertexshader_from_source(vbyte *source) { vbyte *hl_kinc_vertexshader_from_source(vbyte *source) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t)); kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_VERTEX); kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_VERTEX);
return (vbyte *)shader; return (vbyte *)shader;
} }
vbyte *hl_kinc_fragmentshader_from_source(vbyte *source) { vbyte *hl_kinc_fragmentshader_from_source(vbyte *source) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t)); kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_FRAGMENT); kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_FRAGMENT);
return (vbyte *)shader; return (vbyte *)shader;
} }
vbyte *hl_kinc_geometryshader_from_source(vbyte *source) { vbyte *hl_kinc_geometryshader_from_source(vbyte *source) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t)); kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_GEOMETRY); kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_GEOMETRY);
return (vbyte *)shader; return (vbyte *)shader;
} }
vbyte *hl_kinc_tesscontrolshader_from_source(vbyte *source) { vbyte *hl_kinc_tesscontrolshader_from_source(vbyte *source) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t)); kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_TESSELLATION_CONTROL); kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_TESSELLATION_CONTROL);
return (vbyte *)shader; return (vbyte *)shader;
} }
vbyte *hl_kinc_tessevalshader_from_source(vbyte *source) { vbyte *hl_kinc_tessevalshader_from_source(vbyte *source) {
kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t)); kinc_g4_shader_t *shader = (kinc_g4_shader_t *)malloc(sizeof(kinc_g4_shader_t));
kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_TESSELLATION_EVALUATION); kinc_g4_shader_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_TESSELLATION_EVALUATION);
return (vbyte *)shader; return (vbyte *)shader;
} }
vbyte *hl_kinc_create_pipeline() { vbyte *hl_kinc_create_pipeline() {
kinc_g4_pipeline_t *pipeline = (kinc_g4_pipeline_t *)malloc(sizeof(kinc_g4_pipeline_t)); kinc_g4_pipeline_t *pipeline = (kinc_g4_pipeline_t *)malloc(sizeof(kinc_g4_pipeline_t));
kinc_g4_pipeline_init(pipeline); kinc_g4_pipeline_init(pipeline);
return (vbyte *)pipeline; return (vbyte *)pipeline;
} }
void hl_kinc_delete_pipeline(vbyte *pipeline) { void hl_kinc_delete_pipeline(vbyte *pipeline) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline; kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_pipeline_destroy(pipe); kinc_g4_pipeline_destroy(pipe);
free(pipe); free(pipe);
} }
void hl_kinc_pipeline_set_vertex_shader(vbyte *pipeline, vbyte *shader) { void hl_kinc_pipeline_set_vertex_shader(vbyte *pipeline, vbyte *shader) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline; kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader; kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
pipe->vertex_shader = sh; pipe->vertex_shader = sh;
} }
void hl_kinc_pipeline_set_fragment_shader(vbyte *pipeline, vbyte *shader) { void hl_kinc_pipeline_set_fragment_shader(vbyte *pipeline, vbyte *shader) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline; kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader; kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
pipe->fragment_shader = sh; pipe->fragment_shader = sh;
} }
void hl_kinc_pipeline_set_geometry_shader(vbyte *pipeline, vbyte *shader) { void hl_kinc_pipeline_set_geometry_shader(vbyte *pipeline, vbyte *shader) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline; kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader; kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
pipe->geometry_shader = sh; pipe->geometry_shader = sh;
} }
void hl_kinc_pipeline_set_tesscontrol_shader(vbyte *pipeline, vbyte *shader) { void hl_kinc_pipeline_set_tesscontrol_shader(vbyte *pipeline, vbyte *shader) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline; kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader; kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
pipe->tessellation_control_shader = sh; pipe->tessellation_control_shader = sh;
} }
void hl_kinc_pipeline_set_tesseval_shader(vbyte *pipeline, vbyte *shader) { void hl_kinc_pipeline_set_tesseval_shader(vbyte *pipeline, vbyte *shader) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline; kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader; kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
pipe->tessellation_evaluation_shader = sh; pipe->tessellation_evaluation_shader = sh;
} }
void hl_kinc_pipeline_compile(vbyte *pipeline, vbyte *structure0, vbyte *structure1, vbyte *structure2, vbyte *structure3) { void hl_kinc_pipeline_compile(vbyte *pipeline, vbyte *structure0, vbyte *structure1, vbyte *structure2, vbyte *structure3) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline; kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
pipe->input_layout[0] = (kinc_g4_vertex_structure_t *)structure0; pipe->input_layout[0] = (kinc_g4_vertex_structure_t *)structure0;
pipe->input_layout[1] = (kinc_g4_vertex_structure_t *)structure1; pipe->input_layout[1] = (kinc_g4_vertex_structure_t *)structure1;
pipe->input_layout[2] = (kinc_g4_vertex_structure_t *)structure2; pipe->input_layout[2] = (kinc_g4_vertex_structure_t *)structure2;
pipe->input_layout[3] = (kinc_g4_vertex_structure_t *)structure3; pipe->input_layout[3] = (kinc_g4_vertex_structure_t *)structure3;
pipe->input_layout[4] = NULL; pipe->input_layout[4] = NULL;
kinc_g4_pipeline_compile(pipe); kinc_g4_pipeline_compile(pipe);
} }
void hl_kinc_pipeline_set_states(vbyte *pipeline, int cullMode, int depthMode, int stencilFrontMode, int stencilFrontBothPass, int stencilFrontDepthFail, void hl_kinc_pipeline_set_states(vbyte *pipeline, int cullMode, int depthMode, int stencilFrontMode, int stencilFrontBothPass, int stencilFrontDepthFail,
int stencilFrontFail, int stencilBackMode, int stencilBackBothPass, int stencilBackDepthFail, int stencilBackFail, int stencilFrontFail, int stencilBackMode, int stencilBackBothPass, int stencilBackDepthFail, int stencilBackFail,
int blendSource, int blendDestination, int alphaBlendSource, int alphaBlendDestination, bool depthWrite, int blendSource, int blendDestination, int alphaBlendSource, int alphaBlendDestination, bool depthWrite,
int stencilReferenceValue, int stencilReadMask, int stencilWriteMask, bool colorWriteMaskRed, bool colorWriteMaskGreen, int stencilReferenceValue, int stencilReadMask, int stencilWriteMask, bool colorWriteMaskRed, bool colorWriteMaskGreen,
bool colorWriteMaskBlue, bool colorWriteMaskAlpha, int colorAttachmentCount, int colorAttachment0, int colorAttachment1, bool colorWriteMaskBlue, bool colorWriteMaskAlpha, int colorAttachmentCount, int colorAttachment0, int colorAttachment1,
int colorAttachment2, int colorAttachment3, int colorAttachment4, int colorAttachment5, int colorAttachment6, int colorAttachment2, int colorAttachment3, int colorAttachment4, int colorAttachment5, int colorAttachment6,
int colorAttachment7, int depthAttachmentBits, int stencilAttachmentBits, bool conservativeRasterization) { int colorAttachment7, int depthAttachmentBits, int stencilAttachmentBits, bool conservativeRasterization) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline; kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
switch (cullMode) { switch (cullMode) {
case 0: case 0:
pipe->cull_mode = KINC_G4_CULL_CLOCKWISE; pipe->cull_mode = KINC_G4_CULL_CLOCKWISE;
break; break;
case 1: case 1:
pipe->cull_mode = KINC_G4_CULL_COUNTER_CLOCKWISE; pipe->cull_mode = KINC_G4_CULL_COUNTER_CLOCKWISE;
break; break;
case 2: case 2:
pipe->cull_mode = KINC_G4_CULL_NOTHING; pipe->cull_mode = KINC_G4_CULL_NOTHING;
break; break;
} }
pipe->depth_mode = convertCompareMode(depthMode); pipe->depth_mode = convertCompareMode(depthMode);
pipe->depth_write = depthWrite; pipe->depth_write = depthWrite;
pipe->stencil_front_mode = convertCompareMode(stencilFrontMode); pipe->stencil_front_mode = convertCompareMode(stencilFrontMode);
pipe->stencil_front_both_pass = convertStencilAction(stencilFrontBothPass); pipe->stencil_front_both_pass = convertStencilAction(stencilFrontBothPass);
pipe->stencil_front_depth_fail = convertStencilAction(stencilFrontDepthFail); pipe->stencil_front_depth_fail = convertStencilAction(stencilFrontDepthFail);
pipe->stencil_front_fail = convertStencilAction(stencilFrontFail); pipe->stencil_front_fail = convertStencilAction(stencilFrontFail);
pipe->stencil_back_mode = convertCompareMode(stencilBackMode); pipe->stencil_back_mode = convertCompareMode(stencilBackMode);
pipe->stencil_back_both_pass = convertStencilAction(stencilBackBothPass); pipe->stencil_back_both_pass = convertStencilAction(stencilBackBothPass);
pipe->stencil_back_depth_fail = convertStencilAction(stencilBackDepthFail); pipe->stencil_back_depth_fail = convertStencilAction(stencilBackDepthFail);
pipe->stencil_back_fail = convertStencilAction(stencilBackFail); pipe->stencil_back_fail = convertStencilAction(stencilBackFail);
pipe->stencil_reference_value = stencilReferenceValue; pipe->stencil_reference_value = stencilReferenceValue;
pipe->stencil_read_mask = stencilReadMask; pipe->stencil_read_mask = stencilReadMask;
pipe->stencil_write_mask = stencilWriteMask; pipe->stencil_write_mask = stencilWriteMask;
pipe->blend_source = (kinc_g4_blending_factor_t)blendSource; pipe->blend_source = (kinc_g4_blending_factor_t)blendSource;
pipe->blend_destination = (kinc_g4_blending_factor_t)blendDestination; pipe->blend_destination = (kinc_g4_blending_factor_t)blendDestination;
pipe->alpha_blend_source = (kinc_g4_blending_factor_t)alphaBlendSource; pipe->alpha_blend_source = (kinc_g4_blending_factor_t)alphaBlendSource;
pipe->alpha_blend_destination = (kinc_g4_blending_factor_t)alphaBlendDestination; pipe->alpha_blend_destination = (kinc_g4_blending_factor_t)alphaBlendDestination;
pipe->color_write_mask_red[0] = colorWriteMaskRed; pipe->color_write_mask_red[0] = colorWriteMaskRed;
pipe->color_write_mask_green[0] = colorWriteMaskGreen; pipe->color_write_mask_green[0] = colorWriteMaskGreen;
pipe->color_write_mask_blue[0] = colorWriteMaskBlue; pipe->color_write_mask_blue[0] = colorWriteMaskBlue;
pipe->color_write_mask_alpha[0] = colorWriteMaskAlpha; pipe->color_write_mask_alpha[0] = colorWriteMaskAlpha;
pipe->color_attachment_count = colorAttachmentCount; pipe->color_attachment_count = colorAttachmentCount;
pipe->color_attachment[0] = convertColorAttachment(colorAttachment0); pipe->color_attachment[0] = convertColorAttachment(colorAttachment0);
pipe->color_attachment[1] = convertColorAttachment(colorAttachment1); pipe->color_attachment[1] = convertColorAttachment(colorAttachment1);
pipe->color_attachment[2] = convertColorAttachment(colorAttachment2); pipe->color_attachment[2] = convertColorAttachment(colorAttachment2);
pipe->color_attachment[3] = convertColorAttachment(colorAttachment3); pipe->color_attachment[3] = convertColorAttachment(colorAttachment3);
pipe->color_attachment[4] = convertColorAttachment(colorAttachment4); pipe->color_attachment[4] = convertColorAttachment(colorAttachment4);
pipe->color_attachment[5] = convertColorAttachment(colorAttachment5); pipe->color_attachment[5] = convertColorAttachment(colorAttachment5);
pipe->color_attachment[6] = convertColorAttachment(colorAttachment6); pipe->color_attachment[6] = convertColorAttachment(colorAttachment6);
pipe->color_attachment[7] = convertColorAttachment(colorAttachment7); pipe->color_attachment[7] = convertColorAttachment(colorAttachment7);
pipe->depth_attachment_bits = depthAttachmentBits; pipe->depth_attachment_bits = depthAttachmentBits;
pipe->stencil_attachment_bits = stencilAttachmentBits; pipe->stencil_attachment_bits = stencilAttachmentBits;
pipe->conservative_rasterization = conservativeRasterization; pipe->conservative_rasterization = conservativeRasterization;
} }
void hl_kinc_pipeline_set(vbyte *pipeline) { void hl_kinc_pipeline_set(vbyte *pipeline) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline; kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_set_pipeline(pipe); kinc_g4_set_pipeline(pipe);
} }
vbyte *hl_kinc_pipeline_get_constantlocation(vbyte *pipeline, vbyte *name) { vbyte *hl_kinc_pipeline_get_constantlocation(vbyte *pipeline, vbyte *name) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline; kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_constant_location_t *location = (kinc_g4_constant_location_t *)malloc(sizeof(kinc_g4_constant_location_t)); kinc_g4_constant_location_t *location = (kinc_g4_constant_location_t *)malloc(sizeof(kinc_g4_constant_location_t));
*location = kinc_g4_pipeline_get_constant_location(pipe, (char *)name); *location = kinc_g4_pipeline_get_constant_location(pipe, (char *)name);
return (vbyte *)location; return (vbyte *)location;
} }
vbyte *hl_kinc_pipeline_get_textureunit(vbyte *pipeline, vbyte *name) { vbyte *hl_kinc_pipeline_get_textureunit(vbyte *pipeline, vbyte *name) {
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline; kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
kinc_g4_texture_unit_t *unit = (kinc_g4_texture_unit_t *)malloc(sizeof(kinc_g4_texture_unit_t)); kinc_g4_texture_unit_t *unit = (kinc_g4_texture_unit_t *)malloc(sizeof(kinc_g4_texture_unit_t));
*unit = kinc_g4_pipeline_get_texture_unit(pipe, (char *)name); *unit = kinc_g4_pipeline_get_texture_unit(pipe, (char *)name);
return (vbyte *)unit; return (vbyte *)unit;
} }

View File

@ -1,201 +1,201 @@
#include <kinc/input/acceleration.h> #include <kinc/input/acceleration.h>
#include <kinc/input/gamepad.h> #include <kinc/input/gamepad.h>
#include <kinc/input/keyboard.h> #include <kinc/input/keyboard.h>
#include <kinc/input/mouse.h> #include <kinc/input/mouse.h>
#include <kinc/input/pen.h> #include <kinc/input/pen.h>
#include <kinc/input/rotation.h> #include <kinc/input/rotation.h>
#include <kinc/input/surface.h> #include <kinc/input/surface.h>
#include <kinc/log.h> #include <kinc/log.h>
#include <kinc/system.h> #include <kinc/system.h>
#include <kinc/video.h> #include <kinc/video.h>
#include <kinc/window.h> #include <kinc/window.h>
#include <hl.h> #include <hl.h>
void hl_kinc_log(vbyte *v) { void hl_kinc_log(vbyte *v) {
kinc_log(KINC_LOG_LEVEL_INFO, (char *)v); kinc_log(KINC_LOG_LEVEL_INFO, (char *)v);
} }
double hl_kinc_get_time(void) { double hl_kinc_get_time(void) {
return kinc_time(); return kinc_time();
} }
int hl_kinc_get_window_width(int window) { int hl_kinc_get_window_width(int window) {
return kinc_window_width(window); return kinc_window_width(window);
} }
int hl_kinc_get_window_height(int window) { int hl_kinc_get_window_height(int window) {
return kinc_window_height(window); return kinc_window_height(window);
} }
vbyte *hl_kinc_get_system_id(void) { vbyte *hl_kinc_get_system_id(void) {
return (vbyte *)kinc_system_id(); return (vbyte *)kinc_system_id();
} }
void hl_kinc_vibrate(int ms) { void hl_kinc_vibrate(int ms) {
kinc_vibrate(ms); kinc_vibrate(ms);
} }
vbyte *hl_kinc_get_language(void) { vbyte *hl_kinc_get_language(void) {
return (vbyte *)kinc_language(); return (vbyte *)kinc_language();
} }
void hl_kinc_request_shutdown(void) { void hl_kinc_request_shutdown(void) {
kinc_stop(); kinc_stop();
} }
void hl_kinc_mouse_lock(int windowId) { void hl_kinc_mouse_lock(int windowId) {
kinc_mouse_lock(windowId); kinc_mouse_lock(windowId);
} }
void hl_kinc_mouse_unlock(void) { void hl_kinc_mouse_unlock(void) {
kinc_mouse_unlock(); kinc_mouse_unlock();
} }
bool hl_kinc_can_lock_mouse(void) { bool hl_kinc_can_lock_mouse(void) {
return kinc_mouse_can_lock(); return kinc_mouse_can_lock();
} }
bool hl_kinc_is_mouse_locked(void) { bool hl_kinc_is_mouse_locked(void) {
return kinc_mouse_is_locked(); return kinc_mouse_is_locked();
} }
void hl_kinc_show_mouse(bool show) { void hl_kinc_show_mouse(bool show) {
if (show) { if (show) {
kinc_mouse_show(); kinc_mouse_show();
} }
else { else {
kinc_mouse_hide(); kinc_mouse_hide();
} }
} }
bool hl_kinc_system_is_fullscreen(void) { bool hl_kinc_system_is_fullscreen(void) {
return false; // kinc_is_fullscreen(); return false; // kinc_is_fullscreen();
} }
void hl_kinc_system_request_fullscreen(void) { void hl_kinc_system_request_fullscreen(void) {
// kinc_change_resolution(display_width(), display_height(), true); // kinc_change_resolution(display_width(), display_height(), true);
} }
void hl_kinc_system_exit_fullscreen(int previousWidth, int previousHeight) { void hl_kinc_system_exit_fullscreen(int previousWidth, int previousHeight) {
// kinc_change_resolution(previousWidth, previousHeight, false); // kinc_change_resolution(previousWidth, previousHeight, false);
} }
void hl_kinc_system_change_resolution(int width, int height) { void hl_kinc_system_change_resolution(int width, int height) {
// kinc_change_resolution(width, height, false); // kinc_change_resolution(width, height, false);
} }
void hl_kinc_system_set_keepscreenon(bool on) { void hl_kinc_system_set_keepscreenon(bool on) {
kinc_set_keep_screen_on(on); kinc_set_keep_screen_on(on);
} }
void hl_kinc_system_load_url(vbyte *url) { void hl_kinc_system_load_url(vbyte *url) {
kinc_load_url((char *)url); kinc_load_url((char *)url);
} }
vbyte *hl_kinc_get_gamepad_id(int index) { vbyte *hl_kinc_get_gamepad_id(int index) {
return (vbyte *)kinc_gamepad_product_name(index); return (vbyte*)kinc_gamepad_product_name(index);
} }
vbyte *hl_kinc_get_gamepad_vendor(int index) { vbyte *hl_kinc_get_gamepad_vendor(int index) {
return (vbyte *)kinc_gamepad_vendor(index); return (vbyte*)kinc_gamepad_vendor(index);
} }
bool hl_kinc_gamepad_connected(int index) { bool hl_kinc_gamepad_connected(int index) {
return kinc_gamepad_connected(index); return kinc_gamepad_connected(index);
} }
typedef void (*FN_KEY_DOWN)(int, void *); typedef void (*FN_KEY_DOWN)(int, void *);
typedef void (*FN_KEY_UP)(int, void *); typedef void (*FN_KEY_UP)(int, void *);
typedef void (*FN_KEY_PRESS)(unsigned int, void *); typedef void (*FN_KEY_PRESS)(unsigned int, void *);
void hl_kinc_register_keyboard(vclosure *keyDown, vclosure *keyUp, vclosure *keyPress) { void hl_kinc_register_keyboard(vclosure *keyDown, vclosure *keyUp, vclosure *keyPress) {
kinc_keyboard_set_key_down_callback(*((FN_KEY_DOWN *)(&keyDown->fun)), NULL); kinc_keyboard_set_key_down_callback(*((FN_KEY_DOWN *)(&keyDown->fun)), NULL);
kinc_keyboard_set_key_up_callback(*((FN_KEY_UP *)(&keyUp->fun)), NULL); kinc_keyboard_set_key_up_callback(*((FN_KEY_UP *)(&keyUp->fun)), NULL);
kinc_keyboard_set_key_press_callback(*((FN_KEY_PRESS *)(&keyPress->fun)), NULL); kinc_keyboard_set_key_press_callback(*((FN_KEY_PRESS *)(&keyPress->fun)), NULL);
} }
typedef void (*FN_MOUSE_DOWN)(int, int, int, int, void *); typedef void (*FN_MOUSE_DOWN)(int, int, int, int, void *);
typedef void (*FN_MOUSE_UP)(int, int, int, int, void *); typedef void (*FN_MOUSE_UP)(int, int, int, int, void *);
typedef void (*FN_MOUSE_MOVE)(int, int, int, int, int, void *); typedef void (*FN_MOUSE_MOVE)(int, int, int, int, int, void *);
typedef void (*FN_MOUSE_WHEEL)(int, int, void *); typedef void (*FN_MOUSE_WHEEL)(int, int, void *);
void hl_kinc_register_mouse(vclosure *mouseDown, vclosure *mouseUp, vclosure *mouseMove, vclosure *mouseWheel) { void hl_kinc_register_mouse(vclosure *mouseDown, vclosure *mouseUp, vclosure *mouseMove, vclosure *mouseWheel) {
kinc_mouse_set_press_callback(*((FN_MOUSE_DOWN *)(&mouseDown->fun)), NULL); kinc_mouse_set_press_callback(*((FN_MOUSE_DOWN *)(&mouseDown->fun)), NULL);
kinc_mouse_set_release_callback(*((FN_MOUSE_UP *)(&mouseUp->fun)), NULL); kinc_mouse_set_release_callback(*((FN_MOUSE_UP *)(&mouseUp->fun)), NULL);
kinc_mouse_set_move_callback(*((FN_MOUSE_MOVE *)(&mouseMove->fun)), NULL); kinc_mouse_set_move_callback(*((FN_MOUSE_MOVE *)(&mouseMove->fun)), NULL);
kinc_mouse_set_scroll_callback(*((FN_MOUSE_WHEEL *)(&mouseWheel->fun)), NULL); kinc_mouse_set_scroll_callback(*((FN_MOUSE_WHEEL *)(&mouseWheel->fun)), NULL);
} }
typedef void (*FN_PEN_DOWN)(int, int, int, float); typedef void (*FN_PEN_DOWN)(int, int, int, float);
typedef void (*FN_PEN_UP)(int, int, int, float); typedef void (*FN_PEN_UP)(int, int, int, float);
typedef void (*FN_PEN_MOVE)(int, int, int, float); typedef void (*FN_PEN_MOVE)(int, int, int, float);
void hl_kinc_register_pen(vclosure *penDown, vclosure *penUp, vclosure *penMove) { void hl_kinc_register_pen(vclosure *penDown, vclosure *penUp, vclosure *penMove) {
kinc_pen_set_press_callback(*((FN_PEN_DOWN *)(&penDown->fun))); kinc_pen_set_press_callback(*((FN_PEN_DOWN *)(&penDown->fun)));
kinc_pen_set_release_callback(*((FN_PEN_UP *)(&penUp->fun))); kinc_pen_set_release_callback(*((FN_PEN_UP *)(&penUp->fun)));
kinc_pen_set_move_callback(*((FN_PEN_MOVE *)(&penMove->fun))); kinc_pen_set_move_callback(*((FN_PEN_MOVE *)(&penMove->fun)));
} }
typedef void (*FN_GAMEPAD_AXIS)(int, int, float, void *); typedef void (*FN_GAMEPAD_AXIS)(int, int, float);
typedef void (*FN_GAMEPAD_BUTTON)(int, int, float, void *); typedef void (*FN_GAMEPAD_BUTTON)(int, int, float);
void hl_kinc_register_gamepad(vclosure *gamepadAxis, vclosure *gamepadButton) { void hl_kinc_register_gamepad(vclosure *gamepadAxis, vclosure *gamepadButton) {
kinc_gamepad_set_axis_callback(*((FN_GAMEPAD_AXIS *)(&gamepadAxis->fun)), NULL); kinc_gamepad_set_axis_callback(*((FN_GAMEPAD_AXIS *)(&gamepadAxis->fun)));
kinc_gamepad_set_button_callback(*((FN_GAMEPAD_BUTTON *)(&gamepadButton->fun)), NULL); kinc_gamepad_set_button_callback(*((FN_GAMEPAD_BUTTON *)(&gamepadButton->fun)));
} }
typedef void (*FN_TOUCH_START)(int, int, int); typedef void (*FN_TOUCH_START)(int, int, int);
typedef void (*FN_TOUCH_END)(int, int, int); typedef void (*FN_TOUCH_END)(int, int, int);
typedef void (*FN_TOUCH_MOVE)(int, int, int); typedef void (*FN_TOUCH_MOVE)(int, int, int);
void hl_kinc_register_surface(vclosure *touchStart, vclosure *touchEnd, vclosure *touchMove) { void hl_kinc_register_surface(vclosure *touchStart, vclosure *touchEnd, vclosure *touchMove) {
kinc_surface_set_touch_start_callback(*((FN_TOUCH_START *)(&touchStart->fun))); kinc_surface_set_touch_start_callback(*((FN_TOUCH_START *)(&touchStart->fun)));
kinc_surface_set_touch_end_callback(*((FN_TOUCH_END *)(&touchEnd->fun))); kinc_surface_set_touch_end_callback(*((FN_TOUCH_END *)(&touchEnd->fun)));
kinc_surface_set_move_callback(*((FN_TOUCH_MOVE *)(&touchMove->fun))); kinc_surface_set_move_callback(*((FN_TOUCH_MOVE *)(&touchMove->fun)));
} }
typedef void (*FN_SENSOR_ACCELEROMETER)(float, float, float); typedef void (*FN_SENSOR_ACCELEROMETER)(float, float, float);
typedef void (*FN_SENSOR_GYROSCOPE)(float, float, float); typedef void (*FN_SENSOR_GYROSCOPE)(float, float, float);
void hl_kinc_register_sensor(vclosure *accelerometerChanged, vclosure *gyroscopeChanged) { void hl_kinc_register_sensor(vclosure *accelerometerChanged, vclosure *gyroscopeChanged) {
kinc_acceleration_set_callback(*((FN_SENSOR_ACCELEROMETER *)(&accelerometerChanged->fun))); kinc_acceleration_set_callback(*((FN_SENSOR_ACCELEROMETER *)(&accelerometerChanged->fun)));
kinc_rotation_set_callback(*((FN_SENSOR_GYROSCOPE *)(&gyroscopeChanged->fun))); kinc_rotation_set_callback(*((FN_SENSOR_GYROSCOPE *)(&gyroscopeChanged->fun)));
} }
// typedef void(*FN_CB_ORIENTATION)(int); // typedef void(*FN_CB_ORIENTATION)(int);
typedef void (*FN_CB_FOREGROUND)(void *); typedef void (*FN_CB_FOREGROUND)(void *);
typedef void (*FN_CB_RESUME)(void *); typedef void (*FN_CB_RESUME)(void *);
typedef void (*FN_CB_PAUSE)(void *); typedef void (*FN_CB_PAUSE)(void *);
typedef void (*FN_CB_BACKGROUND)(void *); typedef void (*FN_CB_BACKGROUND)(void *);
typedef void (*FN_CB_SHUTDOWN)(void *); typedef void (*FN_CB_SHUTDOWN)(void *);
void hl_kinc_register_callbacks(vclosure *foreground, vclosure *resume, vclosure *pause, vclosure *background, vclosure *shutdown) { void hl_kinc_register_callbacks(vclosure *foreground, vclosure *resume, vclosure *pause, vclosure *background, vclosure *shutdown) {
// kinc_set_orientation_callback(orientation); // kinc_set_orientation_callback(orientation);
kinc_set_foreground_callback(*((FN_CB_FOREGROUND *)(&foreground->fun)), NULL); kinc_set_foreground_callback(*((FN_CB_FOREGROUND *)(&foreground->fun)), NULL);
kinc_set_resume_callback(*((FN_CB_RESUME *)(&resume->fun)), NULL); kinc_set_resume_callback(*((FN_CB_RESUME *)(&resume->fun)), NULL);
kinc_set_pause_callback(*((FN_CB_PAUSE *)(&pause->fun)), NULL); kinc_set_pause_callback(*((FN_CB_PAUSE *)(&pause->fun)), NULL);
kinc_set_background_callback(*((FN_CB_BACKGROUND *)(&background->fun)), NULL); kinc_set_background_callback(*((FN_CB_BACKGROUND *)(&background->fun)), NULL);
kinc_set_shutdown_callback(*((FN_CB_SHUTDOWN *)(&shutdown->fun)), NULL); kinc_set_shutdown_callback(*((FN_CB_SHUTDOWN *)(&shutdown->fun)), NULL);
} }
typedef void (*FN_CB_DROPFILES)(wchar_t *); typedef void (*FN_CB_DROPFILES)(wchar_t *);
void hl_kinc_register_dropfiles(vclosure *dropFiles) { void hl_kinc_register_dropfiles(vclosure *dropFiles) {
// todo: string convert // todo: string convert
// kinc_set_drop_files_callback(*((FN_CB_DROPFILES*)(&dropFiles->fun))); // kinc_set_drop_files_callback(*((FN_CB_DROPFILES*)(&dropFiles->fun)));
} }
typedef char *(*FN_CB_COPY)(void *); typedef char *(*FN_CB_COPY)(void *);
typedef char *(*FN_CB_CUT)(void *); typedef char *(*FN_CB_CUT)(void *);
typedef void (*FN_CB_PASTE)(char *, void *); typedef void (*FN_CB_PASTE)(char *, void *);
void hl_kinc_register_copycutpaste(vclosure *copy, vclosure *cut, vclosure *paste) { void hl_kinc_register_copycutpaste(vclosure *copy, vclosure *cut, vclosure *paste) {
kinc_set_copy_callback(*((FN_CB_COPY *)(&copy->fun)), NULL); kinc_set_copy_callback(*((FN_CB_COPY *)(&copy->fun)), NULL);
kinc_set_cut_callback(*((FN_CB_CUT *)(&cut->fun)), NULL); kinc_set_cut_callback(*((FN_CB_CUT *)(&cut->fun)), NULL);
kinc_set_paste_callback(*((FN_CB_PASTE *)(&paste->fun)), NULL); kinc_set_paste_callback(*((FN_CB_PASTE *)(&paste->fun)), NULL);
} }
const char *hl_kinc_video_format(void) { const char *hl_kinc_video_format(void) {
return kinc_video_formats()[0]; return kinc_video_formats()[0];
} }

View File

@ -140,4 +140,4 @@ void kinc_internal_gamepad_trigger_button(int gamepad, int button, float value)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -26,9 +26,10 @@ class GetBoneTransformNode extends LogicNode {
// Get bone in armature // Get bone in armature
var bone = anim.getBone(boneName); var bone = anim.getBone(boneName);
return anim.getAbsWorldMat(anim.skeletonMats, bone); //return anim.getAbsWorldMat(bone);
//return anim.getAbsMat(bone).clone().multmat(object.transform.world); return anim.getAbsMat(bone).clone().multmat(object.transform.world);
//return anim.getAbsWorldMat(bone);
#else #else
return null; return null;

View File

@ -1213,7 +1213,7 @@ class Inc {
kha.compute.Compute.setSampledTexture(voxel_td4, rts.get("voxelsSDF").image); kha.compute.Compute.setSampledTexture(voxel_td4, rts.get("voxelsSDF").image);
kha.compute.Compute.setTexture(voxel_te4, rts.get("voxels_specular").image, kha.compute.Access.Write); kha.compute.Compute.setTexture(voxel_te4, rts.get("voxels_specular").image, kha.compute.Access.Write);
//kha.compute.Compute.setSampledTexture(voxel_tf4, rts.get("gbuffer2").image); kha.compute.Compute.setSampledTexture(voxel_tf4, rts.get("gbuffer2").image);
var fa:Float32Array = new Float32Array(Main.voxelgiClipmapCount * 10); var fa:Float32Array = new Float32Array(Main.voxelgiClipmapCount * 10);
for (i in 0...Main.voxelgiClipmapCount) { for (i in 0...Main.voxelgiClipmapCount) {

View File

@ -7,46 +7,48 @@ if lnx.is_reload(__name__):
else: else:
lnx.enable_reload(__name__) lnx.enable_reload(__name__)
#lnx.keymaps = [] lnx.keymaps = []
def register(): def register():
wm = bpy.context.window_manager wm = bpy.context.window_manager
keyconfig = wm.keyconfigs.user addon_keyconfig = wm.keyconfigs.addon
# Keyconfigs are not available in background mode. If the keyconfig # Keyconfigs are not available in background mode. If the keyconfig
# was not found despite running _not_ in background mode, a warning # was not found despite running _not_ in background mode, a warning
# is printed # is printed
if keyconfig is None: if addon_keyconfig is None:
if not bpy.app.background: if not bpy.app.background:
log.warn("No keyconfig path found") log.warn("No keyconfig path found")
return return
km = keyconfig.keymaps.get('Window')
if km is None: km = addon_keyconfig.keymaps.new(name='Window', space_type='EMPTY', region_type="WINDOW")
log.warn("Window keymaps not available") km.keymap_items.new(props_ui.LeenkxPlayButton.bl_idname, type='F5', value='PRESS')
return km.keymap_items.new("tlm.build_lightmaps", type='F6', value='PRESS')
lnx_start = any(kmi.idname == props_ui.LeenkxPlayButton.bl_idname for kmi in km.keymap_items) km.keymap_items.new("tlm.clean_lightmaps", type='F7', value='PRESS')
if not lnx_start: lnx.keymaps.append(km)
kmw = keyconfig.keymaps.new(name='Window', space_type='EMPTY', region_type="WINDOW")
kmw.keymap_items.new(props_ui.LeenkxPlayButton.bl_idname, type='F5', value='PRESS') km = addon_keyconfig.keymaps.new(name='Node Editor', space_type='NODE_EDITOR')
kmw.keymap_items.new('tlm.build_lightmaps', type='F6', value='PRESS')
kmw.keymap_items.new('tlm.clean_lightmaps', type='F7', value='PRESS') # shift+G: Create a new node call group node
kmn = keyconfig.keymaps.new(name='Node Editor', space_type='NODE_EDITOR') km.keymap_items.new('lnx.add_call_group_node', 'G', 'PRESS', shift=True)
kmn.keymap_items.new('lnx.add_call_group_node', 'G', 'PRESS', shift=True)
kmn.keymap_items.new('lnx.add_group_tree_from_selected', 'G', 'PRESS', ctrl=True) # ctrl+G: make node group from selected
kmn.keymap_items.new('lnx.edit_group_tree', 'TAB', 'PRESS') km.keymap_items.new('lnx.add_group_tree_from_selected', 'G', 'PRESS', ctrl=True)
kmn.keymap_items.new('node.tree_path_parent', 'TAB', 'PRESS', ctrl=True)
kmn.keymap_items.new('lnx.ungroup_group_tree', 'G', 'PRESS', alt=True) # TAB: enter node groups depending on selection
km.keymap_items.new('lnx.edit_group_tree', 'TAB', 'PRESS')
# ctrl+TAB: exit node groups depending on selectio
km.keymap_items.new('node.tree_path_parent', 'TAB', 'PRESS', ctrl=True)
# alt+G: ungroup node tree
km.keymap_items.new('lnx.ungroup_group_tree', 'G', 'PRESS', alt=True)
lnx.keymaps.append(km)
def unregister(): def unregister():
kmw = bpy.context.window_manager.keyconfigs.user.keymaps.get('Window') wm = bpy.context.window_manager
kmw.keymap_items.remove(kmw.keymap_items[props_ui.LeenkxPlayButton.bl_idname]) for km in lnx.keymaps:
kmw.keymap_items.remove(kmw.keymap_items['tlm.build_lightmaps']) wm.keyconfigs.addon.keymaps.remove(km)
kmw.keymap_items.remove(kmw.keymap_items['tlm.clean_lightmaps']) del lnx.keymaps[:]
kmn = bpy.context.window_manager.keyconfigs.user.keymaps.get('Node Editor')
kmn.keymap_items.remove(kmn.keymap_items['lnx.add_call_group_node'])
kmn.keymap_items.remove(kmn.keymap_items['lnx.add_group_tree_from_selected'])
kmn.keymap_items.remove(kmn.keymap_items['lnx.edit_group_tree'])
kmn.keymap_items.remove(kmn.keymap_items['node.tree_path_parent'])
kmn.keymap_items.remove(kmn.keymap_items['lnx.ungroup_group_tree'])

View File

@ -139,10 +139,7 @@ if bpy.app.version > (4, 1, 0):
subsurface_radius = c.parse_vector_input(node.inputs[9]) subsurface_radius = c.parse_vector_input(node.inputs[9])
subsurface_color = c.parse_vector_input(node.inputs[8]) subsurface_color = c.parse_vector_input(node.inputs[8])
state.out_metallic = c.parse_value_input(node.inputs[1]) state.out_metallic = c.parse_value_input(node.inputs[1])
if bpy.app.version > (4, 2, 4): state.out_specular = c.parse_value_input(node.inputs[12])
state.out_specular = c.parse_value_input(node.inputs[13])
else:
state.out_specular = c.parse_value_input(node.inputs[12])
state.out_roughness = c.parse_value_input(node.inputs[2]) state.out_roughness = c.parse_value_input(node.inputs[2])
# Prevent black material when metal = 1.0 and roughness = 0.0 # Prevent black material when metal = 1.0 and roughness = 0.0
try: try:

View File

@ -686,9 +686,9 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False):
if parse_opacity: if parse_opacity:
frag.write('indirect = traceDiffuse(wposition, n, voxels, clipmaps).rgb * albedo * voxelgiDiff;') frag.write('indirect = traceDiffuse(wposition, n, voxels, clipmaps).rgb * albedo * voxelgiDiff;')
frag.write('if (roughness < 1.0 && specular > 0.0){') frag.write('if (roughness < 1.0 && specular > 0.0){')
frag.add_uniform('sampler2D sveloc') #frag.add_uniform('sampler2D sveloc')
frag.write(' vec2 velocity = -textureLod(sveloc, gl_FragCoord.xy, 0.0).rg;') #frag.write(' vec2 velocity = -textureLod(sveloc, gl_FragCoord.xy, 0.0).rg;')
frag.write(' indirect += traceSpecular(wposition, n, voxels, voxelsSDF, normalize(eye - wposition), roughness, clipmaps, gl_FragCoord.xy, velocity).rgb * specular * voxelgiRefl;}') frag.write(' indirect += traceSpecular(wposition, n, voxels, voxelsSDF, normalize(eye - wposition), roughness, clipmaps, gl_FragCoord.xy).rgb * specular * voxelgiRefl;}')
else: else:
frag.add_uniform("sampler2D voxels_diffuse") frag.add_uniform("sampler2D voxels_diffuse")
frag.add_uniform("sampler2D voxels_specular") frag.add_uniform("sampler2D voxels_specular")
@ -779,10 +779,9 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False):
if '_MicroShadowing' in wrd.world_defs: if '_MicroShadowing' in wrd.world_defs:
frag.write(', occlusion') frag.write(', occlusion')
if '_SSRS' in wrd.world_defs: if '_SSRS' in wrd.world_defs:
frag.add_uniform('sampler2D gbufferD', top=True)
frag.add_uniform('mat4 invVP', '_inverseViewProjectionMatrix') frag.add_uniform('mat4 invVP', '_inverseViewProjectionMatrix')
frag.add_uniform('vec3 eye', '_cameraPosition') frag.add_uniform('vec3 eye', '_cameraPosition')
frag.write(', gbufferD, invVP, eye') frag.write(', gl_FragCoord.z, inVP, eye')
frag.write(');') frag.write(');')
if '_Clusters' in wrd.world_defs: if '_Clusters' in wrd.world_defs:
@ -795,8 +794,8 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False):
if '_VoxelRefract' in wrd.world_defs and parse_opacity: if '_VoxelRefract' in wrd.world_defs and parse_opacity:
frag.write('if (opacity < 1.0) {') frag.write('if (opacity < 1.0) {')
frag.write(' vec2 velocity = -textureLod(sveloc, gl_FragCoord.xy, 0.0).rg;') #frag.write(' vec2 velocity = -textureLod(sveloc, gl_FragCoord.xy, 0.0).rg;')
frag.write(' vec3 refraction = traceRefraction(wposition, n, voxels, voxelsSDF, normalize(eye - wposition), ior, roughness, clipmaps, gl_FragCoord.xy,velocity).rgb;') frag.write(' vec3 refraction = traceRefraction(wposition, n, voxels, voxelsSDF, normalize(eye - wposition), ior, roughness, clipmaps, gl_FragCoord.xy).rgb;')
frag.write(' indirect = mix(refraction, indirect, opacity) * voxelgiRefr;') frag.write(' indirect = mix(refraction, indirect, opacity) * voxelgiRefr;')
frag.write(' direct = mix(refraction, direct, opacity) * voxelgiRefr;') frag.write(' direct = mix(refraction, direct, opacity) * voxelgiRefr;')
frag.write('}') frag.write('}')

View File

@ -264,7 +264,7 @@ class LnxOpenNodeHaxeSource(bpy.types.Operator):
version = lnx.utils.get_last_commit() version = lnx.utils.get_last_commit()
if version == '': if version == '':
version = 'main' version = 'main'
webbrowser.open(f'https://dev.leenkx.com/LeenkxTeam/LNXSDK/src/branch/{version}/leenkx/Sources/leenkx/logicnode/{name}.hx') webbrowser.open(f'https://github.com/leenkx3d/leenkx/blob/{version}/leenkx/Sources/leenkx/logicnode/{name}.hx')
return{'FINISHED'} return{'FINISHED'}
@ -282,7 +282,7 @@ class LnxOpenNodePythonSource(bpy.types.Operator):
if version == '': if version == '':
version = 'main' version = 'main'
rel_path = node.__module__.replace('.', '/') rel_path = node.__module__.replace('.', '/')
webbrowser.open(f'https://dev.leenkx.com/LeenkxTeam/LNXSDK/src/branch/{version}/leenkx/blender/{rel_path}.py') webbrowser.open(f'https://github.com/leenkx3d/leenkx/blob/{version}/leenkx/blender/{rel_path}.py')
return{'FINISHED'} return{'FINISHED'}

View File

@ -216,7 +216,7 @@ def is_gapi_gl_es() -> bool:
def get_rp() -> lnx.props_renderpath.LnxRPListItem: def get_rp() -> lnx.props_renderpath.LnxRPListItem:
wrd = bpy.data.worlds['Lnx'] wrd = bpy.data.worlds['Lnx']
if not state.is_export and wrd.lnx_play_renderpath != '' and lnx.props_renderpath.LnxRPListItem.get_by_name(wrd.lnx_play_renderpath) is not None: if not state.is_export and wrd.lnx_play_renderpath != '':
return lnx.props_renderpath.LnxRPListItem.get_by_name(wrd.lnx_play_renderpath) return lnx.props_renderpath.LnxRPListItem.get_by_name(wrd.lnx_play_renderpath)
else: else:
return wrd.lnx_rplist[wrd.lnx_rplist_index] return wrd.lnx_rplist[wrd.lnx_rplist_index]

View File

@ -1,3 +1,3 @@
// Keep this file so that the headers are included in the compilation // Keep this file so that the headers are included in the compilation
#include "hl/aura/math/FFT.h" #include "hl/aura/math/fft.h"
#include "hl/aura/types/complex_array.h" #include "hl/aura/types/complex_array.h"

View File

@ -2,27 +2,27 @@
#include <hl.h> #include <hl.h>
//#include <aura/types/_ComplexArray/HL_ComplexArrayImpl.h> #include <aura/types/_ComplexArray/HL_ComplexArrayImpl.h>
#include "hl/aura/aurahl.h" #include "hl/aura/aurahl.h"
#include "common_c/math/fft.h" #include "common_c/math/fft.h"
#include "common_c/types/complex_t.h" #include "common_c/types/complex_t.h"
//HL_PRIM void AURA_HL_FUNC(ditfft2)(aura__types___ComplexArray__HL_ComplexArrayImpl time_array, int t, aura__types___ComplexArray__HL_ComplexArrayImpl freq_array, int f, int n, int step, bool inverse) { HL_PRIM void AURA_HL_FUNC(ditfft2)(aura__types___ComplexArray__HL_ComplexArrayImpl time_array, int t, aura__types___ComplexArray__HL_ComplexArrayImpl freq_array, int f, int n, int step, bool inverse) {
// const aura_complex_t *times = (aura_complex_t*) time_array->self; const aura_complex_t *times = (aura_complex_t*) time_array->self;
// aura_complex_t *freqs = (aura_complex_t*) freq_array->self; aura_complex_t *freqs = (aura_complex_t*) freq_array->self;
/// aura_ditfft2(times, t, freqs, f, n, step, inverse); aura_ditfft2(times, t, freqs, f, n, step, inverse);
//} }
//HL_PRIM void AURA_HL_FUNC(ditfft2_iterative)(aura__types___ComplexArray__HL_ComplexArrayImpl time_array, aura__types___ComplexArray__HL_ComplexArrayImpl freq_array, int n, bool inverse, aura__types___ComplexArray__HL_ComplexArrayImpl exp_rotation_step_table) { HL_PRIM void AURA_HL_FUNC(ditfft2_iterative)(aura__types___ComplexArray__HL_ComplexArrayImpl time_array, aura__types___ComplexArray__HL_ComplexArrayImpl freq_array, int n, bool inverse, aura__types___ComplexArray__HL_ComplexArrayImpl exp_rotation_step_table) {
// const aura_complex_t *times = (aura_complex_t*) time_array->self; const aura_complex_t *times = (aura_complex_t*) time_array->self;
// aura_complex_t *freqs = (aura_complex_t*) freq_array->self; aura_complex_t *freqs = (aura_complex_t*) freq_array->self;
// const aura_complex_t *exp_lut = (aura_complex_t*) exp_rotation_step_table->self; const aura_complex_t *exp_lut = (aura_complex_t*) exp_rotation_step_table->self;
// aura_ditfft2_iterative(times, freqs, n, inverse, exp_lut); aura_ditfft2_iterative(times, freqs, n, inverse, exp_lut);
//} }
//DEFINE_PRIM(_VOID, ditfft2, _BYTES _I32 _BYTES _I32 _I32 _I32 _BOOL) DEFINE_PRIM(_VOID, ditfft2, _BYTES _I32 _BYTES _I32 _I32 _I32 _BOOL)
//DEFINE_PRIM(_VOID, ditfft2_iterative, _BYTES _BYTES _I32 _BOOL _BYTES) DEFINE_PRIM(_VOID, ditfft2_iterative, _BYTES _BYTES _I32 _BOOL _BYTES)