Rendering context, wasm platform layer and win32 platform layer work

This commit is contained in:
PS 2022-03-27 12:47:18 +02:00
parent 56518bdd66
commit 7925279d59
52 changed files with 39188 additions and 574 deletions

View File

@ -1,294 +1,2 @@
#!/bin/bash
# --------------------------------------------
# Usage
print_usage () {
echo
echo Build Command Syntax:
echo " $0 [mode] [platform] [arch]"
echo
echo "Release Mode Options:"
echo " debug"
echo " prod"
echo
echo "Platform Options:"
echo " win32"
echo " osx"
echo " webgl"
echo
echo "Arch Options: (architecture)"
echo " intel (valid with Platform Win32 and OSX) (default)"
echo " arm64 (only valid for Platform OSX)"
}
# --------------------------------------------
# Arguments
MODE=$1
PLATFORM=$2
ARCH=$3
PACKAGE=$4
if [ "${MODE}" == "" ] | [ "${PLATFORM}" == "" ]
then
print_usage
exit 0
fi
# Default to Intel architecture if none provided
if [ "${ARCH}" == "" ]
then
ARCH="intel"
fi
if [ "${ARCH}" != "intel" ] && [ "${ARCH}" != "arm64" ]
then
echo "Uknown target architecture: ${ARCH}"
print_usage
exit 0
fi
# --------------------------------------------
# Utilities
pushdir () {
command pushd "$@" > /dev/null
}
popdir () {
command popd "$@" > /dev/null
}
# --------------------------------------------
# Getting Project Path
#
# Project is stored in PROJECT_PATH
SCRIPT_REL_DIR=$(dirname "${BASH_SOURCE[0]}")
pushdir $SCRIPT_REL_DIR
pushdir ..
PROJECT_PATH=$(pwd)
popdir
popdir
# --------------------------------------------
# Platform/Mode Specific Variables
# Compiler Selection
Compiler_win32="cl"
Compiler_osx="clang++"
WasiSdk="/c/drive/apps/wasi-sdk"
Compiler_webgl="$WasiSdk/bin/clang++"
Compiler_linux="clang++"
# Platform Entry Points
PlatformEntry_win32="src_v2/platform/win32/lumenarium_first_win32.cpp"
PlatformEntry_osx="src_v2/platform/osx/lumenarium_first_osx.cpp"
PlatformEntry_webgl="src_v2/platform/webgl/lumenarium_first_webgl.cpp"
PlatformEntry_linux="src_v2/platform/linux/lumenarium_first_linux.cpp"
# Intermediate Outputs
CompilerOutput_win32="lumenarium.o"
CompilerOutput_osx="lumenarium"
CompilerOutput_webgl="lumenarium.wasm"
CompilerOutput_linux=""
# Executables
LinkerOutput_win32="lumenarium.exe"
LinkerOutput_osx="lumenarium"
LinkerOutput_webgl="lumenarium.wasm"
LinkerOutput_linux=""
# Wasm Sys Root
WasmSysRoot="${PROJECT_PATH}/src_v2/platform/webgl/sysroot/"
# Compiler Flags
CompilerFlags_win32="-nologo -FC -WX -W4 -Z7 -Oi -MTd -fp:fast"
CompilerFlags_win32="$CompilerFlags_win32 -wd4505 -wd4100 -wd4189"
CompilerFlags_osx=""
CompilerFlags_webgl="-target wasm32 --sysroot ${WasmSysRoot} -s -fvisibility=hidden -fno-builtin -fno-exceptions -fno-threadsafe-statics"
# CompilerFlags_webgl="-nostartfiles -fno-exceptions -fno-entry -strip-all -s -import-memory -fvisibility=hidden --sysroot ${WasmSysRoot}"
CompilerFlags_linux=""
CompilerFlags_DEBUG_win32="-Od -Zi -DDEBUG"
CompilerFlags_DEBUG="-O0 -g -DDEBUG"
CompilerFlags_PROD="-O3"
# Compiler flags that no matter what, we want to define
# for the most part these pass the build parameters into the executable
CompilerFlags_common="-DPLATFORM=${PLATFORM} -DMODE=${MODE} -DARCH=${ARCH}"
# Linker Flags
LinkerFlags_win32="-NOLOGO -incremental:no -subsystem:windows -entry:WinMain -opt:ref"
LinkerFlags_osx=""
# LinkerFlags_webgl="--no-entry --export-dynamic -allow-undefined -import-memory -export=__wasm_call_ctors -export=malloc -export=free -export=main"
LinkerFlags_webgl="--no-entry --export-dynamic --unresolved-symbols=import-functions"
LinkerFlags_linux=""
LinkerFlags_DEBUG="-debug"
LinkerFlags_PROD=""
# Linker Libs
LinkerLibs_win32="user32.lib kernel32.lib gdi32.lib opengl32.lib"
# winmm.lib gdi32.lib dsound.lib Ws2_32.lib Comdlg32.lib Winspool.lib"
LinkerLibs_osx="-framework OpenGL -framework Cocoa"
LinkerLibs_webgl=""
LinkerLibs_linux=""
# --------------------------------------------
# Varible Selection
# Select Platform Variables
if [ "${PLATFORM}" == "win32" ]
then
Compiler=$Compiler_win32
PlatformEntry=$PlatformEntry_win32
CompilerFlags=$CompilerFlags_win32
CompilerOutput=$CompilerOutput_win32
LinkerOutput=$LinkerOutput_win32
LinkerFlags=$LinkerFlags_win32
LinkerLibs=$LinkerLibs_win32
elif [ "${PLATFORM}" == "osx" ]
then
Compiler=$Compiler_osx
PlatformEntry=$PlatformEntry_osx
CompilerFlags=$CompilerFlags_osx
CompilerOutput=$CompilerOutput_osx
LinkerOutput=$LinkerOutput_osx
LinkerFlags=$LinkerFlags_osx
LinkerLibs=$LinkerLibs_osx
elif [ "${PLATFORM}" == "webgl" ]
then
Compiler=$Compiler_webgl
PlatformEntry=$PlatformEntry_webgl
CompilerFlags=$CompilerFlags_webgl
CompilerOutput=$CompilerOutput_webgl
LinkerOutput=$LinkerOutput_webgl
LinkerFlags=$LinkerFlags_webgl
LinkerLibs=$LinkerLibs_webgl
elif [ "${PLATFORM}" == "linux" ]
then
Compiler=$Compiler_linux
PlatformEntry=$PlatformEntry_linux
CompilerFlags=$CompilerFlags_linux
CompilerOutput=$CompilerOutput_linux
LinkerOutput=$LinkerOutput_linux
LinkerFlags=$LinkerFlags_linux
LinkerLibs=$LinkerLibs_linux
else
echo "Attempting to build for an unknown platform: ${PLATFORM}"
print_usage
exit 0
fi
# Select Release Mode Variables
if [ "${MODE}" == "debug" ]
then
if [ $PLATFORM == "win32" ]
then
CompilerFlags="${CompilerFlags} ${CompilerFlags_DEBUG_win32}"
else
CompilerFlags="${CompilerFlags} ${CompilerFlags_DEBUG}"
fi
LinkerFlags="${LinkerFlags} ${LinkerFlags_DEBUG}"
elif [ "${MODE}" == "prod" ]
then
CompilerFlags="${CompilerFlags} ${CompilerFlags_PROD}"
LinkerFlags="${LinkerFlags} ${LinkerFlags_PROD}"
else
echo "Attempting to build for an unknown release mode: ${MODE}"
print_usage
exit 0
fi
# Common Flags
CompilerFlags="${CompilerFlags} ${CompilerFlags_common}"
# --------------------------------------------
# Build Path Construction
#
# This determines where the generated executable will
# be located. In general, it can be found at
# project_path/run_tree/platform/arch/release_mode/lumenarium.exe
#
# This section also ensures that the path requested actually exists
BuildDir="${PROJECT_PATH}/run_tree/${PLATFORM}/${ARCH}/${MODE}"
EntryPath="${PROJECT_PATH}/${PlatformEntry}"
# Exception for webgl, which doesn't care about cpu architecture
if [ $PLATFORM == "webgl" ]
then
BuildDir="${PROJECT_PATH}/run_tree/${PLATFORM}/${MODE}"
fi
# Make the build directory,
# "-p" flag makes it make the entire tree, and not emit errors if it
# exists.
mkdir -p "${BuildDir}"
# --------------------------------------------
# Compilation
echo "Building To: ${BuildDir}/${LinkerOutput}"
echo
pushdir $BuildDir
rm ${CompilerOutput} 2> /dev/null
rm ${LinkerOutput} 2> /dev/null
echo "COMPILING..."
if [ $PLATFORM == "win32" ]
then
$Compiler $CompilerFlags $EntryPath \
-link $LinkerFlags $LinkerLibs -OUT:${LinkerOutput}
elif [ $PLATFORM == "webgl" ]
then
LD="$WasiSdk/bin/wasm-ld"
echo $Compiler
CFlags="-O3 -flto --target=wasm32-unknown-wasi"
LDFlags="--no-entry --export-dynamic --allow-undefined --lto-O3 --import-memory"
$Compiler \
-Wno-writable-strings \
--target=wasm32 \
-nostdlib \
-Wl,--export-all \
-Wl,--no-entry \
-Wl,--allow-undefined \
-o lumenarium.wasm \
$EntryPath \
else
$Compiler -o $LinkerOutput $CompilerFlags $EntryPath $LinkerLibs
fi
echo "Finished..."
popdir
$SCRIPT_REL_DIR/build_.sh debug win32 intel

326
build/build_.sh Normal file
View File

@ -0,0 +1,326 @@
#!/bin/bash
# --------------------------------------------
# Usage
print_usage () {
echo
echo Build Command Syntax:
echo " $0 [mode] [platform] [arch]"
echo
echo "Release Mode Options:"
echo " debug"
echo " prod"
echo
echo "Platform Options:"
echo " win32"
echo " osx"
echo " wasm"
echo
echo "Arch Options: (architecture)"
echo " intel (valid with Platform Win32 and OSX) (default)"
echo " arm64 (only valid for Platform OSX)"
}
# --------------------------------------------
# Arguments
MODE=$1
PLATFORM=$2
ARCH=$3
PACKAGE=$4
if [ "${MODE}" == "" ] | [ "${PLATFORM}" == "" ]
then
print_usage
exit 0
fi
# Default to Intel architecture if none provided
if [ "${ARCH}" == "" ]
then
ARCH="intel"
fi
if [ "${ARCH}" != "intel" ] && [ "${ARCH}" != "arm64" ]
then
echo "Uknown target architecture: ${ARCH}"
print_usage
exit 0
fi
# --------------------------------------------
# Utilities
pushdir () {
command pushd "$@" > /dev/null
}
popdir () {
command popd "$@" > /dev/null
}
add_flag () {
local -n ref=$1
ref="$ref $2"
}
# --------------------------------------------
# Getting Project Path
#
# Project is stored in PROJECT_PATH
SCRIPT_REL_DIR=$(dirname "${BASH_SOURCE[0]}")
pushdir $SCRIPT_REL_DIR
pushdir ..
PROJECT_PATH=$(pwd)
popdir
popdir
# --------------------------------------------
# Platform/Mode Specific Variables
# Compiler Selection
Compiler_win32="cl"
Compiler_osx="clang++"
WasiSdk="/c/drive/apps/wasi-sdk"
Compiler_wasm="$WasiSdk/bin/clang++"
Compiler_linux="clang++"
# Platform Entry Points
PlatformEntry_win32="src_v2/platform/win32/lumenarium_first_win32.cpp"
PlatformEntry_osx="src_v2/platform/osx/lumenarium_first_osx.cpp"
PlatformEntry_wasm="src_v2/platform/wasm/lumenarium_first_wasm.cpp"
PlatformEntry_linux="src_v2/platform/linux/lumenarium_first_linux.cpp"
# Intermediate Outputs
CompilerOutput_win32="lumenarium.o"
CompilerOutput_osx="lumenarium"
CompilerOutput_wasm="lumenarium.wasm"
CompilerOutput_linux=""
# Executables
LinkerOutput_win32="lumenarium.exe"
LinkerOutput_osx="lumenarium"
LinkerOutput_wasm="lumenarium.wasm"
LinkerOutput_linux=""
# Wasm Sys Root
WasmSysRoot="${PROJECT_PATH}/src_v2/platform/wasm/sysroot/"
# Compiler Flags
CompilerFlags_win32="-nologo"
add_flag CompilerFlags_win32 "-FC" # display errors with full path
add_flag CompilerFlags_win32 "-WX" # treat warnings as errors
add_flag CompilerFlags_win32 "-W4" # output warning level
add_flag CompilerFlags_win32 "-Z7" # generate C compatible debug info
# add_flag CompilerFlags_win32 "-Oi" # generate intrinsic functions
# add_flag CompilerFlags_win32 "-MTd" # create a debug multithreaded exe w/ Libcmtd.lib
# add_flag CompilerFlags_win32 "-fp:fast" # fast floating point model
add_flag CompilerFlags_win32 "-wd4505" #
add_flag CompilerFlags_win32 "-wd4100" #
add_flag CompilerFlags_win32 "-wd4189" #
add_flag CompilerFlags_win32 "-wd4702" #
CompilerFlags_osx=""
CompilerFlags_wasm=""
add_flag CompilerFlags_wasm "-Wno-writable-strings" #
add_flag CompilerFlags_wasm "--target=wasm32" #
add_flag CompilerFlags_wasm "-nostdlib" #
add_flag CompilerFlags_wasm "-Wl,--no-entry" #
add_flag CompilerFlags_wasm "-Wl,--allow-undefined" #
add_flag CompilerFlags_wasm "-Wl,--export-all" #
CompilerFlags_linux=""
CompilerFlags_DEBUG_win32=""
add_flag CompilerFlags_DEBUG_win32 "-Od" #
add_flag CompilerFlags_DEBUG_win32 "-Zi" #
add_flag CompilerFlags_DEBUG_win32 "-DDEBUG" #
CompilerFlags_DEBUG="-O0"
add_flag CompilerFlags_DEBUG "-g" #
add_flag CompilerFlags_DEBUG "-DDEBUG" #
CompilerFlags_PROD="-O3"
# Compiler flags that no matter what, we want to define
# for the most part these pass the build parameters into the executable
CompilerFlags_common="-DPLATFORM_${PLATFORM}=1 -DMODE_${MODE}=1 -DARCH_${ARCH}=1"
# Linker Flags
LinkerFlags_win32="-NOLOGO"
add_flag LinkerFlags_win32 "-incremental:no" #
add_flag LinkerFlags_win32 "-subsystem:windows" #
# add_flag LinkerFlags_win32 "-entry:WinMain" #
add_flag LinkerFlags_win32 "-opt:ref" # eliminate functions that are never referenced
LinkerFlags_osx=""
LinkerFlags_wasm="--no-entry"
add_flag LinkerFlags_wasm "--export-dynamic" #
add_flag LinkerFlags_wasm "--unresolved-symbols=import-functions" #
LinkerFlags_linux=""
LinkerFlags_DEBUG="-debug"
LinkerFlags_PROD=""
# Linker Libs
LinkerLibs_win32="user32.lib kernel32.lib gdi32.lib opengl32.lib"
# winmm.lib gdi32.lib dsound.lib Ws2_32.lib Comdlg32.lib Winspool.lib"
LinkerLibs_osx="-framework OpenGL -framework Cocoa"
LinkerLibs_wasm=""
LinkerLibs_linux=""
# --------------------------------------------
# Varible Selection
# Select Platform Variables
if [ "${PLATFORM}" == "win32" ]
then
Compiler=$Compiler_win32
PlatformEntry=$PlatformEntry_win32
CompilerFlags=$CompilerFlags_win32
CompilerOutput=$CompilerOutput_win32
LinkerOutput=$LinkerOutput_win32
LinkerFlags=$LinkerFlags_win32
LinkerLibs=$LinkerLibs_win32
elif [ "${PLATFORM}" == "osx" ]
then
Compiler=$Compiler_osx
PlatformEntry=$PlatformEntry_osx
CompilerFlags=$CompilerFlags_osx
CompilerOutput=$CompilerOutput_osx
LinkerOutput=$LinkerOutput_osx
LinkerFlags=$LinkerFlags_osx
LinkerLibs=$LinkerLibs_osx
elif [ "${PLATFORM}" == "wasm" ]
then
Compiler=$Compiler_wasm
PlatformEntry=$PlatformEntry_wasm
CompilerFlags=$CompilerFlags_wasm
CompilerOutput=$CompilerOutput_wasm
LinkerOutput=$LinkerOutput_wasm
LinkerFlags=$LinkerFlags_wasm
LinkerLibs=$LinkerLibs_wasm
elif [ "${PLATFORM}" == "linux" ]
then
Compiler=$Compiler_linux
PlatformEntry=$PlatformEntry_linux
CompilerFlags=$CompilerFlags_linux
CompilerOutput=$CompilerOutput_linux
LinkerOutput=$LinkerOutput_linux
LinkerFlags=$LinkerFlags_linux
LinkerLibs=$LinkerLibs_linux
else
echo "Attempting to build for an unknown platform: ${PLATFORM}"
print_usage
exit 0
fi
# Select Release Mode Variables
if [ "${MODE}" == "debug" ]
then
if [ $PLATFORM == "win32" ]
then
CompilerFlags="${CompilerFlags} ${CompilerFlags_DEBUG_win32}"
else
CompilerFlags="${CompilerFlags} ${CompilerFlags_DEBUG}"
fi
LinkerFlags="${LinkerFlags} ${LinkerFlags_DEBUG}"
elif [ "${MODE}" == "prod" ]
then
CompilerFlags="${CompilerFlags} ${CompilerFlags_PROD}"
LinkerFlags="${LinkerFlags} ${LinkerFlags_PROD}"
else
echo "Attempting to build for an unknown release mode: ${MODE}"
print_usage
exit 0
fi
# Common Flags
CompilerFlags="${CompilerFlags} ${CompilerFlags_common}"
# --------------------------------------------
# Build Path Construction
#
# This determines where the generated executable will
# be located. In general, it can be found at
# project_path/run_tree/platform/arch/release_mode/lumenarium.exe
#
# This section also ensures that the path requested actually exists
BuildDir="${PROJECT_PATH}/run_tree/${PLATFORM}/${ARCH}/${MODE}"
EntryPath="${PROJECT_PATH}/${PlatformEntry}"
# Exception for wasm, which doesn't care about cpu architecture
if [ $PLATFORM == "wasm" ]
then
BuildDir="${PROJECT_PATH}/run_tree/${PLATFORM}/${MODE}"
fi
# Make the build directory,
# "-p" flag makes it make the entire tree, and not emit errors if it
# exists.
mkdir -p "${BuildDir}"
# --------------------------------------------
# Compilation
echo "Building To: ${BuildDir}/${LinkerOutput}"
echo
pushdir $BuildDir
rm ${CompilerOutput} 2> /dev/null
rm ${LinkerOutput} 2> /dev/null
echo "COMPILING..."
if [ $PLATFORM == "win32" ]
then
$Compiler \
$CompilerFlags \
$EntryPath \
-link \
$LinkerFlags \
$LinkerLibs \
-OUT:${LinkerOutput}
elif [ $PLATFORM == "wasm" ]
then
$Compiler \
$CompilerFlags \
-o $LinkerOutput \
$EntryPath
cp \
"${PROJECT_PATH}/src_v2/platform/wasm/lumenarium_wasm_imports.js" \
./lumenarium_wasm_imports.js
else
$Compiler -o $LinkerOutput $CompilerFlags $EntryPath $LinkerLibs
fi
echo "Finished..."
popdir

View File

