set up rendering + basic lighting, added imgui, added camera
This commit is contained in:
parent
958e9c86ee
commit
c55242ba80
11
alloc.cpp
11
alloc.cpp
@ -106,12 +106,17 @@ End(TempArena *temp_arena)
|
|||||||
{
|
{
|
||||||
if(temp_arena->arena)
|
if(temp_arena->arena)
|
||||||
{
|
{
|
||||||
temp_arena->start_pool->used = temp_arena->start_pos;
|
ArenaPool *start_pool = temp_arena->start_pool;
|
||||||
|
|
||||||
|
start_pool->used = temp_arena->start_pos;
|
||||||
|
memset(start_pool->buffer+start_pool->used, 0, start_pool->length-start_pool->used);
|
||||||
|
|
||||||
ArenaPool *pool = temp_arena->start_pool->next;
|
ArenaPool *pool = temp_arena->start_pool->next;
|
||||||
while(pool)
|
while(pool)
|
||||||
{
|
{
|
||||||
pool->used = 0;
|
pool->used = 0;
|
||||||
pool = pool->next;
|
pool = pool->next;
|
||||||
|
memset(pool->buffer, 0, pool->length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,7 +175,7 @@ Alloc(Arena* arena)
|
|||||||
template<typename T> Array<T>
|
template<typename T> Array<T>
|
||||||
Alloc(Arena* arena, u64 length)
|
Alloc(Arena* arena, u64 length)
|
||||||
{
|
{
|
||||||
Array<T> array;
|
Array<T> array = {};
|
||||||
|
|
||||||
array.ptr = AllocAlign<T>(arena, sizeof(T)*length, DEFAULT_ALIGNMENT);
|
array.ptr = AllocAlign<T>(arena, sizeof(T)*length, DEFAULT_ALIGNMENT);
|
||||||
array.length = length;
|
array.length = length;
|
||||||
@ -265,7 +270,7 @@ AllocPtrArray(u64 length)
|
|||||||
template<typename T> Array<T>
|
template<typename T> Array<T>
|
||||||
Alloc(u64 length)
|
Alloc(u64 length)
|
||||||
{
|
{
|
||||||
Array<T> array;
|
Array<T> array = {};
|
||||||
|
|
||||||
array.ptr = (T *)Malloc(sizeof(T)*length);
|
array.ptr = (T *)Malloc(sizeof(T)*length);
|
||||||
array.length = length;
|
array.length = length;
|
||||||
|
|||||||
387
assets.cpp
387
assets.cpp
@ -59,6 +59,42 @@ struct Model
|
|||||||
|
|
||||||
Model g_models[MODEL_MAX];
|
Model g_models[MODEL_MAX];
|
||||||
|
|
||||||
|
ModelBuffers
|
||||||
|
CreateModelBuffers(Array<Vertex> vertices, Array<u32> indices)
|
||||||
|
{
|
||||||
|
ModelBuffers buffers = CreateModelBuffers();
|
||||||
|
|
||||||
|
glBindVertexArray(buffers.vertex_array);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, buffers.vertex_buffer);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex)*vertices.length, vertices.ptr, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers.index_buffer);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(u32)*indices.length, indices.ptr, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, color));
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, tangent));
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(2);
|
||||||
|
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, pos));
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(3);
|
||||||
|
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, normal));
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(4);
|
||||||
|
glVertexAttribPointer(4, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, uv[0]));
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(5);
|
||||||
|
glVertexAttribPointer(5, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)(offsetof(Vertex, uv[1])));
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
return buffers;
|
||||||
|
}
|
||||||
|
|
||||||
Array<u8>
|
Array<u8>
|
||||||
OpenFile(String8 file_path)
|
OpenFile(String8 file_path)
|
||||||
{
|
{
|
||||||
@ -307,6 +343,65 @@ LoadImageToTexture(cgltf_image *asset_image, String8 texture_path)
|
|||||||
return texture_id;
|
return texture_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextureID
|
||||||
|
LoadImageToTexture(u8 *data, i32 width, i32 height, i32 channels)
|
||||||
|
{
|
||||||
|
assert(width > 0 && height > 0 && channels > 0);
|
||||||
|
|
||||||
|
Array<u8> temp_buffer = {};
|
||||||
|
if(channels == 1)
|
||||||
|
{
|
||||||
|
u64 length = width*height*channels;
|
||||||
|
temp_buffer = Alloc<u8>(length*4);
|
||||||
|
for(u64 i = 0; i < length; i += 1)
|
||||||
|
{
|
||||||
|
temp_buffer[i*3 + 0] = data[i];
|
||||||
|
temp_buffer[i*3 + 1] = data[i];
|
||||||
|
temp_buffer[i*3 + 2] = data[i];
|
||||||
|
temp_buffer[i*3 + 3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(channels == 3)
|
||||||
|
{
|
||||||
|
temp_buffer = Alloc<u8>(width*height*4);
|
||||||
|
u64 pixels = width*height;
|
||||||
|
for(u64 i = 0; i < pixels; i += 1)
|
||||||
|
{
|
||||||
|
temp_buffer[i*4 + 0] = data[i*3 + 0];
|
||||||
|
temp_buffer[i*4 + 1] = data[i*3 + 1];
|
||||||
|
temp_buffer[i*4 + 2] = data[i*3 + 2];
|
||||||
|
temp_buffer[i*4 + 3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(channels < 4)
|
||||||
|
{
|
||||||
|
data = temp_buffer.ptr;
|
||||||
|
channels = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageBuffer image_buffer = {
|
||||||
|
.data = {
|
||||||
|
.ptr = data,
|
||||||
|
.length = (u64)(width*height*channels),
|
||||||
|
},
|
||||||
|
.w = (u32)width,
|
||||||
|
.h = (u32)height,
|
||||||
|
.ch = (u32)channels,
|
||||||
|
};
|
||||||
|
|
||||||
|
assert(image_buffer.data.length > 0);
|
||||||
|
|
||||||
|
TextureID texture_id = CreateTexture(image_buffer);
|
||||||
|
|
||||||
|
if(temp_buffer)
|
||||||
|
{
|
||||||
|
Free(&temp_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture_id;
|
||||||
|
}
|
||||||
|
|
||||||
TextureID
|
TextureID
|
||||||
FindTexture(cgltf_texture *texture, cgltf_data *data, Model *model)
|
FindTexture(cgltf_texture *texture, cgltf_data *data, Model *model)
|
||||||
{
|
{
|
||||||
@ -502,9 +597,9 @@ LoadGLTF(Arena* arena, Model* model_result, String8 file_name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
model.materials[i].buffer_id = CreateBuffer(&material_set);
|
model.materials[i].buffer_id = CreateBuffer(&material_set, true);
|
||||||
model.materials[i].shader_state = shader_state;
|
model.materials[i].shader_state = shader_state;
|
||||||
model.materials[i].shader_state_buffer_id = CreateBuffer(&shader_state);
|
model.materials[i].shader_state_buffer_id = CreateBuffer(&shader_state, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 mesh_index = 0, point_index = 0;
|
u64 mesh_index = 0, point_index = 0;
|
||||||
@ -727,35 +822,7 @@ LoadGLTF(Arena* arena, Model* model_result, String8 file_name)
|
|||||||
|
|
||||||
Free(&file_data);
|
Free(&file_data);
|
||||||
|
|
||||||
model.buffers = CreateModelBuffers();
|
model.buffers = CreateModelBuffers(vertices, indices);
|
||||||
|
|
||||||
glBindVertexArray(model.buffers.vertex_array);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, model.buffers.vertex_buffer);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex)*vertices.length, vertices.ptr, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, model.buffers.index_buffer);
|
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(u32)*indices.length, indices.ptr, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, color));
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, tangent));
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(2);
|
|
||||||
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, pos));
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(3);
|
|
||||||
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, normal));
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(4);
|
|
||||||
glVertexAttribPointer(4, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, uv[0]));
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(5);
|
|
||||||
glVertexAttribPointer(5, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)(offsetof(Vertex, uv[1])));
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
End(&temp_arena);
|
End(&temp_arena);
|
||||||
|
|
||||||
@ -764,6 +831,262 @@ LoadGLTF(Arena* arena, Model* model_result, String8 file_name)
|
|||||||
cgltf_free(data);
|
cgltf_free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return result == cgltf_result_success;
|
return result == cgltf_result_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
M3DPropToStr(u8 type)
|
||||||
|
{
|
||||||
|
const char *result = "Unknown";
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case m3dp_Kd: result = "Diffuse"; break;
|
||||||
|
case m3dp_Ka: result = "Ambient"; break;
|
||||||
|
case m3dp_Ks: result = "Specular Color"; break;
|
||||||
|
case m3dp_Ns: result = "Specular Exponent"; break;
|
||||||
|
case m3dp_Ke: result = "Emissive"; break;
|
||||||
|
case m3dp_Tf: result = "Transmission"; break;
|
||||||
|
case m3dp_Km: result = "Bump Strength"; break;
|
||||||
|
case m3dp_d: result = "Alpha"; break;
|
||||||
|
case m3dp_il: result = "Illumination"; break;
|
||||||
|
case m3dp_Pr: result = "Roughness"; break;
|
||||||
|
case m3dp_Pm: result = "Metallic"; break;
|
||||||
|
case m3dp_Ps: result = "Sheen"; break;
|
||||||
|
case m3dp_Ni: result = "Refraction"; break;
|
||||||
|
case m3dp_Nt: result = "Face Thickness"; break;
|
||||||
|
case m3dp_map_Kd: result = "Diffuse Texture"; break;
|
||||||
|
case m3dp_map_Ka: result = "Ambient Texture"; break;
|
||||||
|
case m3dp_map_Ks: result = "Specular Texture"; break;
|
||||||
|
case m3dp_map_Ns: result = "Specular Exponent Texture"; break;
|
||||||
|
case m3dp_map_Ke: result = "Emissive Texture"; break;
|
||||||
|
case m3dp_map_Tf: result = "Transmission Texture"; break;
|
||||||
|
case m3dp_map_Km: result = "Bump Map"; break;
|
||||||
|
case m3dp_map_D: result = "Alpha Map"; break;
|
||||||
|
case m3dp_map_N: result = "Normal Map"; break;
|
||||||
|
case m3dp_map_Pr: result = "Roughness Map"; break;
|
||||||
|
case m3dp_map_Pm: result = "Metallic Map"; break;
|
||||||
|
case m3dp_map_Ps: result = "Sheen Map"; break;
|
||||||
|
case m3dp_map_Ni: result = "Refraction Map"; break;
|
||||||
|
case m3dp_map_Nt: result = "Thickness Map"; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
LoadM3D(Arena* arena, Model* model_result, String8 file_name)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
Array<u8> file_data = OpenFile(file_name);
|
||||||
|
assert(file_data);
|
||||||
|
|
||||||
|
m3d_t *m3d = m3d_load(file_data.ptr, NULL, NULL, NULL);
|
||||||
|
assert(m3d);
|
||||||
|
|
||||||
|
if(m3d->numface)
|
||||||
|
{
|
||||||
|
Model model = {
|
||||||
|
textures: Alloc<TextureID>(arena, m3d->numtexture),
|
||||||
|
materials: Alloc<Material>(arena, m3d->nummaterial),
|
||||||
|
};
|
||||||
|
|
||||||
|
for(u64 i = 0; i < m3d->numtexture; i += 1)
|
||||||
|
{
|
||||||
|
model.textures[i] = LoadImageToTexture(m3d->texture[i].d, m3d->texture[i].w, m3d->texture[i].h, m3d->texture[i].f);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(u64 i = 0; i < m3d->nummaterial; i += 1)
|
||||||
|
{
|
||||||
|
MaterialSet material_set = {};
|
||||||
|
ShaderModelState shader_state = {};
|
||||||
|
|
||||||
|
for(u64 j = 0; j < m3d->material[i].numprop; j += 1)
|
||||||
|
{
|
||||||
|
auto prop = m3d->material[i].prop + j;
|
||||||
|
TextureID *textures = model.materials[i].textures;
|
||||||
|
|
||||||
|
switch(prop->type)
|
||||||
|
{
|
||||||
|
case m3dp_Kd: material_set.maps[MMI_Albedo].color = U32ToVec4(prop->value.color); break;
|
||||||
|
case m3dp_Ka: material_set.maps[MMI_Occlusion].color = U32ToVec4(prop->value.color); break;
|
||||||
|
case m3dp_Ks: material_set.maps[MMI_Metallic].color = U32ToVec4(prop->value.color); break;
|
||||||
|
case m3dp_Ns: material_set.maps[MMI_Roughness].value = prop->value.fnum; break;
|
||||||
|
case m3dp_d: break; // Alpha
|
||||||
|
case m3dp_map_Kd:
|
||||||
|
{
|
||||||
|
textures[MMI_Albedo] = model.textures[prop->value.textureid];
|
||||||
|
shader_state.albedo_texture = true;
|
||||||
|
} break;
|
||||||
|
case m3dp_map_Ka:
|
||||||
|
{
|
||||||
|
textures[MMI_Occlusion] = model.textures[prop->value.textureid];
|
||||||
|
shader_state.occlusion_texture = true;
|
||||||
|
} break;
|
||||||
|
case m3dp_map_Ks:
|
||||||
|
{
|
||||||
|
textures[MMI_Metallic] = model.textures[prop->value.textureid];
|
||||||
|
textures[MMI_Roughness] = model.textures[prop->value.textureid]; // Maybe incorrect..
|
||||||
|
shader_state.metallic_roughness_texture = true;
|
||||||
|
} break;
|
||||||
|
case m3dp_map_D:
|
||||||
|
{
|
||||||
|
// Alpha texture
|
||||||
|
} break;
|
||||||
|
default: break; // Logf("Unsupported property: %s", M3DPropToStr(prop->type)); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
model.materials[i].buffer_id = CreateBuffer(&material_set, true);
|
||||||
|
model.materials[i].shader_state = shader_state;
|
||||||
|
model.materials[i].shader_state_buffer_id = CreateBuffer(&shader_state, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 mesh_count = 0;
|
||||||
|
u64 last = -2U;
|
||||||
|
for(u64 i = 0; i < m3d->numface; i += 1)
|
||||||
|
{
|
||||||
|
if(m3d->face[i].materialid != last)
|
||||||
|
{
|
||||||
|
last = m3d->face[i].materialid;
|
||||||
|
mesh_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
model.meshes = Alloc<Mesh>(arena, mesh_count);
|
||||||
|
|
||||||
|
u64 vertex_count = 0;
|
||||||
|
u64 mesh_index = 0;
|
||||||
|
if(mesh_count > 1)
|
||||||
|
{
|
||||||
|
last = -2U;
|
||||||
|
|
||||||
|
for(u64 i = 0; i < m3d->numface; i += 1)
|
||||||
|
{
|
||||||
|
if(last == -2U)
|
||||||
|
{
|
||||||
|
model.meshes[mesh_index].material_index = m3d->face[i].materialid;
|
||||||
|
model.meshes[mesh_index].start = 0;
|
||||||
|
model.meshes[mesh_index].index_start = 0;
|
||||||
|
|
||||||
|
last = m3d->face[i].materialid;
|
||||||
|
}
|
||||||
|
else if(m3d->face[i].materialid != last)
|
||||||
|
{
|
||||||
|
model.meshes[mesh_index].length = i*3-vertex_count;
|
||||||
|
model.meshes[mesh_index].index_length = i*3-vertex_count;
|
||||||
|
|
||||||
|
mesh_index += 1;
|
||||||
|
vertex_count += model.meshes[mesh_index].length;
|
||||||
|
|
||||||
|
model.meshes[mesh_index].start = vertex_count;
|
||||||
|
model.meshes[mesh_index].index_start = vertex_count;
|
||||||
|
model.meshes[mesh_index].material_index = m3d->face[i].materialid;
|
||||||
|
|
||||||
|
last = m3d->face[i].materialid;
|
||||||
|
}
|
||||||
|
if(i == m3d->numface-1)
|
||||||
|
{
|
||||||
|
model.meshes[mesh_index].length = i*3 - vertex_count;
|
||||||
|
model.meshes[mesh_index].index_length = i*3 - vertex_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
model.meshes[0].start = 0;
|
||||||
|
model.meshes[0].index_start = 0;
|
||||||
|
model.meshes[0].length = m3d->numface*3;
|
||||||
|
model.meshes[0].index_length = m3d->numface*3;
|
||||||
|
model.meshes[0].material_index = m3d->face[0].materialid;
|
||||||
|
}
|
||||||
|
|
||||||
|
TempArena temp_arena = Begin(arena);
|
||||||
|
|
||||||
|
Array<Vertex> vertices = Alloc<Vertex>(temp_arena, m3d->numface*3);
|
||||||
|
Array<u32> indices = Alloc<u32>(temp_arena, m3d->numface*3);
|
||||||
|
Array<Vec3> positions = Alloc<Vec3>(temp_arena, m3d->numface);
|
||||||
|
Array<u32> position_indices = Alloc<u32>(temp_arena, m3d->numface);
|
||||||
|
|
||||||
|
for(u64 i = 0; i < m3d->numface; i += 1)
|
||||||
|
{
|
||||||
|
u64 vi = i*3;
|
||||||
|
|
||||||
|
memcpy(&vertices[vi+0].pos, &m3d->vertex[m3d->face[i].vertex[0]], sizeof(Vec3));
|
||||||
|
memcpy(&vertices[vi+1].pos, &m3d->vertex[m3d->face[i].vertex[1]], sizeof(Vec3));
|
||||||
|
memcpy(&vertices[vi+2].pos, &m3d->vertex[m3d->face[i].vertex[2]], sizeof(Vec3));
|
||||||
|
|
||||||
|
memcpy(&vertices[vi+0].normal, &m3d->vertex[m3d->face[i].normal[0]], sizeof(Vec3));
|
||||||
|
memcpy(&vertices[vi+1].normal, &m3d->vertex[m3d->face[i].normal[1]], sizeof(Vec3));
|
||||||
|
memcpy(&vertices[vi+2].normal, &m3d->vertex[m3d->face[i].normal[2]], sizeof(Vec3));
|
||||||
|
|
||||||
|
vertices[vi+0].color = U32ToVec4(m3d->vertex[m3d->face[i].vertex[0]].color);
|
||||||
|
vertices[vi+1].color = U32ToVec4(m3d->vertex[m3d->face[i].vertex[1]].color);
|
||||||
|
vertices[vi+2].color = U32ToVec4(m3d->vertex[m3d->face[i].vertex[2]].color);
|
||||||
|
|
||||||
|
if(m3d->numtmap)
|
||||||
|
{
|
||||||
|
memcpy(&vertices[vi+0].uv[0], &m3d->tmap[m3d->face[i].texcoord[0]], sizeof(Vec2));
|
||||||
|
memcpy(&vertices[vi+1].uv[0], &m3d->tmap[m3d->face[i].texcoord[1]], sizeof(Vec2));
|
||||||
|
memcpy(&vertices[vi+2].uv[0], &m3d->tmap[m3d->face[i].texcoord[2]], sizeof(Vec2));
|
||||||
|
}
|
||||||
|
|
||||||
|
indices[vi+0] = vi+0;
|
||||||
|
indices[vi+1] = vi+1;
|
||||||
|
indices[vi+2] = vi+2;
|
||||||
|
|
||||||
|
positions[i] = (vertices[vi+0].pos + vertices[vi+1].pos + vertices[vi+2].pos) / 3.0f;
|
||||||
|
position_indices[i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(u64 i = 0; i < indices.length; i += 3)
|
||||||
|
{
|
||||||
|
u32 i0 = indices[i+0];
|
||||||
|
u32 i1 = indices[i+1];
|
||||||
|
u32 i2 = indices[i+2];
|
||||||
|
|
||||||
|
Vec3 edge1 = vertices[i1].pos - vertices[i0].pos;
|
||||||
|
Vec3 edge2 = vertices[i2].pos - vertices[i0].pos;
|
||||||
|
|
||||||
|
Vec2 delta_uv1 = vertices[i1].uv[0] - vertices[i0].uv[0];
|
||||||
|
Vec2 delta_uv2 = vertices[i2].uv[0] - vertices[i0].uv[0];
|
||||||
|
|
||||||
|
f32 dividend = delta_uv1.x*delta_uv2.y - delta_uv2.x*delta_uv1.y;
|
||||||
|
f32 fc = 1.0f/dividend;
|
||||||
|
|
||||||
|
Vec3 tangent = Vec3(
|
||||||
|
fc * (delta_uv2.y * edge1.x - delta_uv1.y * edge2.x),
|
||||||
|
fc * (delta_uv2.y * edge1.y - delta_uv1.y * edge2.y),
|
||||||
|
fc * (delta_uv2.y * edge1.z - delta_uv1.y * edge2.z)
|
||||||
|
);
|
||||||
|
|
||||||
|
tangent = Normalize(tangent);
|
||||||
|
|
||||||
|
f32 handedness = ((delta_uv1.y*delta_uv2.x - delta_uv2.y*delta_uv1.x) < 0.0f) ? -1.0f : +1.0f;
|
||||||
|
|
||||||
|
Vec3 t = tangent * handedness;
|
||||||
|
|
||||||
|
vertices[i0].tangent = Vec4(t, handedness);
|
||||||
|
vertices[i1].tangent = Vec4(t, handedness);
|
||||||
|
vertices[i2].tangent = Vec4(t, handedness);
|
||||||
|
}
|
||||||
|
|
||||||
|
model.buffers = CreateModelBuffers(vertices, indices);
|
||||||
|
|
||||||
|
End(&temp_arena);
|
||||||
|
|
||||||
|
*model_result = model;
|
||||||
|
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logf("No faces in M3D model");
|
||||||
|
}
|
||||||
|
|
||||||
|
m3d_free(m3d);
|
||||||
|
Free(&file_data);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
BIN
assets/cube_with_vertexcolors.m3d
Normal file
BIN
assets/cube_with_vertexcolors.m3d
Normal file
Binary file not shown.
BIN
assets/yoda.m3d
Normal file
BIN
assets/yoda.m3d
Normal file
Binary file not shown.
13
build.sh
13
build.sh
@ -64,9 +64,18 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
src="main.cpp"
|
imgui_src="external/include/imgui/imgui_main.cpp"
|
||||||
|
imgui_out="-obuild/imgui.o"
|
||||||
|
imgui_flags="-std=c++23 -D_USE_MATH_DEFINES -g -c -fmax-errors=5 ${compiler_flags} -Iexternal/include/imgui"
|
||||||
|
imgui_linker_flags="-lGL -lpthread -Lbuild -l:libSDL3.a"
|
||||||
|
|
||||||
|
if ! [ -f "build/imgui.o" ]; then
|
||||||
|
$compiler $imgui_src $imgui_linker_flags $imgui_flags $imgui_out
|
||||||
|
fi
|
||||||
|
|
||||||
|
src="main.cpp build/imgui.o"
|
||||||
out="build/Renderer"
|
out="build/Renderer"
|
||||||
flags="-std=c++23 -D_USE_MATH_DEFINES ${build_mode} ${compiler_flags} ${mode_flags} -Iexternal/include -fuse-ld=${linker} -Wno-pointer-arith -o${out}"
|
flags="-std=c++23 -D_USE_MATH_DEFINES ${build_mode} ${compiler_flags} ${mode_flags} -Iexternal/include -Iexternal/include/imgui -fuse-ld=${linker} -Wno-pointer-arith -o${out}"
|
||||||
linker_flags="-lGL -lpthread -Lbuild -l:libSDL3.a"
|
linker_flags="-lGL -lpthread -Lbuild -l:libSDL3.a"
|
||||||
|
|
||||||
$compiler $src $linker_flags $flags
|
$compiler $src $linker_flags $flags
|
||||||
|
|||||||
147
external/include/imgui/imconfig.h
vendored
Normal file
147
external/include/imgui/imconfig.h
vendored
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// DEAR IMGUI COMPILE-TIME OPTIONS
|
||||||
|
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
|
||||||
|
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it)
|
||||||
|
// B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
|
||||||
|
// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
|
||||||
|
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
|
||||||
|
// Call IMGUI_CHECKVERSION() from your .cpp file to verify that the data structures your files are using are matching the ones imgui.cpp is using.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//---- Define assertion handler. Defaults to calling assert().
|
||||||
|
// - If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
|
||||||
|
// - Compiling with NDEBUG will usually strip out assert() to nothing, which is NOT recommended because we use asserts to notify of programmer mistakes.
|
||||||
|
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
|
||||||
|
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
|
||||||
|
|
||||||
|
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
|
||||||
|
// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
|
||||||
|
// - Windows DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
|
||||||
|
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
|
||||||
|
//#define IMGUI_API __declspec(dllexport) // MSVC Windows: DLL export
|
||||||
|
//#define IMGUI_API __declspec(dllimport) // MSVC Windows: DLL import
|
||||||
|
//#define IMGUI_API __attribute__((visibility("default"))) // GCC/Clang: override visibility when set is hidden
|
||||||
|
|
||||||
|
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names.
|
||||||
|
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
|
|
||||||
|
//---- Disable all of Dear ImGui or don't implement standard windows/tools.
|
||||||
|
// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp.
|
||||||
|
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
|
||||||
|
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty.
|
||||||
|
//#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowIDStackToolWindow() will be empty.
|
||||||
|
|
||||||
|
//---- Don't implement some functions to reduce linkage requirements.
|
||||||
|
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
|
||||||
|
//#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW)
|
||||||
|
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
|
||||||
|
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME).
|
||||||
|
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS // Don't implement default platform_io.Platform_OpenInShellFn() handler (Win32: ShellExecute(), require shell32.lib/.a, Mac/Linux: use system("")).
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
|
||||||
|
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_FONT // Disable default embedded fonts (ProggyClean/ProggyForever), remove ~9 KB + ~14 KB from output binary. AddFontDefaultXXX() functions will assert.
|
||||||
|
//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
|
||||||
|
|
||||||
|
//---- Enable Test Engine / Automation features.
|
||||||
|
//#define IMGUI_ENABLE_TEST_ENGINE // Enable imgui_test_engine hooks. Generally set automatically by include "imgui_te_config.h", see Test Engine for details.
|
||||||
|
|
||||||
|
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
||||||
|
// May be convenient for some users to only explicitly include vanilla imgui.h and have extra stuff included.
|
||||||
|
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
||||||
|
//#define IMGUI_USER_H_FILENAME "my_folder/my_imgui_user.h"
|
||||||
|
|
||||||
|
//---- Pack vertex colors as BGRA8 instead of RGBA8 (to avoid converting from one to another). Need dedicated backend support.
|
||||||
|
//#define IMGUI_USE_BGRA_PACKED_COLOR
|
||||||
|
|
||||||
|
//---- Use legacy CRC32-adler tables (used before 1.91.6), in order to preserve old .ini data that you cannot afford to invalidate.
|
||||||
|
//#define IMGUI_USE_LEGACY_CRC32_ADLER
|
||||||
|
|
||||||
|
//---- Use 32-bit for ImWchar (default is 16-bit) to support Unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
|
||||||
|
//#define IMGUI_USE_WCHAR32
|
||||||
|
|
||||||
|
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
|
||||||
|
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
|
||||||
|
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
|
||||||
|
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
|
||||||
|
//#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined.
|
||||||
|
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
||||||
|
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
//#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined.
|
||||||
|
|
||||||
|
//---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
|
||||||
|
// Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h.
|
||||||
|
//#define IMGUI_USE_STB_SPRINTF
|
||||||
|
|
||||||
|
//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
|
||||||
|
// Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
|
||||||
|
// Note that imgui_freetype.cpp may be used _without_ this define, if you manually call ImFontAtlas::SetFontLoader(). The define is simply a convenience.
|
||||||
|
// On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
|
||||||
|
//#define IMGUI_ENABLE_FREETYPE
|
||||||
|
|
||||||
|
//---- Use FreeType + plutosvg or lunasvg to render OpenType SVG fonts (SVGinOT)
|
||||||
|
// Only works in combination with IMGUI_ENABLE_FREETYPE.
|
||||||
|
// - plutosvg is currently easier to install, as e.g. it is part of vcpkg. It will support more fonts and may load them faster. See misc/freetype/README for instructions.
|
||||||
|
// - Both require headers to be available in the include path + program to be linked with the library code (not provided).
|
||||||
|
// - (note: lunasvg implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
|
||||||
|
//#define IMGUI_ENABLE_FREETYPE_PLUTOSVG
|
||||||
|
//#define IMGUI_ENABLE_FREETYPE_LUNASVG
|
||||||
|
|
||||||
|
//---- Use stb_truetype to build and rasterize the font atlas (default)
|
||||||
|
// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.
|
||||||
|
//#define IMGUI_ENABLE_STB_TRUETYPE
|
||||||
|
|
||||||
|
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
|
||||||
|
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
|
||||||
|
/*
|
||||||
|
#define IM_VEC2_CLASS_EXTRA \
|
||||||
|
constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \
|
||||||
|
operator MyVec2() const { return MyVec2(x,y); }
|
||||||
|
|
||||||
|
#define IM_VEC4_CLASS_EXTRA \
|
||||||
|
constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
|
||||||
|
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
||||||
|
*/
|
||||||
|
//---- ...Or use Dear ImGui's own very basic math operators.
|
||||||
|
//#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
|
||||||
|
//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
|
||||||
|
// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
|
||||||
|
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
|
||||||
|
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
|
||||||
|
//#define ImDrawIdx unsigned int
|
||||||
|
|
||||||
|
//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
|
||||||
|
//struct ImDrawList;
|
||||||
|
//struct ImDrawCmd;
|
||||||
|
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
|
||||||
|
//#define ImDrawCallback MyImDrawCallback
|
||||||
|
|
||||||
|
//---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase)
|
||||||
|
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
|
||||||
|
//#define IM_DEBUG_BREAK IM_ASSERT(0)
|
||||||
|
//#define IM_DEBUG_BREAK __debugbreak()
|
||||||
|
|
||||||
|
//---- Debug Tools: Enable highlight ID conflicts _before_ hovering items. When io.ConfigDebugHighlightIdConflicts is set.
|
||||||
|
// (THIS WILL SLOW DOWN DEAR IMGUI. Only use occasionally and disable after use)
|
||||||
|
//#define IMGUI_DEBUG_HIGHLIGHT_ALL_ID_CONFLICTS
|
||||||
|
|
||||||
|
//---- Debug Tools: Enable slower asserts
|
||||||
|
//#define IMGUI_DEBUG_PARANOID
|
||||||
|
|
||||||
|
//---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files)
|
||||||
|
/*
|
||||||
|
namespace ImGui
|
||||||
|
{
|
||||||
|
void MyFunction(const char* name, MyMatrix44* mtx);
|
||||||
|
}
|
||||||
|
*/
|
||||||
18183
external/include/imgui/imgui.cpp
vendored
Normal file
18183
external/include/imgui/imgui.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
4203
external/include/imgui/imgui.h
vendored
Normal file
4203
external/include/imgui/imgui.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
10942
external/include/imgui/imgui_demo.cpp
vendored
Normal file
10942
external/include/imgui/imgui_demo.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
6739
external/include/imgui/imgui_draw.cpp
vendored
Normal file
6739
external/include/imgui/imgui_draw.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1066
external/include/imgui/imgui_impl_opengl3.cpp
vendored
Normal file
1066
external/include/imgui/imgui_impl_opengl3.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
68
external/include/imgui/imgui_impl_opengl3.h
vendored
Normal file
68
external/include/imgui/imgui_impl_opengl3.h
vendored
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
// dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline
|
||||||
|
// - Desktop GL: 2.x 3.x 4.x
|
||||||
|
// - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
|
||||||
|
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
||||||
|
|
||||||
|
// Implemented features:
|
||||||
|
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture as texture identifier. Read the FAQ about ImTextureID/ImTextureRef!
|
||||||
|
// [x] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset) [Desktop OpenGL only!]
|
||||||
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
|
|
||||||
|
// About WebGL/ES:
|
||||||
|
// - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES.
|
||||||
|
// - This is done automatically on iOS, Android and Emscripten targets.
|
||||||
|
// - For other targets, the define needs to be visible from the imgui_impl_opengl3.cpp compilation unit. If unsure, define globally or in imconfig.h.
|
||||||
|
|
||||||
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
|
// Learn about Dear ImGui:
|
||||||
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
// - Getting Started https://dearimgui.com/getting-started
|
||||||
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||||
|
// - Introduction, links and more at the top of imgui.cpp
|
||||||
|
|
||||||
|
// About GLSL version:
|
||||||
|
// The 'glsl_version' initialization parameter should be nullptr (default) or a "#version XXX" string.
|
||||||
|
// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
|
||||||
|
// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "imgui.h" // IMGUI_IMPL_API
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
|
||||||
|
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data);
|
||||||
|
|
||||||
|
// (Optional) Called by Init/NewFrame/Shutdown
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
|
||||||
|
|
||||||
|
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplOpenGL3_UpdateTexture(ImTextureData* tex);
|
||||||
|
|
||||||
|
// Configuration flags to add in your imconfig file:
|
||||||
|
//#define IMGUI_IMPL_OPENGL_ES2 // Enable ES 2 (Auto-detected on Emscripten)
|
||||||
|
//#define IMGUI_IMPL_OPENGL_ES3 // Enable ES 3 (Auto-detected on iOS/Android)
|
||||||
|
|
||||||
|
// You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
|
||||||
|
#if !defined(IMGUI_IMPL_OPENGL_ES2) \
|
||||||
|
&& !defined(IMGUI_IMPL_OPENGL_ES3)
|
||||||
|
|
||||||
|
// Try to detect GLES on matching platforms
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include <TargetConditionals.h>
|
||||||
|
#endif
|
||||||
|
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
|
||||||
|
#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
|
||||||
|
#elif defined(__EMSCRIPTEN__) || defined(__amigaos4__)
|
||||||
|
#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
|
||||||
|
#else
|
||||||
|
// Otherwise imgui_impl_opengl3_loader.h will be used.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
958
external/include/imgui/imgui_impl_opengl3_loader.h
vendored
Normal file
958
external/include/imgui/imgui_impl_opengl3_loader.h
vendored
Normal file
@ -0,0 +1,958 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// About imgui_impl_opengl3_loader.h:
|
||||||
|
//
|
||||||
|
// We embed our own OpenGL loader to not require user to provide their own or to have to use ours,
|
||||||
|
// which proved to be endless problems for users.
|
||||||
|
// Our loader is custom-generated, based on gl3w but automatically filtered to only include
|
||||||
|
// enums/functions that we use in our imgui_impl_opengl3.cpp source file in order to be small.
|
||||||
|
//
|
||||||
|
// YOU SHOULD NOT NEED TO INCLUDE/USE THIS DIRECTLY. THIS IS USED BY imgui_impl_opengl3.cpp ONLY.
|
||||||
|
// THE REST OF YOUR APP SHOULD USE A DIFFERENT GL LOADER: ANY GL LOADER OF YOUR CHOICE.
|
||||||
|
//
|
||||||
|
// IF YOU GET BUILD ERRORS IN THIS FILE (commonly macro redefinitions or function redefinitions):
|
||||||
|
// IT LIKELY MEANS THAT YOU ARE BUILDING 'imgui_impl_opengl3.cpp' OR INCLUDING 'imgui_impl_opengl3_loader.h'
|
||||||
|
// IN THE SAME COMPILATION UNIT AS ONE OF YOUR FILE WHICH IS USING A THIRD-PARTY OPENGL LOADER.
|
||||||
|
// (e.g. COULD HAPPEN IF YOU ARE DOING A UNITY/JUMBO BUILD, OR INCLUDING .CPP FILES FROM OTHERS)
|
||||||
|
// YOU SHOULD NOT BUILD BOTH IN THE SAME COMPILATION UNIT.
|
||||||
|
// BUT IF YOU REALLY WANT TO, you can '#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM' and imgui_impl_opengl3.cpp
|
||||||
|
// WILL NOT BE USING OUR LOADER, AND INSTEAD EXPECT ANOTHER/YOUR LOADER TO BE AVAILABLE IN THE COMPILATION UNIT.
|
||||||
|
//
|
||||||
|
// Regenerate with:
|
||||||
|
// python3 gl3w_gen.py --output ../imgui/backends/imgui_impl_opengl3_loader.h --ref ../imgui/backends/imgui_impl_opengl3.cpp ./extra_symbols.txt
|
||||||
|
//
|
||||||
|
// More info:
|
||||||
|
// https://github.com/dearimgui/gl3w_stripped
|
||||||
|
// https://github.com/ocornut/imgui/issues/4445
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file was generated with gl3w_gen.py, part of imgl3w
|
||||||
|
* (hosted at https://github.com/dearimgui/gl3w_stripped)
|
||||||
|
*
|
||||||
|
* This is free and unencumbered software released into the public domain.
|
||||||
|
*
|
||||||
|
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||||
|
* distribute this software, either in source code form or as a compiled
|
||||||
|
* binary, for any purpose, commercial or non-commercial, and by any
|
||||||
|
* means.
|
||||||
|
*
|
||||||
|
* In jurisdictions that recognize copyright laws, the author or authors
|
||||||
|
* of this software dedicate any and all copyright interest in the
|
||||||
|
* software to the public domain. We make this dedication for the benefit
|
||||||
|
* of the public at large and to the detriment of our heirs and
|
||||||
|
* successors. We intend this dedication to be an overt act of
|
||||||
|
* relinquishment in perpetuity of all present and future rights to this
|
||||||
|
* software under copyright law.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __gl3w_h_
|
||||||
|
#define __gl3w_h_
|
||||||
|
|
||||||
|
// Adapted from KHR/khrplatform.h to avoid including entire file.
|
||||||
|
#ifndef __khrplatform_h_
|
||||||
|
typedef float khronos_float_t;
|
||||||
|
typedef signed char khronos_int8_t;
|
||||||
|
typedef unsigned char khronos_uint8_t;
|
||||||
|
typedef signed short int khronos_int16_t;
|
||||||
|
typedef unsigned short int khronos_uint16_t;
|
||||||
|
#ifdef _WIN64
|
||||||
|
typedef signed long long int khronos_intptr_t;
|
||||||
|
typedef signed long long int khronos_ssize_t;
|
||||||
|
#else
|
||||||
|
typedef signed long int khronos_intptr_t;
|
||||||
|
typedef signed long int khronos_ssize_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && !defined(__clang__)
|
||||||
|
typedef signed __int64 khronos_int64_t;
|
||||||
|
typedef unsigned __int64 khronos_uint64_t;
|
||||||
|
#elif (defined(__clang__) || defined(__GNUC__)) && (__cplusplus < 201100)
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#else
|
||||||
|
typedef signed long long khronos_int64_t;
|
||||||
|
typedef unsigned long long khronos_uint64_t;
|
||||||
|
#endif
|
||||||
|
#endif // __khrplatform_h_
|
||||||
|
|
||||||
|
#ifndef __gl_glcorearb_h_
|
||||||
|
#define __gl_glcorearb_h_ 1
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
** Copyright 2013-2020 The Khronos Group Inc.
|
||||||
|
** SPDX-License-Identifier: MIT
|
||||||
|
**
|
||||||
|
** This header is generated from the Khronos OpenGL / OpenGL ES XML
|
||||||
|
** API Registry. The current version of the Registry, generator scripts
|
||||||
|
** used to make the header, and the header can be found at
|
||||||
|
** https://github.com/KhronosGroup/OpenGL-Registry
|
||||||
|
*/
|
||||||
|
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
|
||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN 1
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
#ifndef APIENTRY
|
||||||
|
#define APIENTRY
|
||||||
|
#endif
|
||||||
|
#ifndef APIENTRYP
|
||||||
|
#define APIENTRYP APIENTRY *
|
||||||
|
#endif
|
||||||
|
#ifndef GLAPI
|
||||||
|
#define GLAPI extern
|
||||||
|
#endif
|
||||||
|
/* glcorearb.h is for use with OpenGL core profile implementations.
|
||||||
|
** It should should be placed in the same directory as gl.h and
|
||||||
|
** included as <GL/glcorearb.h>.
|
||||||
|
**
|
||||||
|
** glcorearb.h includes only APIs in the latest OpenGL core profile
|
||||||
|
** implementation together with APIs in newer ARB extensions which
|
||||||
|
** can be supported by the core profile. It does not, and never will
|
||||||
|
** include functionality removed from the core profile, such as
|
||||||
|
** fixed-function vertex and fragment processing.
|
||||||
|
**
|
||||||
|
** Do not #include both <GL/glcorearb.h> and either of <GL/gl.h> or
|
||||||
|
** <GL/glext.h> in the same source file.
|
||||||
|
*/
|
||||||
|
/* Generated C header for:
|
||||||
|
* API: gl
|
||||||
|
* Profile: core
|
||||||
|
* Versions considered: .*
|
||||||
|
* Versions emitted: .*
|
||||||
|
* Default extensions included: glcore
|
||||||
|
* Additional extensions included: _nomatch_^
|
||||||
|
* Extensions removed: _nomatch_^
|
||||||
|
*/
|
||||||
|
#ifndef GL_VERSION_1_0
|
||||||
|
typedef void GLvoid;
|
||||||
|
typedef unsigned int GLenum;
|
||||||
|
|
||||||
|
typedef khronos_float_t GLfloat;
|
||||||
|
typedef int GLint;
|
||||||
|
typedef int GLsizei;
|
||||||
|
typedef unsigned int GLbitfield;
|
||||||
|
typedef double GLdouble;
|
||||||
|
typedef unsigned int GLuint;
|
||||||
|
typedef unsigned char GLboolean;
|
||||||
|
typedef khronos_uint8_t GLubyte;
|
||||||
|
#define GL_COLOR_BUFFER_BIT 0x00004000
|
||||||
|
#define GL_FALSE 0
|
||||||
|
#define GL_TRUE 1
|
||||||
|
#define GL_TRIANGLES 0x0004
|
||||||
|
#define GL_ONE 1
|
||||||
|
#define GL_SRC_ALPHA 0x0302
|
||||||
|
#define GL_ONE_MINUS_SRC_ALPHA 0x0303
|
||||||
|
#define GL_FRONT 0x0404
|
||||||
|
#define GL_BACK 0x0405
|
||||||
|
#define GL_FRONT_AND_BACK 0x0408
|
||||||
|
#define GL_POLYGON_MODE 0x0B40
|
||||||
|
#define GL_CULL_FACE 0x0B44
|
||||||
|
#define GL_DEPTH_TEST 0x0B71
|
||||||
|
#define GL_STENCIL_TEST 0x0B90
|
||||||
|
#define GL_VIEWPORT 0x0BA2
|
||||||
|
#define GL_BLEND 0x0BE2
|
||||||
|
#define GL_SCISSOR_BOX 0x0C10
|
||||||
|
#define GL_SCISSOR_TEST 0x0C11
|
||||||
|
#define GL_UNPACK_ROW_LENGTH 0x0CF2
|
||||||
|
#define GL_UNPACK_ALIGNMENT 0x0CF5
|
||||||
|
#define GL_PACK_ALIGNMENT 0x0D05
|
||||||
|
#define GL_MAX_TEXTURE_SIZE 0x0D33
|
||||||
|
#define GL_TEXTURE_2D 0x0DE1
|
||||||
|
#define GL_UNSIGNED_BYTE 0x1401
|
||||||
|
#define GL_UNSIGNED_SHORT 0x1403
|
||||||
|
#define GL_UNSIGNED_INT 0x1405
|
||||||
|
#define GL_FLOAT 0x1406
|
||||||
|
#define GL_RGBA 0x1908
|
||||||
|
#define GL_FILL 0x1B02
|
||||||
|
#define GL_VENDOR 0x1F00
|
||||||
|
#define GL_RENDERER 0x1F01
|
||||||
|
#define GL_VERSION 0x1F02
|
||||||
|
#define GL_EXTENSIONS 0x1F03
|
||||||
|
#define GL_NEAREST 0x2600
|
||||||
|
#define GL_LINEAR 0x2601
|
||||||
|
#define GL_TEXTURE_MAG_FILTER 0x2800
|
||||||
|
#define GL_TEXTURE_MIN_FILTER 0x2801
|
||||||
|
#define GL_TEXTURE_WRAP_S 0x2802
|
||||||
|
#define GL_TEXTURE_WRAP_T 0x2803
|
||||||
|
#define GL_REPEAT 0x2901
|
||||||
|
typedef void (APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode);
|
||||||
|
typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||||
|
typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
|
||||||
|
typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
|
||||||
|
typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask);
|
||||||
|
typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||||
|
typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
|
||||||
|
typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
|
||||||
|
typedef void (APIENTRYP PFNGLFLUSHPROC) (void);
|
||||||
|
typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param);
|
||||||
|
typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
|
||||||
|
typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void);
|
||||||
|
typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data);
|
||||||
|
typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
|
||||||
|
typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap);
|
||||||
|
typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode);
|
||||||
|
GLAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||||
|
GLAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param);
|
||||||
|
GLAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
|
||||||
|
GLAPI void APIENTRY glClear (GLbitfield mask);
|
||||||
|
GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||||
|
GLAPI void APIENTRY glDisable (GLenum cap);
|
||||||
|
GLAPI void APIENTRY glEnable (GLenum cap);
|
||||||
|
GLAPI void APIENTRY glFlush (void);
|
||||||
|
GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param);
|
||||||
|
GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
|
||||||
|
GLAPI GLenum APIENTRY glGetError (void);
|
||||||
|
GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *data);
|
||||||
|
GLAPI const GLubyte *APIENTRY glGetString (GLenum name);
|
||||||
|
GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap);
|
||||||
|
GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_1_0 */
|
||||||
|
#ifndef GL_VERSION_1_1
|
||||||
|
typedef khronos_float_t GLclampf;
|
||||||
|
typedef double GLclampd;
|
||||||
|
#define GL_TEXTURE_BINDING_2D 0x8069
|
||||||
|
typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices);
|
||||||
|
typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
|
||||||
|
typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
|
||||||
|
typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures);
|
||||||
|
typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices);
|
||||||
|
GLAPI void APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
|
||||||
|
GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture);
|
||||||
|
GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures);
|
||||||
|
GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_1_1 */
|
||||||
|
#ifndef GL_VERSION_1_2
|
||||||
|
#define GL_CLAMP_TO_EDGE 0x812F
|
||||||
|
#endif /* GL_VERSION_1_2 */
|
||||||
|
#ifndef GL_VERSION_1_3
|
||||||
|
#define GL_TEXTURE0 0x84C0
|
||||||
|
#define GL_ACTIVE_TEXTURE 0x84E0
|
||||||
|
typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glActiveTexture (GLenum texture);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_1_3 */
|
||||||
|
#ifndef GL_VERSION_1_4
|
||||||
|
#define GL_BLEND_DST_RGB 0x80C8
|
||||||
|
#define GL_BLEND_SRC_RGB 0x80C9
|
||||||
|
#define GL_BLEND_DST_ALPHA 0x80CA
|
||||||
|
#define GL_BLEND_SRC_ALPHA 0x80CB
|
||||||
|
#define GL_FUNC_ADD 0x8006
|
||||||
|
typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
|
||||||
|
typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
|
||||||
|
GLAPI void APIENTRY glBlendEquation (GLenum mode);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_1_4 */
|
||||||
|
#ifndef GL_VERSION_1_5
|
||||||
|
typedef khronos_ssize_t GLsizeiptr;
|
||||||
|
typedef khronos_intptr_t GLintptr;
|
||||||
|
#define GL_ARRAY_BUFFER 0x8892
|
||||||
|
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
|
||||||
|
#define GL_ARRAY_BUFFER_BINDING 0x8894
|
||||||
|
#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
|
||||||
|
#define GL_STREAM_DRAW 0x88E0
|
||||||
|
typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
|
||||||
|
typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
|
||||||
|
typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
|
||||||
|
typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
|
||||||
|
typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer);
|
||||||
|
GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers);
|
||||||
|
GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers);
|
||||||
|
GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
|
||||||
|
GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_1_5 */
|
||||||
|
#ifndef GL_VERSION_2_0
|
||||||
|
typedef char GLchar;
|
||||||
|
typedef khronos_int16_t GLshort;
|
||||||
|
typedef khronos_int8_t GLbyte;
|
||||||
|
typedef khronos_uint16_t GLushort;
|
||||||
|
#define GL_BLEND_EQUATION_RGB 0x8009
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
|
||||||
|
#define GL_BLEND_EQUATION_ALPHA 0x883D
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
|
||||||
|
#define GL_FRAGMENT_SHADER 0x8B30
|
||||||
|
#define GL_VERTEX_SHADER 0x8B31
|
||||||
|
#define GL_COMPILE_STATUS 0x8B81
|
||||||
|
#define GL_LINK_STATUS 0x8B82
|
||||||
|
#define GL_INFO_LOG_LENGTH 0x8B84
|
||||||
|
#define GL_CURRENT_PROGRAM 0x8B8D
|
||||||
|
#define GL_UPPER_LEFT 0x8CA2
|
||||||
|
typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha);
|
||||||
|
typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
|
||||||
|
typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader);
|
||||||
|
typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void);
|
||||||
|
typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type);
|
||||||
|
typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program);
|
||||||
|
typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader);
|
||||||
|
typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
|
||||||
|
typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index);
|
||||||
|
typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
|
||||||
|
typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name);
|
||||||
|
typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
|
||||||
|
typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||||
|
typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
|
||||||
|
typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||||
|
typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name);
|
||||||
|
typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params);
|
||||||
|
typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer);
|
||||||
|
typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program);
|
||||||
|
typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program);
|
||||||
|
typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
|
||||||
|
typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program);
|
||||||
|
typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
|
||||||
|
typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
|
||||||
|
typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha);
|
||||||
|
GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader);
|
||||||
|
GLAPI void APIENTRY glCompileShader (GLuint shader);
|
||||||
|
GLAPI GLuint APIENTRY glCreateProgram (void);
|
||||||
|
GLAPI GLuint APIENTRY glCreateShader (GLenum type);
|
||||||
|
GLAPI void APIENTRY glDeleteProgram (GLuint program);
|
||||||
|
GLAPI void APIENTRY glDeleteShader (GLuint shader);
|
||||||
|
GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader);
|
||||||
|
GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index);
|
||||||
|
GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index);
|
||||||
|
GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name);
|
||||||
|
GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params);
|
||||||
|
GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||||
|
GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params);
|
||||||
|
GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
|
||||||
|
GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name);
|
||||||
|
GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params);
|
||||||
|
GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer);
|
||||||
|
GLAPI GLboolean APIENTRY glIsProgram (GLuint program);
|
||||||
|
GLAPI void APIENTRY glLinkProgram (GLuint program);
|
||||||
|
GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
|
||||||
|
GLAPI void APIENTRY glUseProgram (GLuint program);
|
||||||
|
GLAPI void APIENTRY glUniform1i (GLint location, GLint v0);
|
||||||
|
GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
|
||||||
|
GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_2_0 */
|
||||||
|
#ifndef GL_VERSION_2_1
|
||||||
|
#define GL_PIXEL_UNPACK_BUFFER 0x88EC
|
||||||
|
#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF
|
||||||
|
#endif /* GL_VERSION_2_1 */
|
||||||
|
#ifndef GL_VERSION_3_0
|
||||||
|
typedef khronos_uint16_t GLhalf;
|
||||||
|
#define GL_MAJOR_VERSION 0x821B
|
||||||
|
#define GL_MINOR_VERSION 0x821C
|
||||||
|
#define GL_NUM_EXTENSIONS 0x821D
|
||||||
|
#define GL_FRAMEBUFFER_SRGB 0x8DB9
|
||||||
|
#define GL_VERTEX_ARRAY_BINDING 0x85B5
|
||||||
|
typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data);
|
||||||
|
typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data);
|
||||||
|
typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index);
|
||||||
|
typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array);
|
||||||
|
typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays);
|
||||||
|
typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI const GLubyte *APIENTRY glGetStringi (GLenum name, GLuint index);
|
||||||
|
GLAPI void APIENTRY glBindVertexArray (GLuint array);
|
||||||
|
GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays);
|
||||||
|
GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_3_0 */
|
||||||
|
#ifndef GL_VERSION_3_1
|
||||||
|
#define GL_VERSION_3_1 1
|
||||||
|
#define GL_PRIMITIVE_RESTART 0x8F9D
|
||||||
|
#endif /* GL_VERSION_3_1 */
|
||||||
|
#ifndef GL_VERSION_3_2
|
||||||
|
#define GL_VERSION_3_2 1
|
||||||
|
typedef struct __GLsync *GLsync;
|
||||||
|
typedef khronos_uint64_t GLuint64;
|
||||||
|
typedef khronos_int64_t GLint64;
|
||||||
|
#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
|
||||||
|
#define GL_CONTEXT_PROFILE_MASK 0x9126
|
||||||
|
typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
|
||||||
|
typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_3_2 */
|
||||||
|
#ifndef GL_VERSION_3_3
|
||||||
|
#define GL_VERSION_3_3 1
|
||||||
|
#define GL_SAMPLER_BINDING 0x8919
|
||||||
|
typedef void (APIENTRYP PFNGLGENSAMPLERSPROC) (GLsizei count, GLuint *samplers);
|
||||||
|
typedef void (APIENTRYP PFNGLDELETESAMPLERSPROC) (GLsizei count, const GLuint *samplers);
|
||||||
|
typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler);
|
||||||
|
typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIPROC) (GLuint sampler, GLenum pname, GLint param);
|
||||||
|
#ifdef GL_GLEXT_PROTOTYPES
|
||||||
|
GLAPI void APIENTRY glGenSamplers (GLsizei count, GLuint *samplers);
|
||||||
|
GLAPI void APIENTRY glDeleteSamplers (GLsizei count, const GLuint *samplers);
|
||||||
|
GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler);
|
||||||
|
GLAPI void APIENTRY glSamplerParameteri (GLuint sampler, GLenum pname, GLint param);
|
||||||
|
#endif
|
||||||
|
#endif /* GL_VERSION_3_3 */
|
||||||
|
#ifndef GL_VERSION_4_1
|
||||||
|
typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data);
|
||||||
|
typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data);
|
||||||
|
#endif /* GL_VERSION_4_1 */
|
||||||
|
#ifndef GL_VERSION_4_3
|
||||||
|
typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
|
||||||
|
#endif /* GL_VERSION_4_3 */
|
||||||
|
#ifndef GL_VERSION_4_5
|
||||||
|
#define GL_CLIP_ORIGIN 0x935C
|
||||||
|
typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint *param);
|
||||||
|
typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI64_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint64 *param);
|
||||||
|
#endif /* GL_VERSION_4_5 */
|
||||||
|
#ifndef GL_ARB_bindless_texture
|
||||||
|
typedef khronos_uint64_t GLuint64EXT;
|
||||||
|
#endif /* GL_ARB_bindless_texture */
|
||||||
|
#ifndef GL_ARB_cl_event
|
||||||
|
struct _cl_context;
|
||||||
|
struct _cl_event;
|
||||||
|
#endif /* GL_ARB_cl_event */
|
||||||
|
#ifndef GL_ARB_clip_control
|
||||||
|
#define GL_ARB_clip_control 1
|
||||||
|
#endif /* GL_ARB_clip_control */
|
||||||
|
#ifndef GL_ARB_debug_output
|
||||||
|
typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
|
||||||
|
#endif /* GL_ARB_debug_output */
|
||||||
|
#ifndef GL_EXT_EGL_image_storage
|
||||||
|
typedef void *GLeglImageOES;
|
||||||
|
#endif /* GL_EXT_EGL_image_storage */
|
||||||
|
#ifndef GL_EXT_direct_state_access
|
||||||
|
typedef void (APIENTRYP PFNGLGETFLOATI_VEXTPROC) (GLenum pname, GLuint index, GLfloat *params);
|
||||||
|
typedef void (APIENTRYP PFNGLGETDOUBLEI_VEXTPROC) (GLenum pname, GLuint index, GLdouble *params);
|
||||||
|
typedef void (APIENTRYP PFNGLGETPOINTERI_VEXTPROC) (GLenum pname, GLuint index, void **params);
|
||||||
|
typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint *param);
|
||||||
|
typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, void **param);
|
||||||
|
#endif /* GL_EXT_direct_state_access */
|
||||||
|
#ifndef GL_NV_draw_vulkan_image
|
||||||
|
typedef void (APIENTRY *GLVULKANPROCNV)(void);
|
||||||
|
#endif /* GL_NV_draw_vulkan_image */
|
||||||
|
#ifndef GL_NV_gpu_shader5
|
||||||
|
typedef khronos_int64_t GLint64EXT;
|
||||||
|
#endif /* GL_NV_gpu_shader5 */
|
||||||
|
#ifndef GL_NV_vertex_buffer_unified_memory
|
||||||
|
typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result);
|
||||||
|
#endif /* GL_NV_vertex_buffer_unified_memory */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef GL3W_API
|
||||||
|
#define GL3W_API
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __gl_h_
|
||||||
|
#define __gl_h_
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define GL3W_OK 0
|
||||||
|
#define GL3W_ERROR_INIT -1
|
||||||
|
#define GL3W_ERROR_LIBRARY_OPEN -2
|
||||||
|
#define GL3W_ERROR_OPENGL_VERSION -3
|
||||||
|
|
||||||
|
typedef void (*GL3WglProc)(void);
|
||||||
|
typedef GL3WglProc (*GL3WGetProcAddressProc)(const char *proc);
|
||||||
|
|
||||||
|
/* gl3w api */
|
||||||
|
GL3W_API int imgl3wInit(void);
|
||||||
|
GL3W_API int imgl3wInit2(GL3WGetProcAddressProc proc);
|
||||||
|
GL3W_API void imgl3wShutdown(void);
|
||||||
|
GL3W_API int imgl3wIsSupported(int major, int minor);
|
||||||
|
GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc);
|
||||||
|
|
||||||
|
/* gl3w internal state */
|
||||||
|
union ImGL3WProcs {
|
||||||
|
GL3WglProc ptr[63];
|
||||||
|
struct {
|
||||||
|
PFNGLACTIVETEXTUREPROC ActiveTexture;
|
||||||
|
PFNGLATTACHSHADERPROC AttachShader;
|
||||||
|
PFNGLBINDBUFFERPROC BindBuffer;
|
||||||
|
PFNGLBINDSAMPLERPROC BindSampler;
|
||||||
|
PFNGLBINDTEXTUREPROC BindTexture;
|
||||||
|
PFNGLBINDVERTEXARRAYPROC BindVertexArray;
|
||||||
|
PFNGLBLENDEQUATIONPROC BlendEquation;
|
||||||
|
PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate;
|
||||||
|
PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate;
|
||||||
|
PFNGLBUFFERDATAPROC BufferData;
|
||||||
|
PFNGLBUFFERSUBDATAPROC BufferSubData;
|
||||||
|
PFNGLCLEARPROC Clear;
|
||||||
|
PFNGLCLEARCOLORPROC ClearColor;
|
||||||
|
PFNGLCOMPILESHADERPROC CompileShader;
|
||||||
|
PFNGLCREATEPROGRAMPROC CreateProgram;
|
||||||
|
PFNGLCREATESHADERPROC CreateShader;
|
||||||
|
PFNGLDELETEBUFFERSPROC DeleteBuffers;
|
||||||
|
PFNGLDELETEPROGRAMPROC DeleteProgram;
|
||||||
|
PFNGLDELETESAMPLERSPROC DeleteSamplers;
|
||||||
|
PFNGLDELETESHADERPROC DeleteShader;
|
||||||
|
PFNGLDELETETEXTURESPROC DeleteTextures;
|
||||||
|
PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays;
|
||||||
|
PFNGLDETACHSHADERPROC DetachShader;
|
||||||
|
PFNGLDISABLEPROC Disable;
|
||||||
|
PFNGLDISABLEVERTEXATTRIBARRAYPROC DisableVertexAttribArray;
|
||||||
|
PFNGLDRAWELEMENTSPROC DrawElements;
|
||||||
|
PFNGLDRAWELEMENTSBASEVERTEXPROC DrawElementsBaseVertex;
|
||||||
|
PFNGLENABLEPROC Enable;
|
||||||
|
PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray;
|
||||||
|
PFNGLFLUSHPROC Flush;
|
||||||
|
PFNGLGENBUFFERSPROC GenBuffers;
|
||||||
|
PFNGLGENSAMPLERSPROC GenSamplers;
|
||||||
|
PFNGLGENTEXTURESPROC GenTextures;
|
||||||
|
PFNGLGENVERTEXARRAYSPROC GenVertexArrays;
|
||||||
|
PFNGLGETATTRIBLOCATIONPROC GetAttribLocation;
|
||||||
|
PFNGLGETERRORPROC GetError;
|
||||||
|
PFNGLGETINTEGERVPROC GetIntegerv;
|
||||||
|
PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog;
|
||||||
|
PFNGLGETPROGRAMIVPROC GetProgramiv;
|
||||||
|
PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog;
|
||||||
|
PFNGLGETSHADERIVPROC GetShaderiv;
|
||||||
|
PFNGLGETSTRINGPROC GetString;
|
||||||
|
PFNGLGETSTRINGIPROC GetStringi;
|
||||||
|
PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation;
|
||||||
|
PFNGLGETVERTEXATTRIBPOINTERVPROC GetVertexAttribPointerv;
|
||||||
|
PFNGLGETVERTEXATTRIBIVPROC GetVertexAttribiv;
|
||||||
|
PFNGLISENABLEDPROC IsEnabled;
|
||||||
|
PFNGLISPROGRAMPROC IsProgram;
|
||||||
|
PFNGLLINKPROGRAMPROC LinkProgram;
|
||||||
|
PFNGLPIXELSTOREIPROC PixelStorei;
|
||||||
|
PFNGLPOLYGONMODEPROC PolygonMode;
|
||||||
|
PFNGLREADPIXELSPROC ReadPixels;
|
||||||
|
PFNGLSAMPLERPARAMETERIPROC SamplerParameteri;
|
||||||
|
PFNGLSCISSORPROC Scissor;
|
||||||
|
PFNGLSHADERSOURCEPROC ShaderSource;
|
||||||
|
PFNGLTEXIMAGE2DPROC TexImage2D;
|
||||||
|
PFNGLTEXPARAMETERIPROC TexParameteri;
|
||||||
|
PFNGLTEXSUBIMAGE2DPROC TexSubImage2D;
|
||||||
|
PFNGLUNIFORM1IPROC Uniform1i;
|
||||||
|
PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv;
|
||||||
|
PFNGLUSEPROGRAMPROC UseProgram;
|
||||||
|
PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer;
|
||||||
|
PFNGLVIEWPORTPROC Viewport;
|
||||||
|
} gl;
|
||||||
|
};
|
||||||
|
|
||||||
|
GL3W_API extern union ImGL3WProcs imgl3wProcs;
|
||||||
|
|
||||||
|
/* OpenGL functions */
|
||||||
|
#define glActiveTexture imgl3wProcs.gl.ActiveTexture
|
||||||
|
#define glAttachShader imgl3wProcs.gl.AttachShader
|
||||||
|
#define glBindBuffer imgl3wProcs.gl.BindBuffer
|
||||||
|
#define glBindSampler imgl3wProcs.gl.BindSampler
|
||||||
|
#define glBindTexture imgl3wProcs.gl.BindTexture
|
||||||
|
#define glBindVertexArray imgl3wProcs.gl.BindVertexArray
|
||||||
|
#define glBlendEquation imgl3wProcs.gl.BlendEquation
|
||||||
|
#define glBlendEquationSeparate imgl3wProcs.gl.BlendEquationSeparate
|
||||||
|
#define glBlendFuncSeparate imgl3wProcs.gl.BlendFuncSeparate
|
||||||
|
#define glBufferData imgl3wProcs.gl.BufferData
|
||||||
|
#define glBufferSubData imgl3wProcs.gl.BufferSubData
|
||||||
|
#define glClear imgl3wProcs.gl.Clear
|
||||||
|
#define glClearColor imgl3wProcs.gl.ClearColor
|
||||||
|
#define glCompileShader imgl3wProcs.gl.CompileShader
|
||||||
|
#define glCreateProgram imgl3wProcs.gl.CreateProgram
|
||||||
|
#define glCreateShader imgl3wProcs.gl.CreateShader
|
||||||
|
#define glDeleteBuffers imgl3wProcs.gl.DeleteBuffers
|
||||||
|
#define glDeleteProgram imgl3wProcs.gl.DeleteProgram
|
||||||
|
#define glDeleteSamplers imgl3wProcs.gl.DeleteSamplers
|
||||||
|
#define glDeleteShader imgl3wProcs.gl.DeleteShader
|
||||||
|
#define glDeleteTextures imgl3wProcs.gl.DeleteTextures
|
||||||
|
#define glDeleteVertexArrays imgl3wProcs.gl.DeleteVertexArrays
|
||||||
|
#define glDetachShader imgl3wProcs.gl.DetachShader
|
||||||
|
#define glDisable imgl3wProcs.gl.Disable
|
||||||
|
#define glDisableVertexAttribArray imgl3wProcs.gl.DisableVertexAttribArray
|
||||||
|
#define glDrawElements imgl3wProcs.gl.DrawElements
|
||||||
|
#define glDrawElementsBaseVertex imgl3wProcs.gl.DrawElementsBaseVertex
|
||||||
|
#define glEnable imgl3wProcs.gl.Enable
|
||||||
|
#define glEnableVertexAttribArray imgl3wProcs.gl.EnableVertexAttribArray
|
||||||
|
#define glFlush imgl3wProcs.gl.Flush
|
||||||
|
#define glGenBuffers imgl3wProcs.gl.GenBuffers
|
||||||
|
#define glGenSamplers imgl3wProcs.gl.GenSamplers
|
||||||
|
#define glGenTextures imgl3wProcs.gl.GenTextures
|
||||||
|
#define glGenVertexArrays imgl3wProcs.gl.GenVertexArrays
|
||||||
|
#define glGetAttribLocation imgl3wProcs.gl.GetAttribLocation
|
||||||
|
#define glGetError imgl3wProcs.gl.GetError
|
||||||
|
#define glGetIntegerv imgl3wProcs.gl.GetIntegerv
|
||||||
|
#define glGetProgramInfoLog imgl3wProcs.gl.GetProgramInfoLog
|
||||||
|
#define glGetProgramiv imgl3wProcs.gl.GetProgramiv
|
||||||
|
#define glGetShaderInfoLog imgl3wProcs.gl.GetShaderInfoLog
|
||||||
|
#define glGetShaderiv imgl3wProcs.gl.GetShaderiv
|
||||||
|
#define glGetString imgl3wProcs.gl.GetString
|
||||||
|
#define glGetStringi imgl3wProcs.gl.GetStringi
|
||||||
|
#define glGetUniformLocation imgl3wProcs.gl.GetUniformLocation
|
||||||
|
#define glGetVertexAttribPointerv imgl3wProcs.gl.GetVertexAttribPointerv
|
||||||
|
#define glGetVertexAttribiv imgl3wProcs.gl.GetVertexAttribiv
|
||||||
|
#define glIsEnabled imgl3wProcs.gl.IsEnabled
|
||||||
|
#define glIsProgram imgl3wProcs.gl.IsProgram
|
||||||
|
#define glLinkProgram imgl3wProcs.gl.LinkProgram
|
||||||
|
#define glPixelStorei imgl3wProcs.gl.PixelStorei
|
||||||
|
#define glPolygonMode imgl3wProcs.gl.PolygonMode
|
||||||
|
#define glReadPixels imgl3wProcs.gl.ReadPixels
|
||||||
|
#define glSamplerParameteri imgl3wProcs.gl.SamplerParameteri
|
||||||
|
#define glScissor imgl3wProcs.gl.Scissor
|
||||||
|
#define glShaderSource imgl3wProcs.gl.ShaderSource
|
||||||
|
#define glTexImage2D imgl3wProcs.gl.TexImage2D
|
||||||
|
#define glTexParameteri imgl3wProcs.gl.TexParameteri
|
||||||
|
#define glTexSubImage2D imgl3wProcs.gl.TexSubImage2D
|
||||||
|
#define glUniform1i imgl3wProcs.gl.Uniform1i
|
||||||
|
#define glUniformMatrix4fv imgl3wProcs.gl.UniformMatrix4fv
|
||||||
|
#define glUseProgram imgl3wProcs.gl.UseProgram
|
||||||
|
#define glVertexAttribPointer imgl3wProcs.gl.VertexAttribPointer
|
||||||
|
#define glViewport imgl3wProcs.gl.Viewport
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IMGL3W_IMPL
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define GL3W_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN 1
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
static HMODULE libgl = NULL;
|
||||||
|
typedef PROC(__stdcall* GL3WglGetProcAddr)(LPCSTR);
|
||||||
|
static GL3WglGetProcAddr wgl_get_proc_address;
|
||||||
|
|
||||||
|
static int open_libgl(void)
|
||||||
|
{
|
||||||
|
libgl = LoadLibraryA("opengl32.dll");
|
||||||
|
if (!libgl)
|
||||||
|
return GL3W_ERROR_LIBRARY_OPEN;
|
||||||
|
wgl_get_proc_address = (GL3WglGetProcAddr)GetProcAddress(libgl, "wglGetProcAddress");
|
||||||
|
return GL3W_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void close_libgl(void) { FreeLibrary(libgl); libgl = NULL; }
|
||||||
|
static GL3WglProc get_proc(const char *proc)
|
||||||
|
{
|
||||||
|
GL3WglProc res;
|
||||||
|
res = (GL3WglProc)wgl_get_proc_address(proc);
|
||||||
|
if (!res)
|
||||||
|
res = (GL3WglProc)GetProcAddress(libgl, proc);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
|
static void *libgl = NULL;
|
||||||
|
static int open_libgl(void)
|
||||||
|
{
|
||||||
|
libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (!libgl)
|
||||||
|
return GL3W_ERROR_LIBRARY_OPEN;
|
||||||
|
return GL3W_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void close_libgl(void) { dlclose(libgl); libgl = NULL; }
|
||||||
|
|
||||||
|
static GL3WglProc get_proc(const char *proc)
|
||||||
|
{
|
||||||
|
GL3WglProc res;
|
||||||
|
*(void **)(&res) = dlsym(libgl, proc);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
|
static void* libgl; // OpenGL library
|
||||||
|
static void* libglx; // GLX library
|
||||||
|
static void* libegl; // EGL library
|
||||||
|
static GL3WGetProcAddressProc gl_get_proc_address;
|
||||||
|
|
||||||
|
static void close_libgl(void)
|
||||||
|
{
|
||||||
|
if (libgl) {
|
||||||
|
dlclose(libgl);
|
||||||
|
libgl = NULL;
|
||||||
|
}
|
||||||
|
if (libegl) {
|
||||||
|
dlclose(libegl);
|
||||||
|
libegl = NULL;
|
||||||
|
}
|
||||||
|
if (libglx) {
|
||||||
|
dlclose(libglx);
|
||||||
|
libglx = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int is_library_loaded(const char* name, void** lib)
|
||||||
|
{
|
||||||
|
#if defined(__HAIKU__)
|
||||||
|
*lib = NULL; // no support for RTLD_NOLOAD on Haiku.
|
||||||
|
#else
|
||||||
|
*lib = dlopen(name, RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
|
||||||
|
#endif
|
||||||
|
return *lib != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int open_libs(void)
|
||||||
|
{
|
||||||
|
// On Linux we have two APIs to get process addresses: EGL and GLX.
|
||||||
|
// EGL is supported under both X11 and Wayland, whereas GLX is X11-specific.
|
||||||
|
|
||||||
|
libgl = NULL;
|
||||||
|
libegl = NULL;
|
||||||
|
libglx = NULL;
|
||||||
|
|
||||||
|
// First check what's already loaded, the windowing library might have
|
||||||
|
// already loaded either EGL or GLX and we want to use the same one.
|
||||||
|
|
||||||
|
if (is_library_loaded("libEGL.so.1", &libegl) ||
|
||||||
|
is_library_loaded("libGLX.so.0", &libglx)) {
|
||||||
|
libgl = dlopen("libOpenGL.so.0", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (libgl)
|
||||||
|
return GL3W_OK;
|
||||||
|
else
|
||||||
|
close_libgl();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_library_loaded("libGL.so", &libgl))
|
||||||
|
return GL3W_OK;
|
||||||
|
if (is_library_loaded("libGL.so.1", &libgl))
|
||||||
|
return GL3W_OK;
|
||||||
|
if (is_library_loaded("libGL.so.3", &libgl))
|
||||||
|
return GL3W_OK;
|
||||||
|
|
||||||
|
// Neither is already loaded, so we have to load one. Try EGL first
|
||||||
|
// because it is supported under both X11 and Wayland.
|
||||||
|
|
||||||
|
// Load OpenGL + EGL
|
||||||
|
libgl = dlopen("libOpenGL.so.0", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
libegl = dlopen("libEGL.so.1", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (libgl && libegl)
|
||||||
|
return GL3W_OK;
|
||||||
|
else
|
||||||
|
close_libgl();
|
||||||
|
|
||||||
|
// Fall back to legacy libGL, which includes GLX
|
||||||
|
// While most systems use libGL.so.1, NetBSD seems to use that libGL.so.3. See https://github.com/ocornut/imgui/issues/6983
|
||||||
|
libgl = dlopen("libGL.so", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (!libgl)
|
||||||
|
libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (!libgl)
|
||||||
|
libgl = dlopen("libGL.so.3", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
|
||||||
|
if (libgl)
|
||||||
|
return GL3W_OK;
|
||||||
|
|
||||||
|
return GL3W_ERROR_LIBRARY_OPEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int open_libgl(void)
|
||||||
|
{
|
||||||
|
int res = open_libs();
|
||||||
|
if (res)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
if (libegl)
|
||||||
|
*(void**)(&gl_get_proc_address) = dlsym(libegl, "eglGetProcAddress");
|
||||||
|
else if (libglx)
|
||||||
|
*(void**)(&gl_get_proc_address) = dlsym(libglx, "glXGetProcAddressARB");
|
||||||
|
else
|
||||||
|
*(void**)(&gl_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB");
|
||||||
|
|
||||||
|
if (!gl_get_proc_address) {
|
||||||
|
close_libgl();
|
||||||
|
return GL3W_ERROR_LIBRARY_OPEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GL3W_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GL3WglProc get_proc(const char* proc)
|
||||||
|
{
|
||||||
|
GL3WglProc res = NULL;
|
||||||
|
|
||||||
|
// Before EGL version 1.5, eglGetProcAddress doesn't support querying core
|
||||||
|
// functions and may return a dummy function if we try, so try to load the
|
||||||
|
// function from the GL library directly first.
|
||||||
|
if (libegl)
|
||||||
|
*(void**)(&res) = dlsym(libgl, proc);
|
||||||
|
|
||||||
|
if (!res)
|
||||||
|
res = gl_get_proc_address(proc);
|
||||||
|
|
||||||
|
if (!libegl && !res)
|
||||||
|
*(void**)(&res) = dlsym(libgl, proc);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static struct { int major, minor; } version;
|
||||||
|
|
||||||
|
static int parse_version(void)
|
||||||
|
{
|
||||||
|
if (!glGetIntegerv)
|
||||||
|
return GL3W_ERROR_INIT;
|
||||||
|
glGetIntegerv(GL_MAJOR_VERSION, &version.major);
|
||||||
|
glGetIntegerv(GL_MINOR_VERSION, &version.minor);
|
||||||
|
if (version.major == 0 && version.minor == 0)
|
||||||
|
{
|
||||||
|
// Query GL_VERSION in desktop GL 2.x, the string will start with "<major>.<minor>"
|
||||||
|
if (const char* gl_version = (const char*)glGetString(GL_VERSION))
|
||||||
|
sscanf(gl_version, "%d.%d", &version.major, &version.minor);
|
||||||
|
}
|
||||||
|
if (version.major < 2)
|
||||||
|
return GL3W_ERROR_OPENGL_VERSION;
|
||||||
|
return GL3W_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void load_procs(GL3WGetProcAddressProc proc);
|
||||||
|
static void clear_procs();
|
||||||
|
|
||||||
|
int imgl3wInit(void)
|
||||||
|
{
|
||||||
|
int res = open_libgl();
|
||||||
|
if (res)
|
||||||
|
return res;
|
||||||
|
atexit(close_libgl);
|
||||||
|
return imgl3wInit2(get_proc);
|
||||||
|
}
|
||||||
|
|
||||||
|
int imgl3wInit2(GL3WGetProcAddressProc proc)
|
||||||
|
{
|
||||||
|
load_procs(proc);
|
||||||
|
return parse_version();
|
||||||
|
}
|
||||||
|
|
||||||
|
void imgl3wShutdown(void)
|
||||||
|
{
|
||||||
|
close_libgl();
|
||||||
|
clear_procs();
|
||||||
|
}
|
||||||
|
|
||||||
|
int imgl3wIsSupported(int major, int minor)
|
||||||
|
{
|
||||||
|
if (major < 2)
|
||||||
|
return 0;
|
||||||
|
if (version.major == major)
|
||||||
|
return version.minor >= minor;
|
||||||
|
return version.major >= major;
|
||||||
|
}
|
||||||
|
|
||||||
|
GL3WglProc imgl3wGetProcAddress(const char *proc) { return get_proc(proc); }
|
||||||
|
|
||||||
|
static const char *proc_names[] = {
|
||||||
|
"glActiveTexture",
|
||||||
|
"glAttachShader",
|
||||||
|
"glBindBuffer",
|
||||||
|
"glBindSampler",
|
||||||
|
"glBindTexture",
|
||||||
|
"glBindVertexArray",
|
||||||
|
"glBlendEquation",
|
||||||
|
"glBlendEquationSeparate",
|
||||||
|
"glBlendFuncSeparate",
|
||||||
|
"glBufferData",
|
||||||
|
"glBufferSubData",
|
||||||
|
"glClear",
|
||||||
|
"glClearColor",
|
||||||
|
"glCompileShader",
|
||||||
|
"glCreateProgram",
|
||||||
|
"glCreateShader",
|
||||||
|
"glDeleteBuffers",
|
||||||
|
"glDeleteProgram",
|
||||||
|
"glDeleteSamplers",
|
||||||
|
"glDeleteShader",
|
||||||
|
"glDeleteTextures",
|
||||||
|
"glDeleteVertexArrays",
|
||||||
|
"glDetachShader",
|
||||||
|
"glDisable",
|
||||||
|
"glDisableVertexAttribArray",
|
||||||
|
"glDrawElements",
|
||||||
|
"glDrawElementsBaseVertex",
|
||||||
|
"glEnable",
|
||||||
|
"glEnableVertexAttribArray",
|
||||||
|
"glFlush",
|
||||||
|
"glGenBuffers",
|
||||||
|
"glGenSamplers",
|
||||||
|
"glGenTextures",
|
||||||
|
"glGenVertexArrays",
|
||||||
|
"glGetAttribLocation",
|
||||||
|
"glGetError",
|
||||||
|
"glGetIntegerv",
|
||||||
|
"glGetProgramInfoLog",
|
||||||
|
"glGetProgramiv",
|
||||||
|
"glGetShaderInfoLog",
|
||||||
|
"glGetShaderiv",
|
||||||
|
"glGetString",
|
||||||
|
"glGetStringi",
|
||||||
|
"glGetUniformLocation",
|
||||||
|
"glGetVertexAttribPointerv",
|
||||||
|
"glGetVertexAttribiv",
|
||||||
|
"glIsEnabled",
|
||||||
|
"glIsProgram",
|
||||||
|
"glLinkProgram",
|
||||||
|
"glPixelStorei",
|
||||||
|
"glPolygonMode",
|
||||||
|
"glReadPixels",
|
||||||
|
"glSamplerParameteri",
|
||||||
|
"glScissor",
|
||||||
|
"glShaderSource",
|
||||||
|
"glTexImage2D",
|
||||||
|
"glTexParameteri",
|
||||||
|
"glTexSubImage2D",
|
||||||
|
"glUniform1i",
|
||||||
|
"glUniformMatrix4fv",
|
||||||
|
"glUseProgram",
|
||||||
|
"glVertexAttribPointer",
|
||||||
|
"glViewport",
|
||||||
|
};
|
||||||
|
|
||||||
|
GL3W_API union ImGL3WProcs imgl3wProcs;
|
||||||
|
|
||||||
|
static void load_procs(GL3WGetProcAddressProc proc)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < GL3W_ARRAY_SIZE(proc_names); i++)
|
||||||
|
imgl3wProcs.ptr[i] = proc(proc_names[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void clear_procs()
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < GL3W_ARRAY_SIZE(proc_names); i++)
|
||||||
|
imgl3wProcs.ptr[i] = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
887
external/include/imgui/imgui_impl_sdl3.cpp
vendored
Normal file
887
external/include/imgui/imgui_impl_sdl3.cpp
vendored
Normal file
@ -0,0 +1,887 @@
|
|||||||
|
// dear imgui: Platform Backend for SDL3
|
||||||
|
// This needs to be used along with a Renderer (e.g. SDL_GPU, DirectX11, OpenGL3, Vulkan..)
|
||||||
|
// (Info: SDL3 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
|
||||||
|
|
||||||
|
// Implemented features:
|
||||||
|
// [X] Platform: Clipboard support.
|
||||||
|
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
|
||||||
|
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values are obsolete since 1.87 and not supported since 1.91.5]
|
||||||
|
// [X] Platform: Gamepad support.
|
||||||
|
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||||
|
// [X] Platform: IME support.
|
||||||
|
|
||||||
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
|
// Learn about Dear ImGui:
|
||||||
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
// - Getting Started https://dearimgui.com/getting-started
|
||||||
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||||
|
// - Introduction, links and more at the top of imgui.cpp
|
||||||
|
|
||||||
|
// CHANGELOG
|
||||||
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
|
// 2026-02-13: Inputs: systems other than X11 are back to starting mouse capture on mouse down (reverts 2025-02-26 change). Only X11 requires waiting for a drag by default (not ideal, but a better default for X11 users). Added ImGui_ImplSDL3_SetMouseCaptureMode() for X11 debugger users. (#3650, #6410, #9235)
|
||||||
|
// 2026-01-15: Changed GetClipboardText() handler to return nullptr on error aka clipboard contents is not text. Consistent with other backends. (#9168)
|
||||||
|
// 2025-11-05: Fixed an issue with missing characters events when an already active text field changes viewports. (#9054)
|
||||||
|
// 2025-10-22: Fixed Platform_OpenInShellFn() return value (unused in core).
|
||||||
|
// 2025-09-24: Skip using the SDL_GetGlobalMouseState() state when one of our window is hovered, as the SDL_EVENT_MOUSE_MOTION data is reliable. Fix macOS notch mouse coordinates issue in fullscreen mode + better perf on X11. (#7919, #7786)
|
||||||
|
// 2025-09-18: Call platform_io.ClearPlatformHandlers() on shutdown.
|
||||||
|
// 2025-09-15: Use SDL_GetWindowDisplayScale() on Mac to output DisplayFrameBufferScale. The function is more reliable during resolution changes e.g. going fullscreen. (#8703, #4414)
|
||||||
|
// 2025-06-27: IME: avoid calling SDL_StartTextInput() again if already active. (#8727)
|
||||||
|
// 2025-04-22: IME: honor ImGuiPlatformImeData->WantTextInput as an alternative way to call SDL_StartTextInput(), without IME being necessarily visible.
|
||||||
|
// 2025-04-09: Don't attempt to call SDL_CaptureMouse() on drivers where we don't call SDL_GetGlobalMouseState(). (#8561)
|
||||||
|
// 2025-03-30: Update for SDL3 api changes: Revert SDL_GetClipboardText() memory ownership change. (#8530, #7801)
|
||||||
|
// 2025-03-21: Fill gamepad inputs and set ImGuiBackendFlags_HasGamepad regardless of ImGuiConfigFlags_NavEnableGamepad being set.
|
||||||
|
// 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468)
|
||||||
|
// 2025-02-26: Only start SDL_CaptureMouse() when mouse is being dragged, to mitigate issues with e.g. Linux debuggers not claiming capture back. (#6410, #3650)
|
||||||
|
// 2025-02-24: Avoid calling SDL_GetGlobalMouseState() when mouse is in relative mode.
|
||||||
|
// 2025-02-18: Added ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress mouse cursor support.
|
||||||
|
// 2025-02-10: Using SDL_OpenURL() in platform_io.Platform_OpenInShellFn handler.
|
||||||
|
// 2025-01-20: Made ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode_Manual) accept an empty array.
|
||||||
|
// 2024-10-24: Emscripten: SDL_EVENT_MOUSE_WHEEL event doesn't require dividing by 100.0f on Emscripten.
|
||||||
|
// 2024-09-03: Update for SDL3 api changes: SDL_GetGamepads() memory ownership revert. (#7918, #7898, #7807)
|
||||||
|
// 2024-08-22: moved some OS/backend related function pointers from ImGuiIO to ImGuiPlatformIO:
|
||||||
|
// - io.GetClipboardTextFn -> platform_io.Platform_GetClipboardTextFn
|
||||||
|
// - io.SetClipboardTextFn -> platform_io.Platform_SetClipboardTextFn
|
||||||
|
// - io.PlatformSetImeDataFn -> platform_io.Platform_SetImeDataFn
|
||||||
|
// 2024-08-19: Storing SDL_WindowID inside ImGuiViewport::PlatformHandle instead of SDL_Window*.
|
||||||
|
// 2024-08-19: ImGui_ImplSDL3_ProcessEvent() now ignores events intended for other SDL windows. (#7853)
|
||||||
|
// 2024-07-22: Update for SDL3 api changes: SDL_GetGamepads() memory ownership change. (#7807)
|
||||||
|
// 2024-07-18: Update for SDL3 api changes: SDL_GetClipboardText() memory ownership change. (#7801)
|
||||||
|
// 2024-07-15: Update for SDL3 api changes: SDL_GetProperty() change to SDL_GetPointerProperty(). (#7794)
|
||||||
|
// 2024-07-02: Update for SDL3 api changes: SDLK_x renames and SDLK_KP_x removals (#7761, #7762).
|
||||||
|
// 2024-07-01: Update for SDL3 api changes: SDL_SetTextInputRect() changed to SDL_SetTextInputArea().
|
||||||
|
// 2024-06-26: Update for SDL3 api changes: SDL_StartTextInput()/SDL_StopTextInput()/SDL_SetTextInputRect() functions signatures.
|
||||||
|
// 2024-06-24: Update for SDL3 api changes: SDL_EVENT_KEY_DOWN/SDL_EVENT_KEY_UP contents.
|
||||||
|
// 2024-06-03; Update for SDL3 api changes: SDL_SYSTEM_CURSOR_ renames.
|
||||||
|
// 2024-05-15: Update for SDL3 api changes: SDLK_ renames.
|
||||||
|
// 2024-04-15: Inputs: Re-enable calling SDL_StartTextInput()/SDL_StopTextInput() as SDL3 no longer enables it by default and should play nicer with IME.
|
||||||
|
// 2024-02-13: Inputs: Fixed gamepad support. Handle gamepad disconnection. Added ImGui_ImplSDL3_SetGamepadMode().
|
||||||
|
// 2023-11-13: Updated for recent SDL3 API changes.
|
||||||
|
// 2023-10-05: Inputs: Added support for extra ImGuiKey values: F13 to F24 function keys, app back/forward keys.
|
||||||
|
// 2023-05-04: Fixed build on Emscripten/iOS/Android. (#6391)
|
||||||
|
// 2023-04-06: Inputs: Avoid calling SDL_StartTextInput()/SDL_StopTextInput() as they don't only pertain to IME. It's unclear exactly what their relation is to IME. (#6306)
|
||||||
|
// 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen. (#2702)
|
||||||
|
// 2023-02-23: Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. (#6189, #6114, #3644)
|
||||||
|
// 2023-02-07: Forked "imgui_impl_sdl2" into "imgui_impl_sdl3". Removed version checks for old feature. Refer to imgui_impl_sdl2.cpp for older changelog.
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
#include "imgui_impl_sdl3.h"
|
||||||
|
|
||||||
|
// Clang warnings with -Weverything
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast
|
||||||
|
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// SDL
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
#include <stdio.h> // for snprintf()
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include <TargetConditionals.h>
|
||||||
|
#endif
|
||||||
|
#ifdef _WIN32
|
||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS) && !defined(__amigaos4__)
|
||||||
|
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 1
|
||||||
|
#else
|
||||||
|
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// FIXME-LEGACY: remove when SDL 3.1.3 preview is released.
|
||||||
|
#ifndef SDLK_APOSTROPHE
|
||||||
|
#define SDLK_APOSTROPHE SDLK_QUOTE
|
||||||
|
#endif
|
||||||
|
#ifndef SDLK_GRAVE
|
||||||
|
#define SDLK_GRAVE SDLK_BACKQUOTE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// SDL Data
|
||||||
|
struct ImGui_ImplSDL3_Data
|
||||||
|
{
|
||||||
|
SDL_Window* Window;
|
||||||
|
SDL_WindowID WindowID;
|
||||||
|
SDL_Renderer* Renderer;
|
||||||
|
Uint64 Time;
|
||||||
|
char* ClipboardTextData;
|
||||||
|
char BackendPlatformName[48];
|
||||||
|
|
||||||
|
// IME handling
|
||||||
|
SDL_Window* ImeWindow;
|
||||||
|
ImGuiPlatformImeData ImeData;
|
||||||
|
bool ImeDirty;
|
||||||
|
|
||||||
|
// Mouse handling
|
||||||
|
Uint32 MouseWindowID;
|
||||||
|
int MouseButtonsDown;
|
||||||
|
SDL_Cursor* MouseCursors[ImGuiMouseCursor_COUNT];
|
||||||
|
SDL_Cursor* MouseLastCursor;
|
||||||
|
int MousePendingLeaveFrame;
|
||||||
|
bool MouseCanUseGlobalState;
|
||||||
|
ImGui_ImplSDL3_MouseCaptureMode MouseCaptureMode;
|
||||||
|
|
||||||
|
// Gamepad handling
|
||||||
|
ImVector<SDL_Gamepad*> Gamepads;
|
||||||
|
ImGui_ImplSDL3_GamepadMode GamepadMode;
|
||||||
|
bool WantUpdateGamepadsList;
|
||||||
|
|
||||||
|
ImGui_ImplSDL3_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
|
||||||
|
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
||||||
|
// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
|
||||||
|
// FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context.
|
||||||
|
static ImGui_ImplSDL3_Data* ImGui_ImplSDL3_GetBackendData()
|
||||||
|
{
|
||||||
|
return ImGui::GetCurrentContext() ? (ImGui_ImplSDL3_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forward Declarations
|
||||||
|
static void ImGui_ImplSDL3_UpdateIme();
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
static const char* ImGui_ImplSDL3_GetClipboardText(ImGuiContext*)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
if (bd->ClipboardTextData)
|
||||||
|
SDL_free(bd->ClipboardTextData);
|
||||||
|
if (SDL_HasClipboardText())
|
||||||
|
bd->ClipboardTextData = SDL_GetClipboardText();
|
||||||
|
else
|
||||||
|
bd->ClipboardTextData = nullptr;
|
||||||
|
return bd->ClipboardTextData;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_SetClipboardText(ImGuiContext*, const char* text)
|
||||||
|
{
|
||||||
|
SDL_SetClipboardText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ImGuiViewport* ImGui_ImplSDL3_GetViewportForWindowID(SDL_WindowID window_id)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
return (window_id == bd->WindowID) ? ImGui::GetMainViewport() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_PlatformSetImeData(ImGuiContext*, ImGuiViewport*, ImGuiPlatformImeData* data)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
bd->ImeData = *data;
|
||||||
|
bd->ImeDirty = true;
|
||||||
|
ImGui_ImplSDL3_UpdateIme();
|
||||||
|
}
|
||||||
|
|
||||||
|
// We discard viewport passed via ImGuiPlatformImeData and always call SDL_StartTextInput() on SDL_GetKeyboardFocus().
|
||||||
|
static void ImGui_ImplSDL3_UpdateIme()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
ImGuiPlatformImeData* data = &bd->ImeData;
|
||||||
|
SDL_Window* window = SDL_GetKeyboardFocus();
|
||||||
|
|
||||||
|
// Stop previous input
|
||||||
|
if ((!(data->WantVisible || data->WantTextInput) || bd->ImeWindow != window) && bd->ImeWindow != nullptr)
|
||||||
|
{
|
||||||
|
SDL_StopTextInput(bd->ImeWindow);
|
||||||
|
bd->ImeWindow = nullptr;
|
||||||
|
}
|
||||||
|
if ((!bd->ImeDirty && bd->ImeWindow == window) || (window == nullptr))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Start/update current input
|
||||||
|
bd->ImeDirty = false;
|
||||||
|
if (data->WantVisible)
|
||||||
|
{
|
||||||
|
SDL_Rect r;
|
||||||
|
r.x = (int)data->InputPos.x;
|
||||||
|
r.y = (int)data->InputPos.y;
|
||||||
|
r.w = 1;
|
||||||
|
r.h = (int)data->InputLineHeight;
|
||||||
|
SDL_SetTextInputArea(window, &r, 0);
|
||||||
|
bd->ImeWindow = window;
|
||||||
|
}
|
||||||
|
if (!SDL_TextInputActive(window) && (data->WantVisible || data->WantTextInput))
|
||||||
|
SDL_StartTextInput(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not static to allow third-party code to use that if they want to (but undocumented)
|
||||||
|
ImGuiKey ImGui_ImplSDL3_KeyEventToImGuiKey(SDL_Keycode keycode, SDL_Scancode scancode);
|
||||||
|
ImGuiKey ImGui_ImplSDL3_KeyEventToImGuiKey(SDL_Keycode keycode, SDL_Scancode scancode)
|
||||||
|
{
|
||||||
|
// Keypad doesn't have individual key values in SDL3
|
||||||
|
switch (scancode)
|
||||||
|
{
|
||||||
|
case SDL_SCANCODE_KP_0: return ImGuiKey_Keypad0;
|
||||||
|
case SDL_SCANCODE_KP_1: return ImGuiKey_Keypad1;
|
||||||
|
case SDL_SCANCODE_KP_2: return ImGuiKey_Keypad2;
|
||||||
|
case SDL_SCANCODE_KP_3: return ImGuiKey_Keypad3;
|
||||||
|
case SDL_SCANCODE_KP_4: return ImGuiKey_Keypad4;
|
||||||
|
case SDL_SCANCODE_KP_5: return ImGuiKey_Keypad5;
|
||||||
|
case SDL_SCANCODE_KP_6: return ImGuiKey_Keypad6;
|
||||||
|
case SDL_SCANCODE_KP_7: return ImGuiKey_Keypad7;
|
||||||
|
case SDL_SCANCODE_KP_8: return ImGuiKey_Keypad8;
|
||||||
|
case SDL_SCANCODE_KP_9: return ImGuiKey_Keypad9;
|
||||||
|
case SDL_SCANCODE_KP_PERIOD: return ImGuiKey_KeypadDecimal;
|
||||||
|
case SDL_SCANCODE_KP_DIVIDE: return ImGuiKey_KeypadDivide;
|
||||||
|
case SDL_SCANCODE_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
|
||||||
|
case SDL_SCANCODE_KP_MINUS: return ImGuiKey_KeypadSubtract;
|
||||||
|
case SDL_SCANCODE_KP_PLUS: return ImGuiKey_KeypadAdd;
|
||||||
|
case SDL_SCANCODE_KP_ENTER: return ImGuiKey_KeypadEnter;
|
||||||
|
case SDL_SCANCODE_KP_EQUALS: return ImGuiKey_KeypadEqual;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
switch (keycode)
|
||||||
|
{
|
||||||
|
case SDLK_TAB: return ImGuiKey_Tab;
|
||||||
|
case SDLK_LEFT: return ImGuiKey_LeftArrow;
|
||||||
|
case SDLK_RIGHT: return ImGuiKey_RightArrow;
|
||||||
|
case SDLK_UP: return ImGuiKey_UpArrow;
|
||||||
|
case SDLK_DOWN: return ImGuiKey_DownArrow;
|
||||||
|
case SDLK_PAGEUP: return ImGuiKey_PageUp;
|
||||||
|
case SDLK_PAGEDOWN: return ImGuiKey_PageDown;
|
||||||
|
case SDLK_HOME: return ImGuiKey_Home;
|
||||||
|
case SDLK_END: return ImGuiKey_End;
|
||||||
|
case SDLK_INSERT: return ImGuiKey_Insert;
|
||||||
|
case SDLK_DELETE: return ImGuiKey_Delete;
|
||||||
|
case SDLK_BACKSPACE: return ImGuiKey_Backspace;
|
||||||
|
case SDLK_SPACE: return ImGuiKey_Space;
|
||||||
|
case SDLK_RETURN: return ImGuiKey_Enter;
|
||||||
|
case SDLK_ESCAPE: return ImGuiKey_Escape;
|
||||||
|
//case SDLK_APOSTROPHE: return ImGuiKey_Apostrophe;
|
||||||
|
case SDLK_COMMA: return ImGuiKey_Comma;
|
||||||
|
//case SDLK_MINUS: return ImGuiKey_Minus;
|
||||||
|
case SDLK_PERIOD: return ImGuiKey_Period;
|
||||||
|
//case SDLK_SLASH: return ImGuiKey_Slash;
|
||||||
|
case SDLK_SEMICOLON: return ImGuiKey_Semicolon;
|
||||||
|
//case SDLK_EQUALS: return ImGuiKey_Equal;
|
||||||
|
//case SDLK_LEFTBRACKET: return ImGuiKey_LeftBracket;
|
||||||
|
//case SDLK_BACKSLASH: return ImGuiKey_Backslash;
|
||||||
|
//case SDLK_RIGHTBRACKET: return ImGuiKey_RightBracket;
|
||||||
|
//case SDLK_GRAVE: return ImGuiKey_GraveAccent;
|
||||||
|
case SDLK_CAPSLOCK: return ImGuiKey_CapsLock;
|
||||||
|
case SDLK_SCROLLLOCK: return ImGuiKey_ScrollLock;
|
||||||
|
case SDLK_NUMLOCKCLEAR: return ImGuiKey_NumLock;
|
||||||
|
case SDLK_PRINTSCREEN: return ImGuiKey_PrintScreen;
|
||||||
|
case SDLK_PAUSE: return ImGuiKey_Pause;
|
||||||
|
case SDLK_LCTRL: return ImGuiKey_LeftCtrl;
|
||||||
|
case SDLK_LSHIFT: return ImGuiKey_LeftShift;
|
||||||
|
case SDLK_LALT: return ImGuiKey_LeftAlt;
|
||||||
|
case SDLK_LGUI: return ImGuiKey_LeftSuper;
|
||||||
|
case SDLK_RCTRL: return ImGuiKey_RightCtrl;
|
||||||
|
case SDLK_RSHIFT: return ImGuiKey_RightShift;
|
||||||
|
case SDLK_RALT: return ImGuiKey_RightAlt;
|
||||||
|
case SDLK_RGUI: return ImGuiKey_RightSuper;
|
||||||
|
case SDLK_APPLICATION: return ImGuiKey_Menu;
|
||||||
|
case SDLK_0: return ImGuiKey_0;
|
||||||
|
case SDLK_1: return ImGuiKey_1;
|
||||||
|
case SDLK_2: return ImGuiKey_2;
|
||||||
|
case SDLK_3: return ImGuiKey_3;
|
||||||
|
case SDLK_4: return ImGuiKey_4;
|
||||||
|
case SDLK_5: return ImGuiKey_5;
|
||||||
|
case SDLK_6: return ImGuiKey_6;
|
||||||
|
case SDLK_7: return ImGuiKey_7;
|
||||||
|
case SDLK_8: return ImGuiKey_8;
|
||||||
|
case SDLK_9: return ImGuiKey_9;
|
||||||
|
case SDLK_A: return ImGuiKey_A;
|
||||||
|
case SDLK_B: return ImGuiKey_B;
|
||||||
|
case SDLK_C: return ImGuiKey_C;
|
||||||
|
case SDLK_D: return ImGuiKey_D;
|
||||||
|
case SDLK_E: return ImGuiKey_E;
|
||||||
|
case SDLK_F: return ImGuiKey_F;
|
||||||
|
case SDLK_G: return ImGuiKey_G;
|
||||||
|
case SDLK_H: return ImGuiKey_H;
|
||||||
|
case SDLK_I: return ImGuiKey_I;
|
||||||
|
case SDLK_J: return ImGuiKey_J;
|
||||||
|
case SDLK_K: return ImGuiKey_K;
|
||||||
|
case SDLK_L: return ImGuiKey_L;
|
||||||
|
case SDLK_M: return ImGuiKey_M;
|
||||||
|
case SDLK_N: return ImGuiKey_N;
|
||||||
|
case SDLK_O: return ImGuiKey_O;
|
||||||
|
case SDLK_P: return ImGuiKey_P;
|
||||||
|
case SDLK_Q: return ImGuiKey_Q;
|
||||||
|
case SDLK_R: return ImGuiKey_R;
|
||||||
|
case SDLK_S: return ImGuiKey_S;
|
||||||
|
case SDLK_T: return ImGuiKey_T;
|
||||||
|
case SDLK_U: return ImGuiKey_U;
|
||||||
|
case SDLK_V: return ImGuiKey_V;
|
||||||
|
case SDLK_W: return ImGuiKey_W;
|
||||||
|
case SDLK_X: return ImGuiKey_X;
|
||||||
|
case SDLK_Y: return ImGuiKey_Y;
|
||||||
|
case SDLK_Z: return ImGuiKey_Z;
|
||||||
|
case SDLK_F1: return ImGuiKey_F1;
|
||||||
|
case SDLK_F2: return ImGuiKey_F2;
|
||||||
|
case SDLK_F3: return ImGuiKey_F3;
|
||||||
|
case SDLK_F4: return ImGuiKey_F4;
|
||||||
|
case SDLK_F5: return ImGuiKey_F5;
|
||||||
|
case SDLK_F6: return ImGuiKey_F6;
|
||||||
|
case SDLK_F7: return ImGuiKey_F7;
|
||||||
|
case SDLK_F8: return ImGuiKey_F8;
|
||||||
|
case SDLK_F9: return ImGuiKey_F9;
|
||||||
|
case SDLK_F10: return ImGuiKey_F10;
|
||||||
|
case SDLK_F11: return ImGuiKey_F11;
|
||||||
|
case SDLK_F12: return ImGuiKey_F12;
|
||||||
|
case SDLK_F13: return ImGuiKey_F13;
|
||||||
|
case SDLK_F14: return ImGuiKey_F14;
|
||||||
|
case SDLK_F15: return ImGuiKey_F15;
|
||||||
|
case SDLK_F16: return ImGuiKey_F16;
|
||||||
|
case SDLK_F17: return ImGuiKey_F17;
|
||||||
|
case SDLK_F18: return ImGuiKey_F18;
|
||||||
|
case SDLK_F19: return ImGuiKey_F19;
|
||||||
|
case SDLK_F20: return ImGuiKey_F20;
|
||||||
|
case SDLK_F21: return ImGuiKey_F21;
|
||||||
|
case SDLK_F22: return ImGuiKey_F22;
|
||||||
|
case SDLK_F23: return ImGuiKey_F23;
|
||||||
|
case SDLK_F24: return ImGuiKey_F24;
|
||||||
|
case SDLK_AC_BACK: return ImGuiKey_AppBack;
|
||||||
|
case SDLK_AC_FORWARD: return ImGuiKey_AppForward;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to scancode
|
||||||
|
switch (scancode)
|
||||||
|
{
|
||||||
|
case SDL_SCANCODE_GRAVE: return ImGuiKey_GraveAccent;
|
||||||
|
case SDL_SCANCODE_MINUS: return ImGuiKey_Minus;
|
||||||
|
case SDL_SCANCODE_EQUALS: return ImGuiKey_Equal;
|
||||||
|
case SDL_SCANCODE_LEFTBRACKET: return ImGuiKey_LeftBracket;
|
||||||
|
case SDL_SCANCODE_RIGHTBRACKET: return ImGuiKey_RightBracket;
|
||||||
|
case SDL_SCANCODE_NONUSBACKSLASH: return ImGuiKey_Oem102;
|
||||||
|
case SDL_SCANCODE_BACKSLASH: return ImGuiKey_Backslash;
|
||||||
|
case SDL_SCANCODE_SEMICOLON: return ImGuiKey_Semicolon;
|
||||||
|
case SDL_SCANCODE_APOSTROPHE: return ImGuiKey_Apostrophe;
|
||||||
|
case SDL_SCANCODE_COMMA: return ImGuiKey_Comma;
|
||||||
|
case SDL_SCANCODE_PERIOD: return ImGuiKey_Period;
|
||||||
|
case SDL_SCANCODE_SLASH: return ImGuiKey_Slash;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return ImGuiKey_None;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_UpdateKeyModifiers(SDL_Keymod sdl_key_mods)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.AddKeyEvent(ImGuiMod_Ctrl, (sdl_key_mods & SDL_KMOD_CTRL) != 0);
|
||||||
|
io.AddKeyEvent(ImGuiMod_Shift, (sdl_key_mods & SDL_KMOD_SHIFT) != 0);
|
||||||
|
io.AddKeyEvent(ImGuiMod_Alt, (sdl_key_mods & SDL_KMOD_ALT) != 0);
|
||||||
|
io.AddKeyEvent(ImGuiMod_Super, (sdl_key_mods & SDL_KMOD_GUI) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||||
|
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||||
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||||
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||||
|
bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplSDL3_Init()?");
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
switch (event->type)
|
||||||
|
{
|
||||||
|
case SDL_EVENT_MOUSE_MOTION:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->motion.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
ImVec2 mouse_pos((float)event->motion.x, (float)event->motion.y);
|
||||||
|
io.AddMouseSourceEvent(event->motion.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
||||||
|
io.AddMousePosEvent(mouse_pos.x, mouse_pos.y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_EVENT_MOUSE_WHEEL:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->wheel.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
//IMGUI_DEBUG_LOG("wheel %.2f %.2f, precise %.2f %.2f\n", (float)event->wheel.x, (float)event->wheel.y, event->wheel.preciseX, event->wheel.preciseY);
|
||||||
|
float wheel_x = -event->wheel.x;
|
||||||
|
float wheel_y = event->wheel.y;
|
||||||
|
io.AddMouseSourceEvent(event->wheel.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
||||||
|
io.AddMouseWheelEvent(wheel_x, wheel_y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
||||||
|
case SDL_EVENT_MOUSE_BUTTON_UP:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->button.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
int mouse_button = -1;
|
||||||
|
if (event->button.button == SDL_BUTTON_LEFT) { mouse_button = 0; }
|
||||||
|
if (event->button.button == SDL_BUTTON_RIGHT) { mouse_button = 1; }
|
||||||
|
if (event->button.button == SDL_BUTTON_MIDDLE) { mouse_button = 2; }
|
||||||
|
if (event->button.button == SDL_BUTTON_X1) { mouse_button = 3; }
|
||||||
|
if (event->button.button == SDL_BUTTON_X2) { mouse_button = 4; }
|
||||||
|
if (mouse_button == -1)
|
||||||
|
break;
|
||||||
|
io.AddMouseSourceEvent(event->button.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
||||||
|
io.AddMouseButtonEvent(mouse_button, (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN));
|
||||||
|
bd->MouseButtonsDown = (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) ? (bd->MouseButtonsDown | (1 << mouse_button)) : (bd->MouseButtonsDown & ~(1 << mouse_button));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_EVENT_TEXT_INPUT:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->text.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
io.AddInputCharactersUTF8(event->text.text);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_EVENT_KEY_DOWN:
|
||||||
|
case SDL_EVENT_KEY_UP:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->key.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
ImGui_ImplSDL3_UpdateKeyModifiers((SDL_Keymod)event->key.mod);
|
||||||
|
//IMGUI_DEBUG_LOG("SDL_EVENT_KEY_%s : key=%d ('%s'), scancode=%d ('%s'), mod=%X\n",
|
||||||
|
// (event->type == SDL_EVENT_KEY_DOWN) ? "DOWN" : "UP ", event->key.key, SDL_GetKeyName(event->key.key), event->key.scancode, SDL_GetScancodeName(event->key.scancode), event->key.mod);
|
||||||
|
ImGuiKey key = ImGui_ImplSDL3_KeyEventToImGuiKey(event->key.key, event->key.scancode);
|
||||||
|
io.AddKeyEvent(key, (event->type == SDL_EVENT_KEY_DOWN));
|
||||||
|
io.SetKeyEventNativeData(key, (int)event->key.key, (int)event->key.scancode, (int)event->key.scancode); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_EVENT_WINDOW_MOUSE_ENTER:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->window.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
bd->MouseWindowID = event->window.windowID;
|
||||||
|
bd->MousePendingLeaveFrame = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// - In some cases, when detaching a window from main viewport SDL may send SDL_WINDOWEVENT_ENTER one frame too late,
|
||||||
|
// causing SDL_WINDOWEVENT_LEAVE on previous frame to interrupt drag operation by clear mouse position. This is why
|
||||||
|
// we delay process the SDL_WINDOWEVENT_LEAVE events by one frame. See issue #5012 for details.
|
||||||
|
// FIXME: Unconfirmed whether this is still needed with SDL3.
|
||||||
|
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->window.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
bd->MousePendingLeaveFrame = ImGui::GetFrameCount() + 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_EVENT_WINDOW_FOCUS_GAINED:
|
||||||
|
case SDL_EVENT_WINDOW_FOCUS_LOST:
|
||||||
|
{
|
||||||
|
if (ImGui_ImplSDL3_GetViewportForWindowID(event->window.windowID) == nullptr)
|
||||||
|
return false;
|
||||||
|
io.AddFocusEvent(event->type == SDL_EVENT_WINDOW_FOCUS_GAINED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_EVENT_GAMEPAD_ADDED:
|
||||||
|
case SDL_EVENT_GAMEPAD_REMOVED:
|
||||||
|
{
|
||||||
|
bd->WantUpdateGamepadsList = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_SetupPlatformHandles(ImGuiViewport* viewport, SDL_Window* window)
|
||||||
|
{
|
||||||
|
viewport->PlatformHandle = (void*)(intptr_t)SDL_GetWindowID(window);
|
||||||
|
viewport->PlatformHandleRaw = nullptr;
|
||||||
|
#if defined(_WIN32) && !defined(__WINRT__)
|
||||||
|
viewport->PlatformHandleRaw = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, nullptr);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
viewport->PlatformHandleRaw = SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_COCOA_WINDOW_POINTER, nullptr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ImGui_ImplSDL3_Init(SDL_Window* window, SDL_Renderer* renderer, void* sdl_gl_context)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
|
||||||
|
IM_UNUSED(sdl_gl_context); // Unused in this branch
|
||||||
|
//SDL_SetHint(SDL_HINT_EVENT_LOGGING, "2");
|
||||||
|
|
||||||
|
const int ver_linked = SDL_GetVersion();
|
||||||
|
|
||||||
|
// Setup backend capabilities flags
|
||||||
|
ImGui_ImplSDL3_Data* bd = IM_NEW(ImGui_ImplSDL3_Data)();
|
||||||
|
snprintf(bd->BackendPlatformName, sizeof(bd->BackendPlatformName), "imgui_impl_sdl3 (%d.%d.%d; %d.%d.%d)",
|
||||||
|
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION, SDL_VERSIONNUM_MAJOR(ver_linked), SDL_VERSIONNUM_MINOR(ver_linked), SDL_VERSIONNUM_MICRO(ver_linked));
|
||||||
|
io.BackendPlatformUserData = (void*)bd;
|
||||||
|
io.BackendPlatformName = bd->BackendPlatformName;
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
||||||
|
|
||||||
|
bd->Window = window;
|
||||||
|
bd->WindowID = SDL_GetWindowID(window);
|
||||||
|
bd->Renderer = renderer;
|
||||||
|
|
||||||
|
// Check and store if we are on a SDL backend that supports SDL_GetGlobalMouseState() and SDL_CaptureMouse()
|
||||||
|
// ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list)
|
||||||
|
bd->MouseCanUseGlobalState = false;
|
||||||
|
bd->MouseCaptureMode = ImGui_ImplSDL3_MouseCaptureMode_Disabled;
|
||||||
|
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
||||||
|
const char* sdl_backend = SDL_GetCurrentVideoDriver();
|
||||||
|
const char* capture_and_global_state_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" };
|
||||||
|
for (const char* item : capture_and_global_state_whitelist)
|
||||||
|
if (strncmp(sdl_backend, item, strlen(item)) == 0)
|
||||||
|
{
|
||||||
|
bd->MouseCanUseGlobalState = true;
|
||||||
|
bd->MouseCaptureMode = (strcmp(item, "x11") == 0) ? ImGui_ImplSDL3_MouseCaptureMode_EnabledAfterDrag : ImGui_ImplSDL3_MouseCaptureMode_Enabled;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
platform_io.Platform_SetClipboardTextFn = ImGui_ImplSDL3_SetClipboardText;
|
||||||
|
platform_io.Platform_GetClipboardTextFn = ImGui_ImplSDL3_GetClipboardText;
|
||||||
|
platform_io.Platform_SetImeDataFn = ImGui_ImplSDL3_PlatformSetImeData;
|
||||||
|
platform_io.Platform_OpenInShellFn = [](ImGuiContext*, const char* url) { return SDL_OpenURL(url); };
|
||||||
|
|
||||||
|
// Gamepad handling
|
||||||
|
bd->GamepadMode = ImGui_ImplSDL3_GamepadMode_AutoFirst;
|
||||||
|
bd->WantUpdateGamepadsList = true;
|
||||||
|
|
||||||
|
// Load mouse cursors
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_TEXT);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_MOVE);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NS_RESIZE);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_EW_RESIZE);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NESW_RESIZE);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NWSE_RESIZE);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_Hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_POINTER);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_Wait] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_Progress] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_PROGRESS);
|
||||||
|
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NOT_ALLOWED);
|
||||||
|
|
||||||
|
// Set platform dependent data in viewport
|
||||||
|
// Our mouse update function expect PlatformHandle to be filled for the main viewport
|
||||||
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
|
ImGui_ImplSDL3_SetupPlatformHandles(main_viewport, window);
|
||||||
|
|
||||||
|
// From 2.0.5: Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't emit the event.
|
||||||
|
// Without this, when clicking to gain focus, our widgets wouldn't activate even though they showed as hovered.
|
||||||
|
// (This is unfortunately a global SDL setting, so enabling it might have a side-effect on your application.
|
||||||
|
// It is unlikely to make a difference, but if your app absolutely needs to ignore the initial on-focus click:
|
||||||
|
// you can ignore SDL_EVENT_MOUSE_BUTTON_DOWN events coming right after a SDL_EVENT_WINDOW_FOCUS_GAINED)
|
||||||
|
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
|
||||||
|
|
||||||
|
// From 2.0.22: Disable auto-capture, this is preventing drag and drop across multiple windows (see #5710)
|
||||||
|
SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should technically be a SDL_GLContext but due to typedef it is sane to keep it void* in public interface.
|
||||||
|
bool ImGui_ImplSDL3_InitForOpenGL(SDL_Window* window, void* sdl_gl_context)
|
||||||
|
{
|
||||||
|
return ImGui_ImplSDL3_Init(window, nullptr, sdl_gl_context);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDL3_InitForVulkan(SDL_Window* window)
|
||||||
|
{
|
||||||
|
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDL3_InitForD3D(SDL_Window* window)
|
||||||
|
{
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
IM_ASSERT(0 && "Unsupported");
|
||||||
|
#endif
|
||||||
|
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDL3_InitForMetal(SDL_Window* window)
|
||||||
|
{
|
||||||
|
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDL3_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer)
|
||||||
|
{
|
||||||
|
return ImGui_ImplSDL3_Init(window, renderer, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDL3_InitForSDLGPU(SDL_Window* window)
|
||||||
|
{
|
||||||
|
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSDL3_InitForOther(SDL_Window* window)
|
||||||
|
{
|
||||||
|
return ImGui_ImplSDL3_Init(window, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_CloseGamepads();
|
||||||
|
|
||||||
|
void ImGui_ImplSDL3_Shutdown()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
|
|
||||||
|
if (bd->ClipboardTextData)
|
||||||
|
SDL_free(bd->ClipboardTextData);
|
||||||
|
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
||||||
|
SDL_DestroyCursor(bd->MouseCursors[cursor_n]);
|
||||||
|
ImGui_ImplSDL3_CloseGamepads();
|
||||||
|
|
||||||
|
io.BackendPlatformName = nullptr;
|
||||||
|
io.BackendPlatformUserData = nullptr;
|
||||||
|
io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad);
|
||||||
|
platform_io.ClearPlatformHandlers();
|
||||||
|
IM_DELETE(bd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSDL3_SetMouseCaptureMode(ImGui_ImplSDL3_MouseCaptureMode mode)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
if (mode == ImGui_ImplSDL3_MouseCaptureMode_Disabled && bd->MouseCaptureMode != ImGui_ImplSDL3_MouseCaptureMode_Disabled)
|
||||||
|
SDL_CaptureMouse(false);
|
||||||
|
bd->MouseCaptureMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_UpdateMouseData()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
// We forward mouse input when hovered or captured (via SDL_EVENT_MOUSE_MOTION) or when focused (below)
|
||||||
|
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
||||||
|
// - SDL_CaptureMouse() let the OS know e.g. that our drags can extend outside of parent boundaries (we want updated position) and shouldn't trigger other operations outside.
|
||||||
|
// - Debuggers under Linux tends to leave captured mouse on break, which may be very inconvenient, so to mitigate the issue on X11 we we wait until mouse has moved to begin capture.
|
||||||
|
if (bd->MouseCaptureMode == ImGui_ImplSDL3_MouseCaptureMode_Enabled)
|
||||||
|
{
|
||||||
|
SDL_CaptureMouse(bd->MouseButtonsDown != 0);
|
||||||
|
}
|
||||||
|
else if (bd->MouseCaptureMode == ImGui_ImplSDL3_MouseCaptureMode_EnabledAfterDrag)
|
||||||
|
{
|
||||||
|
bool want_capture = false;
|
||||||
|
for (int button_n = 0; button_n < ImGuiMouseButton_COUNT && !want_capture; button_n++)
|
||||||
|
if (ImGui::IsMouseDragging(button_n, 1.0f))
|
||||||
|
want_capture = true;
|
||||||
|
SDL_CaptureMouse(want_capture);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Window* focused_window = SDL_GetKeyboardFocus();
|
||||||
|
const bool is_app_focused = (bd->Window == focused_window);
|
||||||
|
#else
|
||||||
|
SDL_Window* focused_window = bd->Window;
|
||||||
|
const bool is_app_focused = (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_INPUT_FOCUS) != 0; // SDL 2.0.3 and non-windowed systems: single-viewport only
|
||||||
|
#endif
|
||||||
|
if (is_app_focused)
|
||||||
|
{
|
||||||
|
// (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when io.ConfigNavMoveSetMousePos is enabled by user)
|
||||||
|
if (io.WantSetMousePos)
|
||||||
|
SDL_WarpMouseInWindow(bd->Window, io.MousePos.x, io.MousePos.y);
|
||||||
|
|
||||||
|
// (Optional) Fallback to provide unclamped mouse position when focused but not hovered (SDL_EVENT_MOUSE_MOTION already provides this when hovered or captured)
|
||||||
|
// Note that SDL_GetGlobalMouseState() is in theory slow on X11, but this only runs on rather specific cases. If a problem we may provide a way to opt-out this feature.
|
||||||
|
SDL_Window* hovered_window = SDL_GetMouseFocus();
|
||||||
|
const bool is_relative_mouse_mode = SDL_GetWindowRelativeMouseMode(bd->Window);
|
||||||
|
if (hovered_window == nullptr && bd->MouseCanUseGlobalState && bd->MouseButtonsDown == 0 && !is_relative_mouse_mode)
|
||||||
|
{
|
||||||
|
// Single-viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window)
|
||||||
|
float mouse_x, mouse_y;
|
||||||
|
int window_x, window_y;
|
||||||
|
SDL_GetGlobalMouseState(&mouse_x, &mouse_y);
|
||||||
|
SDL_GetWindowPosition(focused_window, &window_x, &window_y);
|
||||||
|
mouse_x -= window_x;
|
||||||
|
mouse_y -= window_y;
|
||||||
|
io.AddMousePosEvent(mouse_x, mouse_y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_UpdateMouseCursor()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
|
||||||
|
return;
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
|
||||||
|
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
||||||
|
if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None)
|
||||||
|
{
|
||||||
|
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
||||||
|
SDL_HideCursor();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Show OS mouse cursor
|
||||||
|
SDL_Cursor* expected_cursor = bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow];
|
||||||
|
if (bd->MouseLastCursor != expected_cursor)
|
||||||
|
{
|
||||||
|
SDL_SetCursor(expected_cursor); // SDL function doesn't have an early out (see #6113)
|
||||||
|
bd->MouseLastCursor = expected_cursor;
|
||||||
|
}
|
||||||
|
SDL_ShowCursor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_CloseGamepads()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
if (bd->GamepadMode != ImGui_ImplSDL3_GamepadMode_Manual)
|
||||||
|
for (SDL_Gamepad* gamepad : bd->Gamepads)
|
||||||
|
SDL_CloseGamepad(gamepad);
|
||||||
|
bd->Gamepads.resize(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode mode, SDL_Gamepad** manual_gamepads_array, int manual_gamepads_count)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
ImGui_ImplSDL3_CloseGamepads();
|
||||||
|
if (mode == ImGui_ImplSDL3_GamepadMode_Manual)
|
||||||
|
{
|
||||||
|
IM_ASSERT(manual_gamepads_array != nullptr || manual_gamepads_count <= 0);
|
||||||
|
for (int n = 0; n < manual_gamepads_count; n++)
|
||||||
|
bd->Gamepads.push_back(manual_gamepads_array[n]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IM_ASSERT(manual_gamepads_array == nullptr && manual_gamepads_count <= 0);
|
||||||
|
bd->WantUpdateGamepadsList = true;
|
||||||
|
}
|
||||||
|
bd->GamepadMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_UpdateGamepadButton(ImGui_ImplSDL3_Data* bd, ImGuiIO& io, ImGuiKey key, SDL_GamepadButton button_no)
|
||||||
|
{
|
||||||
|
bool merged_value = false;
|
||||||
|
for (SDL_Gamepad* gamepad : bd->Gamepads)
|
||||||
|
merged_value |= SDL_GetGamepadButton(gamepad, button_no) != 0;
|
||||||
|
io.AddKeyEvent(key, merged_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline float Saturate(float v) { return v < 0.0f ? 0.0f : v > 1.0f ? 1.0f : v; }
|
||||||
|
static void ImGui_ImplSDL3_UpdateGamepadAnalog(ImGui_ImplSDL3_Data* bd, ImGuiIO& io, ImGuiKey key, SDL_GamepadAxis axis_no, float v0, float v1)
|
||||||
|
{
|
||||||
|
float merged_value = 0.0f;
|
||||||
|
for (SDL_Gamepad* gamepad : bd->Gamepads)
|
||||||
|
{
|
||||||
|
float vn = Saturate((float)(SDL_GetGamepadAxis(gamepad, axis_no) - v0) / (float)(v1 - v0));
|
||||||
|
if (merged_value < vn)
|
||||||
|
merged_value = vn;
|
||||||
|
}
|
||||||
|
io.AddKeyAnalogEvent(key, merged_value > 0.1f, merged_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_UpdateGamepads()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
|
||||||
|
// Update list of gamepads to use
|
||||||
|
if (bd->WantUpdateGamepadsList && bd->GamepadMode != ImGui_ImplSDL3_GamepadMode_Manual)
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_CloseGamepads();
|
||||||
|
int sdl_gamepads_count = 0;
|
||||||
|
SDL_JoystickID* sdl_gamepads = SDL_GetGamepads(&sdl_gamepads_count);
|
||||||
|
for (int n = 0; n < sdl_gamepads_count; n++)
|
||||||
|
if (SDL_Gamepad* gamepad = SDL_OpenGamepad(sdl_gamepads[n]))
|
||||||
|
{
|
||||||
|
bd->Gamepads.push_back(gamepad);
|
||||||
|
if (bd->GamepadMode == ImGui_ImplSDL3_GamepadMode_AutoFirst)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
bd->WantUpdateGamepadsList = false;
|
||||||
|
SDL_free(sdl_gamepads);
|
||||||
|
}
|
||||||
|
|
||||||
|
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
||||||
|
if (bd->Gamepads.Size == 0)
|
||||||
|
return;
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||||
|
|
||||||
|
// Update gamepad inputs
|
||||||
|
const int thumb_dead_zone = 8000; // SDL_gamepad.h suggests using this value.
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadStart, SDL_GAMEPAD_BUTTON_START);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadBack, SDL_GAMEPAD_BUTTON_BACK);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceLeft, SDL_GAMEPAD_BUTTON_WEST); // Xbox X, PS Square
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceRight, SDL_GAMEPAD_BUTTON_EAST); // Xbox B, PS Circle
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceUp, SDL_GAMEPAD_BUTTON_NORTH); // Xbox Y, PS Triangle
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceDown, SDL_GAMEPAD_BUTTON_SOUTH); // Xbox A, PS Cross
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadLeft, SDL_GAMEPAD_BUTTON_DPAD_LEFT);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadRight, SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadUp, SDL_GAMEPAD_BUTTON_DPAD_UP);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadDown, SDL_GAMEPAD_BUTTON_DPAD_DOWN);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadL1, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadR1, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadL2, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, 0.0f, 32767);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadR2, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, 0.0f, 32767);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadL3, SDL_GAMEPAD_BUTTON_LEFT_STICK);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadButton(bd, io, ImGuiKey_GamepadR3, SDL_GAMEPAD_BUTTON_RIGHT_STICK);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickLeft, SDL_GAMEPAD_AXIS_LEFTX, -thumb_dead_zone, -32768);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickRight, SDL_GAMEPAD_AXIS_LEFTX, +thumb_dead_zone, +32767);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickUp, SDL_GAMEPAD_AXIS_LEFTY, -thumb_dead_zone, -32768);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickDown, SDL_GAMEPAD_AXIS_LEFTY, +thumb_dead_zone, +32767);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickLeft, SDL_GAMEPAD_AXIS_RIGHTX, -thumb_dead_zone, -32768);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickRight, SDL_GAMEPAD_AXIS_RIGHTX, +thumb_dead_zone, +32767);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickUp, SDL_GAMEPAD_AXIS_RIGHTY, -thumb_dead_zone, -32768);
|
||||||
|
ImGui_ImplSDL3_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickDown, SDL_GAMEPAD_AXIS_RIGHTY, +thumb_dead_zone, +32767);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSDL3_GetWindowSizeAndFramebufferScale(SDL_Window* window, ImVec2* out_size, ImVec2* out_framebuffer_scale)
|
||||||
|
{
|
||||||
|
int w, h;
|
||||||
|
SDL_GetWindowSize(window, &w, &h);
|
||||||
|
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)
|
||||||
|
w = h = 0;
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
float fb_scale_x = SDL_GetWindowDisplayScale(window); // Seems more reliable during resolution change (#8703)
|
||||||
|
float fb_scale_y = fb_scale_x;
|
||||||
|
#else
|
||||||
|
int display_w, display_h;
|
||||||
|
SDL_GetWindowSizeInPixels(window, &display_w, &display_h);
|
||||||
|
float fb_scale_x = (w > 0) ? (float)display_w / (float)w : 1.0f;
|
||||||
|
float fb_scale_y = (h > 0) ? (float)display_h / (float)h : 1.0f;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (out_size != nullptr)
|
||||||
|
*out_size = ImVec2((float)w, (float)h);
|
||||||
|
if (out_framebuffer_scale != nullptr)
|
||||||
|
*out_framebuffer_scale = ImVec2(fb_scale_x, fb_scale_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSDL3_NewFrame()
|
||||||
|
{
|
||||||
|
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||||
|
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplSDL3_Init()?");
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
// Setup main viewport size (every frame to accommodate for window resizing)
|
||||||
|
ImGui_ImplSDL3_GetWindowSizeAndFramebufferScale(bd->Window, &io.DisplaySize, &io.DisplayFramebufferScale);
|
||||||
|
|
||||||
|
// Setup time step (we could also use SDL_GetTicksNS() available since SDL3)
|
||||||
|
// (Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. Happens in VMs and Emscripten, see #6189, #6114, #3644)
|
||||||
|
static Uint64 frequency = SDL_GetPerformanceFrequency();
|
||||||
|
Uint64 current_time = SDL_GetPerformanceCounter();
|
||||||
|
if (current_time <= bd->Time)
|
||||||
|
current_time = bd->Time + 1;
|
||||||
|
io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / frequency) : (float)(1.0f / 60.0f);
|
||||||
|
bd->Time = current_time;
|
||||||
|
|
||||||
|
if (bd->MousePendingLeaveFrame && bd->MousePendingLeaveFrame >= ImGui::GetFrameCount() && bd->MouseButtonsDown == 0)
|
||||||
|
{
|
||||||
|
bd->MouseWindowID = 0;
|
||||||
|
bd->MousePendingLeaveFrame = 0;
|
||||||
|
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui_ImplSDL3_UpdateMouseData();
|
||||||
|
ImGui_ImplSDL3_UpdateMouseCursor();
|
||||||
|
ImGui_ImplSDL3_UpdateIme();
|
||||||
|
|
||||||
|
// Update game controllers (if enabled and available)
|
||||||
|
ImGui_ImplSDL3_UpdateGamepads();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
54
external/include/imgui/imgui_impl_sdl3.h
vendored
Normal file
54
external/include/imgui/imgui_impl_sdl3.h
vendored
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// dear imgui: Platform Backend for SDL3
|
||||||
|
// This needs to be used along with a Renderer (e.g. SDL_GPU, DirectX11, OpenGL3, Vulkan..)
|
||||||
|
// (Info: SDL3 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
|
||||||
|
|
||||||
|
// Implemented features:
|
||||||
|
// [X] Platform: Clipboard support.
|
||||||
|
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
|
||||||
|
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values are obsolete since 1.87 and not supported since 1.91.5]
|
||||||
|
// [X] Platform: Gamepad support.
|
||||||
|
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||||
|
// [X] Platform: IME support.
|
||||||
|
|
||||||
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
|
// Learn about Dear ImGui:
|
||||||
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
// - Getting Started https://dearimgui.com/getting-started
|
||||||
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||||
|
// - Introduction, links and more at the top of imgui.cpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "imgui.h" // IMGUI_IMPL_API
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
|
||||||
|
struct SDL_Window;
|
||||||
|
struct SDL_Renderer;
|
||||||
|
struct SDL_Gamepad;
|
||||||
|
typedef union SDL_Event SDL_Event;
|
||||||
|
|
||||||
|
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForVulkan(SDL_Window* window);
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForD3D(SDL_Window* window);
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForMetal(SDL_Window* window);
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer);
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForSDLGPU(SDL_Window* window);
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForOther(SDL_Window* window);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDL3_Shutdown();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDL3_NewFrame();
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event);
|
||||||
|
|
||||||
|
// Gamepad selection automatically starts in AutoFirst mode, picking first available SDL_Gamepad. You may override this.
|
||||||
|
// When using manual mode, caller is responsible for opening/closing gamepad.
|
||||||
|
enum ImGui_ImplSDL3_GamepadMode { ImGui_ImplSDL3_GamepadMode_AutoFirst, ImGui_ImplSDL3_GamepadMode_AutoAll, ImGui_ImplSDL3_GamepadMode_Manual };
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode mode, SDL_Gamepad** manual_gamepads_array = nullptr, int manual_gamepads_count = -1);
|
||||||
|
|
||||||
|
// (Advanced, for X11 users) Override Mouse Capture mode. Mouse capture allows receiving updated mouse position after clicking inside our window and dragging outside it.
|
||||||
|
// Having this 'Enabled' is in theory always better. But, on X11 if you crash/break to debugger while capture is active you may temporarily lose access to your mouse.
|
||||||
|
// The best solution is to setup your debugger to automatically release capture, e.g. 'setxkbmap -option grab:break_actions && xdotool key XF86Ungrab' or via a GDB script. See #3650.
|
||||||
|
// But you may independently decide on X11, when a debugger is attached, to set this value to ImGui_ImplSDL3_MouseCaptureMode_Disabled.
|
||||||
|
enum ImGui_ImplSDL3_MouseCaptureMode { ImGui_ImplSDL3_MouseCaptureMode_Enabled, ImGui_ImplSDL3_MouseCaptureMode_EnabledAfterDrag, ImGui_ImplSDL3_MouseCaptureMode_Disabled };
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplSDL3_SetMouseCaptureMode(ImGui_ImplSDL3_MouseCaptureMode mode);
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
||||||
3991
external/include/imgui/imgui_internal.h
vendored
Normal file
3991
external/include/imgui/imgui_internal.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
8
external/include/imgui/imgui_main.cpp
vendored
Normal file
8
external/include/imgui/imgui_main.cpp
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
|
||||||
|
#include "imgui_draw.cpp"
|
||||||
|
#include "imgui_impl_sdl3.cpp"
|
||||||
|
#include "imgui_impl_opengl3.cpp"
|
||||||
|
#include "imgui_tables.cpp"
|
||||||
|
#include "imgui_widgets.cpp"
|
||||||
|
#include "imgui.cpp"
|
||||||
4573
external/include/imgui/imgui_tables.cpp
vendored
Normal file
4573
external/include/imgui/imgui_tables.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
10817
external/include/imgui/imgui_widgets.cpp
vendored
Normal file
10817
external/include/imgui/imgui_widgets.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
627
external/include/imgui/imstb_rectpack.h
vendored
Normal file
627
external/include/imgui/imstb_rectpack.h
vendored
Normal file
@ -0,0 +1,627 @@
|
|||||||
|
// [DEAR IMGUI]
|
||||||
|
// This is a slightly modified version of stb_rect_pack.h 1.01.
|
||||||
|
// Grep for [DEAR IMGUI] to find the changes.
|
||||||
|
//
|
||||||
|
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
|
||||||
|
// Sean Barrett 2014
|
||||||
|
//
|
||||||
|
// Useful for e.g. packing rectangular textures into an atlas.
|
||||||
|
// Does not do rotation.
|
||||||
|
//
|
||||||
|
// Before #including,
|
||||||
|
//
|
||||||
|
// #define STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
//
|
||||||
|
// in the file that you want to have the implementation.
|
||||||
|
//
|
||||||
|
// Not necessarily the awesomest packing method, but better than
|
||||||
|
// the totally naive one in stb_truetype (which is primarily what
|
||||||
|
// this is meant to replace).
|
||||||
|
//
|
||||||
|
// Has only had a few tests run, may have issues.
|
||||||
|
//
|
||||||
|
// More docs to come.
|
||||||
|
//
|
||||||
|
// No memory allocations; uses qsort() and assert() from stdlib.
|
||||||
|
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
||||||
|
//
|
||||||
|
// This library currently uses the Skyline Bottom-Left algorithm.
|
||||||
|
//
|
||||||
|
// Please note: better rectangle packers are welcome! Please
|
||||||
|
// implement them to the same API, but with a different init
|
||||||
|
// function.
|
||||||
|
//
|
||||||
|
// Credits
|
||||||
|
//
|
||||||
|
// Library
|
||||||
|
// Sean Barrett
|
||||||
|
// Minor features
|
||||||
|
// Martins Mozeiko
|
||||||
|
// github:IntellectualKitty
|
||||||
|
//
|
||||||
|
// Bugfixes / warning fixes
|
||||||
|
// Jeremy Jaussaud
|
||||||
|
// Fabian Giesen
|
||||||
|
//
|
||||||
|
// Version history:
|
||||||
|
//
|
||||||
|
// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
|
||||||
|
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
||||||
|
// 0.99 (2019-02-07) warning fixes
|
||||||
|
// 0.11 (2017-03-03) return packing success/fail result
|
||||||
|
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||||
|
// 0.09 (2016-08-27) fix compiler warnings
|
||||||
|
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
|
||||||
|
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
|
||||||
|
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
||||||
|
// 0.05: added STBRP_ASSERT to allow replacing assert
|
||||||
|
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
||||||
|
// 0.01: initial release
|
||||||
|
//
|
||||||
|
// LICENSE
|
||||||
|
//
|
||||||
|
// See end of file for license information.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// INCLUDE SECTION
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef STB_INCLUDE_STB_RECT_PACK_H
|
||||||
|
#define STB_INCLUDE_STB_RECT_PACK_H
|
||||||
|
|
||||||
|
#define STB_RECT_PACK_VERSION 1
|
||||||
|
|
||||||
|
#ifdef STBRP_STATIC
|
||||||
|
#define STBRP_DEF static
|
||||||
|
#else
|
||||||
|
#define STBRP_DEF extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct stbrp_context stbrp_context;
|
||||||
|
typedef struct stbrp_node stbrp_node;
|
||||||
|
typedef struct stbrp_rect stbrp_rect;
|
||||||
|
|
||||||
|
typedef int stbrp_coord;
|
||||||
|
|
||||||
|
#define STBRP__MAXVAL 0x7fffffff
|
||||||
|
// Mostly for internal use, but this is the maximum supported coordinate value.
|
||||||
|
|
||||||
|
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
|
||||||
|
// Assign packed locations to rectangles. The rectangles are of type
|
||||||
|
// 'stbrp_rect' defined below, stored in the array 'rects', and there
|
||||||
|
// are 'num_rects' many of them.
|
||||||
|
//
|
||||||
|
// Rectangles which are successfully packed have the 'was_packed' flag
|
||||||
|
// set to a non-zero value and 'x' and 'y' store the minimum location
|
||||||
|
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
|
||||||
|
// if you imagine y increasing downwards). Rectangles which do not fit
|
||||||
|
// have the 'was_packed' flag set to 0.
|
||||||
|
//
|
||||||
|
// You should not try to access the 'rects' array from another thread
|
||||||
|
// while this function is running, as the function temporarily reorders
|
||||||
|
// the array while it executes.
|
||||||
|
//
|
||||||
|
// To pack into another rectangle, you need to call stbrp_init_target
|
||||||
|
// again. To continue packing into the same rectangle, you can call
|
||||||
|
// this function again. Calling this multiple times with multiple rect
|
||||||
|
// arrays will probably produce worse packing results than calling it
|
||||||
|
// a single time with the full rectangle array, but the option is
|
||||||
|
// available.
|
||||||
|
//
|
||||||
|
// The function returns 1 if all of the rectangles were successfully
|
||||||
|
// packed and 0 otherwise.
|
||||||
|
|
||||||
|
struct stbrp_rect
|
||||||
|
{
|
||||||
|
// reserved for your use:
|
||||||
|
int id;
|
||||||
|
|
||||||
|
// input:
|
||||||
|
stbrp_coord w, h;
|
||||||
|
|
||||||
|
// output:
|
||||||
|
stbrp_coord x, y;
|
||||||
|
int was_packed; // non-zero if valid packing
|
||||||
|
|
||||||
|
}; // 16 bytes, nominally
|
||||||
|
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
|
||||||
|
// Initialize a rectangle packer to:
|
||||||
|
// pack a rectangle that is 'width' by 'height' in dimensions
|
||||||
|
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
|
||||||
|
//
|
||||||
|
// You must call this function every time you start packing into a new target.
|
||||||
|
//
|
||||||
|
// There is no "shutdown" function. The 'nodes' memory must stay valid for
|
||||||
|
// the following stbrp_pack_rects() call (or calls), but can be freed after
|
||||||
|
// the call (or calls) finish.
|
||||||
|
//
|
||||||
|
// Note: to guarantee best results, either:
|
||||||
|
// 1. make sure 'num_nodes' >= 'width'
|
||||||
|
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
|
||||||
|
//
|
||||||
|
// If you don't do either of the above things, widths will be quantized to multiples
|
||||||
|
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
|
||||||
|
//
|
||||||
|
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
|
||||||
|
// may run out of temporary storage and be unable to pack some rectangles.
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
|
||||||
|
// Optionally call this function after init but before doing any packing to
|
||||||
|
// change the handling of the out-of-temp-memory scenario, described above.
|
||||||
|
// If you call init again, this will be reset to the default (false).
|
||||||
|
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
|
||||||
|
// Optionally select which packing heuristic the library should use. Different
|
||||||
|
// heuristics will produce better/worse results for different data sets.
|
||||||
|
// If you call init again, this will be reset to the default.
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
STBRP_HEURISTIC_Skyline_default=0,
|
||||||
|
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
|
||||||
|
STBRP_HEURISTIC_Skyline_BF_sortHeight
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// the details of the following structures don't matter to you, but they must
|
||||||
|
// be visible so you can handle the memory allocations for them
|
||||||
|
|
||||||
|
struct stbrp_node
|
||||||
|
{
|
||||||
|
stbrp_coord x,y;
|
||||||
|
stbrp_node *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct stbrp_context
|
||||||
|
{
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int align;
|
||||||
|
int init_mode;
|
||||||
|
int heuristic;
|
||||||
|
int num_nodes;
|
||||||
|
stbrp_node *active_head;
|
||||||
|
stbrp_node *free_head;
|
||||||
|
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// IMPLEMENTATION SECTION
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
#ifndef STBRP_SORT
|
||||||
|
#include <stdlib.h>
|
||||||
|
#define STBRP_SORT qsort
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STBRP_ASSERT
|
||||||
|
#include <assert.h>
|
||||||
|
#define STBRP_ASSERT assert
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define STBRP__NOTUSED(v) (void)(v)
|
||||||
|
#define STBRP__CDECL __cdecl
|
||||||
|
#else
|
||||||
|
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
||||||
|
#define STBRP__CDECL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
STBRP__INIT_skyline = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
|
||||||
|
{
|
||||||
|
switch (context->init_mode) {
|
||||||
|
case STBRP__INIT_skyline:
|
||||||
|
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
|
||||||
|
context->heuristic = heuristic;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
STBRP_ASSERT(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
|
||||||
|
{
|
||||||
|
if (allow_out_of_mem)
|
||||||
|
// if it's ok to run out of memory, then don't bother aligning them;
|
||||||
|
// this gives better packing, but may fail due to OOM (even though
|
||||||
|
// the rectangles easily fit). @TODO a smarter approach would be to only
|
||||||
|
// quantize once we've hit OOM, then we could get rid of this parameter.
|
||||||
|
context->align = 1;
|
||||||
|
else {
|
||||||
|
// if it's not ok to run out of memory, then quantize the widths
|
||||||
|
// so that num_nodes is always enough nodes.
|
||||||
|
//
|
||||||
|
// I.e. num_nodes * align >= width
|
||||||
|
// align >= width / num_nodes
|
||||||
|
// align = ceil(width/num_nodes)
|
||||||
|
|
||||||
|
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i < num_nodes-1; ++i)
|
||||||
|
nodes[i].next = &nodes[i+1];
|
||||||
|
nodes[i].next = NULL;
|
||||||
|
context->init_mode = STBRP__INIT_skyline;
|
||||||
|
context->heuristic = STBRP_HEURISTIC_Skyline_default;
|
||||||
|
context->free_head = &nodes[0];
|
||||||
|
context->active_head = &context->extra[0];
|
||||||
|
context->width = width;
|
||||||
|
context->height = height;
|
||||||
|
context->num_nodes = num_nodes;
|
||||||
|
stbrp_setup_allow_out_of_mem(context, 0);
|
||||||
|
|
||||||
|
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
|
||||||
|
context->extra[0].x = 0;
|
||||||
|
context->extra[0].y = 0;
|
||||||
|
context->extra[0].next = &context->extra[1];
|
||||||
|
context->extra[1].x = (stbrp_coord) width;
|
||||||
|
context->extra[1].y = (1<<30);
|
||||||
|
context->extra[1].next = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find minimum y position if it starts at x1
|
||||||
|
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
|
||||||
|
{
|
||||||
|
stbrp_node *node = first;
|
||||||
|
int x1 = x0 + width;
|
||||||
|
int min_y, visited_width, waste_area;
|
||||||
|
|
||||||
|
STBRP__NOTUSED(c);
|
||||||
|
|
||||||
|
STBRP_ASSERT(first->x <= x0);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// skip in case we're past the node
|
||||||
|
while (node->next->x <= x0)
|
||||||
|
++node;
|
||||||
|
#else
|
||||||
|
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
|
||||||
|
#endif
|
||||||
|
|
||||||
|
STBRP_ASSERT(node->x <= x0);
|
||||||
|
|
||||||
|
min_y = 0;
|
||||||
|
waste_area = 0;
|
||||||
|
visited_width = 0;
|
||||||
|
while (node->x < x1) {
|
||||||
|
if (node->y > min_y) {
|
||||||
|
// raise min_y higher.
|
||||||
|
// we've accounted for all waste up to min_y,
|
||||||
|
// but we'll now add more waste for everything we've visted
|
||||||
|
waste_area += visited_width * (node->y - min_y);
|
||||||
|
min_y = node->y;
|
||||||
|
// the first time through, visited_width might be reduced
|
||||||
|
if (node->x < x0)
|
||||||
|
visited_width += node->next->x - x0;
|
||||||
|
else
|
||||||
|
visited_width += node->next->x - node->x;
|
||||||
|
} else {
|
||||||
|
// add waste area
|
||||||
|
int under_width = node->next->x - node->x;
|
||||||
|
if (under_width + visited_width > width)
|
||||||
|
under_width = width - visited_width;
|
||||||
|
waste_area += under_width * (min_y - node->y);
|
||||||
|
visited_width += under_width;
|
||||||
|
}
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pwaste = waste_area;
|
||||||
|
return min_y;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int x,y;
|
||||||
|
stbrp_node **prev_link;
|
||||||
|
} stbrp__findresult;
|
||||||
|
|
||||||
|
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
|
||||||
|
{
|
||||||
|
int best_waste = (1<<30), best_x, best_y = (1 << 30);
|
||||||
|
stbrp__findresult fr;
|
||||||
|
stbrp_node **prev, *node, *tail, **best = NULL;
|
||||||
|
|
||||||
|
// align to multiple of c->align
|
||||||
|
width = (width + c->align - 1);
|
||||||
|
width -= width % c->align;
|
||||||
|
STBRP_ASSERT(width % c->align == 0);
|
||||||
|
|
||||||
|
// if it can't possibly fit, bail immediately
|
||||||
|
if (width > c->width || height > c->height) {
|
||||||
|
fr.prev_link = NULL;
|
||||||
|
fr.x = fr.y = 0;
|
||||||
|
return fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
node = c->active_head;
|
||||||
|
prev = &c->active_head;
|
||||||
|
while (node->x + width <= c->width) {
|
||||||
|
int y,waste;
|
||||||
|
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
|
||||||
|
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
|
||||||
|
// bottom left
|
||||||
|
if (y < best_y) {
|
||||||
|
best_y = y;
|
||||||
|
best = prev;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// best-fit
|
||||||
|
if (y + height <= c->height) {
|
||||||
|
// can only use it if it first vertically
|
||||||
|
if (y < best_y || (y == best_y && waste < best_waste)) {
|
||||||
|
best_y = y;
|
||||||
|
best_waste = waste;
|
||||||
|
best = prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prev = &node->next;
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
best_x = (best == NULL) ? 0 : (*best)->x;
|
||||||
|
|
||||||
|
// if doing best-fit (BF), we also have to try aligning right edge to each node position
|
||||||
|
//
|
||||||
|
// e.g, if fitting
|
||||||
|
//
|
||||||
|
// ____________________
|
||||||
|
// |____________________|
|
||||||
|
//
|
||||||
|
// into
|
||||||
|
//
|
||||||
|
// | |
|
||||||
|
// | ____________|
|
||||||
|
// |____________|
|
||||||
|
//
|
||||||
|
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
|
||||||
|
//
|
||||||
|
// This makes BF take about 2x the time
|
||||||
|
|
||||||
|
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
|
||||||
|
tail = c->active_head;
|
||||||
|
node = c->active_head;
|
||||||
|
prev = &c->active_head;
|
||||||
|
// find first node that's admissible
|
||||||
|
while (tail->x < width)
|
||||||
|
tail = tail->next;
|
||||||
|
while (tail) {
|
||||||
|
int xpos = tail->x - width;
|
||||||
|
int y,waste;
|
||||||
|
STBRP_ASSERT(xpos >= 0);
|
||||||
|
// find the left position that matches this
|
||||||
|
while (node->next->x <= xpos) {
|
||||||
|
prev = &node->next;
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
|
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
|
||||||
|
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
|
||||||
|
if (y + height <= c->height) {
|
||||||
|
if (y <= best_y) {
|
||||||
|
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
||||||
|
best_x = xpos;
|
||||||
|
//STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
|
||||||
|
best_y = y;
|
||||||
|
best_waste = waste;
|
||||||
|
best = prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tail = tail->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fr.prev_link = best;
|
||||||
|
fr.x = best_x;
|
||||||
|
fr.y = best_y;
|
||||||
|
return fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
|
||||||
|
{
|
||||||
|
// find best position according to heuristic
|
||||||
|
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
|
||||||
|
stbrp_node *node, *cur;
|
||||||
|
|
||||||
|
// bail if:
|
||||||
|
// 1. it failed
|
||||||
|
// 2. the best node doesn't fit (we don't always check this)
|
||||||
|
// 3. we're out of memory
|
||||||
|
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
|
||||||
|
res.prev_link = NULL;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// on success, create new node
|
||||||
|
node = context->free_head;
|
||||||
|
node->x = (stbrp_coord) res.x;
|
||||||
|
node->y = (stbrp_coord) (res.y + height);
|
||||||
|
|
||||||
|
context->free_head = node->next;
|
||||||
|
|
||||||
|
// insert the new node into the right starting point, and
|
||||||
|
// let 'cur' point to the remaining nodes needing to be
|
||||||
|
// stiched back in
|
||||||
|
|
||||||
|
cur = *res.prev_link;
|
||||||
|
if (cur->x < res.x) {
|
||||||
|
// preserve the existing one, so start testing with the next one
|
||||||
|
stbrp_node *next = cur->next;
|
||||||
|
cur->next = node;
|
||||||
|
cur = next;
|
||||||
|
} else {
|
||||||
|
*res.prev_link = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
// from here, traverse cur and free the nodes, until we get to one
|
||||||
|
// that shouldn't be freed
|
||||||
|
while (cur->next && cur->next->x <= res.x + width) {
|
||||||
|
stbrp_node *next = cur->next;
|
||||||
|
// move the current node to the free list
|
||||||
|
cur->next = context->free_head;
|
||||||
|
context->free_head = cur;
|
||||||
|
cur = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
// stitch the list back in
|
||||||
|
node->next = cur;
|
||||||
|
|
||||||
|
if (cur->x < res.x + width)
|
||||||
|
cur->x = (stbrp_coord) (res.x + width);
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
cur = context->active_head;
|
||||||
|
while (cur->x < context->width) {
|
||||||
|
STBRP_ASSERT(cur->x < cur->next->x);
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
STBRP_ASSERT(cur->next == NULL);
|
||||||
|
|
||||||
|
{
|
||||||
|
int count=0;
|
||||||
|
cur = context->active_head;
|
||||||
|
while (cur) {
|
||||||
|
cur = cur->next;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
cur = context->free_head;
|
||||||
|
while (cur) {
|
||||||
|
cur = cur->next;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
STBRP_ASSERT(count == context->num_nodes+2);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
||||||
|
{
|
||||||
|
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||||
|
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||||
|
if (p->h > q->h)
|
||||||
|
return -1;
|
||||||
|
if (p->h < q->h)
|
||||||
|
return 1;
|
||||||
|
return (p->w > q->w) ? -1 : (p->w < q->w);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
||||||
|
{
|
||||||
|
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||||
|
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||||
|
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||||
|
}
|
||||||
|
|
||||||
|
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
||||||
|
{
|
||||||
|
int i, all_rects_packed = 1;
|
||||||
|
|
||||||
|
// we use the 'was_packed' field internally to allow sorting/unsorting
|
||||||
|
for (i=0; i < num_rects; ++i) {
|
||||||
|
rects[i].was_packed = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort according to heuristic
|
||||||
|
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||||
|
|
||||||
|
for (i=0; i < num_rects; ++i) {
|
||||||
|
if (rects[i].w == 0 || rects[i].h == 0) {
|
||||||
|
rects[i].x = rects[i].y = 0; // empty rect needs no space
|
||||||
|
} else {
|
||||||
|
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
||||||
|
if (fr.prev_link) {
|
||||||
|
rects[i].x = (stbrp_coord) fr.x;
|
||||||
|
rects[i].y = (stbrp_coord) fr.y;
|
||||||
|
} else {
|
||||||
|
rects[i].x = rects[i].y = STBRP__MAXVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// unsort
|
||||||
|
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||||
|
|
||||||
|
// set was_packed flags and all_rects_packed status
|
||||||
|
for (i=0; i < num_rects; ++i) {
|
||||||
|
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
|
||||||
|
if (!rects[i].was_packed)
|
||||||
|
all_rects_packed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the all_rects_packed status
|
||||||
|
return all_rects_packed;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
This software is available under 2 licenses -- choose whichever you prefer.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
ALTERNATIVE A - MIT License
|
||||||
|
Copyright (c) 2017 Sean Barrett
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||||
|
software, either in source code form or as a compiled binary, for any purpose,
|
||||||
|
commercial or non-commercial, and by any means.
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||||
|
software dedicate any and all copyright interest in the software to the public
|
||||||
|
domain. We make this dedication for the benefit of the public at large and to
|
||||||
|
the detriment of our heirs and successors. We intend this dedication to be an
|
||||||
|
overt act of relinquishment in perpetuity of all present and future rights to
|
||||||
|
this software under copyright law.
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
1527
external/include/imgui/imstb_textedit.h
vendored
Normal file
1527
external/include/imgui/imstb_textedit.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
5085
external/include/imgui/imstb_truetype.h
vendored
Normal file
5085
external/include/imgui/imstb_truetype.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
6574
external/include/m3d.h
vendored
Normal file
6574
external/include/m3d.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
8
imgui.ini
Normal file
8
imgui.ini
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[Window][Debug##Default]
|
||||||
|
Pos=60,60
|
||||||
|
Size=400,400
|
||||||
|
|
||||||
|
[Window][Hello, world!]
|
||||||
|
Pos=47,251
|
||||||
|
Size=175,174
|
||||||
|
|
||||||
385
main.cpp
385
main.cpp
@ -8,17 +8,23 @@
|
|||||||
# define APIENTRY
|
# define APIENTRY
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "glad/gl.h"
|
||||||
|
#include "gl.c"
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_impl_sdl3.h"
|
||||||
|
#include "imgui_impl_opengl3.h"
|
||||||
|
|
||||||
#define CGLTF_IMPLEMENTATION
|
#define CGLTF_IMPLEMENTATION
|
||||||
#include "cgltf.h"
|
#include "cgltf.h"
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
|
|
||||||
#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
|
#define M3D_IMPLEMENTATION
|
||||||
#include "cglm/cglm.h"
|
#include "m3d.h"
|
||||||
|
|
||||||
#include "glad/gl.h"
|
#include "cglm/cglm.h"
|
||||||
#include "gl.c"
|
|
||||||
|
|
||||||
#include "SDL3/SDL.h"
|
#include "SDL3/SDL.h"
|
||||||
#include "SDL3/SDL_main.h"
|
#include "SDL3/SDL_main.h"
|
||||||
@ -177,6 +183,11 @@ struct Vec2
|
|||||||
struct { f32 r, g; };
|
struct { f32 r, g; };
|
||||||
struct { f32 w, h; };
|
struct { f32 w, h; };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Vec2 operator-(const Vec2 &rhs)
|
||||||
|
{
|
||||||
|
return (Vec2){ .x = x-rhs.x, .y = y-rhs.y };
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Vec3
|
struct Vec3
|
||||||
@ -187,6 +198,38 @@ struct Vec3
|
|||||||
struct { f32 x, y, z; };
|
struct { f32 x, y, z; };
|
||||||
struct { f32 r, g, b; };
|
struct { f32 r, g, b; };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void operator+=(const Vec3 &rhs)
|
||||||
|
{
|
||||||
|
x += rhs.x;
|
||||||
|
y += rhs.y;
|
||||||
|
z += rhs.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3 operator+(const Vec3 &rhs)
|
||||||
|
{
|
||||||
|
return (Vec3){ .x = x+rhs.x, .y = y+rhs.y, .z = z+rhs.z };
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3 operator/(const f32 rhs)
|
||||||
|
{
|
||||||
|
return (Vec3){ .x = x/rhs, .y = y/rhs, .z = z/rhs };
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3 operator-(const Vec3 &rhs)
|
||||||
|
{
|
||||||
|
return (Vec3){ .x = x-rhs.x, .y = y-rhs.y, .z = z-rhs.z };
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3 operator*(const Vec3 &rhs)
|
||||||
|
{
|
||||||
|
return (Vec3){ .x = x*rhs.x, .y = r*rhs.y, .z = z*rhs.z };
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3 operator*(const f32 rhs)
|
||||||
|
{
|
||||||
|
return (Vec3){ .x = x*rhs, .y = y*rhs, .z = z*rhs };
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Vec4
|
struct Vec4
|
||||||
@ -207,7 +250,14 @@ struct Mat4
|
|||||||
mat4 matrix;
|
mat4 matrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
Vec4 operator*(const Vec4 &vec)
|
Mat4 operator*(Mat4 mat)
|
||||||
|
{
|
||||||
|
Mat4 result;
|
||||||
|
glm_mat4_mul(matrix, mat.matrix, result.matrix);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec4 operator*(Vec4 vec)
|
||||||
{
|
{
|
||||||
Vec4 result;
|
Vec4 result;
|
||||||
glm_mat4_mulv(matrix, (f32 *)vec.v, result.v);
|
glm_mat4_mulv(matrix, (f32 *)vec.v, result.v);
|
||||||
@ -221,16 +271,35 @@ struct Mat4
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Vec4 MakeVec4(f32 x, f32 y, f32 z, f32 w) { return (Vec4){ .x = x, .y = y, .z = z, .w = w }; }
|
struct Quat
|
||||||
Vec4 MakeVec4(f32 v) { return (Vec4){ .x = v, .y = v, .z = v, .w = v }; }
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
f32 v[4];
|
||||||
|
versor quat;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
Vec4 MakeVec4(Vec3 v, f32 w) { return (Vec4){ .x = v.x, .y = v.y, .z = v.z, .w = w }; }
|
typedef Vector2<u32> UVec2;
|
||||||
Vec3 MakeVec3(f32 x, f32 y, f32 z) { return (Vec3){ .x = x, .y = y, .z = z }; }
|
typedef Vector2<i32> IVec2;
|
||||||
Vec3 MakeVec3(f32 v) { return (Vec3){ .x = v, .y = v, .z = v }; }
|
|
||||||
|
|
||||||
Vec3 MakeVec3(Vec2 v, f32 z) { return (Vec3){ .x = v.x, .y = v.y, .z = z }; }
|
typedef Vector3<u32> UVec3;
|
||||||
Vec2 MakeVec2(f32 x, f32 y) { return (Vec2){ .x = x, .y = y }; }
|
typedef Vector3<i32> IVec3;
|
||||||
Vec2 MakeVec2(f32 v) { return (Vec2){ .x = v, .y = v }; }
|
|
||||||
|
typedef Vector4<u32> UVec4;
|
||||||
|
typedef Vector4<i32> IVec4;
|
||||||
|
|
||||||
|
Vec4 MakeVec4(f32 x, f32 y, f32 z, f32 w) { return (Vec4){ .x = x, .y = y, .z = z, .w = w }; }
|
||||||
|
Vec4 MakeVec4(f32 v) { return (Vec4){ .x = v, .y = v, .z = v, .w = v }; }
|
||||||
|
Vec4 MakeVec4(Vec3 v, f32 w) { return (Vec4){ .x = v.x, .y = v.y, .z = v.z, .w = w }; }
|
||||||
|
|
||||||
|
Vec3 MakeVec3(f32 x, f32 y, f32 z) { return (Vec3){ .x = x, .y = y, .z = z }; }
|
||||||
|
Vec3 MakeVec3(f32 v) { return (Vec3){ .x = v, .y = v, .z = v }; }
|
||||||
|
Vec3 MakeVec3(Vec2 v, f32 z) { return (Vec3){ .x = v.x, .y = v.y, .z = z }; }
|
||||||
|
Vec3 MakeVec3(Vec4 v) { return (Vec3){ .x = v.x, .y = v.y, .z = v.z }; }
|
||||||
|
|
||||||
|
Vec2 MakeVec2(f32 x, f32 y) { return (Vec2){ .x = x, .y = y }; }
|
||||||
|
Vec2 MakeVec2(f32 v) { return (Vec2){ .x = v, .y = v }; }
|
||||||
|
|
||||||
Mat4 MakeMat4(f32 matrix[16])
|
Mat4 MakeMat4(f32 matrix[16])
|
||||||
{
|
{
|
||||||
@ -245,23 +314,6 @@ Mat4 MakeMat4(f32 matrix[16])
|
|||||||
|
|
||||||
#define Mat4(...) MakeMat4(__VA_ARGS__)
|
#define Mat4(...) MakeMat4(__VA_ARGS__)
|
||||||
|
|
||||||
Vec3
|
|
||||||
Transform(Vec3 &vec, Mat4 &mat, f32 last = 1.0)
|
|
||||||
{
|
|
||||||
Vec3 dst = {};
|
|
||||||
glm_mat4_mulv3(mat.matrix, vec.v, last, dst.v);
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef Vector2<u32> UVec2;
|
|
||||||
typedef Vector2<i32> IVec2;
|
|
||||||
|
|
||||||
typedef Vector3<u32> UVec3;
|
|
||||||
typedef Vector3<i32> IVec3;
|
|
||||||
|
|
||||||
typedef Vector4<u32> UVec4;
|
|
||||||
typedef Vector4<i32> IVec4;
|
|
||||||
|
|
||||||
typedef GLuint TextureID;
|
typedef GLuint TextureID;
|
||||||
typedef GLuint PipelineID;
|
typedef GLuint PipelineID;
|
||||||
typedef GLuint ShaderID;
|
typedef GLuint ShaderID;
|
||||||
@ -334,16 +386,25 @@ enum MaterialMapIndex
|
|||||||
#define Min(x, y) (x < y ? x : y)
|
#define Min(x, y) (x < y ? x : y)
|
||||||
|
|
||||||
TextureID CreateTexture(ImageBuffer image_buffer);
|
TextureID CreateTexture(ImageBuffer image_buffer);
|
||||||
template<typename T> BufferID CreateBuffer(T *data);
|
template<typename T> BufferID CreateBuffer(T *data, bool static_draw);
|
||||||
ModelBuffers CreateModelBuffers();
|
ModelBuffers CreateModelBuffers();
|
||||||
|
|
||||||
struct Arena;
|
struct Arena;
|
||||||
|
|
||||||
|
struct Camera
|
||||||
|
{
|
||||||
|
Vec3 velocity;
|
||||||
|
Vec3 position;
|
||||||
|
f32 pitch;
|
||||||
|
f32 yaw;
|
||||||
|
};
|
||||||
|
|
||||||
struct ShaderGlobals
|
struct ShaderGlobals
|
||||||
{
|
{
|
||||||
Mat4 projection;
|
Mat4 projection;
|
||||||
Mat4 view;
|
Mat4 view;
|
||||||
Mat4 model_matrix;
|
Vec3 camera_position;
|
||||||
|
Vec3 ambient;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ShaderModelState
|
struct ShaderModelState
|
||||||
@ -358,6 +419,7 @@ struct ShaderModelState
|
|||||||
b32 irradiance_texture;
|
b32 irradiance_texture;
|
||||||
b32 prefilter_texture;
|
b32 prefilter_texture;
|
||||||
b32 brdf_texture;
|
b32 brdf_texture;
|
||||||
|
b32 no_material;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ShaderInstanceState
|
struct ShaderInstanceState
|
||||||
@ -370,6 +432,7 @@ struct Renderer
|
|||||||
SDL_Window* window;
|
SDL_Window* window;
|
||||||
SDL_GLContext gl_context;
|
SDL_GLContext gl_context;
|
||||||
Arena *arena;
|
Arena *arena;
|
||||||
|
Camera camera;
|
||||||
IVec2 resolution;
|
IVec2 resolution;
|
||||||
PipelineID pipeline_id;
|
PipelineID pipeline_id;
|
||||||
u32 texture_locations[MMI_Max];
|
u32 texture_locations[MMI_Max];
|
||||||
@ -377,10 +440,15 @@ struct Renderer
|
|||||||
BufferID default_material;
|
BufferID default_material;
|
||||||
BufferID globals_buffer_id;
|
BufferID globals_buffer_id;
|
||||||
ShaderGlobals globals;
|
ShaderGlobals globals;
|
||||||
|
BufferID default_material_buffer_id;
|
||||||
|
BufferID default_shader_state_buffer_id;
|
||||||
|
|
||||||
|
b32 exit;
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer g_renderer;
|
Renderer g_renderer = {};
|
||||||
|
|
||||||
|
#include "math.cpp"
|
||||||
#include "alloc.cpp"
|
#include "alloc.cpp"
|
||||||
#include "util.cpp"
|
#include "util.cpp"
|
||||||
#include "assets.cpp"
|
#include "assets.cpp"
|
||||||
@ -392,6 +460,62 @@ if(cond) \
|
|||||||
goto InitFailure; \
|
goto InitFailure; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mat4
|
||||||
|
RotationMatrix(Camera &camera)
|
||||||
|
{
|
||||||
|
Quat pitch_rotation = AngleAxis(camera.pitch, Vec3(1.0f, 0.0f, 0.0f));
|
||||||
|
Quat yaw_rotation = AngleAxis(camera.yaw, Vec3(0.0f, -1.0f, 0.0f));
|
||||||
|
|
||||||
|
return ToMat4(yaw_rotation) * ToMat4(pitch_rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mat4
|
||||||
|
ViewMatrix(Camera &camera)
|
||||||
|
{
|
||||||
|
Mat4 camera_translation = Translate(IdentityMatrix(), camera.position);
|
||||||
|
Mat4 camera_rotation = RotationMatrix(camera);
|
||||||
|
return Inverse(camera_translation * camera_rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ProcessEvent(Camera &camera, SDL_Event &event)
|
||||||
|
{
|
||||||
|
switch(event.type)
|
||||||
|
{
|
||||||
|
case SDL_EVENT_KEY_DOWN:
|
||||||
|
switch(event.key.scancode)
|
||||||
|
{
|
||||||
|
case SDL_SCANCODE_W: camera.velocity.z = -1; break;
|
||||||
|
case SDL_SCANCODE_S: camera.velocity.z = +1; break;
|
||||||
|
case SDL_SCANCODE_A: camera.velocity.x = -1; break;
|
||||||
|
case SDL_SCANCODE_D: camera.velocity.x = +1; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDL_EVENT_KEY_UP:
|
||||||
|
switch(event.key.scancode)
|
||||||
|
{
|
||||||
|
case SDL_SCANCODE_W:
|
||||||
|
case SDL_SCANCODE_S: camera.velocity.z = 0; break;
|
||||||
|
case SDL_SCANCODE_A:
|
||||||
|
case SDL_SCANCODE_D: camera.velocity.x = 0; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDL_EVENT_MOUSE_MOTION:
|
||||||
|
camera.yaw += (f32)(event.motion.xrel)/500.0f;
|
||||||
|
camera.pitch -= (f32)(event.motion.yrel)/500.0f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Update(Camera &camera)
|
||||||
|
{
|
||||||
|
Mat4 camera_rotation = RotationMatrix(camera);
|
||||||
|
camera.position += Vec3(camera_rotation * Vec4(camera.velocity*0.5f, 0.0f));
|
||||||
|
}
|
||||||
|
|
||||||
ModelBuffers
|
ModelBuffers
|
||||||
CreateModelBuffers()
|
CreateModelBuffers()
|
||||||
{
|
{
|
||||||
@ -518,58 +642,65 @@ UpdateBuffer(BufferID target, T *data)
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
BufferID
|
BufferID
|
||||||
CreateBuffer(T *data)
|
CreateBuffer(T *data, bool static_draw)
|
||||||
{
|
{
|
||||||
BufferID buffer;
|
BufferID buffer;
|
||||||
|
|
||||||
glGenBuffers(1, &buffer);
|
glGenBuffers(1, &buffer);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, buffer);
|
glBindBuffer(GL_UNIFORM_BUFFER, buffer);
|
||||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(T), data, GL_STATIC_DRAW);
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(T), data, static_draw ? GL_STATIC_DRAW : GL_DYNAMIC_DRAW);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BUILD_DEBUG
|
#ifdef BUILD_DEBUG
|
||||||
void APIENTRY glDebugOutput(GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, const char *message, const void *userParam)
|
void APIENTRY
|
||||||
|
glDebugOutput(GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, const char *message, const void *userParam)
|
||||||
{
|
{
|
||||||
// ignore non-significant error/warning codes
|
// ignore non-significant error/warning codes
|
||||||
if(id == 131169 || id == 131185 || id == 131218 || id == 131204) return;
|
if(id == 131169 || id == 131185 || id == 131218 || id == 131204) return;
|
||||||
|
|
||||||
printf("---------------\n");
|
printf("---------------\n");
|
||||||
|
|
||||||
|
b32 shader_failure = false;
|
||||||
|
b32 error_level = false;
|
||||||
|
|
||||||
switch (source)
|
switch (source)
|
||||||
{
|
{
|
||||||
case GL_DEBUG_SOURCE_API: printf("Source: API\n"); break;
|
case GL_DEBUG_SOURCE_API: printf("Source: API\n"); break;
|
||||||
case GL_DEBUG_SOURCE_WINDOW_SYSTEM: printf("Source: Window System\n"); break;
|
case GL_DEBUG_SOURCE_WINDOW_SYSTEM: printf("Source: Window System\n"); break;
|
||||||
case GL_DEBUG_SOURCE_SHADER_COMPILER: printf("Source: Shader Compiler\n"); break;
|
case GL_DEBUG_SOURCE_SHADER_COMPILER: printf("Source: Shader Compiler\n"); shader_failure = true; break;
|
||||||
case GL_DEBUG_SOURCE_THIRD_PARTY: printf("Source: Third Party\n"); break;
|
case GL_DEBUG_SOURCE_THIRD_PARTY: printf("Source: Third Party\n"); break;
|
||||||
case GL_DEBUG_SOURCE_APPLICATION: printf("Source: Application\n"); break;
|
case GL_DEBUG_SOURCE_APPLICATION: printf("Source: Application\n"); break;
|
||||||
case GL_DEBUG_SOURCE_OTHER: printf("Source: Other\n"); break;
|
case GL_DEBUG_SOURCE_OTHER: printf("Source: Other\n"); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case GL_DEBUG_TYPE_ERROR: printf("Type: Error\n"); break;
|
case GL_DEBUG_TYPE_ERROR: printf("Type: Error\n"); error_level = true; break;
|
||||||
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: printf("Type: Deprecated Behaviour\n"); break;
|
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: printf("Type: Deprecated Behaviour\n"); break;
|
||||||
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: printf("Type: Undefined Behaviour\n"); break;
|
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: printf("Type: Undefined Behaviour\n"); break;
|
||||||
case GL_DEBUG_TYPE_PORTABILITY: printf("Type: Portability\n"); break;
|
case GL_DEBUG_TYPE_PORTABILITY: printf("Type: Portability\n"); break;
|
||||||
case GL_DEBUG_TYPE_PERFORMANCE: printf("Type: Performance\n"); break;
|
case GL_DEBUG_TYPE_PERFORMANCE: printf("Type: Performance\n"); break;
|
||||||
case GL_DEBUG_TYPE_MARKER: printf("Type: Marker\n"); break;
|
case GL_DEBUG_TYPE_MARKER: printf("Type: Marker\n"); break;
|
||||||
case GL_DEBUG_TYPE_PUSH_GROUP: printf("Type: Push Group\n"); break;
|
case GL_DEBUG_TYPE_PUSH_GROUP: printf("Type: Push Group\n"); break;
|
||||||
case GL_DEBUG_TYPE_POP_GROUP: printf("Type: Pop Group\n"); break;
|
case GL_DEBUG_TYPE_POP_GROUP: printf("Type: Pop Group\n"); break;
|
||||||
case GL_DEBUG_TYPE_OTHER: printf("Type: Other\n"); break;
|
case GL_DEBUG_TYPE_OTHER: printf("Type: Other\n"); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (severity)
|
switch (severity)
|
||||||
{
|
{
|
||||||
case GL_DEBUG_SEVERITY_HIGH: printf("Severity: high\n\n"); break;
|
case GL_DEBUG_SEVERITY_HIGH: printf("Severity: high\n\n"); break;
|
||||||
case GL_DEBUG_SEVERITY_MEDIUM: printf("Severity: medium\n\n"); break;
|
case GL_DEBUG_SEVERITY_MEDIUM: printf("Severity: medium\n\n"); break;
|
||||||
case GL_DEBUG_SEVERITY_LOW: printf("Severity: low\n\n"); break;
|
case GL_DEBUG_SEVERITY_LOW: printf("Severity: low\n\n"); break;
|
||||||
case GL_DEBUG_SEVERITY_NOTIFICATION: printf("Severity: notification\n\n"); break;
|
case GL_DEBUG_SEVERITY_NOTIFICATION: printf("Severity: notification\n\n"); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Debug message (%llu): %s\n", id, message);
|
printf("Debug message (%llu): %s\n", id, message);
|
||||||
|
|
||||||
|
if(shader_failure && error_level)
|
||||||
|
g_renderer.exit = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -644,9 +775,28 @@ Init(Renderer *renderer)
|
|||||||
InitCheckError(!renderer->pipeline_id, "Unable to create pipeline");
|
InitCheckError(!renderer->pipeline_id, "Unable to create pipeline");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
ImGui::CreateContext();
|
||||||
|
ImGuiIO &io = ImGui::GetIO(); (void)io;
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
||||||
|
|
||||||
|
ImGui::StyleColorsDark();
|
||||||
|
|
||||||
|
f32 main_scale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay());
|
||||||
|
|
||||||
|
ImGuiStyle &style = ImGui::GetStyle();
|
||||||
|
style.ScaleAllSizes(main_scale);
|
||||||
|
style.FontScaleDpi = main_scale;
|
||||||
|
|
||||||
|
ImGui_ImplSDL3_InitForOpenGL(renderer->window, renderer->gl_context);
|
||||||
|
ImGui_ImplOpenGL3_Init("#version 130");
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
renderer->default_texture = CreateTexture(DEFAULT_TEXTURE);
|
renderer->default_texture = CreateTexture(DEFAULT_TEXTURE);
|
||||||
renderer->default_material = CreateBuffer(&DEFAULT_MATERIAL);
|
renderer->default_material = CreateBuffer(&DEFAULT_MATERIAL, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -663,10 +813,15 @@ Init(Renderer *renderer)
|
|||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
renderer->globals.projection = IdentityMatrix();
|
renderer->globals.projection = IdentityMatrix();
|
||||||
renderer->globals.view = LookAt(Vec3(0.0f, 5.0f, 0.0f), Vec3(0.0f, 30.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f));
|
renderer->globals.view = LookAt(Vec3(15.0f, 0.0f, 0.0f), Vec3(0.0f, 5.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f));
|
||||||
renderer->globals.model_matrix = Translate(IdentityMatrix(), Vec3(0.0f, 0.0f, 20.0f));
|
renderer->globals.ambient = Vec3(0.5);
|
||||||
renderer->globals_buffer_id = CreateBuffer(&renderer->globals);
|
|
||||||
|
renderer->globals_buffer_id = CreateBuffer(&renderer->globals, false);
|
||||||
|
|
||||||
|
ShaderModelState shader_model_state = { .no_material = true };
|
||||||
|
renderer->default_material_buffer_id = CreateBuffer(&DEFAULT_MATERIAL, true);
|
||||||
|
renderer->default_shader_state_buffer_id = CreateBuffer(&shader_model_state, true);
|
||||||
|
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, 0, g_renderer.globals_buffer_id);
|
glBindBufferBase(GL_UNIFORM_BUFFER, 0, g_renderer.globals_buffer_id);
|
||||||
}
|
}
|
||||||
@ -679,15 +834,51 @@ InitFailure:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DrawModel(Model *model, BufferID model_matrix_id)
|
||||||
|
{
|
||||||
|
glBindVertexArray(model->buffers.vertex_array);
|
||||||
|
for(u64 i = 0; i < model->meshes.length; i += 1)
|
||||||
|
{
|
||||||
|
if(model->materials.length)
|
||||||
|
{
|
||||||
|
Material *material = model->materials.ptr + model->meshes[i].material_index;
|
||||||
|
for(u64 j = 0; j < MMI_Max; j += 1)
|
||||||
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0+j);
|
||||||
|
glUniform1i(g_renderer.texture_locations[j], j);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, material->textures[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
glBindBufferBase(GL_UNIFORM_BUFFER, 1, material->shader_state_buffer_id);
|
||||||
|
glBindBufferBase(GL_UNIFORM_BUFFER, 3, material->buffer_id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glBindBufferBase(GL_UNIFORM_BUFFER, 1, g_renderer.default_shader_state_buffer_id);
|
||||||
|
glBindBufferBase(GL_UNIFORM_BUFFER, 3, g_renderer.default_material_buffer_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
glBindBufferBase(GL_UNIFORM_BUFFER, 2, model_matrix_id);
|
||||||
|
|
||||||
|
glDrawElements(GL_TRIANGLES, model->meshes[i].index_length, GL_UNSIGNED_INT, (void *)(u64)(model->meshes[i].index_start*sizeof(u32)));
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
}
|
||||||
|
glBindVertexArray(0);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char** argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
bool running = Init(&g_renderer);
|
bool running = Init(&g_renderer);
|
||||||
|
|
||||||
Model tree_model = {};
|
Model tree_model = {};
|
||||||
|
Model yoder = {};
|
||||||
if(running)
|
if(running)
|
||||||
{
|
{
|
||||||
running = LoadGLTF(g_renderer.arena, &tree_model, String8Lit("./assets/StylizedNature/glTF/CherryBlossom_1.gltf"));
|
running &= LoadGLTF(g_renderer.arena, &tree_model, String8Lit("./assets/StylizedNature/glTF/CherryBlossom_1.gltf"));
|
||||||
|
running &= LoadM3D(g_renderer.arena, &yoder, String8Lit("./assets/yoda.m3d"));
|
||||||
|
|
||||||
if(!running)
|
if(!running)
|
||||||
{
|
{
|
||||||
@ -695,16 +886,29 @@ main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4 model_matrix = IdentityMatrix();
|
Mat4 model_matrix = Translate(IdentityMatrix(), Vec3(0.0f, 0.0f, 0.0f));
|
||||||
BufferID model_matrix_buffer_id = CreateBuffer(&model_matrix);
|
BufferID model_matrix_buffer_id = CreateBuffer(&model_matrix, false);
|
||||||
|
|
||||||
|
Mat4 yoder_matrix = Translate(IdentityMatrix(), Vec3(2.0f, 0.0f, 0.0f));
|
||||||
|
BufferID yoder_matrix_id = CreateBuffer(&yoder_matrix, false);
|
||||||
|
|
||||||
while(running)
|
while(running)
|
||||||
{
|
{
|
||||||
BeginScratch();
|
BeginScratch();
|
||||||
|
|
||||||
|
if(g_renderer.exit)
|
||||||
|
{
|
||||||
|
running = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while(SDL_PollEvent(&event))
|
while(SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
|
ImGui_ImplSDL3_ProcessEvent(&event);
|
||||||
|
|
||||||
|
ProcessEvent(g_renderer.camera, event);
|
||||||
|
|
||||||
if(event.type == SDL_EVENT_QUIT)
|
if(event.type == SDL_EVENT_QUIT)
|
||||||
{
|
{
|
||||||
running = false;
|
running = false;
|
||||||
@ -716,6 +920,8 @@ main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Update(g_renderer.camera);
|
||||||
|
|
||||||
i32 w, h;
|
i32 w, h;
|
||||||
SDL_GetWindowSize(g_renderer.window, &w, &h);
|
SDL_GetWindowSize(g_renderer.window, &w, &h);
|
||||||
if(g_renderer.resolution.w != w || g_renderer.resolution.h != h)
|
if(g_renderer.resolution.w != w || g_renderer.resolution.h != h)
|
||||||
@ -723,7 +929,7 @@ main(int argc, char** argv)
|
|||||||
glViewport(0, 0, (int)w, (int)h);
|
glViewport(0, 0, (int)w, (int)h);
|
||||||
g_renderer.resolution.w = w;
|
g_renderer.resolution.w = w;
|
||||||
g_renderer.resolution.h = h;
|
g_renderer.resolution.h = h;
|
||||||
g_renderer.globals.projection = Perspective(Radians(90.0f), (f32)(w)/(f32)(h), 10000.0f, 0.1f);
|
g_renderer.globals.projection = Perspective(Radians(90.0f), (f32)(w)/(f32)(h), 0.1f, 10000.0f);
|
||||||
UpdateBuffer(g_renderer.globals_buffer_id, &g_renderer.globals);
|
UpdateBuffer(g_renderer.globals_buffer_id, &g_renderer.globals);
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, 0, g_renderer.globals_buffer_id);
|
glBindBufferBase(GL_UNIFORM_BUFFER, 0, g_renderer.globals_buffer_id);
|
||||||
}
|
}
|
||||||
@ -736,31 +942,46 @@ main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
ImGui_ImplSDL3_NewFrame();
|
||||||
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
ImGui::Begin("Hello, world!");
|
||||||
|
|
||||||
|
if(ImGui::Button("Yeah"))
|
||||||
|
{
|
||||||
|
Logf("yeah!");
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
glClearColor(0.2, 0.3, 0.7, 1.0);
|
glClearColor(0.2, 0.3, 0.7, 1.0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
static f32 time_passed = 0.0f;
|
||||||
|
static f32 delta = 0.0f;
|
||||||
|
const f32 radius = 15.0f;
|
||||||
|
|
||||||
|
f32 new_time = (f32)SDL_GetTicks();
|
||||||
|
f32 d = (new_time - time_passed) / 100.0f;
|
||||||
|
time_passed = new_time;
|
||||||
|
|
||||||
|
delta += d;
|
||||||
|
|
||||||
|
f32 cam_x = sin(delta * 0.1f) * radius;
|
||||||
|
f32 cam_z = cos(delta * 0.1f) * radius;
|
||||||
|
|
||||||
|
g_renderer.globals.camera_position = g_renderer.camera.position;
|
||||||
|
g_renderer.globals.view = ViewMatrix(g_renderer.camera);
|
||||||
|
UpdateBuffer(g_renderer.globals_buffer_id, &g_renderer.globals);
|
||||||
|
|
||||||
glUseProgram(g_renderer.pipeline_id);
|
glUseProgram(g_renderer.pipeline_id);
|
||||||
|
|
||||||
glBindVertexArray(tree_model.buffers.vertex_array);
|
DrawModel(&tree_model, model_matrix_buffer_id);
|
||||||
for(u64 i = 0; i < tree_model.meshes.length; i += 1)
|
DrawModel(&yoder, yoder_matrix_id);
|
||||||
{
|
|
||||||
Material *material = tree_model.materials.ptr + tree_model.meshes[i].material_index;
|
|
||||||
for(u64 j = 0; j < MMI_Max; j += 1)
|
|
||||||
{
|
|
||||||
glActiveTexture(GL_TEXTURE0+j);
|
|
||||||
glUniform1i(g_renderer.texture_locations[j], j);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, material->textures[j]);
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, 1, material->shader_state_buffer_id);
|
ImGui::Render();
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, 2, model_matrix_buffer_id);
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, 3, material->buffer_id);
|
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, tree_model.meshes[i].index_length, GL_UNSIGNED_INT, (void *)(u64)(tree_model.meshes[i].index_start*sizeof(u32)));
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
}
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
SDL_GL_SwapWindow(g_renderer.window);
|
SDL_GL_SwapWindow(g_renderer.window);
|
||||||
}
|
}
|
||||||
|
|||||||
60
math.cpp
Normal file
60
math.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
Vec3
|
||||||
|
Transform(Vec3 &vec, Mat4 &mat, f32 last = 1.0)
|
||||||
|
{
|
||||||
|
Vec3 dst = {};
|
||||||
|
glm_mat4_mulv3(mat.matrix, vec.v, last, dst.v);
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
f32
|
||||||
|
Dot(Vec3 &lhs, Vec3 &rhs)
|
||||||
|
{
|
||||||
|
return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3
|
||||||
|
Normalize(Vec3 &vec)
|
||||||
|
{
|
||||||
|
f32 length = sqrtf(Dot(vec, vec));
|
||||||
|
|
||||||
|
Vec3 result = vec;
|
||||||
|
if(length < 0.00009f)
|
||||||
|
{
|
||||||
|
result.x = 0.0f;
|
||||||
|
result.y = 0.0f;
|
||||||
|
result.z = 0.0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.x *= 1.0f/length;
|
||||||
|
result.y *= 1.0f/length;
|
||||||
|
result.z *= 1.0f/length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mat4
|
||||||
|
Inverse(Mat4 mat)
|
||||||
|
{
|
||||||
|
Mat4 result;
|
||||||
|
glm_mat4_inv(mat.matrix, result.matrix);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Quat
|
||||||
|
AngleAxis(f32 angle, Vec3 axis)
|
||||||
|
{
|
||||||
|
Quat q;
|
||||||
|
glm_quat(q.quat, angle, axis.x, axis.y, axis.z);
|
||||||
|
return q;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mat4
|
||||||
|
ToMat4(Quat quat)
|
||||||
|
{
|
||||||
|
Mat4 mat;
|
||||||
|
glm_quat_mat4(quat.quat, mat.matrix);
|
||||||
|
return mat;
|
||||||
|
}
|
||||||
|
|
||||||
@ -83,11 +83,16 @@ struct MaterialMap
|
|||||||
|
|
||||||
layout(location = 0) varying_param vec2 v_uv0;
|
layout(location = 0) varying_param vec2 v_uv0;
|
||||||
layout(location = 1) varying_param vec2 v_uv1;
|
layout(location = 1) varying_param vec2 v_uv1;
|
||||||
|
layout(location = 2) varying_param vec3 v_normal;
|
||||||
|
layout(location = 3) varying_param vec3 v_position;
|
||||||
|
layout(location = 4) varying_param vec4 v_color;
|
||||||
|
|
||||||
layout(std140, binding = 0) uniform Globals
|
layout(std140, binding = 0) uniform Globals
|
||||||
{
|
{
|
||||||
mat4 projection;
|
mat4 projection;
|
||||||
mat4 view;
|
mat4 view;
|
||||||
|
vec3 camera_position;
|
||||||
|
vec3 ambient;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout(std140, binding = 1) uniform ModelState
|
layout(std140, binding = 1) uniform ModelState
|
||||||
@ -102,6 +107,7 @@ layout(std140, binding = 1) uniform ModelState
|
|||||||
bool irradiance_texture;
|
bool irradiance_texture;
|
||||||
bool prefilter_texture;
|
bool prefilter_texture;
|
||||||
bool brdf_texture;
|
bool brdf_texture;
|
||||||
|
bool no_material;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout(std140, binding = 2) uniform InstanceState
|
layout(std140, binding = 2) uniform InstanceState
|
||||||
@ -114,13 +120,29 @@ layout(std140, binding = 3) uniform Materials
|
|||||||
MaterialMap material_maps[MMI_MAX];
|
MaterialMap material_maps[MMI_MAX];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
f32
|
||||||
|
InverseLerp(f32 v, f32 min_value, f32 max_value)
|
||||||
|
{
|
||||||
|
return (v-min_value) / (max_value-min_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
f32
|
||||||
|
Remap(f32 v, f32 in_min, f32 in_max, f32 out_min, f32 out_max)
|
||||||
|
{
|
||||||
|
f32 t = InverseLerp(v, in_min, in_max);
|
||||||
|
return mix(out_min, out_max, t);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef VERTEX_SHADER
|
#ifdef VERTEX_SHADER
|
||||||
|
|
||||||
void
|
void
|
||||||
VertexMain()
|
VertexMain()
|
||||||
{
|
{
|
||||||
gl_Position = projection * model_matrix * vec4(a_pos, 1.0);
|
gl_Position = projection * view * model_matrix * vec4(a_pos, 1.0);
|
||||||
v_uv0 = a_uv0;
|
v_uv0 = a_uv0;
|
||||||
|
v_normal = (model_matrix * vec4(a_normal, 0.0f)).xyz;
|
||||||
|
v_position = (model_matrix * vec4(a_pos, 1.0f)).xyz;
|
||||||
|
v_color = a_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -128,14 +150,56 @@ VertexMain()
|
|||||||
void
|
void
|
||||||
FragmentMain()
|
FragmentMain()
|
||||||
{
|
{
|
||||||
|
vec3 normal = normalize(v_normal);
|
||||||
|
vec3 view_direction = normalize(camera_position - v_position);
|
||||||
|
|
||||||
|
vec4 color;
|
||||||
if(albedo_texture)
|
if(albedo_texture)
|
||||||
{
|
{
|
||||||
FragColor = texture(AlbedoTexture, v_uv0);
|
color = texture(AlbedoTexture, v_uv0);
|
||||||
|
}
|
||||||
|
else if(no_material)
|
||||||
|
{
|
||||||
|
color = v_color;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FragColor = AlbedoMaterial.color;
|
color = AlbedoMaterial.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(color.a < 0.03f)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 light_pos = vec3(0.0f, 100000.0f, 0.0f);
|
||||||
|
vec3 light_dir = normalize(light_pos-v_position);
|
||||||
|
vec3 light_color = vec3(1.0, 1.0, 0.9);
|
||||||
|
|
||||||
|
// Hemi lighting
|
||||||
|
vec3 sky_color = vec3(0.0, 0.3, 0.6);
|
||||||
|
vec3 ground_color = vec3(0.6, 0.3, 0.1);
|
||||||
|
|
||||||
|
f32 hemi_mix = Remap(normal.y, -1.0, 1.0, 0.0, 1.0);
|
||||||
|
vec3 hemi = mix(ground_color, sky_color, hemi_mix);
|
||||||
|
|
||||||
|
// Diffuse
|
||||||
|
f32 dp = max(0.0, dot(light_dir, normal));
|
||||||
|
|
||||||
|
vec3 diffuse = dp * light_color;
|
||||||
|
|
||||||
|
// Phong
|
||||||
|
|
||||||
|
vec3 r = normalize(reflect(-light_dir, normal));
|
||||||
|
f32 phong_value = max(0.0, dot(view_direction, r));
|
||||||
|
phong_value = pow(phong_value, 32.0);
|
||||||
|
|
||||||
|
vec3 specular = vec3(phong_value);
|
||||||
|
|
||||||
|
vec3 lighting = ambient + hemi + diffuse + specular;
|
||||||
|
lighting = pow(lighting, vec3(1.0/2.2));
|
||||||
|
|
||||||
|
FragColor = color * vec4(lighting, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -14,7 +14,6 @@ layout(std140, binding = 0) uniform Globals
|
|||||||
{
|
{
|
||||||
mat4 projection;
|
mat4 projection;
|
||||||
mat4 view;
|
mat4 view;
|
||||||
mat4 model_matrix;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
21
util.cpp
21
util.cpp
@ -2,6 +2,27 @@
|
|||||||
#define MB(x) (KB(x)*1024)
|
#define MB(x) (KB(x)*1024)
|
||||||
#define GB(x) (MB(x)*1024)
|
#define GB(x) (MB(x)*1024)
|
||||||
|
|
||||||
|
Vec4
|
||||||
|
U32ToVec4(u32 src)
|
||||||
|
{
|
||||||
|
Vec4 col = {};
|
||||||
|
|
||||||
|
if(src)
|
||||||
|
{
|
||||||
|
col.r = (f32)(((src >> 0 ) & 0xFF) / 255.0f);
|
||||||
|
col.g = (f32)(((src >> 8 ) & 0xFF) / 255.0f);
|
||||||
|
col.b = (f32)(((src >> 16) & 0xFF) / 255.0f);
|
||||||
|
col.a = (f32)(((src >> 24) & 0xFF) / 255.0f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
col.r = col.g = col.b = 0.0f;
|
||||||
|
col.a = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return col;
|
||||||
|
}
|
||||||
|
|
||||||
f32
|
f32
|
||||||
Radians(f32 deg)
|
Radians(f32 deg)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user