1. k3Update added, which must be called per frame. 2. Added GPU timers for profiling. 3. Added ARB_direct_state_access support because Mesa is being a bitch again. 4. Cached uniform locations in an open-addressing hash table. Unfortunately, I'm pretty sure there was no performance increase, at least on my development machine, but it shouldn't hurt anywhere else.
137 lines
2.3 KiB
C
137 lines
2.3 KiB
C
#pragma once
|
|
|
|
#include"k3.h"
|
|
|
|
#include"gl.h"
|
|
|
|
#include<cglm/vec2.h>
|
|
#include<cglm/frustum.h>
|
|
#include<cglm/cam.h>
|
|
#include<string.h>
|
|
|
|
#define GL_FROM_K3TEX(k3t) ((k3t) ? (k3t)->tex : 0)
|
|
#define GL_FROM_K3MARCHER(k3m) ((GLuint) (uintptr_t) (k3m))
|
|
#define GL_FROM_K3ARBVP(k3m) ((GLuint) (uintptr_t) (k3m))
|
|
#define GL_FROM_K3ARBFP(k3m) ((GLuint) (uintptr_t) (k3m))
|
|
#define GL_FROM_K3GLSL(k3m) (((struct k3GLSLP*) k3m)->handle)
|
|
|
|
extern bool k3IsCore;
|
|
|
|
struct k3Tex {
|
|
GLuint tex;
|
|
int cubemap;
|
|
uint32_t szX;
|
|
uint32_t szY;
|
|
uint32_t szZ;
|
|
GLuint glInternalFormat;
|
|
GLuint glExternalFormat;
|
|
GLuint glInType;
|
|
bool mipmap;
|
|
|
|
// Asynchronous decoding
|
|
uint8_t deferredRemaining;
|
|
uint8_t *deferredData[6];
|
|
struct k3Tex *deferredNext;
|
|
};
|
|
|
|
struct k3Storage {
|
|
int16_t ref;
|
|
void(*free)(struct k3Storage*);
|
|
};
|
|
|
|
struct k3StorageBasic {
|
|
struct k3Storage;
|
|
GLuint gl;
|
|
};
|
|
|
|
struct k3Offscreen {
|
|
GLuint fbo;
|
|
struct k3Tex *diffuse;
|
|
struct k3Tex *depth;
|
|
|
|
struct {
|
|
uint8_t samples;
|
|
GLuint fbo;
|
|
GLuint rboDiffuse;
|
|
GLuint rboDepth;
|
|
} multisampling;
|
|
};
|
|
|
|
struct k3Mdl {
|
|
struct {
|
|
vec3 *pos;
|
|
uint8_t *boneids;
|
|
uint16_t *boneweights;
|
|
} cpuSkinning;
|
|
|
|
size_t verts;
|
|
struct k3StorageBasic *vstore;
|
|
struct k3StorageBasic *estore;
|
|
|
|
uint16_t meshCount;
|
|
struct k3Mesh *meshes;
|
|
|
|
size_t boneCount;
|
|
mat4 *invBind;
|
|
uint8_t *boneParents;
|
|
char *boneNames;
|
|
|
|
uint16_t animCount;
|
|
struct k3AnimationFountain **anims;
|
|
|
|
vec3 aabb[2];
|
|
|
|
int offV, offN, offC, offU, offB, offT;
|
|
|
|
const char *debugname;
|
|
};
|
|
|
|
struct k3GLSLP {
|
|
GLhandleARB handle;
|
|
|
|
size_t ucount;
|
|
char **uname;
|
|
GLint *uloc;
|
|
};
|
|
|
|
struct k3Timer {
|
|
GLuint qStart;
|
|
GLuint qEnd;
|
|
char name[64];
|
|
};
|
|
extern struct k3Timer *k3Timers;
|
|
extern size_t k3TimerCount;
|
|
static inline struct k3Timer k3StartTimer(char *name) {
|
|
struct k3Timer t = {};
|
|
|
|
if(!GLAD_GL_ARB_timer_query) {
|
|
return;
|
|
}
|
|
|
|
glGenQueries(2, (GLuint*) &t);
|
|
|
|
strncpy(t.name, name, sizeof(t.name));
|
|
|
|
glQueryCounter(t.qStart, GL_TIMESTAMP);
|
|
|
|
if(GLAD_GL_KHR_debug) {
|
|
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, name);
|
|
}
|
|
|
|
return t;
|
|
}
|
|
static inline void k3EndTimer(struct k3Timer t) {
|
|
if(!GLAD_GL_ARB_timer_query) {
|
|
return;
|
|
}
|
|
|
|
glQueryCounter(t.qEnd, GL_TIMESTAMP);
|
|
|
|
if(GLAD_GL_KHR_debug) {
|
|
glPopDebugGroup();
|
|
}
|
|
|
|
k3Timers = realloc(k3Timers, sizeof(*k3Timers) * (k3TimerCount + 1));
|
|
k3Timers[k3TimerCount++] = t;
|
|
}
|