Update Files
This commit is contained in:
221
Kha/Backends/Kinc-HL/kinc-bridge/arrays.c.h
Normal file
221
Kha/Backends/Kinc-HL/kinc-bridge/arrays.c.h
Normal file
@ -0,0 +1,221 @@
|
||||
#include <hl.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
vbyte *hl_kinc_bytebuffer_alloc(int elements) {
|
||||
char *data = (char *)malloc(elements * sizeof(char));
|
||||
return (vbyte *)data;
|
||||
}
|
||||
|
||||
void hl_kinc_bytebuffer_free(vbyte *bytearray) {
|
||||
free(bytearray);
|
||||
}
|
||||
|
||||
// Get
|
||||
|
||||
int hl_kinc_bytearray_getint8(vbyte *bytearray, int byteoffset) {
|
||||
return (int)*((int8_t *)&(bytearray[byteoffset]));
|
||||
}
|
||||
|
||||
int hl_kinc_bytearray_getuint8(vbyte *bytearray, int byteoffset) {
|
||||
return (int)*((uint8_t *)&(bytearray[byteoffset]));
|
||||
}
|
||||
|
||||
int hl_kinc_bytearray_getint16(vbyte *bytearray, int byteoffset) {
|
||||
return (int)*((int16_t *)&bytearray[byteoffset]);
|
||||
}
|
||||
|
||||
int hl_kinc_bytearray_getuint16(vbyte *bytearray, int byteoffset) {
|
||||
return (int)*((uint16_t *)&bytearray[byteoffset]);
|
||||
}
|
||||
|
||||
int hl_kinc_bytearray_getint32(vbyte *bytearray, int byteoffset) {
|
||||
return (int)*((int32_t *)&bytearray[byteoffset]);
|
||||
}
|
||||
|
||||
int64_t hl_kinc_bytearray_getuint32(vbyte *bytearray, int byteoffset) {
|
||||
return (int64_t)*((uint32_t *)&bytearray[byteoffset]);
|
||||
}
|
||||
|
||||
float hl_kinc_bytearray_getfloat32(vbyte *bytearray, int byteoffset) {
|
||||
return *((float *)&bytearray[byteoffset]);
|
||||
}
|
||||
|
||||
double hl_kinc_bytearray_getfloat64(vbyte *bytearray, int byteoffset) {
|
||||
return *((double *)&bytearray[byteoffset]);
|
||||
}
|
||||
|
||||
// Set
|
||||
|
||||
void hl_kinc_bytearray_setint8(vbyte *bytearray, int byteoffset, int value) {
|
||||
*((int8_t *)&bytearray[byteoffset]) = (int8_t)value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setuint8(vbyte *bytearray, int byteoffset, int value) {
|
||||
*((uint8_t *)&bytearray[byteoffset]) = (uint8_t)value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setint16(vbyte *bytearray, int byteoffset, int value) {
|
||||
*((int16_t *)&bytearray[byteoffset]) = (int16_t)value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setuint16(vbyte *bytearray, int byteoffset, int value) {
|
||||
*((uint16_t *)&bytearray[byteoffset]) = (uint16_t)value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setint32(vbyte *bytearray, int byteoffset, int value) {
|
||||
*((int32_t *)&bytearray[byteoffset]) = (int32_t)value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setuint32(vbyte *bytearray, int byteoffset, int64_t value) {
|
||||
*((uint32_t *)&bytearray[byteoffset]) = (uint32_t)value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setfloat32(vbyte *bytearray, int byteoffset, float value) {
|
||||
*((float *)&bytearray[byteoffset]) = value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setfloat64(vbyte *bytearray, int byteoffset, double value) {
|
||||
*((double *)&bytearray[byteoffset]) = value;
|
||||
}
|
||||
|
||||
// Get (little endian on big endian system)
|
||||
|
||||
int hl_kinc_bytearray_getint16_le(vbyte *bytearray, int byteoffset) {
|
||||
return (int)(bytearray[byteoffset] << 0 | bytearray[byteoffset + 1] << 8);
|
||||
}
|
||||
|
||||
int hl_kinc_bytearray_getuint16_le(vbyte *bytearray, int byteoffset) {
|
||||
return (int)(bytearray[byteoffset] << 0 | bytearray[byteoffset + 1] << 8);
|
||||
}
|
||||
|
||||
int hl_kinc_bytearray_getint32_le(vbyte *bytearray, int byteoffset) {
|
||||
return (int)(bytearray[byteoffset] << 0 | bytearray[byteoffset + 1] << 8 | bytearray[byteoffset + 2] << 16 | bytearray[byteoffset + 3] << 24);
|
||||
}
|
||||
|
||||
int64_t hl_kinc_bytearray_getuint32_le(vbyte *bytearray, int byteoffset) {
|
||||
return (int64_t)(bytearray[byteoffset] << 0 | bytearray[byteoffset + 1] << 8 | bytearray[byteoffset + 2] << 16 | bytearray[byteoffset + 3] << 24);
|
||||
}
|
||||
|
||||
float hl_kinc_bytearray_getfloat32_le(vbyte *bytearray, int byteoffset) {
|
||||
int32_t v = (bytearray[byteoffset] << 0 | bytearray[byteoffset + 1] << 8 | bytearray[byteoffset + 2] << 16 | bytearray[byteoffset + 3] << 24);
|
||||
return *(float *)&v;
|
||||
}
|
||||
|
||||
double hl_kinc_bytearray_getfloat64_le(vbyte *bytearray, int byteoffset) {
|
||||
int64_t v = ((int64_t)bytearray[byteoffset] << 0 | (int64_t)bytearray[byteoffset + 1] << 8 | (int64_t)bytearray[byteoffset + 2] << 16 |
|
||||
(int64_t)bytearray[byteoffset + 3] << 24 | (int64_t)bytearray[byteoffset + 4] << 32 | (int64_t)bytearray[byteoffset + 5] << 40 |
|
||||
(int64_t)bytearray[byteoffset + 6] << 48 | (int64_t)bytearray[byteoffset + 7] << 56);
|
||||
return *(double *)&v;
|
||||
}
|
||||
|
||||
// Set (little endian on big endian system)
|
||||
|
||||
void hl_kinc_bytearray_setint16_le(vbyte *bytearray, int byteoffset, int value) {
|
||||
int16_t val = value;
|
||||
int8_t *data = (int8_t *)&(val);
|
||||
int16_t le_value = data[0] << 8 | data[1] << 0;
|
||||
*((int16_t *)&bytearray[byteoffset]) = le_value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setuint16_le(vbyte *bytearray, int byteoffset, int value) {
|
||||
uint16_t val = value;
|
||||
int8_t *data = (int8_t *)&(val);
|
||||
uint16_t le_value = data[0] << 8 | data[1] << 0;
|
||||
*((uint16_t *)&bytearray[byteoffset]) = le_value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setint32_le(vbyte *bytearray, int byteoffset, int value) {
|
||||
int8_t *data = (int8_t *)&(value);
|
||||
int32_t le_value = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3] << 0;
|
||||
*((int32_t *)&bytearray[byteoffset]) = le_value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setuint32_le(vbyte *bytearray, int byteoffset, int64_t value) {
|
||||
uint32_t val = (uint32_t)value;
|
||||
int8_t *data = (int8_t *)&(val);
|
||||
uint32_t le_value = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3] << 0;
|
||||
*((uint32_t *)&bytearray[byteoffset]) = le_value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setfloat32_le(vbyte *bytearray, int byteoffset, float value) {
|
||||
int8_t *data = (int8_t *)&value;
|
||||
int32_t le_value = (data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3] << 0);
|
||||
*((float *)&bytearray[byteoffset]) = *(float *)&le_value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setfloat64_le(vbyte *bytearray, int byteoffset, double value) {
|
||||
int8_t *data = (int8_t *)&value;
|
||||
int64_t le_value = (int64_t)data[0] << 56 | (int64_t)data[1] << 48 | (int64_t)data[2] << 40 | (int64_t)data[3] << 32 | (int64_t)data[4] << 24 |
|
||||
(int64_t)data[5] << 16 | (int64_t)data[6] << 8 | (int64_t)data[7] << 0;
|
||||
*((double *)&bytearray[byteoffset]) = *(double *)&le_value;
|
||||
}
|
||||
|
||||
// Get (big endian on little endian system)
|
||||
|
||||
int hl_kinc_bytearray_getint16_be(vbyte *bytearray, int byteoffset) {
|
||||
return (int)(bytearray[byteoffset + 1] << 0 | bytearray[byteoffset] << 8);
|
||||
}
|
||||
|
||||
int hl_kinc_bytearray_getuint16_be(vbyte *bytearray, int byteoffset) {
|
||||
return (int)(bytearray[byteoffset + 1] << 0 | bytearray[byteoffset] << 8);
|
||||
}
|
||||
|
||||
int hl_kinc_bytearray_getint32_be(vbyte *bytearray, int byteoffset) {
|
||||
return (int)(bytearray[byteoffset + 3] << 0 | bytearray[byteoffset + 2] << 8 | bytearray[byteoffset + 1] << 16 | bytearray[byteoffset] << 24);
|
||||
}
|
||||
|
||||
int64_t hl_kinc_bytearray_getuint32_be(vbyte *bytearray, int byteoffset) {
|
||||
return (int64_t)(bytearray[byteoffset + 3] << 0 | bytearray[byteoffset + 2] << 8 | bytearray[byteoffset + 1] << 16 | bytearray[byteoffset] << 24);
|
||||
}
|
||||
|
||||
float hl_kinc_bytearray_getfloat32_be(vbyte *bytearray, int byteoffset) {
|
||||
int32_t v = (bytearray[byteoffset + 3] << 0 | bytearray[byteoffset + 2] << 8 | bytearray[byteoffset + 1] << 16 | bytearray[byteoffset] << 24);
|
||||
return *(float *)&v;
|
||||
}
|
||||
|
||||
double hl_kinc_bytearray_getfloat64_be(vbyte *bytearray, int byteoffset) {
|
||||
int64_t v = ((int64_t)bytearray[byteoffset + 7] << 0 | (int64_t)bytearray[byteoffset + 6] << 8 | (int64_t)bytearray[byteoffset + 5] << 16 |
|
||||
(int64_t)bytearray[byteoffset + 4] << 24 | (int64_t)bytearray[byteoffset + 3] << 32 | (int64_t)bytearray[byteoffset + 2] << 40 |
|
||||
(int64_t)bytearray[byteoffset + 1] << 48 | (int64_t)bytearray[byteoffset] << 56);
|
||||
return *(double *)&v;
|
||||
}
|
||||
|
||||
// Set (big endian on little endian system)
|
||||
|
||||
void hl_kinc_bytearray_setint16_be(vbyte *bytearray, int byteoffset, int value) {
|
||||
int8_t *data = (int8_t *)&value;
|
||||
int16_t be_value = data[1] << 8 | data[0] << 0;
|
||||
*((int16_t *)&bytearray[byteoffset]) = be_value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setuint16_be(vbyte *bytearray, int byteoffset, int value) {
|
||||
int8_t *data = (int8_t *)&value;
|
||||
uint16_t be_value = data[1] << 8 | data[0] << 0;
|
||||
*((uint16_t *)&bytearray[byteoffset]) = be_value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setint32_be(vbyte *bytearray, int byteoffset, int value) {
|
||||
int8_t *data = (int8_t *)&value;
|
||||
int32_t be_value = data[3] << 24 | data[2] << 16 | data[1] << 8 | data[0] << 0;
|
||||
*((int32_t *)&bytearray[byteoffset]) = be_value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setuint32_be(vbyte *bytearray, int byteoffset, int64_t value) {
|
||||
int8_t *data = (int8_t *)&value;
|
||||
uint32_t be_value = data[3] << 24 | data[2] << 16 | data[1] << 8 | data[0] << 0;
|
||||
*((uint32_t *)&bytearray[byteoffset]) = be_value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setfloat32_be(vbyte *bytearray, int byteoffset, float value) {
|
||||
int8_t *data = (int8_t *)&value;
|
||||
int32_t be_value = (data[3] << 24 | data[2] << 16 | data[1] << 8 | data[0] << 0);
|
||||
*((float *)&bytearray[byteoffset]) = *(float *)&be_value;
|
||||
}
|
||||
|
||||
void hl_kinc_bytearray_setfloat64_be(vbyte *bytearray, int byteoffset, double value) {
|
||||
int8_t *data = (int8_t *)&value;
|
||||
int64_t be_value = (int64_t)data[7] << 56 | (int64_t)data[6] << 48 | (int64_t)data[5] << 40 | (int64_t)data[4] << 32 | (int64_t)data[3] << 24 |
|
||||
(int64_t)data[2] << 16 | (int64_t)data[1] << 8 | (int64_t)data[0] << 0;
|
||||
*((double *)&bytearray[byteoffset]) = *(double *)&be_value;
|
||||
}
|
13
Kha/Backends/Kinc-HL/kinc-bridge/bridge.c
Normal file
13
Kha/Backends/Kinc-HL/kinc-bridge/bridge.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include "arrays.c.h"
|
||||
#include "compute.c.h"
|
||||
#include "cubemap.c.h"
|
||||
#include "display.c.h"
|
||||
#include "graphics.c.h"
|
||||
#include "indexbuffer.c.h"
|
||||
#include "kinc.c.h"
|
||||
#include "shader.c.h"
|
||||
#include "sound.c.h"
|
||||
#include "system.c.h"
|
||||
#include "texture.c.h"
|
||||
#include "vertexbuffer.c.h"
|
||||
#include "video.c.h"
|
179
Kha/Backends/Kinc-HL/kinc-bridge/compute.c.h
Normal file
179
Kha/Backends/Kinc-HL/kinc-bridge/compute.c.h
Normal file
@ -0,0 +1,179 @@
|
||||
#include <kinc/compute/compute.h>
|
||||
#include <kinc/graphics4/texture.h>
|
||||
|
||||
#include <hl.h>
|
||||
|
||||
vbyte *hl_kinc_compute_create_shader(vbyte *data, int length) {
|
||||
kinc_compute_shader_t *shader = (kinc_compute_shader_t *)malloc(sizeof(kinc_compute_shader_t));
|
||||
kinc_compute_shader_init(shader, data, length);
|
||||
return (vbyte *)shader;
|
||||
}
|
||||
|
||||
void hl_kinc_compute_delete_shader(vbyte *shader) {
|
||||
kinc_compute_shader_t *sh = (kinc_compute_shader_t *)shader;
|
||||
kinc_compute_shader_destroy(sh);
|
||||
free(sh);
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_compute_get_constantlocation(vbyte *shader, vbyte *name) {
|
||||
kinc_compute_shader_t *sh = (kinc_compute_shader_t *)shader;
|
||||
kinc_compute_constant_location_t *location = (kinc_compute_constant_location_t *)malloc(sizeof(kinc_compute_constant_location_t));
|
||||
*location = kinc_compute_shader_get_constant_location(sh, (char *)name), sizeof(kinc_compute_constant_location_t);
|
||||
return (vbyte *)location;
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_compute_get_textureunit(vbyte *shader, vbyte *name) {
|
||||
kinc_compute_shader_t *sh = (kinc_compute_shader_t *)shader;
|
||||
kinc_compute_texture_unit_t *unit = (kinc_compute_texture_unit_t *)malloc(sizeof(kinc_compute_texture_unit_t));
|
||||
*unit = kinc_compute_shader_get_texture_unit(sh, (char *)name), sizeof(kinc_compute_texture_unit_t);
|
||||
return (vbyte *)unit;
|
||||
}
|
||||
|
||||
void hl_kinc_compute_set_bool(vbyte *location, bool value) {
|
||||
kinc_compute_constant_location_t *loc = (kinc_compute_constant_location_t *)location;
|
||||
kinc_compute_set_bool(*loc, value);
|
||||
}
|
||||
|
||||
void hl_kinc_compute_set_int(vbyte *location, int value) {
|
||||
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);
|
||||
}
|
30
Kha/Backends/Kinc-HL/kinc-bridge/cubemap.c.h
Normal file
30
Kha/Backends/Kinc-HL/kinc-bridge/cubemap.c.h
Normal file
@ -0,0 +1,30 @@
|
||||
#include <kinc/graphics4/rendertarget.h>
|
||||
#include <kinc/graphics4/texture.h>
|
||||
|
||||
#include <hl.h>
|
||||
|
||||
vbyte *hl_kinc_cubemap_create(int cubeMapSize, int depthBufferBits, int format, int stencilBufferBits) {
|
||||
kinc_g4_render_target_t *render_target = (kinc_g4_render_target_t *)malloc(sizeof(kinc_g4_render_target_t));
|
||||
kinc_g4_render_target_init_cube(render_target, cubeMapSize, (kinc_g4_render_target_format_t)format, depthBufferBits, stencilBufferBits);
|
||||
return (vbyte *)render_target;
|
||||
}
|
||||
|
||||
int hl_kinc_cubemap_texture_get_width(vbyte *cubemap) {
|
||||
kinc_g4_render_target_t *cm = (kinc_g4_render_target_t *)cubemap;
|
||||
return cm->texWidth;
|
||||
}
|
||||
|
||||
int hl_kinc_cubemap_texture_get_height(vbyte *cubemap) {
|
||||
kinc_g4_render_target_t *cm = (kinc_g4_render_target_t *)cubemap;
|
||||
return cm->texHeight;
|
||||
}
|
||||
|
||||
int hl_kinc_cubemap_target_get_width(vbyte *cubemap) {
|
||||
kinc_g4_render_target_t *cm = (kinc_g4_render_target_t *)cubemap;
|
||||
return cm->width;
|
||||
}
|
||||
|
||||
int hl_kinc_cubemap_target_get_height(vbyte *cubemap) {
|
||||
kinc_g4_render_target_t *cm = (kinc_g4_render_target_t *)cubemap;
|
||||
return cm->height;
|
||||
}
|
33
Kha/Backends/Kinc-HL/kinc-bridge/display.c.h
Normal file
33
Kha/Backends/Kinc-HL/kinc-bridge/display.c.h
Normal file
@ -0,0 +1,33 @@
|
||||
#include <kinc/display.h>
|
||||
|
||||
void hl_kinc_display_init(void) {
|
||||
kinc_display_init();
|
||||
}
|
||||
|
||||
int hl_kinc_display_count(void) {
|
||||
return kinc_count_displays();
|
||||
}
|
||||
|
||||
int hl_kinc_display_width(int index) {
|
||||
return kinc_display_current_mode(index).width;
|
||||
}
|
||||
|
||||
int hl_kinc_display_height(int index) {
|
||||
return kinc_display_current_mode(index).height;
|
||||
}
|
||||
|
||||
int hl_kinc_display_x(int index) {
|
||||
return kinc_display_current_mode(index).x;
|
||||
}
|
||||
|
||||
int hl_kinc_display_y(int index) {
|
||||
return kinc_display_current_mode(index).y;
|
||||
}
|
||||
|
||||
bool hl_kinc_display_is_primary(int index) {
|
||||
return kinc_primary_display() == index;
|
||||
}
|
||||
|
||||
int hl_kinc_display_ppi(void) {
|
||||
return kinc_display_current_mode(kinc_primary_display()).pixels_per_inch;
|
||||
}
|
272
Kha/Backends/Kinc-HL/kinc-bridge/graphics.c.h
Normal file
272
Kha/Backends/Kinc-HL/kinc-bridge/graphics.c.h
Normal file
@ -0,0 +1,272 @@
|
||||
#include <kinc/graphics4/graphics.h>
|
||||
#include <kinc/graphics4/indexbuffer.h>
|
||||
#include <kinc/graphics4/texturearray.h>
|
||||
#include <kinc/graphics4/vertexbuffer.h>
|
||||
|
||||
#include <hl.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
void hl_kinc_graphics_clear(int flags, int color, float z, int stencil) {
|
||||
kinc_g4_clear(flags, color, z, stencil);
|
||||
}
|
||||
|
||||
bool hl_kinc_graphics_vsynced(void) {
|
||||
return true; // Kore::Graphics4::vsynced();
|
||||
}
|
||||
|
||||
int hl_kinc_graphics_refreshrate(void) {
|
||||
return 60; // Kore::Graphics4::refreshRate();
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_viewport(int x, int y, int width, int height) {
|
||||
kinc_g4_viewport(x, y, width, height);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_vertexbuffer(vbyte *buffer) {
|
||||
kinc_g4_vertex_buffer_t *buf = (kinc_g4_vertex_buffer_t *)buffer;
|
||||
kinc_g4_set_vertex_buffer(buf);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_vertexbuffers(vbyte *b0, vbyte *b1, vbyte *b2, vbyte *b3, int count) {
|
||||
assert(count <= 4);
|
||||
kinc_g4_vertex_buffer_t *vertexBuffers[4] = {(kinc_g4_vertex_buffer_t *)b0, (kinc_g4_vertex_buffer_t *)b1, (kinc_g4_vertex_buffer_t *)b2,
|
||||
(kinc_g4_vertex_buffer_t *)b3};
|
||||
kinc_g4_set_vertex_buffers(vertexBuffers, count);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_indexbuffer(vbyte *buffer) {
|
||||
kinc_g4_index_buffer_t *buf = (kinc_g4_index_buffer_t *)buffer;
|
||||
kinc_g4_set_index_buffer(buf);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_scissor(int x, int y, int width, int height) {
|
||||
kinc_g4_scissor(x, y, width, height);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_disable_scissor(void) {
|
||||
kinc_g4_disable_scissor();
|
||||
}
|
||||
|
||||
bool hl_kinc_graphics_render_targets_inverted_y(void) {
|
||||
return kinc_g4_render_targets_inverted_y();
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_texture_parameters(vbyte *unit, int uAddressing, int vAddressing, int minificationFilter, int magnificationFilter, int mipmapFilter) {
|
||||
kinc_g4_texture_unit_t *u = (kinc_g4_texture_unit_t *)unit;
|
||||
kinc_g4_set_texture_addressing(*u, KINC_G4_TEXTURE_DIRECTION_U, (kinc_g4_texture_addressing_t)uAddressing);
|
||||
kinc_g4_set_texture_addressing(*u, KINC_G4_TEXTURE_DIRECTION_V, (kinc_g4_texture_addressing_t)vAddressing);
|
||||
kinc_g4_set_texture_minification_filter(*u, (kinc_g4_texture_filter_t)minificationFilter);
|
||||
kinc_g4_set_texture_magnification_filter(*u, (kinc_g4_texture_filter_t)magnificationFilter);
|
||||
kinc_g4_set_texture_mipmap_filter(*u, (kinc_g4_mipmap_filter_t)mipmapFilter);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_texture3d_parameters(vbyte *unit, int uAddressing, int vAddressing, int wAddressing, int minificationFilter, int magnificationFilter,
|
||||
int mipmapFilter) {
|
||||
kinc_g4_texture_unit_t *u = (kinc_g4_texture_unit_t *)unit;
|
||||
kinc_g4_set_texture3d_addressing(*u, KINC_G4_TEXTURE_DIRECTION_U, (kinc_g4_texture_addressing_t)uAddressing);
|
||||
kinc_g4_set_texture3d_addressing(*u, KINC_G4_TEXTURE_DIRECTION_V, (kinc_g4_texture_addressing_t)vAddressing);
|
||||
kinc_g4_set_texture3d_addressing(*u, KINC_G4_TEXTURE_DIRECTION_W, (kinc_g4_texture_addressing_t)wAddressing);
|
||||
kinc_g4_set_texture3d_minification_filter(*u, (kinc_g4_texture_filter_t)minificationFilter);
|
||||
kinc_g4_set_texture3d_magnification_filter(*u, (kinc_g4_texture_filter_t)magnificationFilter);
|
||||
kinc_g4_set_texture3d_mipmap_filter(*u, (kinc_g4_mipmap_filter_t)mipmapFilter);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_texture_compare_mode(vbyte *unit, bool enabled) {
|
||||
kinc_g4_texture_unit_t *u = (kinc_g4_texture_unit_t *)unit;
|
||||
kinc_g4_set_texture_compare_mode(*u, enabled);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_cube_map_compare_mode(vbyte *unit, bool enabled) {
|
||||
kinc_g4_texture_unit_t *u = (kinc_g4_texture_unit_t *)unit;
|
||||
kinc_g4_set_cubemap_compare_mode(*u, enabled);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_texture(vbyte *unit, vbyte *texture) {
|
||||
kinc_g4_texture_unit_t *u = (kinc_g4_texture_unit_t *)unit;
|
||||
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
|
||||
kinc_g4_set_texture(*u, tex);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_texture_depth(vbyte *unit, vbyte *renderTarget) {
|
||||
kinc_g4_texture_unit_t *u = (kinc_g4_texture_unit_t *)unit;
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
kinc_g4_render_target_use_depth_as_texture(rt, *u);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_texture_array(vbyte *unit, vbyte *textureArray) {
|
||||
kinc_g4_texture_unit_t *u = (kinc_g4_texture_unit_t *)unit;
|
||||
kinc_g4_texture_array_t *texArray = (kinc_g4_texture_array_t *)textureArray;
|
||||
kinc_g4_set_texture_array(*u, texArray);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_render_target(vbyte *unit, vbyte *renderTarget) {
|
||||
kinc_g4_texture_unit_t *u = (kinc_g4_texture_unit_t *)unit;
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
kinc_g4_render_target_use_color_as_texture(rt, *u);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_cubemap_texture(vbyte *unit, vbyte *renderTarget) {
|
||||
kinc_g4_texture_unit_t *u = (kinc_g4_texture_unit_t *)unit;
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
kinc_g4_render_target_use_color_as_texture(rt, *u);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_cubemap_depth(vbyte *unit, vbyte *renderTarget) {
|
||||
kinc_g4_texture_unit_t *u = (kinc_g4_texture_unit_t *)unit;
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
kinc_g4_render_target_use_depth_as_texture(rt, *u);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_image_texture(vbyte *unit, vbyte *texture) {
|
||||
kinc_g4_texture_unit_t *u = (kinc_g4_texture_unit_t *)unit;
|
||||
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
|
||||
kinc_g4_set_image_texture(*u, tex);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_cubemap_target(vbyte *unit, vbyte *renderTarget) {
|
||||
kinc_g4_texture_unit_t *u = (kinc_g4_texture_unit_t *)unit;
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
kinc_g4_render_target_use_color_as_texture(rt, *u);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_bool(vbyte *location, bool value) {
|
||||
kinc_g4_constant_location_t *loc = (kinc_g4_constant_location_t *)location;
|
||||
kinc_g4_set_bool(*loc, value);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_int(vbyte *location, int value) {
|
||||
kinc_g4_constant_location_t *loc = (kinc_g4_constant_location_t *)location;
|
||||
kinc_g4_set_int(*loc, value);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_int2(vbyte *location, int value1, int value2) {
|
||||
kinc_g4_constant_location_t *loc = (kinc_g4_constant_location_t *)location;
|
||||
kinc_g4_set_int2(*loc, value1, value2);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_int3(vbyte *location, int value1, int value2, int value3) {
|
||||
kinc_g4_constant_location_t *loc = (kinc_g4_constant_location_t *)location;
|
||||
kinc_g4_set_int3(*loc, value1, value2, value3);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_int4(vbyte *location, int value1, int value2, int value3, int value4) {
|
||||
kinc_g4_constant_location_t *loc = (kinc_g4_constant_location_t *)location;
|
||||
kinc_g4_set_int4(*loc, value1, value2, value3, value4);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_ints(vbyte *location, vbyte *values, int count) {
|
||||
kinc_g4_constant_location_t *loc = (kinc_g4_constant_location_t *)location;
|
||||
kinc_g4_set_ints(*loc, (int *)values, count);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_float(vbyte *location, float value) {
|
||||
kinc_g4_constant_location_t *loc = (kinc_g4_constant_location_t *)location;
|
||||
kinc_g4_set_float(*loc, value);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_float2(vbyte *location, float value1, float value2) {
|
||||
kinc_g4_constant_location_t *loc = (kinc_g4_constant_location_t *)location;
|
||||
kinc_g4_set_float2(*loc, value1, value2);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_float3(vbyte *location, float value1, float value2, float value3) {
|
||||
kinc_g4_constant_location_t *loc = (kinc_g4_constant_location_t *)location;
|
||||
kinc_g4_set_float3(*loc, value1, value2, value3);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_float4(vbyte *location, float value1, float value2, float value3, float value4) {
|
||||
kinc_g4_constant_location_t *loc = (kinc_g4_constant_location_t *)location;
|
||||
kinc_g4_set_float4(*loc, value1, value2, value3, value4);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_floats(vbyte *location, vbyte *values, int count) {
|
||||
kinc_g4_constant_location_t *loc = (kinc_g4_constant_location_t *)location;
|
||||
kinc_g4_set_floats(*loc, (float *)values, count);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_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_g4_constant_location_t *loc = (kinc_g4_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_g4_set_matrix4(*loc, &value);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_set_matrix3(vbyte *location, float _00, float _10, float _20, float _01, float _11, float _21, float _02, float _12, float _22) {
|
||||
kinc_g4_constant_location_t *loc = (kinc_g4_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_g4_set_matrix3(*loc, &value);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_draw_all_indexed_vertices(void) {
|
||||
kinc_g4_draw_indexed_vertices();
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_draw_indexed_vertices(int start, int count) {
|
||||
kinc_g4_draw_indexed_vertices_from_to(start, count);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_draw_all_indexed_vertices_instanced(int instanceCount) {
|
||||
kinc_g4_draw_indexed_vertices_instanced(instanceCount);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_draw_indexed_vertices_instanced(int instanceCount, int start, int count) {
|
||||
kinc_g4_draw_indexed_vertices_instanced_from_to(instanceCount, start, count);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_restore_render_target(void) {
|
||||
kinc_g4_restore_render_target();
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_render_to_texture(vbyte *renderTarget) {
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
kinc_g4_set_render_targets(&rt, 1);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_render_to_textures(vbyte *rt0, vbyte *rt1, vbyte *rt2, vbyte *rt3, vbyte *rt4, vbyte *rt5, vbyte *rt6, vbyte *rt7, int count) {
|
||||
assert(count <= 8);
|
||||
kinc_g4_render_target_t *t0 = (kinc_g4_render_target_t *)rt0;
|
||||
kinc_g4_render_target_t *t1 = (kinc_g4_render_target_t *)rt1;
|
||||
kinc_g4_render_target_t *t2 = (kinc_g4_render_target_t *)rt2;
|
||||
kinc_g4_render_target_t *t3 = (kinc_g4_render_target_t *)rt3;
|
||||
kinc_g4_render_target_t *t4 = (kinc_g4_render_target_t *)rt4;
|
||||
kinc_g4_render_target_t *t5 = (kinc_g4_render_target_t *)rt5;
|
||||
kinc_g4_render_target_t *t6 = (kinc_g4_render_target_t *)rt6;
|
||||
kinc_g4_render_target_t *t7 = (kinc_g4_render_target_t *)&rt7;
|
||||
kinc_g4_render_target_t *targets[8] = {t0, t1, t2, t3, t4, t5, t6, t7};
|
||||
kinc_g4_set_render_targets(targets, count);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_render_to_face(vbyte *renderTarget, int face) {
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
kinc_g4_set_render_target_face(rt, face);
|
||||
}
|
||||
|
||||
void hl_kinc_graphics_flush(void) {
|
||||
kinc_g4_flush();
|
||||
}
|
25
Kha/Backends/Kinc-HL/kinc-bridge/indexbuffer.c.h
Normal file
25
Kha/Backends/Kinc-HL/kinc-bridge/indexbuffer.c.h
Normal file
@ -0,0 +1,25 @@
|
||||
#include <kinc/graphics4/indexbuffer.h>
|
||||
|
||||
#include <hl.h>
|
||||
|
||||
vbyte *hl_kinc_create_indexbuffer(int count) {
|
||||
kinc_g4_index_buffer_t *buffer = (kinc_g4_index_buffer_t *)malloc(sizeof(kinc_g4_index_buffer_t));
|
||||
kinc_g4_index_buffer_init(buffer, count, KINC_G4_INDEX_BUFFER_FORMAT_32BIT, KINC_G4_USAGE_STATIC);
|
||||
return (vbyte *)buffer;
|
||||
}
|
||||
|
||||
void hl_kinc_delete_indexbuffer(vbyte *buffer) {
|
||||
kinc_g4_index_buffer_t *buf = (kinc_g4_index_buffer_t *)buffer;
|
||||
kinc_g4_index_buffer_destroy(buf);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_indexbuffer_lock(vbyte *buffer, int start, int count) {
|
||||
kinc_g4_index_buffer_t *buf = (kinc_g4_index_buffer_t *)buffer;
|
||||
return (vbyte *)kinc_g4_index_buffer_lock(buf, start, count);
|
||||
}
|
||||
|
||||
void hl_kinc_indexbuffer_unlock(vbyte *buffer, int count) {
|
||||
kinc_g4_index_buffer_t *buf = (kinc_g4_index_buffer_t *)buffer;
|
||||
kinc_g4_index_buffer_unlock(buf, count);
|
||||
}
|
127
Kha/Backends/Kinc-HL/kinc-bridge/kinc.c.h
Normal file
127
Kha/Backends/Kinc-HL/kinc-bridge/kinc.c.h
Normal file
@ -0,0 +1,127 @@
|
||||
#include <kinc/audio2/audio.h>
|
||||
#include <kinc/graphics4/graphics.h>
|
||||
#include <kinc/io/filereader.h>
|
||||
#include <kinc/log.h>
|
||||
#include <kinc/system.h>
|
||||
#include <kinc/window.h>
|
||||
|
||||
#include <hl.h>
|
||||
|
||||
void frame();
|
||||
|
||||
static bool visible = true;
|
||||
static bool paused = false;
|
||||
|
||||
typedef void (*FN_AUDIO_CALL_CALLBACK)(int);
|
||||
typedef float (*FN_AUDIO_READ_SAMPLE)(void);
|
||||
|
||||
void (*audioCallCallback)(int);
|
||||
float (*audioReadSample)(void);
|
||||
|
||||
static void update(void *data) {
|
||||
if (paused) {
|
||||
return;
|
||||
}
|
||||
|
||||
kinc_a2_update();
|
||||
|
||||
int windowCount = kinc_count_windows();
|
||||
|
||||
for (int windowIndex = 0; windowIndex < windowCount; ++windowIndex) {
|
||||
if (visible) {
|
||||
kinc_g4_begin(windowIndex);
|
||||
frame();
|
||||
kinc_g4_end(windowIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (!kinc_g4_swap_buffers()) {
|
||||
kinc_log(KINC_LOG_LEVEL_ERROR, "Graphics context lost.");
|
||||
}
|
||||
}
|
||||
|
||||
static bool mixThreadregistered = false;
|
||||
|
||||
static void mix(kinc_a2_buffer_t *buffer, int samples) {
|
||||
#ifdef KORE_MULTITHREADED_AUDIO
|
||||
if (!mixThreadregistered) {
|
||||
vdynamic *ret;
|
||||
hl_register_thread(&ret);
|
||||
mixThreadregistered = true;
|
||||
}
|
||||
hl_blocking(true);
|
||||
#endif
|
||||
|
||||
audioCallCallback(samples);
|
||||
|
||||
for (int i = 0; i < samples; ++i) {
|
||||
float value = audioReadSample();
|
||||
*(float *)&buffer->data[buffer->write_location] = value;
|
||||
buffer->write_location += 4;
|
||||
if (buffer->write_location >= buffer->data_size) {
|
||||
buffer->write_location = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef KORE_MULTITHREADED_AUDIO
|
||||
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");
|
||||
|
||||
kinc_window_options_t win;
|
||||
kinc_window_options_set_defaults(&win);
|
||||
win.title = (char *)title;
|
||||
win.width = width;
|
||||
win.height = height;
|
||||
win.x = -1;
|
||||
win.y = -1;
|
||||
win.mode = (kinc_window_mode_t)windowMode;
|
||||
win.window_features = windowFeatures;
|
||||
kinc_framebuffer_options_t frame;
|
||||
kinc_framebuffer_options_set_defaults(&frame);
|
||||
frame.vertical_sync = vSync;
|
||||
frame.samples_per_pixel = samplesPerPixel;
|
||||
kinc_init((char *)title, width, height, &win, &frame);
|
||||
|
||||
kinc_set_update_callback(update, NULL);
|
||||
}
|
||||
|
||||
void hl_kinc_init_audio(vclosure *callCallback, vclosure *readSample, int *outSamplesPerSecond) {
|
||||
audioCallCallback = *((FN_AUDIO_CALL_CALLBACK *)(&callCallback->fun));
|
||||
audioReadSample = *((FN_AUDIO_READ_SAMPLE *)(&readSample->fun));
|
||||
kinc_a2_set_callback(mix);
|
||||
kinc_a2_init();
|
||||
*outSamplesPerSecond = kinc_a2_samples_per_second;
|
||||
}
|
||||
|
||||
void hl_run_kore(void) {
|
||||
kinc_start();
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_file_contents(vbyte *name, int *size) {
|
||||
int len;
|
||||
int p = 0;
|
||||
vbyte *content;
|
||||
kinc_file_reader_t file;
|
||||
if (!kinc_file_reader_open(&file, (char *)name, KINC_FILE_TYPE_ASSET)) {
|
||||
return NULL;
|
||||
}
|
||||
hl_blocking(true);
|
||||
len = (int)kinc_file_reader_size(&file);
|
||||
if (size) {
|
||||
*size = len;
|
||||
}
|
||||
hl_blocking(false);
|
||||
content = (vbyte *)hl_gc_alloc_noptr(size ? len : len + 1);
|
||||
hl_blocking(true);
|
||||
if (!size) {
|
||||
content[len] = 0; // final 0 for UTF8
|
||||
}
|
||||
kinc_file_reader_read(&file, content, len);
|
||||
kinc_file_reader_close(&file);
|
||||
hl_blocking(false);
|
||||
return content;
|
||||
}
|
265
Kha/Backends/Kinc-HL/kinc-bridge/shader.c.h
Normal file
265
Kha/Backends/Kinc-HL/kinc-bridge/shader.c.h
Normal file
@ -0,0 +1,265 @@
|
||||
#include <kinc/graphics4/graphics.h>
|
||||
#include <kinc/graphics4/pipeline.h>
|
||||
#include <kinc/graphics4/shader.h>
|
||||
#include <kinc/graphics4/vertexstructure.h>
|
||||
|
||||
#include <hl.h>
|
||||
|
||||
static kinc_g4_compare_mode_t convertCompareMode(int mode) {
|
||||
switch (mode) {
|
||||
case 0:
|
||||
return KINC_G4_COMPARE_ALWAYS;
|
||||
case 1:
|
||||
return KINC_G4_COMPARE_NEVER;
|
||||
case 2:
|
||||
return KINC_G4_COMPARE_EQUAL;
|
||||
case 3:
|
||||
return KINC_G4_COMPARE_NOT_EQUAL;
|
||||
case 4:
|
||||
return KINC_G4_COMPARE_LESS;
|
||||
case 5:
|
||||
return KINC_G4_COMPARE_LESS_EQUAL;
|
||||
case 6:
|
||||
return KINC_G4_COMPARE_GREATER;
|
||||
case 7:
|
||||
default:
|
||||
return KINC_G4_COMPARE_GREATER_EQUAL;
|
||||
}
|
||||
}
|
||||
|
||||
static kinc_g4_stencil_action_t convertStencilAction(int action) {
|
||||
switch (action) {
|
||||
case 0:
|
||||
return KINC_G4_STENCIL_KEEP;
|
||||
case 1:
|
||||
return KINC_G4_STENCIL_ZERO;
|
||||
case 2:
|
||||
return KINC_G4_STENCIL_REPLACE;
|
||||
case 3:
|
||||
return KINC_G4_STENCIL_INCREMENT;
|
||||
case 4:
|
||||
return KINC_G4_STENCIL_INCREMENT_WRAP;
|
||||
case 5:
|
||||
return KINC_G4_STENCIL_DECREMENT;
|
||||
case 6:
|
||||
return KINC_G4_STENCIL_DECREMENT_WRAP;
|
||||
case 7:
|
||||
default:
|
||||
return KINC_G4_STENCIL_INVERT;
|
||||
}
|
||||
}
|
||||
|
||||
static kinc_g4_render_target_format_t convertColorAttachment(int format) {
|
||||
switch (format) {
|
||||
case 0:
|
||||
return KINC_G4_RENDER_TARGET_FORMAT_32BIT;
|
||||
case 1:
|
||||
return KINC_G4_RENDER_TARGET_FORMAT_8BIT_RED;
|
||||
case 2:
|
||||
return KINC_G4_RENDER_TARGET_FORMAT_128BIT_FLOAT;
|
||||
case 3:
|
||||
return KINC_G4_RENDER_TARGET_FORMAT_16BIT_DEPTH;
|
||||
case 4:
|
||||
return KINC_G4_RENDER_TARGET_FORMAT_64BIT_FLOAT;
|
||||
case 5:
|
||||
return KINC_G4_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT;
|
||||
case 6:
|
||||
default:
|
||||
return KINC_G4_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT;
|
||||
}
|
||||
}
|
||||
|
||||
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_init(shader, data, length, KINC_G4_SHADER_TYPE_VERTEX);
|
||||
return (vbyte *)shader;
|
||||
}
|
||||
|
||||
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_init(shader, data, length, KINC_G4_SHADER_TYPE_FRAGMENT);
|
||||
return (vbyte *)shader;
|
||||
}
|
||||
|
||||
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_init(shader, data, length, KINC_G4_SHADER_TYPE_GEOMETRY);
|
||||
return (vbyte *)shader;
|
||||
}
|
||||
|
||||
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_init(shader, data, length, KINC_G4_SHADER_TYPE_TESSELLATION_CONTROL);
|
||||
return (vbyte *)shader;
|
||||
}
|
||||
|
||||
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_init(shader, data, length, KINC_G4_SHADER_TYPE_TESSELLATION_EVALUATION);
|
||||
return (vbyte *)shader;
|
||||
}
|
||||
|
||||
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_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_VERTEX);
|
||||
return (vbyte *)shader;
|
||||
}
|
||||
|
||||
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_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_FRAGMENT);
|
||||
return (vbyte *)shader;
|
||||
}
|
||||
|
||||
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_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_GEOMETRY);
|
||||
return (vbyte *)shader;
|
||||
}
|
||||
|
||||
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_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_TESSELLATION_CONTROL);
|
||||
return (vbyte *)shader;
|
||||
}
|
||||
|
||||
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_init_from_source(shader, (char *)source, KINC_G4_SHADER_TYPE_TESSELLATION_EVALUATION);
|
||||
return (vbyte *)shader;
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_create_pipeline() {
|
||||
kinc_g4_pipeline_t *pipeline = (kinc_g4_pipeline_t *)malloc(sizeof(kinc_g4_pipeline_t));
|
||||
kinc_g4_pipeline_init(pipeline);
|
||||
return (vbyte *)pipeline;
|
||||
}
|
||||
|
||||
void hl_kinc_delete_pipeline(vbyte *pipeline) {
|
||||
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
|
||||
kinc_g4_pipeline_destroy(pipe);
|
||||
free(pipe);
|
||||
}
|
||||
|
||||
void hl_kinc_pipeline_set_vertex_shader(vbyte *pipeline, vbyte *shader) {
|
||||
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
|
||||
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
|
||||
pipe->vertex_shader = sh;
|
||||
}
|
||||
|
||||
void hl_kinc_pipeline_set_fragment_shader(vbyte *pipeline, vbyte *shader) {
|
||||
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
|
||||
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
|
||||
pipe->fragment_shader = sh;
|
||||
}
|
||||
|
||||
void hl_kinc_pipeline_set_geometry_shader(vbyte *pipeline, vbyte *shader) {
|
||||
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
|
||||
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
|
||||
pipe->geometry_shader = sh;
|
||||
}
|
||||
|
||||
void hl_kinc_pipeline_set_tesscontrol_shader(vbyte *pipeline, vbyte *shader) {
|
||||
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
|
||||
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
|
||||
pipe->tessellation_control_shader = sh;
|
||||
}
|
||||
|
||||
void hl_kinc_pipeline_set_tesseval_shader(vbyte *pipeline, vbyte *shader) {
|
||||
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
|
||||
kinc_g4_shader_t *sh = (kinc_g4_shader_t *)shader;
|
||||
pipe->tessellation_evaluation_shader = sh;
|
||||
}
|
||||
|
||||
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;
|
||||
pipe->input_layout[0] = (kinc_g4_vertex_structure_t *)structure0;
|
||||
pipe->input_layout[1] = (kinc_g4_vertex_structure_t *)structure1;
|
||||
pipe->input_layout[2] = (kinc_g4_vertex_structure_t *)structure2;
|
||||
pipe->input_layout[3] = (kinc_g4_vertex_structure_t *)structure3;
|
||||
pipe->input_layout[4] = NULL;
|
||||
kinc_g4_pipeline_compile(pipe);
|
||||
}
|
||||
|
||||
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 blendSource, int blendDestination, int alphaBlendSource, int alphaBlendDestination, bool depthWrite,
|
||||
int stencilReferenceValue, int stencilReadMask, int stencilWriteMask, bool colorWriteMaskRed, bool colorWriteMaskGreen,
|
||||
bool colorWriteMaskBlue, bool colorWriteMaskAlpha, int colorAttachmentCount, int colorAttachment0, int colorAttachment1,
|
||||
int colorAttachment2, int colorAttachment3, int colorAttachment4, int colorAttachment5, int colorAttachment6,
|
||||
int colorAttachment7, int depthAttachmentBits, int stencilAttachmentBits, bool conservativeRasterization) {
|
||||
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
|
||||
|
||||
switch (cullMode) {
|
||||
case 0:
|
||||
pipe->cull_mode = KINC_G4_CULL_CLOCKWISE;
|
||||
break;
|
||||
case 1:
|
||||
pipe->cull_mode = KINC_G4_CULL_COUNTER_CLOCKWISE;
|
||||
break;
|
||||
case 2:
|
||||
pipe->cull_mode = KINC_G4_CULL_NOTHING;
|
||||
break;
|
||||
}
|
||||
|
||||
pipe->depth_mode = convertCompareMode(depthMode);
|
||||
pipe->depth_write = depthWrite;
|
||||
|
||||
pipe->stencil_front_mode = convertCompareMode(stencilFrontMode);
|
||||
pipe->stencil_front_both_pass = convertStencilAction(stencilFrontBothPass);
|
||||
pipe->stencil_front_depth_fail = convertStencilAction(stencilFrontDepthFail);
|
||||
pipe->stencil_front_fail = convertStencilAction(stencilFrontFail);
|
||||
|
||||
pipe->stencil_back_mode = convertCompareMode(stencilBackMode);
|
||||
pipe->stencil_back_both_pass = convertStencilAction(stencilBackBothPass);
|
||||
pipe->stencil_back_depth_fail = convertStencilAction(stencilBackDepthFail);
|
||||
pipe->stencil_back_fail = convertStencilAction(stencilBackFail);
|
||||
|
||||
pipe->stencil_reference_value = stencilReferenceValue;
|
||||
pipe->stencil_read_mask = stencilReadMask;
|
||||
pipe->stencil_write_mask = stencilWriteMask;
|
||||
|
||||
pipe->blend_source = (kinc_g4_blending_factor_t)blendSource;
|
||||
pipe->blend_destination = (kinc_g4_blending_factor_t)blendDestination;
|
||||
pipe->alpha_blend_source = (kinc_g4_blending_factor_t)alphaBlendSource;
|
||||
pipe->alpha_blend_destination = (kinc_g4_blending_factor_t)alphaBlendDestination;
|
||||
|
||||
pipe->color_write_mask_red[0] = colorWriteMaskRed;
|
||||
pipe->color_write_mask_green[0] = colorWriteMaskGreen;
|
||||
pipe->color_write_mask_blue[0] = colorWriteMaskBlue;
|
||||
pipe->color_write_mask_alpha[0] = colorWriteMaskAlpha;
|
||||
|
||||
pipe->color_attachment_count = colorAttachmentCount;
|
||||
pipe->color_attachment[0] = convertColorAttachment(colorAttachment0);
|
||||
pipe->color_attachment[1] = convertColorAttachment(colorAttachment1);
|
||||
pipe->color_attachment[2] = convertColorAttachment(colorAttachment2);
|
||||
pipe->color_attachment[3] = convertColorAttachment(colorAttachment3);
|
||||
pipe->color_attachment[4] = convertColorAttachment(colorAttachment4);
|
||||
pipe->color_attachment[5] = convertColorAttachment(colorAttachment5);
|
||||
pipe->color_attachment[6] = convertColorAttachment(colorAttachment6);
|
||||
pipe->color_attachment[7] = convertColorAttachment(colorAttachment7);
|
||||
|
||||
pipe->depth_attachment_bits = depthAttachmentBits;
|
||||
pipe->stencil_attachment_bits = stencilAttachmentBits;
|
||||
|
||||
pipe->conservative_rasterization = conservativeRasterization;
|
||||
}
|
||||
|
||||
void hl_kinc_pipeline_set(vbyte *pipeline) {
|
||||
kinc_g4_pipeline_t *pipe = (kinc_g4_pipeline_t *)pipeline;
|
||||
kinc_g4_set_pipeline(pipe);
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_pipeline_get_constantlocation(vbyte *pipeline, vbyte *name) {
|
||||
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));
|
||||
*location = kinc_g4_pipeline_get_constant_location(pipe, (char *)name);
|
||||
return (vbyte *)location;
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_pipeline_get_textureunit(vbyte *pipeline, vbyte *name) {
|
||||
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));
|
||||
*unit = kinc_g4_pipeline_get_texture_unit(pipe, (char *)name);
|
||||
return (vbyte *)unit;
|
||||
}
|
197
Kha/Backends/Kinc-HL/kinc-bridge/sound.c.h
Normal file
197
Kha/Backends/Kinc-HL/kinc-bridge/sound.c.h
Normal file
@ -0,0 +1,197 @@
|
||||
#include <kinc/error.h>
|
||||
#include <kinc/io/filereader.h>
|
||||
|
||||
#define STB_VORBIS_HEADER_ONLY
|
||||
#include <kinc/libs/stb_vorbis.c>
|
||||
|
||||
#include <hl.h>
|
||||
|
||||
struct WaveData {
|
||||
uint16_t audioFormat;
|
||||
uint16_t numChannels;
|
||||
uint32_t sampleRate;
|
||||
uint32_t bytesPerSecond;
|
||||
uint16_t bitsPerSample;
|
||||
uint32_t dataSize;
|
||||
uint8_t *data;
|
||||
};
|
||||
|
||||
static void checkFOURCC(uint8_t **data, const char *fourcc, const char *filename) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
kinc_affirm_message(*(*data) == fourcc[i], "Corrupt wav file: %s", filename);
|
||||
++(*data);
|
||||
}
|
||||
}
|
||||
|
||||
static void readFOURCC(uint8_t **data, char *fourcc) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
fourcc[i] = *(*data);
|
||||
++(*data);
|
||||
}
|
||||
fourcc[4] = 0;
|
||||
}
|
||||
|
||||
static void readChunk(uint8_t **data, struct WaveData *wave) {
|
||||
char fourcc[5];
|
||||
readFOURCC(data, fourcc);
|
||||
uint32_t chunksize = kinc_read_u32le(*data);
|
||||
*data += 4;
|
||||
if (strcmp(fourcc, "fmt ") == 0) {
|
||||
wave->audioFormat = kinc_read_u16le(*data + 0);
|
||||
wave->numChannels = kinc_read_u16le(*data + 2);
|
||||
wave->sampleRate = kinc_read_u32le(*data + 4);
|
||||
wave->bytesPerSecond = kinc_read_u32le(*data + 8);
|
||||
wave->bitsPerSample = kinc_read_u16le(*data + 14);
|
||||
*data += chunksize;
|
||||
}
|
||||
else if (strcmp(fourcc, "data") == 0) {
|
||||
wave->dataSize = chunksize;
|
||||
wave->data = (uint8_t *)malloc(chunksize * sizeof(uint8_t));
|
||||
memcpy(wave->data, *data, chunksize);
|
||||
*data += chunksize;
|
||||
}
|
||||
else {
|
||||
*data += chunksize;
|
||||
}
|
||||
}
|
||||
|
||||
static int16_t convert8to16(uint8_t sample) {
|
||||
return (sample - 128) << 8;
|
||||
}
|
||||
|
||||
static void splitStereo8(uint8_t *data, int size, int16_t *left, int16_t *right) {
|
||||
for (int i = 0; i < size; ++i) {
|
||||
left[i] = convert8to16(data[i * 2 + 0]);
|
||||
right[i] = convert8to16(data[i * 2 + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
static void splitStereo16(int16_t *data, int size, int16_t *left, int16_t *right) {
|
||||
for (int i = 0; i < size; ++i) {
|
||||
left[i] = data[i * 2 + 0];
|
||||
right[i] = data[i * 2 + 1];
|
||||
}
|
||||
}
|
||||
|
||||
static void splitMono8(uint8_t *data, int size, int16_t *left, int16_t *right) {
|
||||
for (int i = 0; i < size; ++i) {
|
||||
left[i] = convert8to16(data[i]);
|
||||
right[i] = convert8to16(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void splitMono16(int16_t *data, int size, int16_t *left, int16_t *right) {
|
||||
for (int i = 0; i < size; ++i) {
|
||||
left[i] = data[i];
|
||||
right[i] = data[i];
|
||||
}
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_sound_init_wav(vbyte *filename, vbyte *outSize, int *outSampleRate, double *outLength) {
|
||||
struct WaveData wave = {0};
|
||||
{
|
||||
kinc_file_reader_t reader;
|
||||
bool opened = kinc_file_reader_open(&reader, (char *)filename, KINC_FILE_TYPE_ASSET);
|
||||
kinc_affirm(opened);
|
||||
uint8_t *filedata = (uint8_t *)malloc(kinc_file_reader_size(&reader));
|
||||
kinc_file_reader_read(&reader, filedata, kinc_file_reader_size(&reader));
|
||||
kinc_file_reader_close(&reader);
|
||||
uint8_t *data = filedata;
|
||||
|
||||
checkFOURCC(&data, "RIFF", (char *)filename);
|
||||
uint32_t filesize = kinc_read_u32le(data);
|
||||
data += 4;
|
||||
checkFOURCC(&data, "WAVE", (char *)filename);
|
||||
while (data + 8 - filedata < (intptr_t)filesize) {
|
||||
readChunk(&data, &wave);
|
||||
}
|
||||
|
||||
free(filedata);
|
||||
}
|
||||
|
||||
float length = (wave.dataSize / (wave.bitsPerSample / 8) / wave.numChannels) / (float)wave.sampleRate;
|
||||
|
||||
int16_t *left;
|
||||
int16_t *right;
|
||||
|
||||
if (wave.numChannels == 1) {
|
||||
if (wave.bitsPerSample == 8) {
|
||||
left = (int16_t *)malloc(wave.dataSize * sizeof(int16_t));
|
||||
right = (int16_t *)malloc(wave.dataSize * sizeof(int16_t));
|
||||
splitMono8(wave.data, wave.dataSize, left, right);
|
||||
}
|
||||
else if (wave.bitsPerSample == 16) {
|
||||
wave.dataSize /= 2;
|
||||
left = (int16_t *)malloc(wave.dataSize * sizeof(int16_t));
|
||||
right = (int16_t *)malloc(wave.dataSize * sizeof(int16_t));
|
||||
splitMono16((int16_t *)wave.data, wave.dataSize, left, right);
|
||||
}
|
||||
else {
|
||||
kinc_affirm(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Left and right channel are in s16 audio stream, alternating.
|
||||
if (wave.bitsPerSample == 8) {
|
||||
wave.dataSize /= 2;
|
||||
left = (int16_t *)malloc(wave.dataSize * sizeof(int16_t));
|
||||
right = (int16_t *)malloc(wave.dataSize * sizeof(int16_t));
|
||||
splitStereo8(wave.data, wave.dataSize, left, right);
|
||||
}
|
||||
else if (wave.bitsPerSample == 16) {
|
||||
wave.dataSize /= 4;
|
||||
left = (int16_t *)malloc(wave.dataSize * sizeof(int16_t));
|
||||
right = (int16_t *)malloc(wave.dataSize * sizeof(int16_t));
|
||||
splitStereo16((int16_t *)wave.data, wave.dataSize, left, right);
|
||||
}
|
||||
else {
|
||||
kinc_affirm(false);
|
||||
}
|
||||
}
|
||||
|
||||
free(wave.data);
|
||||
|
||||
float *uncompressedData = (float *)malloc(wave.dataSize * 2 * sizeof(float));
|
||||
*((unsigned int *)outSize) = wave.dataSize * 2; // Return array size to Kha
|
||||
for (uint32_t i = 0; i < wave.dataSize; i += 1) {
|
||||
uncompressedData[i * 2 + 0] = (float)(left[i] / 32767.0);
|
||||
uncompressedData[i * 2 + 1] = (float)(right[i] / 32767.0);
|
||||
}
|
||||
*outSampleRate = wave.sampleRate;
|
||||
*outLength = (double)length;
|
||||
|
||||
free(left);
|
||||
free(right);
|
||||
|
||||
return (vbyte *)uncompressedData;
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_sound_init_vorbis(vbyte *data, int length) {
|
||||
return (vbyte *)stb_vorbis_open_memory(data, length, NULL, NULL);
|
||||
}
|
||||
|
||||
bool hl_kinc_sound_next_vorbis_samples(vbyte *vorbis, vbyte *samples, int length, bool loop, bool atend) {
|
||||
int read = stb_vorbis_get_samples_float_interleaved((stb_vorbis *)vorbis, 2, (float *)samples, length);
|
||||
if (read < length / 2) {
|
||||
if (loop) {
|
||||
stb_vorbis_seek_start((stb_vorbis *)vorbis);
|
||||
}
|
||||
else {
|
||||
atend = true;
|
||||
}
|
||||
for (int i = read * 2; i < length; ++i) {
|
||||
samples[i] = 0;
|
||||
}
|
||||
}
|
||||
return atend;
|
||||
}
|
||||
|
||||
float hl_kinc_sound_vorbis_get_length(vbyte *vorbis) {
|
||||
if (vorbis == NULL) return 0;
|
||||
return stb_vorbis_stream_length_in_seconds((stb_vorbis *)vorbis);
|
||||
}
|
||||
|
||||
float hl_kinc_sound_vorbis_get_position(vbyte *vorbis) {
|
||||
if (vorbis == NULL) return 0;
|
||||
return stb_vorbis_get_sample_offset((stb_vorbis *)vorbis) / (float)stb_vorbis_stream_length_in_samples((stb_vorbis *)vorbis);
|
||||
}
|
201
Kha/Backends/Kinc-HL/kinc-bridge/system.c.h
Normal file
201
Kha/Backends/Kinc-HL/kinc-bridge/system.c.h
Normal file
@ -0,0 +1,201 @@
|
||||
#include <kinc/input/acceleration.h>
|
||||
#include <kinc/input/gamepad.h>
|
||||
#include <kinc/input/keyboard.h>
|
||||
#include <kinc/input/mouse.h>
|
||||
#include <kinc/input/pen.h>
|
||||
#include <kinc/input/rotation.h>
|
||||
#include <kinc/input/surface.h>
|
||||
#include <kinc/log.h>
|
||||
#include <kinc/system.h>
|
||||
#include <kinc/video.h>
|
||||
#include <kinc/window.h>
|
||||
|
||||
#include <hl.h>
|
||||
|
||||
void hl_kinc_log(vbyte *v) {
|
||||
kinc_log(KINC_LOG_LEVEL_INFO, (char *)v);
|
||||
}
|
||||
|
||||
double hl_kinc_get_time(void) {
|
||||
return kinc_time();
|
||||
}
|
||||
|
||||
int hl_kinc_get_window_width(int window) {
|
||||
return kinc_window_width(window);
|
||||
}
|
||||
|
||||
int hl_kinc_get_window_height(int window) {
|
||||
return kinc_window_height(window);
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_get_system_id(void) {
|
||||
return (vbyte *)kinc_system_id();
|
||||
}
|
||||
|
||||
void hl_kinc_vibrate(int ms) {
|
||||
kinc_vibrate(ms);
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_get_language(void) {
|
||||
return (vbyte *)kinc_language();
|
||||
}
|
||||
|
||||
void hl_kinc_request_shutdown(void) {
|
||||
kinc_stop();
|
||||
}
|
||||
|
||||
void hl_kinc_mouse_lock(int windowId) {
|
||||
kinc_mouse_lock(windowId);
|
||||
}
|
||||
|
||||
void hl_kinc_mouse_unlock(void) {
|
||||
kinc_mouse_unlock();
|
||||
}
|
||||
|
||||
bool hl_kinc_can_lock_mouse(void) {
|
||||
return kinc_mouse_can_lock();
|
||||
}
|
||||
|
||||
bool hl_kinc_is_mouse_locked(void) {
|
||||
return kinc_mouse_is_locked();
|
||||
}
|
||||
|
||||
void hl_kinc_show_mouse(bool show) {
|
||||
if (show) {
|
||||
kinc_mouse_show();
|
||||
}
|
||||
else {
|
||||
kinc_mouse_hide();
|
||||
}
|
||||
}
|
||||
|
||||
bool hl_kinc_system_is_fullscreen(void) {
|
||||
return false; // kinc_is_fullscreen();
|
||||
}
|
||||
|
||||
void hl_kinc_system_request_fullscreen(void) {
|
||||
// kinc_change_resolution(display_width(), display_height(), true);
|
||||
}
|
||||
|
||||
void hl_kinc_system_exit_fullscreen(int previousWidth, int previousHeight) {
|
||||
// kinc_change_resolution(previousWidth, previousHeight, false);
|
||||
}
|
||||
|
||||
void hl_kinc_system_change_resolution(int width, int height) {
|
||||
// kinc_change_resolution(width, height, false);
|
||||
}
|
||||
|
||||
void hl_kinc_system_set_keepscreenon(bool on) {
|
||||
kinc_set_keep_screen_on(on);
|
||||
}
|
||||
|
||||
void hl_kinc_system_load_url(vbyte *url) {
|
||||
kinc_load_url((char *)url);
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_get_gamepad_id(int index) {
|
||||
return (vbyte*)kinc_gamepad_product_name(index);
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_get_gamepad_vendor(int index) {
|
||||
return (vbyte*)kinc_gamepad_vendor(index);
|
||||
}
|
||||
|
||||
bool hl_kinc_gamepad_connected(int index) {
|
||||
return kinc_gamepad_connected(index);
|
||||
}
|
||||
|
||||
typedef void (*FN_KEY_DOWN)(int, void *);
|
||||
typedef void (*FN_KEY_UP)(int, void *);
|
||||
typedef void (*FN_KEY_PRESS)(unsigned int, void *);
|
||||
|
||||
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_up_callback(*((FN_KEY_UP *)(&keyUp->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_UP)(int, int, int, int, void *);
|
||||
typedef void (*FN_MOUSE_MOVE)(int, int, int, int, int, void *);
|
||||
typedef void (*FN_MOUSE_WHEEL)(int, int, void *);
|
||||
|
||||
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_release_callback(*((FN_MOUSE_UP *)(&mouseUp->fun)), NULL);
|
||||
kinc_mouse_set_move_callback(*((FN_MOUSE_MOVE *)(&mouseMove->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_UP)(int, int, int, float);
|
||||
typedef void (*FN_PEN_MOVE)(int, int, int, float);
|
||||
|
||||
void hl_kinc_register_pen(vclosure *penDown, vclosure *penUp, vclosure *penMove) {
|
||||
kinc_pen_set_press_callback(*((FN_PEN_DOWN *)(&penDown->fun)));
|
||||
kinc_pen_set_release_callback(*((FN_PEN_UP *)(&penUp->fun)));
|
||||
kinc_pen_set_move_callback(*((FN_PEN_MOVE *)(&penMove->fun)));
|
||||
}
|
||||
|
||||
typedef void (*FN_GAMEPAD_AXIS)(int, int, float);
|
||||
typedef void (*FN_GAMEPAD_BUTTON)(int, int, float);
|
||||
|
||||
void hl_kinc_register_gamepad(vclosure *gamepadAxis, vclosure *gamepadButton) {
|
||||
kinc_gamepad_set_axis_callback(*((FN_GAMEPAD_AXIS *)(&gamepadAxis->fun)));
|
||||
kinc_gamepad_set_button_callback(*((FN_GAMEPAD_BUTTON *)(&gamepadButton->fun)));
|
||||
}
|
||||
|
||||
typedef void (*FN_TOUCH_START)(int, int, int);
|
||||
typedef void (*FN_TOUCH_END)(int, int, int);
|
||||
typedef void (*FN_TOUCH_MOVE)(int, int, int);
|
||||
|
||||
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_end_callback(*((FN_TOUCH_END *)(&touchEnd->fun)));
|
||||
kinc_surface_set_move_callback(*((FN_TOUCH_MOVE *)(&touchMove->fun)));
|
||||
}
|
||||
|
||||
typedef void (*FN_SENSOR_ACCELEROMETER)(float, float, float);
|
||||
typedef void (*FN_SENSOR_GYROSCOPE)(float, float, float);
|
||||
|
||||
void hl_kinc_register_sensor(vclosure *accelerometerChanged, vclosure *gyroscopeChanged) {
|
||||
kinc_acceleration_set_callback(*((FN_SENSOR_ACCELEROMETER *)(&accelerometerChanged->fun)));
|
||||
kinc_rotation_set_callback(*((FN_SENSOR_GYROSCOPE *)(&gyroscopeChanged->fun)));
|
||||
}
|
||||
|
||||
// typedef void(*FN_CB_ORIENTATION)(int);
|
||||
typedef void (*FN_CB_FOREGROUND)(void *);
|
||||
typedef void (*FN_CB_RESUME)(void *);
|
||||
typedef void (*FN_CB_PAUSE)(void *);
|
||||
typedef void (*FN_CB_BACKGROUND)(void *);
|
||||
typedef void (*FN_CB_SHUTDOWN)(void *);
|
||||
|
||||
void hl_kinc_register_callbacks(vclosure *foreground, vclosure *resume, vclosure *pause, vclosure *background, vclosure *shutdown) {
|
||||
// kinc_set_orientation_callback(orientation);
|
||||
kinc_set_foreground_callback(*((FN_CB_FOREGROUND *)(&foreground->fun)), NULL);
|
||||
kinc_set_resume_callback(*((FN_CB_RESUME *)(&resume->fun)), NULL);
|
||||
kinc_set_pause_callback(*((FN_CB_PAUSE *)(&pause->fun)), NULL);
|
||||
kinc_set_background_callback(*((FN_CB_BACKGROUND *)(&background->fun)), NULL);
|
||||
kinc_set_shutdown_callback(*((FN_CB_SHUTDOWN *)(&shutdown->fun)), NULL);
|
||||
}
|
||||
|
||||
typedef void (*FN_CB_DROPFILES)(wchar_t *);
|
||||
|
||||
void hl_kinc_register_dropfiles(vclosure *dropFiles) {
|
||||
// todo: string convert
|
||||
// kinc_set_drop_files_callback(*((FN_CB_DROPFILES*)(&dropFiles->fun)));
|
||||
}
|
||||
|
||||
typedef char *(*FN_CB_COPY)(void *);
|
||||
typedef char *(*FN_CB_CUT)(void *);
|
||||
typedef void (*FN_CB_PASTE)(char *, void *);
|
||||
|
||||
void hl_kinc_register_copycutpaste(vclosure *copy, vclosure *cut, vclosure *paste) {
|
||||
kinc_set_copy_callback(*((FN_CB_COPY *)(©->fun)), NULL);
|
||||
kinc_set_cut_callback(*((FN_CB_CUT *)(&cut->fun)), NULL);
|
||||
kinc_set_paste_callback(*((FN_CB_PASTE *)(&paste->fun)), NULL);
|
||||
}
|
||||
|
||||
const char *hl_kinc_video_format(void) {
|
||||
return kinc_video_formats()[0];
|
||||
}
|
327
Kha/Backends/Kinc-HL/kinc-bridge/texture.c.h
Normal file
327
Kha/Backends/Kinc-HL/kinc-bridge/texture.c.h
Normal file
@ -0,0 +1,327 @@
|
||||
#include <kinc/graphics4/graphics.h>
|
||||
#include <kinc/image.h>
|
||||
#include <kinc/video.h>
|
||||
|
||||
#include <hl.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
typedef struct tex_and_data {
|
||||
kinc_g4_texture_t texture;
|
||||
int width, height;
|
||||
void *data;
|
||||
} tex_and_data_t;
|
||||
|
||||
static kinc_image_format_t convertImageFormat(int format) {
|
||||
switch (format) {
|
||||
default:
|
||||
case 0:
|
||||
return KINC_IMAGE_FORMAT_RGBA32;
|
||||
case 1:
|
||||
return KINC_IMAGE_FORMAT_GREY8;
|
||||
case 2:
|
||||
return KINC_IMAGE_FORMAT_RGBA128;
|
||||
case 4:
|
||||
return KINC_IMAGE_FORMAT_RGBA64;
|
||||
case 5:
|
||||
return KINC_IMAGE_FORMAT_A32;
|
||||
case 6:
|
||||
return KINC_IMAGE_FORMAT_A16;
|
||||
}
|
||||
}
|
||||
|
||||
static int sizeOf(kinc_image_format_t format) {
|
||||
switch (format) {
|
||||
case KINC_IMAGE_FORMAT_RGBA128:
|
||||
return 16;
|
||||
case KINC_IMAGE_FORMAT_RGBA32:
|
||||
case KINC_IMAGE_FORMAT_BGRA32:
|
||||
return 4;
|
||||
case KINC_IMAGE_FORMAT_RGBA64:
|
||||
return 8;
|
||||
case KINC_IMAGE_FORMAT_A32:
|
||||
return 4;
|
||||
case KINC_IMAGE_FORMAT_A16:
|
||||
return 2;
|
||||
case KINC_IMAGE_FORMAT_GREY8:
|
||||
return 1;
|
||||
case KINC_IMAGE_FORMAT_RGB24:
|
||||
return 3;
|
||||
}
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_texture_create(int width, int height, int format, bool readable) {
|
||||
tex_and_data_t *texture = (tex_and_data_t *)malloc(sizeof(tex_and_data_t));
|
||||
kinc_image_format_t f = convertImageFormat(format);
|
||||
kinc_g4_texture_init(&texture->texture, width, height, f);
|
||||
texture->width = width;
|
||||
texture->height = height;
|
||||
if (readable) {
|
||||
texture->data = malloc(width * height * sizeOf(f));
|
||||
}
|
||||
else {
|
||||
texture->data = NULL;
|
||||
}
|
||||
return (vbyte *)texture;
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_texture_create_from_file(vbyte *filename, bool readable) {
|
||||
size_t size = kinc_image_size_from_file((char *)filename);
|
||||
if (size > 0) {
|
||||
tex_and_data_t *texture = (tex_and_data_t *)malloc(sizeof(tex_and_data_t));
|
||||
texture->data = malloc(size);
|
||||
kinc_image_t image;
|
||||
if (kinc_image_init_from_file(&image, texture->data, (char *)filename) != 0) {
|
||||
kinc_g4_texture_init_from_image(&texture->texture, &image);
|
||||
texture->width = image.width;
|
||||
texture->height = image.height;
|
||||
if (!readable) {
|
||||
free(texture->data);
|
||||
texture->data = NULL;
|
||||
}
|
||||
kinc_image_destroy(&image);
|
||||
return (vbyte *)texture;
|
||||
}
|
||||
kinc_image_destroy(&image);
|
||||
free(texture->data);
|
||||
texture->data = NULL;
|
||||
free(texture);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_texture_create3d(int width, int height, int depth, int format, bool readable) {
|
||||
tex_and_data_t *texture = (tex_and_data_t *)malloc(sizeof(tex_and_data_t));
|
||||
kinc_image_format_t f = convertImageFormat(format);
|
||||
kinc_g4_texture_init(&texture->texture, width, height, f);
|
||||
texture->width = width;
|
||||
texture->height = height;
|
||||
if (readable) {
|
||||
texture->data = malloc(width * height * depth * sizeOf(f));
|
||||
}
|
||||
else {
|
||||
texture->data = NULL;
|
||||
}
|
||||
return (vbyte *)texture;
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_video_get_current_image(vbyte *video) {
|
||||
kinc_video_t *v = (kinc_video_t *)video;
|
||||
return (vbyte *)kinc_video_current_image(v);
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_texture_from_bytes(vbyte *bytes, int width, int height, int format, bool readable) {
|
||||
kinc_image_format_t f = convertImageFormat(format);
|
||||
|
||||
kinc_image_t image;
|
||||
kinc_image_init(&image, bytes, width, height, f);
|
||||
|
||||
tex_and_data_t *texture = (tex_and_data_t *)malloc(sizeof(tex_and_data_t));
|
||||
kinc_g4_texture_init_from_image(&texture->texture, &image);
|
||||
texture->width = width;
|
||||
texture->height = height;
|
||||
|
||||
kinc_image_destroy(&image);
|
||||
|
||||
if (readable) {
|
||||
size_t size = width * height * sizeOf(f);
|
||||
texture->data = malloc(size);
|
||||
memcpy(texture->data, bytes, size);
|
||||
}
|
||||
else {
|
||||
texture->data = NULL;
|
||||
}
|
||||
|
||||
return (vbyte *)texture;
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_texture_from_bytes3d(vbyte *bytes, int width, int height, int depth, int format, bool readable) {
|
||||
kinc_image_format_t f = convertImageFormat(format);
|
||||
|
||||
kinc_image_t image;
|
||||
kinc_image_init3d(&image, bytes, width, height, depth, f);
|
||||
|
||||
tex_and_data_t *texture = (tex_and_data_t *)malloc(sizeof(tex_and_data_t));
|
||||
kinc_g4_texture_init_from_image3d(&texture->texture, &image);
|
||||
texture->width = width;
|
||||
texture->height = height;
|
||||
|
||||
kinc_image_destroy(&image);
|
||||
|
||||
if (readable) {
|
||||
size_t size = width * height * depth * sizeOf(f);
|
||||
texture->data = malloc(size);
|
||||
memcpy(texture->data, bytes, size);
|
||||
}
|
||||
else {
|
||||
texture->data = NULL;
|
||||
}
|
||||
|
||||
return (vbyte *)texture;
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_texture_from_encoded_bytes(vbyte *bytes, int length, vbyte *format, bool readable) {
|
||||
tex_and_data_t *texture = (tex_and_data_t *)malloc(sizeof(tex_and_data_t));
|
||||
|
||||
size_t size = kinc_image_size_from_encoded_bytes(bytes, length, (char *)format);
|
||||
texture->data = malloc(size);
|
||||
|
||||
kinc_image_t image;
|
||||
kinc_image_init_from_encoded_bytes(&image, texture->data, bytes, length, (char *)format);
|
||||
|
||||
kinc_g4_texture_init_from_image(&texture->texture, &image);
|
||||
texture->width = image.width;
|
||||
texture->height = image.height;
|
||||
|
||||
kinc_image_destroy(&image);
|
||||
|
||||
if (!readable) {
|
||||
free(texture->data);
|
||||
texture->data = NULL;
|
||||
}
|
||||
|
||||
return (vbyte *)texture;
|
||||
}
|
||||
|
||||
bool hl_kinc_non_pow2_textures_supported(void) {
|
||||
return kinc_g4_supports_non_pow2_textures();
|
||||
}
|
||||
|
||||
int hl_kinc_texture_get_width(vbyte *texture) {
|
||||
tex_and_data_t *tex = (tex_and_data_t *)texture;
|
||||
return tex->width;
|
||||
}
|
||||
|
||||
int hl_kinc_texture_get_height(vbyte *texture) {
|
||||
tex_and_data_t *tex = (tex_and_data_t *)texture;
|
||||
return tex->height;
|
||||
}
|
||||
|
||||
int hl_kinc_texture_get_real_width(vbyte *texture) {
|
||||
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
|
||||
return tex->tex_width;
|
||||
}
|
||||
|
||||
int hl_kinc_texture_get_real_height(vbyte *texture) {
|
||||
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
|
||||
return tex->tex_height;
|
||||
}
|
||||
|
||||
int hl_kinc_texture_get_stride(vbyte *texture) {
|
||||
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
|
||||
return kinc_g4_texture_stride(tex);
|
||||
}
|
||||
|
||||
int hl_kinc_texture_at(vbyte *texture, int x, int y) {
|
||||
tex_and_data_t *tex = (tex_and_data_t *)texture;
|
||||
assert(tex->data != NULL);
|
||||
return *(int *)&((uint8_t *)tex->data)[tex->width * sizeOf(tex->texture.format) * y + x * sizeOf(tex->texture.format)];
|
||||
}
|
||||
|
||||
void hl_kinc_texture_unload(vbyte *texture) {
|
||||
tex_and_data_t *tex = (tex_and_data_t *)texture;
|
||||
if (tex->data != NULL) {
|
||||
free(tex->data);
|
||||
tex->data = NULL;
|
||||
}
|
||||
kinc_g4_texture_destroy(&tex->texture);
|
||||
free(tex);
|
||||
}
|
||||
|
||||
void hl_kinc_render_target_unload(vbyte *renderTarget) {
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
kinc_g4_render_target_destroy(rt);
|
||||
free(rt);
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_render_target_create(int width, int height, int depthBufferBits, int format, int stencilBufferBits) {
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)malloc(sizeof(kinc_g4_render_target_t));
|
||||
kinc_g4_render_target_init(rt, width, height, (kinc_g4_render_target_format_t)format, depthBufferBits, stencilBufferBits);
|
||||
return (vbyte *)rt;
|
||||
}
|
||||
|
||||
int hl_kinc_render_target_get_width(vbyte *renderTarget) {
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
return rt->width;
|
||||
}
|
||||
|
||||
int hl_kinc_render_target_get_height(vbyte *renderTarget) {
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
return rt->height;
|
||||
}
|
||||
|
||||
int hl_kinc_render_target_get_real_width(vbyte *renderTarget) {
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
return rt->texWidth;
|
||||
}
|
||||
|
||||
int hl_kinc_render_target_get_real_height(vbyte *renderTarget) {
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
return rt->texHeight;
|
||||
}
|
||||
|
||||
void hl_kinc_texture_unlock(vbyte *texture, vbyte *bytes) {
|
||||
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
|
||||
uint8_t *b = (uint8_t *)bytes;
|
||||
uint8_t *btex = kinc_g4_texture_lock(tex);
|
||||
int size = sizeOf(tex->format);
|
||||
int stride = kinc_g4_texture_stride(tex);
|
||||
for (int y = 0; y < tex->tex_height; ++y) {
|
||||
for (int x = 0; x < tex->tex_width; ++x) {
|
||||
#ifdef KORE_DIRECT3D
|
||||
if (tex->format == KINC_IMAGE_FORMAT_RGBA32) {
|
||||
// RBGA->BGRA
|
||||
btex[y * stride + x * size + 0] = b[(y * tex->tex_width + x) * size + 2];
|
||||
btex[y * stride + x * size + 1] = b[(y * tex->tex_width + x) * size + 1];
|
||||
btex[y * stride + x * size + 2] = b[(y * tex->tex_width + x) * size + 0];
|
||||
btex[y * stride + x * size + 3] = b[(y * tex->tex_width + x) * size + 3];
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
for (int i = 0; i < size; ++i) {
|
||||
btex[y * stride + x * size + i] = b[(y * tex->tex_width + x) * size + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
kinc_g4_texture_unlock(tex);
|
||||
}
|
||||
|
||||
void hl_kinc_render_target_get_pixels(vbyte *renderTarget, vbyte *pixels) {
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
kinc_g4_render_target_get_pixels(rt, pixels);
|
||||
}
|
||||
|
||||
void hl_kinc_generate_mipmaps_texture(vbyte *texture, int levels) {
|
||||
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
|
||||
kinc_g4_texture_generate_mipmaps(tex, levels);
|
||||
}
|
||||
|
||||
void hl_kinc_generate_mipmaps_target(vbyte *renderTarget, int levels) {
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
kinc_g4_render_target_generate_mipmaps(rt, levels);
|
||||
}
|
||||
|
||||
void hl_kinc_set_mipmap_texture(vbyte *texture, vbyte *mipmap, int level) {
|
||||
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
|
||||
tex_and_data_t *miptex = (tex_and_data_t *)mipmap;
|
||||
assert(miptex->data != NULL);
|
||||
kinc_image_t mipimage;
|
||||
kinc_image_init(&mipimage, miptex->data, miptex->width, miptex->height, miptex->texture.format);
|
||||
kinc_g4_texture_set_mipmap(tex, &mipimage, level);
|
||||
kinc_image_destroy(&mipimage);
|
||||
}
|
||||
|
||||
void hl_kinc_render_target_set_depth_stencil_from(vbyte *renderTarget, vbyte *from) {
|
||||
kinc_g4_render_target_t *rt = (kinc_g4_render_target_t *)renderTarget;
|
||||
kinc_g4_render_target_t *rt2 = (kinc_g4_render_target_t *)from;
|
||||
kinc_g4_render_target_set_depth_stencil_from(rt, rt2);
|
||||
}
|
||||
|
||||
void hl_kinc_texture_clear(vbyte *texture, int x, int y, int z, int width, int height, int depth, int color) {
|
||||
kinc_g4_texture_t *tex = (kinc_g4_texture_t *)texture;
|
||||
kinc_g4_texture_clear(tex, x, y, z, width, height, depth, color);
|
||||
}
|
49
Kha/Backends/Kinc-HL/kinc-bridge/vertexbuffer.c.h
Normal file
49
Kha/Backends/Kinc-HL/kinc-bridge/vertexbuffer.c.h
Normal file
@ -0,0 +1,49 @@
|
||||
#include <kinc/graphics4/vertexbuffer.h>
|
||||
#include <kinc/graphics4/vertexstructure.h>
|
||||
|
||||
#include <hl.h>
|
||||
|
||||
vbyte *hl_kinc_create_vertexstructure(bool instanced) {
|
||||
kinc_g4_vertex_structure_t *struc = (kinc_g4_vertex_structure_t *)malloc(sizeof(kinc_g4_vertex_structure_t));
|
||||
kinc_g4_vertex_structure_init(struc);
|
||||
struc->instanced = instanced;
|
||||
return (vbyte *)struc;
|
||||
}
|
||||
|
||||
void hl_kinc_vertexstructure_add(vbyte *structure, vbyte *name, int data) {
|
||||
kinc_g4_vertex_structure_t *struc = (kinc_g4_vertex_structure_t *)structure;
|
||||
kinc_g4_vertex_structure_add(struc, (char *)name, (kinc_g4_vertex_data_t)data);
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_create_vertexbuffer(int vertexCount, vbyte *structure, int usage, int stepRate) {
|
||||
kinc_g4_vertex_structure_t *struc = (kinc_g4_vertex_structure_t *)structure;
|
||||
kinc_g4_vertex_buffer_t *buffer = (kinc_g4_vertex_buffer_t *)malloc(sizeof(kinc_g4_vertex_buffer_t));
|
||||
kinc_g4_vertex_buffer_init(buffer, vertexCount, struc, (kinc_g4_usage_t)usage, stepRate);
|
||||
return (vbyte *)buffer;
|
||||
}
|
||||
|
||||
void hl_kinc_delete_vertexbuffer(vbyte *buffer) {
|
||||
kinc_g4_vertex_buffer_t *buf = (kinc_g4_vertex_buffer_t *)buffer;
|
||||
kinc_g4_vertex_buffer_destroy(buf);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
vbyte *hl_kinc_vertexbuffer_lock(vbyte *buffer) {
|
||||
kinc_g4_vertex_buffer_t *buf = (kinc_g4_vertex_buffer_t *)buffer;
|
||||
return (vbyte *)kinc_g4_vertex_buffer_lock_all(buf);
|
||||
}
|
||||
|
||||
void hl_kinc_vertexbuffer_unlock(vbyte *buffer, int count) {
|
||||
kinc_g4_vertex_buffer_t *buf = (kinc_g4_vertex_buffer_t *)buffer;
|
||||
kinc_g4_vertex_buffer_unlock_all(buf);
|
||||
}
|
||||
|
||||
int hl_kinc_vertexbuffer_count(vbyte *buffer) {
|
||||
kinc_g4_vertex_buffer_t *buf = (kinc_g4_vertex_buffer_t *)buffer;
|
||||
return kinc_g4_vertex_buffer_count(buf);
|
||||
}
|
||||
|
||||
int hl_kinc_vertexbuffer_stride(vbyte *buffer) {
|
||||
kinc_g4_vertex_buffer_t *buf = (kinc_g4_vertex_buffer_t *)buffer;
|
||||
return kinc_g4_vertex_buffer_stride(buf);
|
||||
}
|
60
Kha/Backends/Kinc-HL/kinc-bridge/video.c.h
Normal file
60
Kha/Backends/Kinc-HL/kinc-bridge/video.c.h
Normal file
@ -0,0 +1,60 @@
|
||||
#include <kinc/video.h>
|
||||
|
||||
#include <hl.h>
|
||||
|
||||
vbyte *hl_kinc_video_create(vbyte *filename) {
|
||||
kinc_video_t *video = (kinc_video_t *)malloc(sizeof(kinc_video_t));
|
||||
kinc_video_init(video, (char *)filename);
|
||||
return (vbyte *)video;
|
||||
}
|
||||
|
||||
void hl_kinc_video_play(vbyte *video) {
|
||||
kinc_video_t *vid = (kinc_video_t *)video;
|
||||
kinc_video_play(vid, false);
|
||||
}
|
||||
|
||||
void hl_kinc_video_pause(vbyte *video) {
|
||||
kinc_video_t *vid = (kinc_video_t *)video;
|
||||
kinc_video_pause(vid);
|
||||
}
|
||||
|
||||
void hl_kinc_video_stop(vbyte *video) {
|
||||
kinc_video_t *vid = (kinc_video_t *)video;
|
||||
kinc_video_stop(vid);
|
||||
}
|
||||
|
||||
int hl_kinc_video_get_duration(vbyte *video) {
|
||||
kinc_video_t *vid = (kinc_video_t *)video;
|
||||
return (int)(kinc_video_duration(vid) * 1000.0);
|
||||
}
|
||||
|
||||
int hl_kinc_video_get_position(vbyte *video) {
|
||||
kinc_video_t *vid = (kinc_video_t *)video;
|
||||
return (int)(kinc_video_position(vid) * 1000.0);
|
||||
}
|
||||
|
||||
void hl_kinc_video_set_position(vbyte *video, int value) {
|
||||
kinc_video_t *vid = (kinc_video_t *)video;
|
||||
kinc_video_update(vid, value / 1000.0);
|
||||
}
|
||||
|
||||
bool hl_kinc_video_is_finished(vbyte *video) {
|
||||
kinc_video_t *vid = (kinc_video_t *)video;
|
||||
return kinc_video_finished(vid);
|
||||
}
|
||||
|
||||
int hl_kinc_video_width(vbyte *video) {
|
||||
kinc_video_t *vid = (kinc_video_t *)video;
|
||||
return kinc_video_width(vid);
|
||||
}
|
||||
|
||||
int hl_kinc_video_height(vbyte *video) {
|
||||
kinc_video_t *vid = (kinc_video_t *)video;
|
||||
return kinc_video_height(vid);
|
||||
}
|
||||
|
||||
void hl_kinc_video_unload(vbyte *video) {
|
||||
kinc_video_t *vid = (kinc_video_t *)video;
|
||||
kinc_video_destroy(vid);
|
||||
free(vid);
|
||||
}
|
Reference in New Issue
Block a user