@ -1,6 +1,7 @@
version(1);
project_name = "main.exe";
patterns = {
"*.js",
"*.c",
"*.cpp",
"*.h",
@ -13,6 +14,8 @@ blacklist_patterns = {
".*",
};
load_paths_base = {
{ ".", .relative = true, .recursive = false, },
{ "build", .relative = true, .recursive = false, },
{ "src", .relative = true, .recursive = true, },
{ "src_v2", .relative = true, .recursive = true, },
{ "meta", .relative = true, .recursive = true, },
@ -23,7 +26,7 @@ load_paths = {
{ load_paths_base, .os = "linux", },
{ load_paths_base, .os = "mac", },
};
enable_virtual_whitespace=true;
enable_virtual_whitespace = true;
command_list = {
{ .name = "build_application",
@ -38,7 +41,7 @@ command_list = {
{ "./build_meta.sh", .os = "mac" }, }, },
{ .name = "build_v2",
.out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
.cmd = { { "bash build\build.sh debug win32 intel" , .os = "win" },
.cmd = { { "bash build\build.sh" , .os = "win" },
{ "./build_meta.sh", .os = "linux" },
{ "./build_meta.sh", .os = "mac" }, }, },
};

View File

@ -4,6 +4,9 @@
<meta charset="utf-8" />
</head>
<body>
<canvas id="gl_canvas" width="640" height="480"></canvas>
<script type="text/javascript" src="lumenarium_wasm_imports.js"></script>
<script type="text/javascript" src="loader.js"></script>
</body>
</html>

View File

@ -0,0 +1,39 @@
let module = null;
let instance = null;
async function load_webassembly_module ()
{
lumenarium_wasm_imports = webgl_add_imports("#gl_canvas", lumenarium_wasm_imports);
const path = "lumenarium.wasm";
const promise = fetch(path);
const module = await WebAssembly.compileStreaming(promise);
let memory = new WebAssembly.Memory({ initial: 2 });
const env = {
memory,
...lumenarium_wasm_imports,
};
let table = new WebAssembly.Table({ element: "anyfunc", initial: 32, });
instance = await WebAssembly.instantiate(module, { env })
.then((res, err) => {
return res;
})
.catch((a, b) => {
console.log(a,b);
});
lumenarium_wasm_instance = instance;
// If function '__wasm_call_ctors' (global C++ constructors) exists, call it
if (instance.exports.__wasm_call_ctors) instance.exports.__wasm_call_ctors();
// If function 'main' exists, call it with dummy arguments
let result = 0;
if (instance.exports.main) result = instance.exports.main();
}
window.addEventListener("load", load_webassembly_module)

Binary file not shown.

View File

@ -0,0 +1,274 @@
var lumenarium_wasm_module = null;
var lumenarium_wasm_instance = null;
var WASM_PAGE_SIZE = 65536;
function wasm_mem_get_u8_arr(inst, ptr, size)
{
let view = new Uint8Array(inst.exports.memory.buffer, ptr, size);
return view;
}
function wasm_read_string(inst, ptr, len)
{
let view = wasm_mem_get_u8_arr(inst, ptr, len);
let string = '';
for (let i = 0; i < len; i++)
{
string += String.fromCharCode(view[i]);
}
return string;
}
function wasm_write_bytes(inst, src, ptr, len)
{
let view = wasm_mem_get_u8_arr(inst, ptr, len);
for (let i = 0; i < len; i++) view[i] = src[i];
}
function wasm_get_proc(inst, proc_ptr)
{
let result = inst.exports.__indirect_function_table.get(proc_ptr);
return result;
}
function fract (v) { return v % 1; }
var lumenarium_wasm_imports = {
memset: (dst, size, value) => {
let view_dst = wasm_mem_get_u8_arr(lumenarium_wasm_instance, dst, size);
for (let i = 0; i < size; i++)
{
view_dst[i] = value;
}
},
memcpy: (dst, src, size) => {
let view_dst = wasm_mem_get_u8_arr(lumenarium_wasm_instance, dst, size);
let view_src = wasm_mem_get_u8_arr(lumenarium_wasm_instance, src, size);
for (let i = 0; i < size; i++)
{
view_dst[i] = view_src[i];
}
},
wasm_assert_always: (file, file_len, line) => {
let file_str = wasm_read_string(lumenarium_wasm_instance, file, file_len);
console.assert(false, "At: " + file_str + "::" + line);
},
wasm_get_memory_size: () => {
return instance.exports.memory.buffer.byteLength;
},
wasm_mem_grow: (new_size) => {
let pages = new_size / WASM_PAGE_SIZE;
let pages_rem = fract(pages);
if (pages_rem > 0) pages = Math.floor(pages) + 1;
let size_before = lumenarium_wasm_instance.exports.memory.buffer.byteLength;
let old_page_count = lumenarium_wasm_instance.exports.memory.grow(pages);
console.log("mem_grow\n",
"req size: ", new_size, "\n",
"old size: ", (old_page_count * WASM_PAGE_SIZE), "\n",
"old size: ", size_before, "\n",
"grew by: ", (pages * WASM_PAGE_SIZE), "\n",
"new size: ", lumenarium_wasm_instance.exports.memory.buffer.byteLength, "");
},
wasm_performance_now: () => {
return performance.now();
},
wasm_sleep: (milliseconds) => {
let start = Date.now();
for (let at = Date.now(); (at - start) < milliseconds; at = Date.now()) {}
},
wasm_fetch: async (file_path, file_path_len, dest, dest_size) => {
let path = wasm_read_string(lumenarium_wasm_instance, file_path, file_path_len);
fetch(path)
.then(async (res) => {
// TODO(PS): success checking
let reader = res.body.getReader();
let read_res = { done: false };
let view = wasm_mem_get_u8_arr(lumenarium_wasm_instance, dest, dest_size);
let last_write = 0;
while (!read_res.done)
{
read_res = await reader.read();
if (read_res.done) break;
let len = read_res.value.length;
let write_end = last_write + len;
for (let i = last_write; i < write_end; i++)
{
view[i] = read_res.value[i - last_write];
}
last_write = write_end + 1;
}
});
return 0;
},
wasm_request_animation_frame: (cb) => {
let cb_proc = wasm_get_proc(lumenarium_wasm_instance, cb);
window.requestAnimationFrame(cb_proc);
},
print: (str_base, len) => {
let string = wasm_read_string(lumenarium_wasm_instance, str_base, len);
console.log(string);
},
};
///////////////////////////////////////
// Web GL Imports
let gl = null;
// NOTE(PS): it seems like its not enough to set
// the values of imports to gl.function
// ie. imports.glClearColor = gl.clearColor
// instead we need to wrap them for some reason.
// Not sure why
function glClearColor (r, g, b, a) { return gl.clearColor(r,g,b,a); }
function glEnable(v) { return gl.enable(v); }
function glDisable(v) { return gl.disable(v); }
function glBlendFunc(a,b) { return gl.blendFunc(a,b); }
function glViewport(xmin, ymin, xmax, ymax) { return gl.viewport(xmin,ymin,xmax,ymax); }
function glDepthFunc(v) { return gl.depthFunc(v); }
function glClear(mask) { return gl.clear(mask); }
let glBuffers = [];
let glShaders = [];
let glPrograms = [];
function gl_get_managed_resource(arr, id) {
if (id == 0) return null;
return arr[id - 1];
}
function gl_get_buffer(id) { return gl_get_managed_resource(glBuffers, id); }
function gl_get_shader(id) { return gl_get_managed_resource(glShaders, id); }
function gl_get_program(id) { return gl_get_managed_resource(glPrograms, id); }
function glCreateBuffer() {
let buffer = gl.createBuffer();
let new_len = glBuffers.push(buffer);
return new_len;
}
function glBindBuffer(buffer_kind, buffer_id)
{
return gl.bindBuffer(buffer_kind, gl_get_buffer(buffer_id));
}
function glBufferData(target, size, ptr, usage)
{
let data = wasm_mem_get_u8_arr(lumenarium_wasm_instance, ptr, size);
return gl.bufferData(target, data, usage);
}
function glCreateShader(kind)
{
let shader = gl.createShader(kind);
let new_len = glShaders.push(shader);
return new_len;
}
function glShaderSource(shader_id, shader_code, shader_code_len)
{
let str = wasm_read_string(lumenarium_wasm_instance, shader_code, shader_code_len);
console.error("For some reason, str isn't getting the correct data out of here", str);
return gl.shaderSource(gl_get_shader(shader_id), str);
}
function glCompileShader(shader_id)
{
let s = gl_get_shader(shader_id);
let r = gl.compileShader(s);
let m = gl.getShaderInfoLog(s);
if (m.length > 0)
{
console.error("glCompileShader: \n\n" + m);
}
}
function glCreateProgram()
{
let prog = gl.createProgram();
let new_len = glPrograms.push(prog);
return new_len;
}
function glAttachShader(program, shader)
{
let s = gl_get_shader(shader);
let p = gl_get_program(program);
return gl.attachShader(p, s);
}
function glLinkProgram(program)
{
let p = gl_get_program(program);
gl.linkProgram(p);
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) {
var info = gl.getProgramInfoLog(p);
console.error("Failed to compile WebGL program. \n\n"+info);
}
}
function glUseProgram(program)
{
let p = gl_get_program(program);
return gl.useProgram(p);
}
function glGetAttribLocation(program, name, name_len)
{
let str = wasm_read_string(lumenarium_wasm_instance, name, name_len);
return gl.getAttribLocation(gl_get_program(program), str);
}
function glVertexAttribPointer(attr, size, type, normalized, stride, pointer)
{
return gl.vertexAttribPointer(attr, size, type, normalized, stride, pointer);
}
function glEnableVertexAttribArray(index)
{
return gl.enableVertexAttribArray(index);
}
function glDrawElements(type, index_count, ele_type, indices)
{
return gl.drawElements(type, index_count, ele_type, indices);
}
function webgl_add_imports (canvas_selector, imports) {
const canvas = document.querySelector(canvas_selector);
if (!canvas) return console.error("no canvas");
gl = canvas.getContext("webgl");
if (gl === null) return console.error("no webgl ctx");
console.log(
gl.FLOAT.toString(16), "\n",
gl.UNSIGNED_INT.toString(16), "\n"
);
imports.glClearColor = glClearColor;
imports.glEnable = glEnable;
imports.glDisable = glDisable;
imports.glBlendFunc = glBlendFunc;
imports.glViewport = glViewport;
imports.glDepthFunc = glDepthFunc;
imports.glClear = glClear;
imports.glCreateBuffer = glCreateBuffer;
imports.glBindBuffer = glBindBuffer;
imports.glBufferData = glBufferData;
imports.glCreateShader = glCreateShader;
imports.glShaderSource = glShaderSource;
imports.glCompileShader = glCompileShader;
imports.glCreateProgram = glCreateProgram;
imports.glAttachShader = glAttachShader;
imports.glLinkProgram = glLinkProgram;
imports.glUseProgram = glUseProgram;
imports.glGetAttribLocation = glGetAttribLocation;
imports.glVertexAttribPointer = glVertexAttribPointer;
imports.glEnableVertexAttribArray = glEnableVertexAttribArray;
imports.glDrawElements = glDrawElements;
return imports;
}

Binary file not shown.

View File

@ -1,130 +0,0 @@
let memory = null;
let memory_u8 = null;
// TODO(PS): you need to figure out how to get text to convert to a string
function print (text)
{
console.log(i, memory_u8.length, text);
}
async function load_webassembly_module ()
{
const path = "lumenarium.wasm";
const promise = fetch(path);
const module = await WebAssembly.compileStreaming(promise);
memory = new WebAssembly.Memory({ initial: 2 });
memory_u8 = new Uint8Array(memory.buffer);
const env = {
memory,
print,
};
const result = await WebAssembly.instantiate(module, { env });
console.log(result);
result.exports.main();
}
window.addEventListener("load", load_webassembly_module)
/*
function load_webassembly_module (wa)
{
fetch(wa.module)
.then(res => res.arrayBuffer())
.then((wasm_bytes) => {
"use strict";
wasm_bytes = new Uint8Array(wasm_bytes);
// find start of heap and calc initial mem requirements
var wasm_heap_base = 65536;
// see https://webassembly.org/docs/binary-encoding/
for (let i = 8, section_end, type, length;
i < wasm_bytes.length;
i = section_end
){
function get_b8()
{
return wasm_bytes[i++];
}
function get_leb()
{
for (var s = i, r = 0, n = 128; n & 128; i++)
{
r |= ((n = wasm_bytes[i]) & 127) << ((i - s) * 7);
}
return r; // TODO(PS): this might belong in the for loop?
}
type = get_leb();
length = get_leb();
section_end = i + length;
if (type < 0 || type > 11 || length <= 0 || section_end > wasm_bytes.length)
{
break;
}
if (type == 6)
{
//Section 6 'Globals', llvm places the heap base pointer into the first value here
let count = get_leb();
let gtype = get_b8();
let mutable = get_b8();
let opcode = get_leb();
let offset = get_leb();
let endcode = get_leb();
wasm_heap_base = offset;
break;
}
}
// Set the wasm memory size to [DATA] + [STACK] + [256KB HEAP]
// (This loader does not support memory growing so it stays at this size)
var wasm_mem_init = ((wasm_heap_base + 65535) >> 16 << 16) + (256 * 1024);
var env = {
env: {
memory: new WebAssembly.Memory(
{
initial: wasm_mem_init >> 16
}
),
},
};
// Instantiate the wasm module by passing the prepared environment
WebAssembly.instantiate(wasm_bytes, env)
.then(function (output)
{
// Store the list of the functions exported by the wasm module in WA.asm
wa.asm = output.instance.exports;
// If function '__wasm_call_ctors' (global C++ constructors) exists, call it
if (wa.asm.__wasm_call_ctors) wa.asm.__wasm_call_ctors();
// If function 'main' exists, call it with dummy arguments
if (wa.asm.main) wa.asm.main(0, 0);
// If the outer HTML file supplied a 'started' callback, call it
if (wa.started) wa.started();
})
.catch(function (err)
{
// On an exception, if the err is 'abort' the error was already processed in the abort function above
if (err !== 'abort') {
let stack = err.stack ? "\n" + err.stack : "";
console.error('BOOT: WASM instiantate error: ' + err + stack);
return;
}
});
});
}
load_webassembly_module(web_assembly)
*/

Binary file not shown.

View File

@ -0,0 +1,167 @@
var lumenarium_wasm_module = null;
var lumenarium_wasm_instance = null;
var WASM_PAGE_SIZE = 65536;
function wasm_mem_get_u8_arr(inst, ptr, size)
{
let view = new Uint8Array(inst.exports.memory.buffer, ptr, size);
return view;
}
function wasm_read_string(inst, ptr, len)
{
let view = wasm_mem_get_u8_arr(inst, ptr, len);
let string = '';
for (let i = 0; i < len; i++)
{
string += String.fromCharCode(view[i]);
}
return string;
}
function wasm_write_bytes(inst, src, ptr, len)
{
let view = wasm_mem_get_u8_arr(inst, ptr, len);
for (let i = 0; i < len; i++) view[i] = src[i];
}
function wasm_get_proc(inst, proc_ptr)
{
let result = inst.exports.__indirect_function_table.get(proc_ptr);
return result;
}
function fract (v) { return v % 1; }
var lumenarium_wasm_imports = {
memset: (dst, size, value) => {
let view_dst = wasm_mem_get_u8_arr(lumenarium_wasm_instance, dst, size);
for (let i = 0; i < size; i++)
{
view_dst[i] = value;
}
},
memcpy: (dst, src, size) => {
let view_dst = wasm_mem_get_u8_arr(lumenarium_wasm_instance, dst, size);
let view_src = wasm_mem_get_u8_arr(lumenarium_wasm_instance, src, size);
for (let i = 0; i < size; i++)
{
view_dst[i] = view_src[i];
}
},
wasm_assert_always: () => {
console.assert(false);
},
wasm_get_memory_size: () => {
return instance.exports.memory.buffer.byteLength;
},
wasm_mem_grow: (new_size) => {
let pages = new_size / WASM_PAGE_SIZE;
let pages_rem = fract(pages);
if (pages_rem > 0) pages = Math.floor(pages) + 1;
let size_before = lumenarium_wasm_instance.exports.memory.buffer.byteLength;
let old_page_count = lumenarium_wasm_instance.exports.memory.grow(pages);
console.log("mem_grow\n",
"req size: ", new_size, "\n",
"old size: ", (old_page_count * WASM_PAGE_SIZE), "\n",
"old size: ", size_before, "\n",
"grew by: ", (pages * WASM_PAGE_SIZE), "\n",
"new size: ", lumenarium_wasm_instance.exports.memory.buffer.byteLength, "");
},
wasm_performance_now: () => {
return performance.now();
},
wasm_sleep: (milliseconds) => {
let start = Date.now();
for (let at = Date.now(); (at - start) < milliseconds; at = Date.now()) {}
},
wasm_fetch: async (file_path, file_path_len, dest, dest_size) => {
let path = wasm_read_string(lumenarium_wasm_instance, file_path, file_path_len);
fetch(path)
.then(async (res) => {
// TODO(PS): success checking
let reader = res.body.getReader();
let read_res = { done: false };
let view = wasm_mem_get_u8_arr(lumenarium_wasm_instance, dest, dest_size);
let last_write = 0;
while (!read_res.done)
{
read_res = await reader.read();
if (read_res.done) break;
let len = read_res.value.length;
let write_end = last_write + len;
for (let i = last_write; i < write_end; i++)
{
view[i] = read_res.value[i - last_write];
}
last_write = write_end + 1;
}
});
return 0;
},
wasm_request_animation_frame: (cb) => {
let cb_proc = wasm_get_proc(lumenarium_wasm_instance, cb);
window.requestAnimationFrame(cb_proc);
},
print: (str_base, len) => {
let string = wasm_read_string(lumenarium_wasm_instance, str_base, len);
console.log(string);
},
};
let gl = null;
function glClearColor (r, g, b, a) { gl.clearColor(r,g,b,a); }
function glEnable(v) { gl.enable(v); }
function glDisable(v) { gl.disable(v); }
function glBlendFunc(a,b) { gl.blendFunc(a,b); }
function glViewport(xmin, ymin, xmax, ymax) { gl.viewport(xmin,ymin,xmax,ymax); }
function glDepthFunc(v) { gl.depthFunc(v); }
function glClear(mask) { gl.clear(mask); }
function webgl_add_imports (canvas_selector, imports) {
const canvas = document.querySelector(canvas_selector);
if (!canvas) return console.error("no canvas");
gl = canvas.getContext("webgl");
if (gl === null) return console.error("no webgl ctx");
///////////////////////////////////////
// Constants
imports.GL_TEXTURE_2D = gl.TEXTURE_2D;
imports.GL_BLEND = gl.BLEND;
imports.GL_SRC_ALPHA = gl.SRC_ALPHA;
imports.GL_ONE_MINUS_SRC_ALPHA = gl.ONE_MINUS_SRC_ALPHA;
imports.GL_DEPTH_TEST = gl.DEPTH_TEST;
imports.GL_LESS = gl.LESS;
imports.GL_COLOR_BUFFER_BIT = gl.COLOR_BUFFER_BIT;
imports.GL_DEPTH_BUFFER_BIT = gl.DEPTH_BUFFER_BIT;
///////////////////////////////////////
// Functions
imports.glClearColor = glClearColor;
imports.glEnable = glEnable;
imports.glDisable = glDisable;
imports.glBlendFunc = glBlendFunc;
imports.glViewport = glViewport;
imports.glDepthFunc = glDepthFunc;
imports.glClear = glClear;
return imports;
}

Binary file not shown.

Binary file not shown.

View File

@ -1,20 +1,94 @@
internal void
edr_init(App_State* state)
{
v4 quad_verts[] = {
-0.5f, 0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.0f, 1.0f,
00.5f, -0.5f, 0.0f, 1.0f,
00.5f, 0.5f, 0.0f, 1.0f,
};
u32 quad_indices[] = {
3, 2, 1,
3, 1, 0,
};
char* shader_code_vert =
"#version 140\n"
"attribute vec4 coordinates;\n"
"void main(void) {\n"
" gl_Position = coordinates;\n"
"}";
char* shader_code_frag =
"#version 140\n"
"void main(void) {\n"
" gl_FragColor = vec4(1, 0, 1, 1);\n"
"}";
#if 0
/* ======= Geometry =======*/
glCreateBuffers(1, &buffer_vertex);
glBindBuffer(GL_ARRAY_BUFFER, buffer_vertex);
glBufferData(GL_ARRAY_BUFFER, quad_verts, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, NULL);
glCreateBuffer(1, &buffer_index);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer_index);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, quad_indices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL);
/* ======= Shaders =======*/
shader_vert = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(shader_vertex, shader_code_vert);
glCompileShader(shader_vert);
shader_frag = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(shader_frag, shader_code_frag);
glCompileShader(shader_frag);
shader_prog = glCreateProgram();
glAttachShader(shader_prog, shader_vert);
glAttachShader(shader_prog, shader_frag);
glLinkProgram(shader_prog);
glUseProgram(shader_prog);
/* ======= Associating shaders to buffer objects =======*/
glBindBuffer(GL_ARRAY_BUFFER, buffer_vertex);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer_index);
coord = glGetAttribLocation(shader_prog, "coordinates");
glVertexAttribPointer(coord, 4, GL_FLOAT, false, 0, 0);
glEnableVertexAttribArray(coord);
#endif
}
internal void
edr_render_quad()
{
#if 0
glBindBuffer(GL_ARRAY_BUFFER, buffer_vertex);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer_index);
glEnableVertexAttribArray(coord);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
#endif
}
internal void
edr_render(App_State* state)
{
glMatrixMode(GL_TEXTURE_2D);
glLoadIdentity();
Platform_Graphics_Frame_Desc desc = {};
desc.clear_color = { 0.1f, 0.1f, 0.1f, 1 };
desc.viewport_min = { 0, 0 };
desc.viewport_max = { 1600, 900 };
platform_frame_begin(desc);
platform_frame_clear();
glClearColor(0.1f, 0.1f, 0.1f, 1);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_TEXTURE_2D);
glViewport(0, 0, 1600, 900);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#if 0
edr_render_quad();
#endif
}

View File

