mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-18 14:35:48 +01:00
Compare commits
228 Commits
be653b6bd3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e8f5958c7 | |||
| bc0743a72b | |||
| 81b21ff7ce | |||
| 7df20e9aa1 | |||
| 5cf0292ebe | |||
| 64b06d88c8 | |||
| 8bb8671fb0 | |||
| 8d0e825157 | |||
| 5f909d1d65 | |||
| 87541d5789 | |||
| 316726a610 | |||
| 1aa34f7d3f | |||
| 00719b1933 | |||
| eb45650178 | |||
| 8ca49aa4fa | |||
| d4fabf437c | |||
| cebe0df8a2 | |||
| aa58d931aa | |||
| 27c862c215 | |||
| 6eb7d126da | |||
| 1e24a4ee92 | |||
| 181fca6828 | |||
| f6e5712876 | |||
| 47d34b3f7d | |||
| e623a352d2 | |||
| 079361771f | |||
| 66e3d0d06f | |||
| adfca88d3c | |||
| e9c922d3cd | |||
| d46f8c0900 | |||
| 2261209d8d | |||
| a16f454396 | |||
| 945a82e5f6 | |||
| 88d39150dd | |||
| 76c992efdc | |||
| 28b98705f5 | |||
| 057b234251 | |||
| dd2f4c403c | |||
| dc3abf992b | |||
| 1e10fec9c6 | |||
| 41d944ac21 | |||
| faa93f4372 | |||
| e3c0afbb2f | |||
| 11c8748262 | |||
| 25fa078c98 | |||
| 023123e54f | |||
| b13739c782 | |||
| 5db42a2b15 | |||
| 2277b8ec77 | |||
| fa26a3561d | |||
| 15b5430611 | |||
| 6c184a4d36 | |||
| 82ebe1f4d1 | |||
| 5f3bd40a47 | |||
| 158a7f8383 | |||
| c32d1551c8 | |||
| b04ce9998f | |||
| 218b98e684 | |||
| f20171c0d7 | |||
| 3a7709c392 | |||
| ec36d8c475 | |||
| a14ef55262 | |||
| d340bbe40b | |||
| 0f6a2579b9 | |||
| 1ac4592503 | |||
| 4da02373a5 | |||
| c724ff0449 | |||
| 348c4e484c | |||
| 1140bd97bf | |||
| 997b15c640 | |||
| f481af7e78 | |||
| 1169ca98b1 | |||
| 75ebff9071 | |||
| 4f081e7f3e | |||
| 8a1ed6e3c4 | |||
| a7678c874c | |||
| d9ddae770a | |||
| c2e1b67b4c | |||
| 8548c2d037 | |||
| 7ec6a3b91a | |||
| 3f48a7abb2 | |||
| 667814fb72 | |||
| 23fda298e6 | |||
| 03c76b0be6 | |||
| f0d14e76b2 | |||
| 07f4ea34d2 | |||
| 5de0c77992 | |||
| 2cfae0fce4 | |||
| d933931829 | |||
| f020347f71 | |||
| b13de01f24 | |||
| 3a0704710c | |||
| b72b8eaee1 | |||
| 55635d44ae | |||
| 4fa0b41e7a | |||
| 8a5afd6915 | |||
| 8b952fb86f | |||
| 0baadfca75 | |||
| 9a45294e56 | |||
| 5b5f1f54af | |||
| f1141e0db4 | |||
| 15942b47f5 | |||
| bc8803525d | |||
| 7531d786be | |||
| 2c5b9def28 | |||
| cd277873b5 | |||
| f203cabad9 | |||
| 28dd8af353 | |||
| 9c690eb327 | |||
| af8211c5ce | |||
| 767f3a5c13 | |||
| 43e3e4fe85 | |||
| fad6f366b4 | |||
| b7859d56d9 | |||
| 7a45724de7 | |||
| 1c863099a9 | |||
| 2f68574aea | |||
| 4e230ae856 | |||
| e02f4091b8 | |||
| 1f46640e49 | |||
| 17357d4672 | |||
| 5644d377de | |||
| 44d2271972 | |||
| 545eecca37 | |||
| 6dae1d1600 | |||
| a6442a851e | |||
| ec04177f45 | |||
| 40b8c0ef30 | |||
| 7feb193c51 | |||
| 29c8a2b6ea | |||
| 8cd29225d1 | |||
| 20ec45f230 | |||
| 3cdee8b40c | |||
| 89ceb5263c | |||
| 4fa0a84c94 | |||
| 8452f7d21e | |||
| 6c0a1de365 | |||
| d9ee6c9155 | |||
| 5ba44689ff | |||
| fb21e7e782 | |||
| f1ea7dcef8 | |||
| 9996e84ef5 | |||
| 949cac5bfe | |||
| 3eb92541db | |||
| df3720b966 | |||
| f53e4315ee | |||
| 24f9ba047e | |||
| e67d8c7fd4 | |||
| 23b64199d7 | |||
| 6a9d6f75a4 | |||
| e018e1ff1b | |||
| 1b09d3d7f1 | |||
| e4b90246c5 | |||
| c15046e017 | |||
| e3a8063124 | |||
| 10a2aca0a5 | |||
| e6cc6ce2e8 | |||
| 999180cd74 | |||
| 08a8e261f0 | |||
| c716a9accd | |||
| c1471e92bd | |||
| c2c4afb49f | |||
| 916e81aaad | |||
| ee27935aab | |||
| 51a05f2d7c | |||
| ebd5b6b430 | |||
| 2e7932a70c | |||
| 37181a299c | |||
| 41828c6ea7 | |||
| f0e6aa38c7 | |||
| 54428e72f9 | |||
| 75008c6ca8 | |||
| 7ef32c06ea | |||
| 5c57a77ad4 | |||
| bdf4d7b22b | |||
| 114a7d4ea5 | |||
| e287f6034f | |||
| 0e00cb2d54 | |||
| c3fc688c35 | |||
| 4871a19695 | |||
| 2d33255ce8 | |||
| 066e1c0049 | |||
| 1052dcaac9 | |||
| f952268152 | |||
| 4b2404e903 | |||
| ff7598a7e3 | |||
| e472d9c251 | |||
| d70888f9fb | |||
| 6dbf034ba1 | |||
| 1ea37b6e86 | |||
| f3273ed5d0 | |||
| 6ccb55de8b | |||
| 69dc174ff2 | |||
| 58d0dd01e2 | |||
| 4005163d61 | |||
| 8964a1a563 | |||
| f0c5408c51 | |||
| 1d5df8df0a | |||
| cdf13b7529 | |||
| 13e1ceddfc | |||
| 333417dadd | |||
| fd8db02e77 | |||
| 2daeb9823c | |||
| 4e1cd68c38 | |||
| 501c623f01 | |||
| 65ee7c5b55 | |||
| 5d7c244c8f | |||
| 9fd920908e | |||
| 8102dd6a71 | |||
| ac3be7e8ab | |||
| 6c2f51929b | |||
| ee1811a3a5 | |||
| db76d6992b | |||
| 8345ac1164 | |||
| 13451da2e8 | |||
| 6aff9aa528 | |||
| be87ccbe22 | |||
| d1d5e14971 | |||
| bcf7c9be60 | |||
| 8861e591f6 | |||
| 2cb5d03211 | |||
| 600fa0f25e | |||
| ceea087a88 | |||
| 9b9a20e226 | |||
| c56e2399e9 | |||
| 66badc2dc6 | |||
| 5e0db59198 | |||
| 271773a28c |
@@ -1,3 +1,7 @@
|
||||
# Copyright (c) 2025 Quinn.
|
||||
# This is a file from the project MCA-Selector-Lite and is
|
||||
# licensed under the MIT Licence. See included LICENSE file for details.
|
||||
#
|
||||
---
|
||||
# ---------------------------
|
||||
# general style settings
|
||||
@@ -21,9 +25,9 @@ AlignTrailingComments: true
|
||||
AlignConsecutiveMacros: AcrossEmptyLines
|
||||
AlignEscapedNewlines: Left
|
||||
AlignArrayOfStructures: Left
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignConsecutiveAssignments: Consecutive
|
||||
AlignConsecutiveBitFields: AcrossEmptyLines
|
||||
AlignConsecutiveDeclarations: None
|
||||
AlignConsecutiveDeclarations: Consecutive
|
||||
AlignConsecutiveShortCaseStatements:
|
||||
Enabled: true
|
||||
|
||||
@@ -31,9 +35,9 @@ AlignConsecutiveShortCaseStatements:
|
||||
# short constructs on a single line
|
||||
# ---------------------------
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
@@ -58,7 +62,7 @@ BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterFunction: true
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
@@ -87,7 +91,7 @@ BinPackArguments: true
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Right
|
||||
ReferenceAlignment: Pointer
|
||||
QualifierAlignment: Right
|
||||
QualifierAlignment: Left
|
||||
|
||||
# ---------------------------
|
||||
# include settings and sorting
|
||||
@@ -96,10 +100,6 @@ IncludeIsMainSourceRegex: ''
|
||||
IncludeIsMainRegex: '([-_](test|unittest))?$'
|
||||
IncludeBlocks: Regroup
|
||||
IncludeCategories:
|
||||
- Regex: '^<glad/gl\.h>'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
CaseSensitive: true
|
||||
- Regex: '^<.*\.h>'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Copyright (c) 2025 Quinn
|
||||
# Licensed under the MIT Licence. See LICENSE for details
|
||||
# Copyright (c) 2025 Quinn.
|
||||
# This is a file from the project MCA-Selector-Lite and is
|
||||
# licensed under the MIT Licence. See included LICENSE file for details.
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
@@ -15,6 +16,10 @@ indent_size = tab
|
||||
indent_style = tab
|
||||
indent_size = tab
|
||||
|
||||
[*.{yaml,json}]
|
||||
[*.{json}]
|
||||
indent_style = tab
|
||||
indent_size = tab
|
||||
|
||||
[*.{yaml}]
|
||||
indent_style = space
|
||||
intent_size = 2
|
||||
|
||||
39
.github/Dockerfile
vendored
39
.github/Dockerfile
vendored
@@ -1,39 +0,0 @@
|
||||
# Copyright (c) 2025 Quinn
|
||||
# Licensed under the MIT Licence. See LICENSE for details
|
||||
|
||||
# docker buildx build . -t ghcr.io/thepigeongenerator/mcaselector-lite:latest
|
||||
# docker push ghcr.io/thepigeongenerator/mcaselector-lite:latest
|
||||
FROM debian:testing-slim
|
||||
LABEL org.opencontainers.image.source="https://github.com/thepigeongenerator/mcaselector-lite"
|
||||
LABEL org.opencontainers.image.source-path="/.github/Dockerfile"
|
||||
|
||||
# install the dependencies
|
||||
RUN \
|
||||
echo 'APT::Install-Recommends "false";' > /etc/apt/apt.conf.d/no-recommends; \
|
||||
echo 'APT::Install-Suggests "false";' >> /etc/apt/apt.conf.d/no-recommends; \
|
||||
dpkg --add-architecture i386; \
|
||||
apt-get update -qq; \
|
||||
apt-get install -y \
|
||||
ca-certificates \
|
||||
binutils \
|
||||
git curl \
|
||||
zip unzip \
|
||||
wine wine64 \
|
||||
make cmake pkg-config \
|
||||
gcc gcc-multilib g++ mingw-w64 \
|
||||
libc6-dev \
|
||||
libxinerama-dev libxcursor-dev libxi-dev libxrandr-dev libglu1-mesa-dev \
|
||||
libglfw3 \
|
||||
nodejs; \
|
||||
apt-get clean; \
|
||||
rm -rf /var/lib/apt/lists/* /usr/share/doc/* /usr/share/man/* /usr/share/locale/*; \
|
||||
rm -rf /usr/lib/node_modules/npm/docs /usr/lib/node_modules/npm/html; \
|
||||
rm -rf /usr/share/wine/fonts /usr/share/wine/mono; \
|
||||
find /usr -name "*.py" -delete; \
|
||||
find /usr/lib/wine -name "*.a" -delete; \
|
||||
find /usr/lib/wine -name "*.la" -delete; \
|
||||
find /usr/lib/wine -name "*.def" -delete; \
|
||||
strip /usr/bin/wine* || true; \
|
||||
rm -rf /var/cache/* /var/log/*;
|
||||
|
||||
CMD ["bash"]
|
||||
96
.github/workflows/ci.yaml
vendored
96
.github/workflows/ci.yaml
vendored
@@ -1,53 +1,57 @@
|
||||
# Copyright (c) 2025 Quinn
|
||||
# Licensed under the MIT Licence. See LICENSE for details
|
||||
name: CI
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '**'
|
||||
pull_request:
|
||||
branches:
|
||||
- '**'
|
||||
env:
|
||||
VCPKG_DISABLE_METRICS: 1
|
||||
VCPKG_ROOT: ${{github.workspace}}/.vcpkg
|
||||
DEPS_VCPKG: glfw3:x64-linux-dynamic glfw3:x64-mingw-static
|
||||
WINEPREFIX: /tmp/wineprefix
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
#
|
||||
# the mega job containing all things we need to do, since setting up a single system is more efficient than installing the same stuff on multiple ones
|
||||
#
|
||||
exec-ci-tasks:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/thepigeongenerator/mcaselector-lite:latest
|
||||
compile-and-test:
|
||||
strategy:
|
||||
fail-fast: false # disable fail fast, so feedback is provided for all matrix combinations
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
cc: cc
|
||||
- os: ubuntu-24.04-arm
|
||||
cc: cc
|
||||
- os: windows-latest
|
||||
cc: gcc
|
||||
- os: windows-11-arm
|
||||
cc: gcc
|
||||
# - os: macos-latest
|
||||
# cc: cc
|
||||
env:
|
||||
CC: ${{matrix.cc}}
|
||||
runs-on: ${{matrix.os}}
|
||||
steps:
|
||||
#
|
||||
# general setup
|
||||
#
|
||||
- uses: actions/checkout@v4
|
||||
#
|
||||
# VCPKG setup
|
||||
#
|
||||
- id: gen-keys
|
||||
run: echo "HASH_VCPKG=vcpkg-$(echo "$DEPS_VCPKG" | sha256sum | cut -d ' ' -f1)" >>"$GITHUB_OUTPUT"
|
||||
# load the vcpkg cache
|
||||
- uses: actions/cache@v4
|
||||
id: vcpkg-cache
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
path: ${{env.VCPKG_ROOT}}
|
||||
key: ${{steps.gen-keys.outputs.HASH_VCPKG}}
|
||||
restore-keys: vcpkg-
|
||||
# setup vcpkg if the cache didn't hit
|
||||
- if: steps.vcpkg-cache.outputs.cache-hit != 'true'
|
||||
submodules: true
|
||||
fetch-depth: 1
|
||||
|
||||
- name: "Linux: install deps"
|
||||
if: runner.os == 'Linux'
|
||||
run: |
|
||||
git clone https://github.com/microsoft/vcpkg.git "$VCPKG_ROOT"
|
||||
"$VCPKG_ROOT/bootstrap-vcpkg.sh"
|
||||
"$VCPKG_ROOT/vcpkg" install $DEPS_VCPKG
|
||||
# compilation (using bulk compilation)
|
||||
- run: make all CALL=compile -j || echo "JOB_FAILED=1" >>"$GITHUB_ENV"
|
||||
# executing unit tests (using bulk flags)
|
||||
- run: make all CALL=run DEBUG=test -j || echo "JOB_FAILED=1" >>"$GITHUB_ENV"
|
||||
# exit if any errors occurred
|
||||
- name: exit on errors
|
||||
run: |
|
||||
[ "$JOB_FAILED" != "1" ]
|
||||
sudo apt update
|
||||
sudo apt install -y libwayland-dev libxkbcommon-dev xorg-dev cmake xxd
|
||||
|
||||
- name: get submodule hash
|
||||
id: get-hash
|
||||
run: echo "HASH=$(git submodule | sha1sum | cut -d' ' -f1)" >$GITHUB_OUTPUT
|
||||
shell: bash
|
||||
|
||||
- uses: actions/cache@v4
|
||||
id: cache-deps
|
||||
with:
|
||||
path: lib/obj/
|
||||
# I swear to god, if runner.arch displays x64 for x86_64, I will eat a potato.
|
||||
# note: it is... fucking shit.
|
||||
key: ${{runner.os}}_${{runner.arch}}-lib/obj-${{steps.get-hash.outputs.HASH}}
|
||||
restore-keys: ${{runner.os}}_${{runner.arch}}-lib/obj-
|
||||
|
||||
- run: make -Bj libs
|
||||
if: steps.cache-deps.outputs.cache-hit != 'true' && runner.os != 'Windows'
|
||||
- run: make -Bj2 libs # compile fewer cores, to save memory.
|
||||
if: steps.cache-deps.outputs.cache-hit != 'true' && runner.os == 'Windows'
|
||||
|
||||
- run: make -j all
|
||||
- run: make -j check
|
||||
|
||||
49
.github/workflows/release.yaml
vendored
49
.github/workflows/release.yaml
vendored
@@ -1,49 +0,0 @@
|
||||
# Copyright (c) 2025 Quinn
|
||||
# Licensed under the MIT Licence. See LICENSE for details
|
||||
name: release
|
||||
on:
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
release_tag:
|
||||
required: true
|
||||
description: the tag to release for
|
||||
default: ""
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/thepigeongenerator/mcaselector-lite:latest
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- kernel: linux
|
||||
march: x86_64
|
||||
cc: x86_64-linux-gnu-gcc
|
||||
- kernel: mingw
|
||||
march: x86_64
|
||||
cc: x86_64-w64-mingw32-gcc
|
||||
env:
|
||||
OUT: ${{github.workspace}}/mcaselector-lite-${{matrix.march}}-${{matrix.kernel}}-${{github.event.release.tag_name || github.event.inputs.release_tag}}.zip
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: compile ${{matrix.march}}-${{matrix.kernel}}
|
||||
run: make compile MARCH=${{matrix.march}} KERNEL=${{matrix.kernel}} CC=${{matrix.cc}} -j
|
||||
- name: compress binary information
|
||||
run: |
|
||||
cd "${{github.workspace}}/bin/${{matrix.march}}-${{matrix.kernel}}/${{github.event.release.tag_name || github.event.inputs.release_tag}}/rel/" || exit 1
|
||||
zip -rv "${{env.OUT}}" *
|
||||
cd -
|
||||
# upload to the release
|
||||
- name: upload release
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: ${{!env.ACT}}
|
||||
with:
|
||||
files: ${{env.OUT}}
|
||||
# upload to the artefact directory if running locally with act
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: ${{env.ACT}}
|
||||
with:
|
||||
path: ${{env.OUT}}
|
||||
12
.gitignore
vendored
12
.gitignore
vendored
@@ -1,11 +1,13 @@
|
||||
# Copyright (c) 2025 Quinn
|
||||
# Licensed under the MIT Licence. See LICENSE for details
|
||||
# Copyright (c) 2025 Quinn.
|
||||
# This is a file from the project MCA-Selector-Lite and is
|
||||
# licensed under the MIT Licence. See included LICENSE file for details.
|
||||
|
||||
# ignore all dotfiles by default
|
||||
.*
|
||||
|
||||
# unhide dotfiles we want to keep
|
||||
!.gitignore
|
||||
!.gitmodules
|
||||
!.editorconfig
|
||||
!.clang-format
|
||||
!/.github/
|
||||
@@ -14,9 +16,9 @@
|
||||
*.o
|
||||
*.d
|
||||
*.out
|
||||
*.lock
|
||||
/bin/
|
||||
/obj/
|
||||
/test/bin/
|
||||
/test/obj/
|
||||
*.lock
|
||||
/lib/obj/
|
||||
compile_commands.json
|
||||
compile_commands.events.json
|
||||
|
||||
11
.gitmodules
vendored
Normal file
11
.gitmodules
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2025 Quinn.
|
||||
# This is a file from the project MCA-Selector-Lite and is
|
||||
# licensed under the MIT Licence. See included LICENSE file for details.
|
||||
|
||||
[submodule "lib/glfw"]
|
||||
path = lib/glfw
|
||||
url = https://github.com/glfw/glfw
|
||||
|
||||
[submodule "lib/libarchive"]
|
||||
path = lib/libarchive
|
||||
url = https://github.com/libarchive/libarchive
|
||||
105
Makefile
Normal file
105
Makefile
Normal file
@@ -0,0 +1,105 @@
|
||||
# Copyright (c) 2025 Quinn.
|
||||
# This is a file from the project MCA-Selector-Lite and is
|
||||
# licensed under the MIT Licence. See included LICENSE file for details.
|
||||
|
||||
SHELL = /bin/sh
|
||||
.SUFFIXES:
|
||||
|
||||
NAME = mcaselector-lite
|
||||
|
||||
CC ?= cc
|
||||
RM ?= rm -vf
|
||||
CMAKE ?= cmake -G 'Unix Makefiles'
|
||||
|
||||
CPPFLAGS ?= -DNDEBUG
|
||||
CFLAGS ?= -O2
|
||||
LDFLAGS ?= -flto
|
||||
|
||||
CPPFLAGS += -DGLFW_INCLUDE_NONE
|
||||
CPPFLAGS += -Iinclude -Ilib/glad/include -Ilib/glfw/include -Ilib/libarchive/libarchive
|
||||
LDFLAGS += -Llib/obj/glfw/src -Llib/obj/libarchive/libarchive
|
||||
LDLIBS += -lglfw3 -larchive -lm
|
||||
CFLAGS += -std=gnu99 -g -MMD -MP
|
||||
CFLAGS += -Wall -Wextra -Wpedantic -Wno-pointer-arith
|
||||
|
||||
# detect if we're compiling on Windows, meaning
|
||||
# a lot of things considered "standard" are unavailable.
|
||||
ifeq ($(OS),Windows_NT)
|
||||
NAME := $(NAME).exe
|
||||
LDLIBS += -lopengl32 -lgdi32
|
||||
$(warning Detected Windows_NT, please refer to the documentation if you encounter issues.)
|
||||
# in the case of Mac OS X
|
||||
else ifeq ($(shell uname -s),Darwin)
|
||||
LDLIBS += -framework Coca -framework OpenGL -framework IOKit
|
||||
$(info Mac OS X detected.)
|
||||
endif
|
||||
|
||||
# find all the source files using wildcards
|
||||
# TODO: find a better method to find all source files
|
||||
# NOTE: MS-DOS and MS-Windows uses backslash `\`, this might break.
|
||||
RES := $(wildcard res/*)
|
||||
SRC := $(wildcard src/*.c src/*/*.c src/*/*/*.c src/*/*/*/*.c src/*/*/*/*/*.c src/*/*/*/*/*/*.c src/*/*/*/*/*/*/*.c src/*/*/*/*/*/*/*/*.c)
|
||||
SRC += lib/glad/src/gl.c
|
||||
TSRC := $(wildcard test/*.c test/*/*.c test/*/*/*.c test/*/*/*/*.c test/*/*/*/*/*.c test/*/*/*/*/*/*.c test/*/*/*/*/*/*/*.c test/*/*/*/*/*/*/*/*.c)
|
||||
|
||||
OBJ := $(RES:%=obj/%.o) $(SRC:%.c=obj/%.o)
|
||||
TOBJ := $(TSRC:%.c=obj/%.o)
|
||||
|
||||
# TODO: potentially automatically detect whether we should compile libs, or if we can just go ahead.
|
||||
|
||||
.PHONY: all libs check clean clean-libs
|
||||
all: bin/$(NAME)
|
||||
libs: lib/obj/glfw/ lib/obj/libarchive/
|
||||
check: bin/TEST_$(NAME); ./$<
|
||||
clean:; @-$(RM) -r bin/ obj/
|
||||
clean-libs:; @-$(RM) -r lib/obj/
|
||||
|
||||
.PHONY:
|
||||
install: all
|
||||
ifneq ($(OS),Windows_NT)
|
||||
# TODO: POSIX-compliant installation
|
||||
else
|
||||
# TODO: WINDOWS_NT installation
|
||||
endif
|
||||
|
||||
.PHONY:
|
||||
install-strip: install
|
||||
# TODO: strip the produced installation
|
||||
|
||||
# compiles the libraries using cmake
|
||||
lib/obj/%/: lib/%/
|
||||
$(CMAKE) -S $< -B $@
|
||||
$(MAKE) -C $@
|
||||
|
||||
# link together a runtime binary
|
||||
bin/$(NAME): $(OBJ)
|
||||
$(info [LD] $@)
|
||||
@mkdir -p $(@D)
|
||||
@$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
# link together a testing binary
|
||||
bin/TEST_$(NAME): $(TOBJ) $(filter-out obj/src/main.o,$(OBJ))
|
||||
$(info [LD] $@)
|
||||
@mkdir -p $(@D)
|
||||
@$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
obj/res/%.c: res/%
|
||||
$(info [XXD] $@)
|
||||
@mkdir -p $(@D)
|
||||
@cd res/ && xxd -i $(patsubst res/%,%,$<) $(abspath $@)
|
||||
|
||||
obj/%.o: %.c
|
||||
$(info [CC] $@)
|
||||
@mkdir -p $(@D)
|
||||
@$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
|
||||
|
||||
obj/%.o: obj/%.c
|
||||
$(info [CC] $@)
|
||||
@mkdir -p $(@D)
|
||||
@$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
|
||||
|
||||
# Include the generated dependency files.
|
||||
# Which creates rules for all dependencies,
|
||||
# as a result updating an .o file when a .h is updated.
|
||||
-include $(OBJ:%.o=%.d)
|
||||
-include $(TOBJ:%.o=%.d)
|
||||
@@ -7,8 +7,7 @@ A from-scratch rewrite of [mcaselector](https://github.com/Querz/mcaselector) in
|
||||
[](https://github.com/thepigeongenerator/mcaselector-lite/blob/main/LICENSE)
|
||||
[](https://github.com/thepigeongenerator/mcaselector-lite/issues/)
|
||||
|
||||
[](https://github.com/thepigeongenerator/mcaselector-lite/actions/workflows/ci.yaml)
|
||||
[](https://github.com/thepigeongenerator/mcaselector-lite/actions/workflows/release.yaml)
|
||||
[](https://github.com/thepigeongenerator/mcaselector-lite/actions/workflows/ci.yaml)
|
||||
|
||||
## what does it do
|
||||
MCA selector lite is a tool used to edit [region files](https://minecraft.wiki/w/Region_file_format) of your [Minecraft java](https://minecraft.wiki/w/Java_Edition) worlds.
|
||||
@@ -20,3 +19,14 @@ MCA selector is a tool written in Java. Where it depends upon JRE21 and JavaFX.
|
||||
The goal of this project is to create a version of the original MCA selector, but written in C, leveraging the improved performance due to native execution and more low-level control.
|
||||
I have picked C as the language for the core portions of the application, where I prefer fine-grained control with little abstractions.
|
||||
This version is not intended to serve to entirely replace MCA selector, just to offer an alternative. Both tools will have their strengths and weaknesses.
|
||||
|
||||
# planned features
|
||||
- [ ] (very basic) world map viewing (Y level + surface)
|
||||
- [ ] filtering chunks based on time spent in them
|
||||
- [ ] chunk-level removal of data.
|
||||
- [ ] CLI-only version
|
||||
- [ ] (idea) change chunk compression
|
||||
- [ ] (idea) view chunk metadata
|
||||
- [ ] (idea) change chunk sNBT (this'll be tricky to add)
|
||||
*note that entries marked with `(idea)` aren't guaranteed to be implemented.
|
||||
Due to their viability and usefulness is still to be measured.*
|
||||
|
||||
13
docs/dev/correct-c.md
Normal file
13
docs/dev/correct-c.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Correct C
|
||||
A monster list about bad code practices for the absolute beginners.
|
||||
Things obviously should be taken with a grain of salt, just stating the obvious.
|
||||
|
||||
- Functions without parameters will be defined with `void` in the parameter list, as opposed to leaving it empty. (e.i. `(void)` rather than `()`)
|
||||
- (public-facing) names mustn't be prefixed with `_`, this is a reserved identifier.
|
||||
- `typedef`s mustn't be suffixed with `_t`, this is a POSIX reserved identifier.
|
||||
- `typedef`s are discouraged, unless the name alias is clear in what it stores. (e.i. `u32` for a 32 bit unsigned integer)
|
||||
- Functions should do one thing, and do it well.
|
||||
- `inline` functions should serve as a replacement for macro definitions, don't put things in here that you wouldn't put in a macro. (block ≤5 lines)
|
||||
- Mark all implementations in a `*.c` file with `static` if there isn't a matching definition in a `*.h` file. (unless there's a clear reason to)
|
||||
- When a function parameter takes in a pointer, and does not modify the pointed at data, a const pointer should be used. (`const int *ptr`)
|
||||
- Try to limit yourself at ~112 columns, but generally avoid overly long lines.
|
||||
@@ -1,6 +1,7 @@
|
||||
# mcaselector-lite style reference
|
||||
## contents
|
||||
- [recommended tool chains](#recommended-tool-chains)
|
||||
- [recommended tools](#recommended-tools)
|
||||
- [code information](#code-information)
|
||||
- [style guide](#style-guide)
|
||||
|
||||
### recommended tools
|
||||
@@ -10,17 +11,24 @@
|
||||
- clang-tidy
|
||||
- linux / unix-like machine
|
||||
|
||||
### style guide
|
||||
- parameterless functions should have the `void` parameter.[^cstd]
|
||||
- symbols mustn't be prefixed with `_`; this is a C standard reserved symbol.[^cstd]
|
||||
- typedefs (or anything else for that matter) mustn't be suffixed with `_t`, this is reserved by POSIX.[^cstd]
|
||||
- functions should do one thing, and do that thing well.[^cstd]
|
||||
- K&R style braces/indentation[^wikiindent]
|
||||
- typedefs are discouraged
|
||||
- snake_case is used for all user-defined symbols. Macros are often all-uppercase, same goes for enums and other types of compile-time constants.
|
||||
- tabs are used for indentation, spaces are used for alignment.
|
||||
- British spelling is preferred, but not enforced. What is enforced is that British variants of the symbols are available.
|
||||
- commits should attempt to convey clearly what is being changed, for the sanity of the maintainer(s).
|
||||
### code information
|
||||
The project is written in the [GNU dialect](https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html) of [C99](https://www.en.cppreference.com/w/c/99.html).
|
||||
Where we have dependencies on:
|
||||
| library | summary |
|
||||
|:----------------------------------|:--------------------------------------------------------|
|
||||
| [libarchive](libarchive.org) | compression / decompression of various formats. |
|
||||
| [glfw](https://www.glfw.org/) | window creation / input handling. |
|
||||
| [openGL](https://www.opengl.org/) | hardware accelleration, for handling graphics. |
|
||||
|
||||
[cstd]: this is a general C practice, included since it is something commonly done incorrectly.
|
||||
[wikiindent]: <https://en.wikipedia.org/wiki/Indentation_style>
|
||||
It is intended to be platform-agnostic, within reason. But the main focus is for [Linux](https://wikipedia.org/wiki/Linux) systems with [x86_64](https://wikipedia.org/wiki/X86-64) architecture.
|
||||
Within [types.h](/src/types.h) there live definitions for fixed-width integer types.
|
||||
|
||||
### style guide
|
||||
- Code must be written correctly, read [Correct C](./correct-c.md) if more information is required.
|
||||
- `snake_casing` is used, with no [Hungarian notation](https://en.m.wikipedia.org/wiki/Hungarian_notation). (macros are all-uppercase, with a few exceptions)
|
||||
- [K&R style braces/indentation](https://en.wikipedia.org/wiki/Indentation_style) should be used.
|
||||
- For indentation tabs are used, and are assumed to be 8 spaces wide. For alignment spaces should be used.
|
||||
- A space should precede a pointer `*`. Where it is attached to the name, rather than the type. For `const` clarity, and chains such as: `u8 *a, *b, *c;`. This is true for functions as well: `void *malloc(size_t n);`
|
||||
- Generally speaking, British spelling is preferred. Define potential macros for, or when using alternate dialects.
|
||||
- Grammar should be correct. (`don't` or `do not`, not `dont`)
|
||||
- Commits should attempt to convey clearly what is being changed, for the sanity of the maintainer(s).
|
||||
|
||||
@@ -7,21 +7,22 @@ A tag is an individual part of the data tree, where the first byte is the ID, fo
|
||||
note: UUID are stored as an integer array.
|
||||
|
||||
### tag types
|
||||
| ID | tag name | payload specification |
|
||||
|-----:|:-------------|:------------------------------------|
|
||||
| `0` | `end` | - |
|
||||
| `1` | `byte` | `int8_t` |
|
||||
| `2` | `short` | `int16_t` (BE) |
|
||||
| `3` | `int` | `int32_t` (BE) |
|
||||
| `4` | `long` | `int64_t` (BE) |
|
||||
| `5` | `float` | `float` (BE) |
|
||||
| `6` | `double` | `double` (BE) |
|
||||
| `7` | `byte array` | `int32_t` (len) -> `int8_t` |
|
||||
| `8` | `string` | `uint16_t` (len) -> `UTF-8` |
|
||||
| `9` | `list` | ID: `int32_t` (len) -> ID |
|
||||
| `10` | `compound` | list of tags delimited with end tag |
|
||||
| `11` | `int array` | `int32_t` (len) -> `int32_t` |
|
||||
| `12` | `long array` | `int32_t` (len) -> `int64_t` |
|
||||
| ID | tag name | payload specification |
|
||||
|:-----:|:-------------|:------------------------------------|
|
||||
| `0x0` | `end` | - |
|
||||
| `0x1` | `byte` | `int8_t` |
|
||||
| `0x2` | `short` | `int16_t` (BE[^be]) |
|
||||
| `0x3` | `int` | `int32_t` (BE) |
|
||||
| `0x4` | `long` | `int64_t` (BE) |
|
||||
| `0x5` | `float` | `float` (BE) |
|
||||
| `0x6` | `double` | `double` (BE) |
|
||||
| `0x7` | `byte array` | `int32_t` (len) -> `int8_t` |
|
||||
| `0x8` | `string` | `uint16_t` (len) -> `UTF-8` |
|
||||
| `0x9` | `list` | ID: `int32_t` (len) -> ID |
|
||||
| `0xA` | `compound` | list of tags delimited with end tag |
|
||||
| `0xB` | `int array` | `int32_t` (len) -> `int32_t` |
|
||||
| `0xC` | `long array` | `int32_t` (len) -> `int64_t` |
|
||||
[^be]: [big-endian](https://en.wikipedia.org/wiki/Endianness)
|
||||
|
||||
## world data
|
||||
There is a difference between \*.mca and \*.mcr files.
|
||||
@@ -38,13 +39,8 @@ Where \*.mca files are the newer variant.
|
||||
|
||||
### coordinate conversions
|
||||
```c
|
||||
// block->chunk:
|
||||
return (x / 16) - sgn(x);
|
||||
return (x >> 4) - (x & 0x80000000);
|
||||
|
||||
// chunk->region:
|
||||
return (x / 32) - sgn(x);
|
||||
return (x >> 5) - (x & 0x80000000);
|
||||
return (x >> 4); // block->chunk
|
||||
return (x >> 5); // chunk->region
|
||||
```
|
||||
|
||||
|
||||
@@ -85,10 +81,10 @@ unsigned offs = bit & 63; // calc the offset within the segment
|
||||
// calculate the correct index
|
||||
uint16_t idx;
|
||||
idx = (block_states->dat[sgmt] >> offs); // acquire the data in the segment
|
||||
idx |= !((offs + w) > 64) ? 0 : block_states->dat[sgmt+1] << (64-offs); // complete with the data from the other segment, if present
|
||||
idx |= -!!((offs + w) > 64) & (block_states->dat[sgmt+1] << (64-offs)); // complete with the data from the other segment, if present
|
||||
idx &= (1 << w) - 1; // truncate the data to only contain what we desire.
|
||||
|
||||
blockdat blk = block_states->palette.dat[idx];
|
||||
struct blockdat blk = block_states->palette.dat[idx];
|
||||
```
|
||||
|
||||
### MCR format specification
|
||||
@@ -102,8 +98,8 @@ The offset of a chunk (x,z) (in chunk coordinates) in the first table can be fou
|
||||
| data | locations (4B) | timestamps (4B) | chunks and unused space |
|
||||
|
||||
##### chunk location
|
||||
Location info for a chunk is stored as a 32 bit big-endian integer, where the first three bytes are an offset in 4KiB sectors from the start of the file.
|
||||
The last byte gives the length of the chunk in 4KiB sectors. (rounded up, of course). Where chunks are always less than 1MiB in size.
|
||||
Location info for a chunk is stored as a 32 bit big-endian integer, where the first three bytes (0xFFFFFF00) are an offset in 4KiB sectors from the start of the file.
|
||||
The last byte (0x000000FF) gives the length of the chunk in 4KiB sectors. (rounded up, of course). Where chunks are always less than 1MiB in size.
|
||||
If a chunk isn't present in the region file (e.g. because it hasn't been generated or migrated yet), both fields are zero.
|
||||
|
||||
##### timestamps
|
||||
|
||||
40
include/endian.h
Normal file
40
include/endian.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#ifndef PORTABLE_ENDIAN_H
|
||||
#define PORTABLE_ENDIAN_H 1
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
#define le16toh(x) __uint16_identity(x)
|
||||
#define le32toh(x) __uint32_identity(x)
|
||||
#define le64toh(x) __uint64_identity(x)
|
||||
#define htole16(x) __uint16_identity(x)
|
||||
#define htole32(x) __uint32_identity(x)
|
||||
#define htole64(x) __uint64_identity(x)
|
||||
#define be16toh(x) __builtin_bswap16(x)
|
||||
#define be32toh(x) __builtin_bswap32(x)
|
||||
#define be64toh(x) __builtin_bswap64(x)
|
||||
#define htobe16(x) __builtin_bswap16(x)
|
||||
#define htobe32(x) __builtin_bswap32(x)
|
||||
#define htobe64(x) __builtin_bswap64(x)
|
||||
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
#define le16toh(x) __builtin_bswap16(x)
|
||||
#define le32toh(x) __builtin_bswap32(x)
|
||||
#define le64toh(x) __builtin_bswap64(x)
|
||||
#define htole16(x) __builtin_bswap16(x)
|
||||
#define htole32(x) __builtin_bswap32(x)
|
||||
#define htole64(x) __builtin_bswap64(x)
|
||||
#define be16toh(x) __uint16_identity(x)
|
||||
#define be32toh(x) __uint32_identity(x)
|
||||
#define be64toh(x) __uint64_identity(x)
|
||||
#define htobe16(x) __uint16_identity(x)
|
||||
#define htobe32(x) __uint32_identity(x)
|
||||
#define htobe64(x) __uint64_identity(x)
|
||||
#else
|
||||
#error machine architecture unsupported! Expected either big-endian or little-endian, make sure to use a compiler which defines __BYTE_ORDER__ (like clang or gcc)
|
||||
#endif /* byte order */
|
||||
|
||||
#else
|
||||
#error GNU C is unavailable
|
||||
#endif /* __GNUC__ */
|
||||
#endif /* PORTABLE_ENDIAN_H */
|
||||
311
lib/glad/include/KHR/khrplatform.h
Normal file
311
lib/glad/include/KHR/khrplatform.h
Normal file
@@ -0,0 +1,311 @@
|
||||
#ifndef __khrplatform_h_
|
||||
#define __khrplatform_h_
|
||||
|
||||
/*
|
||||
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||
** copy of this software and/or associated documentation files (the
|
||||
** "Materials"), to deal in the Materials without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
** permit persons to whom the Materials are 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 Materials.
|
||||
**
|
||||
** THE MATERIALS ARE 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
|
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
/* Khronos platform-specific types and definitions.
|
||||
*
|
||||
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||
* The last semantic modification to khrplatform.h was at commit ID:
|
||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||
*
|
||||
* Adopters may modify this file to suit their platform. Adopters are
|
||||
* encouraged to submit platform specific modifications to the Khronos
|
||||
* group so that they can be included in future versions of this file.
|
||||
* Please submit changes by filing pull requests or issues on
|
||||
* the EGL Registry repository linked above.
|
||||
*
|
||||
*
|
||||
* See the Implementer's Guidelines for information about where this file
|
||||
* should be located on your system and for more details of its use:
|
||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||
*
|
||||
* This file should be included as
|
||||
* #include <KHR/khrplatform.h>
|
||||
* by Khronos client API header files that use its types and defines.
|
||||
*
|
||||
* The types in khrplatform.h should only be used to define API-specific types.
|
||||
*
|
||||
* Types defined in khrplatform.h:
|
||||
* khronos_int8_t signed 8 bit
|
||||
* khronos_uint8_t unsigned 8 bit
|
||||
* khronos_int16_t signed 16 bit
|
||||
* khronos_uint16_t unsigned 16 bit
|
||||
* khronos_int32_t signed 32 bit
|
||||
* khronos_uint32_t unsigned 32 bit
|
||||
* khronos_int64_t signed 64 bit
|
||||
* khronos_uint64_t unsigned 64 bit
|
||||
* khronos_intptr_t signed same number of bits as a pointer
|
||||
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||
* khronos_ssize_t signed size
|
||||
* khronos_usize_t unsigned size
|
||||
* khronos_float_t signed 32 bit floating point
|
||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||
* nanoseconds
|
||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||
* only be used as a base type when a client API's boolean type is
|
||||
* an enum. Client APIs which use an integer or other type for
|
||||
* booleans cannot use this as the base type for their boolean.
|
||||
*
|
||||
* Tokens defined in khrplatform.h:
|
||||
*
|
||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||
*
|
||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||
*
|
||||
* Calling convention macros defined in this file:
|
||||
* KHRONOS_APICALL
|
||||
* KHRONOS_APIENTRY
|
||||
* KHRONOS_APIATTRIBUTES
|
||||
*
|
||||
* These may be used in function prototypes as:
|
||||
*
|
||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||
* int arg1,
|
||||
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||
*/
|
||||
|
||||
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||
# define KHRONOS_STATIC 1
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APICALL
|
||||
*-------------------------------------------------------------------------
|
||||
* This precedes the return type of the function in the function prototype.
|
||||
*/
|
||||
#if defined(KHRONOS_STATIC)
|
||||
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||
* header compatible with static linking. */
|
||||
# define KHRONOS_APICALL
|
||||
#elif defined(_WIN32)
|
||||
# define KHRONOS_APICALL __declspec(dllimport)
|
||||
#elif defined (__SYMBIAN32__)
|
||||
# define KHRONOS_APICALL IMPORT_C
|
||||
#elif defined(__ANDROID__)
|
||||
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||
#else
|
||||
# define KHRONOS_APICALL
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIENTRY
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the return type of the function and precedes the function
|
||||
* name in the function prototype.
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||
/* Win32 but not WinCE */
|
||||
# define KHRONOS_APIENTRY __stdcall
|
||||
#else
|
||||
# define KHRONOS_APIENTRY
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIATTRIBUTES
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the closing parenthesis of the function prototype arguments.
|
||||
*/
|
||||
#if defined (__ARMCC_2__)
|
||||
#define KHRONOS_APIATTRIBUTES __softfp
|
||||
#else
|
||||
#define KHRONOS_APIATTRIBUTES
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* basic type definitions
|
||||
*-----------------------------------------------------------------------*/
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||
|
||||
|
||||
/*
|
||||
* Using <stdint.h>
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
/*
|
||||
* To support platform where unsigned long cannot be used interchangeably with
|
||||
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
||||
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
||||
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
|
||||
* unsigned long long or similar (this results in different C++ name mangling).
|
||||
* To avoid changes for existing platforms, we restrict usage of intptr_t to
|
||||
* platforms where the size of a pointer is larger than the size of long.
|
||||
*/
|
||||
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
||||
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
||||
#define KHRONOS_USE_INTPTR_T
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif defined(__VMS ) || defined(__sgi)
|
||||
|
||||
/*
|
||||
* Using <inttypes.h>
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||
|
||||
/*
|
||||
* Win32
|
||||
*/
|
||||
typedef __int32 khronos_int32_t;
|
||||
typedef unsigned __int32 khronos_uint32_t;
|
||||
typedef __int64 khronos_int64_t;
|
||||
typedef unsigned __int64 khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__sun__) || defined(__digital__)
|
||||
|
||||
/*
|
||||
* Sun or Digital
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#if defined(__arch64__) || defined(_LP64)
|
||||
typedef long int khronos_int64_t;
|
||||
typedef unsigned long int khronos_uint64_t;
|
||||
#else
|
||||
typedef long long int khronos_int64_t;
|
||||
typedef unsigned long long int khronos_uint64_t;
|
||||
#endif /* __arch64__ */
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif 0
|
||||
|
||||
/*
|
||||
* Hypothetical platform with no float or int64 support
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#define KHRONOS_SUPPORT_INT64 0
|
||||
#define KHRONOS_SUPPORT_FLOAT 0
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Generic fallback
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Types that are (so far) the same on all platforms
|
||||
*/
|
||||
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;
|
||||
|
||||
/*
|
||||
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||
* to be the only LLP64 architecture in current use.
|
||||
*/
|
||||
#ifdef KHRONOS_USE_INTPTR_T
|
||||
typedef intptr_t khronos_intptr_t;
|
||||
typedef uintptr_t khronos_uintptr_t;
|
||||
#elif defined(_WIN64)
|
||||
typedef signed long long int khronos_intptr_t;
|
||||
typedef unsigned long long int khronos_uintptr_t;
|
||||
#else
|
||||
typedef signed long int khronos_intptr_t;
|
||||
typedef unsigned long int khronos_uintptr_t;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN64)
|
||||
typedef signed long long int khronos_ssize_t;
|
||||
typedef unsigned long long int khronos_usize_t;
|
||||
#else
|
||||
typedef signed long int khronos_ssize_t;
|
||||
typedef unsigned long int khronos_usize_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_FLOAT
|
||||
/*
|
||||
* Float type
|
||||
*/
|
||||
typedef float khronos_float_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_INT64
|
||||
/* Time types
|
||||
*
|
||||
* These types can be used to represent a time interval in nanoseconds or
|
||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||
* time the system booted). The Unadjusted System Time is an unsigned
|
||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||
* may be either signed or unsigned.
|
||||
*/
|
||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Dummy value used to pad enum types to 32 bits.
|
||||
*/
|
||||
#ifndef KHRONOS_MAX_ENUM
|
||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enumerated boolean type
|
||||
*
|
||||
* Values other than zero should be considered to be true. Therefore
|
||||
* comparisons should not be made against KHRONOS_TRUE.
|
||||
*/
|
||||
typedef enum {
|
||||
KHRONOS_FALSE = 0,
|
||||
KHRONOS_TRUE = 1,
|
||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||
} khronos_boolean_enum_t;
|
||||
|
||||
#endif /* __khrplatform_h_ */
|
||||
File diff suppressed because it is too large
Load Diff
951
lib/glad/src/gl.c
Normal file
951
lib/glad/src/gl.c
Normal file
@@ -0,0 +1,951 @@
|
||||
/**
|
||||
* SPDX-License-Identifier: (WTFPL OR CC0-1.0) AND Apache-2.0
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <glad/gl.h>
|
||||
|
||||
#ifndef GLAD_IMPL_UTIL_C_
|
||||
#define GLAD_IMPL_UTIL_C_
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define GLAD_IMPL_UTIL_SSCANF sscanf_s
|
||||
#else
|
||||
#define GLAD_IMPL_UTIL_SSCANF sscanf
|
||||
#endif
|
||||
|
||||
#endif /* GLAD_IMPL_UTIL_C_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int GLAD_GL_VERSION_1_0 = 0;
|
||||
int GLAD_GL_VERSION_1_1 = 0;
|
||||
int GLAD_GL_VERSION_1_2 = 0;
|
||||
int GLAD_GL_VERSION_1_3 = 0;
|
||||
int GLAD_GL_VERSION_1_4 = 0;
|
||||
int GLAD_GL_VERSION_1_5 = 0;
|
||||
int GLAD_GL_VERSION_2_0 = 0;
|
||||
int GLAD_GL_VERSION_2_1 = 0;
|
||||
int GLAD_GL_VERSION_3_0 = 0;
|
||||
int GLAD_GL_VERSION_3_1 = 0;
|
||||
int GLAD_GL_VERSION_3_2 = 0;
|
||||
int GLAD_GL_VERSION_3_3 = 0;
|
||||
|
||||
|
||||
|
||||
PFNGLACTIVETEXTUREPROC glad_glActiveTexture = NULL;
|
||||
PFNGLATTACHSHADERPROC glad_glAttachShader = NULL;
|
||||
PFNGLBEGINCONDITIONALRENDERPROC glad_glBeginConditionalRender = NULL;
|
||||
PFNGLBEGINQUERYPROC glad_glBeginQuery = NULL;
|
||||
PFNGLBEGINTRANSFORMFEEDBACKPROC glad_glBeginTransformFeedback = NULL;
|
||||
PFNGLBINDATTRIBLOCATIONPROC glad_glBindAttribLocation = NULL;
|
||||
PFNGLBINDBUFFERPROC glad_glBindBuffer = NULL;
|
||||
PFNGLBINDBUFFERBASEPROC glad_glBindBufferBase = NULL;
|
||||
PFNGLBINDBUFFERRANGEPROC glad_glBindBufferRange = NULL;
|
||||
PFNGLBINDFRAGDATALOCATIONPROC glad_glBindFragDataLocation = NULL;
|
||||
PFNGLBINDFRAGDATALOCATIONINDEXEDPROC glad_glBindFragDataLocationIndexed = NULL;
|
||||
PFNGLBINDFRAMEBUFFERPROC glad_glBindFramebuffer = NULL;
|
||||
PFNGLBINDRENDERBUFFERPROC glad_glBindRenderbuffer = NULL;
|
||||
PFNGLBINDSAMPLERPROC glad_glBindSampler = NULL;
|
||||
PFNGLBINDTEXTUREPROC glad_glBindTexture = NULL;
|
||||
PFNGLBINDVERTEXARRAYPROC glad_glBindVertexArray = NULL;
|
||||
PFNGLBLENDCOLORPROC glad_glBlendColor = NULL;
|
||||
PFNGLBLENDEQUATIONPROC glad_glBlendEquation = NULL;
|
||||
PFNGLBLENDEQUATIONSEPARATEPROC glad_glBlendEquationSeparate = NULL;
|
||||
PFNGLBLENDFUNCPROC glad_glBlendFunc = NULL;
|
||||
PFNGLBLENDFUNCSEPARATEPROC glad_glBlendFuncSeparate = NULL;
|
||||
PFNGLBLITFRAMEBUFFERPROC glad_glBlitFramebuffer = NULL;
|
||||
PFNGLBUFFERDATAPROC glad_glBufferData = NULL;
|
||||
PFNGLBUFFERSUBDATAPROC glad_glBufferSubData = NULL;
|
||||
PFNGLCHECKFRAMEBUFFERSTATUSPROC glad_glCheckFramebufferStatus = NULL;
|
||||
PFNGLCLAMPCOLORPROC glad_glClampColor = NULL;
|
||||
PFNGLCLEARPROC glad_glClear = NULL;
|
||||
PFNGLCLEARBUFFERFIPROC glad_glClearBufferfi = NULL;
|
||||
PFNGLCLEARBUFFERFVPROC glad_glClearBufferfv = NULL;
|
||||
PFNGLCLEARBUFFERIVPROC glad_glClearBufferiv = NULL;
|
||||
PFNGLCLEARBUFFERUIVPROC glad_glClearBufferuiv = NULL;
|
||||
PFNGLCLEARCOLORPROC glad_glClearColor = NULL;
|
||||
PFNGLCLEARDEPTHPROC glad_glClearDepth = NULL;
|
||||
PFNGLCLEARSTENCILPROC glad_glClearStencil = NULL;
|
||||
PFNGLCLIENTWAITSYNCPROC glad_glClientWaitSync = NULL;
|
||||
PFNGLCOLORMASKPROC glad_glColorMask = NULL;
|
||||
PFNGLCOLORMASKIPROC glad_glColorMaski = NULL;
|
||||
PFNGLCOMPILESHADERPROC glad_glCompileShader = NULL;
|
||||
PFNGLCOMPRESSEDTEXIMAGE1DPROC glad_glCompressedTexImage1D = NULL;
|
||||
PFNGLCOMPRESSEDTEXIMAGE2DPROC glad_glCompressedTexImage2D = NULL;
|
||||
PFNGLCOMPRESSEDTEXIMAGE3DPROC glad_glCompressedTexImage3D = NULL;
|
||||
PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC glad_glCompressedTexSubImage1D = NULL;
|
||||
PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glad_glCompressedTexSubImage2D = NULL;
|
||||
PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glad_glCompressedTexSubImage3D = NULL;
|
||||
PFNGLCOPYBUFFERSUBDATAPROC glad_glCopyBufferSubData = NULL;
|
||||
PFNGLCOPYTEXIMAGE1DPROC glad_glCopyTexImage1D = NULL;
|
||||
PFNGLCOPYTEXIMAGE2DPROC glad_glCopyTexImage2D = NULL;
|
||||
PFNGLCOPYTEXSUBIMAGE1DPROC glad_glCopyTexSubImage1D = NULL;
|
||||
PFNGLCOPYTEXSUBIMAGE2DPROC glad_glCopyTexSubImage2D = NULL;
|
||||
PFNGLCOPYTEXSUBIMAGE3DPROC glad_glCopyTexSubImage3D = NULL;
|
||||
PFNGLCREATEPROGRAMPROC glad_glCreateProgram = NULL;
|
||||
PFNGLCREATESHADERPROC glad_glCreateShader = NULL;
|
||||
PFNGLCULLFACEPROC glad_glCullFace = NULL;
|
||||
PFNGLDELETEBUFFERSPROC glad_glDeleteBuffers = NULL;
|
||||
PFNGLDELETEFRAMEBUFFERSPROC glad_glDeleteFramebuffers = NULL;
|
||||
PFNGLDELETEPROGRAMPROC glad_glDeleteProgram = NULL;
|
||||
PFNGLDELETEQUERIESPROC glad_glDeleteQueries = NULL;
|
||||
PFNGLDELETERENDERBUFFERSPROC glad_glDeleteRenderbuffers = NULL;
|
||||
PFNGLDELETESAMPLERSPROC glad_glDeleteSamplers = NULL;
|
||||
PFNGLDELETESHADERPROC glad_glDeleteShader = NULL;
|
||||
PFNGLDELETESYNCPROC glad_glDeleteSync = NULL;
|
||||
PFNGLDELETETEXTURESPROC glad_glDeleteTextures = NULL;
|
||||
PFNGLDELETEVERTEXARRAYSPROC glad_glDeleteVertexArrays = NULL;
|
||||
PFNGLDEPTHFUNCPROC glad_glDepthFunc = NULL;
|
||||
PFNGLDEPTHMASKPROC glad_glDepthMask = NULL;
|
||||
PFNGLDEPTHRANGEPROC glad_glDepthRange = NULL;
|
||||
PFNGLDETACHSHADERPROC glad_glDetachShader = NULL;
|
||||
PFNGLDISABLEPROC glad_glDisable = NULL;
|
||||
PFNGLDISABLEVERTEXATTRIBARRAYPROC glad_glDisableVertexAttribArray = NULL;
|
||||
PFNGLDISABLEIPROC glad_glDisablei = NULL;
|
||||
PFNGLDRAWARRAYSPROC glad_glDrawArrays = NULL;
|
||||
PFNGLDRAWARRAYSINSTANCEDPROC glad_glDrawArraysInstanced = NULL;
|
||||
PFNGLDRAWBUFFERPROC glad_glDrawBuffer = NULL;
|
||||
PFNGLDRAWBUFFERSPROC glad_glDrawBuffers = NULL;
|
||||
PFNGLDRAWELEMENTSPROC glad_glDrawElements = NULL;
|
||||
PFNGLDRAWELEMENTSBASEVERTEXPROC glad_glDrawElementsBaseVertex = NULL;
|
||||
PFNGLDRAWELEMENTSINSTANCEDPROC glad_glDrawElementsInstanced = NULL;
|
||||
PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glad_glDrawElementsInstancedBaseVertex = NULL;
|
||||
PFNGLDRAWRANGEELEMENTSPROC glad_glDrawRangeElements = NULL;
|
||||
PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC glad_glDrawRangeElementsBaseVertex = NULL;
|
||||
PFNGLENABLEPROC glad_glEnable = NULL;
|
||||
PFNGLENABLEVERTEXATTRIBARRAYPROC glad_glEnableVertexAttribArray = NULL;
|
||||
PFNGLENABLEIPROC glad_glEnablei = NULL;
|
||||
PFNGLENDCONDITIONALRENDERPROC glad_glEndConditionalRender = NULL;
|
||||
PFNGLENDQUERYPROC glad_glEndQuery = NULL;
|
||||
PFNGLENDTRANSFORMFEEDBACKPROC glad_glEndTransformFeedback = NULL;
|
||||
PFNGLFENCESYNCPROC glad_glFenceSync = NULL;
|
||||
PFNGLFINISHPROC glad_glFinish = NULL;
|
||||
PFNGLFLUSHPROC glad_glFlush = NULL;
|
||||
PFNGLFLUSHMAPPEDBUFFERRANGEPROC glad_glFlushMappedBufferRange = NULL;
|
||||
PFNGLFRAMEBUFFERRENDERBUFFERPROC glad_glFramebufferRenderbuffer = NULL;
|
||||
PFNGLFRAMEBUFFERTEXTUREPROC glad_glFramebufferTexture = NULL;
|
||||
PFNGLFRAMEBUFFERTEXTURE1DPROC glad_glFramebufferTexture1D = NULL;
|
||||
PFNGLFRAMEBUFFERTEXTURE2DPROC glad_glFramebufferTexture2D = NULL;
|
||||
PFNGLFRAMEBUFFERTEXTURE3DPROC glad_glFramebufferTexture3D = NULL;
|
||||
PFNGLFRAMEBUFFERTEXTURELAYERPROC glad_glFramebufferTextureLayer = NULL;
|
||||
PFNGLFRONTFACEPROC glad_glFrontFace = NULL;
|
||||
PFNGLGENBUFFERSPROC glad_glGenBuffers = NULL;
|
||||
PFNGLGENFRAMEBUFFERSPROC glad_glGenFramebuffers = NULL;
|
||||
PFNGLGENQUERIESPROC glad_glGenQueries = NULL;
|
||||
PFNGLGENRENDERBUFFERSPROC glad_glGenRenderbuffers = NULL;
|
||||
PFNGLGENSAMPLERSPROC glad_glGenSamplers = NULL;
|
||||
PFNGLGENTEXTURESPROC glad_glGenTextures = NULL;
|
||||
PFNGLGENVERTEXARRAYSPROC glad_glGenVertexArrays = NULL;
|
||||
PFNGLGENERATEMIPMAPPROC glad_glGenerateMipmap = NULL;
|
||||
PFNGLGETACTIVEATTRIBPROC glad_glGetActiveAttrib = NULL;
|
||||
PFNGLGETACTIVEUNIFORMPROC glad_glGetActiveUniform = NULL;
|
||||
PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC glad_glGetActiveUniformBlockName = NULL;
|
||||
PFNGLGETACTIVEUNIFORMBLOCKIVPROC glad_glGetActiveUniformBlockiv = NULL;
|
||||
PFNGLGETACTIVEUNIFORMNAMEPROC glad_glGetActiveUniformName = NULL;
|
||||
PFNGLGETACTIVEUNIFORMSIVPROC glad_glGetActiveUniformsiv = NULL;
|
||||
PFNGLGETATTACHEDSHADERSPROC glad_glGetAttachedShaders = NULL;
|
||||
PFNGLGETATTRIBLOCATIONPROC glad_glGetAttribLocation = NULL;
|
||||
PFNGLGETBOOLEANI_VPROC glad_glGetBooleani_v = NULL;
|
||||
PFNGLGETBOOLEANVPROC glad_glGetBooleanv = NULL;
|
||||
PFNGLGETBUFFERPARAMETERI64VPROC glad_glGetBufferParameteri64v = NULL;
|
||||
PFNGLGETBUFFERPARAMETERIVPROC glad_glGetBufferParameteriv = NULL;
|
||||
PFNGLGETBUFFERPOINTERVPROC glad_glGetBufferPointerv = NULL;
|
||||
PFNGLGETBUFFERSUBDATAPROC glad_glGetBufferSubData = NULL;
|
||||
PFNGLGETCOMPRESSEDTEXIMAGEPROC glad_glGetCompressedTexImage = NULL;
|
||||
PFNGLGETDOUBLEVPROC glad_glGetDoublev = NULL;
|
||||
PFNGLGETERRORPROC glad_glGetError = NULL;
|
||||
PFNGLGETFLOATVPROC glad_glGetFloatv = NULL;
|
||||
PFNGLGETFRAGDATAINDEXPROC glad_glGetFragDataIndex = NULL;
|
||||
PFNGLGETFRAGDATALOCATIONPROC glad_glGetFragDataLocation = NULL;
|
||||
PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glad_glGetFramebufferAttachmentParameteriv = NULL;
|
||||
PFNGLGETINTEGER64I_VPROC glad_glGetInteger64i_v = NULL;
|
||||
PFNGLGETINTEGER64VPROC glad_glGetInteger64v = NULL;
|
||||
PFNGLGETINTEGERI_VPROC glad_glGetIntegeri_v = NULL;
|
||||
PFNGLGETINTEGERVPROC glad_glGetIntegerv = NULL;
|
||||
PFNGLGETMULTISAMPLEFVPROC glad_glGetMultisamplefv = NULL;
|
||||
PFNGLGETPROGRAMINFOLOGPROC glad_glGetProgramInfoLog = NULL;
|
||||
PFNGLGETPROGRAMIVPROC glad_glGetProgramiv = NULL;
|
||||
PFNGLGETQUERYOBJECTI64VPROC glad_glGetQueryObjecti64v = NULL;
|
||||
PFNGLGETQUERYOBJECTIVPROC glad_glGetQueryObjectiv = NULL;
|
||||
PFNGLGETQUERYOBJECTUI64VPROC glad_glGetQueryObjectui64v = NULL;
|
||||
PFNGLGETQUERYOBJECTUIVPROC glad_glGetQueryObjectuiv = NULL;
|
||||
PFNGLGETQUERYIVPROC glad_glGetQueryiv = NULL;
|
||||
PFNGLGETRENDERBUFFERPARAMETERIVPROC glad_glGetRenderbufferParameteriv = NULL;
|
||||
PFNGLGETSAMPLERPARAMETERIIVPROC glad_glGetSamplerParameterIiv = NULL;
|
||||
PFNGLGETSAMPLERPARAMETERIUIVPROC glad_glGetSamplerParameterIuiv = NULL;
|
||||
PFNGLGETSAMPLERPARAMETERFVPROC glad_glGetSamplerParameterfv = NULL;
|
||||
PFNGLGETSAMPLERPARAMETERIVPROC glad_glGetSamplerParameteriv = NULL;
|
||||
PFNGLGETSHADERINFOLOGPROC glad_glGetShaderInfoLog = NULL;
|
||||
PFNGLGETSHADERSOURCEPROC glad_glGetShaderSource = NULL;
|
||||
PFNGLGETSHADERIVPROC glad_glGetShaderiv = NULL;
|
||||
PFNGLGETSTRINGPROC glad_glGetString = NULL;
|
||||
PFNGLGETSTRINGIPROC glad_glGetStringi = NULL;
|
||||
PFNGLGETSYNCIVPROC glad_glGetSynciv = NULL;
|
||||
PFNGLGETTEXIMAGEPROC glad_glGetTexImage = NULL;
|
||||
PFNGLGETTEXLEVELPARAMETERFVPROC glad_glGetTexLevelParameterfv = NULL;
|
||||
PFNGLGETTEXLEVELPARAMETERIVPROC glad_glGetTexLevelParameteriv = NULL;
|
||||
PFNGLGETTEXPARAMETERIIVPROC glad_glGetTexParameterIiv = NULL;
|
||||
PFNGLGETTEXPARAMETERIUIVPROC glad_glGetTexParameterIuiv = NULL;
|
||||
PFNGLGETTEXPARAMETERFVPROC glad_glGetTexParameterfv = NULL;
|
||||
PFNGLGETTEXPARAMETERIVPROC glad_glGetTexParameteriv = NULL;
|
||||
PFNGLGETTRANSFORMFEEDBACKVARYINGPROC glad_glGetTransformFeedbackVarying = NULL;
|
||||
PFNGLGETUNIFORMBLOCKINDEXPROC glad_glGetUniformBlockIndex = NULL;
|
||||
PFNGLGETUNIFORMINDICESPROC glad_glGetUniformIndices = NULL;
|
||||
PFNGLGETUNIFORMLOCATIONPROC glad_glGetUniformLocation = NULL;
|
||||
PFNGLGETUNIFORMFVPROC glad_glGetUniformfv = NULL;
|
||||
PFNGLGETUNIFORMIVPROC glad_glGetUniformiv = NULL;
|
||||
PFNGLGETUNIFORMUIVPROC glad_glGetUniformuiv = NULL;
|
||||
PFNGLGETVERTEXATTRIBIIVPROC glad_glGetVertexAttribIiv = NULL;
|
||||
PFNGLGETVERTEXATTRIBIUIVPROC glad_glGetVertexAttribIuiv = NULL;
|
||||
PFNGLGETVERTEXATTRIBPOINTERVPROC glad_glGetVertexAttribPointerv = NULL;
|
||||
PFNGLGETVERTEXATTRIBDVPROC glad_glGetVertexAttribdv = NULL;
|
||||
PFNGLGETVERTEXATTRIBFVPROC glad_glGetVertexAttribfv = NULL;
|
||||
PFNGLGETVERTEXATTRIBIVPROC glad_glGetVertexAttribiv = NULL;
|
||||
PFNGLHINTPROC glad_glHint = NULL;
|
||||
PFNGLISBUFFERPROC glad_glIsBuffer = NULL;
|
||||
PFNGLISENABLEDPROC glad_glIsEnabled = NULL;
|
||||
PFNGLISENABLEDIPROC glad_glIsEnabledi = NULL;
|
||||
PFNGLISFRAMEBUFFERPROC glad_glIsFramebuffer = NULL;
|
||||
PFNGLISPROGRAMPROC glad_glIsProgram = NULL;
|
||||
PFNGLISQUERYPROC glad_glIsQuery = NULL;
|
||||
PFNGLISRENDERBUFFERPROC glad_glIsRenderbuffer = NULL;
|
||||
PFNGLISSAMPLERPROC glad_glIsSampler = NULL;
|
||||
PFNGLISSHADERPROC glad_glIsShader = NULL;
|
||||
PFNGLISSYNCPROC glad_glIsSync = NULL;
|
||||
PFNGLISTEXTUREPROC glad_glIsTexture = NULL;
|
||||
PFNGLISVERTEXARRAYPROC glad_glIsVertexArray = NULL;
|
||||
PFNGLLINEWIDTHPROC glad_glLineWidth = NULL;
|
||||
PFNGLLINKPROGRAMPROC glad_glLinkProgram = NULL;
|
||||
PFNGLLOGICOPPROC glad_glLogicOp = NULL;
|
||||
PFNGLMAPBUFFERPROC glad_glMapBuffer = NULL;
|
||||
PFNGLMAPBUFFERRANGEPROC glad_glMapBufferRange = NULL;
|
||||
PFNGLMULTIDRAWARRAYSPROC glad_glMultiDrawArrays = NULL;
|
||||
PFNGLMULTIDRAWELEMENTSPROC glad_glMultiDrawElements = NULL;
|
||||
PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC glad_glMultiDrawElementsBaseVertex = NULL;
|
||||
PFNGLPIXELSTOREFPROC glad_glPixelStoref = NULL;
|
||||
PFNGLPIXELSTOREIPROC glad_glPixelStorei = NULL;
|
||||
PFNGLPOINTPARAMETERFPROC glad_glPointParameterf = NULL;
|
||||
PFNGLPOINTPARAMETERFVPROC glad_glPointParameterfv = NULL;
|
||||
PFNGLPOINTPARAMETERIPROC glad_glPointParameteri = NULL;
|
||||
PFNGLPOINTPARAMETERIVPROC glad_glPointParameteriv = NULL;
|
||||
PFNGLPOINTSIZEPROC glad_glPointSize = NULL;
|
||||
PFNGLPOLYGONMODEPROC glad_glPolygonMode = NULL;
|
||||
PFNGLPOLYGONOFFSETPROC glad_glPolygonOffset = NULL;
|
||||
PFNGLPRIMITIVERESTARTINDEXPROC glad_glPrimitiveRestartIndex = NULL;
|
||||
PFNGLPROVOKINGVERTEXPROC glad_glProvokingVertex = NULL;
|
||||
PFNGLQUERYCOUNTERPROC glad_glQueryCounter = NULL;
|
||||
PFNGLREADBUFFERPROC glad_glReadBuffer = NULL;
|
||||
PFNGLREADPIXELSPROC glad_glReadPixels = NULL;
|
||||
PFNGLRENDERBUFFERSTORAGEPROC glad_glRenderbufferStorage = NULL;
|
||||
PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glad_glRenderbufferStorageMultisample = NULL;
|
||||
PFNGLSAMPLECOVERAGEPROC glad_glSampleCoverage = NULL;
|
||||
PFNGLSAMPLEMASKIPROC glad_glSampleMaski = NULL;
|
||||
PFNGLSAMPLERPARAMETERIIVPROC glad_glSamplerParameterIiv = NULL;
|
||||
PFNGLSAMPLERPARAMETERIUIVPROC glad_glSamplerParameterIuiv = NULL;
|
||||
PFNGLSAMPLERPARAMETERFPROC glad_glSamplerParameterf = NULL;
|
||||
PFNGLSAMPLERPARAMETERFVPROC glad_glSamplerParameterfv = NULL;
|
||||
PFNGLSAMPLERPARAMETERIPROC glad_glSamplerParameteri = NULL;
|
||||
PFNGLSAMPLERPARAMETERIVPROC glad_glSamplerParameteriv = NULL;
|
||||
PFNGLSCISSORPROC glad_glScissor = NULL;
|
||||
PFNGLSHADERSOURCEPROC glad_glShaderSource = NULL;
|
||||
PFNGLSTENCILFUNCPROC glad_glStencilFunc = NULL;
|
||||
PFNGLSTENCILFUNCSEPARATEPROC glad_glStencilFuncSeparate = NULL;
|
||||
PFNGLSTENCILMASKPROC glad_glStencilMask = NULL;
|
||||
PFNGLSTENCILMASKSEPARATEPROC glad_glStencilMaskSeparate = NULL;
|
||||
PFNGLSTENCILOPPROC glad_glStencilOp = NULL;
|
||||
PFNGLSTENCILOPSEPARATEPROC glad_glStencilOpSeparate = NULL;
|
||||
PFNGLTEXBUFFERPROC glad_glTexBuffer = NULL;
|
||||
PFNGLTEXIMAGE1DPROC glad_glTexImage1D = NULL;
|
||||
PFNGLTEXIMAGE2DPROC glad_glTexImage2D = NULL;
|
||||
PFNGLTEXIMAGE2DMULTISAMPLEPROC glad_glTexImage2DMultisample = NULL;
|
||||
PFNGLTEXIMAGE3DPROC glad_glTexImage3D = NULL;
|
||||
PFNGLTEXIMAGE3DMULTISAMPLEPROC glad_glTexImage3DMultisample = NULL;
|
||||
PFNGLTEXPARAMETERIIVPROC glad_glTexParameterIiv = NULL;
|
||||
PFNGLTEXPARAMETERIUIVPROC glad_glTexParameterIuiv = NULL;
|
||||
PFNGLTEXPARAMETERFPROC glad_glTexParameterf = NULL;
|
||||
PFNGLTEXPARAMETERFVPROC glad_glTexParameterfv = NULL;
|
||||
PFNGLTEXPARAMETERIPROC glad_glTexParameteri = NULL;
|
||||
PFNGLTEXPARAMETERIVPROC glad_glTexParameteriv = NULL;
|
||||
PFNGLTEXSUBIMAGE1DPROC glad_glTexSubImage1D = NULL;
|
||||
PFNGLTEXSUBIMAGE2DPROC glad_glTexSubImage2D = NULL;
|
||||
PFNGLTEXSUBIMAGE3DPROC glad_glTexSubImage3D = NULL;
|
||||
PFNGLTRANSFORMFEEDBACKVARYINGSPROC glad_glTransformFeedbackVaryings = NULL;
|
||||
PFNGLUNIFORM1FPROC glad_glUniform1f = NULL;
|
||||
PFNGLUNIFORM1FVPROC glad_glUniform1fv = NULL;
|
||||
PFNGLUNIFORM1IPROC glad_glUniform1i = NULL;
|
||||
PFNGLUNIFORM1IVPROC glad_glUniform1iv = NULL;
|
||||
PFNGLUNIFORM1UIPROC glad_glUniform1ui = NULL;
|
||||
PFNGLUNIFORM1UIVPROC glad_glUniform1uiv = NULL;
|
||||
PFNGLUNIFORM2FPROC glad_glUniform2f = NULL;
|
||||
PFNGLUNIFORM2FVPROC glad_glUniform2fv = NULL;
|
||||
PFNGLUNIFORM2IPROC glad_glUniform2i = NULL;
|
||||
PFNGLUNIFORM2IVPROC glad_glUniform2iv = NULL;
|
||||
PFNGLUNIFORM2UIPROC glad_glUniform2ui = NULL;
|
||||
PFNGLUNIFORM2UIVPROC glad_glUniform2uiv = NULL;
|
||||
PFNGLUNIFORM3FPROC glad_glUniform3f = NULL;
|
||||
PFNGLUNIFORM3FVPROC glad_glUniform3fv = NULL;
|
||||
PFNGLUNIFORM3IPROC glad_glUniform3i = NULL;
|
||||
PFNGLUNIFORM3IVPROC glad_glUniform3iv = NULL;
|
||||
PFNGLUNIFORM3UIPROC glad_glUniform3ui = NULL;
|
||||
PFNGLUNIFORM3UIVPROC glad_glUniform3uiv = NULL;
|
||||
PFNGLUNIFORM4FPROC glad_glUniform4f = NULL;
|
||||
PFNGLUNIFORM4FVPROC glad_glUniform4fv = NULL;
|
||||
PFNGLUNIFORM4IPROC glad_glUniform4i = NULL;
|
||||
PFNGLUNIFORM4IVPROC glad_glUniform4iv = NULL;
|
||||
PFNGLUNIFORM4UIPROC glad_glUniform4ui = NULL;
|
||||
PFNGLUNIFORM4UIVPROC glad_glUniform4uiv = NULL;
|
||||
PFNGLUNIFORMBLOCKBINDINGPROC glad_glUniformBlockBinding = NULL;
|
||||
PFNGLUNIFORMMATRIX2FVPROC glad_glUniformMatrix2fv = NULL;
|
||||
PFNGLUNIFORMMATRIX2X3FVPROC glad_glUniformMatrix2x3fv = NULL;
|
||||
PFNGLUNIFORMMATRIX2X4FVPROC glad_glUniformMatrix2x4fv = NULL;
|
||||
PFNGLUNIFORMMATRIX3FVPROC glad_glUniformMatrix3fv = NULL;
|
||||
PFNGLUNIFORMMATRIX3X2FVPROC glad_glUniformMatrix3x2fv = NULL;
|
||||
PFNGLUNIFORMMATRIX3X4FVPROC glad_glUniformMatrix3x4fv = NULL;
|
||||
PFNGLUNIFORMMATRIX4FVPROC glad_glUniformMatrix4fv = NULL;
|
||||
PFNGLUNIFORMMATRIX4X2FVPROC glad_glUniformMatrix4x2fv = NULL;
|
||||
PFNGLUNIFORMMATRIX4X3FVPROC glad_glUniformMatrix4x3fv = NULL;
|
||||
PFNGLUNMAPBUFFERPROC glad_glUnmapBuffer = NULL;
|
||||
PFNGLUSEPROGRAMPROC glad_glUseProgram = NULL;
|
||||
PFNGLVALIDATEPROGRAMPROC glad_glValidateProgram = NULL;
|
||||
PFNGLVERTEXATTRIB1DPROC glad_glVertexAttrib1d = NULL;
|
||||
PFNGLVERTEXATTRIB1DVPROC glad_glVertexAttrib1dv = NULL;
|
||||
PFNGLVERTEXATTRIB1FPROC glad_glVertexAttrib1f = NULL;
|
||||
PFNGLVERTEXATTRIB1FVPROC glad_glVertexAttrib1fv = NULL;
|
||||
PFNGLVERTEXATTRIB1SPROC glad_glVertexAttrib1s = NULL;
|
||||
PFNGLVERTEXATTRIB1SVPROC glad_glVertexAttrib1sv = NULL;
|
||||
PFNGLVERTEXATTRIB2DPROC glad_glVertexAttrib2d = NULL;
|
||||
PFNGLVERTEXATTRIB2DVPROC glad_glVertexAttrib2dv = NULL;
|
||||
PFNGLVERTEXATTRIB2FPROC glad_glVertexAttrib2f = NULL;
|
||||
PFNGLVERTEXATTRIB2FVPROC glad_glVertexAttrib2fv = NULL;
|
||||
PFNGLVERTEXATTRIB2SPROC glad_glVertexAttrib2s = NULL;
|
||||
PFNGLVERTEXATTRIB2SVPROC glad_glVertexAttrib2sv = NULL;
|
||||
PFNGLVERTEXATTRIB3DPROC glad_glVertexAttrib3d = NULL;
|
||||
PFNGLVERTEXATTRIB3DVPROC glad_glVertexAttrib3dv = NULL;
|
||||
PFNGLVERTEXATTRIB3FPROC glad_glVertexAttrib3f = NULL;
|
||||
PFNGLVERTEXATTRIB3FVPROC glad_glVertexAttrib3fv = NULL;
|
||||
PFNGLVERTEXATTRIB3SPROC glad_glVertexAttrib3s = NULL;
|
||||
PFNGLVERTEXATTRIB3SVPROC glad_glVertexAttrib3sv = NULL;
|
||||
PFNGLVERTEXATTRIB4NBVPROC glad_glVertexAttrib4Nbv = NULL;
|
||||
PFNGLVERTEXATTRIB4NIVPROC glad_glVertexAttrib4Niv = NULL;
|
||||
PFNGLVERTEXATTRIB4NSVPROC glad_glVertexAttrib4Nsv = NULL;
|
||||
PFNGLVERTEXATTRIB4NUBPROC glad_glVertexAttrib4Nub = NULL;
|
||||
PFNGLVERTEXATTRIB4NUBVPROC glad_glVertexAttrib4Nubv = NULL;
|
||||
PFNGLVERTEXATTRIB4NUIVPROC glad_glVertexAttrib4Nuiv = NULL;
|
||||
PFNGLVERTEXATTRIB4NUSVPROC glad_glVertexAttrib4Nusv = NULL;
|
||||
PFNGLVERTEXATTRIB4BVPROC glad_glVertexAttrib4bv = NULL;
|
||||
PFNGLVERTEXATTRIB4DPROC glad_glVertexAttrib4d = NULL;
|
||||
PFNGLVERTEXATTRIB4DVPROC glad_glVertexAttrib4dv = NULL;
|
||||
PFNGLVERTEXATTRIB4FPROC glad_glVertexAttrib4f = NULL;
|
||||
PFNGLVERTEXATTRIB4FVPROC glad_glVertexAttrib4fv = NULL;
|
||||
PFNGLVERTEXATTRIB4IVPROC glad_glVertexAttrib4iv = NULL;
|
||||
PFNGLVERTEXATTRIB4SPROC glad_glVertexAttrib4s = NULL;
|
||||
PFNGLVERTEXATTRIB4SVPROC glad_glVertexAttrib4sv = NULL;
|
||||
PFNGLVERTEXATTRIB4UBVPROC glad_glVertexAttrib4ubv = NULL;
|
||||
PFNGLVERTEXATTRIB4UIVPROC glad_glVertexAttrib4uiv = NULL;
|
||||
PFNGLVERTEXATTRIB4USVPROC glad_glVertexAttrib4usv = NULL;
|
||||
PFNGLVERTEXATTRIBDIVISORPROC glad_glVertexAttribDivisor = NULL;
|
||||
PFNGLVERTEXATTRIBI1IPROC glad_glVertexAttribI1i = NULL;
|
||||
PFNGLVERTEXATTRIBI1IVPROC glad_glVertexAttribI1iv = NULL;
|
||||
PFNGLVERTEXATTRIBI1UIPROC glad_glVertexAttribI1ui = NULL;
|
||||
PFNGLVERTEXATTRIBI1UIVPROC glad_glVertexAttribI1uiv = NULL;
|
||||
PFNGLVERTEXATTRIBI2IPROC glad_glVertexAttribI2i = NULL;
|
||||
PFNGLVERTEXATTRIBI2IVPROC glad_glVertexAttribI2iv = NULL;
|
||||
PFNGLVERTEXATTRIBI2UIPROC glad_glVertexAttribI2ui = NULL;
|
||||
PFNGLVERTEXATTRIBI2UIVPROC glad_glVertexAttribI2uiv = NULL;
|
||||
PFNGLVERTEXATTRIBI3IPROC glad_glVertexAttribI3i = NULL;
|
||||
PFNGLVERTEXATTRIBI3IVPROC glad_glVertexAttribI3iv = NULL;
|
||||
PFNGLVERTEXATTRIBI3UIPROC glad_glVertexAttribI3ui = NULL;
|
||||
PFNGLVERTEXATTRIBI3UIVPROC glad_glVertexAttribI3uiv = NULL;
|
||||
PFNGLVERTEXATTRIBI4BVPROC glad_glVertexAttribI4bv = NULL;
|
||||
PFNGLVERTEXATTRIBI4IPROC glad_glVertexAttribI4i = NULL;
|
||||
PFNGLVERTEXATTRIBI4IVPROC glad_glVertexAttribI4iv = NULL;
|
||||
PFNGLVERTEXATTRIBI4SVPROC glad_glVertexAttribI4sv = NULL;
|
||||
PFNGLVERTEXATTRIBI4UBVPROC glad_glVertexAttribI4ubv = NULL;
|
||||
PFNGLVERTEXATTRIBI4UIPROC glad_glVertexAttribI4ui = NULL;
|
||||
PFNGLVERTEXATTRIBI4UIVPROC glad_glVertexAttribI4uiv = NULL;
|
||||
PFNGLVERTEXATTRIBI4USVPROC glad_glVertexAttribI4usv = NULL;
|
||||
PFNGLVERTEXATTRIBIPOINTERPROC glad_glVertexAttribIPointer = NULL;
|
||||
PFNGLVERTEXATTRIBP1UIPROC glad_glVertexAttribP1ui = NULL;
|
||||
PFNGLVERTEXATTRIBP1UIVPROC glad_glVertexAttribP1uiv = NULL;
|
||||
PFNGLVERTEXATTRIBP2UIPROC glad_glVertexAttribP2ui = NULL;
|
||||
PFNGLVERTEXATTRIBP2UIVPROC glad_glVertexAttribP2uiv = NULL;
|
||||
PFNGLVERTEXATTRIBP3UIPROC glad_glVertexAttribP3ui = NULL;
|
||||
PFNGLVERTEXATTRIBP3UIVPROC glad_glVertexAttribP3uiv = NULL;
|
||||
PFNGLVERTEXATTRIBP4UIPROC glad_glVertexAttribP4ui = NULL;
|
||||
PFNGLVERTEXATTRIBP4UIVPROC glad_glVertexAttribP4uiv = NULL;
|
||||
PFNGLVERTEXATTRIBPOINTERPROC glad_glVertexAttribPointer = NULL;
|
||||
PFNGLVIEWPORTPROC glad_glViewport = NULL;
|
||||
PFNGLWAITSYNCPROC glad_glWaitSync = NULL;
|
||||
|
||||
|
||||
static void glad_gl_load_GL_VERSION_1_0( GLADuserptrloadfunc load, void* userptr) {
|
||||
if(!GLAD_GL_VERSION_1_0) return;
|
||||
glad_glBlendFunc = (PFNGLBLENDFUNCPROC) load(userptr, "glBlendFunc");
|
||||
glad_glClear = (PFNGLCLEARPROC) load(userptr, "glClear");
|
||||
glad_glClearColor = (PFNGLCLEARCOLORPROC) load(userptr, "glClearColor");
|
||||
glad_glClearDepth = (PFNGLCLEARDEPTHPROC) load(userptr, "glClearDepth");
|
||||
glad_glClearStencil = (PFNGLCLEARSTENCILPROC) load(userptr, "glClearStencil");
|
||||
glad_glColorMask = (PFNGLCOLORMASKPROC) load(userptr, "glColorMask");
|
||||
glad_glCullFace = (PFNGLCULLFACEPROC) load(userptr, "glCullFace");
|
||||
glad_glDepthFunc = (PFNGLDEPTHFUNCPROC) load(userptr, "glDepthFunc");
|
||||
glad_glDepthMask = (PFNGLDEPTHMASKPROC) load(userptr, "glDepthMask");
|
||||
glad_glDepthRange = (PFNGLDEPTHRANGEPROC) load(userptr, "glDepthRange");
|
||||
glad_glDisable = (PFNGLDISABLEPROC) load(userptr, "glDisable");
|
||||
glad_glDrawBuffer = (PFNGLDRAWBUFFERPROC) load(userptr, "glDrawBuffer");
|
||||
glad_glEnable = (PFNGLENABLEPROC) load(userptr, "glEnable");
|
||||
glad_glFinish = (PFNGLFINISHPROC) load(userptr, "glFinish");
|
||||
glad_glFlush = (PFNGLFLUSHPROC) load(userptr, "glFlush");
|
||||
glad_glFrontFace = (PFNGLFRONTFACEPROC) load(userptr, "glFrontFace");
|
||||
glad_glGetBooleanv = (PFNGLGETBOOLEANVPROC) load(userptr, "glGetBooleanv");
|
||||
glad_glGetDoublev = (PFNGLGETDOUBLEVPROC) load(userptr, "glGetDoublev");
|
||||
glad_glGetError = (PFNGLGETERRORPROC) load(userptr, "glGetError");
|
||||
glad_glGetFloatv = (PFNGLGETFLOATVPROC) load(userptr, "glGetFloatv");
|
||||
glad_glGetIntegerv = (PFNGLGETINTEGERVPROC) load(userptr, "glGetIntegerv");
|
||||
glad_glGetString = (PFNGLGETSTRINGPROC) load(userptr, "glGetString");
|
||||
glad_glGetTexImage = (PFNGLGETTEXIMAGEPROC) load(userptr, "glGetTexImage");
|
||||
glad_glGetTexLevelParameterfv = (PFNGLGETTEXLEVELPARAMETERFVPROC) load(userptr, "glGetTexLevelParameterfv");
|
||||
glad_glGetTexLevelParameteriv = (PFNGLGETTEXLEVELPARAMETERIVPROC) load(userptr, "glGetTexLevelParameteriv");
|
||||
glad_glGetTexParameterfv = (PFNGLGETTEXPARAMETERFVPROC) load(userptr, "glGetTexParameterfv");
|
||||
glad_glGetTexParameteriv = (PFNGLGETTEXPARAMETERIVPROC) load(userptr, "glGetTexParameteriv");
|
||||
glad_glHint = (PFNGLHINTPROC) load(userptr, "glHint");
|
||||
glad_glIsEnabled = (PFNGLISENABLEDPROC) load(userptr, "glIsEnabled");
|
||||
glad_glLineWidth = (PFNGLLINEWIDTHPROC) load(userptr, "glLineWidth");
|
||||
glad_glLogicOp = (PFNGLLOGICOPPROC) load(userptr, "glLogicOp");
|
||||
glad_glPixelStoref = (PFNGLPIXELSTOREFPROC) load(userptr, "glPixelStoref");
|
||||
glad_glPixelStorei = (PFNGLPIXELSTOREIPROC) load(userptr, "glPixelStorei");
|
||||
glad_glPointSize = (PFNGLPOINTSIZEPROC) load(userptr, "glPointSize");
|
||||
glad_glPolygonMode = (PFNGLPOLYGONMODEPROC) load(userptr, "glPolygonMode");
|
||||
glad_glReadBuffer = (PFNGLREADBUFFERPROC) load(userptr, "glReadBuffer");
|
||||
glad_glReadPixels = (PFNGLREADPIXELSPROC) load(userptr, "glReadPixels");
|
||||
glad_glScissor = (PFNGLSCISSORPROC) load(userptr, "glScissor");
|
||||
glad_glStencilFunc = (PFNGLSTENCILFUNCPROC) load(userptr, "glStencilFunc");
|
||||
glad_glStencilMask = (PFNGLSTENCILMASKPROC) load(userptr, "glStencilMask");
|
||||
glad_glStencilOp = (PFNGLSTENCILOPPROC) load(userptr, "glStencilOp");
|
||||
glad_glTexImage1D = (PFNGLTEXIMAGE1DPROC) load(userptr, "glTexImage1D");
|
||||
glad_glTexImage2D = (PFNGLTEXIMAGE2DPROC) load(userptr, "glTexImage2D");
|
||||
glad_glTexParameterf = (PFNGLTEXPARAMETERFPROC) load(userptr, "glTexParameterf");
|
||||
glad_glTexParameterfv = (PFNGLTEXPARAMETERFVPROC) load(userptr, "glTexParameterfv");
|
||||
glad_glTexParameteri = (PFNGLTEXPARAMETERIPROC) load(userptr, "glTexParameteri");
|
||||
glad_glTexParameteriv = (PFNGLTEXPARAMETERIVPROC) load(userptr, "glTexParameteriv");
|
||||
glad_glViewport = (PFNGLVIEWPORTPROC) load(userptr, "glViewport");
|
||||
}
|
||||
static void glad_gl_load_GL_VERSION_1_1( GLADuserptrloadfunc load, void* userptr) {
|
||||
if(!GLAD_GL_VERSION_1_1) return;
|
||||
glad_glBindTexture = (PFNGLBINDTEXTUREPROC) load(userptr, "glBindTexture");
|
||||
glad_glCopyTexImage1D = (PFNGLCOPYTEXIMAGE1DPROC) load(userptr, "glCopyTexImage1D");
|
||||
glad_glCopyTexImage2D = (PFNGLCOPYTEXIMAGE2DPROC) load(userptr, "glCopyTexImage2D");
|
||||
glad_glCopyTexSubImage1D = (PFNGLCOPYTEXSUBIMAGE1DPROC) load(userptr, "glCopyTexSubImage1D");
|
||||
glad_glCopyTexSubImage2D = (PFNGLCOPYTEXSUBIMAGE2DPROC) load(userptr, "glCopyTexSubImage2D");
|
||||
glad_glDeleteTextures = (PFNGLDELETETEXTURESPROC) load(userptr, "glDeleteTextures");
|
||||
glad_glDrawArrays = (PFNGLDRAWARRAYSPROC) load(userptr, "glDrawArrays");
|
||||
glad_glDrawElements = (PFNGLDRAWELEMENTSPROC) load(userptr, "glDrawElements");
|
||||
glad_glGenTextures = (PFNGLGENTEXTURESPROC) load(userptr, "glGenTextures");
|
||||
glad_glIsTexture = (PFNGLISTEXTUREPROC) load(userptr, "glIsTexture");
|
||||
glad_glPolygonOffset = (PFNGLPOLYGONOFFSETPROC) load(userptr, "glPolygonOffset");
|
||||
glad_glTexSubImage1D = (PFNGLTEXSUBIMAGE1DPROC) load(userptr, "glTexSubImage1D");
|
||||
glad_glTexSubImage2D = (PFNGLTEXSUBIMAGE2DPROC) load(userptr, "glTexSubImage2D");
|
||||
}
|
||||
static void glad_gl_load_GL_VERSION_1_2( GLADuserptrloadfunc load, void* userptr) {
|
||||
if(!GLAD_GL_VERSION_1_2) return;
|
||||
glad_glCopyTexSubImage3D = (PFNGLCOPYTEXSUBIMAGE3DPROC) load(userptr, "glCopyTexSubImage3D");
|
||||
glad_glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC) load(userptr, "glDrawRangeElements");
|
||||
glad_glTexImage3D = (PFNGLTEXIMAGE3DPROC) load(userptr, "glTexImage3D");
|
||||
glad_glTexSubImage3D = (PFNGLTEXSUBIMAGE3DPROC) load(userptr, "glTexSubImage3D");
|
||||
}
|
||||
static void glad_gl_load_GL_VERSION_1_3( GLADuserptrloadfunc load, void* userptr) {
|
||||
if(!GLAD_GL_VERSION_1_3) return;
|
||||
glad_glActiveTexture = (PFNGLACTIVETEXTUREPROC) load(userptr, "glActiveTexture");
|
||||
glad_glCompressedTexImage1D = (PFNGLCOMPRESSEDTEXIMAGE1DPROC) load(userptr, "glCompressedTexImage1D");
|
||||
glad_glCompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DPROC) load(userptr, "glCompressedTexImage2D");
|
||||
glad_glCompressedTexImage3D = (PFNGLCOMPRESSEDTEXIMAGE3DPROC) load(userptr, "glCompressedTexImage3D");
|
||||
glad_glCompressedTexSubImage1D = (PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) load(userptr, "glCompressedTexSubImage1D");
|
||||
glad_glCompressedTexSubImage2D = (PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) load(userptr, "glCompressedTexSubImage2D");
|
||||
glad_glCompressedTexSubImage3D = (PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) load(userptr, "glCompressedTexSubImage3D");
|
||||
glad_glGetCompressedTexImage = (PFNGLGETCOMPRESSEDTEXIMAGEPROC) load(userptr, "glGetCompressedTexImage");
|
||||
glad_glSampleCoverage = (PFNGLSAMPLECOVERAGEPROC) load(userptr, "glSampleCoverage");
|
||||
}
|
||||
static void glad_gl_load_GL_VERSION_1_4( GLADuserptrloadfunc load, void* userptr) {
|
||||
if(!GLAD_GL_VERSION_1_4) return;
|
||||
glad_glBlendColor = (PFNGLBLENDCOLORPROC) load(userptr, "glBlendColor");
|
||||
glad_glBlendEquation = (PFNGLBLENDEQUATIONPROC) load(userptr, "glBlendEquation");
|
||||
glad_glBlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC) load(userptr, "glBlendFuncSeparate");
|
||||
glad_glMultiDrawArrays = (PFNGLMULTIDRAWARRAYSPROC) load(userptr, "glMultiDrawArrays");
|
||||
glad_glMultiDrawElements = (PFNGLMULTIDRAWELEMENTSPROC) load(userptr, "glMultiDrawElements");
|
||||
glad_glPointParameterf = (PFNGLPOINTPARAMETERFPROC) load(userptr, "glPointParameterf");
|
||||
glad_glPointParameterfv = (PFNGLPOINTPARAMETERFVPROC) load(userptr, "glPointParameterfv");
|
||||
glad_glPointParameteri = (PFNGLPOINTPARAMETERIPROC) load(userptr, "glPointParameteri");
|
||||
glad_glPointParameteriv = (PFNGLPOINTPARAMETERIVPROC) load(userptr, "glPointParameteriv");
|
||||
}
|
||||
static void glad_gl_load_GL_VERSION_1_5( GLADuserptrloadfunc load, void* userptr) {
|
||||
if(!GLAD_GL_VERSION_1_5) return;
|
||||
glad_glBeginQuery = (PFNGLBEGINQUERYPROC) load(userptr, "glBeginQuery");
|
||||
glad_glBindBuffer = (PFNGLBINDBUFFERPROC) load(userptr, "glBindBuffer");
|
||||
glad_glBufferData = (PFNGLBUFFERDATAPROC) load(userptr, "glBufferData");
|
||||
glad_glBufferSubData = (PFNGLBUFFERSUBDATAPROC) load(userptr, "glBufferSubData");
|
||||
glad_glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) load(userptr, "glDeleteBuffers");
|
||||
glad_glDeleteQueries = (PFNGLDELETEQUERIESPROC) load(userptr, "glDeleteQueries");
|
||||
glad_glEndQuery = (PFNGLENDQUERYPROC) load(userptr, "glEndQuery");
|
||||
glad_glGenBuffers = (PFNGLGENBUFFERSPROC) load(userptr, "glGenBuffers");
|
||||
glad_glGenQueries = (PFNGLGENQUERIESPROC) load(userptr, "glGenQueries");
|
||||
glad_glGetBufferParameteriv = (PFNGLGETBUFFERPARAMETERIVPROC) load(userptr, "glGetBufferParameteriv");
|
||||
glad_glGetBufferPointerv = (PFNGLGETBUFFERPOINTERVPROC) load(userptr, "glGetBufferPointerv");
|
||||
glad_glGetBufferSubData = (PFNGLGETBUFFERSUBDATAPROC) load(userptr, "glGetBufferSubData");
|
||||
glad_glGetQueryObjectiv = (PFNGLGETQUERYOBJECTIVPROC) load(userptr, "glGetQueryObjectiv");
|
||||
glad_glGetQueryObjectuiv = (PFNGLGETQUERYOBJECTUIVPROC) load(userptr, "glGetQueryObjectuiv");
|
||||
glad_glGetQueryiv = (PFNGLGETQUERYIVPROC) load(userptr, "glGetQueryiv");
|
||||
glad_glIsBuffer = (PFNGLISBUFFERPROC) load(userptr, "glIsBuffer");
|
||||
glad_glIsQuery = (PFNGLISQUERYPROC) load(userptr, "glIsQuery");
|
||||
glad_glMapBuffer = (PFNGLMAPBUFFERPROC) load(userptr, "glMapBuffer");
|
||||
glad_glUnmapBuffer = (PFNGLUNMAPBUFFERPROC) load(userptr, "glUnmapBuffer");
|
||||
}
|
||||
static void glad_gl_load_GL_VERSION_2_0( GLADuserptrloadfunc load, void* userptr) {
|
||||
if(!GLAD_GL_VERSION_2_0) return;
|
||||
glad_glAttachShader = (PFNGLATTACHSHADERPROC) load(userptr, "glAttachShader");
|
||||
glad_glBindAttribLocation = (PFNGLBINDATTRIBLOCATIONPROC) load(userptr, "glBindAttribLocation");
|
||||
glad_glBlendEquationSeparate = (PFNGLBLENDEQUATIONSEPARATEPROC) load(userptr, "glBlendEquationSeparate");
|
||||
glad_glCompileShader = (PFNGLCOMPILESHADERPROC) load(userptr, "glCompileShader");
|
||||
glad_glCreateProgram = (PFNGLCREATEPROGRAMPROC) load(userptr, "glCreateProgram");
|
||||
glad_glCreateShader = (PFNGLCREATESHADERPROC) load(userptr, "glCreateShader");
|
||||
glad_glDeleteProgram = (PFNGLDELETEPROGRAMPROC) load(userptr, "glDeleteProgram");
|
||||
glad_glDeleteShader = (PFNGLDELETESHADERPROC) load(userptr, "glDeleteShader");
|
||||
glad_glDetachShader = (PFNGLDETACHSHADERPROC) load(userptr, "glDetachShader");
|
||||
glad_glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC) load(userptr, "glDisableVertexAttribArray");
|
||||
glad_glDrawBuffers = (PFNGLDRAWBUFFERSPROC) load(userptr, "glDrawBuffers");
|
||||
glad_glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC) load(userptr, "glEnableVertexAttribArray");
|
||||
glad_glGetActiveAttrib = (PFNGLGETACTIVEATTRIBPROC) load(userptr, "glGetActiveAttrib");
|
||||
glad_glGetActiveUniform = (PFNGLGETACTIVEUNIFORMPROC) load(userptr, "glGetActiveUniform");
|
||||
glad_glGetAttachedShaders = (PFNGLGETATTACHEDSHADERSPROC) load(userptr, "glGetAttachedShaders");
|
||||
glad_glGetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC) load(userptr, "glGetAttribLocation");
|
||||
glad_glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) load(userptr, "glGetProgramInfoLog");
|
||||
glad_glGetProgramiv = (PFNGLGETPROGRAMIVPROC) load(userptr, "glGetProgramiv");
|
||||
glad_glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC) load(userptr, "glGetShaderInfoLog");
|
||||
glad_glGetShaderSource = (PFNGLGETSHADERSOURCEPROC) load(userptr, "glGetShaderSource");
|
||||
glad_glGetShaderiv = (PFNGLGETSHADERIVPROC) load(userptr, "glGetShaderiv");
|
||||
glad_glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC) load(userptr, "glGetUniformLocation");
|
||||
glad_glGetUniformfv = (PFNGLGETUNIFORMFVPROC) load(userptr, "glGetUniformfv");
|
||||
glad_glGetUniformiv = (PFNGLGETUNIFORMIVPROC) load(userptr, "glGetUniformiv");
|
||||
glad_glGetVertexAttribPointerv = (PFNGLGETVERTEXATTRIBPOINTERVPROC) load(userptr, "glGetVertexAttribPointerv");
|
||||
glad_glGetVertexAttribdv = (PFNGLGETVERTEXATTRIBDVPROC) load(userptr, "glGetVertexAttribdv");
|
||||
glad_glGetVertexAttribfv = (PFNGLGETVERTEXATTRIBFVPROC) load(userptr, "glGetVertexAttribfv");
|
||||
glad_glGetVertexAttribiv = (PFNGLGETVERTEXATTRIBIVPROC) load(userptr, "glGetVertexAttribiv");
|
||||
glad_glIsProgram = (PFNGLISPROGRAMPROC) load(userptr, "glIsProgram");
|
||||
glad_glIsShader = (PFNGLISSHADERPROC) load(userptr, "glIsShader");
|
||||
glad_glLinkProgram = (PFNGLLINKPROGRAMPROC) load(userptr, "glLinkProgram");
|
||||
glad_glShaderSource = (PFNGLSHADERSOURCEPROC) load(userptr, "glShaderSource");
|
||||
glad_glStencilFuncSeparate = (PFNGLSTENCILFUNCSEPARATEPROC) load(userptr, "glStencilFuncSeparate");
|
||||
glad_glStencilMaskSeparate = (PFNGLSTENCILMASKSEPARATEPROC) load(userptr, "glStencilMaskSeparate");
|
||||
glad_glStencilOpSeparate = (PFNGLSTENCILOPSEPARATEPROC) load(userptr, "glStencilOpSeparate");
|
||||
glad_glUniform1f = (PFNGLUNIFORM1FPROC) load(userptr, "glUniform1f");
|
||||
glad_glUniform1fv = (PFNGLUNIFORM1FVPROC) load(userptr, "glUniform1fv");
|
||||
glad_glUniform1i = (PFNGLUNIFORM1IPROC) load(userptr, "glUniform1i");
|
||||
glad_glUniform1iv = (PFNGLUNIFORM1IVPROC) load(userptr, "glUniform1iv");
|
||||
glad_glUniform2f = (PFNGLUNIFORM2FPROC) load(userptr, "glUniform2f");
|
||||
glad_glUniform2fv = (PFNGLUNIFORM2FVPROC) load(userptr, "glUniform2fv");
|
||||
glad_glUniform2i = (PFNGLUNIFORM2IPROC) load(userptr, "glUniform2i");
|
||||
glad_glUniform2iv = (PFNGLUNIFORM2IVPROC) load(userptr, "glUniform2iv");
|
||||
glad_glUniform3f = (PFNGLUNIFORM3FPROC) load(userptr, "glUniform3f");
|
||||
glad_glUniform3fv = (PFNGLUNIFORM3FVPROC) load(userptr, "glUniform3fv");
|
||||
glad_glUniform3i = (PFNGLUNIFORM3IPROC) load(userptr, "glUniform3i");
|
||||
glad_glUniform3iv = (PFNGLUNIFORM3IVPROC) load(userptr, "glUniform3iv");
|
||||
glad_glUniform4f = (PFNGLUNIFORM4FPROC) load(userptr, "glUniform4f");
|
||||
glad_glUniform4fv = (PFNGLUNIFORM4FVPROC) load(userptr, "glUniform4fv");
|
||||
glad_glUniform4i = (PFNGLUNIFORM4IPROC) load(userptr, "glUniform4i");
|
||||
glad_glUniform4iv = (PFNGLUNIFORM4IVPROC) load(userptr, "glUniform4iv");
|
||||
glad_glUniformMatrix2fv = (PFNGLUNIFORMMATRIX2FVPROC) load(userptr, "glUniformMatrix2fv");
|
||||
glad_glUniformMatrix3fv = (PFNGLUNIFORMMATRIX3FVPROC) load(userptr, "glUniformMatrix3fv");
|
||||
glad_glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC) load(userptr, "glUniformMatrix4fv");
|
||||
glad_glUseProgram = (PFNGLUSEPROGRAMPROC) load(userptr, "glUseProgram");
|
||||
glad_glValidateProgram = (PFNGLVALIDATEPROGRAMPROC) load(userptr, "glValidateProgram");
|
||||
glad_glVertexAttrib1d = (PFNGLVERTEXATTRIB1DPROC) load(userptr, "glVertexAttrib1d");
|
||||
glad_glVertexAttrib1dv = (PFNGLVERTEXATTRIB1DVPROC) load(userptr, "glVertexAttrib1dv");
|
||||
glad_glVertexAttrib1f = (PFNGLVERTEXATTRIB1FPROC) load(userptr, "glVertexAttrib1f");
|
||||
glad_glVertexAttrib1fv = (PFNGLVERTEXATTRIB1FVPROC) load(userptr, "glVertexAttrib1fv");
|
||||
glad_glVertexAttrib1s = (PFNGLVERTEXATTRIB1SPROC) load(userptr, "glVertexAttrib1s");
|
||||
glad_glVertexAttrib1sv = (PFNGLVERTEXATTRIB1SVPROC) load(userptr, "glVertexAttrib1sv");
|
||||
glad_glVertexAttrib2d = (PFNGLVERTEXATTRIB2DPROC) load(userptr, "glVertexAttrib2d");
|
||||
glad_glVertexAttrib2dv = (PFNGLVERTEXATTRIB2DVPROC) load(userptr, "glVertexAttrib2dv");
|
||||
glad_glVertexAttrib2f = (PFNGLVERTEXATTRIB2FPROC) load(userptr, "glVertexAttrib2f");
|
||||
glad_glVertexAttrib2fv = (PFNGLVERTEXATTRIB2FVPROC) load(userptr, "glVertexAttrib2fv");
|
||||
glad_glVertexAttrib2s = (PFNGLVERTEXATTRIB2SPROC) load(userptr, "glVertexAttrib2s");
|
||||
glad_glVertexAttrib2sv = (PFNGLVERTEXATTRIB2SVPROC) load(userptr, "glVertexAttrib2sv");
|
||||
glad_glVertexAttrib3d = (PFNGLVERTEXATTRIB3DPROC) load(userptr, "glVertexAttrib3d");
|
||||
glad_glVertexAttrib3dv = (PFNGLVERTEXATTRIB3DVPROC) load(userptr, "glVertexAttrib3dv");
|
||||
glad_glVertexAttrib3f = (PFNGLVERTEXATTRIB3FPROC) load(userptr, "glVertexAttrib3f");
|
||||
glad_glVertexAttrib3fv = (PFNGLVERTEXATTRIB3FVPROC) load(userptr, "glVertexAttrib3fv");
|
||||
glad_glVertexAttrib3s = (PFNGLVERTEXATTRIB3SPROC) load(userptr, "glVertexAttrib3s");
|
||||
glad_glVertexAttrib3sv = (PFNGLVERTEXATTRIB3SVPROC) load(userptr, "glVertexAttrib3sv");
|
||||
glad_glVertexAttrib4Nbv = (PFNGLVERTEXATTRIB4NBVPROC) load(userptr, "glVertexAttrib4Nbv");
|
||||
glad_glVertexAttrib4Niv = (PFNGLVERTEXATTRIB4NIVPROC) load(userptr, "glVertexAttrib4Niv");
|
||||
glad_glVertexAttrib4Nsv = (PFNGLVERTEXATTRIB4NSVPROC) load(userptr, "glVertexAttrib4Nsv");
|
||||
glad_glVertexAttrib4Nub = (PFNGLVERTEXATTRIB4NUBPROC) load(userptr, "glVertexAttrib4Nub");
|
||||
glad_glVertexAttrib4Nubv = (PFNGLVERTEXATTRIB4NUBVPROC) load(userptr, "glVertexAttrib4Nubv");
|
||||
glad_glVertexAttrib4Nuiv = (PFNGLVERTEXATTRIB4NUIVPROC) load(userptr, "glVertexAttrib4Nuiv");
|
||||
glad_glVertexAttrib4Nusv = (PFNGLVERTEXATTRIB4NUSVPROC) load(userptr, "glVertexAttrib4Nusv");
|
||||
glad_glVertexAttrib4bv = (PFNGLVERTEXATTRIB4BVPROC) load(userptr, "glVertexAttrib4bv");
|
||||
glad_glVertexAttrib4d = (PFNGLVERTEXATTRIB4DPROC) load(userptr, "glVertexAttrib4d");
|
||||
glad_glVertexAttrib4dv = (PFNGLVERTEXATTRIB4DVPROC) load(userptr, "glVertexAttrib4dv");
|
||||
glad_glVertexAttrib4f = (PFNGLVERTEXATTRIB4FPROC) load(userptr, "glVertexAttrib4f");
|
||||
glad_glVertexAttrib4fv = (PFNGLVERTEXATTRIB4FVPROC) load(userptr, "glVertexAttrib4fv");
|
||||
glad_glVertexAttrib4iv = (PFNGLVERTEXATTRIB4IVPROC) load(userptr, "glVertexAttrib4iv");
|
||||
glad_glVertexAttrib4s = (PFNGLVERTEXATTRIB4SPROC) load(userptr, "glVertexAttrib4s");
|
||||
glad_glVertexAttrib4sv = (PFNGLVERTEXATTRIB4SVPROC) load(userptr, "glVertexAttrib4sv");
|
||||
glad_glVertexAttrib4ubv = (PFNGLVERTEXATTRIB4UBVPROC) load(userptr, "glVertexAttrib4ubv");
|
||||
glad_glVertexAttrib4uiv = (PFNGLVERTEXATTRIB4UIVPROC) load(userptr, "glVertexAttrib4uiv");
|
||||
glad_glVertexAttrib4usv = (PFNGLVERTEXATTRIB4USVPROC) load(userptr, "glVertexAttrib4usv");
|
||||
glad_glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC) load(userptr, "glVertexAttribPointer");
|
||||
}
|
||||
static void glad_gl_load_GL_VERSION_2_1( GLADuserptrloadfunc load, void* userptr) {
|
||||
if(!GLAD_GL_VERSION_2_1) return;
|
||||
glad_glUniformMatrix2x3fv = (PFNGLUNIFORMMATRIX2X3FVPROC) load(userptr, "glUniformMatrix2x3fv");
|
||||
glad_glUniformMatrix2x4fv = (PFNGLUNIFORMMATRIX2X4FVPROC) load(userptr, "glUniformMatrix2x4fv");
|
||||
glad_glUniformMatrix3x2fv = (PFNGLUNIFORMMATRIX3X2FVPROC) load(userptr, "glUniformMatrix3x2fv");
|
||||
glad_glUniformMatrix3x4fv = (PFNGLUNIFORMMATRIX3X4FVPROC) load(userptr, "glUniformMatrix3x4fv");
|
||||
glad_glUniformMatrix4x2fv = (PFNGLUNIFORMMATRIX4X2FVPROC) load(userptr, "glUniformMatrix4x2fv");
|
||||
glad_glUniformMatrix4x3fv = (PFNGLUNIFORMMATRIX4X3FVPROC) load(userptr, "glUniformMatrix4x3fv");
|
||||
}
|
||||
static void glad_gl_load_GL_VERSION_3_0( GLADuserptrloadfunc load, void* userptr) {
|
||||
if(!GLAD_GL_VERSION_3_0) return;
|
||||
glad_glBeginConditionalRender = (PFNGLBEGINCONDITIONALRENDERPROC) load(userptr, "glBeginConditionalRender");
|
||||
glad_glBeginTransformFeedback = (PFNGLBEGINTRANSFORMFEEDBACKPROC) load(userptr, "glBeginTransformFeedback");
|
||||
glad_glBindBufferBase = (PFNGLBINDBUFFERBASEPROC) load(userptr, "glBindBufferBase");
|
||||
glad_glBindBufferRange = (PFNGLBINDBUFFERRANGEPROC) load(userptr, "glBindBufferRange");
|
||||
glad_glBindFragDataLocation = (PFNGLBINDFRAGDATALOCATIONPROC) load(userptr, "glBindFragDataLocation");
|
||||
glad_glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) load(userptr, "glBindFramebuffer");
|
||||
glad_glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) load(userptr, "glBindRenderbuffer");
|
||||
glad_glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC) load(userptr, "glBindVertexArray");
|
||||
glad_glBlitFramebuffer = (PFNGLBLITFRAMEBUFFERPROC) load(userptr, "glBlitFramebuffer");
|
||||
glad_glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) load(userptr, "glCheckFramebufferStatus");
|
||||
glad_glClampColor = (PFNGLCLAMPCOLORPROC) load(userptr, "glClampColor");
|
||||
glad_glClearBufferfi = (PFNGLCLEARBUFFERFIPROC) load(userptr, "glClearBufferfi");
|
||||
glad_glClearBufferfv = (PFNGLCLEARBUFFERFVPROC) load(userptr, "glClearBufferfv");
|
||||
glad_glClearBufferiv = (PFNGLCLEARBUFFERIVPROC) load(userptr, "glClearBufferiv");
|
||||
glad_glClearBufferuiv = (PFNGLCLEARBUFFERUIVPROC) load(userptr, "glClearBufferuiv");
|
||||
glad_glColorMaski = (PFNGLCOLORMASKIPROC) load(userptr, "glColorMaski");
|
||||
glad_glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) load(userptr, "glDeleteFramebuffers");
|
||||
glad_glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) load(userptr, "glDeleteRenderbuffers");
|
||||
glad_glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC) load(userptr, "glDeleteVertexArrays");
|
||||
glad_glDisablei = (PFNGLDISABLEIPROC) load(userptr, "glDisablei");
|
||||
glad_glEnablei = (PFNGLENABLEIPROC) load(userptr, "glEnablei");
|
||||
glad_glEndConditionalRender = (PFNGLENDCONDITIONALRENDERPROC) load(userptr, "glEndConditionalRender");
|
||||
glad_glEndTransformFeedback = (PFNGLENDTRANSFORMFEEDBACKPROC) load(userptr, "glEndTransformFeedback");
|
||||
glad_glFlushMappedBufferRange = (PFNGLFLUSHMAPPEDBUFFERRANGEPROC) load(userptr, "glFlushMappedBufferRange");
|
||||
glad_glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) load(userptr, "glFramebufferRenderbuffer");
|
||||
glad_glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) load(userptr, "glFramebufferTexture1D");
|
||||
glad_glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) load(userptr, "glFramebufferTexture2D");
|
||||
glad_glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) load(userptr, "glFramebufferTexture3D");
|
||||
glad_glFramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERPROC) load(userptr, "glFramebufferTextureLayer");
|
||||
glad_glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) load(userptr, "glGenFramebuffers");
|
||||
glad_glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) load(userptr, "glGenRenderbuffers");
|
||||
glad_glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC) load(userptr, "glGenVertexArrays");
|
||||
glad_glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) load(userptr, "glGenerateMipmap");
|
||||
glad_glGetBooleani_v = (PFNGLGETBOOLEANI_VPROC) load(userptr, "glGetBooleani_v");
|
||||
glad_glGetFragDataLocation = (PFNGLGETFRAGDATALOCATIONPROC) load(userptr, "glGetFragDataLocation");
|
||||
glad_glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) load(userptr, "glGetFramebufferAttachmentParameteriv");
|
||||
glad_glGetIntegeri_v = (PFNGLGETINTEGERI_VPROC) load(userptr, "glGetIntegeri_v");
|
||||
glad_glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) load(userptr, "glGetRenderbufferParameteriv");
|
||||
glad_glGetStringi = (PFNGLGETSTRINGIPROC) load(userptr, "glGetStringi");
|
||||
glad_glGetTexParameterIiv = (PFNGLGETTEXPARAMETERIIVPROC) load(userptr, "glGetTexParameterIiv");
|
||||
glad_glGetTexParameterIuiv = (PFNGLGETTEXPARAMETERIUIVPROC) load(userptr, "glGetTexParameterIuiv");
|
||||
glad_glGetTransformFeedbackVarying = (PFNGLGETTRANSFORMFEEDBACKVARYINGPROC) load(userptr, "glGetTransformFeedbackVarying");
|
||||
glad_glGetUniformuiv = (PFNGLGETUNIFORMUIVPROC) load(userptr, "glGetUniformuiv");
|
||||
glad_glGetVertexAttribIiv = (PFNGLGETVERTEXATTRIBIIVPROC) load(userptr, "glGetVertexAttribIiv");
|
||||
glad_glGetVertexAttribIuiv = (PFNGLGETVERTEXATTRIBIUIVPROC) load(userptr, "glGetVertexAttribIuiv");
|
||||
glad_glIsEnabledi = (PFNGLISENABLEDIPROC) load(userptr, "glIsEnabledi");
|
||||
glad_glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) load(userptr, "glIsFramebuffer");
|
||||
glad_glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) load(userptr, "glIsRenderbuffer");
|
||||
glad_glIsVertexArray = (PFNGLISVERTEXARRAYPROC) load(userptr, "glIsVertexArray");
|
||||
glad_glMapBufferRange = (PFNGLMAPBUFFERRANGEPROC) load(userptr, "glMapBufferRange");
|
||||
glad_glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) load(userptr, "glRenderbufferStorage");
|
||||
glad_glRenderbufferStorageMultisample = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) load(userptr, "glRenderbufferStorageMultisample");
|
||||
glad_glTexParameterIiv = (PFNGLTEXPARAMETERIIVPROC) load(userptr, "glTexParameterIiv");
|
||||
glad_glTexParameterIuiv = (PFNGLTEXPARAMETERIUIVPROC) load(userptr, "glTexParameterIuiv");
|
||||
glad_glTransformFeedbackVaryings = (PFNGLTRANSFORMFEEDBACKVARYINGSPROC) load(userptr, "glTransformFeedbackVaryings");
|
||||
glad_glUniform1ui = (PFNGLUNIFORM1UIPROC) load(userptr, "glUniform1ui");
|
||||
glad_glUniform1uiv = (PFNGLUNIFORM1UIVPROC) load(userptr, "glUniform1uiv");
|
||||
glad_glUniform2ui = (PFNGLUNIFORM2UIPROC) load(userptr, "glUniform2ui");
|
||||
glad_glUniform2uiv = (PFNGLUNIFORM2UIVPROC) load(userptr, "glUniform2uiv");
|
||||
glad_glUniform3ui = (PFNGLUNIFORM3UIPROC) load(userptr, "glUniform3ui");
|
||||
glad_glUniform3uiv = (PFNGLUNIFORM3UIVPROC) load(userptr, "glUniform3uiv");
|
||||
glad_glUniform4ui = (PFNGLUNIFORM4UIPROC) load(userptr, "glUniform4ui");
|
||||
glad_glUniform4uiv = (PFNGLUNIFORM4UIVPROC) load(userptr, "glUniform4uiv");
|
||||
glad_glVertexAttribI1i = (PFNGLVERTEXATTRIBI1IPROC) load(userptr, "glVertexAttribI1i");
|
||||
glad_glVertexAttribI1iv = (PFNGLVERTEXATTRIBI1IVPROC) load(userptr, "glVertexAttribI1iv");
|
||||
glad_glVertexAttribI1ui = (PFNGLVERTEXATTRIBI1UIPROC) load(userptr, "glVertexAttribI1ui");
|
||||
glad_glVertexAttribI1uiv = (PFNGLVERTEXATTRIBI1UIVPROC) load(userptr, "glVertexAttribI1uiv");
|
||||
glad_glVertexAttribI2i = (PFNGLVERTEXATTRIBI2IPROC) load(userptr, "glVertexAttribI2i");
|
||||
glad_glVertexAttribI2iv = (PFNGLVERTEXATTRIBI2IVPROC) load(userptr, "glVertexAttribI2iv");
|
||||
glad_glVertexAttribI2ui = (PFNGLVERTEXATTRIBI2UIPROC) load(userptr, "glVertexAttribI2ui");
|
||||
glad_glVertexAttribI2uiv = (PFNGLVERTEXATTRIBI2UIVPROC) load(userptr, "glVertexAttribI2uiv");
|
||||
glad_glVertexAttribI3i = (PFNGLVERTEXATTRIBI3IPROC) load(userptr, "glVertexAttribI3i");
|
||||
glad_glVertexAttribI3iv = (PFNGLVERTEXATTRIBI3IVPROC) load(userptr, "glVertexAttribI3iv");
|
||||
glad_glVertexAttribI3ui = (PFNGLVERTEXATTRIBI3UIPROC) load(userptr, "glVertexAttribI3ui");
|
||||
glad_glVertexAttribI3uiv = (PFNGLVERTEXATTRIBI3UIVPROC) load(userptr, "glVertexAttribI3uiv");
|
||||
glad_glVertexAttribI4bv = (PFNGLVERTEXATTRIBI4BVPROC) load(userptr, "glVertexAttribI4bv");
|
||||
glad_glVertexAttribI4i = (PFNGLVERTEXATTRIBI4IPROC) load(userptr, "glVertexAttribI4i");
|
||||
glad_glVertexAttribI4iv = (PFNGLVERTEXATTRIBI4IVPROC) load(userptr, "glVertexAttribI4iv");
|
||||
glad_glVertexAttribI4sv = (PFNGLVERTEXATTRIBI4SVPROC) load(userptr, "glVertexAttribI4sv");
|
||||
glad_glVertexAttribI4ubv = (PFNGLVERTEXATTRIBI4UBVPROC) load(userptr, "glVertexAttribI4ubv");
|
||||
glad_glVertexAttribI4ui = (PFNGLVERTEXATTRIBI4UIPROC) load(userptr, "glVertexAttribI4ui");
|
||||
glad_glVertexAttribI4uiv = (PFNGLVERTEXATTRIBI4UIVPROC) load(userptr, "glVertexAttribI4uiv");
|
||||
glad_glVertexAttribI4usv = (PFNGLVERTEXATTRIBI4USVPROC) load(userptr, "glVertexAttribI4usv");
|
||||
glad_glVertexAttribIPointer = (PFNGLVERTEXATTRIBIPOINTERPROC) load(userptr, "glVertexAttribIPointer");
|
||||
}
|
||||
static void glad_gl_load_GL_VERSION_3_1( GLADuserptrloadfunc load, void* userptr) {
|
||||
if(!GLAD_GL_VERSION_3_1) return;
|
||||
glad_glBindBufferBase = (PFNGLBINDBUFFERBASEPROC) load(userptr, "glBindBufferBase");
|
||||
glad_glBindBufferRange = (PFNGLBINDBUFFERRANGEPROC) load(userptr, "glBindBufferRange");
|
||||
glad_glCopyBufferSubData = (PFNGLCOPYBUFFERSUBDATAPROC) load(userptr, "glCopyBufferSubData");
|
||||
glad_glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC) load(userptr, "glDrawArraysInstanced");
|
||||
glad_glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC) load(userptr, "glDrawElementsInstanced");
|
||||
glad_glGetActiveUniformBlockName = (PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC) load(userptr, "glGetActiveUniformBlockName");
|
||||
glad_glGetActiveUniformBlockiv = (PFNGLGETACTIVEUNIFORMBLOCKIVPROC) load(userptr, "glGetActiveUniformBlockiv");
|
||||
glad_glGetActiveUniformName = (PFNGLGETACTIVEUNIFORMNAMEPROC) load(userptr, "glGetActiveUniformName");
|
||||
glad_glGetActiveUniformsiv = (PFNGLGETACTIVEUNIFORMSIVPROC) load(userptr, "glGetActiveUniformsiv");
|
||||
glad_glGetIntegeri_v = (PFNGLGETINTEGERI_VPROC) load(userptr, "glGetIntegeri_v");
|
||||
glad_glGetUniformBlockIndex = (PFNGLGETUNIFORMBLOCKINDEXPROC) load(userptr, "glGetUniformBlockIndex");
|
||||
glad_glGetUniformIndices = (PFNGLGETUNIFORMINDICESPROC) load(userptr, "glGetUniformIndices");
|
||||
glad_glPrimitiveRestartIndex = (PFNGLPRIMITIVERESTARTINDEXPROC) load(userptr, "glPrimitiveRestartIndex");
|
||||
glad_glTexBuffer = (PFNGLTEXBUFFERPROC) load(userptr, "glTexBuffer");
|
||||
glad_glUniformBlockBinding = (PFNGLUNIFORMBLOCKBINDINGPROC) load(userptr, "glUniformBlockBinding");
|
||||
}
|
||||
static void glad_gl_load_GL_VERSION_3_2( GLADuserptrloadfunc load, void* userptr) {
|
||||
if(!GLAD_GL_VERSION_3_2) return;
|
||||
glad_glClientWaitSync = (PFNGLCLIENTWAITSYNCPROC) load(userptr, "glClientWaitSync");
|
||||
glad_glDeleteSync = (PFNGLDELETESYNCPROC) load(userptr, "glDeleteSync");
|
||||
glad_glDrawElementsBaseVertex = (PFNGLDRAWELEMENTSBASEVERTEXPROC) load(userptr, "glDrawElementsBaseVertex");
|
||||
glad_glDrawElementsInstancedBaseVertex = (PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) load(userptr, "glDrawElementsInstancedBaseVertex");
|
||||
glad_glDrawRangeElementsBaseVertex = (PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC) load(userptr, "glDrawRangeElementsBaseVertex");
|
||||
glad_glFenceSync = (PFNGLFENCESYNCPROC) load(userptr, "glFenceSync");
|
||||
glad_glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC) load(userptr, "glFramebufferTexture");
|
||||
glad_glGetBufferParameteri64v = (PFNGLGETBUFFERPARAMETERI64VPROC) load(userptr, "glGetBufferParameteri64v");
|
||||
glad_glGetInteger64i_v = (PFNGLGETINTEGER64I_VPROC) load(userptr, "glGetInteger64i_v");
|
||||
glad_glGetInteger64v = (PFNGLGETINTEGER64VPROC) load(userptr, "glGetInteger64v");
|
||||
glad_glGetMultisamplefv = (PFNGLGETMULTISAMPLEFVPROC) load(userptr, "glGetMultisamplefv");
|
||||
glad_glGetSynciv = (PFNGLGETSYNCIVPROC) load(userptr, "glGetSynciv");
|
||||
glad_glIsSync = (PFNGLISSYNCPROC) load(userptr, "glIsSync");
|
||||
glad_glMultiDrawElementsBaseVertex = (PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) load(userptr, "glMultiDrawElementsBaseVertex");
|
||||
glad_glProvokingVertex = (PFNGLPROVOKINGVERTEXPROC) load(userptr, "glProvokingVertex");
|
||||
glad_glSampleMaski = (PFNGLSAMPLEMASKIPROC) load(userptr, "glSampleMaski");
|
||||
glad_glTexImage2DMultisample = (PFNGLTEXIMAGE2DMULTISAMPLEPROC) load(userptr, "glTexImage2DMultisample");
|
||||
glad_glTexImage3DMultisample = (PFNGLTEXIMAGE3DMULTISAMPLEPROC) load(userptr, "glTexImage3DMultisample");
|
||||
glad_glWaitSync = (PFNGLWAITSYNCPROC) load(userptr, "glWaitSync");
|
||||
}
|
||||
static void glad_gl_load_GL_VERSION_3_3( GLADuserptrloadfunc load, void* userptr) {
|
||||
if(!GLAD_GL_VERSION_3_3) return;
|
||||
glad_glBindFragDataLocationIndexed = (PFNGLBINDFRAGDATALOCATIONINDEXEDPROC) load(userptr, "glBindFragDataLocationIndexed");
|
||||
glad_glBindSampler = (PFNGLBINDSAMPLERPROC) load(userptr, "glBindSampler");
|
||||
glad_glDeleteSamplers = (PFNGLDELETESAMPLERSPROC) load(userptr, "glDeleteSamplers");
|
||||
glad_glGenSamplers = (PFNGLGENSAMPLERSPROC) load(userptr, "glGenSamplers");
|
||||
glad_glGetFragDataIndex = (PFNGLGETFRAGDATAINDEXPROC) load(userptr, "glGetFragDataIndex");
|
||||
glad_glGetQueryObjecti64v = (PFNGLGETQUERYOBJECTI64VPROC) load(userptr, "glGetQueryObjecti64v");
|
||||
glad_glGetQueryObjectui64v = (PFNGLGETQUERYOBJECTUI64VPROC) load(userptr, "glGetQueryObjectui64v");
|
||||
glad_glGetSamplerParameterIiv = (PFNGLGETSAMPLERPARAMETERIIVPROC) load(userptr, "glGetSamplerParameterIiv");
|
||||
glad_glGetSamplerParameterIuiv = (PFNGLGETSAMPLERPARAMETERIUIVPROC) load(userptr, "glGetSamplerParameterIuiv");
|
||||
glad_glGetSamplerParameterfv = (PFNGLGETSAMPLERPARAMETERFVPROC) load(userptr, "glGetSamplerParameterfv");
|
||||
glad_glGetSamplerParameteriv = (PFNGLGETSAMPLERPARAMETERIVPROC) load(userptr, "glGetSamplerParameteriv");
|
||||
glad_glIsSampler = (PFNGLISSAMPLERPROC) load(userptr, "glIsSampler");
|
||||
glad_glQueryCounter = (PFNGLQUERYCOUNTERPROC) load(userptr, "glQueryCounter");
|
||||
glad_glSamplerParameterIiv = (PFNGLSAMPLERPARAMETERIIVPROC) load(userptr, "glSamplerParameterIiv");
|
||||
glad_glSamplerParameterIuiv = (PFNGLSAMPLERPARAMETERIUIVPROC) load(userptr, "glSamplerParameterIuiv");
|
||||
glad_glSamplerParameterf = (PFNGLSAMPLERPARAMETERFPROC) load(userptr, "glSamplerParameterf");
|
||||
glad_glSamplerParameterfv = (PFNGLSAMPLERPARAMETERFVPROC) load(userptr, "glSamplerParameterfv");
|
||||
glad_glSamplerParameteri = (PFNGLSAMPLERPARAMETERIPROC) load(userptr, "glSamplerParameteri");
|
||||
glad_glSamplerParameteriv = (PFNGLSAMPLERPARAMETERIVPROC) load(userptr, "glSamplerParameteriv");
|
||||
glad_glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC) load(userptr, "glVertexAttribDivisor");
|
||||
glad_glVertexAttribP1ui = (PFNGLVERTEXATTRIBP1UIPROC) load(userptr, "glVertexAttribP1ui");
|
||||
glad_glVertexAttribP1uiv = (PFNGLVERTEXATTRIBP1UIVPROC) load(userptr, "glVertexAttribP1uiv");
|
||||
glad_glVertexAttribP2ui = (PFNGLVERTEXATTRIBP2UIPROC) load(userptr, "glVertexAttribP2ui");
|
||||
glad_glVertexAttribP2uiv = (PFNGLVERTEXATTRIBP2UIVPROC) load(userptr, "glVertexAttribP2uiv");
|
||||
glad_glVertexAttribP3ui = (PFNGLVERTEXATTRIBP3UIPROC) load(userptr, "glVertexAttribP3ui");
|
||||
glad_glVertexAttribP3uiv = (PFNGLVERTEXATTRIBP3UIVPROC) load(userptr, "glVertexAttribP3uiv");
|
||||
glad_glVertexAttribP4ui = (PFNGLVERTEXATTRIBP4UIPROC) load(userptr, "glVertexAttribP4ui");
|
||||
glad_glVertexAttribP4uiv = (PFNGLVERTEXATTRIBP4UIVPROC) load(userptr, "glVertexAttribP4uiv");
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void glad_gl_free_extensions(char **exts_i) {
|
||||
if (exts_i != NULL) {
|
||||
unsigned int index;
|
||||
for(index = 0; exts_i[index]; index++) {
|
||||
free((void *) (exts_i[index]));
|
||||
}
|
||||
free((void *)exts_i);
|
||||
exts_i = NULL;
|
||||
}
|
||||
}
|
||||
static int glad_gl_get_extensions( const char **out_exts, char ***out_exts_i) {
|
||||
#if defined(GL_ES_VERSION_3_0) || defined(GL_VERSION_3_0)
|
||||
if (glad_glGetStringi != NULL && glad_glGetIntegerv != NULL) {
|
||||
unsigned int index = 0;
|
||||
unsigned int num_exts_i = 0;
|
||||
char **exts_i = NULL;
|
||||
glad_glGetIntegerv(GL_NUM_EXTENSIONS, (int*) &num_exts_i);
|
||||
exts_i = (char **) malloc((num_exts_i + 1) * (sizeof *exts_i));
|
||||
if (exts_i == NULL) {
|
||||
return 0;
|
||||
}
|
||||
for(index = 0; index < num_exts_i; index++) {
|
||||
const char *gl_str_tmp = (const char*) glad_glGetStringi(GL_EXTENSIONS, index);
|
||||
size_t len = strlen(gl_str_tmp) + 1;
|
||||
|
||||
char *local_str = (char*) malloc(len * sizeof(char));
|
||||
if(local_str == NULL) {
|
||||
exts_i[index] = NULL;
|
||||
glad_gl_free_extensions(exts_i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(local_str, gl_str_tmp, len * sizeof(char));
|
||||
exts_i[index] = local_str;
|
||||
}
|
||||
exts_i[index] = NULL;
|
||||
|
||||
*out_exts_i = exts_i;
|
||||
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
GLAD_UNUSED(out_exts_i);
|
||||
#endif
|
||||
if (glad_glGetString == NULL) {
|
||||
return 0;
|
||||
}
|
||||
*out_exts = (const char *)glad_glGetString(GL_EXTENSIONS);
|
||||
return 1;
|
||||
}
|
||||
static int glad_gl_has_extension(const char *exts, char **exts_i, const char *ext) {
|
||||
if(exts_i) {
|
||||
unsigned int index;
|
||||
for(index = 0; exts_i[index]; index++) {
|
||||
const char *e = exts_i[index];
|
||||
if(strcmp(e, ext) == 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const char *extensions;
|
||||
const char *loc;
|
||||
const char *terminator;
|
||||
extensions = exts;
|
||||
if(extensions == NULL || ext == NULL) {
|
||||
return 0;
|
||||
}
|
||||
while(1) {
|
||||
loc = strstr(extensions, ext);
|
||||
if(loc == NULL) {
|
||||
return 0;
|
||||
}
|
||||
terminator = loc + strlen(ext);
|
||||
if((loc == extensions || *(loc - 1) == ' ') &&
|
||||
(*terminator == ' ' || *terminator == '\0')) {
|
||||
return 1;
|
||||
}
|
||||
extensions = terminator;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static GLADapiproc glad_gl_get_proc_from_userptr(void *userptr, const char* name) {
|
||||
return (GLAD_GNUC_EXTENSION (GLADapiproc (*)(const char *name)) userptr)(name);
|
||||
}
|
||||
|
||||
static int glad_gl_find_extensions_gl(void) {
|
||||
const char *exts = NULL;
|
||||
char **exts_i = NULL;
|
||||
if (!glad_gl_get_extensions(&exts, &exts_i)) return 0;
|
||||
|
||||
GLAD_UNUSED(&glad_gl_has_extension);
|
||||
|
||||
glad_gl_free_extensions(exts_i);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int glad_gl_find_core_gl(void) {
|
||||
int i;
|
||||
const char* version;
|
||||
const char* prefixes[] = {
|
||||
"OpenGL ES-CM ",
|
||||
"OpenGL ES-CL ",
|
||||
"OpenGL ES ",
|
||||
"OpenGL SC ",
|
||||
NULL
|
||||
};
|
||||
int major = 0;
|
||||
int minor = 0;
|
||||
version = (const char*) glad_glGetString(GL_VERSION);
|
||||
if (!version) return 0;
|
||||
for (i = 0; prefixes[i]; i++) {
|
||||
const size_t length = strlen(prefixes[i]);
|
||||
if (strncmp(version, prefixes[i], length) == 0) {
|
||||
version += length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GLAD_IMPL_UTIL_SSCANF(version, "%d.%d", &major, &minor);
|
||||
|
||||
GLAD_GL_VERSION_1_0 = (major == 1 && minor >= 0) || major > 1;
|
||||
GLAD_GL_VERSION_1_1 = (major == 1 && minor >= 1) || major > 1;
|
||||
GLAD_GL_VERSION_1_2 = (major == 1 && minor >= 2) || major > 1;
|
||||
GLAD_GL_VERSION_1_3 = (major == 1 && minor >= 3) || major > 1;
|
||||
GLAD_GL_VERSION_1_4 = (major == 1 && minor >= 4) || major > 1;
|
||||
GLAD_GL_VERSION_1_5 = (major == 1 && minor >= 5) || major > 1;
|
||||
GLAD_GL_VERSION_2_0 = (major == 2 && minor >= 0) || major > 2;
|
||||
GLAD_GL_VERSION_2_1 = (major == 2 && minor >= 1) || major > 2;
|
||||
GLAD_GL_VERSION_3_0 = (major == 3 && minor >= 0) || major > 3;
|
||||
GLAD_GL_VERSION_3_1 = (major == 3 && minor >= 1) || major > 3;
|
||||
GLAD_GL_VERSION_3_2 = (major == 3 && minor >= 2) || major > 3;
|
||||
GLAD_GL_VERSION_3_3 = (major == 3 && minor >= 3) || major > 3;
|
||||
|
||||
return GLAD_MAKE_VERSION(major, minor);
|
||||
}
|
||||
|
||||
int gladLoadGLUserPtr( GLADuserptrloadfunc load, void *userptr) {
|
||||
int version;
|
||||
|
||||
glad_glGetString = (PFNGLGETSTRINGPROC) load(userptr, "glGetString");
|
||||
if(glad_glGetString == NULL) return 0;
|
||||
version = glad_gl_find_core_gl();
|
||||
|
||||
glad_gl_load_GL_VERSION_1_0(load, userptr);
|
||||
glad_gl_load_GL_VERSION_1_1(load, userptr);
|
||||
glad_gl_load_GL_VERSION_1_2(load, userptr);
|
||||
glad_gl_load_GL_VERSION_1_3(load, userptr);
|
||||
glad_gl_load_GL_VERSION_1_4(load, userptr);
|
||||
glad_gl_load_GL_VERSION_1_5(load, userptr);
|
||||
glad_gl_load_GL_VERSION_2_0(load, userptr);
|
||||
glad_gl_load_GL_VERSION_2_1(load, userptr);
|
||||
glad_gl_load_GL_VERSION_3_0(load, userptr);
|
||||
glad_gl_load_GL_VERSION_3_1(load, userptr);
|
||||
glad_gl_load_GL_VERSION_3_2(load, userptr);
|
||||
glad_gl_load_GL_VERSION_3_3(load, userptr);
|
||||
|
||||
if (!glad_gl_find_extensions_gl()) return 0;
|
||||
|
||||
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
int gladLoadGL( GLADloadfunc load) {
|
||||
return gladLoadGLUserPtr( glad_gl_get_proc_from_userptr, GLAD_GNUC_EXTENSION (void*) load);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
1
lib/glfw
Submodule
1
lib/glfw
Submodule
Submodule lib/glfw added at 7b6aead9fb
1
lib/libarchive
Submodule
1
lib/libarchive
Submodule
Submodule lib/libarchive added at 9525f90ca4
149
makefile
149
makefile
@@ -1,149 +0,0 @@
|
||||
# Copyright (c) 2025 Quinn
|
||||
# Licensed under the MIT Licence. See LICENSE for details
|
||||
|
||||
# dependencies:
|
||||
# - make
|
||||
# - C compiler
|
||||
# - glfw3 (install glfw3:x64-mingw-dynamic via vcpkg for cross compilation)
|
||||
# - xxd (tinyxxd recommended; faster)
|
||||
# - (windows) git bash (recommended)
|
||||
|
||||
# build configuration, information about the current build process
|
||||
NAME := mcaselector-lite
|
||||
VERSION := 0.0.0
|
||||
DEBUG ?= 0
|
||||
CC ?= cc
|
||||
LD ?= ld
|
||||
CFLAGS += -c -std=gnu99 -Wall -Wextra -Wpedantic -Ilib -MMD -MP
|
||||
LDFLAGS += -lm
|
||||
MARCH ?= $(shell uname -m)
|
||||
KERNEL ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
# check whether KERNEL is something nonsensical
|
||||
ISWIN := $(if $(filter linux darwin freebsd netbsd openbsd,$(KERNEL)),0,1)
|
||||
|
||||
# profiles
|
||||
ifeq ($(DEBUG),1) # check whether we're debugging
|
||||
CFLAGS += -UNDEBUG -Og -g
|
||||
PROF := dbg
|
||||
ifeq ($(ISWIN),0)
|
||||
CFLAGS += -fsanitize=address,undefined
|
||||
LDFLAGS += -fsanitize=address,undefined
|
||||
endif
|
||||
else ifeq ($(DEBUG),test) # check whether we're perhaps testing
|
||||
CFLAGS += -UNDEBUG -O2 -g
|
||||
PROF := test
|
||||
ifeq ($(ISWIN),0)
|
||||
CFLAGS += -fsanitize=address
|
||||
LDFLAGS += -fsanitize=address
|
||||
endif
|
||||
else # otherwise, assume release
|
||||
CFLAGS += -DNDEBUG -O2
|
||||
PROF := rel
|
||||
endif
|
||||
|
||||
# setup the VCPKG_TRIPLET
|
||||
# because microsoft thinks they should use a different method of classifying stuff than the standard
|
||||
ifneq ($(VCPKG_ROOT),)
|
||||
VCPKG_TRIPLET ?= $(strip \
|
||||
$(if $(filter x86_64,$(MARCH)),x64, \
|
||||
))-$(strip \
|
||||
$(if $(filter linux,$(KERNEL)),linux-dynamic, \
|
||||
$(if $(filter darwin,$(KERNEL)),osx-dynamic, \
|
||||
mingw-static)) \
|
||||
)
|
||||
|
||||
# override the pkg config path, so it is used instead of system packages
|
||||
export PKG_CONFIG_PATH := $(VCPKG_ROOT)/installed/$(VCPKG_TRIPLET)/lib/pkgconfig
|
||||
$(info using PKG_CONFIG_PATH: '$(PKG_CONFIG_PATH)')
|
||||
else ifneq ($(shell which pkg-config),)
|
||||
$(warning couldn't find VCPKG_ROOT, attempting to use system packages using pkg-config!)
|
||||
else
|
||||
$(error neither VCPKG_ROOT nor pkg-config were available!)
|
||||
endif
|
||||
|
||||
# use pkg-config to set the include and linker information
|
||||
CFLAGS += $(shell pkg-config --cflags glfw3)
|
||||
LDFLAGS += $(shell pkg-config --libs glfw3)
|
||||
|
||||
# windows specific handling
|
||||
ifeq ($(ISWIN),1)
|
||||
NAME := $(NAME).exe
|
||||
endif
|
||||
|
||||
# build directory structure
|
||||
DIR_BIN := bin/$(MARCH)-$(KERNEL)/$(VERSION)/$(PROF)
|
||||
DIR_OBJ := obj/$(MARCH)-$(KERNEL)/$(VERSION)/$(PROF)
|
||||
|
||||
# get source files
|
||||
ifneq ($(DEBUG),test)
|
||||
SRC := $(shell find src/ -name '*.c')
|
||||
else
|
||||
SRC := $(filter-out src/main.c, $(shell find test/ src/ -name '*.c'))
|
||||
endif
|
||||
RES := $(shell find res/ -type f)
|
||||
|
||||
# output files
|
||||
BIN := $(DIR_BIN)/$(NAME)
|
||||
OBJ := $(SRC:%.c=$(DIR_OBJ)/%.o) $(RES:%=$(DIR_OBJ)/%.o)
|
||||
DEP := $(OBJ:.o=.d)
|
||||
|
||||
COMPILE_COMMANDS := $(DIR_OBJ)/compile_commands.json
|
||||
|
||||
.PHONY: run compile echo
|
||||
run: echo compile_commands $(BIN)
|
||||
ifeq ($(ISWIN),0)
|
||||
$(BIN)
|
||||
else
|
||||
wine $(BIN)
|
||||
endif
|
||||
compile: echo compile_commands $(BIN)
|
||||
echo:
|
||||
$(info $(shell printf "\033[36m")compiling for: $(MARCH), $(KERNEL)$(shell printf "\033[0m"))
|
||||
$(info $(shell printf "\033[36m")using compiler: $(CC)$(shell printf "\033[0m"))
|
||||
|
||||
# some definitions for "default" and assumed compilers, for bulk selection
|
||||
.PHONY: all x86_64-linux-gnu-gcc x86_64-w64-mingw32-gcc
|
||||
all: x86_64-linux-gnu-gcc x86_64-w64-mingw32-gcc
|
||||
x86_64-linux-gnu-gcc:; $(MAKE) $(CALL) $(MAKEFLAGS) CC=$@ MARCH=x86_64 KERNEL=linux NOCMDS=1
|
||||
x86_64-w64-mingw32-gcc:; $(MAKE) $(CALL) $(MAKEFLAGS) CC=$@ MARCH=x86_64 KERNEL=mingw NOCMDS=1
|
||||
|
||||
# creates the binary (linking step)
|
||||
$(BIN): $(OBJ)
|
||||
@mkdir -p $(@D)
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
# compilation rule
|
||||
$(DIR_OBJ)/%.o: %.c
|
||||
@mkdir -p $(@D)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
# use linker to embed the resources into the final binary
|
||||
$(DIR_OBJ)/res/%.o: res/%
|
||||
@mkdir -p $(@D)
|
||||
$(LD) -r -b binary -o $@ $<
|
||||
|
||||
.PHONY .NOTPARALLEL:
|
||||
clean:
|
||||
rm -rf obj bin compile_commands.json
|
||||
|
||||
# update compile commands if the makefile has been updated (for linting)
|
||||
compile_commands: # default, empty rule
|
||||
ifneq ($(shell which bear),)
|
||||
ifneq ($(COMPILE_COMMANDS),)
|
||||
ifeq ($(NOCMDS),)
|
||||
.PHONY .NOTPARALLEL:
|
||||
compile_commands: $(COMPILE_COMMANDS)
|
||||
ln -sf $< compile_commands.json
|
||||
|
||||
.NOTPARALLEL:
|
||||
$(COMPILE_COMMANDS): makefile
|
||||
@$(warning regenerating compile_commands.json thus recompiling.)
|
||||
@mkdir -p ${@D} # ensure the target directory exists
|
||||
@touch $@ # create the file so it isn't retriggered (will just change modification time if already exists)
|
||||
@bear --output $@ -- make -B compile NOCMDS=1 # rebuild the current target using bear, to create the compile commands
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
-include $(DEP)
|
||||
187
src/dat/mcx.c
Normal file
187
src/dat/mcx.c
Normal file
@@ -0,0 +1,187 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#include "mcx.h"
|
||||
|
||||
#include <archive.h>
|
||||
#include <assert.h>
|
||||
#include <endian.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../types.h"
|
||||
#include "../util/error.h"
|
||||
|
||||
#define SECTOR 0x1000 // sector size
|
||||
#define TABLE 0x800 // table (total) element count
|
||||
#define CHUNKS 0x400 // amount of chunks in a file
|
||||
|
||||
enum mcx_compression {
|
||||
MCX_COMPRESSION_GZIP = 0x01,
|
||||
MCX_COMPRESSION_ZLIB = 0x02,
|
||||
MCX_COMPRESSION_NONE = 0x03,
|
||||
MCX_COMPRESSION_LZ4 = 0x04,
|
||||
MCX_COMPRESSION_CUSTOM = 0x7F,
|
||||
};
|
||||
|
||||
/* first 4 bytes is an i32 indicating remaining bytes, the following byte defines the compression scheme */
|
||||
static int mcx_loadchunk(const u8 *restrict buf, const i32 *restrict table, int idx)
|
||||
{
|
||||
const u8 *chunk = buf + (be32toh(table[idx]) >> 8) * SECTOR;
|
||||
|
||||
i32 len;
|
||||
memcpy(&len, chunk, 4);
|
||||
len = be32toh(len);
|
||||
chunk += 4;
|
||||
|
||||
struct archive *archive = archive_read_new();
|
||||
archive_read_support_format_raw(archive);
|
||||
switch (*chunk) {
|
||||
case MCX_COMPRESSION_GZIP: /* fall-through; ZLIB is handled under the GZIP filter */
|
||||
case MCX_COMPRESSION_ZLIB: archive_read_support_filter_gzip(archive); break;
|
||||
case MCX_COMPRESSION_NONE: archive_read_support_filter_none(archive); break;
|
||||
case MCX_COMPRESSION_LZ4: archive_read_support_filter_lz4(archive); break;
|
||||
case MCX_COMPRESSION_CUSTOM: archive_read_support_filter_all(archive); break;
|
||||
default: fatal("compression type of '%i' is unsupported!", *chunk);
|
||||
}
|
||||
|
||||
if (archive_read_open_memory(archive, chunk, len) != ARCHIVE_OK) {
|
||||
error("failed to decompress %i bytes of compression type %i", len, *chunk);
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct archive_entry *entry;
|
||||
if (archive_read_next_header(archive, &entry) != ARCHIVE_OK) {
|
||||
error("failed to decompress %i bytes of compression type %i", len, *chunk);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ssize size = -1;
|
||||
for (;;) {
|
||||
// TODO: handle buffer
|
||||
// size = archive_read_data(archive, , );
|
||||
if (size < 0) {
|
||||
error("failed to decompress %i bytes of compression type %i", len, *chunk);
|
||||
return 1;
|
||||
}
|
||||
if (size == 0)
|
||||
break;
|
||||
// TODO: handle data
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Moves chunks `src_s` to `src_e` (inclusive) from `src`, back onto `dst`. */
|
||||
static void mvchunks(u8 *dst, u8 *src, u32 *restrict table, int src_s, int src_e)
|
||||
{
|
||||
assert(src > dst);
|
||||
uintptr len = src - dst; // acquire the amount of bytes that we shall move
|
||||
assert(!(len % SECTOR));
|
||||
|
||||
// count how many bytes we need to move, whilst updating location data
|
||||
usize blen = 0;
|
||||
for (src_s++; src_s <= src_e; src_s++) {
|
||||
blen += (be32toh(table[src_s]) & 0xFF) * SECTOR;
|
||||
table[src_s] -= htobe32((len / SECTOR) << 8);
|
||||
}
|
||||
memmove(dst, src, blen);
|
||||
}
|
||||
|
||||
/* Deletes chunk `sidx` by moving chunks up to `eidx` back over `sidx` in `buf`.
|
||||
* `rmb` is an optional additional offset that can be applied, and signifies bytes already removed.
|
||||
* Returns the bytes removed by this function. */
|
||||
static usize delchunk(u8 *restrict buf, u32 *restrict table, usize rmb, int sidx, int eidx)
|
||||
{
|
||||
// load the table data
|
||||
usize slen, bidx, blen;
|
||||
slen = be32toh(table[sidx]) & 0xFF; // acquire the sector length of the chunk
|
||||
bidx = (be32toh(table[sidx]) >> 8) * SECTOR; // acquire and compute the byte offset the chunk starts at
|
||||
blen = slen * SECTOR; // compute the byte length of the chunk
|
||||
|
||||
// reset the table data
|
||||
table[sidx] = 0;
|
||||
table[sidx + CHUNKS] = htobe32(time(NULL)); // assign the current time to the timestamp, for correctness NOTE: might need to zero-out instead
|
||||
|
||||
// move the succeeding chunks over the deleted chunk
|
||||
u8 *dst = buf + bidx - rmb;
|
||||
u8 *src = buf + bidx + blen;
|
||||
mvchunks(dst, src, table, sidx, eidx - 1);
|
||||
return blen;
|
||||
}
|
||||
|
||||
/* Call `delchunk` with the parameters and some defaults. Ensuring the table is copied correctly as well.
|
||||
* This is done instead of `delchunk` being globally linked, because
|
||||
* `delchunk` requests more specific parameters, which is confusing outside this module. */
|
||||
usize mcx_delchunk(u8 *restrict buf, int chunk)
|
||||
{
|
||||
u32 table[TABLE];
|
||||
memcpy(table, buf, sizeof(table));
|
||||
usize res = delchunk(buf, table, 0, chunk, CHUNKS);
|
||||
memcpy(buf, table, sizeof(table));
|
||||
return res;
|
||||
}
|
||||
|
||||
usize mcx_delchunk_range(u8 *restrict buf, int start, int end)
|
||||
{
|
||||
assert(start < end && end < CHUNKS);
|
||||
u32 table[TABLE];
|
||||
memcpy(table, buf, sizeof(table));
|
||||
u8 *dst = buf + (be32toh(table[start]) >> 8) * SECTOR;
|
||||
u8 *src = buf + (be32toh(table[end]) >> 8) * SECTOR;
|
||||
src += (be32toh(table[end]) & 0xFF) * SECTOR;
|
||||
|
||||
// zeroes-out the chunk data within this range. (and set the timestamp)
|
||||
u32 ts = htobe32(time(NULL));
|
||||
for (int i = start; i <= end; i++) {
|
||||
table[i] = 0;
|
||||
table[i + CHUNKS] = ts;
|
||||
}
|
||||
|
||||
// move the remaining chunks down
|
||||
if (end < (CHUNKS - 1))
|
||||
mvchunks(dst, src, table, end, (CHUNKS - 1));
|
||||
memcpy(buf, table, sizeof(table));
|
||||
return src - dst;
|
||||
}
|
||||
|
||||
/* comparer function for to be inputted into `qsort` to compare two */
|
||||
static int cmp_chunkids(const void *restrict x, const void *restrict y)
|
||||
{
|
||||
u16 x2 = *(u16 *)x;
|
||||
u16 y2 = *(u16 *)y;
|
||||
return (x2 > y2) - (x2 < y2);
|
||||
}
|
||||
|
||||
/* Sorts the chunks marked for deletion from smallest to greatest index.
|
||||
* Then performs the deletion in this order. Making sure to only update the chunks up to the next. */
|
||||
usize mcx_delchunk_bulk(u8 *restrict buf, const u16 *restrict chunks, int chunkc)
|
||||
{
|
||||
// ensure the chunks ids we're working on are sorted from least to greatest
|
||||
u16 chunkids[chunkc + 1];
|
||||
memcpy(chunkids, chunks, chunkc);
|
||||
qsort(chunkids, chunkc, sizeof(int), cmp_chunkids);
|
||||
chunkids[chunkc] = CHUNKS; // set the spare chunk to the max chunks, so the rest of the chunks are moved
|
||||
|
||||
u32 table[TABLE];
|
||||
memcpy(table, buf, sizeof(table));
|
||||
|
||||
usize rmb = 0;
|
||||
for (int i = 0; i < chunkc; i++)
|
||||
rmb += delchunk(buf, table, rmb, chunkids[i], chunkids[i + 1]);
|
||||
|
||||
memcpy(buf, table, sizeof(table));
|
||||
return rmb;
|
||||
}
|
||||
|
||||
/* Sum together the 4th byte in each location integer to compute the sector size of all chunks.
|
||||
* Multiplying by `SECTOR`, and adding the size of the table itself. */
|
||||
usize mcx_calcsize(const u8 *restrict buf)
|
||||
{
|
||||
usize size = 0;
|
||||
for (uint i = 0; i < CHUNKS; i++)
|
||||
size += *(buf + (i * 4) + 3);
|
||||
return (size * SECTOR) + (TABLE * 4);
|
||||
}
|
||||
38
src/dat/mcx.h
Normal file
38
src/dat/mcx.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../types.h"
|
||||
#include "../util/atrb.h"
|
||||
|
||||
/* contains chunk metadata */
|
||||
struct mcx_chunk {
|
||||
usize idx; // byte offset for start of chunk data
|
||||
u32 len; // byte length of chunk (+ padding)
|
||||
u32 time; // modification time in epoch seconds
|
||||
};
|
||||
|
||||
/* Deletes a single chunk (`chunk`) out of `buf`.
|
||||
* The chunk's location data shall become `0`, and timestamp data the current time.
|
||||
* All succeeding chunks shall be moved back, freeing space.
|
||||
* Returns the amount of bytes removed. */
|
||||
usize mcx_delchunk(u8 *restrict buf, int chunk) NONNULL((1));
|
||||
|
||||
/* Deletes the range defined by `start`—`end` (inclusive) of chunks out of `buf`.
|
||||
* The chunk's location data shall become `0`, and timestamp data the current time.
|
||||
* All succeeding chunks shall be moved back, freeing space.
|
||||
* Returns the amount of bytes removed */
|
||||
usize mcx_delchunk_range(u8 *restrict buf, int start, int end) NONNULL((1));
|
||||
|
||||
/* Deletes a `chunkc` chunks from `chunks` out of `buf`.
|
||||
* If the `chunks` indices are known to be sequential, i.e. have a constant difference of `1`, `mcx_delchunk_range` should be preferred.
|
||||
* The chunk's location data shall become `0`, and timestamp data the current time.
|
||||
* All succeeding chunks shall be moved back, freeing space.
|
||||
* Returns the amount of bytes removed */
|
||||
usize mcx_delchunk_bulk(u8 *restrict buf, const u16 *restrict chunks, int chunkc) NONNULL((1, 2));
|
||||
|
||||
/* Computes the byte size of the `*.mcX` file in `buf` and returns it. */
|
||||
usize mcx_calcsize(const u8 *restrict buf) NONNULL((1)) PURE;
|
||||
218
src/dat/nbt.c
Normal file
218
src/dat/nbt.c
Normal file
@@ -0,0 +1,218 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#include "nbt.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <endian.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../types.h"
|
||||
|
||||
#define MAX_DEPTH 512
|
||||
|
||||
/* Extracts a big endian 16 bit integer from address `buf`, converts it to host byte size if needed and returns. */
|
||||
static inline u16 buftoh16(const void *restrict buf)
|
||||
{
|
||||
u16 i;
|
||||
memcpy(&i, buf, sizeof(i));
|
||||
return be16toh(i);
|
||||
}
|
||||
|
||||
/* Extracts a big endian 32 bit integer from address `buf`, converts it to host byte size if needed and returns. */
|
||||
static inline u32 buftoh32(const void *restrict buf)
|
||||
{
|
||||
u32 i;
|
||||
memcpy(&i, buf, sizeof(i));
|
||||
return be32toh(i);
|
||||
}
|
||||
|
||||
/* Extracts a big endian 64 bit integer from address `buf`, converts it to host byte size if needed and returns. */
|
||||
static inline u64 buftoh64(const void *restrict buf)
|
||||
{
|
||||
u64 i;
|
||||
memcpy(&i, buf, sizeof(i));
|
||||
return be64toh(i);
|
||||
}
|
||||
|
||||
/* Processes the incoming array data in `buf`. Which contains `nmem` items of `size`.
|
||||
* The data shall be converted to little-endian on little-endian systems
|
||||
* Outputs the allocated data to `out`, returns where the next pointer would be. */
|
||||
static const u8 *procarr(const u8 *restrict buf, i32 nmemb, uint size, struct nbt_array *restrict out)
|
||||
{
|
||||
usize len = nmemb * size;
|
||||
*out = (struct nbt_array){
|
||||
out->nmemb = nmemb,
|
||||
out->dat = malloc(len),
|
||||
};
|
||||
if (!out->dat)
|
||||
return buf + len;
|
||||
|
||||
memcpy(out->dat, buf, len);
|
||||
buf += len;
|
||||
|
||||
/* Only include this code for little-endian systems. Since only they require this logic.
|
||||
* Producing optimised code for other platforms. */
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
if (size == 1)
|
||||
return buf;
|
||||
i32 i = 0;
|
||||
while (i < nmemb) {
|
||||
switch (size) {
|
||||
case 2: ((u16 *)out->dat)[i] = be16toh(((u16 *)out->dat)[i]); break;
|
||||
case 4: ((u32 *)out->dat)[i] = be16toh(((u32 *)out->dat)[i]); break;
|
||||
case 8: ((u64 *)out->dat)[i] = be16toh(((u64 *)out->dat)[i]); break;
|
||||
default: __builtin_unreachable(); // this should be impossible
|
||||
}
|
||||
i += size;
|
||||
}
|
||||
#endif
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* calls `procarr` for the simple types available. */
|
||||
static const u8 *proclist(const u8 *restrict buf, struct nbt_array *restrict out)
|
||||
{
|
||||
uint size;
|
||||
|
||||
switch (*(u8 *)buf) {
|
||||
case NBT_I8: size = 1; break;
|
||||
case NBT_I16: size = 2; break;
|
||||
case NBT_I32: // fall through
|
||||
case NBT_F32: size = 4; break;
|
||||
case NBT_I64: // fall though
|
||||
case NBT_F64: size = 8; break;
|
||||
default: return NULL;
|
||||
}
|
||||
|
||||
buf++;
|
||||
i32 len;
|
||||
memcpy(&len, buf, 4);
|
||||
len = be32toh(len);
|
||||
buf += 4;
|
||||
return procarr(buf, len, size, out);
|
||||
}
|
||||
|
||||
const u8 *nbt_proctag(const u8 *restrict buf, u16 slen, void *restrict out)
|
||||
{
|
||||
const u8 *ptr, *tmp;
|
||||
ptr = buf + 3 + slen;
|
||||
|
||||
i32 nmem;
|
||||
uint size;
|
||||
|
||||
switch (*buf) {
|
||||
case NBT_I8: *(u8 *)out = *ptr; return ptr + 1;
|
||||
case NBT_I16: *(u16 *)out = buftoh16(ptr); return ptr + 2;
|
||||
case NBT_I32: // fall through
|
||||
case NBT_F32: *(u32 *)out = buftoh32(ptr); return ptr + 4;
|
||||
case NBT_I64: // fall through
|
||||
case NBT_F64: *(u64 *)out = buftoh64(ptr); return ptr + 8;
|
||||
|
||||
case NBT_STR: nmem = buftoh16(ptr), size = 1, ptr += 2; break;
|
||||
case NBT_ARR_I8: nmem = buftoh32(ptr), size = 1, ptr += 4; break;
|
||||
case NBT_ARR_I32: nmem = buftoh32(ptr), size = 4, ptr += 4; break;
|
||||
case NBT_ARR_I64: nmem = buftoh32(ptr), size = 8, ptr += 4; break;
|
||||
|
||||
case NBT_LIST:
|
||||
return proclist(ptr, (struct nbt_array *)out);
|
||||
return tmp;
|
||||
|
||||
default: return NULL;
|
||||
}
|
||||
|
||||
return procarr(ptr, nmem, size, (struct nbt_array *)out);
|
||||
}
|
||||
|
||||
|
||||
/* handles incrementing to the next tag in the case of `NBT_LIST`. This function shan't return `NULL`.
|
||||
* `ptr` is assumed to be the start of the `NBT_LIST` data, e.i. The list's ID, followed by the list's length.
|
||||
* If `ID` is `NBT_I8`, `NBT_I16`, `NBT_I32`, `NBT_I64`, `NBT_F32`, or `NBT_F64`, the entire list length is computed and returned.
|
||||
* For other types this won't be possible, and thus will add `1` to `dpt`, and write the list data to `lens` and `tags` at this new `dpt`. */
|
||||
static const u8 *nexttag_list(const u8 *restrict ptr, uint *restrict const dpt, i32 *restrict const lens, u8 *restrict const tags)
|
||||
{
|
||||
const u8 *tag = ptr;
|
||||
ptr++;
|
||||
switch (*tag) {
|
||||
case NBT_END: break;
|
||||
case NBT_I8: ptr += (i32)buftoh32(ptr) * 1; break;
|
||||
case NBT_I16: ptr += (i32)buftoh32(ptr) * 2; break;
|
||||
case NBT_I32: // fall through
|
||||
case NBT_F32: ptr += (i32)buftoh32(ptr) * 4; break;
|
||||
case NBT_I64: // fall through
|
||||
case NBT_F64: ptr += (i32)buftoh32(ptr) * 8; break;
|
||||
default:
|
||||
// TODO: handle out of bounds... Might not be required if we use flexible array member
|
||||
(*dpt)++;
|
||||
tags[*dpt] = *tag;
|
||||
lens[*dpt] = (i32)buftoh32(ptr);
|
||||
break;
|
||||
}
|
||||
ptr += 4;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* increments to the next tag and returns it (or `NULL`)
|
||||
* - `tag` represents the start of the tag, e.i. The tag ID, or in the case of `NBT_LIST` data, the start of this data.
|
||||
* - `dpt` shall point to the "depth" we're at, this is used as index for `lens` and `tags`
|
||||
* - `lens` shall contain `MAX_DEPTH` of items representing the list length, if the current item is non-zero we shall assume we're in a list.
|
||||
* Where the value is decremented until we reach `0`.
|
||||
* - `tags` shall contain `MAX_DEPTH` of items representing the list's stored type. */
|
||||
static const u8 *nexttag(const u8 *restrict tag, uint *restrict const dpt, i32 *restrict const lens, u8 *restrict const tags)
|
||||
{
|
||||
u8 type;
|
||||
const u8 *ptr = tag;
|
||||
if (lens[*dpt]) {
|
||||
type = tags[*dpt];
|
||||
lens[*dpt]--;
|
||||
*dpt -= !lens[*dpt];
|
||||
} else {
|
||||
type = *tag;
|
||||
ptr += buftoh16(tag + 1) + 3;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case NBT_I8: ptr += 1; break;
|
||||
case NBT_I16: ptr += 2; break;
|
||||
case NBT_I32: // fall through
|
||||
case NBT_F32: ptr += 4; break;
|
||||
case NBT_I64: // fall through
|
||||
case NBT_F64: ptr += 8; break;
|
||||
|
||||
case NBT_ARR_I8: ptr += 4 + (i32)buftoh32(ptr) * 1; break;
|
||||
case NBT_ARR_I32: ptr += 4 + (i32)buftoh32(ptr) * 4; break;
|
||||
case NBT_ARR_I64: ptr += 4 + (i32)buftoh32(ptr) * 8; break;
|
||||
case NBT_STR: ptr += 2 + (u16)buftoh16(ptr) * 1; break;
|
||||
|
||||
case NBT_END: (*dpt)--; break;
|
||||
case NBT_COMPOUND: (*dpt)++; break;
|
||||
|
||||
case NBT_LIST: ptr = nexttag_list(ptr, dpt, lens, tags); break;
|
||||
|
||||
default: return NULL; // unexpected value; buffer is likely corrupt
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* TODO: write test cases for this function:
|
||||
* - list:compound...
|
||||
* - non-existent type
|
||||
* - compound:list:int32
|
||||
* - string
|
||||
*/
|
||||
const u8 *nbt_nexttag(const u8 *restrict buf)
|
||||
{
|
||||
const u8 *tag;
|
||||
u8 tags[MAX_DEPTH] = {0};
|
||||
i32 lens[MAX_DEPTH] = {0};
|
||||
uint dpt = 0;
|
||||
|
||||
tag = buf;
|
||||
do {
|
||||
tag = nexttag(tag, &dpt, lens, tags);
|
||||
} while (dpt > 0);
|
||||
return tag;
|
||||
}
|
||||
57
src/dat/nbt.h
Normal file
57
src/dat/nbt.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <endian.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../types.h"
|
||||
#include "../util/atrb.h"
|
||||
|
||||
/* NBT (named binary tag) is a tree data structure. Tags have a numeric type ID, name and a payload.
|
||||
* NBT files are a compressed `compound` tag. GZip is the compression used in most cases,
|
||||
* in some (rare) cases it's stored uncompressed.
|
||||
* A tag is an individual part of the data tree.
|
||||
* The first byte is the ID, followed by a `u16`, for the length of the name.
|
||||
* Then the name as `UTF-8`. (end tag does not contain name) */
|
||||
|
||||
|
||||
/* specifies the NBT tag IDs.
|
||||
* NOTE: every type is stored as BE (big-endian) in the file. */
|
||||
enum nbt_tagid {
|
||||
NBT_END = 0x00, // signifies the end of a compound tag
|
||||
NBT_I8 = 0x01, // next byte is for an 8 bit signed integer.
|
||||
NBT_I16 = 0x02, // next 2 bytes are for a 16 bit signed integer
|
||||
NBT_I32 = 0x03, // next 4 bytes are for a 32 bit signed integer
|
||||
NBT_I64 = 0x04, // next 8 bytes are for a 64 bit signed integer
|
||||
NBT_F32 = 0x05, // next 4 bytes are for a single-precision floating-point
|
||||
NBT_F64 = 0x06, // next 8 bytes are for a double-precision floating-point
|
||||
NBT_ARR_I8 = 0x07, // starts with a i32, denoting size, followed by the i8 data
|
||||
NBT_STR = 0x08, // starts with a u16, denoting size, followed by the UTF-8 data
|
||||
NBT_LIST = 0x09, // starts with an ID, followed by a 32 bit signed integer denoting the size
|
||||
NBT_COMPOUND = 0x0A, // compound tag, contains tags and is delimited by `NBT_END`
|
||||
NBT_ARR_I32 = 0x0B, // starts with a i32, denoting size, followed by the i32 data
|
||||
NBT_ARR_I64 = 0x0C, // starts with a i32, denoting size, followed by the u32 data
|
||||
};
|
||||
|
||||
struct nbt_array {
|
||||
i32 nmemb;
|
||||
void *dat;
|
||||
};
|
||||
|
||||
|
||||
/* Acquires the data contained by the named tag.
|
||||
* - `buf` points to the start of the tag.
|
||||
* - `slen` contains the string length of the name.
|
||||
* - `out` points to where the data should be written.
|
||||
* if `buf` points to `NBT_I8`, `NBT_I16`, `NBT_I32`, `NBT_I64`, `NBT_F32`, or `NBT_F64`, `*out` is assumed
|
||||
* to have the available byte width for one of these types. In the case of `NBT_ARR*` and `NBT_LIST`
|
||||
* it must point to a `struct nbt_array*`. Where in the case of `NBT_LIST`, it must be one of the previous static-width types. */
|
||||
const u8 *nbt_proctag(const u8 *restrict buf, u16 slen, void *restrict out) NONNULL((1, 3));
|
||||
|
||||
/* searches for the end of a named tag without processing data, the final pointer is returned.
|
||||
* `NULL` is returned upon failure, the otherwise returned pointer is not guaranteed to be valid. */
|
||||
const u8 *nbt_nexttag(const u8 *restrict buf) NONNULL((1)) PURE;
|
||||
21
src/error.h
21
src/error.h
@@ -1,21 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
|
||||
#if __INCLUDE_LEVEL__ > 0
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "util/macro.h"
|
||||
#endif
|
||||
|
||||
#define debug(s, ...) printf("\033[95m" __FILE__ ":" MACRO_STR2(__LINE__) ": [DBG]: " s "\033[0m\n", ##__VA_ARGS__)
|
||||
#define info(s, ...) printf(__FILE__ ":" MACRO_STR2(__LINE__) ": [INF]: " s "\n", ##__VA_ARGS__)
|
||||
#define warn(s, ...) fprintf(stderr, "\033[93m" __FILE__ ":" MACRO_STR2(__LINE__) ": [WAR]: " s "\033[0m\n", ##__VA_ARGS__)
|
||||
#define error(s, ...) fprintf(stderr, "\033[91m" __FILE__ ":" MACRO_STR2(__LINE__) ": [ERR]: " s "\033[0m\n", ##__VA_ARGS__)
|
||||
|
||||
#define fatal(s, ...) \
|
||||
do { \
|
||||
printf("\033[101m" __FILE__ ":" MACRO_STR2(__LINE__) ": [FAT]: " s "\033[0m\n", ##__VA_ARGS__); \
|
||||
exit(1); \
|
||||
} while (0)
|
||||
35
src/io/conf.c
Normal file
35
src/io/conf.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "conf.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "../types.h"
|
||||
#include "../util/atrb.h"
|
||||
|
||||
/* Matches s1 with s2, returns a pointer to s1 where the match stopped. */
|
||||
static const char *strmat(const char *s1, const char *s2) PURE NONNULL((1, 2));
|
||||
static const char *strmat(const char *s1, const char *s2)
|
||||
{
|
||||
while ((*s1 == *s2) & !!*s1)
|
||||
s1++, s2++;
|
||||
return s1;
|
||||
}
|
||||
|
||||
int conf_getkeyval(const char *restrict buf, const char *const restrict *restrict keys, int klen, const char *restrict *restrict out)
|
||||
{
|
||||
const char *tmp = NULL;
|
||||
|
||||
ASSUME((klen > 0));
|
||||
int i = 0;
|
||||
for (; i < klen && !tmp; i++) {
|
||||
tmp = strmat(buf, keys[i]);
|
||||
tmp = keys[i][buf - tmp] ? tmp : 0;
|
||||
}
|
||||
|
||||
if (!tmp || *tmp != '=')
|
||||
return -1;
|
||||
|
||||
*out = tmp + 1;
|
||||
return i;
|
||||
}
|
||||
|
||||
int conf_val(int);
|
||||
12
src/io/conf.h
Normal file
12
src/io/conf.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "../types.h"
|
||||
#include "../util/atrb.h"
|
||||
|
||||
/* Gets the key and value, if present. Writes the pointer for the value to `out`.
|
||||
* Returns the key index, or <0 upon failure. */
|
||||
int conf_getkeyval(const char *restrict buf, const char *const restrict *restrict keys, int klen,
|
||||
const char *restrict *restrict out) NONNULL((1, 2, 4));
|
||||
|
||||
/* Processes the value of `type` in `val`. Outputs to `out`.
|
||||
* Returns non-zero on failure. */
|
||||
int conf_procval(u8 type, const char *restrict val, void *restrict out) NONNULL((2, 3));
|
||||
@@ -1,7 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
void key_callback(GLFWwindow* win, int key, int scancode, int action, int mods);
|
||||
@@ -1,10 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
int render_init(void);
|
||||
void render_update(GLFWwindow* win);
|
||||
@@ -1,59 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#include "shader.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../error.h"
|
||||
|
||||
#define NAM_S(name) _binary_res_##name##_start // name of a start variable
|
||||
#define NAM_E(name) _binary_res_##name##_end // name of an end variable
|
||||
|
||||
// macro for generating the variable declarations
|
||||
#define DEF_GLSL(name) \
|
||||
extern char const NAM_S(name)[]; \
|
||||
extern char const NAM_E(name)[]
|
||||
|
||||
// NOTE: we are currently just sucking up the memory costs for ease. We can either include the source files themselves. Or use compression, where I'd prefer the latter for ease of installation.
|
||||
// NOLINTBEGIN (bugprone-reserved-identifier)
|
||||
DEF_GLSL(sh_vert_glsl);
|
||||
DEF_GLSL(sh_frag_glsl);
|
||||
DEF_GLSL(sh_geom_glsl);
|
||||
// NOLINTEND
|
||||
|
||||
/* compile a shader */
|
||||
static GLuint shader_compile(GLenum type, char const* src, size_t len) {
|
||||
int ilen = len;
|
||||
GLuint shader = glCreateShader(type);
|
||||
glShaderSource(shader, 1, &src, &ilen);
|
||||
glCompileShader(shader);
|
||||
|
||||
// repurposing ilen for the max length of the shader log
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &ilen);
|
||||
if (ilen > 0) {
|
||||
char log[ilen];
|
||||
glGetShaderInfoLog(shader, ilen, &ilen, log);
|
||||
log[ilen - 1] = '\0'; // terminate the string one character sooner since the log includes a newline
|
||||
error("error whilst compiling shader type '0X%X': '%s'", type, log);
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
#define COMPILE_NAME(_type, _name) shader_compile(_type, NAM_S(_name), (uintptr_t)NAM_E(_name) - (uintptr_t)NAM_S(_name))
|
||||
int shader_init(GLuint pipe) {
|
||||
GLuint vs = COMPILE_NAME(GL_VERTEX_SHADER, sh_vert_glsl);
|
||||
GLuint fs = COMPILE_NAME(GL_FRAGMENT_SHADER, sh_frag_glsl);
|
||||
GLuint gs = COMPILE_NAME(GL_GEOMETRY_SHADER, sh_geom_glsl);
|
||||
|
||||
glAttachShader(pipe, vs);
|
||||
glAttachShader(pipe, fs);
|
||||
glAttachShader(pipe, gs);
|
||||
|
||||
glDeleteShader(vs);
|
||||
glDeleteShader(fs);
|
||||
glDeleteShader(gs);
|
||||
return 1;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int shader_init(GLuint pipe);
|
||||
@@ -1,10 +1,12 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#include "input.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
void key_callback(GLFWwindow* win, int key, int scancode, int action, int mods) {
|
||||
void input_callback(GLFWwindow *win, int key, int scancode, int action, int mods)
|
||||
{
|
||||
(void)win, (void)key, (void)scancode, (void)action, (void)mods; // make the compiler shut up as this is fine
|
||||
#ifndef NDEBUG
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
10
src/io/win/input.h
Normal file
10
src/io/win/input.h
Normal file
@@ -0,0 +1,10 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
/* Handles incoming key inputs for `win`.
|
||||
* Intended to be given as an argument to `glfwSetKeyCallback`. */
|
||||
void input_callback(GLFWwindow *win, int key, int scancode, int action, int mods);
|
||||
@@ -1,14 +1,14 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#include "render.h"
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glad/gl.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../error.h"
|
||||
#include "../util/types.h"
|
||||
#include "../../types.h"
|
||||
#include "../../util/error.h"
|
||||
#include "shader.h"
|
||||
|
||||
#define VERTC 3
|
||||
@@ -16,9 +16,10 @@ static GLuint pipe;
|
||||
static GLuint vbo; // vertex buffer object
|
||||
static GLuint vao; // vertex array object
|
||||
static GLuint screen_loc; // location to where OpenGL sends to the shaders of the screen dimensions
|
||||
static int win_w, win_h;
|
||||
static int win_w, win_h;
|
||||
|
||||
static void screen_resize(int w, int h) {
|
||||
static void screen_resize(int w, int h)
|
||||
{
|
||||
i32 verts[VERTC][4] = {
|
||||
{0, 0, w, 20 },
|
||||
{0, 20, w, h - 40},
|
||||
@@ -32,7 +33,8 @@ static void screen_resize(int w, int h) {
|
||||
win_h = h;
|
||||
}
|
||||
|
||||
int render_init(void) {
|
||||
int render_init(void)
|
||||
{
|
||||
pipe = glCreateProgram();
|
||||
shader_init(pipe); // initialise and include the shaders
|
||||
glLinkProgram(pipe); // link the application
|
||||
@@ -64,7 +66,8 @@ int render_init(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void render_update(GLFWwindow *win) {
|
||||
void render_update(GLFWwindow *win)
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
@@ -80,3 +83,13 @@ void render_update(GLFWwindow *win) {
|
||||
glBindVertexArray(vao);
|
||||
glDrawArrays(GL_POINTS, 0, VERTC);
|
||||
}
|
||||
|
||||
void render_free(void)
|
||||
{
|
||||
glDeleteVertexArrays(1, &vao);
|
||||
glDeleteBuffers(1, &vbo);
|
||||
glDeleteProgram(pipe);
|
||||
vbo = 0;
|
||||
vao = 0;
|
||||
pipe = 0;
|
||||
}
|
||||
11
src/io/win/render.h
Normal file
11
src/io/win/render.h
Normal file
@@ -0,0 +1,11 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glad/gl.h>
|
||||
|
||||
int render_init(void);
|
||||
void render_update(GLFWwindow *win);
|
||||
void render_free(void);
|
||||
57
src/io/win/shader.c
Normal file
57
src/io/win/shader.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#include "shader.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../../util/error.h"
|
||||
|
||||
|
||||
// NOTE: we are currently just sucking up the memory costs for ease. We can either include the source files themselves. Or use compression, where I'd prefer the latter for ease of installation.
|
||||
extern const char sh_vert_glsl[];
|
||||
extern const char sh_frag_glsl[];
|
||||
extern const char sh_geom_glsl[];
|
||||
extern const uint sh_vert_glsl_len;
|
||||
extern const uint sh_frag_glsl_len;
|
||||
extern const uint sh_geom_glsl_len;
|
||||
|
||||
/* Compiles a shader of `type` from `src` with `len` bytes.
|
||||
* Returns the integer for the shader. */
|
||||
static GLuint shader_compile(GLenum type, const char *src, usize len)
|
||||
{
|
||||
int ilen = len;
|
||||
GLuint shader = glCreateShader(type);
|
||||
glShaderSource(shader, 1, &src, &ilen);
|
||||
glCompileShader(shader);
|
||||
|
||||
// repurposing ilen for the max length of the shader log
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &ilen);
|
||||
if (ilen > 0) {
|
||||
char log[ilen];
|
||||
glGetShaderInfoLog(shader, ilen, &ilen, log);
|
||||
log[ilen - 1] = '\0'; // terminate the string one character sooner since the log includes a newline
|
||||
error("error whilst compiling shader type '0x%X': '%s'", type, log);
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
int shader_init(GLuint pipe)
|
||||
{
|
||||
GLuint vs = shader_compile(GL_VERTEX_SHADER, sh_vert_glsl, sh_vert_glsl_len);
|
||||
GLuint fs = shader_compile(GL_FRAGMENT_SHADER, sh_frag_glsl, sh_frag_glsl_len);
|
||||
GLuint gs = shader_compile(GL_GEOMETRY_SHADER, sh_geom_glsl, sh_geom_glsl_len);
|
||||
|
||||
glAttachShader(pipe, vs);
|
||||
glAttachShader(pipe, fs);
|
||||
glAttachShader(pipe, gs);
|
||||
|
||||
// mark shaders off for deletion
|
||||
glDeleteShader(vs);
|
||||
glDeleteShader(fs);
|
||||
glDeleteShader(gs);
|
||||
return 1;
|
||||
}
|
||||
11
src/io/win/shader.h
Normal file
11
src/io/win/shader.h
Normal file
@@ -0,0 +1,11 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
#include <glad/gl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* Initialises the (embedded) shaders onto `pipe` */
|
||||
int shader_init(GLuint pipe);
|
||||
89
src/io/win/window.c
Normal file
89
src/io/win/window.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#include "window.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <assert.h>
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include "../../types.h"
|
||||
#include "../../util/error.h"
|
||||
#include "input.h"
|
||||
#include "render.h"
|
||||
|
||||
static struct GLFWwindow *win = NULL;
|
||||
|
||||
/* Initialises the GLFW window with some defaults,
|
||||
* then proceed to activate OpenGL on it. */
|
||||
int window_init(void)
|
||||
{
|
||||
// initialise the window
|
||||
#ifndef NDEBUG
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
|
||||
#endif
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, 1);
|
||||
glfwWindowHint(GLFW_RED_BITS, 8);
|
||||
glfwWindowHint(GLFW_GREEN_BITS, 8);
|
||||
glfwWindowHint(GLFW_BLUE_BITS, 8);
|
||||
glfwWindowHint(GLFW_ALPHA_BITS, 0);
|
||||
/* NOTE: on my system; x86_64, GTX 1650 580.82.09-2, X11, i3, this causes one direct, 2 indirect memory leaks.
|
||||
* This is not my fault, and can safely be ignored. */
|
||||
win = glfwCreateWindow(640, 480, "MCA-Selector lite", NULL, NULL);
|
||||
if (!win)
|
||||
return 1;
|
||||
|
||||
glfwMakeContextCurrent(win);
|
||||
if (!gladLoadGL(glfwGetProcAddress))
|
||||
return 1;
|
||||
glfwSwapInterval(1); // wait 1 screen update for a redraw a.k.a. "vsync". (not really applicable in this case but eh)
|
||||
|
||||
glfwSetKeyCallback(win, input_callback);
|
||||
|
||||
debug(
|
||||
"version info:\n"
|
||||
"\tvendor: %s\n"
|
||||
"\trenderer: %s\n"
|
||||
"\tversion: %s\n"
|
||||
"\tshading lang: %s\n",
|
||||
glGetString(GL_VENDOR),
|
||||
glGetString(GL_RENDERER),
|
||||
glGetString(GL_VERSION),
|
||||
glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void window_loop(void)
|
||||
{
|
||||
assert(win);
|
||||
render_init();
|
||||
while (!glfwWindowShouldClose(win)) {
|
||||
glfwWaitEvents();
|
||||
|
||||
render_update(win);
|
||||
glfwSwapBuffers(win);
|
||||
glfwPollEvents();
|
||||
}
|
||||
}
|
||||
|
||||
void window_close(void)
|
||||
{
|
||||
assert(win);
|
||||
glfwSetWindowShouldClose(win, 1);
|
||||
}
|
||||
|
||||
void window_free(void)
|
||||
{
|
||||
if (!win) {
|
||||
debug("window has already been freed.");
|
||||
return;
|
||||
}
|
||||
|
||||
glfwDestroyWindow(win);
|
||||
render_free();
|
||||
win = NULL;
|
||||
}
|
||||
20
src/io/win/window.h
Normal file
20
src/io/win/window.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
/* Set up the window, enabling OpenGL, and
|
||||
* configuring the settings that are needed.
|
||||
* Returns `0` upon success, otherwise `1`. */
|
||||
int window_init(void);
|
||||
|
||||
/* Calls the update loop for the window.
|
||||
* This function does not exit until the window does. */
|
||||
void window_loop(void);
|
||||
|
||||
/* Requests the window to close (gracefully). */
|
||||
void window_close(void);
|
||||
|
||||
/* Cleans up all resources held by the window.
|
||||
* If the window is still open, it will be terminated. */
|
||||
void window_free(void);
|
||||
@@ -1,74 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#include "window.h"
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "../error.h"
|
||||
#include "input.h"
|
||||
#include "render.h"
|
||||
|
||||
// macros for ease of access
|
||||
#define WIN_NAME "MCA Selector Lite"
|
||||
#define WIN_DEFAULT_WIDTH 640
|
||||
#define WIN_DEFAULT_HEIGHT 480
|
||||
|
||||
static GLFWwindow* win = NULL;
|
||||
|
||||
int window_init(void) {
|
||||
#ifndef NDEBUG
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
|
||||
#endif
|
||||
|
||||
// initialize the window
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // sets the profile to "core", so old, deprecated functions are disabled.
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_RED_BITS, 8);
|
||||
glfwWindowHint(GLFW_GREEN_BITS, 8);
|
||||
glfwWindowHint(GLFW_BLUE_BITS, 8);
|
||||
glfwWindowHint(GLFW_ALPHA_BITS, 0);
|
||||
win = glfwCreateWindow(WIN_DEFAULT_WIDTH, WIN_DEFAULT_HEIGHT, WIN_NAME, NULL, NULL);
|
||||
if (!win) return 1;
|
||||
|
||||
// setup OpenGL for the window
|
||||
glfwMakeContextCurrent(win);
|
||||
if (!gladLoadGL(glfwGetProcAddress)) return 1;
|
||||
glfwSwapInterval(1); // wait 1 screen update for a redraw a.k.a. "vsync". (not really applicable in this case but eh)
|
||||
|
||||
// configure callbacks
|
||||
glfwSetKeyCallback(win, key_callback);
|
||||
|
||||
// print the OpenGL version information
|
||||
debug(
|
||||
"version info:\n"
|
||||
"\tvendor: %s\n"
|
||||
"\trenderer: %s\n"
|
||||
"\tversion: %s\n"
|
||||
"\tshading lang: %s\n",
|
||||
glGetString(GL_VENDOR),
|
||||
glGetString(GL_RENDERER),
|
||||
glGetString(GL_VERSION),
|
||||
glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void window_loop(void) {
|
||||
assert(win != NULL);
|
||||
|
||||
render_init();
|
||||
while (!glfwWindowShouldClose(win)) {
|
||||
glfwWaitEvents(); // wait till an update has been given
|
||||
|
||||
render_update(win);
|
||||
glfwSwapBuffers(win);
|
||||
}
|
||||
|
||||
glfwDestroyWindow(win);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
|
||||
int window_init(void); // initializes the global window, returns non-zero upon failure
|
||||
void window_loop(void); // performs the window updates
|
||||
57
src/main.c
57
src/main.c
@@ -1,48 +1,45 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include <glad/gl.h>
|
||||
#undef GLAD_GL_IMPLEMENTATION
|
||||
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glad/gl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "error.h"
|
||||
#include "io/window.h"
|
||||
#include "io/win/window.h"
|
||||
#include "util/error.h"
|
||||
|
||||
|
||||
#define WIN_NAME "MCA Selector Lite"
|
||||
#define WIN_DEFAULT_WIDTH 640
|
||||
#define WIN_DEFAULT_HEIGHT 480
|
||||
|
||||
// callback for GLFW errors
|
||||
static void error_callback(int err, char const *const msg) {
|
||||
fprintf(stderr, "\033[91mE: glfw returned (%i); \"%s\"\033[0m\n", err, msg);
|
||||
/* reroutes GLFW errors to our logging system. */
|
||||
static void error_callback(int err, const char *const msg)
|
||||
{
|
||||
error("glfw returned (%i); \"%s\"", err, msg);
|
||||
}
|
||||
|
||||
static inline int init(void) {
|
||||
glfwSetErrorCallback(error_callback);
|
||||
glfwInitHint(GLFW_JOYSTICK_HAT_BUTTONS, GLFW_FALSE); // disable joystick buttons
|
||||
static void quit(void)
|
||||
{
|
||||
window_free();
|
||||
|
||||
if (!glfwInit()) return 1; // initialize GLFW
|
||||
if (window_init()) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void quit(void) {
|
||||
/* terminates GLFW; destroying any
|
||||
* remaining windows, or other resources held by GLFW. */
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
/* Entry-point of the application. */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
(void)argc, (void)argv;
|
||||
printf("debug: [DBG], info: [INF], warning: [WAR], error: [ERR], fatal: [FAT]\n");
|
||||
if (init()) fatal("failed to initialize!");
|
||||
atexit(quit);
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
glfwInitHint(GLFW_JOYSTICK_HAT_BUTTONS, GLFW_FALSE); // disable joystick buttons; since we won't need them
|
||||
if (!glfwInit() || window_init())
|
||||
fatal("failed to initialise!");
|
||||
|
||||
window_loop();
|
||||
quit();
|
||||
|
||||
// return success, since some architectures do not follow 0=success
|
||||
/* return success, since some architectures do not follow 0=success
|
||||
* This action will call `quit`. */
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
36
src/types.h
Normal file
36
src/types.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
typedef signed long long int llong;
|
||||
typedef unsigned short int ushort;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned long long ullong;
|
||||
typedef __INT8_TYPE__ i8;
|
||||
typedef __INT16_TYPE__ i16;
|
||||
typedef __INT32_TYPE__ i32;
|
||||
typedef __INT64_TYPE__ i64;
|
||||
typedef __UINT8_TYPE__ u8;
|
||||
typedef __UINT16_TYPE__ u16;
|
||||
typedef __UINT32_TYPE__ u32;
|
||||
typedef __UINT64_TYPE__ u64;
|
||||
typedef __SIZE_TYPE__ usize;
|
||||
typedef __INTPTR_TYPE__ intptr;
|
||||
typedef __UINTPTR_TYPE__ uintptr;
|
||||
|
||||
#if __SIZEOF_SIZE_T__ == __SIZEOF_LONG_LONG__
|
||||
typedef llong ssize;
|
||||
#elif __SIZEOF_SIZE_T__ == __SIZEOF_LONG__
|
||||
typedef long ssize;
|
||||
#elif __SIZEOF_SIZE_T__ == __SIZEOF_INT__
|
||||
typedef int ssize;
|
||||
#endif
|
||||
|
||||
#if __SIZEOF_FLOAT__ == 4
|
||||
typedef float f32;
|
||||
#endif
|
||||
#if __SIZEOF_DOUBLE__ == 8
|
||||
typedef double f64;
|
||||
#endif
|
||||
@@ -1,30 +1,64 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
// define the attributes where possible
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define atrb(...) __attribute__(__VA_ARGS__)
|
||||
#define atrb_deprecated __attribute__((depricated))
|
||||
#define atrb_unused __attribute__((unused))
|
||||
#define atrb_pure __attribute__((pure))
|
||||
#define atrb_const __attribute__((const))
|
||||
#define atrb_noreturn __attribute__((noreturn))
|
||||
#define atrb_malloc __attribute__((malloc))
|
||||
#define atrb_format(...) __attribute__((format(__VA_ARGS__)))
|
||||
#define atrb_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
|
||||
#elif defined(_MSC_VER)
|
||||
#define atrb __declspec
|
||||
#define atrb_deprecated __declspec(deprecated)
|
||||
#define atrb_noreturn __declspec(noreturn)
|
||||
#if defined(__GNUC__)
|
||||
#if __has_attribute(__pure__)
|
||||
#define PURE __attribute__((__pure__))
|
||||
#else
|
||||
#define atrb
|
||||
#define atrb_deprecated
|
||||
#define atrb_unused
|
||||
#define atrb_pure
|
||||
#define atrb_const
|
||||
#define atrb_noreturn
|
||||
#define atrb_malloc
|
||||
#define atrb_format()
|
||||
#define atrb_nonnull()
|
||||
#define PURE
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__const__)
|
||||
#define CONST __attribute__((__const__))
|
||||
#else
|
||||
#define CONST
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__noreturn__)
|
||||
#define NORET __attribute__((__noreturn__))
|
||||
#else
|
||||
#define NORET
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__malloc__)
|
||||
#define MALLOC __attribute__((__malloc__))
|
||||
#else
|
||||
#define MALLOC
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__used__)
|
||||
#define USED __attribute__((__used__))
|
||||
#else
|
||||
#define USED
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__unused__)
|
||||
#define UNUSED __attribute__((__unused__))
|
||||
#else
|
||||
#define UNUSED
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__deprecated__)
|
||||
#define DEPRECATED __attribute__((__deprecated__))
|
||||
#else
|
||||
#define DEPRECATED
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__format__)
|
||||
#define FORMAT(args) __attribute__((format args))
|
||||
#else
|
||||
#define FORMAT(args)
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__nonnull__)
|
||||
#define NONNULL(args) __attribute__((__nonnull__ args))
|
||||
#else
|
||||
#define NONNULL(args)
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__assume__)
|
||||
#define ASSUME(args) __attribute__((__assume__ args))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
// stores colour in a rgba format stored as little-endian, each channel being a 8 bits wide.
|
||||
typedef union colour32 {
|
||||
u32 dat; // full colour data; little-endian
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
// colour channel information for little-endian systems
|
||||
struct {
|
||||
u8 a, b, g, r;
|
||||
} ch;
|
||||
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
// colour channel information for big-endian systems
|
||||
struct {
|
||||
u8 r, g, b, a;
|
||||
} ch;
|
||||
#endif
|
||||
} colour32;
|
||||
|
||||
#define COLOUR32_BLACK ((colour32){0x000000FF})
|
||||
#define COLOUR32_RED ((colour32){0xFF0000FF})
|
||||
#define COLOUR32_YELLOW ((colour32){0xFFFF00FF})
|
||||
#define COLOUR32_ORANGE ((colour32){0xFF6D00FF})
|
||||
#define COLOUR32_GREEN ((colour32){0x00FF00FF})
|
||||
#define COLOUR32_CYAN ((colour32){0x00FFFFFF})
|
||||
#define COLOUR32_BLUE ((colour32){0x0000FFFF})
|
||||
#define COLOUR32_MAGENTA ((colour32){0xFF00FFFF})
|
||||
#define COLOUR32_WHITE ((colour32){0xFFFFFFFF})
|
||||
|
||||
// american macros:
|
||||
#define color32 colour32
|
||||
#define COLOR32_BLACK COLOUR32_BLACK
|
||||
#define COLOR32_RED COLOUR32_RED
|
||||
#define COLOR32_YELLOW COLOUR32_YELLOW
|
||||
#define COLOR32_ORANGE COLOUR32_ORANGE
|
||||
#define COLOR32_GREEN COLOUR32_GREEN
|
||||
#define COLOR32_CYAN COLOUR32_CYAN
|
||||
#define COLOR32_BLUE COLOUR32_BLUE
|
||||
#define COLOR32_MAGENTA COLOUR32_MAGENTA
|
||||
#define COLOR32_WHITE COLOUR32_WHITE
|
||||
@@ -1,44 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "../types.h"
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define bswap16 __builtin_bswap16
|
||||
#define bswap32 __builtin_bswap32
|
||||
#define bswap64 __builtin_bswap64
|
||||
#elif __has_include(<byteswap.h>)
|
||||
#include <byteswap.h>
|
||||
#define bswap16 bswap_16
|
||||
#define bswap32 bswap_32
|
||||
#define bswap64 bswap_64
|
||||
#else
|
||||
#define bswap16 bswap16_impl
|
||||
#define bswap32 bswap32_impl
|
||||
#define bswap64 bswap64_impl
|
||||
#define IMPL_BSWAP
|
||||
#endif
|
||||
|
||||
#if defined(IMPL_BSWAP) || !defined(NDEBUG)
|
||||
static inline u16 bswap16_impl(u16 x) {
|
||||
return (x << 8) | (x >> 8);
|
||||
}
|
||||
|
||||
static inline u32 bswap32_impl(u32 x) {
|
||||
return (x << 24) |
|
||||
((0x0000FF00U & x) << 8) |
|
||||
((0x00FF0000U & x) >> 8) |
|
||||
(x >> 24);
|
||||
}
|
||||
|
||||
static inline u64 bswap64_impl(u64 x) {
|
||||
return (x << 56) |
|
||||
((0x000000000000FF00ULL & x) << 40) |
|
||||
((0x0000000000FF0000ULL & x) << 24) |
|
||||
((0x00000000FF000000ULL & x) << 8) |
|
||||
((0x000000FF00000000ULL & x) >> 8) |
|
||||
((0x0000FF0000000000ULL & x) >> 24) |
|
||||
((0x00FF000000000000ULL & x) >> 40) |
|
||||
(x >> 56);
|
||||
}
|
||||
#endif
|
||||
#undef IMPL_BSWAP
|
||||
@@ -1,55 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../atrb.h"
|
||||
#include "../types.h"
|
||||
#include "bswap.h"
|
||||
|
||||
/* little endian */
|
||||
atrb_const static inline u16 le16ton(u16); // converts little-endian (LE) encoding to native for a 16 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline u32 le32ton(u32); // converts little-endian (LE) encoding to native for a 32 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline u64 le64ton(u64); // converts little-endian (LE) encoding to native for a 64 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline u16 ntole16(u16); // converts native encoding to little-endian (LE) for a 16 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline u32 ntole32(u32); // converts native encoding to little-endian (LE) for a 32 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline u64 ntole64(u64); // converts native encoding to little-endian (LE) for a 64 bit integer. (NOOP if native is LE)
|
||||
|
||||
/* big endian */
|
||||
atrb_const static inline u16 be16ton(u16); // converts big-endian (BE) encoding to native for a 16 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline u32 be32ton(u32); // converts big-endian (BE) encoding to native for a 32 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline u64 be64ton(u64); // converts big-endian (BE) encoding to native for a 64 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline u16 ntobe16(u16); // converts native encoding to big-endian (BE) for a 16 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline u32 ntobe32(u32); // converts native encoding to big-endian (BE) for a 32 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline u64 ntobe64(u64); // converts native encoding to big-endian (BE) for a 64 bit integer. (NOOP if native is BE)
|
||||
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
u16 le16ton(u16 x) { return x; }
|
||||
u32 le32ton(u32 x) { return x; }
|
||||
u64 le64ton(u64 x) { return x; }
|
||||
u16 ntole16(u16 x) { return x; }
|
||||
u32 ntole32(u32 x) { return x; }
|
||||
u64 ntole64(u64 x) { return x; }
|
||||
u16 be16ton(u16 x) { return bswap16(x); }
|
||||
u32 be32ton(u32 x) { return bswap32(x); }
|
||||
u64 be64ton(u64 x) { return bswap64(x); }
|
||||
u16 ntobe16(u16 x) { return bswap16(x); }
|
||||
u32 ntobe32(u32 x) { return bswap32(x); }
|
||||
u64 ntobe64(u64 x) { return bswap64(x); }
|
||||
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
u16 le16ton(u16 x) { bswap_16(x); }
|
||||
u32 le32ton(u32 x) { bswap_32(x); }
|
||||
u64 le64ton(u64 x) { bswap_64(x); }
|
||||
u16 ntole16(u16 x) { bswap_16(x); }
|
||||
u32 ntole32(u32 x) { bswap_32(x); }
|
||||
u64 ntole64(u64 x) { bswap_64(x); }
|
||||
u16 be16ton(u16 x) { return x; }
|
||||
u32 be32ton(u32 x) { return x; }
|
||||
u64 be64ton(u64 x) { return x; }
|
||||
u16 ntobe16(u16 x) { return x; }
|
||||
u32 ntobe32(u32 x) { return x; }
|
||||
u64 ntobe64(u64 x) { return x; }
|
||||
#else
|
||||
#error machine architecture unsupported! Expected either big-endian or little-endian, make sure to use a compiler which defines __BYTE_ORDER__ (like clang or gcc)
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
#if defined __unix__
|
||||
@@ -13,7 +14,7 @@
|
||||
|
||||
/* tests a files access with F_OK, X_OK, R_OK, W_OK OR'd together
|
||||
returns 0 upon success. -1 when errno is set and anything else when one or more of the permissions isn't set */
|
||||
static inline int faccess(char const *restrict fname, int perms);
|
||||
static inline int faccess(const char *restrict fname, int perms);
|
||||
|
||||
// define the constants if they haven't been
|
||||
#ifndef F_OK
|
||||
@@ -33,14 +34,16 @@ static inline int faccess(char const *restrict fname, int perms);
|
||||
#define PATH_SEP '/' // contains the path separator as a character. Yes it is extremely annoying that this has to exist.
|
||||
#define PATH_SEP_STR "/" // contains the path separator as a string, useful for concatenation. Yes it is extremely annoying that this has to exist.
|
||||
|
||||
int faccess(char const *restrict fname, int perms) {
|
||||
int faccess(char const *restrict fname, int perms)
|
||||
{
|
||||
return access(fname, perms);
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
#define PATH_SEP '\\' // contains the path separator as a character. Yes it is extremely annoying that this has to exist.
|
||||
#define PATH_SEP_STR "\\" // contains the path separator as a string, useful for concatenation. Yes it is extremely annoying that this has to exist.
|
||||
|
||||
int faccess(char const *restrict fname, int perms) {
|
||||
int faccess(char const *restrict fname, int perms)
|
||||
{
|
||||
return _access(fname, perms);
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
#if defined(__unix__)
|
||||
|
||||
179
src/util/conf.c
179
src/util/conf.c
@@ -1,179 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#include "conf.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../error.h"
|
||||
#include "atrb.h"
|
||||
#include "types.h"
|
||||
|
||||
int conf_procbuf(char const *restrict buf, char *restrict kout, char *restrict vout, size_t len) {
|
||||
bool feq = false; // whether we've found the equal sign
|
||||
|
||||
// data traversal
|
||||
char *pos = kout; // will point to the next point in the buffer, where we'll write data
|
||||
|
||||
// acquire data
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
// handling of termination tokens
|
||||
bool brk = false; // whether we broke out of the loop, and are done reading
|
||||
switch (buf[i]) {
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\0':
|
||||
case '#':
|
||||
brk = true;
|
||||
break;
|
||||
}
|
||||
if (brk) break;
|
||||
|
||||
// everything after `=` is interpreted as a value
|
||||
if (!feq && buf[i] == '=') {
|
||||
feq = true;
|
||||
*pos = '\0'; // terminate string
|
||||
pos = vout; // move pointer to start of value data
|
||||
continue;
|
||||
}
|
||||
*pos = buf[i]; // copy over the buffer's data
|
||||
pos++; // increment the position pointer
|
||||
}
|
||||
// null-terminate what we've got now (yes, there should be enough space for this since \0 isn't stored)
|
||||
// this also ensures the value is valid, even if none is given
|
||||
*pos = '\0';
|
||||
|
||||
// no data if we didn't move from the key position
|
||||
// syntax error if we couldn't find the equal sign
|
||||
return (pos == kout) ? CONF_ENODAT : (!feq ? CONF_ESYNTAX : 0);
|
||||
}
|
||||
|
||||
struct conf_entry const *conf_matchopt(struct conf_entry const *opts, size_t optc, char const *restrict key) {
|
||||
// find a match for the current key
|
||||
size_t i = 0;
|
||||
for (; i < optc; i++) {
|
||||
if (strcmp(opts[i].key, key) == 0)
|
||||
return opts + i;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int conf_procval(struct conf_entry const *opt, char const *restrict val) {
|
||||
// parse the data
|
||||
errno = 0;
|
||||
char *end;
|
||||
u8 dat[sizeof(u64)];
|
||||
|
||||
switch (opt->type) {
|
||||
// signed integer data parsing
|
||||
case CONF_I8:
|
||||
case CONF_I16:
|
||||
case CONF_I32:
|
||||
case CONF_I64:
|
||||
*(i64 *)dat = strtoll(val, &end, 10); // for signed integer types
|
||||
break;
|
||||
// unsigned integer data parsing
|
||||
case CONF_U8:
|
||||
case CONF_U16:
|
||||
case CONF_U32:
|
||||
case CONF_U64:
|
||||
*(u64 *)dat = strtoull(val, &end, 10); // for unsigned integer types
|
||||
break;
|
||||
|
||||
// floating-point data parsing
|
||||
case CONF_F32: *(f32 *)dat = strtof(val, &end); break;
|
||||
case CONF_F64: *(f64 *)dat = strtod(val, &end); break;
|
||||
|
||||
// string data parsing
|
||||
case CONF_STR:
|
||||
if (*(char **)opt->out) {
|
||||
free(*(char **)opt->out); // if the same key is given multiple times, free the memory so we don't leak.
|
||||
warn("encountered a dynamic string multiple times, this is sub-optimal.");
|
||||
}
|
||||
*(char **)opt->out = strdup(val);
|
||||
return 0;
|
||||
case CONF_FSTR: {
|
||||
struct conf_fstr *s = opt->out;
|
||||
strncpy(s->out, val, s->len);
|
||||
s->out[s->len - 1] = '\0'; // ensure the string is null-terminated
|
||||
return 0;
|
||||
}
|
||||
default: return CONF_EINVALIDTYPE; // return error code indicating function not implemented
|
||||
}
|
||||
|
||||
if (errno || end == val || *end != '\0') {
|
||||
error("failed to parse '%s' as a numeric value", val);
|
||||
return CONF_EPARSE;
|
||||
}
|
||||
|
||||
switch (opt->type) {
|
||||
case CONF_U8: *(u8 *)opt->out = *(u64 *)dat >= UINT8_MAX ? UINT8_MAX : *(u64 *)dat; return 0;
|
||||
case CONF_U16: *(u16 *)opt->out = *(u64 *)dat >= UINT16_MAX ? UINT16_MAX : *(u64 *)dat; return 0;
|
||||
case CONF_U32: *(u32 *)opt->out = *(u64 *)dat >= UINT32_MAX ? UINT32_MAX : *(u64 *)dat; return 0;
|
||||
case CONF_U64: *(u64 *)opt->out = *(u64 *)dat >= UINT64_MAX ? UINT64_MAX : *(u64 *)dat; return 0;
|
||||
case CONF_I8: *(i8 *)opt->out = *(i64 *)dat >= INT8_MAX ? INT8_MAX : (*(i64 *)dat <= INT8_MIN ? INT8_MIN : *(i64 *)dat); return 0;
|
||||
case CONF_I16: *(i16 *)opt->out = *(i64 *)dat >= INT16_MAX ? INT16_MAX : (*(i64 *)dat <= INT16_MIN ? INT16_MIN : *(i64 *)dat); return 0;
|
||||
case CONF_I32: *(i32 *)opt->out = *(i64 *)dat >= INT32_MAX ? INT32_MAX : (*(i64 *)dat <= INT32_MIN ? INT32_MIN : *(i64 *)dat); return 0;
|
||||
case CONF_I64: *(i64 *)opt->out = *(i64 *)dat >= INT64_MAX ? INT64_MAX : (*(i64 *)dat <= INT64_MIN ? INT64_MIN : *(i64 *)dat); return 0;
|
||||
case CONF_F32: *(f32 *)opt->out = *(f32 *)dat; return 0;
|
||||
case CONF_F64: *(f64 *)opt->out = *(f64 *)dat; return 0;
|
||||
default: fatal("invalid switch state, all cases should be handled already"); // abort; this shouldn't be possible, so I blame the programmer
|
||||
}
|
||||
}
|
||||
|
||||
/* utility function for conf_getpat to concatenate 3 strings, where we already know the size */
|
||||
atrb_nonnull(1, 3) static char *conf_getpat_concat(char const *restrict s1, char const *restrict s2, char const *restrict s3, size_t s1len, size_t s2len, size_t s3len) {
|
||||
assert(s2 || (!s2 && !s2len)); // ensuring the programmer passes both s2 and s2len as 0, if they intend to
|
||||
char *buf, *ptr;
|
||||
|
||||
// allocate enough data for all three to the buffer
|
||||
ptr = malloc(s1len + s2len + s3len + 1);
|
||||
if (!ptr) return NULL;
|
||||
buf = ptr; // store the head pointer into buf
|
||||
|
||||
// copy data to the buffer
|
||||
ptr = mempcpy(ptr, s1, s1len); // copy s1 data to the buffer
|
||||
if (s2len) ptr = mempcpy(ptr, s2, s2len); // copy s2 data to the buffer (excluding null-terminator)
|
||||
(void)strcpy(ptr, s3); // copy s3 as a string, thus including null-terminator
|
||||
|
||||
// return the buffer
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* appends str to the config directory string we acquire from environment variables. */
|
||||
char *conf_getpat(char const *restrict str) {
|
||||
char *buf = NULL;
|
||||
size_t len;
|
||||
size_t str_len = strlen(str);
|
||||
#if defined(__linux__)
|
||||
buf = getenv("XDG_CONFIG_HOME");
|
||||
if (!buf) {
|
||||
buf = getenv("HOME");
|
||||
if (!buf) return NULL;
|
||||
len = strlen(buf);
|
||||
return conf_getpat_concat(buf, "/.config", str, len, 8, str_len);
|
||||
}
|
||||
return conf_getpat_concat(buf, NULL, str, strlen(buf), 0, str_len);
|
||||
#elif defined(__APPLE__)
|
||||
buf = getenv("HOME");
|
||||
if (!buf) return NULL;
|
||||
len = strlen(buf);
|
||||
return conf_getpat_concat(buf, "/Library/Application Support", str, len, 28, str_len);
|
||||
#elif defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
|
||||
buf = getenv("APPDATA");
|
||||
if (!buf) {
|
||||
buf = getenv("USERPROFILE");
|
||||
if (!buf) return NULL;
|
||||
len = strlen(buf);
|
||||
return conf_getpat_concat(buf, "\\AppData\\Roaming", str, len, 16, str_len);
|
||||
}
|
||||
return conf_getpat_concat(buf, NULL, str, strlen(buf), 0, str_len);
|
||||
#else
|
||||
#error platform unsupported!
|
||||
#endif
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "atrb.h"
|
||||
|
||||
/* error codes */
|
||||
enum conf_err {
|
||||
CONF_ENODAT = -1, // no data was found
|
||||
CONF_ESYNTAX = 1, // couldn't extract clear key/val data
|
||||
CONF_ENOMATCH = 2, // couldn't find a match for the inputted key
|
||||
CONF_EINVALIDTYPE = 3, // the type inputted in conf_entry was invalid
|
||||
CONF_EPARSE = 4, // something went wrong whilst parsing
|
||||
};
|
||||
|
||||
/* defines the primitive types available in the config file */
|
||||
enum conf_primitive {
|
||||
CONF_STR = 0, // expects: `char**`, will output malloc'd data !!must be freed!!
|
||||
CONF_I8 = 1, // expects: `int8_t*`, will point to a location in memory where an i8 is stored.
|
||||
CONF_I16 = 2, // expects: `int16_t*`, will point to a location in memory where an i16 is stored.
|
||||
CONF_I32 = 4, // expects: `int32_t*`, will point to a location in memory where an i32 is stored.
|
||||
CONF_I64 = 8, // expects: `int64_t*`, will point to a location in memory where an i64 is stored.
|
||||
CONF_U8 = CONF_I8 | 0x80, // expects: `uint8_t*`, will point to a location in memory where an u8 is stored.
|
||||
CONF_U16 = CONF_I16 | 0x80, // expects: `uint16_t*`, will point to a location in memory where an u16 is stored.
|
||||
CONF_U32 = CONF_I32 | 0x80, // expects: `uint32_t*`, will point to a location in memory where an u32 is stored.
|
||||
CONF_U64 = CONF_I64 | 0x80, // expects: `uint64_t*`, will point to a location in memory where an u64 is stored.
|
||||
CONF_F32 = CONF_I32 | 0x40, // expects: `float*`, will point to a location in memory where an f32 is stored.
|
||||
CONF_F64 = CONF_I64 | 0x40, // expects: `double*`, will point to a location in memory where an f64 is stored.
|
||||
CONF_FSTR = 0x40, // expects: `struct conf_fstr*`, which contains the data for a fixed-width string
|
||||
};
|
||||
|
||||
/* for outputting a fixed string as this config field */
|
||||
struct conf_fstr {
|
||||
size_t len; // length in BYTES of the output data
|
||||
char *out; // where we will output the data
|
||||
};
|
||||
|
||||
/* defines the structure of a config file entry */
|
||||
struct conf_entry {
|
||||
char const *key; // the key of this entry
|
||||
void *out; // the pointer to which the data is written value is read if the given option is incorrect or missing
|
||||
uint8_t type; // the primitive type which we are querying for
|
||||
};
|
||||
|
||||
/* processes an incoming buffer.
|
||||
* `buf`, `kout` and `vout` mustn't overlap, and must be (at least) `len` bytes long!
|
||||
* `kout` and `vout` will contain a null-terminated string if the function returned successfully.
|
||||
* returns `0` on success, `<0` when no data was found. `>0` when data was invalid but something went wrong.
|
||||
* see `CONF_E*` or `enum conf_err` */
|
||||
int conf_procbuf(char const *restrict buf, char *restrict kout, char *restrict vout, size_t len);
|
||||
|
||||
/* matches the key with one of the options and returns the pointer. Returns NULL if none could be found. */
|
||||
struct conf_entry const *conf_matchopt(struct conf_entry const *opts, size_t optc, char const *restrict key);
|
||||
|
||||
/* processes the value belonging to the key and outputs the result to opts.
|
||||
* - `val` points to a null-terminated string which contains the key and value.
|
||||
* returns `0` upon success, non-zero upon failure. For information about specific error codes, see `enum conf_err` */
|
||||
int conf_procval(struct conf_entry const *opts, char const *restrict val);
|
||||
|
||||
/* acquires the config file path, appending str to the end (you need to handle path separators yourself)
|
||||
* expecting str to be null-terminated
|
||||
* - linux: reads $XDG_CONFIG_HOME, if empty $HOME/.config is used, if $HOME is empty NULL is returned.
|
||||
* - windows: reads %APPDATA%, if empty %USERPROFILE%\AppData\Roaming is used, if both are empty NULL is returned.
|
||||
* - osx: reads $HOME, uses $HOME/Library/Application Support, if $HOME is empty NULL is returned.
|
||||
* !! A malloc'd null-terminated string is returned !! */
|
||||
atrb_malloc atrb_nonnull(1) char *conf_getpat(char const *);
|
||||
64
src/util/error.c
Normal file
64
src/util/error.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#include "error.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../types.h"
|
||||
|
||||
static void error_log(FILE *restrict stream, const char *restrict pfx, uint ln, const char *restrict file, const char *restrict fmt, va_list ap)
|
||||
{
|
||||
fprintf(stream, "(%s:%u) [%s] '", file, ln, pfx);
|
||||
vfprintf(stream, fmt, ap);
|
||||
fprintf(stream, "'\n");
|
||||
}
|
||||
|
||||
void error_debug(uint ln, const char *restrict file, const char *restrict fmt, ...)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
#else
|
||||
char *env = getenv("DEBUG");
|
||||
if (env && env[0] != '1')
|
||||
return;
|
||||
#endif
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
error_log(stdout, "\033[95mDBG\033[0m", ln, file, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void error_info(uint ln, const char *restrict file, const char *restrict fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
error_log(stdout, "\033[94mINF\033[0m", ln, file, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void error_warn(uint ln, const char *restrict file, const char *restrict fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
error_log(stdout, "\033[93mWAR\033[0m", ln, file, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void error_error(uint ln, const char *restrict file, const char *restrict fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
error_log(stdout, "\033[91mERR\033[0m", ln, file, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void error_fatal(uint ln, const char *restrict file, const char *restrict fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
error_log(stdout, "\033[101mFAT\033[0m", ln, file, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
22
src/util/error.h
Normal file
22
src/util/error.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../types.h"
|
||||
#include "atrb.h"
|
||||
|
||||
void error_debug(uint ln, const char *restrict file, const char *restrict fmt, ...);
|
||||
void error_info(uint ln, const char *restrict file, const char *restrict fmt, ...);
|
||||
void error_warn(uint ln, const char *restrict file, const char *restrict fmt, ...);
|
||||
void error_error(uint ln, const char *restrict file, const char *restrict fmt, ...);
|
||||
void error_fatal(uint ln, const char *restrict file, const char *restrict fmt, ...) NORET;
|
||||
|
||||
#define debug(...) error_debug(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define info(...) error_info(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define warn(...) error_warn(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define error(...) error_error(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define fatal(...) error_fatal(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
#define WIDTHOF(t) (sizeof(t) * 8) // gets the bit width of a type
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
|
||||
/* variable-width integer types */
|
||||
typedef unsigned int uint; // ≥16 bit unsigned integer
|
||||
typedef unsigned long ulong; // ≥32 bit unsigned integer
|
||||
typedef signed long long llong; // ≥64 bit signed integer
|
||||
typedef unsigned long long ullong; // ≥64 bit unsigned integer
|
||||
|
||||
/* fixed-width integer types */
|
||||
#include <stdint.h>
|
||||
typedef int8_t i8;
|
||||
typedef int16_t i16;
|
||||
typedef int32_t i32;
|
||||
typedef int64_t i64;
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
/* floating point types */
|
||||
typedef float f32; // single-precision floating-point
|
||||
typedef double f64; // double-precision floating-point
|
||||
9
src/util/util.h
Normal file
9
src/util/util.h
Normal file
@@ -0,0 +1,9 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
/* Acquires the next power of two of value `x`.
|
||||
* Automatically determines the type (and therefore the width) of `x`.
|
||||
* Explicitly cast `x` to a desired width, if necessary. */
|
||||
#define bit_ceil(x) (1 << (sizeof(__typeof__(x)) * 8 - __builtin_clzg(((x) - !!(x)) | 1)))
|
||||
21
src/util/vec.h
Normal file
21
src/util/vec.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
#include "../types.h"
|
||||
|
||||
#if defined(__has_attribute) && __has_attribute(vector_size)
|
||||
typedef float fvec2 __attribute__((vector_size(sizeof(float) * 2))); // SMID vector for 2 `float`
|
||||
typedef float fvec4 __attribute__((vector_size(sizeof(float) * 4))); // SMID vector for 4 `float`
|
||||
|
||||
typedef u8 u8vec2 __attribute__((vector_size(sizeof(u8) * 2))); // SMID vector for 2 `u8`
|
||||
typedef u8 u8vec4 __attribute__((vector_size(sizeof(u8) * 4))); // SMID vector for 4 `u8`
|
||||
#else
|
||||
#error the platform is unsupported, attribute vector_size must be available (and so does __has_attribute)
|
||||
#endif
|
||||
|
||||
#define VX 0
|
||||
#define VY 1
|
||||
#define VZ 2
|
||||
#define VW 3
|
||||
@@ -1,69 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "../atrb.h"
|
||||
|
||||
// stores a 2D point using a floating-point number
|
||||
struct float2 {
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
typedef struct float2 float2;
|
||||
|
||||
// adds one float2 to another
|
||||
atrb_const static inline float2 float2_add(float2 v1, float2 v2) {
|
||||
return (float2){v1.x + v2.x, v1.y + v2.y};
|
||||
}
|
||||
|
||||
// subtracts one float2 from another
|
||||
atrb_const static inline float2 float2_sub(float2 v1, float2 v2) {
|
||||
return (float2){v1.x - v2.x, v1.y - v2.y};
|
||||
}
|
||||
|
||||
// multiplies one float2 by another
|
||||
atrb_const static inline float2 float2_mul(float2 v1, float2 v2) {
|
||||
return (float2){v1.x * v2.x, v1.y * v2.y};
|
||||
}
|
||||
|
||||
// divides one float2 by another
|
||||
atrb_const static inline float2 float2_div(float2 v1, float2 v2) {
|
||||
return (float2){v1.x / v2.x, v1.y / v2.y};
|
||||
}
|
||||
|
||||
// preforms a scalar multiplication upon the float2 (multiplies the float2 by some value)
|
||||
atrb_const static inline float2 float2_mul_s(float2 v, float n) {
|
||||
return (float2){v.x * n, v.y * n};
|
||||
}
|
||||
|
||||
// preforms a scalar division upon the float2 (divides the float2 by some value)
|
||||
atrb_const static inline float2 float2_div_s(float2 v, float n) {
|
||||
return (float2){v.x / n, v.y / n};
|
||||
}
|
||||
|
||||
atrb_const static inline float2 float2_neg(float2 v) {
|
||||
return (float2){-v.x, -v.y};
|
||||
}
|
||||
|
||||
// gets the squared magnitude/length of float2
|
||||
atrb_const static inline float float2_mag2(float2 v) {
|
||||
return (v.x * v.x) + (v.y * v.y);
|
||||
}
|
||||
|
||||
// gets the length of float2 (length)
|
||||
atrb_const static inline float float2_mag(float2 v) {
|
||||
return sqrtf(float2_mag2(v));
|
||||
}
|
||||
|
||||
// normalizes the float2
|
||||
atrb_const static inline float2 float2_norm(float2 v) {
|
||||
float s = 1.0F / float2_mag(v); // get the scaling factor
|
||||
return float2_mul_s(v, s); // scale the vector by the scaling factor (slightly more efficient than dividing)
|
||||
}
|
||||
|
||||
// gets the dot product of two float2s
|
||||
atrb_const static inline float float2_dot(float2 v1, float2 v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y;
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "../atrb.h"
|
||||
|
||||
// stores a 3D point using a floating-point number
|
||||
struct float3 {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
typedef struct float3 float3;
|
||||
|
||||
// adds one float3 to another
|
||||
atrb_const static inline float3 float3_add(float3 v1, float3 v2) {
|
||||
return (float3){v1.x + v2.x, v1.y + v2.y, v1.z + v2.z};
|
||||
}
|
||||
|
||||
// subtracts one float3 from another
|
||||
atrb_const static inline float3 float3_sub(float3 v1, float3 v2) {
|
||||
return (float3){v1.x - v2.x, v1.y - v2.y, v1.z - v2.z};
|
||||
}
|
||||
|
||||
// multiplies one float3 by another
|
||||
atrb_const static inline float3 float3_mul(float3 v1, float3 v2) {
|
||||
return (float3){v1.x * v2.x, v1.y * v2.y, v1.z * v2.z};
|
||||
}
|
||||
|
||||
// divides one float3 by another
|
||||
atrb_const static inline float3 float3_div(float3 v1, float3 v2) {
|
||||
return (float3){v1.x / v2.x, v1.y / v2.y, v1.z / v2.z};
|
||||
}
|
||||
|
||||
// preforms a scalar multiplication upon the float3 (multiplies the float3 by some value)
|
||||
atrb_const static inline float3 float3_mul_s(float3 v, float n) {
|
||||
return (float3){v.x * n, v.y * n, v.z * n};
|
||||
}
|
||||
|
||||
// preforms a scalar division upon the float3 (divides the float3 by some value)
|
||||
atrb_const static inline float3 float3_div_s(float3 v, float n) {
|
||||
return (float3){v.x / n, v.y / n, v.z / n};
|
||||
}
|
||||
|
||||
atrb_const static inline float3 float3_neg(float3 v) {
|
||||
return (float3){-v.x, -v.y, -v.z};
|
||||
}
|
||||
|
||||
// gets the squared magnitude/length of float3
|
||||
atrb_const static inline float float3_mag2(float3 v) {
|
||||
return (v.x * v.x) + (v.y * v.y) + (v.z * v.z);
|
||||
}
|
||||
|
||||
// gets the length of float3 (length)
|
||||
atrb_const static inline float float3_mag(float3 v) {
|
||||
return sqrtf(float3_mag2(v));
|
||||
}
|
||||
|
||||
// normalizes the float3
|
||||
atrb_const static inline float3 float3_norm(float3 v) {
|
||||
float s = 1.0F / float3_mag(v); // get the scaling factor
|
||||
return float3_mul_s(v, s); // scale the vector by the scaling factor (slightly more efficient than dividing)
|
||||
}
|
||||
|
||||
// gets the dot product of two float3s
|
||||
atrb_const static inline float float3_dot(float3 v1, float3 v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
|
||||
#include "../atrb.h"
|
||||
|
||||
// stores a 2D point using a floating-point number
|
||||
struct int2 {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
typedef struct int2 int2;
|
||||
|
||||
// adds one int2 to another
|
||||
atrb_const static inline int2 int2_add(int2 v1, int2 v2) {
|
||||
return (int2){v1.x + v2.x, v1.y + v2.y};
|
||||
}
|
||||
|
||||
// subtracts one int2 from another
|
||||
atrb_const static inline int2 int2_sub(int2 v1, int2 v2) {
|
||||
return (int2){v1.x - v2.x, v1.y - v2.y};
|
||||
}
|
||||
|
||||
// multiplies one int2 by another
|
||||
atrb_const static inline int2 int2_mul(int2 v1, int2 v2) {
|
||||
return (int2){v1.x * v2.x, v1.y * v2.y};
|
||||
}
|
||||
|
||||
// divides one int2 by another
|
||||
atrb_const static inline int2 int2_div(int2 v1, int2 v2) {
|
||||
return (int2){v1.x / v2.x, v1.y / v2.y};
|
||||
}
|
||||
|
||||
// preforms a scalar multiplication upon the int2 (multiplies the int2 by some value)
|
||||
atrb_const static inline int2 int2_mul_s(int2 v, float n) {
|
||||
return (int2){v.x * n, v.y * n};
|
||||
}
|
||||
|
||||
// preforms a scalar division upon the int2 (divides the int2 by some value)
|
||||
atrb_const static inline int2 int2_div_s(int2 v, float n) {
|
||||
return (int2){v.x / n, v.y / n};
|
||||
}
|
||||
|
||||
atrb_const static inline int2 int2_neg(int2 v) {
|
||||
return (int2){-v.x, -v.y};
|
||||
}
|
||||
|
||||
// gets the dot product of two int2s
|
||||
atrb_const static inline int int2_dot(int2 v1, int2 v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#pragma once
|
||||
|
||||
#include "../atrb.h"
|
||||
|
||||
// stores a 2D point using a floating-point number
|
||||
struct int4 {
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
int w;
|
||||
};
|
||||
typedef struct int4 int4;
|
||||
|
||||
// adds one int4 to another
|
||||
atrb_const static inline int4 int4_add(int4 v1, int4 v2) {
|
||||
return (int4){v1.x + v2.x, v1.y + v2.y, v1.z - v2.z, v1.w - v2.w};
|
||||
}
|
||||
|
||||
// subtracts one int4 from another
|
||||
atrb_const static inline int4 int4_sub(int4 v1, int4 v2) {
|
||||
return (int4){v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w - v2.w};
|
||||
}
|
||||
|
||||
// multiplies one int4 by another
|
||||
atrb_const static inline int4 int4_mul(int4 v1, int4 v2) {
|
||||
return (int4){v1.x * v2.x, v1.y * v2.y, v1.z * v2.z, v1.w * v2.w};
|
||||
}
|
||||
|
||||
// divides one int4 by another
|
||||
atrb_const static inline int4 int4_div(int4 v1, int4 v2) {
|
||||
return (int4){v1.x / v2.x, v1.y / v2.y, v1.z / v2.z, v1.w / v2.w};
|
||||
}
|
||||
|
||||
// preforms a scalar multiplication upon the int4 (multiplies the int4 by some value)
|
||||
atrb_const static inline int4 int4_mul_s(int4 v, float n) {
|
||||
return (int4){v.x * n, v.y * n, v.z * n, v.w * n};
|
||||
}
|
||||
|
||||
// preforms a scalar division upon the int4 (divides the int4 by some value)
|
||||
atrb_const static inline int4 int4_div_s(int4 v, float n) {
|
||||
return (int4){v.x / n, v.y / n, v.z / n, v.w / n};
|
||||
}
|
||||
|
||||
atrb_const static inline int4 int4_neg(int4 v) {
|
||||
return (int4){-v.x, -v.y, -v.z, v.w};
|
||||
}
|
||||
|
||||
// gets the dot product of two int2s
|
||||
atrb_const static inline int int4_dot(int4 v1, int4 v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
|
||||
}
|
||||
42
test/dat.h
42
test/dat.h
@@ -1,42 +0,0 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../src/util/conf.h"
|
||||
#include "../src/util/types.h"
|
||||
#include "../src/util/vec/float3.h"
|
||||
#include "t_conf.h"
|
||||
#include "t_util.h"
|
||||
#include "test.h"
|
||||
|
||||
testdat tests[] = {
|
||||
{"", test_float3_norm, &(float3){2.0F, 0.67F, 5.0F} },
|
||||
{"", test_float3_norm, &(float3){0.2F, 0.4F, 0.1F} },
|
||||
{"", test_bswap16, (u16[]){0x11EE, 0xEE11} },
|
||||
{"", test_bswap32, (u32[]){0x1142ADEE, 0xEEAD4211} },
|
||||
{"", test_bswap64, (u64[]){0x114266897799ADEE, 0xEEAD997789664211} },
|
||||
{"", test_bswap16_impl, (u16[]){0x11EE, 0xEE11} },
|
||||
{"", test_bswap32_impl, (u32[]){0x1142ADEE, 0xEEAD4211} },
|
||||
{"", test_bswap64_impl, (u64[]){0x114266897799ADEE, 0xEEAD997789664211} },
|
||||
{"k=v", test_procbuf, &(struct test_procbuf){"key=val", "key", "val", 0} },
|
||||
{"sometxt", test_procbuf, &(struct test_procbuf){"sometxt", "sometxt", "", CONF_ESYNTAX} },
|
||||
{"comment", test_procbuf, &(struct test_procbuf){"# comment", "", "", CONF_ENODAT} },
|
||||
{"empty", test_procbuf, &(struct test_procbuf){"", "", "", CONF_ENODAT} },
|
||||
{"LF", test_procbuf, &(struct test_procbuf){"\n", "", "", CONF_ENODAT} },
|
||||
{"CRLF", test_procbuf, &(struct test_procbuf){"\r\n", "", "", CONF_ENODAT} },
|
||||
{"k=v (LF)", test_procbuf, &(struct test_procbuf){"k=v\na", "k", "v", 0} },
|
||||
{"k=v (CRLF)", test_procbuf, &(struct test_procbuf){"k=v\r\na", "k", "v", 0} },
|
||||
{"get", test_matchopt, &(struct test_matchopt){"key3", 2} },
|
||||
{"invalid", test_matchopt, &(struct test_matchopt){"nono", -1} },
|
||||
{"", test_colour32_endianess, NULL }, // NOTE: formatter is fucking with alignment making it use tabs @.@
|
||||
{"i32", test_procval_int, &(struct test_procval_int){"42", 42, CONF_I32} },
|
||||
{"i32_neg", test_procval_int, &(struct test_procval_int){"-42", (u32)-42, CONF_I32} },
|
||||
{"u32_max", test_procval_int, &(struct test_procval_int){"4294967295", UINT32_MAX, CONF_U64} },
|
||||
{"u64", test_procval_int, &(struct test_procval_int){"3141592653589793238", 3141592653589793238, CONF_U64}},
|
||||
{"u8_overflow", test_procval_int, &(struct test_procval_int){"256", 255, CONF_U8} },
|
||||
{"", test_procval_f32, NULL },
|
||||
{"", test_procval_str, NULL },
|
||||
{"", test_procval_str_predef, NULL },
|
||||
{"", test_procval_fstr, NULL },
|
||||
{"", test_procval_fstr_trunc, NULL },
|
||||
{"", test_procval_eparse, NULL },
|
||||
{"", test_getpat, NULL },
|
||||
};
|
||||
60
test/main.c
60
test/main.c
@@ -1,19 +1,55 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include <glad/gl.h>
|
||||
#undef GLAD_GL_IMPLEMENTATION
|
||||
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "dat.h" // contains the test data
|
||||
#include "test.h"
|
||||
#include "test_conf.h"
|
||||
|
||||
int main(void) {
|
||||
// get test count
|
||||
size_t n = sizeof(tests) / sizeof(tests[0]);
|
||||
int main(void)
|
||||
{
|
||||
assert_true(-3 >> 5 == -1); // checking for arithmetic shift, rather than logical shift
|
||||
assert_true(sizeof(u8) == 1);
|
||||
assert_true(sizeof(u16) == 2);
|
||||
assert_true(sizeof(u32) == 4);
|
||||
assert_true(sizeof(u64) == 8);
|
||||
assert_true(sizeof(f32) == 4);
|
||||
assert_true(sizeof(f64) == 8);
|
||||
assert_true(sizeof(usize) == sizeof(size_t));
|
||||
test_conf_procbuf("key=val", "key", "val", 0);
|
||||
test_conf_procbuf("sometxt", "sometxt", "", CONF_ESYNTAX);
|
||||
test_conf_procbuf("# comment", "", "", CONF_ENODAT);
|
||||
test_conf_procbuf("", "", "", CONF_ENODAT);
|
||||
test_conf_procbuf("\n", "", "", CONF_ENODAT);
|
||||
test_conf_procbuf("\r\n", "", "", CONF_ENODAT);
|
||||
test_conf_procbuf("k=v\na", "k", "v", 0);
|
||||
test_conf_procbuf("k=v\r\na", "k", "v", 0);
|
||||
test_conf_getpat();
|
||||
|
||||
return exec_tests(tests, n);
|
||||
struct conf_entry opts[] = {
|
||||
{"key0", NULL, 0},
|
||||
{"key1", NULL, 0},
|
||||
{"key2", NULL, 0}
|
||||
};
|
||||
test_conf_matchopt(opts, 3, "key0", 0);
|
||||
test_conf_matchopt(opts, 3, "key1", 1);
|
||||
test_conf_matchopt(opts, 3, "key2", 2);
|
||||
test_conf_matchopt(opts, 3, "key3", -1);
|
||||
|
||||
test_conf_procval_int("42", 42, CONF_I32);
|
||||
test_conf_procval_int("-42", (u32)-42, CONF_I32);
|
||||
test_conf_procval_int("4294967295", UINT32_MAX, CONF_U32);
|
||||
test_conf_procval_int("9223372036854775807", INT64_MAX, CONF_I64);
|
||||
test_conf_procval_int("256", 255, CONF_U8);
|
||||
|
||||
// TODO: write more tests for float parsing
|
||||
test_conf_procval_f32("0.0", 0.0f);
|
||||
test_conf_procval_f32("3.14159", 3.14159f);
|
||||
test_conf_procval_f32("3.1428571428", 22.0f / 7.0f);
|
||||
test_conf_procval_f32("-5.0", -5.0f);
|
||||
|
||||
/* return 1 if there were failed tests. */
|
||||
printf("test results: (%u/%u)\n", test_okay, test_okay + test_fail);
|
||||
return !!test_fail;
|
||||
}
|
||||
|
||||
205
test/t_conf.h
205
test/t_conf.h
@@ -1,205 +0,0 @@
|
||||
#pragma once
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../src/util/conf.h"
|
||||
#include "../src/util/types.h"
|
||||
#include "test.h"
|
||||
|
||||
// Environment saver structure for conf_getpat tests
|
||||
#if defined(__linux__) || defined(__APPLE__) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
|
||||
struct test_getpat_envdat {
|
||||
char *xdg_config_home;
|
||||
char *home;
|
||||
char *appdata;
|
||||
char *userprofile;
|
||||
};
|
||||
|
||||
/* save the current environment variables */
|
||||
static void env_save(struct test_getpat_envdat *s) {
|
||||
char const *tmp;
|
||||
|
||||
tmp = getenv("XDG_CONFIG_HOME");
|
||||
s->xdg_config_home = tmp ? strdup(tmp) : NULL;
|
||||
|
||||
tmp = getenv("HOME");
|
||||
s->home = tmp ? strdup(tmp) : NULL;
|
||||
|
||||
tmp = getenv("APPDATA");
|
||||
s->appdata = tmp ? strdup(tmp) : NULL;
|
||||
|
||||
tmp = getenv("USERPROFILE");
|
||||
s->userprofile = tmp ? strdup(tmp) : NULL;
|
||||
}
|
||||
|
||||
/* restores the environment variables to what they were before */
|
||||
static void env_restore(struct test_getpat_envdat *s) {
|
||||
#ifdef _WIN32
|
||||
if (s->xdg_config_home) _putenv_s("XDG_CONFIG_HOME", s->xdg_config_home);
|
||||
else _putenv("XDG_CONFIG_HOME=");
|
||||
if (s->home) _putenv_s("HOME", s->home);
|
||||
else _putenv("HOME=");
|
||||
if (s->appdata) _putenv_s("APPDATA", s->appdata);
|
||||
else _putenv("APPDATA=");
|
||||
if (s->userprofile) _putenv_s("USERPROFILE", s->userprofile);
|
||||
else _putenv("USERPROFILE=");
|
||||
#else
|
||||
if (s->xdg_config_home) setenv("XDG_CONFIG_HOME", s->xdg_config_home, 1);
|
||||
else unsetenv("XDG_CONFIG_HOME");
|
||||
if (s->home) setenv("HOME", s->home, 1);
|
||||
else unsetenv("HOME");
|
||||
if (s->appdata) setenv("APPDATA", s->appdata, 1);
|
||||
else unsetenv("APPDATA");
|
||||
if (s->userprofile) setenv("USERPROFILE", s->userprofile, 1);
|
||||
else unsetenv("USERPROFILE");
|
||||
#endif
|
||||
free(s->xdg_config_home);
|
||||
free(s->home);
|
||||
free(s->appdata);
|
||||
free(s->userprofile);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* check procbuf's functionality */
|
||||
struct test_procbuf {
|
||||
char const *in; // data in
|
||||
char const *xkey; // expected key
|
||||
char const *xval; // expected value
|
||||
int xret; // expected return type
|
||||
};
|
||||
int test_procbuf(void *arg) {
|
||||
struct test_procbuf *dat = arg;
|
||||
size_t len = strlen(dat->in) + 1;
|
||||
char k[len], v[len];
|
||||
*k = '\0', *v = '\0';
|
||||
return assert_true(conf_procbuf(dat->in, k, v, len) == dat->xret) ||
|
||||
assert_true(!strcmp(k, dat->xkey)) ||
|
||||
assert_true(!strcmp(v, dat->xval));
|
||||
}
|
||||
|
||||
/* check matchopt functionality */
|
||||
struct test_matchopt {
|
||||
char const *key; // key to search for (key1, key2, key3)
|
||||
int xidx; // expect index (<0 is NULL, may not be more than 2)
|
||||
};
|
||||
int test_matchopt(void *arg) {
|
||||
struct test_matchopt *dat = arg;
|
||||
struct conf_entry opts[] = {
|
||||
{"key1", NULL, 0},
|
||||
{"key2", NULL, 0},
|
||||
{"key3", NULL, 0},
|
||||
};
|
||||
struct conf_entry *xopt = dat->xidx < 0 ? NULL : opts + dat->xidx;
|
||||
return assert_true(conf_matchopt(opts, 3, dat->key) == xopt);
|
||||
}
|
||||
|
||||
struct test_procval_int {
|
||||
char const *val;
|
||||
u64 xres;
|
||||
u8 type;
|
||||
};
|
||||
int test_procval_int(void *arg) {
|
||||
struct test_procval_int *dat = arg;
|
||||
u64 out = 0;
|
||||
return assert_true(!conf_procval(&(struct conf_entry){NULL, &out, dat->type}, dat->val)) ||
|
||||
assert_true(out == dat->xres);
|
||||
}
|
||||
|
||||
int test_procval_f32(void *arg) {
|
||||
(void)arg;
|
||||
f32 out;
|
||||
return assert_true(!conf_procval(&(struct conf_entry){NULL, &out, CONF_F32}, "3.14159265")) ||
|
||||
assert_true(fabsf(out - 3.14159265F) < 1e-6F);
|
||||
}
|
||||
|
||||
int test_procval_str(void *arg) {
|
||||
(void)arg;
|
||||
char *out = NULL;
|
||||
int ret = assert_true(!conf_procval(&(struct conf_entry){NULL, (void *)&out, CONF_STR}, "here comes the sowon")) ||
|
||||
assert_false(strcmp("here comes the sowon", out));
|
||||
free(out);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int test_procval_str_predef(void *arg) {
|
||||
(void)arg;
|
||||
char *out = strdup("owo");
|
||||
int ret = assert_true(!conf_procval(&(struct conf_entry){NULL, (void *)&out, CONF_STR}, "i leak if I don't free")) ||
|
||||
assert_true(!strcmp("i leak if I don't free", out));
|
||||
free(out);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int test_procval_fstr(void *arg) {
|
||||
(void)arg;
|
||||
char buf[16];
|
||||
struct conf_fstr str = {sizeof(buf), buf};
|
||||
return assert_true(!conf_procval(&(struct conf_entry){NULL, &str, CONF_FSTR}, "hewwoo wowld")) ||
|
||||
assert_true(!strcmp(str.out, "hewwoo wowld"));
|
||||
}
|
||||
|
||||
int test_procval_fstr_trunc(void *arg) {
|
||||
(void)arg;
|
||||
char buf[8];
|
||||
struct conf_fstr str = {sizeof(buf), buf};
|
||||
return assert_true(!conf_procval(&(struct conf_entry){NULL, &str, CONF_FSTR}, "hewwooo wowld")) ||
|
||||
assert_true(!strcmp(str.out, "hewwooo"));
|
||||
}
|
||||
|
||||
int test_procval_eparse(void *arg) {
|
||||
(void)arg;
|
||||
i32 out;
|
||||
return assert_true(conf_procval(&(struct conf_entry){NULL, &out, CONF_I32}, "owo") == CONF_EPARSE);
|
||||
}
|
||||
|
||||
/* ensure paths are being set correctly */
|
||||
int test_getpat(void *arg) {
|
||||
(void)arg;
|
||||
struct test_getpat_envdat envs;
|
||||
env_save(&envs);
|
||||
int ret = 0;
|
||||
char *path = NULL;
|
||||
|
||||
#ifdef __linux__
|
||||
setenv("XDG_CONFIG_HOME", "/test/config", 1);
|
||||
path = conf_getpat("/app");
|
||||
ret |= assert_true(path && !strcmp(path, "/test/config/app"));
|
||||
free(path);
|
||||
unsetenv("XDG_CONFIG_HOME");
|
||||
|
||||
setenv("HOME", "/test/home", 1);
|
||||
path = conf_getpat("/app");
|
||||
ret |= assert_true(path && !strcmp(path, "/test/home/.config/app"));
|
||||
free(path);
|
||||
|
||||
unsetenv("HOME");
|
||||
#elif defined(__APPLE__)
|
||||
setenv("HOME", "/test/home", 1);
|
||||
path = conf_getpat("/app");
|
||||
ret |= assert_true(path && !strcmp(path, "/test/home/Library/Application Support/app"));
|
||||
free(path);
|
||||
|
||||
unsetenv("HOME");
|
||||
#elif defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
|
||||
_putenv("APPDATA=C:\\test\\appdata");
|
||||
path = conf_getpat("\\app");
|
||||
ret |= assert_true(path && !strcmp(path, "C:\\test\\appdata\\app"));
|
||||
free(path);
|
||||
|
||||
_putenv("APPDATA=");
|
||||
_putenv("USERPROFILE=C:\\test\\user");
|
||||
path = conf_getpat("\\app");
|
||||
ret |= assert_true(path && !strcmp(path, "C:\\test\\user\\AppData\\Roaming\\app"));
|
||||
free(path);
|
||||
|
||||
_putenv("USERPROFILE=");
|
||||
#endif
|
||||
void *ptr;
|
||||
ret |= assert_true(!(ptr = conf_getpat("anything")));
|
||||
free(ptr);
|
||||
|
||||
env_restore(&envs);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
#pragma once
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../src/util/colour32.h"
|
||||
#include "../src/util/compat/bswap.h"
|
||||
#include "../src/util/types.h"
|
||||
#include "../src/util/vec/float3.h"
|
||||
#include "test.h"
|
||||
|
||||
int test_float3_norm(void *d) {
|
||||
float *arg = d;
|
||||
float3 v = {arg[0], arg[1], arg[2]};
|
||||
float3 r = float3_norm(v);
|
||||
float n = r.x * r.x + r.y * r.y + r.z * r.z;
|
||||
|
||||
// check if the value is within 1 millionth of the one we expect
|
||||
return assert_true(fabsf(n - 1.0F) < 1e-6F);
|
||||
}
|
||||
|
||||
int test_colour32_endianess(void *d) {
|
||||
(void)d;
|
||||
colour32 c = {0xFF000000}; // setting just the red channel
|
||||
return assert_true(c.ch.r == 0xFF);
|
||||
}
|
||||
|
||||
int test_bswap16(void *d) {
|
||||
u16 *arg = d;
|
||||
return assert_true(bswap16(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap32(void *d) {
|
||||
u32 *arg = d;
|
||||
return assert_true(bswap32(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap64(void *d) {
|
||||
u64 *arg = d;
|
||||
return assert_true(bswap64(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap16_impl(void *d) {
|
||||
u16 *arg = d;
|
||||
return assert_true(bswap16_impl(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap32_impl(void *d) {
|
||||
u32 *arg = d;
|
||||
return assert_true(bswap32_impl(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap64_impl(void *d) {
|
||||
u64 *arg = d;
|
||||
return assert_true(bswap64_impl(arg[0]) == arg[1]);
|
||||
}
|
||||
21
test/test.c
Normal file
21
test/test.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#include "test.h"
|
||||
|
||||
#include "../src/types.h"
|
||||
|
||||
uint test_okay = 0;
|
||||
uint test_fail = 0;
|
||||
|
||||
int test_process(int res, const char *restrict file, uint ln, const char *restrict function, const char *restrict expression)
|
||||
{
|
||||
const char *status = res ?
|
||||
"[\033[32;1m OK \033[0m]" :
|
||||
"[\033[31;1m FAIL \033[0m]";
|
||||
test_okay += !!res;
|
||||
test_fail += !res;
|
||||
|
||||
printf("%s\t%s:%u-%s\t-> %s\n", status, file, ln, function, expression);
|
||||
return res;
|
||||
}
|
||||
53
test/test.h
53
test/test.h
@@ -1,48 +1,17 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
|
||||
char const *test_ctest;
|
||||
size_t test_runs = 0;
|
||||
#include "../src/types.h"
|
||||
|
||||
// evaluates the test
|
||||
// returns 1 upon error
|
||||
static inline int assert_helper(int cond, char const *restrict fname, unsigned ln, char const *restrict fnname, char const *restrict expr) {
|
||||
test_runs++;
|
||||
if (cond)
|
||||
printf("[\033[32;1m OK \033[0m] %s %s -> %s:%u (%s)\n", test_ctest, fnname, fname, ln, expr);
|
||||
else
|
||||
printf("[\033[31;1m FAIL \033[0m] %s %s -> %s:%u (%s)\n", test_ctest, fnname, fname, ln, expr);
|
||||
return !cond;
|
||||
}
|
||||
extern uint test_okay;
|
||||
extern uint test_fail;
|
||||
|
||||
#define assert_true(expr) assert_helper(!!(expr), __FILE__, __LINE__, __func__, #expr) // evaluation expected to be true
|
||||
#define assert_false(expr) assert_helper(!(expr), __FILE__, __LINE__, __func__, #expr) // evaluation expected to be false
|
||||
/* Prints the result `res` of a test.
|
||||
* Returns `res` back, for ease of chaining. */
|
||||
int test_process(int res, const char *restrict file, uint ln, const char *restrict function, const char *restrict expression);
|
||||
|
||||
// contains the data for executing a single test
|
||||
struct testdat {
|
||||
char const *name; // test name
|
||||
int (*test)(void *); // test, returns 0 upon success, non-zero upon failure
|
||||
void *args; // arguments to the test
|
||||
};
|
||||
typedef struct testdat testdat;
|
||||
|
||||
// executes the tests, returns the amount of failed tests; >0: failure
|
||||
static inline size_t exec_tests(testdat *dat, size_t ntests) {
|
||||
size_t i;
|
||||
size_t err = 0;
|
||||
|
||||
// perform tests and count the error state
|
||||
for (i = 0; i < ntests; i++) {
|
||||
test_ctest = dat[i].name;
|
||||
err += !!(dat[i].test(dat[i].args));
|
||||
}
|
||||
|
||||
// give final score
|
||||
if (!err)
|
||||
fprintf(stdout, "tests completed! (%zu/%zu)\n", test_runs - err, test_runs);
|
||||
else
|
||||
fprintf(stderr, " tests failed! (%zu/%zu)\n", test_runs - err, test_runs);
|
||||
return err;
|
||||
}
|
||||
#define assert_true(expr) test_process((expr), __FILE__, __LINE__, __func__, #expr)
|
||||
#define assert_false(expr) assert_true(!(expr))
|
||||
|
||||
142
test/test_conf.c
Normal file
142
test/test_conf.c
Normal file
@@ -0,0 +1,142 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#include "test_conf.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../src/types.h"
|
||||
#include "../src/util/conf.h"
|
||||
#include "test.h"
|
||||
|
||||
void test_conf_procbuf(const char *restrict buf, const char *restrict expect_key, const char *restrict expect_val, int expect_return)
|
||||
{
|
||||
usize len = strlen(buf) + 1;
|
||||
char k[len], v[len];
|
||||
*k = '\0', *v = '\0';
|
||||
(void)(assert_true(conf_procbuf(buf, k, v, len) == expect_return) &&
|
||||
assert_true(!strcmp(k, expect_key)) &&
|
||||
assert_true(!strcmp(v, expect_val)));
|
||||
}
|
||||
|
||||
void test_conf_matchopt(struct conf_entry *opts, usize optc, const char *restrict key, int expect_index)
|
||||
{
|
||||
usize idx = opts - conf_matchopt(opts, optc, key);
|
||||
idx = (ssize)idx < 0 ? -idx : idx;
|
||||
int i = idx < optc ? (int)idx : -1;
|
||||
assert_true(i == expect_index);
|
||||
}
|
||||
|
||||
void test_conf_procval_int(const char *val, u64 expect_value, int type)
|
||||
{
|
||||
u8 out[sizeof(u64)] = {0};
|
||||
assert_true(!conf_procval(&(struct conf_entry){NULL, out, type}, val));
|
||||
assert_true(memcmp(out, &expect_value, sizeof(u64)) == 0);
|
||||
}
|
||||
|
||||
void test_conf_procval_f32(const char *val, f32 expect_value)
|
||||
{
|
||||
u8 out[4];
|
||||
f32 result;
|
||||
conf_procval(&(struct conf_entry){NULL, out, CONF_F32}, val);
|
||||
memcpy(&result, out, 4);
|
||||
assert_true(fabsf(expect_value - result) < 1e-9f);
|
||||
}
|
||||
|
||||
void test_procval_str(void)
|
||||
{
|
||||
char *out = NULL;
|
||||
(void)(assert_true(!conf_procval(&(struct conf_entry){NULL, (void *)&out, CONF_STR}, "here comes the sowon")) &&
|
||||
assert_false(strcmp("here comes the sowon", out)));
|
||||
free(out);
|
||||
}
|
||||
|
||||
void test_procval_str_predef(void)
|
||||
{
|
||||
char *out = strdup("owo");
|
||||
(void)(assert_true(!conf_procval(&(struct conf_entry){NULL, (void *)&out, CONF_STR}, "i leak if I don't free")) &&
|
||||
assert_true(!strcmp("i leak if I don't free", out)));
|
||||
free(out);
|
||||
}
|
||||
|
||||
void test_procval_fstr(void)
|
||||
{
|
||||
char buf[16];
|
||||
struct conf_fstr str = {sizeof(buf), buf};
|
||||
(void)(assert_true(!conf_procval(&(struct conf_entry){NULL, &str, CONF_FSTR}, "hewwoo wowld")) &&
|
||||
assert_true(!strcmp(str.out, "hewwoo wowld")));
|
||||
}
|
||||
|
||||
void test_procval_fstr_trunc(void)
|
||||
{
|
||||
char buf[8];
|
||||
struct conf_fstr str = {sizeof(buf), buf};
|
||||
(void)(assert_true(!conf_procval(&(struct conf_entry){NULL, &str, CONF_FSTR}, "hewwooo wowld")) &&
|
||||
assert_true(!strcmp(str.out, "hewwooo")));
|
||||
}
|
||||
|
||||
void test_procval_eparse(void)
|
||||
{
|
||||
i32 out;
|
||||
assert_true(conf_procval(&(struct conf_entry){NULL, &out, CONF_I32}, "owo") == CONF_EPARSE);
|
||||
}
|
||||
|
||||
void test_conf_getpat(void)
|
||||
{
|
||||
char *path;
|
||||
#if defined(__linux__)
|
||||
/* test without setting environment variables. */
|
||||
unsetenv("XDG_CONFIG_HOME");
|
||||
unsetenv("HOME");
|
||||
path = conf_getpat("/mypath");
|
||||
assert_true(path == NULL);
|
||||
free(path);
|
||||
|
||||
/* test with setting HOME. */
|
||||
setenv("HOME", "/home/test", 1);
|
||||
path = conf_getpat("/mypath");
|
||||
assert_true(path != NULL && strcmp(path, "/home/test/.config/mypath") == 0);
|
||||
free(path);
|
||||
conf_getpat("/mypath");
|
||||
|
||||
/* test with setting XDG_CONFIG_HOME. */
|
||||
setenv("XDG_CONFIG_HOME", "/etc/xdg", 1);
|
||||
path = conf_getpat("/mypath");
|
||||
assert_true(path != NULL && strcmp(path, "/etc/xdg/mypath") == 0);
|
||||
free(path);
|
||||
#elif defined(__APPLE__)
|
||||
/* test without setting environment variables. */
|
||||
unsetenv("HOME");
|
||||
path = conf_getpat("/mypath");
|
||||
assert_true(path == NULL);
|
||||
free(path);
|
||||
|
||||
/* test with setting HOME. */
|
||||
setenv("HOME", "/home/test", 1);
|
||||
path = conf_getpat("/mypath");
|
||||
assert_true(path != NULL && strcmp(path, "/home/test/Library/Application Support/mypath") == 0);
|
||||
free(path);
|
||||
#elif defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
|
||||
/* test without setting environment variables. */
|
||||
_putenv("APPDATA=");
|
||||
_putenv("USERPROFILE=");
|
||||
path = conf_getpat("\\mypath");
|
||||
assert_true(path == NULL);
|
||||
free(path);
|
||||
|
||||
/* test with setting USERPROFILE */
|
||||
_putenv("USERPROFILE=C:\\Users\\test");
|
||||
path = conf_getpat("\\mypath");
|
||||
assert_true(path != NULL && strcmp(path, "C:\\Users\\test\\AppData\\Roaming\\mypath") == 0);
|
||||
free(path);
|
||||
|
||||
/* test with setting APPDATA */
|
||||
_putenv("APPDATA=C:\\Users\\test\\AppData\\Roaming");
|
||||
path = conf_getpat("\\mypath");
|
||||
assert_true(path != NULL && strcmp(path, "C:\\Users\\test\\AppData\\Roaming\\mypath") == 0);
|
||||
free(path);
|
||||
#else
|
||||
assert_fail("unsupported operating system; no tests have been written.");
|
||||
#endif
|
||||
}
|
||||
20
test/test_conf.h
Normal file
20
test/test_conf.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/* Copyright (c) 2025 Quinn.
|
||||
* This is a file from the project MCA-Selector-Lite and is
|
||||
* licensed under the MIT Licence. See the project's LICENSE file for details. */
|
||||
#pragma once
|
||||
|
||||
#include "../src/types.h"
|
||||
#include "../src/util/conf.h"
|
||||
|
||||
void test_conf_procbuf(const char *restrict buf, const char *restrict expect_key, const char *restrict expect_val, int expect_return);
|
||||
void test_conf_matchopt(struct conf_entry *restrict opts, usize optc, const char *restrict key, int expect_index);
|
||||
void test_conf_procval_int(const char *val, u64 expect_value, int type);
|
||||
void test_conf_procval_f32(const char *val, f32 expect_value);
|
||||
void test_conf_procval_fstr(const char *val, u64 expect_value, int type);
|
||||
void test_conf_procval_str(const char *val, u64 expect_value, int type);
|
||||
void test_procval_str(void);
|
||||
void test_procval_str_predef(void);
|
||||
void test_procval_fstr(void);
|
||||
void test_procval_fstr_trunc(void);
|
||||
void test_procval_eparse(void);
|
||||
void test_conf_getpat(void);
|
||||
Reference in New Issue
Block a user