217 lines
5.3 KiB
C
217 lines
5.3 KiB
C
#pragma once
|
|
|
|
#include<stddef.h>
|
|
#include<stdint.h>
|
|
#include<cglm/vec3.h>
|
|
#include<cglm/mat4.h>
|
|
#include<cglm/quat.h>
|
|
#include"k3anim.h"
|
|
|
|
#ifdef k3_MULTITHREAD
|
|
#include<pthread.h>
|
|
#endif
|
|
|
|
void k3Init(bool tc, bool mipmap);
|
|
void k3Resize(uint16_t width, uint16_t height);
|
|
void k3Update();
|
|
|
|
enum k3TexType {
|
|
k3_DIFFUSE, k3_NORMAL, k3_DISPLACEMENT, k3_EMISSION, k3_ROUGHNESS, k3_ALPHA,
|
|
k3_DEPTH,
|
|
k3_CUBEMAP,
|
|
k3_RAWCOLOR,
|
|
};
|
|
|
|
struct k3Tex;
|
|
struct k3Tex *k3TexCreate(enum k3TexType type);
|
|
void k3TexUpdate(struct k3Tex*, enum k3TexType type, int index, uint16_t width, uint16_t height, void *data);
|
|
uint32_t k3TexSzX(struct k3Tex*);
|
|
uint32_t k3TexSzY(struct k3Tex*);
|
|
uint32_t k3TexSzZ(struct k3Tex*);
|
|
|
|
struct k3GLSLV;
|
|
struct k3GLSLV *k3ShaderGLSLV(const char *src_, const char*(*ldr)(const char *fn));
|
|
|
|
struct k3GLSLF;
|
|
struct k3GLSLF *k3ShaderGLSLF(const char *src_, const char*(*ldr)(const char *fn));
|
|
|
|
struct k3GLSLG;
|
|
struct k3GLSLG *k3ShaderGLSLG(const char *src_, const char*(*ldr)(const char *fn));
|
|
|
|
struct k3GLSLP;
|
|
struct k3GLSLP *k3ProgramGLSL(struct k3GLSLV*, struct k3GLSLF*, struct k3GLSLG*);
|
|
uint16_t k3ProgramGetUId(struct k3GLSLP*, const char *key);
|
|
|
|
struct k3ARBVP;
|
|
struct k3ARBVP *k3ProgramARBVP(const char *src);
|
|
|
|
struct k3ARBFP;
|
|
struct k3ARBFP *k3ProgramARBFP(const char *src);
|
|
|
|
extern uint8_t k3GraphicalReduction;
|
|
extern bool k3IsCore;
|
|
extern bool k3IsSoftSkinning;
|
|
|
|
struct k3Mat {
|
|
struct {
|
|
vec4 diffuse;
|
|
vec4 specular;
|
|
vec4 emission;
|
|
float shininess;
|
|
} primitive;
|
|
struct {
|
|
struct {
|
|
struct k3ARBVP *vp;
|
|
} arbvp;
|
|
struct {
|
|
struct k3ARBFP *fp;
|
|
} arbfp;
|
|
struct {
|
|
struct k3GLSLP *hp;
|
|
|
|
#ifdef k3_IRREGULAR_SHADOWS
|
|
struct k3GLSLP *hpIrreg1;
|
|
struct k3GLSLP *hpIrreg2;
|
|
#endif
|
|
|
|
uint8_t uCount;
|
|
struct {
|
|
char name[16];
|
|
int8_t id;
|
|
#define k3_MAT_UNIFORM_I1 0
|
|
#define k3_MAT_UNIFORM_F1 4
|
|
uint8_t type;
|
|
union {
|
|
int i1;
|
|
float f1;
|
|
};
|
|
#define k3_MAX_GLSL_UNIFORMS 8
|
|
} u[k3_MAX_GLSL_UNIFORMS];
|
|
} glsl;
|
|
|
|
#define k3_MAX_GLSL_UNITS 8
|
|
struct k3Tex *units[k3_MAX_GLSL_UNITS];
|
|
int unitsUsed;
|
|
|
|
float aabb;
|
|
char additive;
|
|
char transparent;
|
|
char nocull;
|
|
char alphatest;
|
|
char depthwrite;
|
|
} passes[1];
|
|
};
|
|
|
|
struct k3Animator {
|
|
struct k3Mdl *mdl;
|
|
|
|
struct k3AnimationBone *bones;
|
|
|
|
struct k3Animation *anim;
|
|
|
|
double time;
|
|
|
|
bool playing;
|
|
double playStartTime;
|
|
};
|
|
|
|
struct k3Offscreen;
|
|
|
|
enum k3LightType {
|
|
k3_DIRECTIONAL,
|
|
k3_SPOT,
|
|
k3_OMNI,
|
|
k3_HALF_OMNI,
|
|
k3_AMBIENT,
|
|
};
|
|
struct k3Light {
|
|
enum k3LightType type;
|
|
_Alignas(16) int castShadow;
|
|
_Alignas(16) vec4 color;
|
|
_Alignas(16) float radius;
|
|
_Alignas(16) union {
|
|
struct {
|
|
vec4 direction;
|
|
uint8_t cascadeCount;
|
|
} dir;
|
|
struct {
|
|
vec4 position;
|
|
vec4 direction;
|
|
float angle;
|
|
} spot;
|
|
struct {
|
|
vec4 position;
|
|
} omni;
|
|
};
|
|
};
|
|
|
|
struct k3Mesh {
|
|
uint16_t idxStart, idxNumber;
|
|
struct k3Mat mat;
|
|
};
|
|
|
|
struct k3Storage;
|
|
void k3StorageRef(struct k3Storage*);
|
|
void k3StorageUnref(struct k3Storage*);
|
|
|
|
#define k3_ATTRIB_NONE (NULL)
|
|
#define k3_ATTRIB_EMPTY ((void*) 1)
|
|
struct k3Mdl;
|
|
struct k3Mdl *k3MdlCreate(size_t verts, size_t indices, size_t boneCount, vec3 *pos, uint8_t *nrm, float *uvs, uint8_t *cols, uint8_t *boneids, uint16_t *boneweights, uint16_t *inds, mat4 *invBind, uint8_t *boneParents);
|
|
void k3MdlUpdatePos(struct k3Mdl *mdl, vec3 *pos);
|
|
void k3MdlAddMesh(struct k3Mdl*, struct k3Mat*, uint16_t idxStart, uint16_t idxNumber);
|
|
struct k3Mesh *k3MdlGetMeshes(struct k3Mdl*, size_t *count);
|
|
void k3MdlAddAnim(struct k3Mdl*, struct k3AnimationFountain*);
|
|
struct k3AnimationFountain *k3MdlGetAnim(struct k3Mdl*, uint16_t id);
|
|
size_t k3MdlGetBoneCount(struct k3Mdl*);
|
|
struct k3Mdl *k3MdlCopySubs(struct k3Mdl*);
|
|
void k3MdlSetDebugName(struct k3Mdl*, const char*);
|
|
void k3MdlQueryWeights(struct k3Mdl*, size_t bone, float *output);
|
|
intmax_t k3MdlGetBoneFromName(struct k3Mdl*, const char*);
|
|
void k3MdlSetBoneNames(struct k3Mdl*, const char*);
|
|
|
|
void k3AnimatorInit(struct k3Animator*, struct k3Mdl*);
|
|
void k3AnimatorSet(struct k3Animator*, float);
|
|
void k3AnimatorStep(struct k3Animator*, float);
|
|
|
|
void k3SetLights(size_t, struct k3Light*);
|
|
struct k3Light *k3GetLights(size_t*);
|
|
|
|
void k3Clear();
|
|
|
|
void k3Batch(struct k3Mdl*, mat4, struct k3AnimationBone* bones);
|
|
void k3BatchClear();
|
|
|
|
void k3PassForward(mat4 projection, mat4 cam);
|
|
void k3PassDepthOnly(mat4 projection, mat4 cam, int clear, int cull);
|
|
|
|
void k3PassShadowmap(mat4 projection, mat4 cam, struct k3Offscreen *offscr);
|
|
|
|
struct k3Offscreen;
|
|
struct k3Offscreen *k3OffscreenCreateMultisampled(struct k3Tex *diffuse, struct k3Tex *depth, uint8_t samples);
|
|
struct k3Offscreen *k3OffscreenCreate(struct k3Tex *diffuse, struct k3Tex *depth);
|
|
void k3BeginOffscreen(struct k3Offscreen*);
|
|
void k3EndOffscreen(struct k3Offscreen*);
|
|
void k3OffscreenDestroy(struct k3Offscreen*);
|
|
|
|
#define k3_NONE 0
|
|
#define k3_GLSL 1
|
|
#define k3_ARBFRAG 2
|
|
void k3BlitToScreenEffect(struct k3Offscreen *offscr, int additive, int effect, void *program, void *params);
|
|
void k3BlitToScreen(struct k3Offscreen *offscr, int additive);
|
|
|
|
int k3CubemapTraditional(struct k3Tex*, mat4 proj, mat4 cam);
|
|
|
|
void k3SetTime(float t);
|
|
|
|
enum k3LogLevel {
|
|
k3_DEBUG, k3_INFO, k3_WARN, k3_ERR
|
|
};
|
|
typedef void(*k3LogCallback)(enum k3LogLevel, const char *str, size_t len);
|
|
void k3SetLogCallback(k3LogCallback);
|
|
void k3Log(enum k3LogLevel, const char *format, ...);
|
|
|
|
uint16_t k3TexSzMax();
|
|
|
|
void k3PassIrregular(struct k3Offscreen *main, mat4 mainproj, mat4 maincam);
|