@ -0,0 +1,11 @@
/* date = March 24th 2022 4:18 pm */
#ifndef LUMENARIUM_EDITOR_RENDERER_H
#define LUMENARIUM_EDITOR_RENDERER_H
struct Editor_Renderer
{
};
#endif //LUMENARIUM_EDITOR_RENDERER_H

View File

@ -0,0 +1 @@
//

View File

@ -1,8 +1,8 @@
internal void
en_init(App_State* state)
en_init(App_State* state, App_Init_Desc desc)
{
state->assemblies = assembly_array_create(permanent, desc.assembly_cap);
}
internal void

View File

@ -0,0 +1,102 @@
Assembly_Array
assembly_array_create(Allocator* allocator, u32 cap)
{
Assembly_Array result = {};
result.cap = cap;
result.names = allocator_alloc_array(allocator, String, cap);
result.pixel_buffers = allocator_alloc_array(allocator, Assembly_Pixel_Buffer, cap);
result.strip_arrays = allocator_alloc_array(allocator, Assembly_Strip_Array, cap);
result.allocator = allocator;
return result;
}
bool
assembly_handle_is_valid(Assembly_Handle h)
{
return ((h.value & ASSEMBLY_HANDLE_VALID_BIT) != 0);
}
u32
assembly_handle_to_index(Assembly_Handle h)
{
assert(assembly_handle_is_valid(h));
u32 index = (h.value & ASSEMBLY_HANDLE_INDEX_MASK); // mask off high bit
return index;
}
Assembly_Handle
assembly_add(Assembly_Array* a, String name, u32 pixels_cap, u32 strips_cap)
{
Assembly_Handle result = {};
if (a->len < a->cap)
{
result.value = a->len++;
result.value |= ASSEMBLY_HANDLE_VALID_BIT; // high bit being set means its valid
}
else
{
// TODO(PS): find empty index
// we can use the name being zero as a signal that the slot is empty
}
// NOTE(PS): not actually a bug, just go increase App_Init_Desc::assemblies_cap
// b/c you ran out of room
assert(assembly_handle_is_valid(result));
u32 index = assembly_handle_to_index(result);
a->names[index] = name;
Assembly_Pixel_Buffer* pixel_buffer = a->pixel_buffers + index;
pixel_buffer->cap = pixels_cap;
pixel_buffer->pixels = allocator_alloc_array(a->allocator, Assembly_Pixel, pixels_cap);
pixel_buffer->positions = allocator_alloc_array(a->allocator, v4, pixels_cap);
Assembly_Strip_Array* strip_array = a->strip_arrays + index;
strip_array->cap = strips_cap;
strip_array->strips = allocator_alloc_array(a->allocator, Assembly_Strip, strips_cap);
return result;
}
void
assembly_rem(Assembly_Array* a, Assembly_Handle h)
{
}
Assembly_Strip*
assembly_add_strip(Assembly_Array* a, Assembly_Handle h, u32 pixels_cap)
{
u32 index = assembly_handle_to_index(h);
Assembly_Strip_Array* strip_array = a->strip_arrays + index;
assert(strip_array->len < strip_array->cap);
Assembly_Strip* result = strip_array->strips + strip_array->len++;
result->pixels_cap = pixels_cap;
result->pixels_len = 0;
result->pixels = allocator_alloc_array(a->allocator, u32, pixels_cap);
return result;
}
void
assembly_add_led(
Assembly_Array* a,
Assembly_Handle h,
Assembly_Strip* strip,
v4 position
){
u32 index = assembly_handle_to_index(h);
Assembly_Pixel_Buffer* pixel_buffer = a->pixel_buffers + index;
assert(pixel_buffer->len < pixel_buffer->cap);
u32 pixel_index = pixel_buffer->len++;
pixel_buffer->pixels[pixel_index] = {};
pixel_buffer->positions[pixel_index] = position;
assert(strip->pixels_len < strip->pixels_cap);
strip->pixels[strip->pixels_len++] = pixel_index;
}

View File

@ -3,6 +3,16 @@
#ifndef LUMENARIUM_ENGINE_ASSEMBLY_H
#define LUMENARIUM_ENGINE_ASSEMBLY_H
// Assembly_Handle is valid for any index, including zero. However,
// valid values must have the high bit set. This way, the handle declared
// via Assembly_Handle my_handle = {}; is invalid, while still allowing
// index zero to be used in the array.
//
// If memory corruption becomes an issue we can make this a bigger bit
// field that we check since Lumenarium doesn't ever really expect to have
// more than 128 sculptures in a scene - but who knows, maybe someday O.o?
#define ASSEMBLY_HANDLE_VALID_BIT (1 << 31)
#define ASSEMBLY_HANDLE_INDEX_MASK ~ASSEMBLY_HANDLE_VALID_BIT
struct Assembly_Handle
{
u32 value;
@ -29,12 +39,15 @@ struct Assembly_Pixel_Buffer
struct Assembly_Strip
{
u32 pixels_cap;
u32 pixels_len;
// array of indices into the Assembly_Pixel_Buffer for the same assembly
u32* pixels;
};
struct Assembly_Strip_Array
{
u32 cap;
u32 len;
Assembly_Strip* strips;
};
@ -42,16 +55,24 @@ struct Assembly_Array
{
u32 cap;
u32 len;
// assembly names
String* names;
// each assembly gets its own pixel buffer
Assembly_Pixel_Buffer* pixel_buffers;
// each assembly gets its own array of strips which
// index into that assemblies pixel_buffer
Assembly_Strip_Array* strip_arrays;
Allocator* allocator;
};
Assembly_Handle assembly_add(Assembly_Array* a, String name, u64 pixels_cap, u64 strips_cap);
Assembly_Array assembly_array_create(Allocator* allocator, u32 cap);
Assembly_Handle assembly_add(Assembly_Array* a, String name, u32 pixels_cap, u32 strips_cap);
void assembly_rem(Assembly_Array* a, Assembly_Handle h);
Assembly_Strip* assembly_add_strip(Assembly_Array* a, Assembly_Handle h);
Assembly_Strip* assembly_add_strip(Assembly_Array* a, Assembly_Handle h, u32 pixels_cap);
void assembly_add_led(Assembly_Array* a, Assembly_Handle h, Assembly_Strip* strip, v4 position);

View File

@ -443,9 +443,17 @@ extern "C"
{
float R, G, B;
};
struct
{
float r, g, b;
};
};
float A;
union
{
float A;
float a;
};
};
struct

View File

@ -1,23 +1,101 @@
#include "lumenarium_first.h"
#include "user_space/user_space_incenter.cpp"
Platform_Geometry_Buffer quad0;
Platform_Shader shader0;
static r32 z_ = 0;
static r32 r_ = 0.3f;
static r32 quad_verts[] = {
-r_, -r_, z_, 1.0f,
r_, -r_, z_, 1.0f,
r_, r_, z_, 1.0f,
-r_, r_, z_, 1.0f,
};
static u32 quad_indices[] = {
0, 1, 2,
0, 2, 3,
};
static String shader_code_vert_win32 = lit_str(
"#version 330 core\n"
"layout (location = 0) in vec4 coordinates;\n"
"void main(void) {\n"
" gl_Position = coordinates;\n"
"}"
);
static String shader_code_vert_wasm = lit_str(
"attribute vec4 coordinates;\n"
"void main(void) {\n"
" gl_Position = coordinates;\n"
"}");
static String shader_code_frag_win32 = lit_str(
"#version 330 core\n"
"out vec4 FragColor;\n"
"void main(void) {\n"
" FragColor = vec4(1,0,1,1);\n"
"}"
);
static String shader_code_frag_wasm = lit_str(
"void main(void) {\n"
" gl_FragColor = vec4(1, 0, 1, 1);\n"
"}");
void make_quad()
{
// TODO(PS): TEMP
#if defined(PLATFORM_win32)
String shader_code_vert = shader_code_vert_win32;
String shader_code_frag = shader_code_frag_win32;
#elif defined(PLATFORM_wasm)
String shader_code_vert = shader_code_vert_wasm;
String shader_code_frag = shader_code_frag_wasm;
#endif
quad0 = platform_geometry_buffer_create(
quad_verts, 16, quad_indices, 6
);
String attribs[] = { lit_str("coordinates") };
shader0 = platform_shader_create(
shader_code_vert, shader_code_frag, attribs, 1
);
platform_vertex_attrib_pointer(quad0, shader0, 0);
}
internal App_State*
lumenarium_init()
{
permanent = bump_allocator_create_reserve(MB(64));
scratch = bump_allocator_create_reserve(MB(64));
App_State* state = 0;
permanent = bump_allocator_create_reserve(MB(4));
scratch = bump_allocator_create_reserve(KB(64));
run_tests();
App_State* state = allocator_alloc_struct(permanent, App_State);
App_Init_Desc desc = incenter_get_init_desc();
// TODO(PS): make sure the values make sense in desc
state = allocator_alloc_struct(permanent, App_State);
add_flag(state->flags, AppState_IsRunning);
state->input_state = input_state_create();
en_init(state);
en_init(state, desc);
if (!has_flag(state->flags, AppState_NoEditor))
{
ed_init(state);
}
incenter_init(state);
make_quad();
return state;
}
@ -26,6 +104,7 @@ internal void
lumenarium_frame_prepare(App_State* state)
{
allocator_clear(scratch);
input_state_swap_frames(&state->input_state);
en_frame_prepare(state);
@ -33,6 +112,7 @@ lumenarium_frame_prepare(App_State* state)
{
ed_frame_prepare(state);
}
incenter_frame_prepare(state);
}
internal void
@ -41,8 +121,23 @@ lumenarium_frame(App_State* state)
en_frame(state);
if (!has_flag(state->flags, AppState_NoEditor))
{
ed_frame(state);
//ed_frame(state);
Platform_Graphics_Frame_Desc desc = {};
desc.clear_color = { 0.1f, 0.1f, 0.1f, 1 };
desc.viewport_min = { 0, 0 };
desc.viewport_max = { 1600, 900 };
platform_frame_begin(desc);
platform_frame_clear();
platform_geometry_bind(quad0);
platform_shader_bind(shader0);
platform_geometry_draw(quad0);
}
incenter_frame(state);
}
internal void
@ -79,6 +174,7 @@ lumenarium_event(Platform_Window_Event evt, App_State* state)
internal void
lumenarium_cleanup(App_State* state)
{
incenter_cleanup(state);
en_cleanup(state);
if (!has_flag(state->flags, AppState_NoEditor))
{

View File

@ -5,15 +5,16 @@
typedef struct App_State App_State;
// Environment
#include "lumenarium_memory.cpp"
#include "lumenarium_string.cpp"
#include "lumenarium_input.cpp"
// Engine
#include "engine/lumenarium_engine_assembly.h"
#include "engine/lumenarium_engine.cpp"
#include "editor/lumenarium_editor_renderer.cpp"
#include "editor/lumenarium_editor.cpp"
// Editor
#include "editor/lumenarium_editor_renderer.h"
//////////////////////////////////////////////
// Lumenarium Runtime Environment
@ -38,11 +39,24 @@ enum
AppState_NoEditor = 2,
};
struct App_Init_Desc
{
u32 assembly_cap;
};
struct App_State
{
App_State_Flags flags;
Input_State input_state;
Assembly_Array assemblies;
};
#include "engine/lumenarium_engine_assembly.cpp"
#include "engine/lumenarium_engine.cpp"
#include "editor/lumenarium_editor_renderer.cpp"
#include "editor/lumenarium_editor.cpp"
#endif //LUMENARIUM_FIRST_H

View File

@ -138,11 +138,16 @@ bump_allocator_alloc(Allocator* allocator, u64 size)
}
else
{
if (new_size < bump->size_reserved)
if (new_size <= bump->size_reserved)
{
u64 next_page = size_to_pages(bump->at);
if (bump->at == 0 && bump->size_committed == 0) next_page = 0;
u64 commit_amt = new_size - next_page;
bump->base = platform_mem_commit(bump->base + next_page, commit_amt);
u8* new_page = platform_mem_commit(bump->base + next_page, commit_amt);
if (new_page != 0)
{
bump->size_committed = new_size;
}
}
else
{
@ -151,7 +156,7 @@ bump_allocator_alloc(Allocator* allocator, u64 size)
}
}
u8* result = bump->base;
u8* result = bump->base + bump->at;
bump->at = at_after;
return result;

View File

@ -61,7 +61,7 @@ string_substring(String s, u64 min, u64 max)
if (min > max) {
u64 t = min;
min = max;
max = min;
max = t;
}
String result = {};
result.str = s.str + min;

View File

@ -2,12 +2,40 @@
Platform_Thread_Result
thread_proc(Platform_Thread_Data* td)
{
//Sleep(100);
return {};
}
internal void
run_tests()
{
// memory tests
u8* a0 = allocator_alloc_array(scratch, u8, 32);
u8* a1 = allocator_alloc_array(scratch, u8, 32);
assert(a0 != a1);
assert((a0 + 32) <= a1);
for (u32 i = 0; i < 32; i++)
{
a0[i] = (u8)i;
a1[i] = (u8)(100 + i);
}
for (u32 i = 0; i < 32; i++)
{
assert(a0[i] == i);
assert(a1[i] == (100 + i));
}
#if defined(PLATFORM_wasm)
// NOTE(PS): the tests below this point don't make sense on a web assembly
// platform
return;
#endif
// testing strings and exe path
String exe_file_path = platform_get_exe_path(scratch);
assert(exe_file_path.str != 0);
@ -31,16 +59,24 @@ run_tests()
bool r = platform_file_write_all(f, d1);
assert(r);
#if 0
// TODO(PS): these were causing startup problems but you weren't focusing on
// threads/ When you build something multithreaded come back here and
// make tests that actually work
// testing threads
Platform_Thread_Handle threads[8];
for (u32 j = 0; j < 8; j++)
{
threads[j] = platform_thread_begin(thread_proc, 0);
}
for (u32 j = 0; j < 8; j++)
{
platform_thread_end(threads[j]);
}
#endif
allocator_clear(scratch);
}

View File

@ -54,31 +54,6 @@ struct Data
#define add_flag(data, flag) ((data) |= (flag))
#define rem_flag(data, flag) ((data) &= (~(flag)))
//////////////////////////////////////////////
// Assert
// this assert works by simply trying to write to an invalid address
// (in this case, 0x0), which will crash in most debuggers
#define assert_always (*((volatile s32*)0) = 0xFFFF)
#ifdef USE_ASSERTS
# define assert(c) if (!(c)) { assert_always; }
// useful for catching cases that you aren't sure you'll hit, but
// want to be alerted when they happen
# define invalid_code_path assert_always
// useful for switch statements on enums that might grow. You'll
// break in the debugger the first time the default case is hit
// with a new enum value
# define invalid_default_case default: { assert_always; } break;
#else
# define assert(c)
# define invalid_code_path
# define invalid_default_case default: { } break;
#endif
//////////////////////////////////////////////
// List Helper Macros

5991
src_v2/platform/glcorearb.h Normal file

File diff suppressed because it is too large Load Diff

12894
src_v2/platform/glext.h Normal file

File diff suppressed because it is too large Load Diff

View 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_ */

View File

@ -0,0 +1,34 @@
/* date = March 26th 2022 3:42 pm */
#ifndef LUMENARIUM_ASSERT_H
#define LUMENARIUM_ASSERT_H
#if !defined(PLATFORM_wasm)
// this assert works by simply trying to write to an invalid address
// (in this case, 0x0), which will crash in most debuggers
# define assert_always (*((volatile s32*)0) = 0xFFFF)
#else
WASM_EXTERN void wasm_assert_always(char* file, u32 file_len, u32 line);
# define assert_always wasm_assert_always(__FILE__, sizeof(__FILE__), __LINE__)
#endif // defined(PLATFORM_WASM)
#ifdef USE_ASSERTS
# define assert(c) if (!(c)) { assert_always; }
// useful for catching cases that you aren't sure you'll hit, but
// want to be alerted when they happen
# define invalid_code_path assert_always
// useful for switch statements on enums that might grow. You'll
// break in the debugger the first time the default case is hit
// with a new enum value
# define invalid_default_case default: { assert_always; } break;
#else
# define assert(c)
# define invalid_code_path
# define invalid_default_case default: { } break;
#endif
#endif //LUMENARIUM_ASSERT_H

View File

@ -10,7 +10,7 @@
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
#ifdef DEBUG
#if defined(DEBUG)
# define USE_ASSERTS 1
#endif

View File

@ -77,6 +77,8 @@ void platform_file_close(Platform_File_Handle file_handle);
Platform_File_Info platform_file_get_info(Platform_File_Handle file_handle, Allocator* allocator);
Data platform_file_read_all(Platform_File_Handle file_handle, Allocator* allocator);
bool platform_file_write_all(Platform_File_Handle file_handle, Data file_data);
String platform_get_exe_path(Allocator* allocator);
bool platform_pwd_set(String path);
typedef u32 Platform_Enum_Dir_Flags;
enum
@ -291,4 +293,44 @@ s32 platform_Socket_set_opt();
///////////////////////////////////////
// Graphics Integration
#define PLATFORM_SHADER_MAX_ATTRS 8
#define PLATFORM_SHADER_ATTR_LAST (u32)(1 << 31)
struct Platform_Shader
{
u32 id;
u32 attrs[PLATFORM_SHADER_MAX_ATTRS];
};
struct Platform_Geometry_Buffer
{
u32 buffer_id_vao;
u32 buffer_id_vertices;
u32 buffer_id_indices;
u32 indices_len;
};
struct Platform_Graphics_Frame_Desc
{
v4 clear_color;
v2 viewport_min;
v2 viewport_max;
};
void platform_frame_begin(Platform_Graphics_Frame_Desc desc);
void platform_frame_clear();
Platform_Geometry_Buffer platform_geometry_buffer_create(r32* vertices, u32 vertices_len, u32* indices, u32 indices_len);
Platform_Shader platform_shader_create(
String code_vert, String code_frag, String* attribs, u32 attribs_len
);
void platform_vertex_attrib_pointer(
Platform_Geometry_Buffer geo, Platform_Shader shader, u32 attrib_index
);
void platform_geometry_bind(Platform_Geometry_Buffer geo);
void platform_shader_bind(Platform_Shader shader);
void platform_geometry_draw(Platform_Geometry_Buffer geo);
void platform_vertex_attrib_pointer(
Platform_Geometry_Buffer geo, Platform_Shader shader, u32 attr_index
);
#endif //LUMENARIUM_PLATFORM_H

View File

@ -11,6 +11,12 @@
#include <math.h>
#include "lumenarium_assert.h"
#include "glcorearb.h"
#include "glext.h"
#include "wglext.h"
#if 0
#define HMM_SINF sin
#define HMM_COSF cos

View File

@ -0,0 +1,4 @@
// I think this SO post might be helpful
// https://stackoverflow.com/questions/30575995/multi-platform-equivalent-to-queryperformancecounter

16066
src_v2/platform/sokol_gfx.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,90 @@
#define WASM_EXPORT __attribute__((visibility("default")))
#define WASM_EXTERN extern "C"
#define EXTERN_C_BEGIN extern "C" {
#define EXTERN_C_END }
#include "../lumenarium_compiler_flags.h"
#include "../lumenarium_platform_common_includes.h"
#include "../../lumenarium_types.h"
#include "../lumenarium_platform.h"
#include "../../lumenarium_first.cpp"
#include "lumenarium_wasm_webgl.cpp"
#include "lumenarium_wasm_memory.cpp"
// window
#include "lumenarium_wasm_time.cpp"
#include "lumenarium_wasm_file.cpp"
#include "lumenarium_wasm_thread.cpp"
WASM_EXTERN void print(const char* text, int len);
typedef void wasm_animation_frame_cb(u32 time_elapsed);
WASM_EXTERN void wasm_request_animation_frame(wasm_animation_frame_cb* cb);
EXTERN_C_BEGIN;
int
str_len (char* str)
{
int result = 0;
while (str[result] != 0) result++;
return result;
}
u8* dest = 0;
App_State* wasm_app_state = 0;
WASM_EXPORT void
update(u32 time_elapsed)
{
lumenarium_frame_prepare(wasm_app_state);
lumenarium_frame(wasm_app_state);
// TODO(PS): check for app running flags
wasm_request_animation_frame(update);
}
WASM_EXPORT int
main(void)
{
wasm_app_state = lumenarium_init();
//wasm_request_animation_frame(update);
return 0;
#if 0
Platform_Ticks first = platform_get_ticks();
char* str0 = "Hi there!";
int str0_len = str_len(str0);
print(str0, str0_len);
char a = str0[0];
char* str1 = (char*)platform_mem_reserve(32);
char b = str0[0];
for (int i = 0; i < str0_len; i++)
{
int it = str0_len - (i + 1);
str1[i] = str0[i];
}
print(str1, str0_len);
char* file = "text.txt";
int file_len = str_len(file);
dest = platform_mem_reserve(KB(4));
wasm_fetch(file, file_len, dest, KB(4));
Platform_Ticks last = platform_get_ticks();
r64 seconds_elapsed = get_seconds_elapsed(first, last);
return last.value - first.value;
#endif
}
EXTERN_C_END;

View File

