Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,74 @@
#pragma once
#include <kinc/global.h>
#include <kinc/backend/graphics4/compute.h>
#ifdef KINC_OPENGL
#include <kinc/backend/graphics4/ShaderStorageBufferImpl.h>
#include <kinc/graphics4/vertexbuffer.h>
#endif
#include <kinc/graphics4/graphics.h>
/*! \file compute.h
\brief Provides support for running compute-shaders.
*/
#ifdef __cplusplus
extern "C" {
#endif
struct kinc_g4_texture;
struct kinc_g4_render_target;
typedef struct kinc_g4_compute_shader {
kinc_g4_compute_shader_impl impl;
} kinc_g4_compute_shader;
/// <summary>
/// Initialize a compute-shader from system-specific shader-data.
/// </summary>
/// <param name="shader">The shader-object to initialize</param>
/// <param name="source">A pointer to system-specific shader-data</param>
/// <param name="length">Length of the shader-data in bytes</param>
KINC_FUNC void kinc_g4_compute_shader_init(kinc_g4_compute_shader *shader, void *source, int length);
/// <summary>
/// Destroy a shader-object
/// </summary>
/// <param name="shader">The shader-object to destroy</param>
KINC_FUNC void kinc_g4_compute_shader_destroy(kinc_g4_compute_shader *shader);
#ifndef KINC_KONG
/// <summary>
/// Finds the location of a constant/uniform inside of a shader.
/// </summary>
/// <param name="shader">The shader to look into</param>
/// <param name="name">The constant/uniform-name to look for</param>
/// <returns>The found constant-location</returns>
KINC_FUNC kinc_g4_constant_location_t kinc_g4_compute_shader_get_constant_location(kinc_g4_compute_shader *shader, const char *name);
/// <summary>
/// Finds a texture-unit inside of a shader.
/// </summary>
/// <param name="shader">The shader to look into</param>
/// <param name="name">The texture-name to look for</param>
/// <returns>The found texture-unit</returns>
KINC_FUNC kinc_g4_texture_unit_t kinc_g4_compute_shader_get_texture_unit(kinc_g4_compute_shader *shader, const char *name);
#endif
#ifdef KINC_OPENGL
typedef struct kinc_shader_storage_buffer {
kinc_compute_shader_storage_buffer_impl_t impl;
} kinc_shader_storage_buffer_t;
KINC_FUNC void kinc_shader_storage_buffer_init(kinc_shader_storage_buffer_t *buffer, int count, kinc_g4_vertex_data_t type);
KINC_FUNC void kinc_shader_storage_buffer_destroy(kinc_shader_storage_buffer_t *buffer);
KINC_FUNC int *kinc_shader_storage_buffer_lock(kinc_shader_storage_buffer_t *buffer);
KINC_FUNC void kinc_shader_storage_buffer_unlock(kinc_shader_storage_buffer_t *buffer);
KINC_FUNC int kinc_shader_storage_buffer_count(kinc_shader_storage_buffer_t *buffer);
KINC_FUNC void kinc_shader_storage_buffer_internal_set(kinc_shader_storage_buffer_t *buffer);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,77 @@
#pragma once
#ifdef KINC_KONG
#include <kinc/global.h>
#include <kinc/backend/graphics4/constantbuffer.h>
#include <kinc/math/matrix.h>
#include <kinc/math/vector.h>
/*! \file constantbuffer.h
\brief Provides support for managing buffers of constant-data for shaders.
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef struct kinc_g4_constant_buffer {
kinc_g4_constant_buffer_impl impl;
} kinc_g4_constant_buffer;
/// <summary>
/// Initializes a constant-buffer.
/// </summary>
/// <param name="buffer">The buffer to initialize</param>
/// <param name="size">The size of the constant-data in the buffer in bytes</param>
KINC_FUNC void kinc_g4_constant_buffer_init(kinc_g4_constant_buffer *buffer, size_t size);
/// <summary>
/// Destroys a buffer.
/// </summary>
/// <param name="buffer">The buffer to destroy</param>
KINC_FUNC void kinc_g4_constant_buffer_destroy(kinc_g4_constant_buffer *buffer);
/// <summary>
/// Locks all of a constant-buffer to modify its contents.
/// </summary>
/// <param name="buffer">The buffer to lock</param>
/// <returns>The contents of the buffer</returns>
KINC_FUNC uint8_t *kinc_g4_constant_buffer_lock_all(kinc_g4_constant_buffer *buffer);
/// <summary>
/// Locks part of a constant-buffer to modify its contents.
/// </summary>
/// <param name="buffer">The buffer to lock</param>
/// <param name="start">The offset of where to start the lock in bytes</param>
/// <param name="count">The number of bytes to lock</param>
/// <returns>The contents of the buffer, starting at start</returns>
KINC_FUNC uint8_t *kinc_g4_constant_buffer_lock(kinc_g4_constant_buffer *buffer, size_t start, size_t count);
/// <summary>
/// Unlocks a constant-buffer so the changed contents can be used.
/// </summary>
/// <param name="buffer">The buffer to unlock</param>
KINC_FUNC void kinc_g4_constant_buffer_unlock_all(kinc_g4_constant_buffer *buffer);
/// <summary>
/// Unlocks parts of a constant-buffer so the changed contents can be used.
/// </summary>
/// <param name="buffer">The buffer to unlock</param>
/// /// <param name="count">The number of bytes to unlock, starting from the start-index from the previous lock-call</param>
KINC_FUNC void kinc_g4_constant_buffer_unlock(kinc_g4_constant_buffer *buffer, size_t count);
/// <summary>
/// Figures out the size of the constant-data in the buffer.
/// </summary>
/// <param name="buffer">The buffer to figure out the size for</param>
/// <returns>Returns the size of the constant-data in the buffer in bytes</returns>
KINC_FUNC size_t kinc_g4_constant_buffer_size(kinc_g4_constant_buffer *buffer);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,22 @@
#pragma once
#include <kinc/global.h>
#include <kinc/backend/graphics4/pipeline.h>
#include <kinc/backend/graphics4/shader.h>
/*! \file constantlocation.h
\brief Provides the constant_location-struct which is used for setting constants/uniforms in a shader.
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef struct kinc_g4_constant_location {
kinc_g4_constant_location_impl_t impl;
} kinc_g4_constant_location_t;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,4 @@
#include "graphics.c.h"
#include "pipeline.c.h"
#include "rendertarget.c.h"
#include "vertexbuffer.c.h"

View File

@ -0,0 +1,11 @@
#include "graphics.h"
static int antialiasing_samples;
int kinc_g4_antialiasing_samples(void) {
return antialiasing_samples;
}
void kinc_g4_set_antialiasing_samples(int samples) {
antialiasing_samples = samples;
}

View File

@ -0,0 +1,457 @@
#pragma once
#include <kinc/global.h>
#include <kinc/math/matrix.h>
#include "constantlocation.h"
#include "pipeline.h"
#include "textureunit.h"
/*! \file graphics.h
\brief Contains the base G4-functionality.
*/
#ifdef __cplusplus
extern "C" {
#endif
struct kinc_g4_compute_shader;
struct kinc_g4_pipeline;
struct kinc_g4_render_target;
struct kinc_g4_texture;
struct kinc_g4_texture_array;
#ifdef KINC_OPENGL
struct kinc_shader_storage_buffer;
#endif
#ifdef KINC_KONG
struct kinc_g4_constant_buffer;
#endif
typedef enum {
KINC_G4_TEXTURE_ADDRESSING_REPEAT,
KINC_G4_TEXTURE_ADDRESSING_MIRROR,
KINC_G4_TEXTURE_ADDRESSING_CLAMP,
KINC_G4_TEXTURE_ADDRESSING_BORDER
} kinc_g4_texture_addressing_t;
typedef enum { KINC_G4_TEXTURE_DIRECTION_U, KINC_G4_TEXTURE_DIRECTION_V, KINC_G4_TEXTURE_DIRECTION_W } kinc_g4_texture_direction_t;
typedef enum { KINC_G4_TEXTURE_FILTER_POINT, KINC_G4_TEXTURE_FILTER_LINEAR, KINC_G4_TEXTURE_FILTER_ANISOTROPIC } kinc_g4_texture_filter_t;
typedef enum {
KINC_G4_MIPMAP_FILTER_NONE,
KINC_G4_MIPMAP_FILTER_POINT,
KINC_G4_MIPMAP_FILTER_LINEAR // linear texture filter + linear mip filter -> trilinear filter
} kinc_g4_mipmap_filter_t;
/// <summary>
/// Returns whether instanced rendering (kinc_g4_draw_indexed_vertices_instanced and pals) is supported.
/// </summary>
/// <returns>Whether instanced rendering is supported</returns>
KINC_FUNC bool kinc_g4_supports_instanced_rendering(void);
/// <summary>
/// Returns whether GPU-compute (the functions in kinc/compute/compute.h) is supported.
/// </summary>
/// <returns>Whether GPU-compute is supported</returns>
KINC_FUNC bool kinc_g4_supports_compute_shaders(void);
/// <summary>
/// Returns whether blend-constants (see kinc_g4_set_blend_constant and the blending-properties for pipelines) are supported.
/// </summary>
/// <returns>Whether blend-constants are supported</returns>
KINC_FUNC bool kinc_g4_supports_blend_constants(void);
/// <summary>
/// Returns whether textures are supported which have widths/heights which are not powers of two.
/// </summary>
/// <returns>Whether non power of two texture-sizes are supported</returns>
KINC_FUNC bool kinc_g4_supports_non_pow2_textures(void);
/// <summary>
/// Returns whether render-targets are upside down. This happens in OpenGL and there is currently no automatic mitigation.
/// </summary>
/// <returns>Whether render-targets are upside down</returns>
KINC_FUNC bool kinc_g4_render_targets_inverted_y(void);
/// <summary>
/// Returns how many textures can be used at the same time in a fragment-shader.
/// </summary>
/// <returns>The number of textures</returns>
KINC_FUNC int kinc_g4_max_bound_textures(void);
/// <summary>
/// Kicks off lingering work - may or may not actually do anything depending on the underlying graphics-API.
/// </summary>
KINC_FUNC void kinc_g4_flush(void);
/// <summary>
/// Needs to be called before rendering to a window. Typically called at the start of each frame.
/// </summary>
/// <param name="window">The window to render to</param>
KINC_FUNC void kinc_g4_begin(int window);
/// <summary>
/// Needs to be called after rendering to a window. Typically called at the end of each frame.
/// </summary>
/// <param name="window">The window to render to</param>
/// <returns></returns>
KINC_FUNC void kinc_g4_end(int window);
/// <summary>
/// Needs to be called to make the rendered frame visible. Typically called at the very end of each frame.
/// </summary>
KINC_FUNC bool kinc_g4_swap_buffers(void);
#define KINC_G4_CLEAR_COLOR 1
#define KINC_G4_CLEAR_DEPTH 2
#define KINC_G4_CLEAR_STENCIL 4
/// <summary>
/// Clears the color, depth and/or stencil-components of the current framebuffer or render-target.
/// </summary>
/// <param name="flags">Defines what components to clear</param>
/// <param name="color">The color-value to clear to in 0xAARRGGBB</param>
/// <param name="depth">The depth-value to clear to</param>
/// <param name="stencil">The stencil-value to clear to</param>
KINC_FUNC void kinc_g4_clear(unsigned flags, unsigned color, float depth, int stencil);
/// <summary>
/// Sets the viewport which defines the portion of the framebuffer or render-target things are rendered into. By default the viewport is equivalent to the full
/// size of the current render-target or framebuffer.
/// </summary>
/// <param name="x">The x-offset of the viewport from the left of the screen in pixels</param>
/// <param name="y">The y-offset of the viewport from the top of the screen in pixels</param>
/// <param name="width">The width of the viewport in pixels</param>
/// <param name="height">The height of the viewport in pixels</param>
KINC_FUNC void kinc_g4_viewport(int x, int y, int width, int height);
/// <summary>
/// Enables and defines the scissor-rect. When the scissor-rect is enabled, anything that's rendered outside of the scissor-rect will be ignored.
/// </summary>
/// <param name="x">The x-offset of the scissor-rect from the left of the screen in pixels</param>
/// <param name="y">The y-offset of the scissor-rect from the top of the screen in pixels</param>
/// <param name="width">The width of the scissor-rect in pixels</param>
/// <param name="height">The height of the scissor-rect in pixels</param>
KINC_FUNC void kinc_g4_scissor(int x, int y, int width, int height);
/// <summary>
/// Disables the scissor-rect.
/// </summary>
KINC_FUNC void kinc_g4_disable_scissor(void);
/// <summary>
/// Draws the entire content of the currently set index-buffer and vertex-buffer. G4 can only draw triangle-lists using vertex-indices as this is what GPUs tend
/// to be optimized for.
/// </summary>
KINC_FUNC void kinc_g4_draw_indexed_vertices(void);
/// <summary>
/// Draws a part of the content of the currently set index-buffer and vertex-buffer. G4 can only draw triangle-lists using vertex-indices as this is what GPUs
/// tend to be optimized for.
/// </summary>
/// <param name="start">The offset into the index-buffer</param>
/// <param name="count">The number of indices to use</param>
KINC_FUNC void kinc_g4_draw_indexed_vertices_from_to(int start, int count);
/// <summary>
/// Draws a part of the content of the currently set index-buffer and vertex-buffer and additionally applies a general offset into the vertex-buffer. G4 can
/// only draw triangle-lists using vertex-indices as this is what GPUs tend to be optimized for.
/// </summary>
/// <param name="start">The offset into the index-buffer</param>
/// <param name="count">The number of indices to use</param>
/// <param name="vertex_offset">The offset into the vertex-buffer which is added to each index read from the index-buffer</param>
KINC_FUNC void kinc_g4_draw_indexed_vertices_from_to_from(int start, int count, int vertex_offset);
KINC_FUNC void kinc_g4_draw_indexed_vertices_instanced(int instanceCount);
KINC_FUNC void kinc_g4_draw_indexed_vertices_instanced_from_to(int instanceCount, int start, int count);
KINC_FUNC void kinc_g4_set_texture_addressing(kinc_g4_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing);
KINC_FUNC void kinc_g4_set_texture3d_addressing(kinc_g4_texture_unit_t unit, kinc_g4_texture_direction_t dir, kinc_g4_texture_addressing_t addressing);
/// <summary>
/// Sets the pipeline for the next draw-call. The pipeline defines most rendering-state including the shaders to be used.
/// </summary>
/// <param name="pipeline">The pipeline to set</param>
KINC_FUNC void kinc_g4_set_pipeline(struct kinc_g4_pipeline *pipeline);
KINC_FUNC void kinc_g4_set_stencil_reference_value(int value);
/// <summary>
/// Sets the blend constant used for `KINC_G4_BLEND_CONSTANT` or `KINC_G4_INV_BLEND_CONSTANT`
/// </summary>
KINC_FUNC void kinc_g4_set_blend_constant(float r, float g, float b, float a);
#ifdef KINC_KONG
KINC_FUNC void kinc_g4_set_constant_buffer(uint32_t id, struct kinc_g4_constant_buffer *buffer);
#endif
/// <summary>
/// Assigns an integer to a constant/uniform in the currently set pipeline.
/// </summary>
/// <param name="location">The location of the constant/uniform to assign the value to</param>
/// <param name="value">The value to assign to the constant/uniform</param>
KINC_FUNC void kinc_g4_set_int(kinc_g4_constant_location_t location, int value);
/// <summary>
/// Assigns two integers to a constant/uniform in the currently set pipeline.
/// </summary>
/// <param name="location">The location of the constant/uniform to assign the values to</param>
/// <param name="value1">The value to assign to the first component of the constant/uniform</param>
/// <param name="value2">The value to assign to the second component of the constant/uniform</param>
KINC_FUNC void kinc_g4_set_int2(kinc_g4_constant_location_t location, int value1, int value2);
/// <summary>
/// Assigns three integers to a constant/uniform in the currently set pipeline.
/// </summary>
/// <param name="location">The location of the constant/uniform to assign the values to</param>
/// <param name="value1">The value to assign to the first component of the constant/uniform</param>
/// <param name="value2">The value to assign to the second component of the constant/uniform</param>
/// <param name="value3">The value to assign to the third component of the constant/uniform</param>
KINC_FUNC void kinc_g4_set_int3(kinc_g4_constant_location_t location, int value1, int value2, int value3);
/// <summary>
/// Assigns four integers to a constant/uniform in the currently set pipeline.
/// </summary>
/// <param name="location">The location of the constant/uniform to assign the values to</param>
/// <param name="value1">The value to assign to the first component of the constant/uniform</param>
/// <param name="value2">The value to assign to the second component of the constant/uniform</param>
/// <param name="value3">The value to assign to the third component of the constant/uniform</param>
/// <param name="value4">The value to assign to the fourth component of the constant/uniform</param>
KINC_FUNC void kinc_g4_set_int4(kinc_g4_constant_location_t location, int value1, int value2, int value3, int value4);
/// <summary>
/// Assigns a bunch of integers to a constant/uniform in the currently set pipeline.
/// </summary>
/// <param name="location">The location of the constant/uniform to assign the values to</param>
/// <param name="value">The values to assign to the constant/uniform</param>
/// <param name="value">The number of values to assign to the constant/uniform</param>
KINC_FUNC void kinc_g4_set_ints(kinc_g4_constant_location_t location, int *values, int count);
/// <summary>
/// Assigns a float to a constant/uniform in the currently set pipeline.
/// </summary>
/// <param name="location">The location of the constant/uniform to assign the value to</param>
/// <param name="value">The value to assign to the constant/uniform</param>
KINC_FUNC void kinc_g4_set_float(kinc_g4_constant_location_t location, float value);
/// <summary>
/// Assigns two floats to a constant/uniform in the currently set pipeline.
/// </summary>
/// <param name="location">The location of the constant/uniform to assign the values to</param>
/// <param name="value1">The value to assign to the first constant/uniform</param>
/// <param name="value2">The value to assign to the second constant/uniform</param>
KINC_FUNC void kinc_g4_set_float2(kinc_g4_constant_location_t location, float value1, float value2);
/// <summary>
/// Assigns three floats to a constant/uniform in the currently set pipeline.
/// </summary>
/// <param name="location">The location of the constant/uniform to assign the values to</param>
/// <param name="value1">The value to assign to the first constant/uniform</param>
/// <param name="value2">The value to assign to the second constant/uniform</param>
/// <param name="value3">The value to assign to the third constant/uniform</param>
KINC_FUNC void kinc_g4_set_float3(kinc_g4_constant_location_t location, float value1, float value2, float value3);
/// <summary>
/// Assigns four floats to a constant/uniform in the currently set pipeline.
/// </summary>
/// <param name="location">The location of the constant/uniform to assign the values to</param>
/// <param name="value1">The value to assign to the first constant/uniform</param>
/// <param name="value2">The value to assign to the second constant/uniform</param>
/// <param name="value3">The value to assign to the third constant/uniform</param>
/// <param name="value4">The value to assign to the fourth constant/uniform</param>
KINC_FUNC void kinc_g4_set_float4(kinc_g4_constant_location_t location, float value1, float value2, float value3, float value4);
/// <summary>
/// Assigns a bunch of floats to a constant/uniform in the currently set pipeline.
/// </summary>
/// <param name="location">The location of the constant/uniform to assign the values to</param>
/// <param name="value">The values to assign to the constant/uniform</param>
/// <param name="value">The number of values to assign to the constant/uniform</param>
KINC_FUNC void kinc_g4_set_floats(kinc_g4_constant_location_t location, float *values, int count);
/// <summary>
/// Assigns a bool to a constant/uniform in the currently set pipeline.
/// </summary>
/// <param name="location">The location of the constant/uniform to assign the value to</param>
/// <param name="value">The value to assign to the constant/uniform</param>
KINC_FUNC void kinc_g4_set_bool(kinc_g4_constant_location_t location, bool value);
/// <summary>
/// Assigns a 3x3-matrix to a constant/uniform in the currently set pipeline.
/// </summary>
/// <param name="location">The location of the constant/uniform to assign the value to</param>
/// <param name="value">The value to assign to the constant/uniform</param>
KINC_FUNC void kinc_g4_set_matrix3(kinc_g4_constant_location_t location, kinc_matrix3x3_t *value);
/// <summary>
/// Assigns a 4x4-matrix to a constant/uniform in the currently set pipeline.
/// </summary>
/// <param name="location">The location of the constant/uniform to assign the value to</param>
/// <param name="value">The value to assign to the constant/uniform</param>
KINC_FUNC void kinc_g4_set_matrix4(kinc_g4_constant_location_t location, kinc_matrix4x4_t *value);
/// <summary>
/// Set the texture-sampling-mode for upscaled textures.
/// </summary>
/// <param name="unit">The texture-unit to set the texture-sampling-mode for</param>
/// <param name="filter">The mode to set</param>
KINC_FUNC void kinc_g4_set_texture_magnification_filter(kinc_g4_texture_unit_t unit, kinc_g4_texture_filter_t filter);
/// <summary>
/// Set the texture-sampling-mode for upscaled 3D-textures.
/// </summary>
/// <param name="unit">The texture-unit to set the texture-sampling-mode for</param>
/// <param name="filter">The mode to set</param>
KINC_FUNC void kinc_g4_set_texture3d_magnification_filter(kinc_g4_texture_unit_t texunit, kinc_g4_texture_filter_t filter);
/// <summary>
/// Set the texture-sampling-mode for downscaled textures.
/// </summary>
/// <param name="unit">The texture-unit to set the texture-sampling-mode for</param>
/// <param name="filter">The mode to set</param>
KINC_FUNC void kinc_g4_set_texture_minification_filter(kinc_g4_texture_unit_t unit, kinc_g4_texture_filter_t filter);
/// <summary>
/// Set the texture-sampling-mode for downscaled 3D-textures.
/// </summary>
/// <param name="unit">The texture-unit to set the texture-sampling-mode for</param>
/// <param name="filter">The mode to set</param>
KINC_FUNC void kinc_g4_set_texture3d_minification_filter(kinc_g4_texture_unit_t texunit, kinc_g4_texture_filter_t filter);
/// <summary>
/// Sets the mipmap-sampling-mode which defines whether mipmaps are used at all and if so whether the two neighbouring mipmaps are linearly interpolated.
/// </summary>
/// <param name="unit">The texture-unit to set the mipmap-sampling-mode for</param>
/// <param name="filter">The mode to set</param>
KINC_FUNC void kinc_g4_set_texture_mipmap_filter(kinc_g4_texture_unit_t unit, kinc_g4_mipmap_filter_t filter);
/// <summary>
/// Sets the mipmap-sampling-mode for a 3D-texture which defines whether mipmaps are used at all and if so whether the two neighbouring mipmaps are linearly
/// interpolated.
/// </summary>
/// <param name="unit">The texture-unit to set the mipmap-sampling-mode for</param>
/// <param name="filter">The mode to set</param>
KINC_FUNC void kinc_g4_set_texture3d_mipmap_filter(kinc_g4_texture_unit_t texunit, kinc_g4_mipmap_filter_t filter);
KINC_FUNC void kinc_g4_set_texture_compare_mode(kinc_g4_texture_unit_t unit, bool enabled);
KINC_FUNC void kinc_g4_set_texture_compare_func(kinc_g4_texture_unit_t unit, kinc_g4_compare_mode_t mode);
KINC_FUNC void kinc_g4_set_cubemap_compare_mode(kinc_g4_texture_unit_t unit, bool enabled);
KINC_FUNC void kinc_g4_set_cubemap_compare_func(kinc_g4_texture_unit_t unit, kinc_g4_compare_mode_t mode);
KINC_FUNC void kinc_g4_set_texture_max_anisotropy(kinc_g4_texture_unit_t unit, uint16_t max_anisotropy);
KINC_FUNC void kinc_g4_set_cubemap_max_anisotropy(kinc_g4_texture_unit_t unit, uint16_t max_anisotropy);
KINC_FUNC void kinc_g4_set_texture_lod(kinc_g4_texture_unit_t unit, float lod_min_clamp, float lod_max_clamp);
KINC_FUNC void kinc_g4_set_cubemap_lod(kinc_g4_texture_unit_t unit, float lod_min_clamp, float lod_max_clamp);
/// <summary>
/// Sets the framebuffer (aka the actual contents of the current window) to be the target of any future draw-calls.
/// </summary>
KINC_FUNC void kinc_g4_restore_render_target(void);
/// <summary>
/// Sets the passed render-targets to be the target of any future draw-calls.
/// </summary>
/// <param name="targets">An array of render-targets</param>
/// <param name="count">The number of render-targets in the render-target-array</param>
KINC_FUNC void kinc_g4_set_render_targets(struct kinc_g4_render_target **targets, int count);
KINC_FUNC void kinc_g4_set_render_target_face(struct kinc_g4_render_target *texture, int face);
#ifdef KINC_KONG
/// <summary>
/// Assigns a texture to a texture-unit for sampled access via GLSL's texture.
/// </summary>
/// <param name="unit">The unit to assign this texture to</param>
/// <param name="texture">The texture to assign to the unit</param>
KINC_FUNC void kinc_g4_set_texture(uint32_t unit, struct kinc_g4_texture *texture);
#else
/// <summary>
/// Assigns a texture to a texture-unit for sampled access via GLSL's texture.
/// </summary>
/// <param name="unit">The unit to assign this texture to</param>
/// <param name="texture">The texture to assign to the unit</param>
KINC_FUNC void kinc_g4_set_texture(kinc_g4_texture_unit_t unit, struct kinc_g4_texture *texture);
#endif
/// <summary>
/// Assigns a texture to a texture-unit for direct access via GLSL's texelFetch (as
/// opposed to GLSL's texture). The name of this functions is unfortunately based
/// on OpenGL's confusing terminology.
/// </summary>
/// <param name="unit">The unit to assign this texture to</param>
/// <param name="texture">The texture to assign to the unit</param>
KINC_FUNC void kinc_g4_set_image_texture(kinc_g4_texture_unit_t unit, struct kinc_g4_texture *texture);
KINC_FUNC bool kinc_g4_init_occlusion_query(unsigned *occlusionQuery);
KINC_FUNC void kinc_g4_delete_occlusion_query(unsigned occlusionQuery);
KINC_FUNC void kinc_g4_start_occlusion_query(unsigned occlusionQuery);
KINC_FUNC void kinc_g4_end_occlusion_query(unsigned occlusionQuery);
KINC_FUNC bool kinc_g4_are_query_results_available(unsigned occlusionQuery);
KINC_FUNC void kinc_g4_get_query_results(unsigned occlusionQuery, unsigned *pixelCount);
/// <summary>
/// Assigns a texture-array to a texture-unit.
/// </summary>
/// <param name="unit">The unit to assign the texture-array to</param>
/// <param name="array">The texture-array to assign to the texture-unit</param>
KINC_FUNC void kinc_g4_set_texture_array(kinc_g4_texture_unit_t unit, struct kinc_g4_texture_array *array);
/// <summary>
/// Returns the currently used number of samples for hardware-antialiasing.
/// </summary>
/// <returns>The number of samples</returns>
KINC_FUNC int kinc_g4_antialiasing_samples(void);
/// <summary>
/// Sets the number of samples used for hardware-antialiasing. This typically uses multisampling and typically only works with a few specific numbers of
/// sample-counts - 2 and 4 are pretty safe bets. It also might do nothing at all.
/// </summary>
/// <param name="samples">The number of samples</param>
KINC_FUNC void kinc_g4_set_antialiasing_samples(int samples);
#ifdef KINC_OPENGL
/// <summary>
/// Old, hack thing, do not use.
/// </summary>
KINC_FUNC void kinc_g4_set_shader_storage_buffer(struct kinc_shader_storage_buffer *buffer, int index);
#endif
/// <summary>
/// Sets a shader for the next compute-run.
/// </summary>
/// <param name="shader">The shader to use</param>
KINC_FUNC void kinc_g4_set_compute_shader(struct kinc_g4_compute_shader *shader);
/// <summary>
/// Fire off a compute-run on x * y * z elements.
/// </summary>
/// <param name="x">The x-size for the compute-run</param>
/// <param name="y">The y-size for the compute-run</param>
/// <param name="z">The z-size for the compute-run</param>
KINC_FUNC void kinc_g4_compute(int x, int y, int z);
#ifndef KINC_DOCS
void kinc_g4_internal_init(void);
void kinc_g4_internal_init_window(int window, int depth_buffer_bits, int stencil_buffer_bits, bool vsync);
void kinc_g4_internal_destroy_window(int window);
void kinc_g4_internal_destroy(void);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,84 @@
#pragma once
#include <kinc/global.h>
#include "usage.h"
#include <kinc/backend/graphics4/indexbuffer.h>
/*! \file indexbuffer.h
\brief Provides functions for setting up and using index-buffers.
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef enum kinc_g4_index_buffer_format { KINC_G4_INDEX_BUFFER_FORMAT_32BIT, KINC_G4_INDEX_BUFFER_FORMAT_16BIT } kinc_g4_index_buffer_format_t;
typedef struct kinc_g4_index_buffer {
kinc_g4_index_buffer_impl_t impl;
} kinc_g4_index_buffer_t;
/// <summary>
/// Initializes an index-buffer.
/// </summary>
/// <param name="buffer">The buffer to initialize</param>
/// <param name="count">The number of indices to allocate for the buffer</param>
/// <param name="format">The integer-format of the buffer</param>
/// <param name="usage">A hint for how the buffer will be used</param>
KINC_FUNC void kinc_g4_index_buffer_init(kinc_g4_index_buffer_t *buffer, int count, kinc_g4_index_buffer_format_t format, kinc_g4_usage_t usage);
/// <summary>
/// Destroys an index-buffer.
/// </summary>
/// <param name="buffer">The buffer to destroy</param>
KINC_FUNC void kinc_g4_index_buffer_destroy(kinc_g4_index_buffer_t *buffer);
/// <summary>
/// Locks an index-buffer so its contents can be modified.
/// </summary>
/// <param name="buffer">The buffer to lock</param>
/// <returns>The contents of the index-buffer in uint32s or uint16s depending on the format provided when initializing</returns>
KINC_FUNC void *kinc_g4_index_buffer_lock_all(kinc_g4_index_buffer_t *buffer);
/// <summary>
/// Locks part of a vertex-buffer to modify its contents.
/// </summary>
/// <param name="buffer">The buffer to lock</param>
/// <param name="start">The index of the first index to lock</param>
/// <param name="count">The number of indices to lock</param>
/// <returns>The contents of the index-buffer, starting at start, in uint32s or uint16s depending on the format provided when initializing</returns>
KINC_FUNC void *kinc_g4_index_buffer_lock(kinc_g4_index_buffer_t *buffer, int start, int count);
/// <summary>
/// Unlocks an index-buffer after locking it so the changed buffer-contents can be used.
/// </summary>
/// <param name="buffer">The buffer to unlock</param>
KINC_FUNC void kinc_g4_index_buffer_unlock_all(kinc_g4_index_buffer_t *buffer);
/// <summary>
/// Unlocks part of an index-buffer after locking so the changed buffer-contents can be used.
/// </summary>
/// <param name="buffer">The buffer to unlock</param>
/// <param name="count">The number of indices to unlock, starting from the start-index from the previous lock-call</param>
KINC_FUNC void kinc_g4_index_buffer_unlock(kinc_g4_index_buffer_t *buffer, int count);
/// <summary>
/// Returns the number of indices in the buffer.
/// </summary>
/// <param name="buffer">The buffer to query for its number of indices</param>
/// <returns>The number of indices</returns>
KINC_FUNC int kinc_g4_index_buffer_count(kinc_g4_index_buffer_t *buffer);
void kinc_internal_g4_index_buffer_set(kinc_g4_index_buffer_t *buffer);
/// <summary>
/// Sets an index-buffer to be used for the next draw-command.
/// </summary>
/// <param name="buffer">The buffer to use</param>
KINC_FUNC void kinc_g4_set_index_buffer(kinc_g4_index_buffer_t *buffer);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,55 @@
#include "pipeline.h"
#include <stddef.h>
void kinc_g4_internal_pipeline_set_defaults(kinc_g4_pipeline_t *state) {
for (int i = 0; i < 16; ++i)
state->input_layout[i] = NULL;
state->vertex_shader = NULL;
state->fragment_shader = NULL;
state->geometry_shader = NULL;
state->tessellation_control_shader = NULL;
state->tessellation_evaluation_shader = NULL;
state->cull_mode = KINC_G4_CULL_NOTHING;
state->depth_write = false;
state->depth_mode = KINC_G4_COMPARE_ALWAYS;
state->stencil_front_mode = KINC_G4_COMPARE_ALWAYS;
state->stencil_front_both_pass = KINC_G4_STENCIL_KEEP;
state->stencil_front_depth_fail = KINC_G4_STENCIL_KEEP;
state->stencil_front_fail = KINC_G4_STENCIL_KEEP;
state->stencil_back_mode = KINC_G4_COMPARE_ALWAYS;
state->stencil_back_both_pass = KINC_G4_STENCIL_KEEP;
state->stencil_back_depth_fail = KINC_G4_STENCIL_KEEP;
state->stencil_back_fail = KINC_G4_STENCIL_KEEP;
state->stencil_reference_value = 0;
state->stencil_read_mask = 0xff;
state->stencil_write_mask = 0xff;
state->blend_source = KINC_G4_BLEND_ONE;
state->blend_destination = KINC_G4_BLEND_ZERO;
state->blend_operation = KINC_G4_BLENDOP_ADD;
state->alpha_blend_source = KINC_G4_BLEND_ONE;
state->alpha_blend_destination = KINC_G4_BLEND_ZERO;
state->alpha_blend_operation = KINC_G4_BLENDOP_ADD;
for (int i = 0; i < 8; ++i)
state->color_write_mask_red[i] = true;
for (int i = 0; i < 8; ++i)
state->color_write_mask_green[i] = true;
for (int i = 0; i < 8; ++i)
state->color_write_mask_blue[i] = true;
for (int i = 0; i < 8; ++i)
state->color_write_mask_alpha[i] = true;
state->color_attachment_count = 1;
for (int i = 0; i < 8; ++i)
state->color_attachment[i] = KINC_G4_RENDER_TARGET_FORMAT_32BIT;
state->depth_attachment_bits = 0;
state->stencil_attachment_bits = 0;
state->conservative_rasterization = false;
}

View File

@ -0,0 +1,161 @@
#pragma once
#include <kinc/global.h>
#include <kinc/graphics4/constantlocation.h>
#include <kinc/graphics4/rendertarget.h>
#include <kinc/graphics4/textureunit.h>
#include <kinc/backend/graphics4/pipeline.h>
/*! \file pipeline.h
\brief Provides functions for creating and using pipelines which configure the GPU for rendering.
*/
#ifdef __cplusplus
extern "C" {
#endif
struct kinc_g4_vertex_structure;
struct kinc_g4_shader;
typedef enum {
KINC_G4_BLEND_ONE,
KINC_G4_BLEND_ZERO,
KINC_G4_BLEND_SOURCE_ALPHA,
KINC_G4_BLEND_DEST_ALPHA,
KINC_G4_BLEND_INV_SOURCE_ALPHA,
KINC_G4_BLEND_INV_DEST_ALPHA,
KINC_G4_BLEND_SOURCE_COLOR,
KINC_G4_BLEND_DEST_COLOR,
KINC_G4_BLEND_INV_SOURCE_COLOR,
KINC_G4_BLEND_INV_DEST_COLOR,
KINC_G4_BLEND_CONSTANT,
KINC_G4_BLEND_INV_CONSTANT
} kinc_g4_blending_factor_t;
typedef enum {
KINC_G4_BLENDOP_ADD,
KINC_G4_BLENDOP_SUBTRACT,
KINC_G4_BLENDOP_REVERSE_SUBTRACT,
KINC_G4_BLENDOP_MIN,
KINC_G4_BLENDOP_MAX
} kinc_g4_blending_operation_t;
typedef enum {
KINC_G4_COMPARE_ALWAYS,
KINC_G4_COMPARE_NEVER,
KINC_G4_COMPARE_EQUAL,
KINC_G4_COMPARE_NOT_EQUAL,
KINC_G4_COMPARE_LESS,
KINC_G4_COMPARE_LESS_EQUAL,
KINC_G4_COMPARE_GREATER,
KINC_G4_COMPARE_GREATER_EQUAL
} kinc_g4_compare_mode_t;
typedef enum { KINC_G4_CULL_CLOCKWISE, KINC_G4_CULL_COUNTER_CLOCKWISE, KINC_G4_CULL_NOTHING } kinc_g4_cull_mode_t;
typedef enum {
KINC_G4_STENCIL_KEEP,
KINC_G4_STENCIL_ZERO,
KINC_G4_STENCIL_REPLACE,
KINC_G4_STENCIL_INCREMENT,
KINC_G4_STENCIL_INCREMENT_WRAP,
KINC_G4_STENCIL_DECREMENT,
KINC_G4_STENCIL_DECREMENT_WRAP,
KINC_G4_STENCIL_INVERT
} kinc_g4_stencil_action_t;
typedef struct kinc_g4_pipeline {
struct kinc_g4_vertex_structure *input_layout[16];
struct kinc_g4_shader *vertex_shader;
struct kinc_g4_shader *fragment_shader;
struct kinc_g4_shader *geometry_shader;
struct kinc_g4_shader *tessellation_control_shader;
struct kinc_g4_shader *tessellation_evaluation_shader;
kinc_g4_cull_mode_t cull_mode;
bool depth_write;
kinc_g4_compare_mode_t depth_mode;
kinc_g4_compare_mode_t stencil_front_mode;
kinc_g4_stencil_action_t stencil_front_both_pass;
kinc_g4_stencil_action_t stencil_front_depth_fail;
kinc_g4_stencil_action_t stencil_front_fail;
kinc_g4_compare_mode_t stencil_back_mode;
kinc_g4_stencil_action_t stencil_back_both_pass;
kinc_g4_stencil_action_t stencil_back_depth_fail;
kinc_g4_stencil_action_t stencil_back_fail;
int stencil_reference_value;
int stencil_read_mask;
int stencil_write_mask;
// One, Zero deactivates blending
kinc_g4_blending_factor_t blend_source;
kinc_g4_blending_factor_t blend_destination;
kinc_g4_blending_operation_t blend_operation;
kinc_g4_blending_factor_t alpha_blend_source;
kinc_g4_blending_factor_t alpha_blend_destination;
kinc_g4_blending_operation_t alpha_blend_operation;
bool color_write_mask_red[8]; // Per render target
bool color_write_mask_green[8];
bool color_write_mask_blue[8];
bool color_write_mask_alpha[8];
int color_attachment_count;
kinc_g4_render_target_format_t color_attachment[8];
int depth_attachment_bits;
int stencil_attachment_bits;
bool conservative_rasterization;
kinc_g4_pipeline_impl_t impl;
} kinc_g4_pipeline_t;
/// <summary>
/// Initializes a pipeline.
/// </summary>
/// <param name="state">The pipeline to initialize</param>
KINC_FUNC void kinc_g4_pipeline_init(kinc_g4_pipeline_t *pipeline);
/// <summary>
/// Destroys a pipeline.
/// </summary>
/// <param name="pipeline">The pipeline to destroy</param>
KINC_FUNC void kinc_g4_pipeline_destroy(kinc_g4_pipeline_t *pipeline);
/// <summary>
/// Compiles a pipeline. After a pipeline has been compiled it is finalized. It cannot be compiled again and further changes to the pipeline are ignored.
/// </summary>
/// <param name="pipeline">The pipeline to compile</param>
KINC_FUNC void kinc_g4_pipeline_compile(kinc_g4_pipeline_t *pipeline);
#ifndef KINC_KONG
/// <summary>
/// Searches for a constant/uniform and returns a constant-location which can be used to change the constant/uniform.
/// </summary>
/// <param name="pipeline">The pipeline to search in</param>
/// <param name="name">The name of the constant/uniform to find</param>
/// <returns>The constant-location of the constant/uniform</returns>
KINC_FUNC kinc_g4_constant_location_t kinc_g4_pipeline_get_constant_location(kinc_g4_pipeline_t *pipeline, const char *name);
/// <summary>
/// Searches for a texture-declaration and returns a texture-unit which can be used to assign a texture.
/// </summary>
/// <param name="pipeline">The pipeline to search in</param>
/// <param name="name">The name of the texture-declaration to search for</param>
/// <returns>The texture-unit of the texture-declaration</returns>
KINC_FUNC kinc_g4_texture_unit_t kinc_g4_pipeline_get_texture_unit(kinc_g4_pipeline_t *pipeline, const char *name);
#endif
void kinc_g4_internal_set_pipeline(kinc_g4_pipeline_t *pipeline);
void kinc_g4_internal_pipeline_set_defaults(kinc_g4_pipeline_t *pipeline);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,11 @@
#include "rendertarget.h"
void kinc_g4_render_target_init(kinc_g4_render_target_t *renderTarget, int width, int height, kinc_g4_render_target_format_t format, int depthBufferBits,
int stencilBufferBits) {
kinc_g4_render_target_init_with_multisampling(renderTarget, width, height, format, depthBufferBits, stencilBufferBits, 1);
}
void kinc_g4_render_target_init_cube(kinc_g4_render_target_t *renderTarget, int cubeMapSize, kinc_g4_render_target_format_t format, int depthBufferBits,
int stencilBufferBits) {
kinc_g4_render_target_init_cube_with_multisampling(renderTarget, cubeMapSize, format, depthBufferBits, stencilBufferBits, 1);
}

View File

@ -0,0 +1,144 @@
#pragma once
#include <kinc/global.h>
#include <kinc/backend/graphics4/rendertarget.h>
#include "textureunit.h"
#include <stdint.h>
/*! \file rendertarget.h
\brief Provides functions for handling render-targets.
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef enum kinc_g4_render_target_format {
KINC_G4_RENDER_TARGET_FORMAT_32BIT,
KINC_G4_RENDER_TARGET_FORMAT_64BIT_FLOAT,
KINC_G4_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT,
KINC_G4_RENDER_TARGET_FORMAT_128BIT_FLOAT,
KINC_G4_RENDER_TARGET_FORMAT_16BIT_DEPTH,
KINC_G4_RENDER_TARGET_FORMAT_8BIT_RED,
KINC_G4_RENDER_TARGET_FORMAT_16BIT_RED_FLOAT
} kinc_g4_render_target_format_t;
typedef struct kinc_g4_render_target {
int width;
int height;
int texWidth;
int texHeight;
bool isCubeMap;
bool isDepthAttachment;
kinc_g4_render_target_impl_t impl;
} kinc_g4_render_target_t;
/// <summary>
/// Allocates and initializes a regular render-target. The contents of the render-target are undefined.
/// </summary>
/// <param name="renderTarget"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="format"></param>
/// <param name="depthBufferBits"></param>
/// <param name="stencilBufferBits"></param>
KINC_FUNC void kinc_g4_render_target_init(kinc_g4_render_target_t *renderTarget, int width, int height, kinc_g4_render_target_format_t format,
int depthBufferBits, int stencilBufferBits);
/// <summary>
/// Allocates and initializes a multi-sampled render-target if possible - otherwise it falls back to a regular render-target. The contents of the render-target
/// are undefined.
/// </summary>
/// <param name="renderTarget"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="format"></param>
/// <param name="depthBufferBits"></param>
/// <param name="stencilBufferBits"></param>
/// <param name="samples_per_pixel"></param>
KINC_FUNC void kinc_g4_render_target_init_with_multisampling(kinc_g4_render_target_t *renderTarget, int width, int height,
kinc_g4_render_target_format_t format, int depthBufferBits, int stencilBufferBits,
int samples_per_pixel);
/// <summary>
/// Allocates and initializes a render-target-cube-map. The contents of the render-target are undefined.
/// </summary>
/// <param name="renderTarget"></param>
/// <param name="cubeMapSize"></param>
/// <param name="format"></param>
/// <param name="depthBufferBits"></param>
/// <param name="stencilBufferBits"></param>
KINC_FUNC void kinc_g4_render_target_init_cube(kinc_g4_render_target_t *renderTarget, int cubeMapSize, kinc_g4_render_target_format_t format,
int depthBufferBits, int stencilBufferBits);
/// <summary>
/// Allocates and initializes a multi-sampled render-target-cube-map. Can fall back to a non-multi-sampled cube-map. The contents of the render-target are
/// undefined.
/// </summary>
/// <param name="renderTarget"></param>
/// <param name="cubeMapSize"></param>
/// <param name="format"></param>
/// <param name="depthBufferBits"></param>
/// <param name="stencilBufferBits"></param>
/// <param name="samples_per_pixel"></param>
KINC_FUNC void kinc_g4_render_target_init_cube_with_multisampling(kinc_g4_render_target_t *renderTarget, int cubeMapSize, kinc_g4_render_target_format_t format,
int depthBufferBits, int stencilBufferBits, int samples_per_pixel);
/// <summary>
/// Deallocates and destroys a render-target.
/// </summary>
/// <param name="renderTarget">The render-target to destroy</param>
KINC_FUNC void kinc_g4_render_target_destroy(kinc_g4_render_target_t *renderTarget);
#ifdef KINC_KONG
/// <summary>
/// Uses the color-component of a render-target as a texture.
/// </summary>
/// <param name="renderTarget">The render-target to use</param>
/// <param name="unit">The texture-unit to assign the render-target to</param>
KINC_FUNC void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, uint32_t unit);
#else
/// <summary>
/// Uses the color-component of a render-target as a texture.
/// </summary>
/// <param name="renderTarget">The render-target to use</param>
/// <param name="unit">The texture-unit to assign the render-target to</param>
KINC_FUNC void kinc_g4_render_target_use_color_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit);
#endif
/// <summary>
/// Uses the depth-component of a render-target as a texture.
/// </summary>
/// <param name="renderTarget">The render-target to use</param>
/// <param name="unit">The texture-unit to assign the render-target to</param>
KINC_FUNC void kinc_g4_render_target_use_depth_as_texture(kinc_g4_render_target_t *renderTarget, kinc_g4_texture_unit_t unit);
/// <summary>
/// Copies the depth and stencil-components of one render-target into another one.
/// </summary>
/// <param name="renderTarget">The render-target to copy the data into</param>
/// <param name="source">The render-target from which to copy the data</param>
/// <returns></returns>
KINC_FUNC void kinc_g4_render_target_set_depth_stencil_from(kinc_g4_render_target_t *renderTarget, kinc_g4_render_target_t *source);
/// <summary>
/// Copies out the color-data from a render-target. Beware, this is very slow.
/// </summary>
/// <param name="renderTarget">The render-target to copy the color-data from</param>
/// <param name="data">A pointer to where the data will be copied to</param>
KINC_FUNC void kinc_g4_render_target_get_pixels(kinc_g4_render_target_t *renderTarget, uint8_t *data);
/// <summary>
/// Generates the mipmap-chain for a render-target.
/// </summary>
/// <param name="renderTarget">The render-target to create the mipmaps for</param>
/// <param name="levels">The number of mipmap-levels to generate</param>
KINC_FUNC void kinc_g4_render_target_generate_mipmaps(kinc_g4_render_target_t *renderTarget, int levels);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,58 @@
#pragma once
#include <kinc/global.h>
#include <kinc/backend/graphics4/shader.h>
/*! \file shader.h
\brief Provides functions for creating and destroying shaders.
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef enum kinc_g4_shader_type {
KINC_G4_SHADER_TYPE_FRAGMENT,
KINC_G4_SHADER_TYPE_VERTEX,
KINC_G4_SHADER_TYPE_COMPUTE,
KINC_G4_SHADER_TYPE_GEOMETRY,
KINC_G4_SHADER_TYPE_TESSELLATION_CONTROL,
KINC_G4_SHADER_TYPE_TESSELLATION_EVALUATION,
KINC_G4_SHADER_TYPE_COUNT
} kinc_g4_shader_type_t;
typedef struct kinc_g4_shader {
kinc_g4_shader_impl_t impl;
} kinc_g4_shader_t;
/// <summary>
/// Initializes a shader based on system-specific shader-data. The system-specific shader-data is usually created per system by the krafix-shader-compiler which
/// is automatically called by kincmake.
/// </summary>
/// <param name="shader">The shader to initialize</param>
/// <param name="data">The system-specific shader-data</param>
/// <param name="length">The length of the system-specific shader-data in bytes</param>
/// <param name="type">The type of the shader</param>
KINC_FUNC void kinc_g4_shader_init(kinc_g4_shader_t *shader, const void *data, size_t length, kinc_g4_shader_type_t type);
/// <summary>
/// Initializes a shader from GLSL-source-code. This only works on some platforms and only if KRAFIX_LIBRARY define has been set and the krafix-shader-compiler
/// was compiled in library-mode and linked into the application.
/// </summary>
/// <param name="shader">The shader to initialize</param>
/// <param name="source">The GLSL-shader-source-code</param>
/// <param name="type">The type of the shader</param>
/// <returns>The number of errors the compiler encountered - hopefully it's zero.</returns>
KINC_FUNC int kinc_g4_shader_init_from_source(kinc_g4_shader_t *shader, const char *source, kinc_g4_shader_type_t type);
/// <summary>
/// Destroys a shader.
/// </summary>
/// <param name="shader">The shader to destroy</param>
KINC_FUNC void kinc_g4_shader_destroy(kinc_g4_shader_t *shader);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,106 @@
#pragma once
#include <kinc/global.h>
#include <kinc/backend/graphics4/texture.h>
#include <kinc/image.h>
/*! \file texture.h
\brief Provides functions for handling textures.
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef kinc_image_t kinc_g4_image_t;
typedef struct kinc_g4_texture {
int tex_width;
int tex_height;
int tex_depth;
kinc_image_format_t format;
kinc_g4_texture_impl_t impl;
} kinc_g4_texture_t;
/// <summary>
/// Allocates and initializes a texture without copying any data into it.
/// </summary>
/// <param name="texture">The texture to initialize</param>
/// <param name="width">The width of the texture to create</param>
/// <param name="height">The height of the texture to create</param>
/// <param name="format">The format of the texture to create</param>
KINC_FUNC void kinc_g4_texture_init(kinc_g4_texture_t *texture, int width, int height, kinc_image_format_t format);
/// <summary>
/// Allocates and initializes a 3d-texture without copying any data into it.
/// </summary>
/// <param name="texture">The texture to initialize</param>
/// <param name="width">The width of the texture to create</param>
/// <param name="height">The height of the texture to create</param>
/// <param name="depth">The depth of the texture to create</param>
/// <param name="format">The format of the texture to create</param>
KINC_FUNC void kinc_g4_texture_init3d(kinc_g4_texture_t *texture, int width, int height, int depth, kinc_image_format_t format);
/// <summary>
/// Allocates and initializes a texture and copies image-data into it.
/// </summary>
/// <param name="texture">The texture to initialize</param>
/// <param name="image">The image which's data is copied into the texture</param>
KINC_FUNC void kinc_g4_texture_init_from_image(kinc_g4_texture_t *texture, kinc_image_t *image);
/// <summary>
/// Allocates and initializes a texture and copies image-data into it.
/// </summary>
/// <param name="texture">The texture to initialize</param>
/// <param name="image">The image which's data is copied into the texture</param>
KINC_FUNC void kinc_g4_texture_init_from_image3d(kinc_g4_texture_t *texture, kinc_image_t *image);
/// <summary>
/// Deallocates and destroys a texture.
/// </summary>
/// <param name="texture">The texture to destroy</param>
KINC_FUNC void kinc_g4_texture_destroy(kinc_g4_texture_t *texture);
KINC_FUNC unsigned char *kinc_g4_texture_lock(kinc_g4_texture_t *texture);
KINC_FUNC void kinc_g4_texture_unlock(kinc_g4_texture_t *texture);
/// <summary>
/// Clears parts of a texture to a color.
/// </summary>
KINC_FUNC void kinc_g4_texture_clear(kinc_g4_texture_t *texture, int x, int y, int z, int width, int height, int depth, unsigned color);
/// <summary>
/// Generates the mipmap-chain for a texture.
/// </summary>
/// <param name="renderTarget">The render-target to create the mipmaps for</param>
/// <param name="levels">The number of mipmap-levels to generate</param>
KINC_FUNC void kinc_g4_texture_generate_mipmaps(kinc_g4_texture_t *texture, int levels);
/// <summary>
/// Sets the mipmap for one level of a texture.
/// </summary>
/// <param name="texture">The texture to set a mipmap-level for</param>
/// <param name="mipmap">The image-data for the mipmap-level to set</param>
/// <param name="level">The mipmap-level to set</param>
KINC_FUNC void kinc_g4_texture_set_mipmap(kinc_g4_texture_t *texture, kinc_image_t *mipmap, int level);
/// <summary>
/// Returns the stride of the first mipmap-layer of the texture in bytes.
/// </summary>
/// <param name="texture">The texture to figure out the stride for</param>
/// <returns>The stride of the first mipmap-layer in bytes</returns>
KINC_FUNC int kinc_g4_texture_stride(kinc_g4_texture_t *texture);
#ifdef KINC_ANDROID
KINC_FUNC void kinc_g4_texture_init_from_id(kinc_g4_texture_t *texture, unsigned texid);
#endif
#if defined(KINC_IOS) || defined(KINC_MACOS)
KINC_FUNC void kinc_g4_texture_upload(kinc_g4_texture_t *texture, uint8_t *data, int stride);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,37 @@
#pragma once
#include <kinc/global.h>
#include "texture.h"
#include <kinc/backend/graphics4/texturearray.h>
/*! \file texturearray.h
\brief Provides functions for creating and destroying texture-arrays.
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef struct kinc_g4_texture_array {
kinc_g4_texture_array_impl_t impl;
} kinc_g4_texture_array_t;
/// <summary>
/// Allocates and initializes a texture-array based on an array of images.
/// </summary>
/// <param name="array">The texture-array to initialize</param>
/// <param name="images">The images to assign to the texture-array</param>
/// <param name="count">The number of images</param>
KINC_FUNC void kinc_g4_texture_array_init(kinc_g4_texture_array_t *array, kinc_image_t *images, int count);
/// <summary>
/// Deallocates and destroys a texture-array
/// </summary>
/// <param name="array">The texture-array to destroy</param>
KINC_FUNC void kinc_g4_texture_array_destroy(kinc_g4_texture_array_t *array);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,21 @@
#pragma once
#include <kinc/global.h>
#include <kinc/graphics4/shader.h>
/*! \file textureunit.h
\brief Provides a texture-unit-struct which is used for setting textures in a shader.
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef struct kinc_g4_texture_unit {
int stages[KINC_G4_SHADER_TYPE_COUNT];
} kinc_g4_texture_unit_t;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,15 @@
#pragma once
/*! \file usage.h
\brief Provides the usage enum.
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef enum kinc_g4_usage { KINC_G4_USAGE_STATIC, KINC_G4_USAGE_DYNAMIC, KINC_G4_USAGE_READABLE } kinc_g4_usage_t;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,20 @@
#include "vertexbuffer.h"
static void init_vertex_element(kinc_g4_vertex_element_t *element, const char *name, kinc_g4_vertex_data_t data) {
element->name = name;
element->data = data;
}
void kinc_g4_vertex_structure_init(kinc_g4_vertex_structure_t *structure) {
structure->size = 0;
structure->instanced = false;
}
void kinc_g4_vertex_structure_add(kinc_g4_vertex_structure_t *structure, const char *name, kinc_g4_vertex_data_t data) {
init_vertex_element(&structure->elements[structure->size++], name, data);
}
void kinc_g4_set_vertex_buffer(kinc_g4_vertex_buffer_t *buffer) {
kinc_g4_vertex_buffer_t *buffers[1] = {buffer};
kinc_g4_set_vertex_buffers(buffers, 1);
}

View File

@ -0,0 +1,101 @@
#pragma once
#include <kinc/global.h>
#include "usage.h"
#include "vertexstructure.h"
#include <kinc/backend/graphics4/vertexbuffer.h>
#include <stdbool.h>
/*! \file vertexbuffer.h
\brief Provides functions for setting up and using vertex-buffers.
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef struct kinc_g4_vertex_buffer {
kinc_g4_vertex_buffer_impl_t impl;
} kinc_g4_vertex_buffer_t;
/// <summary>
/// Allocate and initialize a vertex-buffer.
/// </summary>
/// <param name="buffer">The buffer to initialize</param>
/// <param name="count">The number of vertices in the buffer</param>
/// <param name="structure">The structure of the buffer</param>
/// <param name="usage">A hint for how the buffer will be used</param>
/// <param name="instance_data_step_rate">The step-rate for instanced-rendering - use 0 if instanced-rendering will not be used with this buffer</param>
KINC_FUNC void kinc_g4_vertex_buffer_init(kinc_g4_vertex_buffer_t *buffer, int count, kinc_g4_vertex_structure_t *structure, kinc_g4_usage_t usage,
int instance_data_step_rate);
/// <summary>
/// Destroys a vertex-buffer.
/// </summary>
/// <param name="buffer">The buffer to destroy</param>
KINC_FUNC void kinc_g4_vertex_buffer_destroy(kinc_g4_vertex_buffer_t *buffer);
/// <summary>
/// Locks all of a vertex-buffer to modify its contents.
/// </summary>
/// <param name="buffer">The buffer to lock</param>
/// <returns>The contents of the buffer</returns>
KINC_FUNC float *kinc_g4_vertex_buffer_lock_all(kinc_g4_vertex_buffer_t *buffer);
/// <summary>
/// Locks part of a vertex-buffer to modify its contents.
/// </summary>
/// <param name="buffer">The buffer to lock</param>
/// <param name="start">The index of the first vertex to lock</param>
/// <param name="count">The number of vertices to lock</param>
/// <returns>The contents of the buffer, starting at start</returns>
KINC_FUNC float *kinc_g4_vertex_buffer_lock(kinc_g4_vertex_buffer_t *buffer, int start, int count);
/// <summary>
/// Unlock all of a vertex-buffer so the changed contents can be used.
/// </summary>
/// <param name="buffer">The buffer to unlock</param>
KINC_FUNC void kinc_g4_vertex_buffer_unlock_all(kinc_g4_vertex_buffer_t *buffer);
/// <summary>
/// Unlocks part of a vertex-buffer so the changed contents can be used.
/// </summary>
/// <param name="buffer">The buffer to unlock</param>
/// <param name="count">The number of vertices to unlock, starting from the start-vertex from the previous lock-call</param>
KINC_FUNC void kinc_g4_vertex_buffer_unlock(kinc_g4_vertex_buffer_t *buffer, int count);
/// <summary>
/// Returns the number of vertices in a buffer.
/// </summary>
/// <param name="buffer">The buffer to figure out the number of vertices for</param>
/// <returns>The number of vertices</returns>
KINC_FUNC int kinc_g4_vertex_buffer_count(kinc_g4_vertex_buffer_t *buffer);
/// <summary>
/// Returns the stride aka the size of one vertex of the buffer in bytes.
/// </summary>
/// <param name="buffer">The buffer to figure out the stride for</param>
/// <returns>The stride of the buffer in bytes</returns>
KINC_FUNC int kinc_g4_vertex_buffer_stride(kinc_g4_vertex_buffer_t *buffer);
int kinc_internal_g4_vertex_buffer_set(kinc_g4_vertex_buffer_t *buffer, int offset);
/// <summary>
/// Sets vertex-buffers for the next draw-call.
/// </summary>
/// <param name="buffers">The buffers to set</param>
/// <param name="count">The number of buffers to set</param>
KINC_FUNC void kinc_g4_set_vertex_buffers(kinc_g4_vertex_buffer_t **buffers, int count);
/// <summary>
/// Sets a vertex-buffer for the next draw-call.
/// </summary>
/// <param name="buffer">The buffer to set</param>
KINC_FUNC void kinc_g4_set_vertex_buffer(kinc_g4_vertex_buffer_t *buffer);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,157 @@
#pragma once
#include <kinc/global.h>
#include <stdbool.h>
/*! \file vertexstructure.h
\brief Provides functions for setting up the structure of vertices in a vertex-buffer.
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef enum kinc_g4_vertex_data {
KINC_G4_VERTEX_DATA_NONE = 0,
KINC_G4_VERTEX_DATA_F32_1X = 1,
KINC_G4_VERTEX_DATA_F32_2X = 2,
KINC_G4_VERTEX_DATA_F32_3X = 3,
KINC_G4_VERTEX_DATA_F32_4X = 4,
KINC_G4_VERTEX_DATA_F32_4X4 = 5,
KINC_G4_VERTEX_DATA_I8_1X = 6,
KINC_G4_VERTEX_DATA_U8_1X = 7,
KINC_G4_VERTEX_DATA_I8_1X_NORMALIZED = 8,
KINC_G4_VERTEX_DATA_U8_1X_NORMALIZED = 9,
KINC_G4_VERTEX_DATA_I8_2X = 10,
KINC_G4_VERTEX_DATA_U8_2X = 11,
KINC_G4_VERTEX_DATA_I8_2X_NORMALIZED = 12,
KINC_G4_VERTEX_DATA_U8_2X_NORMALIZED = 13,
KINC_G4_VERTEX_DATA_I8_4X = 14,
KINC_G4_VERTEX_DATA_U8_4X = 15,
KINC_G4_VERTEX_DATA_I8_4X_NORMALIZED = 16,
KINC_G4_VERTEX_DATA_U8_4X_NORMALIZED = 17,
KINC_G4_VERTEX_DATA_I16_1X = 18,
KINC_G4_VERTEX_DATA_U16_1X = 19,
KINC_G4_VERTEX_DATA_I16_1X_NORMALIZED = 20,
KINC_G4_VERTEX_DATA_U16_1X_NORMALIZED = 21,
KINC_G4_VERTEX_DATA_I16_2X = 22,
KINC_G4_VERTEX_DATA_U16_2X = 23,
KINC_G4_VERTEX_DATA_I16_2X_NORMALIZED = 24,
KINC_G4_VERTEX_DATA_U16_2X_NORMALIZED = 25,
KINC_G4_VERTEX_DATA_I16_4X = 26,
KINC_G4_VERTEX_DATA_U16_4X = 27,
KINC_G4_VERTEX_DATA_I16_4X_NORMALIZED = 28,
KINC_G4_VERTEX_DATA_U16_4X_NORMALIZED = 29,
KINC_G4_VERTEX_DATA_I32_1X = 30,
KINC_G4_VERTEX_DATA_U32_1X = 31,
KINC_G4_VERTEX_DATA_I32_2X = 32,
KINC_G4_VERTEX_DATA_U32_2X = 33,
KINC_G4_VERTEX_DATA_I32_3X = 34,
KINC_G4_VERTEX_DATA_U32_3X = 35,
KINC_G4_VERTEX_DATA_I32_4X = 36,
KINC_G4_VERTEX_DATA_U32_4X = 37,
// deprecated
KINC_G4_VERTEX_DATA_FLOAT1 = KINC_G4_VERTEX_DATA_F32_1X,
KINC_G4_VERTEX_DATA_FLOAT2 = KINC_G4_VERTEX_DATA_F32_2X,
KINC_G4_VERTEX_DATA_FLOAT3 = KINC_G4_VERTEX_DATA_F32_3X,
KINC_G4_VERTEX_DATA_FLOAT4 = KINC_G4_VERTEX_DATA_F32_4X,
KINC_G4_VERTEX_DATA_FLOAT4X4 = KINC_G4_VERTEX_DATA_F32_4X4,
KINC_G4_VERTEX_DATA_SHORT2_NORM = KINC_G4_VERTEX_DATA_I16_2X_NORMALIZED,
KINC_G4_VERTEX_DATA_SHORT4_NORM = KINC_G4_VERTEX_DATA_I16_4X_NORMALIZED,
KINC_G4_VERTEX_DATA_COLOR = KINC_G4_VERTEX_DATA_U8_4X_NORMALIZED
} kinc_g4_vertex_data_t;
static inline int kinc_g4_vertex_data_size(kinc_g4_vertex_data_t data) {
switch (data) {
default:
case KINC_G4_VERTEX_DATA_NONE:
return 0;
case KINC_G4_VERTEX_DATA_F32_1X:
return 1 * 4;
case KINC_G4_VERTEX_DATA_F32_2X:
return 2 * 4;
case KINC_G4_VERTEX_DATA_F32_3X:
return 3 * 4;
case KINC_G4_VERTEX_DATA_F32_4X:
return 4 * 4;
case KINC_G4_VERTEX_DATA_F32_4X4:
return 4 * 4 * 4;
case KINC_G4_VERTEX_DATA_I8_1X:
case KINC_G4_VERTEX_DATA_U8_1X:
case KINC_G4_VERTEX_DATA_I8_1X_NORMALIZED:
case KINC_G4_VERTEX_DATA_U8_1X_NORMALIZED:
return 1 * 1;
case KINC_G4_VERTEX_DATA_I8_2X:
case KINC_G4_VERTEX_DATA_U8_2X:
case KINC_G4_VERTEX_DATA_I8_2X_NORMALIZED:
case KINC_G4_VERTEX_DATA_U8_2X_NORMALIZED:
return 2 * 1;
case KINC_G4_VERTEX_DATA_I8_4X:
case KINC_G4_VERTEX_DATA_U8_4X:
case KINC_G4_VERTEX_DATA_I8_4X_NORMALIZED:
case KINC_G4_VERTEX_DATA_U8_4X_NORMALIZED:
return 4 * 1;
case KINC_G4_VERTEX_DATA_I16_1X:
case KINC_G4_VERTEX_DATA_U16_1X:
case KINC_G4_VERTEX_DATA_I16_1X_NORMALIZED:
case KINC_G4_VERTEX_DATA_U16_1X_NORMALIZED:
return 1 * 2;
case KINC_G4_VERTEX_DATA_I16_2X:
case KINC_G4_VERTEX_DATA_U16_2X:
case KINC_G4_VERTEX_DATA_I16_2X_NORMALIZED:
case KINC_G4_VERTEX_DATA_U16_2X_NORMALIZED:
return 2 * 2;
case KINC_G4_VERTEX_DATA_I16_4X:
case KINC_G4_VERTEX_DATA_U16_4X:
case KINC_G4_VERTEX_DATA_I16_4X_NORMALIZED:
case KINC_G4_VERTEX_DATA_U16_4X_NORMALIZED:
return 4 * 2;
case KINC_G4_VERTEX_DATA_I32_1X:
case KINC_G4_VERTEX_DATA_U32_1X:
return 1 * 4;
case KINC_G4_VERTEX_DATA_I32_2X:
case KINC_G4_VERTEX_DATA_U32_2X:
return 2 * 4;
case KINC_G4_VERTEX_DATA_I32_3X:
case KINC_G4_VERTEX_DATA_U32_3X:
return 3 * 4;
case KINC_G4_VERTEX_DATA_I32_4X:
case KINC_G4_VERTEX_DATA_U32_4X:
return 4 * 4;
}
}
typedef struct kinc_g4_vertex_element {
const char *name;
kinc_g4_vertex_data_t data;
} kinc_g4_vertex_element_t;
#define KINC_G4_MAX_VERTEX_ELEMENTS 16
typedef struct kinc_g4_vertex_structure {
kinc_g4_vertex_element_t elements[KINC_G4_MAX_VERTEX_ELEMENTS];
int size;
bool instanced;
} kinc_g4_vertex_structure_t;
/// <summary>
/// Initializes a vertex-structure.
/// </summary>
/// <param name="structure">The structure to initialize</param>
/// <returns></returns>
KINC_FUNC void kinc_g4_vertex_structure_init(kinc_g4_vertex_structure_t *structure);
/// <summary>
/// Adds an element to a vertex-structure.
/// </summary>
/// <param name="structure">The structure to add an element to</param>
/// <param name="name">The name to use for the new element</param>
/// <param name="data">The type of data to assign for the new element</param>
/// <returns></returns>
KINC_FUNC void kinc_g4_vertex_structure_add(kinc_g4_vertex_structure_t *structure, const char *name, kinc_g4_vertex_data_t data);
#ifdef __cplusplus
}
#endif