@ -0,0 +1,45 @@
WASM_EXTERN u32 wasm_fetch(char* file_path, u32 file_path_len, u8* dest, u32 size);
Platform_File_Handle
platform_file_open(String path, Platform_File_Access_Flags flags_access, Platform_File_Create_Flags flags_create)
{
return {};
}
void
platform_file_close(Platform_File_Handle file_handle)
{
return;
}
Platform_File_Info
platform_file_get_info(Platform_File_Handle file_handle, Allocator* allocator)
{
return {};
}
Data
platform_file_read_all(Platform_File_Handle file_handle, Allocator* allocator)
{
return {};
}
bool
platform_file_write_all(Platform_File_Handle file_handle, Data file_data)
{
return {};
}
String
platform_get_exe_path(Allocator* allocator)
{
return {};
}
bool
platform_pwd_set(String path)
{
return false;
}

View File

@ -0,0 +1,274 @@
var lumenarium_wasm_module = null;
var lumenarium_wasm_instance = null;
var WASM_PAGE_SIZE = 65536;
function wasm_mem_get_u8_arr(inst, ptr, size)
{
let view = new Uint8Array(inst.exports.memory.buffer, ptr, size);
return view;
}
function wasm_read_string(inst, ptr, len)
{
let view = wasm_mem_get_u8_arr(inst, ptr, len);
let string = '';
for (let i = 0; i < len; i++)
{
string += String.fromCharCode(view[i]);
}
return string;
}
function wasm_write_bytes(inst, src, ptr, len)
{
let view = wasm_mem_get_u8_arr(inst, ptr, len);
for (let i = 0; i < len; i++) view[i] = src[i];
}
function wasm_get_proc(inst, proc_ptr)
{
let result = inst.exports.__indirect_function_table.get(proc_ptr);
return result;
}
function fract (v) { return v % 1; }
var lumenarium_wasm_imports = {
memset: (dst, size, value) => {
let view_dst = wasm_mem_get_u8_arr(lumenarium_wasm_instance, dst, size);
for (let i = 0; i < size; i++)
{
view_dst[i] = value;
}
},
memcpy: (dst, src, size) => {
let view_dst = wasm_mem_get_u8_arr(lumenarium_wasm_instance, dst, size);
let view_src = wasm_mem_get_u8_arr(lumenarium_wasm_instance, src, size);
for (let i = 0; i < size; i++)
{
view_dst[i] = view_src[i];
}
},
wasm_assert_always: (file, file_len, line) => {
let file_str = wasm_read_string(lumenarium_wasm_instance, file, file_len);
console.assert(false, "At: " + file_str + "::" + line);
},
wasm_get_memory_size: () => {
return instance.exports.memory.buffer.byteLength;
},
wasm_mem_grow: (new_size) => {
let pages = new_size / WASM_PAGE_SIZE;
let pages_rem = fract(pages);
if (pages_rem > 0) pages = Math.floor(pages) + 1;
let size_before = lumenarium_wasm_instance.exports.memory.buffer.byteLength;
let old_page_count = lumenarium_wasm_instance.exports.memory.grow(pages);
console.log("mem_grow\n",
"req size: ", new_size, "\n",
"old size: ", (old_page_count * WASM_PAGE_SIZE), "\n",
"old size: ", size_before, "\n",
"grew by: ", (pages * WASM_PAGE_SIZE), "\n",
"new size: ", lumenarium_wasm_instance.exports.memory.buffer.byteLength, "");
},
wasm_performance_now: () => {
return performance.now();
},
wasm_sleep: (milliseconds) => {
let start = Date.now();
for (let at = Date.now(); (at - start) < milliseconds; at = Date.now()) {}
},
wasm_fetch: async (file_path, file_path_len, dest, dest_size) => {
let path = wasm_read_string(lumenarium_wasm_instance, file_path, file_path_len);
fetch(path)
.then(async (res) => {
// TODO(PS): success checking
let reader = res.body.getReader();
let read_res = { done: false };
let view = wasm_mem_get_u8_arr(lumenarium_wasm_instance, dest, dest_size);
let last_write = 0;
while (!read_res.done)
{
read_res = await reader.read();
if (read_res.done) break;
let len = read_res.value.length;
let write_end = last_write + len;
for (let i = last_write; i < write_end; i++)
{
view[i] = read_res.value[i - last_write];
}
last_write = write_end + 1;
}
});
return 0;
},
wasm_request_animation_frame: (cb) => {
let cb_proc = wasm_get_proc(lumenarium_wasm_instance, cb);
window.requestAnimationFrame(cb_proc);
},
print: (str_base, len) => {
let string = wasm_read_string(lumenarium_wasm_instance, str_base, len);
console.log(string);
},
};
///////////////////////////////////////
// Web GL Imports
let gl = null;
// NOTE(PS): it seems like its not enough to set
// the values of imports to gl.function
// ie. imports.glClearColor = gl.clearColor
// instead we need to wrap them for some reason.
// Not sure why
function glClearColor (r, g, b, a) { return gl.clearColor(r,g,b,a); }
function glEnable(v) { return gl.enable(v); }
function glDisable(v) { return gl.disable(v); }
function glBlendFunc(a,b) { return gl.blendFunc(a,b); }
function glViewport(xmin, ymin, xmax, ymax) { return gl.viewport(xmin,ymin,xmax,ymax); }
function glDepthFunc(v) { return gl.depthFunc(v); }
function glClear(mask) { return gl.clear(mask); }
let glBuffers = [];
let glShaders = [];
let glPrograms = [];
function gl_get_managed_resource(arr, id) {
if (id == 0) return null;
return arr[id - 1];
}
function gl_get_buffer(id) { return gl_get_managed_resource(glBuffers, id); }
function gl_get_shader(id) { return gl_get_managed_resource(glShaders, id); }
function gl_get_program(id) { return gl_get_managed_resource(glPrograms, id); }
function glCreateBuffer() {
let buffer = gl.createBuffer();
let new_len = glBuffers.push(buffer);
return new_len;
}
function glBindBuffer(buffer_kind, buffer_id)
{
return gl.bindBuffer(buffer_kind, gl_get_buffer(buffer_id));
}
function glBufferData(target, size, ptr, usage)
{
let data = wasm_mem_get_u8_arr(lumenarium_wasm_instance, ptr, size);
return gl.bufferData(target, data, usage);
}
function glCreateShader(kind)
{
let shader = gl.createShader(kind);
let new_len = glShaders.push(shader);
return new_len;
}
function glShaderSource(shader_id, shader_code, shader_code_len)
{
let str = wasm_read_string(lumenarium_wasm_instance, shader_code, shader_code_len);
console.error("For some reason, str isn't getting the correct data out of here", str);
return gl.shaderSource(gl_get_shader(shader_id), str);
}
function glCompileShader(shader_id)
{
let s = gl_get_shader(shader_id);
let r = gl.compileShader(s);
let m = gl.getShaderInfoLog(s);
if (m.length > 0)
{
console.error("glCompileShader: \n\n" + m);
}
}
function glCreateProgram()
{
let prog = gl.createProgram();
let new_len = glPrograms.push(prog);
return new_len;
}
function glAttachShader(program, shader)
{
let s = gl_get_shader(shader);
let p = gl_get_program(program);
return gl.attachShader(p, s);
}
function glLinkProgram(program)
{
let p = gl_get_program(program);
gl.linkProgram(p);
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) {
var info = gl.getProgramInfoLog(p);
console.error("Failed to compile WebGL program. \n\n"+info);
}
}
function glUseProgram(program)
{
let p = gl_get_program(program);
return gl.useProgram(p);
}
function glGetAttribLocation(program, name, name_len)
{
let str = wasm_read_string(lumenarium_wasm_instance, name, name_len);
return gl.getAttribLocation(gl_get_program(program), str);
}
function glVertexAttribPointer(attr, size, type, normalized, stride, pointer)
{
return gl.vertexAttribPointer(attr, size, type, normalized, stride, pointer);
}
function glEnableVertexAttribArray(index)
{
return gl.enableVertexAttribArray(index);
}
function glDrawElements(type, index_count, ele_type, indices)
{
return gl.drawElements(type, index_count, ele_type, indices);
}
function webgl_add_imports (canvas_selector, imports) {
const canvas = document.querySelector(canvas_selector);
if (!canvas) return console.error("no canvas");
gl = canvas.getContext("webgl");
if (gl === null) return console.error("no webgl ctx");
console.log(
gl.FLOAT.toString(16), "\n",
gl.UNSIGNED_INT.toString(16), "\n"
);
imports.glClearColor = glClearColor;
imports.glEnable = glEnable;
imports.glDisable = glDisable;
imports.glBlendFunc = glBlendFunc;
imports.glViewport = glViewport;
imports.glDepthFunc = glDepthFunc;
imports.glClear = glClear;
imports.glCreateBuffer = glCreateBuffer;
imports.glBindBuffer = glBindBuffer;
imports.glBufferData = glBufferData;
imports.glCreateShader = glCreateShader;
imports.glShaderSource = glShaderSource;
imports.glCompileShader = glCompileShader;
imports.glCreateProgram = glCreateProgram;
imports.glAttachShader = glAttachShader;
imports.glLinkProgram = glLinkProgram;
imports.glUseProgram = glUseProgram;
imports.glGetAttribLocation = glGetAttribLocation;
imports.glVertexAttribPointer = glVertexAttribPointer;
imports.glEnableVertexAttribArray = glEnableVertexAttribArray;
imports.glDrawElements = glDrawElements;
return imports;
}

View File

@ -0,0 +1,67 @@
#define WASM_PAGE_SIZE KB(64)
u64
platform_page_size()
{
return WASM_PAGE_SIZE;
}
// this comes from: https://surma.dev/things/c-to-webassembly/
extern u8 __heap_base;
global u8* heap_base = &__heap_base;
global u64 heap_used = 0;
WASM_EXTERN u32 wasm_get_memory_size();
WASM_EXTERN u32 wasm_mem_grow(u32 new_size);
u64
wasm_get_heap_size()
{
u64 memory_size = wasm_get_memory_size();
u64 heap_base_addr = (u64)&__heap_base;
u64 heap_size = memory_size - heap_base_addr;
return heap_size;
}
u8*
platform_mem_reserve(u64 size)
{
// if we are out of memory, double the size of wasm memory
u64 heap_size = wasm_get_heap_size();
if (heap_used + size >= heap_size)
{
u32 heap_size_new = heap_size * 2;
if (heap_used + size >= heap_size_new)
{
heap_size_new = heap_used + size;
}
wasm_mem_grow(heap_size_new);
}
assert(heap_used + size <= wasm_get_heap_size());
u64 ptr_addr = (u64)(heap_base + heap_used);
u8* result = heap_base + heap_used;
heap_used += size; // TODO(PS): alignment
return result;
}
u8*
platform_mem_commit(u8* base, u64 size)
{
return base;
}
bool
platform_mem_decommit(u8* base, u64 size)
{
return true;
}
bool
platform_mem_release(u8* base, u64 size)
{
// TODO(PS): we probably actually want to implement free at some point
return true;
}

View File

@ -0,0 +1,24 @@
Platform_Thread_Handle
platform_thread_begin(Platform_Thread_Proc* proc, u8* user_data)
{
return {};
}
void
platform_thread_end(Platform_Thread_Handle thread_handle)
{
return;
}
u32
platform_interlocked_increment(volatile u32* value)
{
return 0;
}
u32
platform_interlocked_cmp_exchg(volatile u32* dest, u32 new_value, u32 old_value)
{
return 0;
}

View File

@ -0,0 +1,26 @@
// NOTE(PS): should call performance.now() which is in milliseconds
WASM_EXTERN u32 wasm_performance_now();
WASM_EXTERN void wasm_sleep(u32 milliseconds);
Platform_Ticks
platform_get_ticks()
{
Platform_Ticks result = {};
result.value = (u64)wasm_performance_now();
return result;
}
r64
platform_ticks_to_seconds(Platform_Ticks ticks)
{
r64 result = (r64)(ticks.value * 1000);
return result;
}
void
platform_sleep(r64 milliseconds)
{
wasm_sleep(milliseconds);
}

View File

@ -0,0 +1,185 @@
//
// TODO(PS):
// TODO(PS):
// TODO(PS):
// TODO(PS): you guessed the data types and names of ALL of this
// fix it!
typedef unsigned int GLuint;
typedef float GLfloat;
typedef unsigned int GLenum;
typedef bool GLboolean;
typedef unsigned int GLsizei;
// NOTE(PS): these values and function signatures all come from
// the GLES2/gl2.h header file that can be found here:
// https://www.khronos.org/registry/OpenGL/api/GLES2/gl2.h
//
// I resorted to hard coding these rather than passing them in because
// passing them in didn't seem to be working.
#define GL_TEXTURE_2D 0x0DE1
#define GL_DEPTH_BUFFER_BIT 0x00000100
#define GL_STENCIL_BUFFER_BIT 0x00000400
#define GL_COLOR_BUFFER_BIT 0x00004000
#define GL_BLEND 0x0BE2
#define GL_SRC_ALPHA 0x0302
#define GL_ONE_MINUS_SRC_ALPHA 0x0303
#define GL_DEPTH_TEST 0x0B71
#define GL_LESS 0x0201
#define GL_ARRAY_BUFFER 0x8892
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
#define GL_STATIC_DRAW 0x88e4
#define GL_FRAGMENT_SHADER 0x8b30
#define GL_VERTEX_SHADER 0x8b31
#define GL_TRIANGLES 0x0004
#define GL_UNSIGNED_INT 0x1406
#define GL_FLOAT 0x1405
WASM_EXTERN void glClearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
WASM_EXTERN void glEnable(GLuint i);
WASM_EXTERN void glDisable(GLuint i);
WASM_EXTERN void glBlendFunc(GLuint a, GLuint b);
WASM_EXTERN void glViewport(GLuint xmin, GLuint ymin, GLuint xmax, GLuint ymax);
WASM_EXTERN void glDepthFunc(GLuint i);
WASM_EXTERN void glClear(GLuint i);
WASM_EXTERN GLuint glCreateBuffer();
WASM_EXTERN void glBindBuffer(GLenum buffer_kind, GLuint buffer_id);
WASM_EXTERN void glBufferData(GLenum target, size_t size, const void* data, GLenum usage);
WASM_EXTERN GLuint glCreateShader(GLenum kind);
WASM_EXTERN GLuint glShaderSource(GLuint shader_id, char* shader_code, GLuint shader_code_len);
WASM_EXTERN void glCompileShader(GLuint shader_id);
WASM_EXTERN GLuint glCreateProgram(void);
WASM_EXTERN void glAttachShader(GLuint program, GLuint shader);
WASM_EXTERN void glLinkProgram(GLuint program);
WASM_EXTERN void glUseProgram(GLuint program);
WASM_EXTERN GLuint glGetAttribLocation(GLuint program, const char* name, GLuint name_len);
WASM_EXTERN void glVertexAttribPointer(GLuint attr, GLuint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
WASM_EXTERN void glEnableVertexAttribArray(GLuint index);
WASM_EXTERN void glDrawElements(GLenum type, GLuint count, GLenum ele_type, void* indices);
Platform_Geometry_Buffer
platform_geometry_buffer_create(
r32* vertices, GLuint vertices_len,
GLuint* indices, GLuint indices_len
){
Platform_Geometry_Buffer result = {};
result.buffer_id_vertices = glCreateBuffer();
result.buffer_id_indices = glCreateBuffer();
// Vertices
glBindBuffer(GL_ARRAY_BUFFER, result.buffer_id_vertices);
glBufferData(
GL_ARRAY_BUFFER, sizeof(r32) * vertices_len, vertices, GL_STATIC_DRAW
);
// Indices
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, result.buffer_id_indices);
glBufferData(
GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * indices_len, indices, GL_STATIC_DRAW
);
result.indices_len = indices_len;
glBindBuffer(GL_ARRAY_BUFFER, (GLuint)NULL);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, (GLuint)NULL);
return result;
}
Platform_Shader
platform_shader_create(
String code_vert, String code_frag, String* attrs, GLuint attrs_len
){
Platform_Shader result = {};
GLuint shader_vert = glCreateShader(GL_VERTEX_SHADER);
GLuint vert_len = (GLuint)code_vert.len;
glShaderSource(shader_vert, (char*)&code_vert.str, vert_len);
glCompileShader(shader_vert);
GLuint shader_frag = glCreateShader(GL_FRAGMENT_SHADER);
GLuint frag_len = (GLuint)code_frag.len;
glShaderSource(shader_frag, (char*)&code_frag.str, frag_len);
glCompileShader(shader_frag);
result.id = (GLuint)glCreateProgram();
glAttachShader(result.id, shader_vert);
glAttachShader(result.id, shader_frag);
glLinkProgram(result.id);
glUseProgram(result.id);
// TODO(PS): delete the vert and frag programs
assert(attrs_len < PLATFORM_SHADER_MAX_ATTRS);
for (GLuint i = 0; i < attrs_len; i++)
{
s32 len = (s32)attrs[i].len;
result.attrs[i] = glGetAttribLocation(
result.id, (char*)attrs[i].str, len
);
}
result.attrs[attrs_len] = PLATFORM_SHADER_ATTR_LAST;
return result;
}
void
platform_geometry_bind(Platform_Geometry_Buffer geo)
{
glBindBuffer(GL_ARRAY_BUFFER, geo.buffer_id_vertices);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, geo.buffer_id_indices);
}
void
platform_shader_bind(Platform_Shader shader)
{
glUseProgram(shader.id);
for (GLuint i = 0; i < PLATFORM_SHADER_MAX_ATTRS && shader.attrs[i] != PLATFORM_SHADER_MAX_ATTRS; i++)
{
glEnableVertexAttribArray(shader.attrs[i]);
}
}
void
platform_geometry_draw(
Platform_Geometry_Buffer geo
){
glDrawElements(GL_TRIANGLES, geo.indices_len, GL_UNSIGNED_INT, 0);
}
void platform_vertex_attrib_pointer(
Platform_Geometry_Buffer geo, Platform_Shader shader, GLuint attr_index
){
platform_shader_bind(shader);
platform_geometry_bind(geo);
glVertexAttribPointer(shader.attrs[attr_index], 4, GL_FLOAT, false, 0, 0);
}
void
platform_frame_begin(Platform_Graphics_Frame_Desc desc)
{
v4 cc = desc.clear_color;
glClearColor(cc.r, cc.g, cc.b, cc.a);
v2 vmin = desc.viewport_min;
v2 vmax = desc.viewport_max;
glViewport(vmin.x, vmin.y, vmax.x, vmax.y);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void
platform_frame_clear()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

View File

@ -1,18 +0,0 @@
#define WEBGL_EXPORT __attribute__((visibility("default")))
#define WEBGL_EXTERN extern "C"
#define EXTERN_C_BEGIN extern "C" {
#define EXTERN_C_END }
WEBGL_EXTERN void print(char* text);
EXTERN_C_BEGIN;
WEBGL_EXPORT int
main(void)
{
print("Hi there!\n");
return 5;
}
EXTERN_C_END;

845
src_v2/platform/wglext.h Normal file
View File

@ -0,0 +1,845 @@
#ifndef __wgl_wglext_h_
#define __wgl_wglext_h_ 1
#ifdef __cplusplus
extern "C" {
#endif
/*
** Copyright 2013-2020 The Khronos Group Inc.
** SPDX-License-Identifier: MIT
**
** This header is generated from the Khronos OpenGL / OpenGL ES XML
** API Registry. The current version of the Registry, generator scripts
** used to make the header, and the header can be found at
** https://github.com/KhronosGroup/OpenGL-Registry
*/
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#endif
#define WGL_WGLEXT_VERSION 20211115
/* Generated C header for:
* API: wgl
* Versions considered: .*
* Versions emitted: _nomatch_^
* Default extensions included: wgl
* Additional extensions included: _nomatch_^
* Extensions removed: _nomatch_^
*/
#ifndef WGL_ARB_buffer_region
#define WGL_ARB_buffer_region 1
#define WGL_FRONT_COLOR_BUFFER_BIT_ARB 0x00000001
#define WGL_BACK_COLOR_BUFFER_BIT_ARB 0x00000002
#define WGL_DEPTH_BUFFER_BIT_ARB 0x00000004
#define WGL_STENCIL_BUFFER_BIT_ARB 0x00000008
typedef HANDLE (WINAPI * PFNWGLCREATEBUFFERREGIONARBPROC) (HDC hDC, int iLayerPlane, UINT uType);
typedef VOID (WINAPI * PFNWGLDELETEBUFFERREGIONARBPROC) (HANDLE hRegion);
typedef BOOL (WINAPI * PFNWGLSAVEBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height);
typedef BOOL (WINAPI * PFNWGLRESTOREBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc);
#ifdef WGL_WGLEXT_PROTOTYPES
HANDLE WINAPI wglCreateBufferRegionARB (HDC hDC, int iLayerPlane, UINT uType);
VOID WINAPI wglDeleteBufferRegionARB (HANDLE hRegion);
BOOL WINAPI wglSaveBufferRegionARB (HANDLE hRegion, int x, int y, int width, int height);
BOOL WINAPI wglRestoreBufferRegionARB (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc);
#endif
#endif /* WGL_ARB_buffer_region */
#ifndef WGL_ARB_context_flush_control
#define WGL_ARB_context_flush_control 1
#define WGL_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097
#define WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0
#define WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098
#endif /* WGL_ARB_context_flush_control */
#ifndef WGL_ARB_create_context
#define WGL_ARB_create_context 1
#define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002
#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
#define WGL_CONTEXT_FLAGS_ARB 0x2094
#define ERROR_INVALID_VERSION_ARB 0x2095
typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList);
#ifdef WGL_WGLEXT_PROTOTYPES
HGLRC WINAPI wglCreateContextAttribsARB (HDC hDC, HGLRC hShareContext, const int *attribList);
#endif
#endif /* WGL_ARB_create_context */
#ifndef WGL_ARB_create_context_no_error
#define WGL_ARB_create_context_no_error 1
#define WGL_CONTEXT_OPENGL_NO_ERROR_ARB 0x31B3
#endif /* WGL_ARB_create_context_no_error */
#ifndef WGL_ARB_create_context_profile
#define WGL_ARB_create_context_profile 1
#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
#define ERROR_INVALID_PROFILE_ARB 0x2096
#endif /* WGL_ARB_create_context_profile */
#ifndef WGL_ARB_create_context_robustness
#define WGL_ARB_create_context_robustness 1
#define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004
#define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
#define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
#define WGL_NO_RESET_NOTIFICATION_ARB 0x8261
#endif /* WGL_ARB_create_context_robustness */
#ifndef WGL_ARB_extensions_string
#define WGL_ARB_extensions_string 1
typedef const char *(WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
#ifdef WGL_WGLEXT_PROTOTYPES
const char *WINAPI wglGetExtensionsStringARB (HDC hdc);
#endif
#endif /* WGL_ARB_extensions_string */
#ifndef WGL_ARB_framebuffer_sRGB
#define WGL_ARB_framebuffer_sRGB 1
#define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9
#endif /* WGL_ARB_framebuffer_sRGB */
#ifndef WGL_ARB_make_current_read
#define WGL_ARB_make_current_read 1
#define ERROR_INVALID_PIXEL_TYPE_ARB 0x2043
#define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054
typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTARBPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCARBPROC) (void);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglMakeContextCurrentARB (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
HDC WINAPI wglGetCurrentReadDCARB (void);
#endif
#endif /* WGL_ARB_make_current_read */
#ifndef WGL_ARB_multisample
#define WGL_ARB_multisample 1
#define WGL_SAMPLE_BUFFERS_ARB 0x2041
#define WGL_SAMPLES_ARB 0x2042
#endif /* WGL_ARB_multisample */
#ifndef WGL_ARB_pbuffer
#define WGL_ARB_pbuffer 1
DECLARE_HANDLE(HPBUFFERARB);
#define WGL_DRAW_TO_PBUFFER_ARB 0x202D
#define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E
#define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F
#define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030
#define WGL_PBUFFER_LARGEST_ARB 0x2033
#define WGL_PBUFFER_WIDTH_ARB 0x2034
#define WGL_PBUFFER_HEIGHT_ARB 0x2035
#define WGL_PBUFFER_LOST_ARB 0x2036
typedef HPBUFFERARB (WINAPI * PFNWGLCREATEPBUFFERARBPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
typedef HDC (WINAPI * PFNWGLGETPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer);
typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer, HDC hDC);
typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFERARBPROC) (HPBUFFERARB hPbuffer);
typedef BOOL (WINAPI * PFNWGLQUERYPBUFFERARBPROC) (HPBUFFERARB hPbuffer, int iAttribute, int *piValue);
#ifdef WGL_WGLEXT_PROTOTYPES
HPBUFFERARB WINAPI wglCreatePbufferARB (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
HDC WINAPI wglGetPbufferDCARB (HPBUFFERARB hPbuffer);
int WINAPI wglReleasePbufferDCARB (HPBUFFERARB hPbuffer, HDC hDC);
BOOL WINAPI wglDestroyPbufferARB (HPBUFFERARB hPbuffer);
BOOL WINAPI wglQueryPbufferARB (HPBUFFERARB hPbuffer, int iAttribute, int *piValue);
#endif
#endif /* WGL_ARB_pbuffer */
#ifndef WGL_ARB_pixel_format
#define WGL_ARB_pixel_format 1
#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
#define WGL_DRAW_TO_WINDOW_ARB 0x2001
#define WGL_DRAW_TO_BITMAP_ARB 0x2002
#define WGL_ACCELERATION_ARB 0x2003
#define WGL_NEED_PALETTE_ARB 0x2004
#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
#define WGL_SWAP_METHOD_ARB 0x2007
#define WGL_NUMBER_OVERLAYS_ARB 0x2008
#define WGL_NUMBER_UNDERLAYS_ARB 0x2009
#define WGL_TRANSPARENT_ARB 0x200A
#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
#define WGL_SHARE_DEPTH_ARB 0x200C
#define WGL_SHARE_STENCIL_ARB 0x200D
#define WGL_SHARE_ACCUM_ARB 0x200E
#define WGL_SUPPORT_GDI_ARB 0x200F
#define WGL_SUPPORT_OPENGL_ARB 0x2010
#define WGL_DOUBLE_BUFFER_ARB 0x2011
#define WGL_STEREO_ARB 0x2012
#define WGL_PIXEL_TYPE_ARB 0x2013
#define WGL_COLOR_BITS_ARB 0x2014
#define WGL_RED_BITS_ARB 0x2015
#define WGL_RED_SHIFT_ARB 0x2016
#define WGL_GREEN_BITS_ARB 0x2017
#define WGL_GREEN_SHIFT_ARB 0x2018
#define WGL_BLUE_BITS_ARB 0x2019
#define WGL_BLUE_SHIFT_ARB 0x201A
#define WGL_ALPHA_BITS_ARB 0x201B
#define WGL_ALPHA_SHIFT_ARB 0x201C
#define WGL_ACCUM_BITS_ARB 0x201D
#define WGL_ACCUM_RED_BITS_ARB 0x201E
#define WGL_ACCUM_GREEN_BITS_ARB 0x201F
#define WGL_ACCUM_BLUE_BITS_ARB 0x2020
#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
#define WGL_DEPTH_BITS_ARB 0x2022
#define WGL_STENCIL_BITS_ARB 0x2023
#define WGL_AUX_BUFFERS_ARB 0x2024
#define WGL_NO_ACCELERATION_ARB 0x2025
#define WGL_GENERIC_ACCELERATION_ARB 0x2026
#define WGL_FULL_ACCELERATION_ARB 0x2027
#define WGL_SWAP_EXCHANGE_ARB 0x2028
#define WGL_SWAP_COPY_ARB 0x2029
#define WGL_SWAP_UNDEFINED_ARB 0x202A
#define WGL_TYPE_RGBA_ARB 0x202B
#define WGL_TYPE_COLORINDEX_ARB 0x202C
typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues);
typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglGetPixelFormatAttribivARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
BOOL WINAPI wglGetPixelFormatAttribfvARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues);
BOOL WINAPI wglChoosePixelFormatARB (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
#endif
#endif /* WGL_ARB_pixel_format */
#ifndef WGL_ARB_pixel_format_float
#define WGL_ARB_pixel_format_float 1
#define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0
#endif /* WGL_ARB_pixel_format_float */
#ifndef WGL_ARB_render_texture
#define WGL_ARB_render_texture 1
#define WGL_BIND_TO_TEXTURE_RGB_ARB 0x2070
#define WGL_BIND_TO_TEXTURE_RGBA_ARB 0x2071
#define WGL_TEXTURE_FORMAT_ARB 0x2072
#define WGL_TEXTURE_TARGET_ARB 0x2073
#define WGL_MIPMAP_TEXTURE_ARB 0x2074
#define WGL_TEXTURE_RGB_ARB 0x2075
#define WGL_TEXTURE_RGBA_ARB 0x2076
#define WGL_NO_TEXTURE_ARB 0x2077
#define WGL_TEXTURE_CUBE_MAP_ARB 0x2078
#define WGL_TEXTURE_1D_ARB 0x2079
#define WGL_TEXTURE_2D_ARB 0x207A
#define WGL_MIPMAP_LEVEL_ARB 0x207B
#define WGL_CUBE_MAP_FACE_ARB 0x207C
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x207D
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x207E
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x207F
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x2080
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x2081
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x2082
#define WGL_FRONT_LEFT_ARB 0x2083
#define WGL_FRONT_RIGHT_ARB 0x2084
#define WGL_BACK_LEFT_ARB 0x2085
#define WGL_BACK_RIGHT_ARB 0x2086
#define WGL_AUX0_ARB 0x2087
#define WGL_AUX1_ARB 0x2088
#define WGL_AUX2_ARB 0x2089
#define WGL_AUX3_ARB 0x208A
#define WGL_AUX4_ARB 0x208B
#define WGL_AUX5_ARB 0x208C
#define WGL_AUX6_ARB 0x208D
#define WGL_AUX7_ARB 0x208E
#define WGL_AUX8_ARB 0x208F
#define WGL_AUX9_ARB 0x2090
typedef BOOL (WINAPI * PFNWGLBINDTEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer);
typedef BOOL (WINAPI * PFNWGLRELEASETEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer);
typedef BOOL (WINAPI * PFNWGLSETPBUFFERATTRIBARBPROC) (HPBUFFERARB hPbuffer, const int *piAttribList);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglBindTexImageARB (HPBUFFERARB hPbuffer, int iBuffer);
BOOL WINAPI wglReleaseTexImageARB (HPBUFFERARB hPbuffer, int iBuffer);
BOOL WINAPI wglSetPbufferAttribARB (HPBUFFERARB hPbuffer, const int *piAttribList);
#endif
#endif /* WGL_ARB_render_texture */
#ifndef WGL_ARB_robustness_application_isolation
#define WGL_ARB_robustness_application_isolation 1
#define WGL_CONTEXT_RESET_ISOLATION_BIT_ARB 0x00000008
#endif /* WGL_ARB_robustness_application_isolation */
#ifndef WGL_ARB_robustness_share_group_isolation
#define WGL_ARB_robustness_share_group_isolation 1
#endif /* WGL_ARB_robustness_share_group_isolation */
#ifndef WGL_3DFX_multisample
#define WGL_3DFX_multisample 1
#define WGL_SAMPLE_BUFFERS_3DFX 0x2060
#define WGL_SAMPLES_3DFX 0x2061
#endif /* WGL_3DFX_multisample */
#ifndef WGL_3DL_stereo_control
#define WGL_3DL_stereo_control 1
#define WGL_STEREO_EMITTER_ENABLE_3DL 0x2055
#define WGL_STEREO_EMITTER_DISABLE_3DL 0x2056
#define WGL_STEREO_POLARITY_NORMAL_3DL 0x2057
#define WGL_STEREO_POLARITY_INVERT_3DL 0x2058
typedef BOOL (WINAPI * PFNWGLSETSTEREOEMITTERSTATE3DLPROC) (HDC hDC, UINT uState);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglSetStereoEmitterState3DL (HDC hDC, UINT uState);
#endif
#endif /* WGL_3DL_stereo_control */
#ifndef WGL_AMD_gpu_association
#define WGL_AMD_gpu_association 1
#define WGL_GPU_VENDOR_AMD 0x1F00
#define WGL_GPU_RENDERER_STRING_AMD 0x1F01
#define WGL_GPU_OPENGL_VERSION_STRING_AMD 0x1F02
#define WGL_GPU_FASTEST_TARGET_GPUS_AMD 0x21A2
#define WGL_GPU_RAM_AMD 0x21A3
#define WGL_GPU_CLOCK_AMD 0x21A4
#define WGL_GPU_NUM_PIPES_AMD 0x21A5
#define WGL_GPU_NUM_SIMD_AMD 0x21A6
#define WGL_GPU_NUM_RB_AMD 0x21A7
#define WGL_GPU_NUM_SPI_AMD 0x21A8
typedef UINT (WINAPI * PFNWGLGETGPUIDSAMDPROC) (UINT maxCount, UINT *ids);
typedef INT (WINAPI * PFNWGLGETGPUINFOAMDPROC) (UINT id, INT property, GLenum dataType, UINT size, void *data);
typedef UINT (WINAPI * PFNWGLGETCONTEXTGPUIDAMDPROC) (HGLRC hglrc);
typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTAMDPROC) (UINT id);
typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTATTRIBSAMDPROC) (UINT id, HGLRC hShareContext, const int *attribList);
typedef BOOL (WINAPI * PFNWGLDELETEASSOCIATEDCONTEXTAMDPROC) (HGLRC hglrc);
typedef BOOL (WINAPI * PFNWGLMAKEASSOCIATEDCONTEXTCURRENTAMDPROC) (HGLRC hglrc);
typedef HGLRC (WINAPI * PFNWGLGETCURRENTASSOCIATEDCONTEXTAMDPROC) (void);
typedef VOID (WINAPI * PFNWGLBLITCONTEXTFRAMEBUFFERAMDPROC) (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
#ifdef WGL_WGLEXT_PROTOTYPES
UINT WINAPI wglGetGPUIDsAMD (UINT maxCount, UINT *ids);
INT WINAPI wglGetGPUInfoAMD (UINT id, INT property, GLenum dataType, UINT size, void *data);
UINT WINAPI wglGetContextGPUIDAMD (HGLRC hglrc);
HGLRC WINAPI wglCreateAssociatedContextAMD (UINT id);
HGLRC WINAPI wglCreateAssociatedContextAttribsAMD (UINT id, HGLRC hShareContext, const int *attribList);
BOOL WINAPI wglDeleteAssociatedContextAMD (HGLRC hglrc);
BOOL WINAPI wglMakeAssociatedContextCurrentAMD (HGLRC hglrc);
HGLRC WINAPI wglGetCurrentAssociatedContextAMD (void);
VOID WINAPI wglBlitContextFramebufferAMD (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
#endif
#endif /* WGL_AMD_gpu_association */
#ifndef WGL_ATI_pixel_format_float
#define WGL_ATI_pixel_format_float 1
#define WGL_TYPE_RGBA_FLOAT_ATI 0x21A0
#endif /* WGL_ATI_pixel_format_float */
#ifndef WGL_ATI_render_texture_rectangle
#define WGL_ATI_render_texture_rectangle 1
#define WGL_TEXTURE_RECTANGLE_ATI 0x21A5
#endif /* WGL_ATI_render_texture_rectangle */
#ifndef WGL_EXT_colorspace
#define WGL_EXT_colorspace 1
#define WGL_COLORSPACE_EXT 0x309D
#define WGL_COLORSPACE_SRGB_EXT 0x3089
#define WGL_COLORSPACE_LINEAR_EXT 0x308A
#endif /* WGL_EXT_colorspace */
#ifndef WGL_EXT_create_context_es2_profile
#define WGL_EXT_create_context_es2_profile 1
#define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004
#endif /* WGL_EXT_create_context_es2_profile */
#ifndef WGL_EXT_create_context_es_profile
#define WGL_EXT_create_context_es_profile 1
#define WGL_CONTEXT_ES_PROFILE_BIT_EXT 0x00000004
#endif /* WGL_EXT_create_context_es_profile */
#ifndef WGL_EXT_depth_float
#define WGL_EXT_depth_float 1
#define WGL_DEPTH_FLOAT_EXT 0x2040
#endif /* WGL_EXT_depth_float */
#ifndef WGL_EXT_display_color_table
#define WGL_EXT_display_color_table 1
typedef GLboolean (WINAPI * PFNWGLCREATEDISPLAYCOLORTABLEEXTPROC) (GLushort id);
typedef GLboolean (WINAPI * PFNWGLLOADDISPLAYCOLORTABLEEXTPROC) (const GLushort *table, GLuint length);
typedef GLboolean (WINAPI * PFNWGLBINDDISPLAYCOLORTABLEEXTPROC) (GLushort id);
typedef VOID (WINAPI * PFNWGLDESTROYDISPLAYCOLORTABLEEXTPROC) (GLushort id);
#ifdef WGL_WGLEXT_PROTOTYPES
GLboolean WINAPI wglCreateDisplayColorTableEXT (GLushort id);
GLboolean WINAPI wglLoadDisplayColorTableEXT (const GLushort *table, GLuint length);
GLboolean WINAPI wglBindDisplayColorTableEXT (GLushort id);
VOID WINAPI wglDestroyDisplayColorTableEXT (GLushort id);
#endif
#endif /* WGL_EXT_display_color_table */
#ifndef WGL_EXT_extensions_string
#define WGL_EXT_extensions_string 1
typedef const char *(WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC) (void);
#ifdef WGL_WGLEXT_PROTOTYPES
const char *WINAPI wglGetExtensionsStringEXT (void);
#endif
#endif /* WGL_EXT_extensions_string */
#ifndef WGL_EXT_framebuffer_sRGB
#define WGL_EXT_framebuffer_sRGB 1
#define WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20A9
#endif /* WGL_EXT_framebuffer_sRGB */
#ifndef WGL_EXT_make_current_read
#define WGL_EXT_make_current_read 1
#define ERROR_INVALID_PIXEL_TYPE_EXT 0x2043
typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTEXTPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCEXTPROC) (void);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglMakeContextCurrentEXT (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
HDC WINAPI wglGetCurrentReadDCEXT (void);
#endif
#endif /* WGL_EXT_make_current_read */
#ifndef WGL_EXT_multisample
#define WGL_EXT_multisample 1
#define WGL_SAMPLE_BUFFERS_EXT 0x2041
#define WGL_SAMPLES_EXT 0x2042
#endif /* WGL_EXT_multisample */
#ifndef WGL_EXT_pbuffer
#define WGL_EXT_pbuffer 1
DECLARE_HANDLE(HPBUFFEREXT);
#define WGL_DRAW_TO_PBUFFER_EXT 0x202D
#define WGL_MAX_PBUFFER_PIXELS_EXT 0x202E
#define WGL_MAX_PBUFFER_WIDTH_EXT 0x202F
#define WGL_MAX_PBUFFER_HEIGHT_EXT 0x2030
#define WGL_OPTIMAL_PBUFFER_WIDTH_EXT 0x2031
#define WGL_OPTIMAL_PBUFFER_HEIGHT_EXT 0x2032
#define WGL_PBUFFER_LARGEST_EXT 0x2033
#define WGL_PBUFFER_WIDTH_EXT 0x2034
#define WGL_PBUFFER_HEIGHT_EXT 0x2035
typedef HPBUFFEREXT (WINAPI * PFNWGLCREATEPBUFFEREXTPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
typedef HDC (WINAPI * PFNWGLGETPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer);
typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer, HDC hDC);
typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer);
typedef BOOL (WINAPI * PFNWGLQUERYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer, int iAttribute, int *piValue);
#ifdef WGL_WGLEXT_PROTOTYPES
HPBUFFEREXT WINAPI wglCreatePbufferEXT (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
HDC WINAPI wglGetPbufferDCEXT (HPBUFFEREXT hPbuffer);
int WINAPI wglReleasePbufferDCEXT (HPBUFFEREXT hPbuffer, HDC hDC);
BOOL WINAPI wglDestroyPbufferEXT (HPBUFFEREXT hPbuffer);
BOOL WINAPI wglQueryPbufferEXT (HPBUFFEREXT hPbuffer, int iAttribute, int *piValue);
#endif
#endif /* WGL_EXT_pbuffer */
#ifndef WGL_EXT_pixel_format
#define WGL_EXT_pixel_format 1
#define WGL_NUMBER_PIXEL_FORMATS_EXT 0x2000
#define WGL_DRAW_TO_WINDOW_EXT 0x2001
#define WGL_DRAW_TO_BITMAP_EXT 0x2002
#define WGL_ACCELERATION_EXT 0x2003
#define WGL_NEED_PALETTE_EXT 0x2004
#define WGL_NEED_SYSTEM_PALETTE_EXT 0x2005
#define WGL_SWAP_LAYER_BUFFERS_EXT 0x2006
#define WGL_SWAP_METHOD_EXT 0x2007
#define WGL_NUMBER_OVERLAYS_EXT 0x2008
#define WGL_NUMBER_UNDERLAYS_EXT 0x2009
#define WGL_TRANSPARENT_EXT 0x200A
#define WGL_TRANSPARENT_VALUE_EXT 0x200B
#define WGL_SHARE_DEPTH_EXT 0x200C
#define WGL_SHARE_STENCIL_EXT 0x200D
#define WGL_SHARE_ACCUM_EXT 0x200E
#define WGL_SUPPORT_GDI_EXT 0x200F
#define WGL_SUPPORT_OPENGL_EXT 0x2010
#define WGL_DOUBLE_BUFFER_EXT 0x2011
#define WGL_STEREO_EXT 0x2012
#define WGL_PIXEL_TYPE_EXT 0x2013
#define WGL_COLOR_BITS_EXT 0x2014
#define WGL_RED_BITS_EXT 0x2015
#define WGL_RED_SHIFT_EXT 0x2016
#define WGL_GREEN_BITS_EXT 0x2017
#define WGL_GREEN_SHIFT_EXT 0x2018
#define WGL_BLUE_BITS_EXT 0x2019
#define WGL_BLUE_SHIFT_EXT 0x201A
#define WGL_ALPHA_BITS_EXT 0x201B
#define WGL_ALPHA_SHIFT_EXT 0x201C
#define WGL_ACCUM_BITS_EXT 0x201D
#define WGL_ACCUM_RED_BITS_EXT 0x201E
#define WGL_ACCUM_GREEN_BITS_EXT 0x201F
#define WGL_ACCUM_BLUE_BITS_EXT 0x2020
#define WGL_ACCUM_ALPHA_BITS_EXT 0x2021
#define WGL_DEPTH_BITS_EXT 0x2022
#define WGL_STENCIL_BITS_EXT 0x2023
#define WGL_AUX_BUFFERS_EXT 0x2024
#define WGL_NO_ACCELERATION_EXT 0x2025
#define WGL_GENERIC_ACCELERATION_EXT 0x2026
#define WGL_FULL_ACCELERATION_EXT 0x2027
#define WGL_SWAP_EXCHANGE_EXT 0x2028
#define WGL_SWAP_COPY_EXT 0x2029
#define WGL_SWAP_UNDEFINED_EXT 0x202A
#define WGL_TYPE_RGBA_EXT 0x202B
#define WGL_TYPE_COLORINDEX_EXT 0x202C
typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues);
typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues);
typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATEXTPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglGetPixelFormatAttribivEXT (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues);
BOOL WINAPI wglGetPixelFormatAttribfvEXT (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues);
BOOL WINAPI wglChoosePixelFormatEXT (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
#endif
#endif /* WGL_EXT_pixel_format */
#ifndef WGL_EXT_pixel_format_packed_float
#define WGL_EXT_pixel_format_packed_float 1
#define WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT 0x20A8
#endif /* WGL_EXT_pixel_format_packed_float */
#ifndef WGL_EXT_swap_control
#define WGL_EXT_swap_control 1
typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglSwapIntervalEXT (int interval);
int WINAPI wglGetSwapIntervalEXT (void);
#endif
#endif /* WGL_EXT_swap_control */
#ifndef WGL_EXT_swap_control_tear
#define WGL_EXT_swap_control_tear 1
#endif /* WGL_EXT_swap_control_tear */
#ifndef WGL_I3D_digital_video_control
#define WGL_I3D_digital_video_control 1
#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D 0x2050
#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D 0x2051
#define WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D 0x2052
#define WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D 0x2053
typedef BOOL (WINAPI * PFNWGLGETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int *piValue);
typedef BOOL (WINAPI * PFNWGLSETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int *piValue);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglGetDigitalVideoParametersI3D (HDC hDC, int iAttribute, int *piValue);
BOOL WINAPI wglSetDigitalVideoParametersI3D (HDC hDC, int iAttribute, const int *piValue);
#endif
#endif /* WGL_I3D_digital_video_control */
#ifndef WGL_I3D_gamma
#define WGL_I3D_gamma 1
#define WGL_GAMMA_TABLE_SIZE_I3D 0x204E
#define WGL_GAMMA_EXCLUDE_DESKTOP_I3D 0x204F
typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int *piValue);
typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int *piValue);
typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, USHORT *puBlue);
typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, const USHORT *puRed, const USHORT *puGreen, const USHORT *puBlue);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglGetGammaTableParametersI3D (HDC hDC, int iAttribute, int *piValue);
BOOL WINAPI wglSetGammaTableParametersI3D (HDC hDC, int iAttribute, const int *piValue);
BOOL WINAPI wglGetGammaTableI3D (HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, USHORT *puBlue);
BOOL WINAPI wglSetGammaTableI3D (HDC hDC, int iEntries, const USHORT *puRed, const USHORT *puGreen, const USHORT *puBlue);
#endif
#endif /* WGL_I3D_gamma */
#ifndef WGL_I3D_genlock
#define WGL_I3D_genlock 1
#define WGL_GENLOCK_SOURCE_MULTIVIEW_I3D 0x2044
#define WGL_GENLOCK_SOURCE_EXTERNAL_SYNC_I3D 0x2045
#define WGL_GENLOCK_SOURCE_EXTERNAL_FIELD_I3D 0x2046
#define WGL_GENLOCK_SOURCE_EXTERNAL_TTL_I3D 0x2047
#define WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D 0x2048
#define WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D 0x2049
#define WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D 0x204A
#define WGL_GENLOCK_SOURCE_EDGE_RISING_I3D 0x204B
#define WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D 0x204C
typedef BOOL (WINAPI * PFNWGLENABLEGENLOCKI3DPROC) (HDC hDC);
typedef BOOL (WINAPI * PFNWGLDISABLEGENLOCKI3DPROC) (HDC hDC);
typedef BOOL (WINAPI * PFNWGLISENABLEDGENLOCKI3DPROC) (HDC hDC, BOOL *pFlag);
typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEI3DPROC) (HDC hDC, UINT uSource);
typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEI3DPROC) (HDC hDC, UINT *uSource);
typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT uEdge);
typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT *uEdge);
typedef BOOL (WINAPI * PFNWGLGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT uRate);
typedef BOOL (WINAPI * PFNWGLGETGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT *uRate);
typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT uDelay);
typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT *uDelay);
typedef BOOL (WINAPI * PFNWGLQUERYGENLOCKMAXSOURCEDELAYI3DPROC) (HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglEnableGenlockI3D (HDC hDC);
BOOL WINAPI wglDisableGenlockI3D (HDC hDC);
BOOL WINAPI wglIsEnabledGenlockI3D (HDC hDC, BOOL *pFlag);
BOOL WINAPI wglGenlockSourceI3D (HDC hDC, UINT uSource);
BOOL WINAPI wglGetGenlockSourceI3D (HDC hDC, UINT *uSource);
BOOL WINAPI wglGenlockSourceEdgeI3D (HDC hDC, UINT uEdge);
BOOL WINAPI wglGetGenlockSourceEdgeI3D (HDC hDC, UINT *uEdge);
BOOL WINAPI wglGenlockSampleRateI3D (HDC hDC, UINT uRate);
BOOL WINAPI wglGetGenlockSampleRateI3D (HDC hDC, UINT *uRate);
BOOL WINAPI wglGenlockSourceDelayI3D (HDC hDC, UINT uDelay);
BOOL WINAPI wglGetGenlockSourceDelayI3D (HDC hDC, UINT *uDelay);
BOOL WINAPI wglQueryGenlockMaxSourceDelayI3D (HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay);
#endif
#endif /* WGL_I3D_genlock */
#ifndef WGL_I3D_image_buffer
#define WGL_I3D_image_buffer 1
#define WGL_IMAGE_BUFFER_MIN_ACCESS_I3D 0x00000001
#define WGL_IMAGE_BUFFER_LOCK_I3D 0x00000002
typedef LPVOID (WINAPI * PFNWGLCREATEIMAGEBUFFERI3DPROC) (HDC hDC, DWORD dwSize, UINT uFlags);
typedef BOOL (WINAPI * PFNWGLDESTROYIMAGEBUFFERI3DPROC) (HDC hDC, LPVOID pAddress);
typedef BOOL (WINAPI * PFNWGLASSOCIATEIMAGEBUFFEREVENTSI3DPROC) (HDC hDC, const HANDLE *pEvent, const LPVOID *pAddress, const DWORD *pSize, UINT count);
typedef BOOL (WINAPI * PFNWGLRELEASEIMAGEBUFFEREVENTSI3DPROC) (HDC hDC, const LPVOID *pAddress, UINT count);
#ifdef WGL_WGLEXT_PROTOTYPES
LPVOID WINAPI wglCreateImageBufferI3D (HDC hDC, DWORD dwSize, UINT uFlags);
BOOL WINAPI wglDestroyImageBufferI3D (HDC hDC, LPVOID pAddress);
BOOL WINAPI wglAssociateImageBufferEventsI3D (HDC hDC, const HANDLE *pEvent, const LPVOID *pAddress, const DWORD *pSize, UINT count);
BOOL WINAPI wglReleaseImageBufferEventsI3D (HDC hDC, const LPVOID *pAddress, UINT count);
#endif
#endif /* WGL_I3D_image_buffer */
#ifndef WGL_I3D_swap_frame_lock
#define WGL_I3D_swap_frame_lock 1
typedef BOOL (WINAPI * PFNWGLENABLEFRAMELOCKI3DPROC) (void);
typedef BOOL (WINAPI * PFNWGLDISABLEFRAMELOCKI3DPROC) (void);
typedef BOOL (WINAPI * PFNWGLISENABLEDFRAMELOCKI3DPROC) (BOOL *pFlag);
typedef BOOL (WINAPI * PFNWGLQUERYFRAMELOCKMASTERI3DPROC) (BOOL *pFlag);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglEnableFrameLockI3D (void);
BOOL WINAPI wglDisableFrameLockI3D (void);
BOOL WINAPI wglIsEnabledFrameLockI3D (BOOL *pFlag);
BOOL WINAPI wglQueryFrameLockMasterI3D (BOOL *pFlag);
#endif
#endif /* WGL_I3D_swap_frame_lock */
#ifndef WGL_I3D_swap_frame_usage
#define WGL_I3D_swap_frame_usage 1
typedef BOOL (WINAPI * PFNWGLGETFRAMEUSAGEI3DPROC) (float *pUsage);
typedef BOOL (WINAPI * PFNWGLBEGINFRAMETRACKINGI3DPROC) (void);
typedef BOOL (WINAPI * PFNWGLENDFRAMETRACKINGI3DPROC) (void);
typedef BOOL (WINAPI * PFNWGLQUERYFRAMETRACKINGI3DPROC) (DWORD *pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglGetFrameUsageI3D (float *pUsage);
BOOL WINAPI wglBeginFrameTrackingI3D (void);
BOOL WINAPI wglEndFrameTrackingI3D (void);
BOOL WINAPI wglQueryFrameTrackingI3D (DWORD *pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage);
#endif
#endif /* WGL_I3D_swap_frame_usage */
#ifndef WGL_NV_DX_interop
#define WGL_NV_DX_interop 1
#define WGL_ACCESS_READ_ONLY_NV 0x00000000
#define WGL_ACCESS_READ_WRITE_NV 0x00000001
#define WGL_ACCESS_WRITE_DISCARD_NV 0x00000002
typedef BOOL (WINAPI * PFNWGLDXSETRESOURCESHAREHANDLENVPROC) (void *dxObject, HANDLE shareHandle);
typedef HANDLE (WINAPI * PFNWGLDXOPENDEVICENVPROC) (void *dxDevice);
typedef BOOL (WINAPI * PFNWGLDXCLOSEDEVICENVPROC) (HANDLE hDevice);
typedef HANDLE (WINAPI * PFNWGLDXREGISTEROBJECTNVPROC) (HANDLE hDevice, void *dxObject, GLuint name, GLenum type, GLenum access);
typedef BOOL (WINAPI * PFNWGLDXUNREGISTEROBJECTNVPROC) (HANDLE hDevice, HANDLE hObject);
typedef BOOL (WINAPI * PFNWGLDXOBJECTACCESSNVPROC) (HANDLE hObject, GLenum access);
typedef BOOL (WINAPI * PFNWGLDXLOCKOBJECTSNVPROC) (HANDLE hDevice, GLint count, HANDLE *hObjects);
typedef BOOL (WINAPI * PFNWGLDXUNLOCKOBJECTSNVPROC) (HANDLE hDevice, GLint count, HANDLE *hObjects);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglDXSetResourceShareHandleNV (void *dxObject, HANDLE shareHandle);
HANDLE WINAPI wglDXOpenDeviceNV (void *dxDevice);
BOOL WINAPI wglDXCloseDeviceNV (HANDLE hDevice);
HANDLE WINAPI wglDXRegisterObjectNV (HANDLE hDevice, void *dxObject, GLuint name, GLenum type, GLenum access);
BOOL WINAPI wglDXUnregisterObjectNV (HANDLE hDevice, HANDLE hObject);
BOOL WINAPI wglDXObjectAccessNV (HANDLE hObject, GLenum access);
BOOL WINAPI wglDXLockObjectsNV (HANDLE hDevice, GLint count, HANDLE *hObjects);
BOOL WINAPI wglDXUnlockObjectsNV (HANDLE hDevice, GLint count, HANDLE *hObjects);
#endif
#endif /* WGL_NV_DX_interop */
#ifndef WGL_NV_DX_interop2
#define WGL_NV_DX_interop2 1
#endif /* WGL_NV_DX_interop2 */
#ifndef WGL_NV_copy_image
#define WGL_NV_copy_image 1
typedef BOOL (WINAPI * PFNWGLCOPYIMAGESUBDATANVPROC) (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglCopyImageSubDataNV (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth);
#endif
#endif /* WGL_NV_copy_image */
#ifndef WGL_NV_delay_before_swap
#define WGL_NV_delay_before_swap 1
typedef BOOL (WINAPI * PFNWGLDELAYBEFORESWAPNVPROC) (HDC hDC, GLfloat seconds);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglDelayBeforeSwapNV (HDC hDC, GLfloat seconds);
#endif
#endif /* WGL_NV_delay_before_swap */
#ifndef WGL_NV_float_buffer
#define WGL_NV_float_buffer 1
#define WGL_FLOAT_COMPONENTS_NV 0x20B0
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4
#define WGL_TEXTURE_FLOAT_R_NV 0x20B5
#define WGL_TEXTURE_FLOAT_RG_NV 0x20B6
#define WGL_TEXTURE_FLOAT_RGB_NV 0x20B7
#define WGL_TEXTURE_FLOAT_RGBA_NV 0x20B8
#endif /* WGL_NV_float_buffer */
#ifndef WGL_NV_gpu_affinity
#define WGL_NV_gpu_affinity 1
DECLARE_HANDLE(HGPUNV);
struct _GPU_DEVICE {
DWORD cb;
CHAR DeviceName[32];
CHAR DeviceString[128];
DWORD Flags;
RECT rcVirtualScreen;
};
typedef struct _GPU_DEVICE *PGPU_DEVICE;
#define ERROR_INCOMPATIBLE_AFFINITY_MASKS_NV 0x20D0
#define ERROR_MISSING_AFFINITY_MASK_NV 0x20D1
typedef BOOL (WINAPI * PFNWGLENUMGPUSNVPROC) (UINT iGpuIndex, HGPUNV *phGpu);
typedef BOOL (WINAPI * PFNWGLENUMGPUDEVICESNVPROC) (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice);
typedef HDC (WINAPI * PFNWGLCREATEAFFINITYDCNVPROC) (const HGPUNV *phGpuList);
typedef BOOL (WINAPI * PFNWGLENUMGPUSFROMAFFINITYDCNVPROC) (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu);
typedef BOOL (WINAPI * PFNWGLDELETEDCNVPROC) (HDC hdc);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglEnumGpusNV (UINT iGpuIndex, HGPUNV *phGpu);
BOOL WINAPI wglEnumGpuDevicesNV (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice);
HDC WINAPI wglCreateAffinityDCNV (const HGPUNV *phGpuList);
BOOL WINAPI wglEnumGpusFromAffinityDCNV (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu);
BOOL WINAPI wglDeleteDCNV (HDC hdc);
#endif
#endif /* WGL_NV_gpu_affinity */
#ifndef WGL_NV_multigpu_context
#define WGL_NV_multigpu_context 1
#define WGL_CONTEXT_MULTIGPU_ATTRIB_NV 0x20AA
#define WGL_CONTEXT_MULTIGPU_ATTRIB_SINGLE_NV 0x20AB
#define WGL_CONTEXT_MULTIGPU_ATTRIB_AFR_NV 0x20AC
#define WGL_CONTEXT_MULTIGPU_ATTRIB_MULTICAST_NV 0x20AD
#define WGL_CONTEXT_MULTIGPU_ATTRIB_MULTI_DISPLAY_MULTICAST_NV 0x20AE
#endif /* WGL_NV_multigpu_context */
#ifndef WGL_NV_multisample_coverage
#define WGL_NV_multisample_coverage 1
#define WGL_COVERAGE_SAMPLES_NV 0x2042
#define WGL_COLOR_SAMPLES_NV 0x20B9
#endif /* WGL_NV_multisample_coverage */
#ifndef WGL_NV_present_video
#define WGL_NV_present_video 1
DECLARE_HANDLE(HVIDEOOUTPUTDEVICENV);
#define WGL_NUM_VIDEO_SLOTS_NV 0x20F0
typedef int (WINAPI * PFNWGLENUMERATEVIDEODEVICESNVPROC) (HDC hDc, HVIDEOOUTPUTDEVICENV *phDeviceList);
typedef BOOL (WINAPI * PFNWGLBINDVIDEODEVICENVPROC) (HDC hDc, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int *piAttribList);
typedef BOOL (WINAPI * PFNWGLQUERYCURRENTCONTEXTNVPROC) (int iAttribute, int *piValue);
#ifdef WGL_WGLEXT_PROTOTYPES
int WINAPI wglEnumerateVideoDevicesNV (HDC hDc, HVIDEOOUTPUTDEVICENV *phDeviceList);
BOOL WINAPI wglBindVideoDeviceNV (HDC hDc, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int *piAttribList);
BOOL WINAPI wglQueryCurrentContextNV (int iAttribute, int *piValue);
#endif
#endif /* WGL_NV_present_video */
#ifndef WGL_NV_render_depth_texture
#define WGL_NV_render_depth_texture 1
#define WGL_BIND_TO_TEXTURE_DEPTH_NV 0x20A3
#define WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV 0x20A4
#define WGL_DEPTH_TEXTURE_FORMAT_NV 0x20A5
#define WGL_TEXTURE_DEPTH_COMPONENT_NV 0x20A6
#define WGL_DEPTH_COMPONENT_NV 0x20A7
#endif /* WGL_NV_render_depth_texture */
#ifndef WGL_NV_render_texture_rectangle
#define WGL_NV_render_texture_rectangle 1
#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV 0x20A0
#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV 0x20A1
#define WGL_TEXTURE_RECTANGLE_NV 0x20A2
#endif /* WGL_NV_render_texture_rectangle */
#ifndef WGL_NV_swap_group
#define WGL_NV_swap_group 1
typedef BOOL (WINAPI * PFNWGLJOINSWAPGROUPNVPROC) (HDC hDC, GLuint group);
typedef BOOL (WINAPI * PFNWGLBINDSWAPBARRIERNVPROC) (GLuint group, GLuint barrier);
typedef BOOL (WINAPI * PFNWGLQUERYSWAPGROUPNVPROC) (HDC hDC, GLuint *group, GLuint *barrier);
typedef BOOL (WINAPI * PFNWGLQUERYMAXSWAPGROUPSNVPROC) (HDC hDC, GLuint *maxGroups, GLuint *maxBarriers);
typedef BOOL (WINAPI * PFNWGLQUERYFRAMECOUNTNVPROC) (HDC hDC, GLuint *count);
typedef BOOL (WINAPI * PFNWGLRESETFRAMECOUNTNVPROC) (HDC hDC);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglJoinSwapGroupNV (HDC hDC, GLuint group);
BOOL WINAPI wglBindSwapBarrierNV (GLuint group, GLuint barrier);
BOOL WINAPI wglQuerySwapGroupNV (HDC hDC, GLuint *group, GLuint *barrier);
BOOL WINAPI wglQueryMaxSwapGroupsNV (HDC hDC, GLuint *maxGroups, GLuint *maxBarriers);
BOOL WINAPI wglQueryFrameCountNV (HDC hDC, GLuint *count);
BOOL WINAPI wglResetFrameCountNV (HDC hDC);
#endif
#endif /* WGL_NV_swap_group */
#ifndef WGL_NV_vertex_array_range
#define WGL_NV_vertex_array_range 1
typedef void *(WINAPI * PFNWGLALLOCATEMEMORYNVPROC) (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
typedef void (WINAPI * PFNWGLFREEMEMORYNVPROC) (void *pointer);
#ifdef WGL_WGLEXT_PROTOTYPES
void *WINAPI wglAllocateMemoryNV (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
void WINAPI wglFreeMemoryNV (void *pointer);
#endif
#endif /* WGL_NV_vertex_array_range */
#ifndef WGL_NV_video_capture
#define WGL_NV_video_capture 1
DECLARE_HANDLE(HVIDEOINPUTDEVICENV);
#define WGL_UNIQUE_ID_NV 0x20CE
#define WGL_NUM_VIDEO_CAPTURE_SLOTS_NV 0x20CF
typedef BOOL (WINAPI * PFNWGLBINDVIDEOCAPTUREDEVICENVPROC) (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice);
typedef UINT (WINAPI * PFNWGLENUMERATEVIDEOCAPTUREDEVICESNVPROC) (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList);
typedef BOOL (WINAPI * PFNWGLLOCKVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice);
typedef BOOL (WINAPI * PFNWGLQUERYVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue);
typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglBindVideoCaptureDeviceNV (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice);
UINT WINAPI wglEnumerateVideoCaptureDevicesNV (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList);
BOOL WINAPI wglLockVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice);
BOOL WINAPI wglQueryVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue);
BOOL WINAPI wglReleaseVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice);
#endif
#endif /* WGL_NV_video_capture */
#ifndef WGL_NV_video_output
#define WGL_NV_video_output 1
DECLARE_HANDLE(HPVIDEODEV);
#define WGL_BIND_TO_VIDEO_RGB_NV 0x20C0
#define WGL_BIND_TO_VIDEO_RGBA_NV 0x20C1
#define WGL_BIND_TO_VIDEO_RGB_AND_DEPTH_NV 0x20C2
#define WGL_VIDEO_OUT_COLOR_NV 0x20C3
#define WGL_VIDEO_OUT_ALPHA_NV 0x20C4
#define WGL_VIDEO_OUT_DEPTH_NV 0x20C5
#define WGL_VIDEO_OUT_COLOR_AND_ALPHA_NV 0x20C6
#define WGL_VIDEO_OUT_COLOR_AND_DEPTH_NV 0x20C7
#define WGL_VIDEO_OUT_FRAME 0x20C8
#define WGL_VIDEO_OUT_FIELD_1 0x20C9
#define WGL_VIDEO_OUT_FIELD_2 0x20CA
#define WGL_VIDEO_OUT_STACKED_FIELDS_1_2 0x20CB
#define WGL_VIDEO_OUT_STACKED_FIELDS_2_1 0x20CC
typedef BOOL (WINAPI * PFNWGLGETVIDEODEVICENVPROC) (HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice);
typedef BOOL (WINAPI * PFNWGLRELEASEVIDEODEVICENVPROC) (HPVIDEODEV hVideoDevice);
typedef BOOL (WINAPI * PFNWGLBINDVIDEOIMAGENVPROC) (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer);
typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOIMAGENVPROC) (HPBUFFERARB hPbuffer, int iVideoBuffer);
typedef BOOL (WINAPI * PFNWGLSENDPBUFFERTOVIDEONVPROC) (HPBUFFERARB hPbuffer, int iBufferType, unsigned long *pulCounterPbuffer, BOOL bBlock);
typedef BOOL (WINAPI * PFNWGLGETVIDEOINFONVPROC) (HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglGetVideoDeviceNV (HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice);
BOOL WINAPI wglReleaseVideoDeviceNV (HPVIDEODEV hVideoDevice);
BOOL WINAPI wglBindVideoImageNV (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer);
BOOL WINAPI wglReleaseVideoImageNV (HPBUFFERARB hPbuffer, int iVideoBuffer);
BOOL WINAPI wglSendPbufferToVideoNV (HPBUFFERARB hPbuffer, int iBufferType, unsigned long *pulCounterPbuffer, BOOL bBlock);
BOOL WINAPI wglGetVideoInfoNV (HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo);
#endif
#endif /* WGL_NV_video_output */
#ifndef WGL_OML_sync_control
#define WGL_OML_sync_control 1
typedef BOOL (WINAPI * PFNWGLGETSYNCVALUESOMLPROC) (HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc);
typedef BOOL (WINAPI * PFNWGLGETMSCRATEOMLPROC) (HDC hdc, INT32 *numerator, INT32 *denominator);
typedef INT64 (WINAPI * PFNWGLSWAPBUFFERSMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder);
typedef INT64 (WINAPI * PFNWGLSWAPLAYERBUFFERSMSCOMLPROC) (HDC hdc, INT fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder);
typedef BOOL (WINAPI * PFNWGLWAITFORMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64 *ust, INT64 *msc, INT64 *sbc);
typedef BOOL (WINAPI * PFNWGLWAITFORSBCOMLPROC) (HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc);
#ifdef WGL_WGLEXT_PROTOTYPES
BOOL WINAPI wglGetSyncValuesOML (HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc);
BOOL WINAPI wglGetMscRateOML (HDC hdc, INT32 *numerator, INT32 *denominator);
INT64 WINAPI wglSwapBuffersMscOML (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder);
INT64 WINAPI wglSwapLayerBuffersMscOML (HDC hdc, INT fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder);
BOOL WINAPI wglWaitForMscOML (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64 *ust, INT64 *msc, INT64 *sbc);
BOOL WINAPI wglWaitForSbcOML (HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc);
#endif
#endif /* WGL_OML_sync_control */
#ifdef __cplusplus
}
#endif
#endif

View File

@ -2,8 +2,9 @@
#include "../lumenarium_compiler_flags.h"
#include "../lumenarium_platform_common_includes.h"
#include "windows.h"
#include <windows.h>
#include <gl/gl.h>
#include <stdio.h>
#include "../../lumenarium_types.h"
#include "../lumenarium_platform.h"
@ -16,11 +17,18 @@ win32_get_last_error()
win32_last_error = GetLastError();
}
global bool running = true;
#include "lumenarium_win32_opengl.h"
global Win32_OpenGL_Extensions gl;
#include "lumenarium_win32_memory.cpp"
#include "lumenarium_win32_window.cpp"
#include "lumenarium_win32_time.cpp"
#include "lumenarium_win32_file.cpp"
#include "lumenarium_win32_thread.cpp"
#include "lumenarium_win32_graphics.cpp"
internal Platform_Key_Flags
win32_get_key_flags_mod()
@ -172,22 +180,25 @@ WinMain(
PSTR lpCmdLine,
INT nCmdShow)
{
App_State* state = lumenarium_init();
if (!has_flag(state->flags, AppState_IsRunning)) return 0;
// Window Setup
win32_main_window = win32_window_create(
hInstance, "Lumenarium", 1600, 900, win32_window_event_handler
);
win32_window_opengl_ctx_create(&win32_main_window, { 32, 8, 0 });
win32_window_create(
&win32_main_window,
hInstance,
"Lumenariumtest0",
1600,
900,
win32_window_event_handler
);
win32_time_init();
win32_files_init();
win32_threads_init();
App_State* state = lumenarium_init();
if (!has_flag(state->flags, AppState_IsRunning)) return 0;
Platform_Ticks ticks_start = platform_get_ticks();
while (has_flag(state->flags, AppState_IsRunning))
while (running && has_flag(state->flags, AppState_IsRunning))
{
win32_threads_reclaim();
lumenarium_frame_prepare(state);
@ -213,9 +224,14 @@ WinMain(
win32_window_handle_event(window_msg, &win32_main_window, state);
}
// NOTE(PS): WM_CLOSE and WM_DESTROY can both be issued
// the same frame, meaning our drawing context is destroyed
// before calling lumenarium_frame so skipping here to avoid
// using invalid resources
if (!running || !has_flag(state->flags, AppState_IsRunning)) continue;
lumenarium_frame(state);
// Swap Render Buffers
SwapBuffers(win32_main_window.dc);
////////////////////////////////////////
@ -236,7 +252,6 @@ WinMain(
lumenarium_cleanup(state);
// threads cleanup
for (u32 i = 1; i < win32_threads_cap; i++)
{
@ -244,6 +259,8 @@ WinMain(
TerminateThread(win32_threads[i], 0);
}
ExitProcess(0);
// windows cleanup
UnregisterClass(win32_main_window.window_class.lpszClassName, hInstance);
return 0;
}

View File

@ -0,0 +1,193 @@
#define win32_gl_no_error() win32_gl_no_error_()
void win32_gl_no_error_() {
u32 error = glGetError();
char* str = 0;
if (error) {
str = win32_gl_error_to_string(error);
}
assert(error == 0);
}
Platform_Geometry_Buffer
platform_geometry_buffer_create(
r32* vertices, u32 vertices_len,
u32* indices, u32 indices_len
){
Platform_Geometry_Buffer result = {};
gl.glGenVertexArrays(1, &result.buffer_id_vao);
win32_gl_no_error();
GLuint buffers[2];
gl.glGenBuffers(2, (GLuint*)buffers);
win32_gl_no_error();
result.buffer_id_vertices = buffers[0];
result.buffer_id_indices = buffers[1];
// Vertices
gl.glBindVertexArray(result.buffer_id_vao);
gl.glBindBuffer(GL_ARRAY_BUFFER, result.buffer_id_vertices);
win32_gl_no_error();
gl.glBufferData(
GL_ARRAY_BUFFER, sizeof(r32) * vertices_len, vertices, GL_STATIC_DRAW
);
win32_gl_no_error();
// Indices
gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, result.buffer_id_indices);
win32_gl_no_error();
gl.glBufferData(
GL_ELEMENT_ARRAY_BUFFER, sizeof(u32) * indices_len, indices, GL_STATIC_DRAW
);
win32_gl_no_error();
result.indices_len = indices_len;
gl.glBindBuffer(GL_ARRAY_BUFFER, NULL);
gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL);
return result;
}
Platform_Shader
platform_shader_create(
String code_vert, String code_frag, String* attrs, u32 attrs_len
){
Platform_Shader result = {};
GLuint shader_vert = gl.glCreateShader(GL_VERTEX_SHADER);
gl.glShaderSource(shader_vert, 1, (const char**)&code_vert.str, &(s32)code_vert.len);
gl.glCompileShader(shader_vert);
{ // errors
GLint shader_vert_compiled;
gl.glGetShaderiv(shader_vert, GL_COMPILE_STATUS, &shader_vert_compiled);
if (shader_vert_compiled != GL_TRUE)
{
GLsizei log_length = 0;
GLchar message[1024];
gl.glGetShaderInfoLog(shader_vert, 1024, &log_length, message);
invalid_code_path;
}
}
GLuint shader_frag = gl.glCreateShader(GL_FRAGMENT_SHADER);
gl.glShaderSource(shader_frag, 1, (const char**)&code_frag.str, &(s32)code_frag.len);
gl.glCompileShader(shader_frag);
{ // errors
GLint shader_frag_compiled;
gl.glGetShaderiv(shader_frag, GL_COMPILE_STATUS, &shader_frag_compiled);
if (shader_frag_compiled != GL_TRUE)
{
GLsizei log_length = 0;
GLchar message[1024];
gl.glGetShaderInfoLog(shader_frag, 1024, &log_length, message);
invalid_code_path;
}
}
result.id = (u32)gl.glCreateProgram();
gl.glAttachShader(result.id, shader_vert);
gl.glAttachShader(result.id, shader_frag);
gl.glLinkProgram(result.id);
GLint program_linked;
gl.glGetProgramiv(result.id, GL_LINK_STATUS, &program_linked);
if (program_linked != GL_TRUE)
{
GLsizei log_length = 0;
GLchar message[1024];
gl.glGetProgramInfoLog(result.id, 1024, &log_length, message);
invalid_code_path;
}
gl.glUseProgram(result.id);
// TODO(PS): delete the vert and frag programs
assert(attrs_len < PLATFORM_SHADER_MAX_ATTRS);
for (u32 i = 0; i < attrs_len; i++)
{
result.attrs[i] = gl.glGetAttribLocation(
result.id, (char*)attrs[i].str
);
}
result.attrs[attrs_len] = PLATFORM_SHADER_ATTR_LAST;
return result;
}
void
platform_geometry_bind(Platform_Geometry_Buffer geo)
{
gl.glBindVertexArray(geo.buffer_id_vertices);
win32_gl_no_error();
gl.glBindBuffer(GL_ARRAY_BUFFER, geo.buffer_id_vertices);
win32_gl_no_error();
gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, geo.buffer_id_indices);
win32_gl_no_error();
}
void
platform_shader_bind(Platform_Shader shader)
{
gl.glUseProgram(shader.id);
win32_gl_no_error();
for (u32 i = 0;
((i < PLATFORM_SHADER_MAX_ATTRS) && (shader.attrs[i] != PLATFORM_SHADER_ATTR_LAST));
i++)
{
gl.glEnableVertexAttribArray(shader.attrs[i]);
win32_gl_no_error();
}
}
void
platform_geometry_draw(
Platform_Geometry_Buffer geo
){
glDrawElements(GL_TRIANGLES, geo.indices_len, GL_UNSIGNED_INT, 0);
win32_gl_no_error();
}
void platform_vertex_attrib_pointer(
Platform_Geometry_Buffer geo, Platform_Shader shader, u32 attr_index
){
platform_geometry_bind(geo);
gl.glVertexAttribPointer(shader.attrs[attr_index], 4, GL_FLOAT, false, 0, 0);
win32_gl_no_error();
gl.glEnableVertexAttribArray(shader.attrs[attr_index]);
win32_gl_no_error();
}
void
platform_frame_begin(Platform_Graphics_Frame_Desc desc)
{
v4 cc = desc.clear_color;
glClearColor(cc.r, cc.g, cc.b, cc.a);
v2 vmin = desc.viewport_min;
v2 vmax = desc.viewport_max;
glViewport((GLsizei)vmin.x, (GLsizei)vmin.y, (GLint)vmax.x, (GLint)vmax.y);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
//glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void
platform_frame_clear()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

View File

@ -0,0 +1,80 @@
/* date = March 24th 2022 6:05 pm */
#ifndef LUMENARIUM_WIN32_OPENGL_H
#define LUMENARIUM_WIN32_OPENGL_H
// glext.h - https://github.com/KhronosGroup/OpenGL-Registry/blob/main/api/GL/glext.h
// wglext.h -
// OpenGL 3.3+ Context Creation
typedef const char *WINAPI proc_wglGetExtensionsStringARB(HDC hdc);
typedef BOOL proc_wglChoosePixelFormatARB(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
typedef HGLRC proc_wglCreateContextAttribsARB(HDC hDC, HGLRC hshareContext, const int *attribList);
// OpenGL 3.3+ Extensions
typedef void proc_glGenVertexArrays(GLsizei n, GLuint *arrays);
typedef void proc_glBindVertexArray(GLuint array);
typedef void proc_glGenBuffers (GLsizei n, GLuint *buffers);
typedef void proc_glBindBuffer(GLenum target, GLuint buffer);
typedef void proc_glBufferData(GLenum target, size_t size, const void *data, GLenum usage);
typedef GLuint proc_glCreateShader(GLenum type);
typedef void proc_glShaderSource(GLuint shader, u32 count, const char* const* string, const GLint *length);
typedef void proc_glCompileShader(GLuint shader);
typedef GLuint proc_glCreateProgram(void);
typedef void proc_glAttachShader(GLuint program, GLuint shader);
typedef void proc_glLinkProgram(GLuint program);
typedef void proc_glUseProgram(GLuint program);
typedef GLuint proc_glGetAttribLocation(GLuint program, const char* name);
typedef void proc_glVertexAttribPointer(GLuint attr, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
typedef void proc_glEnableVertexAttribArray(GLuint index);
typedef void proc_glGetShaderiv(GLuint shader, GLenum ele, GLint* value_out);
typedef void proc_glGetShaderInfoLog(GLuint shader, GLuint buf_len, GLsizei* len_out, GLchar* buf);
typedef void proc_glGetProgramiv(GLuint program, GLenum ele, GLint* value_out);
typedef void proc_glGetProgramInfoLog(GLuint program, GLuint cap, GLsizei* len_out, GLchar* buf);
struct Win32_OpenGL_Extensions
{
proc_wglGetExtensionsStringARB* wglGetExtensionsStringARB;
proc_wglChoosePixelFormatARB* wglChoosePixelFormatARB;
proc_wglCreateContextAttribsARB* wglCreateContextAttribsARB;
proc_glGenVertexArrays* glGenVertexArrays;
proc_glBindVertexArray* glBindVertexArray;
proc_glGenBuffers* glGenBuffers;
proc_glBindBuffer* glBindBuffer;
proc_glBufferData* glBufferData;
proc_glCreateShader* glCreateShader;
proc_glShaderSource* glShaderSource;
proc_glCompileShader* glCompileShader;
proc_glCreateProgram* glCreateProgram;
proc_glAttachShader* glAttachShader;
proc_glLinkProgram* glLinkProgram;
proc_glUseProgram* glUseProgram;
proc_glGetAttribLocation* glGetAttribLocation;
proc_glVertexAttribPointer* glVertexAttribPointer;
proc_glEnableVertexAttribArray* glEnableVertexAttribArray;
proc_glGetShaderiv* glGetShaderiv;
proc_glGetShaderInfoLog* glGetShaderInfoLog;
proc_glGetProgramiv* glGetProgramiv;
proc_glGetProgramInfoLog* glGetProgramInfoLog;
};
////////////////////////////////////////
// error strings
#define WIN32_GL_ERROR_CASE(code) case (code): { result = #code; } break
char*
win32_gl_error_to_string(u32 error)
{
char* result = 0;
switch (error)
{
WIN32_GL_ERROR_CASE(GL_INVALID_VALUE);
WIN32_GL_ERROR_CASE(GL_INVALID_ENUM );
WIN32_GL_ERROR_CASE(GL_INVALID_OPERATION);
default: { result = "unknown"; }
}
return result;
}
#endif //LUMENARIUM_WIN32_OPENGL_H

View File

@ -76,7 +76,11 @@ void
platform_thread_end(Platform_Thread_Handle thread)
{
HANDLE thread_handle = win32_threads[thread.value];
TerminateThread(thread_handle, 0);
bool result = TerminateThread(thread_handle, 0);
if (!result) {
win32_get_last_error();
invalid_code_path;
}
win32_threads[thread.value] = INVALID_HANDLE_VALUE;
}

View File

@ -15,18 +15,21 @@ struct Win32_Window_OpenGL_Info
HGLRC rc;
};
struct Win32_Window
struct Win32_Window_Info
{
char* name;
char* class_name;
s32 width;
s32 height;
WNDCLASS window_class;
};
struct Win32_Window
{
Win32_Window_Info info;
WNDCLASSEX window_class;
WNDPROC window_event_handler;
HWND window_handle;
HDC dc;
Win32_Window_OpenGL_Info opengl_info;
};
@ -42,8 +45,9 @@ global Win32_Window win32_main_window = {};
//////////////////////////////////////////
//
internal Win32_Window
internal bool
win32_window_create(
Win32_Window* dest,
HINSTANCE hinstance,
char* window_name,
s32 width,
@ -51,39 +55,51 @@ win32_window_create(
WNDPROC window_event_handler
)
{
Win32_Window result = {};
result.name = window_name;
result.class_name = window_name;
result.width = width;
result.height = height;
result.window_event_handler = window_event_handler;
dest->info.name = window_name;
dest->info.class_name = window_name;
dest->info.width = width;
dest->info.height = height;
result.window_class = {};
result.window_class.style = CS_HREDRAW | CS_VREDRAW;
result.window_class.lpfnWndProc = window_event_handler;
result.window_class.hInstance = hinstance;
result.window_class.lpszClassName = window_name;
dest->window_event_handler = window_event_handler;
if (RegisterClass(&result.window_class))
dest->window_class = {};
dest->window_class.cbSize = sizeof(WNDCLASSEX);
dest->window_class.style = (
CS_HREDRAW |
CS_VREDRAW |
CS_OWNDC // TODO(PS): need to know what this is
);
dest->window_class.lpfnWndProc = window_event_handler;
dest->window_class.cbClsExtra = 0;
dest->window_class.cbWndExtra = 0;
dest->window_class.hInstance = hinstance;
dest->window_class.hIcon = NULL;
dest->window_class.hCursor = NULL;
dest->window_class.hbrBackground = NULL;
dest->window_class.lpszMenuName = 0;
dest->window_class.lpszClassName = window_name; // "main_window_class";
dest->window_class.hIconSm = NULL;
if (RegisterClassEx(&dest->window_class))
{
result.window_handle = CreateWindowEx(
0,
result.window_class.lpszClassName,
window_name,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
width,
height,
0,
0,
hinstance,
0
);
result.dc = GetDC(result.window_handle);
dest->window_handle = CreateWindowEx(
0,
dest->window_class.lpszClassName,
window_name,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
width,
height,
0,
0,
hinstance,
0
);
return true;
}
return result;
return false;
}
internal void
@ -91,10 +107,12 @@ win32_window_update_dim(Win32_Window* win)
{
RECT client_rect;
GetClientRect(win->window_handle, &client_rect);
win->width = client_rect.right - client_rect.left;
win->height = client_rect.bottom - client_rect.top;
win->info.width = client_rect.right - client_rect.left;
win->info.height = client_rect.bottom - client_rect.top;
}
internal void win32_window_opengl_ctx_create(Win32_Window* win, Win32_Window_OpenGL_Info info, HINSTANCE hinstance);
LRESULT CALLBACK
win32_window_event_handler(HWND window_handle, UINT msg, WPARAM wparam, LPARAM lparam)
{
@ -102,6 +120,13 @@ win32_window_event_handler(HWND window_handle, UINT msg, WPARAM wparam, LPARAM l
switch (msg)
{
case WM_CREATE:
{
win32_main_window.dc = GetDC(window_handle);
HINSTANCE hinstance = GetModuleHandle(NULL);
win32_window_opengl_ctx_create(&win32_main_window, { 32, 8, 0 }, hinstance);
}break;
case WM_SIZE:
{
win32_window_update_dim(&win32_main_window);
@ -109,12 +134,38 @@ win32_window_event_handler(HWND window_handle, UINT msg, WPARAM wparam, LPARAM l
case WM_CLOSE:
{
result = DefWindowProc(window_handle, msg, wparam, lparam);
if (win32_main_window.opengl_info.rc)
{
wglDeleteContext(win32_main_window.opengl_info.rc);
win32_main_window.opengl_info.rc = NULL;
}
if (win32_main_window.dc)
{
ReleaseDC(win32_main_window.window_handle, win32_main_window.dc);
win32_main_window.dc = NULL;
}
add_flag(win32_window_event_flags, WindowEventFlag_CloseRequested);
running = false;
DestroyWindow(win32_main_window.window_handle);
}break;
case WM_DESTROY:
{
if (win32_main_window.opengl_info.rc)
{
wglDeleteContext(win32_main_window.opengl_info.rc);
win32_main_window.opengl_info.rc = NULL;
}
if (win32_main_window.dc)
{
ReleaseDC(win32_main_window.window_handle, win32_main_window.dc);
win32_main_window.dc = NULL;
}
//PostQuitMessage(0);
//result = DefWindowProc(window_handle, msg, wparam, lparam);
}break;
case WM_PAINT:
@ -151,14 +202,31 @@ win32_window_event_handler(HWND window_handle, UINT msg, WPARAM wparam, LPARAM l
return result;
}
////////////////////////////////////////////
// OpenGL dummy window functions
LRESULT CALLBACK
win32_opengl_event_handler(HWND window_handle, UINT msg, WPARAM wparam, LPARAM lparam)
{
LRESULT result = 0;
switch (msg)
{
case WM_CREATE: { }break;
case WM_CLOSE: { DestroyWindow(window_handle); }break;
case WM_DESTROY: { } break;
default: { return DefWindowProc(window_handle, msg, wparam, lparam); } break;
}
return result;
}
internal void
win32_window_opengl_ctx_create(Win32_Window* win, Win32_Window_OpenGL_Info info)
win32_window_opengl_ctx_create_no_ext(HDC dc, Win32_Window_OpenGL_Info* info)
{
// Setup pixel format
{
PIXELFORMATDESCRIPTOR pixel_format_desc = { 0 };
// TODO: Program seems to work perfectly fine without all other params except dwFlags.
// Can we skip other params for the sake of brevity?
pixel_format_desc.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pixel_format_desc.nVersion = 1;
pixel_format_desc.dwFlags = (
@ -166,38 +234,191 @@ win32_window_opengl_ctx_create(Win32_Window* win, Win32_Window_OpenGL_Info info)
PFD_DRAW_TO_WINDOW |
PFD_DOUBLEBUFFER
);
pixel_format_desc.cColorBits = info.bits_color;
pixel_format_desc.cAlphaBits = info.bits_alpha;
pixel_format_desc.cDepthBits = info.bits_depth;
// TODO(Peter): include these in win32_opengl_window_info?
pixel_format_desc.cColorBits = info->bits_color;
pixel_format_desc.cAlphaBits = info->bits_alpha;
pixel_format_desc.cDepthBits = info->bits_depth;
pixel_format_desc.iPixelType = PFD_TYPE_RGBA;
pixel_format_desc.dwLayerMask = PFD_MAIN_PLANE;
s32 pixel_fmt = ChoosePixelFormat(win->dc, &pixel_format_desc);
if (!pixel_fmt) { invalid_code_path; }
if (!SetPixelFormat(win->dc, pixel_fmt, &pixel_format_desc))
s32 pixel_fmt = ChoosePixelFormat(dc, &pixel_format_desc);
if (pixel_fmt == 0)
{
win32_get_last_error();
invalid_code_path;
}
if ((pixel_fmt = ChoosePixelFormat(dc, &pixel_format_desc)) == 0)
{
win32_get_last_error();
invalid_code_path;
}
if (SetPixelFormat(dc, pixel_fmt, &pixel_format_desc) == FALSE)
{
win32_get_last_error();
invalid_code_path;
}
}
// Create rendering context
{
// TODO: Create "proper" context?
// https://www.opengl.org/wiki/Creating_an_OpenGL_Context_(WGL)#Proper_Context_Creation
info.rc = wglCreateContext(win->dc);
wglMakeCurrent(win->dc, info.rc);
// TODO(Peter): do we want this?
/*
glGetIntegerv(GL_MAJOR_VERSION, );
glGetIntegerv(GL_MINOR_VERSION, );
(char*)glGetString(GL_VENDOR);
(char*)glGetString(GL_RENDERER);
*/
info->rc = wglCreateContext(dc);
if (info->rc == NULL) {
win32_get_last_error();
invalid_code_path;
}
if (!wglMakeCurrent(dc, info->rc))
{
win32_get_last_error();
invalid_code_path;
}
}
}
// Based on documentation at:
// https://www.opengl.org/wiki/Creating_an_OpenGL_Context_(WGL)#Proper_Context_Creation
internal void
win32_window_opengl_ctx_create_ext(HDC dc, Win32_Window_OpenGL_Info* info)
{
const int pixel_fmt_attribs[] = {
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_COLOR_BITS_ARB, 32,
WGL_DEPTH_BITS_ARB, 24,
WGL_STENCIL_BITS_ARB, 8,
0, 0
};
s32 pixel_fmt;
u32 num_formats;
// this will contain the description of pixel_fmt after we set it
PIXELFORMATDESCRIPTOR pixel_format_desc = { 0 };
if (!gl.wglChoosePixelFormatARB(dc, pixel_fmt_attribs, NULL, 1, &pixel_fmt, &num_formats))
{
win32_get_last_error();
invalid_code_path;
}
if (SetPixelFormat(dc, pixel_fmt, &pixel_format_desc) == FALSE)
{
win32_get_last_error();
invalid_code_path;
}
int ctx_flags = WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
#if defined(DEBUG)
ctx_flags |= WGL_CONTEXT_DEBUG_BIT_ARB;
#endif
const int ctx_attribs[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_FLAGS_ARB, ctx_flags,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0, 0,
};
info->rc = gl.wglCreateContextAttribsARB(dc, 0, ctx_attribs);
if (info->rc == NULL) {
win32_get_last_error();
invalid_code_path;
}
if (!wglMakeCurrent(dc, info->rc))
{
win32_get_last_error();
invalid_code_path;
}
#if 0
//char* version_string = (char*)glGetString(GL_VERSION);
OutputDebugStringA("OpenGL Version: ");
OutputDebugStringA(version_string);
OutputDebugStringA("\n");
#endif
}
internal void
win32_window_opengl_make_current(Win32_Window* win)
{
}
#define wgl_load_ext(e,n) e.n = (proc_##n*)wglGetProcAddress(#n); assert((e.n) != 0)
internal Win32_OpenGL_Extensions
win32_window_opengl_get_wgl_ext(HINSTANCE hinstance)
{
Win32_OpenGL_Extensions result = {0};
WNDCLASSEX window_class = {};
window_class.cbSize = sizeof(WNDCLASSEX);
window_class.style = (CS_HREDRAW | CS_VREDRAW | CS_OWNDC);
window_class.lpfnWndProc = win32_opengl_event_handler;
window_class.hInstance = hinstance;
window_class.lpszClassName = "opengl_window_class";
if (RegisterClassEx(&window_class))
{
HWND window_handle = CreateWindowEx(0, window_class.lpszClassName,
"opengl_window", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, 32, 32, 0, 0, hinstance, 0
);
HDC dc = GetDC(window_handle);
Win32_Window_OpenGL_Info info = { 32, 24, 8 };
win32_window_opengl_ctx_create_no_ext(dc, &info);
wgl_load_ext(result, wglGetExtensionsStringARB);
if (result.wglGetExtensionsStringARB != 0)
{
const char* extension_string = result.wglGetExtensionsStringARB(dc);
OutputDebugStringA("OpenGL Extensions: \n");
OutputDebugStringA(extension_string);
OutputDebugStringA("\n\n");
wgl_load_ext(result, wglChoosePixelFormatARB);
wgl_load_ext(result, wglCreateContextAttribsARB);
wgl_load_ext(result, glGenVertexArrays);
wgl_load_ext(result, glBindVertexArray);
wgl_load_ext(result, glGenBuffers);
wgl_load_ext(result, glBindBuffer);
wgl_load_ext(result, glBufferData);
wgl_load_ext(result, glCreateShader);
wgl_load_ext(result, glShaderSource);
wgl_load_ext(result, glCompileShader);
wgl_load_ext(result, glCreateProgram);
wgl_load_ext(result, glAttachShader);
wgl_load_ext(result, glLinkProgram);
wgl_load_ext(result, glUseProgram);
wgl_load_ext(result, glGetAttribLocation);
wgl_load_ext(result, glVertexAttribPointer);
wgl_load_ext(result, glEnableVertexAttribArray);
wgl_load_ext(result, glGetShaderiv);
wgl_load_ext(result, glGetShaderInfoLog);
wgl_load_ext(result, glGetProgramiv);
wgl_load_ext(result, glGetProgramInfoLog);
}
wglMakeCurrent(NULL, NULL);
wglDeleteContext(info.rc);
ReleaseDC(window_handle, dc);
DestroyWindow(window_handle);
}
return result;
}
internal void
win32_window_opengl_ctx_create(Win32_Window* win, Win32_Window_OpenGL_Info info, HINSTANCE hinstance)
{
if (gl.wglGetExtensionsStringARB == 0)
{
gl = win32_window_opengl_get_wgl_ext(hinstance);
}
win32_window_opengl_ctx_create_ext(win->dc, &info);
win->opengl_info = info;
}

View File

@ -0,0 +1,423 @@
/*
* Example of a Windows OpenGL program.
* The OpenGL code is the same as that used in
* the X Window System sample
*/
#include <windows.h>
#include <GL/gl.h>
//#include <GL/glu.h>
/* Windows globals, defines, and prototypes */
CHAR szAppName[]="Win OpenGL";
HWND ghWnd;
HDC ghDC;
HGLRC ghRC;
#define SWAPBUFFERS SwapBuffers(ghDC)
#define BLACK_INDEX 0
#define RED_INDEX 13
#define GREEN_INDEX 14
#define BLUE_INDEX 16
#define WIDTH 300
#define HEIGHT 200
LONG WINAPI MainWndProc (HWND, UINT, WPARAM, LPARAM);
BOOL bSetupPixelFormat(HDC);
/* OpenGL globals, defines, and prototypes */
GLfloat latitude, longitude, latinc, longinc;
GLdouble radius;
#define GLOBE 1
#define CYLINDER 2
#define CONE 3
GLvoid resize(GLsizei, GLsizei);
GLvoid initializeGL(GLsizei, GLsizei);
GLvoid drawScene(GLvoid);
void polarView( GLdouble, GLdouble, GLdouble, GLdouble);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
WNDCLASS wndclass;
/* Register the frame class */
wndclass.style = 0;
wndclass.lpfnWndProc = (WNDPROC)MainWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, szAppName);
wndclass.hCursor = LoadCursor (NULL,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wndclass.lpszMenuName = szAppName;
wndclass.lpszClassName = szAppName;
DWORD r0 = RegisterClass (&wndclass);
if (!r0) return FALSE;
/* Create the frame */
ghWnd = CreateWindow (szAppName,
"Generic OpenGL Sample",
WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
WIDTH,
HEIGHT,
NULL,
NULL,
hInstance,
NULL);
/* make sure window was created */
if (!ghWnd)
return FALSE;
/* show and update main window */
ShowWindow (ghWnd, nCmdShow);
UpdateWindow (ghWnd);
/* animation loop */
while (1) {
/*
* Process all pending messages
*/
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE)
{
if (GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} else {
return TRUE;
}
}
drawScene();
}
}
/* main window procedure */
LONG WINAPI MainWndProc (
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
LONG lRet = 1;
PAINTSTRUCT ps;
RECT rect;
switch (uMsg) {
case WM_CREATE:
ghDC = GetDC(hWnd);
if (!bSetupPixelFormat(ghDC))
PostQuitMessage (0);
ghRC = wglCreateContext(ghDC);
wglMakeCurrent(ghDC, ghRC);
GetClientRect(hWnd, &rect);
initializeGL(rect.right, rect.bottom);
break;
case WM_PAINT:
BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_SIZE:
GetClientRect(hWnd, &rect);
resize(rect.right, rect.bottom);
break;
case WM_CLOSE:
if (ghRC)
wglDeleteContext(ghRC);
if (ghDC)
ReleaseDC(hWnd, ghDC);
ghRC = 0;
ghDC = 0;
DestroyWindow (hWnd);
break;
case WM_DESTROY:
if (ghRC)
wglDeleteContext(ghRC);
if (ghDC)
ReleaseDC(hWnd, ghDC);
PostQuitMessage (0);
break;
case WM_KEYDOWN:
switch (wParam) {
case VK_LEFT:
longinc += 0.5F;
break;
case VK_RIGHT:
longinc -= 0.5F;
break;
case VK_UP:
latinc += 0.5F;
break;
case VK_DOWN:
latinc -= 0.5F;
break;
}
default:
lRet = (LONG)DefWindowProc (hWnd, uMsg, wParam, lParam);
break;
}
return lRet;
}
BOOL bSetupPixelFormat(HDC hdc)
{
PIXELFORMATDESCRIPTOR pfd, *ppfd;
int pixelformat;
ppfd = &pfd;
ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
ppfd->nVersion = 1;
ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER;
ppfd->dwLayerMask = PFD_MAIN_PLANE;
ppfd->iPixelType = PFD_TYPE_COLORINDEX;
ppfd->cColorBits = 8;
ppfd->cDepthBits = 16;
ppfd->cAccumBits = 0;
ppfd->cStencilBits = 0;
pixelformat = ChoosePixelFormat(hdc, ppfd);
if ( (pixelformat = ChoosePixelFormat(hdc, ppfd)) == 0 )
{
MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
return FALSE;
}
if (SetPixelFormat(hdc, pixelformat, ppfd) == FALSE)
{
MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
return FALSE;
}
return TRUE;
}
/* OpenGL code */
GLvoid resize( GLsizei width, GLsizei height )
{
GLfloat aspect;
glViewport( 0, 0, width, height );
aspect = (GLfloat) width / height;
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
//gluPerspective( 45.0, aspect, 3.0, 7.0 );
//glMatrixMode( GL_MODELVIEW );
}
#if 0
GLvoid createObjects()
{
GLUquadricObj *quadObj;
glNewList(GLOBE, GL_COMPILE);
quadObj = gluNewQuadric ();
gluQuadricDrawStyle (quadObj, GLU_LINE);
gluSphere (quadObj, 1.5, 16, 16);
glEndList();
glNewList(CONE, GL_COMPILE);
quadObj = gluNewQuadric ();
gluQuadricDrawStyle (quadObj, GLU_FILL);
gluQuadricNormals (quadObj, GLU_SMOOTH);
gluCylinder(quadObj, 0.3, 0.0, 0.6, 15, 10);
glEndList();
glNewList(CYLINDER, GL_COMPILE);
glPushMatrix ();
glRotatef ((GLfloat)90.0, (GLfloat)1.0, (GLfloat)0.0, (GLfloat)0.0);
glTranslatef ((GLfloat)0.0, (GLfloat)0.0, (GLfloat)-1.0);
quadObj = gluNewQuadric ();
gluQuadricDrawStyle (quadObj, GLU_FILL);
gluQuadricNormals (quadObj, GLU_SMOOTH);
gluCylinder (quadObj, 0.3, 0.3, 0.6, 12, 2);
glPopMatrix ();
glEndList();
}
#endif
GLvoid initializeGL(GLsizei width, GLsizei height)
{
GLfloat maxObjectSize, aspect;
GLdouble near_plane, far_plane;
glClearIndex( (GLfloat)BLACK_INDEX);
glClearDepth( 1.0 );
glEnable(GL_DEPTH_TEST);
glMatrixMode( GL_PROJECTION );
aspect = (GLfloat) width / height;
//gluPerspective( 45.0, aspect, 3.0, 7.0 );
glMatrixMode( GL_MODELVIEW );
near_plane = 3.0;
far_plane = 7.0;
maxObjectSize = 3.0F;
radius = near_plane + maxObjectSize/2.0;
latitude = 0.0F;
longitude = 0.0F;
latinc = 6.0F;
longinc = 2.5F;
//createObjects();
}
void polarView(GLdouble radius_, GLdouble twist, GLdouble latitude_,
GLdouble longitude_)
{
glTranslated(0.0, 0.0, -radius_);
glRotated(-twist, 0.0, 0.0, 1.0);
glRotated(-latitude_, 1.0, 0.0, 0.0);
glRotated(longitude_, 0.0, 0.0, 1.0);
}
GLvoid drawScene(GLvoid)
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
latitude += latinc;
longitude += longinc;
polarView( radius, 0, latitude, longitude );
glIndexi(RED_INDEX);
glCallList(CONE);
glIndexi(BLUE_INDEX);
glCallList(GLOBE);
glIndexi(GREEN_INDEX);
glPushMatrix();
glTranslatef(0.8F, -0.65F, 0.0F);
glRotatef(30.0F, 1.0F, 0.5F, 1.0F);
glCallList(CYLINDER);
glPopMatrix();
glPopMatrix();
SWAPBUFFERS;
}
#if 0
#include "windows.h"
#include <gl/gl.h>
# define assert_always (*((volatile int*)0) = 0xFFFF)
LRESULT CALLBACK
window_event_handler(HWND h, UINT m, WPARAM w, LPARAM l)
{
switch (m)
{
case WM_CLOSE: { return DefWindowProc(h, m, w, l); } break;
case WM_DESTROY: { return DefWindowProc(h, m, w, l); } break;
default: { return DefWindowProc(h, m, w, l); } break;
}
}
INT WINAPI
WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR lpCmdLine,
INT nCmdShow)
{
WNDCLASSEX window_class = {0};
HWND window_handle = NULL;
HDC dc = NULL;
HGLRC rc = NULL;
window_class = {};
window_class.cbSize = sizeof(WNDCLASSEX);
window_class.style = CS_HREDRAW | CS_VREDRAW;
window_class.lpfnWndProc = window_event_handler;
window_class.cbClsExtra = 0;
window_class.cbWndExtra = 0;
window_class.hInstance = hInstance;
window_class.hIcon = NULL;
window_class.hCursor = NULL;
window_class.hbrBackground = NULL;
window_class.lpszMenuName = 0;
window_class.lpszClassName = "my_window_class"; // TODO(PS): does this need to be different from the window itself?
window_class.hIconSm = NULL;
if (RegisterClassEx(&window_class))
{
window_handle = CreateWindowEx(
0,
window_class.lpszClassName,
"my_window",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
600,
400,
0,
0,
hInstance,
0
);
dc = GetDC(window_handle);
}
else
{
assert_always;
}
// Setup pixel format
PIXELFORMATDESCRIPTOR pixel_format_desc = { 0 };
pixel_format_desc.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pixel_format_desc.nVersion = 1;
pixel_format_desc.dwFlags = (
PFD_SUPPORT_OPENGL |
PFD_DRAW_TO_WINDOW |
PFD_DOUBLEBUFFER
);
pixel_format_desc.cColorBits = 32;
pixel_format_desc.cAlphaBits = 8;
pixel_format_desc.cDepthBits = 0;
pixel_format_desc.iPixelType = PFD_TYPE_RGBA;
pixel_format_desc.dwLayerMask = PFD_MAIN_PLANE;
int pixel_fmt = ChoosePixelFormat(dc, &pixel_format_desc);
if (!pixel_fmt) { assert_always; }
if (!SetPixelFormat(dc, pixel_fmt, &pixel_format_desc))
{
assert_always;
}
// Create rendering context
rc = wglCreateContext(dc);
wglMakeCurrent(dc, rc);
return 0;
}
#endif

View File

@ -0,0 +1,57 @@
internal App_Init_Desc
incenter_get_init_desc()
{
App_Init_Desc result = {};
result.assembly_cap = 4;
return result;
}
internal void
incenter_init(App_State* state)
{
return;
// create a fake sculpture
Assembly_Handle ah = assembly_add(&state->assemblies, lit_str("test"), 3000, 100);
r32 scale = 1;
// strips
for (int strip_x = 0; strip_x < 10; strip_x++)
{
for (int strip_y = 0; strip_y < 10; strip_y++)
{
if (strip_x == 5 && strip_y == 7)
{
int x= 5;
}
Assembly_Strip* strip = assembly_add_strip(&state->assemblies, ah, 30);
// leds go up
for (int led_z = 0; led_z < 30; led_z++)
{
v4 pos = { strip_x * scale, strip_y * scale, led_z * scale, 1 };
assembly_add_led(&state->assemblies, ah, strip, pos);
}
}
}
}
internal void
incenter_frame_prepare(App_State* state)
{
}
internal void
incenter_frame(App_State* state)
{
}
internal void
incenter_cleanup(App_State* state)
{
}