Compare commits

...

32 Commits

Author SHA1 Message Date
888918face Refactoring editor 2026-03-31 10:56:44 -05:00
0885da8d44 Fixed dynamic updates on scene rendering 2026-03-29 19:08:58 -05:00
8af961c6d3 Fixed knulli rendering 2026-03-29 18:53:42 -05:00
ef5febdde3 Fixed dolphin rendering. 2026-03-29 18:42:59 -05:00
6d7fbd3926 Change to square only 2026-03-29 17:58:13 -05:00
2680d373d8 Fixed boot.dol in wii 2026-03-29 16:51:54 -05:00
2b2ddb3cf2 Fixed spritebatch flickering on Dolphin 2026-03-29 16:10:39 -05:00
85ff95296b Fix Linux again 2026-03-29 15:19:15 -05:00
314a2de41a Fixed text on PSP 2026-03-29 14:45:40 -05:00
26fafab47a Fix copy issues 2026-03-29 14:25:10 -05:00
e56ff20e2d Attempting to fix PSP alpha textures 2026-03-29 13:38:55 -05:00
55d44f229d Fixed crash on PSP 2026-03-29 10:35:57 -05:00
1c5e50cc4d Test text rendering 2026-03-29 10:15:22 -05:00
ea898da6c2 Fix compile 2026-03-28 21:52:52 -05:00
dbb7e9f53c Getting shaders working with lua. 2026-03-28 21:50:59 -05:00
cbb68a399d Fix compile error 2026-03-28 15:43:38 -05:00
0e794f28b1 Disable paletted textures for now 2026-03-28 15:40:30 -05:00
87d2d9123e Re-implement RGBA textures 2026-03-28 15:21:33 -05:00
6823a4ddb5 Try again again 2026-03-28 11:35:11 -05:00
20a7c70081 Fixiing weird action path missing? 2026-03-28 11:26:25 -05:00
9caa33b3bb Restore all builds 2026-03-28 11:14:15 -05:00
2d7e61460a fix 2026-03-28 11:05:36 -05:00
a4b7fb3f44 Try again 2026-03-28 11:04:42 -05:00
70056cf4ca Temp only build knulli
Some checks failed
Build Dusk / build-knulli (push) Failing after 21s
2026-03-28 11:02:43 -05:00
5f4ab71ade Add knulli build 2026-03-28 11:02:34 -05:00
f3adb3257b Cleanup knulli 2026-03-28 11:00:18 -05:00
438edda7fd Fixed knulli 2026-03-28 10:56:40 -05:00
d5b0441e6f Fixed GLES support (partially), PSP still not working 2026-03-28 10:51:50 -05:00
9ba0ceb000 Moved texture setting around 2026-03-28 09:48:24 -05:00
9474a68995 Slightly more accurate, likely going to have to change how paletted textures work 2026-03-27 21:01:29 -05:00
09c35f0aa6 Builds on knulli 2026-03-27 20:48:43 -05:00
a2113442cb Builds on knulli 2026-03-27 15:59:26 -05:00
110 changed files with 1736 additions and 549 deletions

View File

@@ -1,5 +1,4 @@
name: Build Dusk name: Build Dusk
on: on:
push: push:
branches: branches:
@@ -7,7 +6,6 @@ on:
pull_request: pull_request:
branches: branches:
- main - main
jobs: jobs:
run-tests: run-tests:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -55,6 +53,26 @@ jobs:
path: ./git-artifcats/Dusk path: ./git-artifcats/Dusk
if-no-files-found: error if-no-files-found: error
build-knulli:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Docker
uses: docker/setup-docker-action@v5
- name: Build knulli
run: ./scripts/build-knulli-docker.sh
- name: Move output to Dusk subfolder
run: |
mkdir -p ./git-artifcats/Dusk
cp -r build-knulli/dusk ./git-artifcats/Dusk
- name: Upload knulli binary
uses: actions/upload-artifact@v6
with:
name: dusk-knulli
path: ./git-artifcats/Dusk
if-no-files-found: error
build-gamecube: build-gamecube:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@@ -74,6 +92,7 @@ jobs:
with: with:
name: dusk-gamecube name: dusk-gamecube
path: ./git-artifcats/Dusk path: ./git-artifcats/Dusk
if-no-files-found: error
build-wii: build-wii:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -87,7 +106,7 @@ jobs:
- name: Copy output files. - name: Copy output files.
run: | run: |
mkdir -p ./git-artifcats/Dusk/apps/Dusk mkdir -p ./git-artifcats/Dusk/apps/Dusk
cp build-wii/Dusk.dol ./git-artifcats/Dusk/apps/Dusk/Dusk.dol cp build-wii/Dusk.dol ./git-artifcats/Dusk/apps/Dusk/boot.dol
cp build-wii/dusk.dsk ./git-artifcats/Dusk/apps/Dusk/dusk.dsk cp build-wii/dusk.dsk ./git-artifcats/Dusk/apps/Dusk/dusk.dsk
cp docker/dolphin/meta.xml ./git-artifcats/Dusk/apps/Dusk/meta.xml cp docker/dolphin/meta.xml ./git-artifcats/Dusk/apps/Dusk/meta.xml
- name: Upload Wii binary - name: Upload Wii binary
@@ -95,3 +114,4 @@ jobs:
with: with:
name: dusk-wii name: dusk-wii
path: ./git-artifcats/Dusk path: ./git-artifcats/Dusk
if-no-files-found: error

View File

@@ -70,6 +70,7 @@ elseif LINUX then
inputBind("mouse_x", INPUT_ACTION_POINTERX) inputBind("mouse_x", INPUT_ACTION_POINTERX)
inputBind("mouse_y", INPUT_ACTION_POINTERY) inputBind("mouse_y", INPUT_ACTION_POINTERY)
end end
else else
print("Unknown platform, no default input bindings set.") print("Unknown platform, no default input bindings set.")
end end

View File

@@ -9,6 +9,7 @@ module('text')
module('tileset') module('tileset')
module('texture') module('texture')
module('input') module('input')
module('shader')
CELL_STATE_DEFAULT = 0 CELL_STATE_DEFAULT = 0
CELL_STATE_HOVER = 1 CELL_STATE_HOVER = 1
@@ -62,7 +63,7 @@ function cellDraw(x, y, type)
slice = cellSliceDisabled slice = cellSliceDisabled
end end
spriteBatchPush(textureCell, spriteBatchPush(
x, y, x, y,
x + tilesetCell.tileWidth, y + tilesetCell.tileHeight, x + tilesetCell.tileWidth, y + tilesetCell.tileHeight,
colorWhite(), colorWhite(),
@@ -182,18 +183,28 @@ function sceneUpdate()
y = y + inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN) y = y + inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN)
end end
function sceneRender() function sceneRender()
-- Update camera -- Update camera
cameraPushMatrix(camera) camera.bottom = 0
camera.bottom = screenGetHeight() camera.top = screenGetHeight()
camera.right = screenGetWidth() camera.right = screenGetWidth()
shaderBind(SHADER_UNLIT)
proj = cameraGetProjectionMatrix(camera)
shaderSetMatrix(SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj)
view = cameraGetViewMatrix(camera)
shaderSetMatrix(SHADER_UNLIT, SHADER_UNLIT_VIEW, view)
shaderSetTexture(SHADER_UNLIT, SHADER_UNLIT_TEXTURE, nil)
spriteBatchPush( spriteBatchPush(
nil, x, y,
x, y, x + 32, y + 32, x + 32, y + 32,
colorWhite() colorWhite()
) )
spriteBatchFlush()
textDraw(10, 10, "Hello World\nHow are you?", colorRed())
spriteBatchFlush()
-- Update mouse position -- Update mouse position
-- if INPUT_POINTER then -- if INPUT_POINTER then
@@ -250,7 +261,4 @@ function sceneRender()
-- ) -- )
-- end -- end
-- end -- end
spriteBatchFlush()
cameraPopMatrix()
end end

Binary file not shown.

Binary file not shown.

BIN
assets/ui/minogram.dtx Normal file

Binary file not shown.

View File

@@ -0,0 +1,45 @@
# Find link platform-specific libraries
set(OpenGL_GL_PREFERENCE LEGACY)
find_package(SDL2 REQUIRED)
find_library(EGL_LIB EGL REQUIRED)
find_library(GL_LIB GL REQUIRED)
find_package(OpenGL REQUIRED)
# Setup endianess at compile time to optimize.
include(TestBigEndian)
test_big_endian(IS_BIG_ENDIAN)
if(IS_BIG_ENDIAN)
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
DUSK_PLATFORM_ENDIAN_BIG
)
else()
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
DUSK_PLATFORM_ENDIAN_LITTLE
)
endif()
# Link required libraries.
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
SDL2
pthread
OpenGL::GLES2
${GL_LIB}
${EGL_LIB}
m
)
# Define platform-specific macros.
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
DUSK_SDL2
DUSK_OPENGL
DUSK_OPENGL_ES
DUSK_LINUX
DUSK_DISPLAY_SIZE_DYNAMIC
DUSK_DISPLAY_WIDTH_DEFAULT=640
DUSK_DISPLAY_HEIGHT_DEFAULT=480
DUSK_DISPLAY_SCREEN_HEIGHT=240
DUSK_INPUT_KEYBOARD
DUSK_INPUT_POINTER
DUSK_INPUT_GAMEPAD
DUSK_TIME_DYNAMIC
)

View File

@@ -28,6 +28,7 @@ target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
DUSK_SDL2 DUSK_SDL2
DUSK_OPENGL DUSK_OPENGL
# DUSK_OPENGL_LEGACY
DUSK_LINUX DUSK_LINUX
DUSK_DISPLAY_SIZE_DYNAMIC DUSK_DISPLAY_SIZE_DYNAMIC
DUSK_DISPLAY_WIDTH_DEFAULT=640 DUSK_DISPLAY_WIDTH_DEFAULT=640

View File

@@ -0,0 +1,29 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
set(CMAKE_ASM_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_SYSROOT /)
set(CMAKE_C_COMPILER_TARGET aarch64-linux-gnu)
set(CMAKE_CXX_COMPILER_TARGET aarch64-linux-gnu)
set(CMAKE_FIND_ROOT_PATH
/usr/aarch64-linux-gnu
/usr/lib/aarch64-linux-gnu
/usr/include/aarch64-linux-gnu
)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(ENV{PKG_CONFIG_LIBDIR} "/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig")
set(ENV{PKG_CONFIG_PATH} "/usr/lib/aarch64-linux-gnu/pkgconfig")
set(CMAKE_PREFIX_PATH "/usr/aarch64-linux-gnu;/usr/lib/aarch64-linux-gnu")
# Optional: helps some Find modules
set(SDL2_DIR "/usr/lib/aarch64-linux-gnu/cmake/SDL2" CACHE PATH "")

35
docker/knulli/Dockerfile Normal file
View File

@@ -0,0 +1,35 @@
FROM debian:trixie
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /workdir
RUN dpkg --add-architecture arm64 && \
apt-get update && \
apt-get install -y --no-install-recommends \
crossbuild-essential-arm64 \
ca-certificates \
pkg-config \
cmake \
make \
ninja-build \
git \
file \
python3 \
python3-pip \
python3-polib \
python3-pil \
python3-dotenv \
python3-pyqt5 \
python3-opengl \
liblua5.4-dev:arm64 \
xz-utils:arm64 \
libbz2-dev:arm64 \
zlib1g-dev:arm64 \
libzip-dev:arm64 \
libssl-dev:arm64 \
libsdl2-dev:arm64 \
liblzma-dev:arm64 \
libopengl0:arm64 \
libgl1:arm64 \
libegl1:arm64 \
libgles2:arm64 \
libgl1-mesa-dev:arm64 && \
rm -rf /var/lib/apt/lists/*

41
editor/.gitignore vendored Normal file
View File

@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# env files (can opt-in for committing if needed)
.env*
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts

8
editor/next.config.ts Normal file
View File

@@ -0,0 +1,8 @@
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
/* config options here */
reactCompiler: true,
};
export default nextConfig;

23
editor/package.json Normal file
View File

@@ -0,0 +1,23 @@
{
"name": "dusk-editor",
"version": "0.1.0",
"private": true,
"scripts": {
"start:dev": "next dev",
"build:prod": "next build",
"start:prod": "next start"
},
"dependencies": {
"next": "16.2.1",
"react": "19.2.4",
"react-dom": "19.2.4",
"sass": "^1.98.0"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"babel-plugin-react-compiler": "1.0.0",
"typescript": "^5"
}
}

23
editor/src/app/layout.tsx Normal file
View File

@@ -0,0 +1,23 @@
import type { Metadata } from "next";
import "@/styles/styles.scss";
import Navbar from "@/components/Navbar/Navbar";
export const metadata: Metadata = {
title: "Dusk Editor",
description: "Editor for the Dusk Game Engine",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body>
<Navbar />
{children}
</body>
</html>
);
}

9
editor/src/app/page.tsx Normal file
View File

@@ -0,0 +1,9 @@
import Link from "next/link";
export default function Home() {
return (
<div>
<Link href="/texture-creator">Go to Texture Creator</Link>
</div>
);
}

View File

@@ -0,0 +1,17 @@
'use client';
import React, { createContext, useContext, useState } from "react";
type TexturePageContextType = {
};
const TexturePageContext = createContext<TexturePageContextType | undefined>(undefined);
const TextureCreatorPage: React.FC<{ children: React.ReactNode }> = (props) => {
return (
<TexturePageContext.Provider value={{ }}>
<Typography</Typography>
</TexturePageContext.Provider>
);
}
export default TextureCreatorPage;

View File

@@ -0,0 +1,12 @@
import React from 'react';
import * as styles from './Navbar.module.scss';
const Navbar:React.FC<{}> = (props) => {
return (
<nav className={styles.navbar}>
navbar
</nav>
);
}
export default Navbar;

View File

@@ -0,0 +1,14 @@
const Typography:React.FC<{
element?:string|React.JSXElementConstructor<any>;
}> = (props) => {
const Element = props.element || 'p';
return (
<Element>
{props.children}
</Element>
)
};
export default Typography;

View File

@@ -0,0 +1,17 @@
import React, { createContext, useContext, useState } from "react";
type TextureContextType = {
};
const TextureContext = createContext<TextureContextType | undefined>(undefined);
const TextureCreator: React.FC<{ children: React.ReactNode }> = (props) => {
return (
<TextureContext.Provider value={{ }}>
{props.children}
</TextureContext.Provider>
);
}
export default TextureCreator;

View File

@@ -0,0 +1,4 @@
a {
color: inherit;
text-decoration: none;
}

View File

@@ -0,0 +1,3 @@
* {
box-sizing: border-box;
}

View File

@@ -0,0 +1,8 @@
body {
margin: 0;
padding: 0;
max-width: 100vw;
overflow-x: hidden;
font-size: 16px;
font-family: Arial, Helvetica, sans-serif;
}

View File

@@ -0,0 +1,6 @@
html {
margin: 0;
padding: 0;
max-width: 100vw;
overflow-x: hidden;
}

View File

@@ -0,0 +1,3 @@
:root {
}

View File

@@ -0,0 +1,12 @@
// Elements
@use './elements/root.scss';
@use './elements/all.scss';
@use './elements/a.scss';
@use './elements/html.scss';
@use './elements/body.scss';
// Objects
// Components
// Utilities

34
editor/tsconfig.json Normal file
View File

@@ -0,0 +1,34 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts"
],
"exclude": ["node_modules"]
}

3
scripts/build-knulli-docker.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
docker build -t dusk-knulli -f docker/knulli/Dockerfile .
docker run --rm -v $(pwd):/workdir dusk-knulli /bin/bash -c "./scripts/build-knulli.sh"

24
scripts/build-knulli.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
cmake -S . -B build-knulli -G Ninja \
-DDUSK_BUILD_TESTS=ON \
-DDUSK_TARGET_SYSTEM=knulli \
-DCMAKE_TOOLCHAIN_FILE=./cmake/toolchains/aarch64-linux-gnu.cmake \
-DCMAKE_BUILD_TYPE=Release
cmake --build build-knulli -- -j$(nproc)
# Copy necessary libs out
mkdir -p ./build-knulli/dusk
cp ./build-knulli/Dusk ./build-knulli/dusk/Dusk
cp ./build-knulli/dusk.dsk ./build-knulli/dusk/dusk.dsk
echo '#!/bin/bash' > build-knulli/dusk/Dusk.sh
echo 'cd "$(dirname "$(readlink -f "$0")")"' >> build-knulli/dusk/Dusk.sh
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(dirname "$(readlink -f "$0")")' >> build-knulli/dusk/Dusk.sh
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/gl4es' >> build-knulli/dusk/Dusk.sh
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib' >> build-knulli/dusk/Dusk.sh
echo '$(dirname "$(readlink -f "$0")")/Dusk' >> build-knulli/dusk/Dusk.sh
chmod +x build-knulli/dusk/Dusk.sh
cp /usr/lib/aarch64-linux-gnu/liblua5.4.so.0 build-knulli/dusk/
# cp /usr/lib/aarch64-linux-gnu/libSDL2-2.0.so.0 build-knulli/dusk/
# cp /usr/lib/aarch64-linux-gnu/libGL.so.1 build-knulli/dusk/
# cp /usr/lib/aarch64-linux-gnu/libEGL.so.1 build-knulli/dusk/
# cp /usr/lib/aarch64-linux-gnu/libGLESv2.so.2 build-knulli/dusk/

View File

@@ -4,8 +4,9 @@
# https://opensource.org/licenses/MIT # https://opensource.org/licenses/MIT
add_subdirectory(dusk) add_subdirectory(dusk)
add_subdirectory(duskrpg)
if(DUSK_TARGET_SYSTEM STREQUAL "linux") if(DUSK_TARGET_SYSTEM STREQUAL "linux" OR DUSK_TARGET_SYSTEM STREQUAL "knulli")
add_subdirectory(dusklinux) add_subdirectory(dusklinux)
add_subdirectory(dusksdl2) add_subdirectory(dusksdl2)
add_subdirectory(duskgl) add_subdirectory(duskgl)

View File

@@ -40,9 +40,6 @@ target_sources(${DUSK_BINARY_TARGET_NAME}
main.c main.c
) )
# Defs
dusk_env_to_h(duskdefs.env duskdefs.h)
# Subdirs # Subdirs
add_subdirectory(assert) add_subdirectory(assert)
add_subdirectory(asset) add_subdirectory(asset)
@@ -52,12 +49,9 @@ add_subdirectory(engine)
add_subdirectory(error) add_subdirectory(error)
add_subdirectory(event) add_subdirectory(event)
add_subdirectory(input) add_subdirectory(input)
add_subdirectory(item)
add_subdirectory(locale) add_subdirectory(locale)
add_subdirectory(map)
add_subdirectory(scene) add_subdirectory(scene)
add_subdirectory(script) add_subdirectory(script)
add_subdirectory(story)
add_subdirectory(time) add_subdirectory(time)
add_subdirectory(ui) add_subdirectory(ui)
add_subdirectory(util) add_subdirectory(util)

View File

@@ -7,6 +7,7 @@
#include "assert.h" #include "assert.h"
#include "log/log.h" #include "log/log.h"
#include "util/string.h"
#ifndef DUSK_ASSERTIONS_FAKED #ifndef DUSK_ASSERTIONS_FAKED
#ifdef DUSK_TEST_ASSERT #ifdef DUSK_TEST_ASSERT
@@ -98,4 +99,14 @@
) { ) {
assertUnreachableImpl(file, line, message); assertUnreachableImpl(file, line, message);
} }
void assertStringEqualImpl(
const char *file,
const int32_t line,
const char *a,
const char *b,
const char *message
) {
assertTrueImpl(file, line, stringCompare(a, b) == 0, message);
}
#endif #endif

View File

@@ -104,6 +104,23 @@
const char *message const char *message
); );
/**
* Asserts two strings to be equal.
*
* @param file File that the assertion is being made from.
* @param line Line that the assertion is being made from.
* @param a First string to compare.
* @param b Second string to compare.
* @param message Message to throw against assertion failure.
*/
void assertStringEqualImpl(
const char *file,
const int32_t line,
const char *a,
const char *b,
const char *message
);
/** /**
* Asserts a given value to be true. * Asserts a given value to be true.
* *
@@ -178,6 +195,16 @@
#define assertStrLenMin(str, len, message) \ #define assertStrLenMin(str, len, message) \
assertTrue(strlen(str) >= len, message) assertTrue(strlen(str) >= len, message)
/**
* Asserts two strings to be equal.
*
* @param a First string to compare.
* @param b Second string to compare.
* @param message Message to throw against assertion failure.
*/
#define assertStringEqual(a, b, message) \
assertStringEqualImpl(__FILE__, __LINE__, a, b, message)
#else #else
// If assertions are faked, we define the macros to do nothing. // If assertions are faked, we define the macros to do nothing.
#define assertTrue(x, message) ((void)0) #define assertTrue(x, message) ((void)0)

View File

@@ -19,12 +19,9 @@ typedef enum {
ASSET_TYPE_NULL, ASSET_TYPE_NULL,
ASSET_TYPE_TEXTURE, ASSET_TYPE_TEXTURE,
// ASSET_TYPE_PALETTE,
ASSET_TYPE_TILESET, ASSET_TYPE_TILESET,
ASSET_TYPE_LANGUAGE, ASSET_TYPE_LANGUAGE,
ASSET_TYPE_SCRIPT, ASSET_TYPE_SCRIPT,
ASSET_TYPE_MAP,
ASSET_TYPE_MAP_CHUNK,
ASSET_TYPE_COUNT, ASSET_TYPE_COUNT,
} assettype_t; } assettype_t;
@@ -60,21 +57,14 @@ static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = {
}, },
[ASSET_TYPE_TEXTURE] = { [ASSET_TYPE_TEXTURE] = {
.extension = "dpt", .extension = "DTX",
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE, .loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
.dataSize = sizeof(assettexture_t), .dataSize = sizeof(assettexture_t),
.entire = assetTextureLoad .entire = assetTextureLoad
}, },
// [ASSET_TYPE_PALETTE] = {
// .extension = "dpf",
// .loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
// .dataSize = sizeof(palette_t),
// .entire = assetPaletteLoad
// },
[ASSET_TYPE_TILESET] = { [ASSET_TYPE_TILESET] = {
.extension = "dtf", .extension = "DTF",
.loadStrategy = ASSET_LOAD_STRAT_ENTIRE, .loadStrategy = ASSET_LOAD_STRAT_ENTIRE,
.dataSize = sizeof(assettileset_t), .dataSize = sizeof(assettileset_t),
.entire = assetTilesetLoad .entire = assetTilesetLoad
@@ -91,16 +81,4 @@ static const assettypedef_t ASSET_TYPE_DEFINITIONS[ASSET_TYPE_COUNT] = {
.loadStrategy = ASSET_LOAD_STRAT_CUSTOM, .loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
.custom = assetScriptHandler .custom = assetScriptHandler
}, },
// [ASSET_TYPE_MAP] = {
// .extension = "DMF",
// .loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
// .custom = assetMapHandler
// },
// [ASSET_TYPE_MAP_CHUNK] = {
// .extension = "DMC",
// .loadStrategy = ASSET_LOAD_STRAT_CUSTOM,
// .custom = assetMapChunkHandler
// },
}; };

View File

@@ -21,8 +21,8 @@ errorret_t assetTextureLoad(assetentire_t entire) {
// Read header and version (first 4 bytes) // Read header and version (first 4 bytes)
if( if(
assetData->header[0] != 'D' || assetData->header[0] != 'D' ||
assetData->header[1] != 'P' || assetData->header[1] != 'T' ||
assetData->header[2] != 'T' assetData->header[2] != 'X'
) { ) {
errorThrow("Invalid texture header"); errorThrow("Invalid texture header");
} }
@@ -44,18 +44,35 @@ errorret_t assetTextureLoad(assetentire_t entire) {
errorThrow("Invalid texture dimensions"); errorThrow("Invalid texture dimensions");
} }
textureInit( // Validate format
texture, textureformat_t format;
assetData->width, texturedata_t data;
assetData->height,
TEXTURE_FORMAT_PALETTE, switch(assetData->type) {
(texturedata_t){ case 0x00: // RGBA8888
.paletted = { format = TEXTURE_FORMAT_RGBA;
.indices = NULL, data.rgbaColors = (color_t *)assetData->data;
.palette = NULL break;
// case 0x01:
// format = TEXTURE_FORMAT_RGB;
// break;
// case 0x02:
// format = TEXTURE_FORMAT_RGB565;
// break;
// case 0x03:
// format = TEXTURE_FORMAT_RGB5A3;
// break;
default:
errorThrow("Unsupported texture format");
} }
}
); errorChain(textureInit(
texture, assetData->width, assetData->height, format, data
));
errorOk(); errorOk();
} }

View File

@@ -7,6 +7,7 @@
#pragma once #pragma once
#include "error/error.h" #include "error/error.h"
#include "display/color.h"
#define ASSET_TEXTURE_WIDTH_MAX 2048 #define ASSET_TEXTURE_WIDTH_MAX 2048
#define ASSET_TEXTURE_HEIGHT_MAX 2048 #define ASSET_TEXTURE_HEIGHT_MAX 2048
@@ -20,9 +21,10 @@ typedef struct assetentire_s assetentire_t;
typedef struct { typedef struct {
char_t header[3]; char_t header[3];
uint8_t version; uint8_t version;
uint8_t type;
uint32_t width; uint32_t width;
uint32_t height; uint32_t height;
uint8_t palette[ASSET_TEXTURE_SIZE_MAX]; uint8_t data[ASSET_TEXTURE_SIZE_MAX * sizeof(color4b_t)];
} assettexture_t; } assettexture_t;
#pragma pack(pop) #pragma pack(pop)

View File

@@ -37,7 +37,7 @@ void cameraInitOrthographic(camera_t *camera) {
camera->orthographic.right = SCREEN.width; camera->orthographic.right = SCREEN.width;
camera->orthographic.top = 0.0f; camera->orthographic.top = 0.0f;
camera->orthographic.bottom = SCREEN.height; camera->orthographic.bottom = SCREEN.height;
camera->nearClip = -1.0f; camera->nearClip = 0.1f;
camera->farClip = 1.0f; camera->farClip = 1.0f;
camera->viewType = CAMERA_VIEW_TYPE_2D; camera->viewType = CAMERA_VIEW_TYPE_2D;
@@ -84,7 +84,7 @@ void cameraGetViewMatrix(camera_t *camera, mat4 dest) {
assertNotNull(dest, "Destination matrix must not be null"); assertNotNull(dest, "Destination matrix must not be null");
if(camera->viewType == CAMERA_VIEW_TYPE_MATRIX) { if(camera->viewType == CAMERA_VIEW_TYPE_MATRIX) {
glm_mat4_copy(camera->view, dest); glm_mat4_ucopy(camera->view, dest);
} else if(camera->viewType == CAMERA_VIEW_TYPE_LOOKAT) { } else if(camera->viewType == CAMERA_VIEW_TYPE_LOOKAT) {
glm_mat4_identity(dest); glm_mat4_identity(dest);
glm_lookat( glm_lookat(

View File

@@ -20,13 +20,26 @@
#include "display/shader/shaderunlit.h" #include "display/shader/shaderunlit.h"
#include "time/time.h" #include "time/time.h"
#include "script/module/display/moduleshader.h"
display_t DISPLAY = { 0 }; display_t DISPLAY = { 0 };
mesh_t mesh;
texture_t TEXTURE; meshvertex_t vertices[3] = {
{
uint8_t indices[2 * 2] = { .color = { 255, 0, 0, 255 },
0, 1, .uv = { 0.0f, 0.0f },
2, 3 .pos = { 0.0f, 0.5f, 0.0f }
},
{
.color = { 0, 255, 0, 255 },
.uv = { 0.5f, 1.0f },
.pos = { -0.5f, -0.5f, 0.0f }
},
{
.color = { 0, 0, 255, 255 },
.uv = { 1.0f, 0.0f },
.pos = { 0.5f, -0.5f, 0.0f }
}
}; };
errorret_t displayInit(void) { errorret_t displayInit(void) {
@@ -35,31 +48,27 @@ errorret_t displayInit(void) {
#ifdef displayPlatformInit #ifdef displayPlatformInit
errorChain(displayPlatformInit()); errorChain(displayPlatformInit());
#endif #endif
errorChain(shaderInit(&SHADER_UNLIT, &SHADER_UNLIT_DEFINITION));
errorChain(quadInit()); errorChain(quadInit());
errorChain(frameBufferInitBackBuffer()); errorChain(frameBufferInitBackBuffer());
errorChain(spriteBatchInit()); errorChain(spriteBatchInit());
errorChain(textInit()); errorChain(textInit());
errorChain(screenInit()); errorChain(screenInit());
PALETTES[0].colors[0] = COLOR_RED; // Setup initial shader with default values
PALETTES[0].colors[1] = COLOR_GREEN; errorChain(shaderInit(&SHADER_UNLIT, &SHADER_UNLIT_DEFINITION));
PALETTES[0].colors[2] = COLOR_BLUE; camera_t cam;
PALETTES[0].colors[3] = COLOR_WHITE; cameraInit(&cam);
PALETTES[0].count = 4; mat4 mat;
cameraGetProjectionMatrix(&cam, mat);
errorChain(shaderBind(&SHADER_UNLIT));
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, mat));
cameraGetViewMatrix(&cam, mat);
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, mat));
glm_mat4_identity(mat);
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, mat));
errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, NULL));
errorChain(textureInit( errorChain(meshInit(&mesh, MESH_PRIMITIVE_TYPE_TRIANGLES, 3, vertices));
&TEXTURE,
2, 2,
TEXTURE_FORMAT_PALETTE,
(texturedata_t){
.paletted = {
.indices = indices,
.palette = &PALETTES[0]
}
}
));
errorOk(); errorOk();
} }
@@ -80,37 +89,7 @@ errorret_t displayUpdate(void) {
SCREEN.background SCREEN.background
); );
camera_t camera; errorChain(sceneRender());
// cameraInitOrthographic(&camera);
// camera.orthographic.left = 0.0f;
// camera.orthographic.right = SCREEN.width;
// camera.orthographic.top = SCREEN.height;
// camera.orthographic.bottom = 0.0f;
cameraInitPerspective(&camera);
camera.lookat.position[0] = 3.0f;
camera.lookat.position[1] = 3.0f;
camera.lookat.position[2] = 3.0f;
mat4 proj, view, model;
cameraGetProjectionMatrix(&camera, proj);
cameraGetViewMatrix(&camera, view);
glm_mat4_identity(model);
errorChain(shaderBind(&SHADER_UNLIT));
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj));
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, view));
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, model));
errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, &TEXTURE));
errorChain(spriteBatchPush(
0.0f, 0.0f,
1.0f, 1.0f,
COLOR_WHITE,
0.0f, 0.0f,
1.0f, 1.0f
));
errorChain(spriteBatchFlush());
// errorCatch(errorPrint(sceneRender()));
// Render UI // Render UI
// uiRender(); // uiRender();

View File

@@ -7,4 +7,5 @@
target_sources(${DUSK_LIBRARY_TARGET_NAME} target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC PUBLIC
shader.c shader.c
shaderunlit.c
) )

View File

@@ -8,15 +8,19 @@
#include "shader.h" #include "shader.h"
#include "assert/assert.h" #include "assert/assert.h"
shader_t *bound = NULL;
errorret_t shaderInit(shader_t *shader, const shaderdefinition_t *def) { errorret_t shaderInit(shader_t *shader, const shaderdefinition_t *def) {
assertNotNull(shader, "Shader cannot be null"); assertNotNull(shader, "Shader cannot be null");
errorChain(shaderInitPlatform(shader, def)); errorChain(shaderInitPlatform(shader, def));
bound = NULL;
errorOk(); errorOk();
} }
errorret_t shaderBind(shader_t *shader) { errorret_t shaderBind(shader_t *shader) {
assertNotNull(shader, "Shader cannot be null"); assertNotNull(shader, "Shader cannot be null");
errorChain(shaderBindPlatform(shader)); errorChain(shaderBindPlatform(shader));
bound = shader;
errorOk(); errorOk();
} }
@@ -28,6 +32,7 @@ errorret_t shaderSetMatrix(
assertNotNull(shader, "Shader cannot be null"); assertNotNull(shader, "Shader cannot be null");
assertStrLenMin(name, 1, "Uniform name cannot be empty"); assertStrLenMin(name, 1, "Uniform name cannot be empty");
assertNotNull(matrix, "Matrix cannot be null"); assertNotNull(matrix, "Matrix cannot be null");
assertTrue(bound == shader, "Shader must be bound.");
errorChain(shaderSetMatrixPlatform(shader, name, matrix)); errorChain(shaderSetMatrixPlatform(shader, name, matrix));
errorOk(); errorOk();
} }
@@ -39,6 +44,7 @@ errorret_t shaderSetTexture(
) { ) {
assertNotNull(shader, "Shader cannot be null"); assertNotNull(shader, "Shader cannot be null");
assertStrLenMin(name, 1, "Uniform name cannot be empty"); assertStrLenMin(name, 1, "Uniform name cannot be empty");
assertTrue(bound == shader, "Shader must be bound.");
errorChain(shaderSetTexturePlatform(shader, name, texture)); errorChain(shaderSetTexturePlatform(shader, name, texture));
errorOk(); errorOk();
} }
@@ -56,6 +62,7 @@ errorret_t shaderSetTexture(
errorret_t shaderDispose(shader_t *shader) { errorret_t shaderDispose(shader_t *shader) {
assertNotNull(shader, "Shader cannot be null"); assertNotNull(shader, "Shader cannot be null");
bound = NULL;
errorChain(shaderDisposePlatform(shader)); errorChain(shaderDisposePlatform(shader));
errorOk(); errorOk();
} }

View File

@@ -0,0 +1,10 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "shaderunlit.h"
shader_t SHADER_UNLIT = { 0 };

View File

@@ -15,4 +15,4 @@
// #define SHADER_UNLIT_COLOR "u_Color" // #define SHADER_UNLIT_COLOR "u_Color"
extern shaderdefinition_t SHADER_UNLIT_DEFINITION; extern shaderdefinition_t SHADER_UNLIT_DEFINITION;
static shader_t SHADER_UNLIT; extern shader_t SHADER_UNLIT;

View File

@@ -35,14 +35,13 @@ errorret_t spriteBatchPush(
const float_t u1, const float_t u1,
const float_t v1 const float_t v1
) { ) {
errorChain(spriteBatchPush3D( return spriteBatchPush3D(
(vec3){ minX, minY, 0 }, (vec3){ minX, minY, 0 },
(vec3){ maxX, maxY, 0 }, (vec3){ maxX, maxY, 0 },
color, color,
(vec2){ u0, v0 }, (vec2){ u0, v0 },
(vec2){ u1, v1 } (vec2){ u1, v1 }
)); );
errorOk();
} }
errorret_t spriteBatchPush3D( errorret_t spriteBatchPush3D(
@@ -53,11 +52,14 @@ errorret_t spriteBatchPush3D(
const vec2 uv1 const vec2 uv1
) { ) {
// Need to flush? // Need to flush?
if(SPRITEBATCH.spriteCount >= SPRITEBATCH_SPRITES_MAX) { if(SPRITEBATCH.spriteCount >= SPRITEBATCH_SPRITES_MAX_PER_FLUSH) {
errorChain(spriteBatchFlush()); errorChain(spriteBatchFlush());
} }
size_t vertexOffset = SPRITEBATCH.spriteCount * QUAD_VERTEX_COUNT; size_t vertexOffset = (
SPRITEBATCH.spriteCount +
(SPRITEBATCH.spriteFlush * SPRITEBATCH_SPRITES_MAX_PER_FLUSH)
) * QUAD_VERTEX_COUNT;
quadBuffer3D( quadBuffer3D(
&SPRITEBATCH_VERTICES[vertexOffset], &SPRITEBATCH_VERTICES[vertexOffset],
min, max, color, uv0, uv1 min, max, color, uv0, uv1
@@ -68,6 +70,7 @@ errorret_t spriteBatchPush3D(
void spriteBatchClear() { void spriteBatchClear() {
SPRITEBATCH.spriteCount = 0; SPRITEBATCH.spriteCount = 0;
SPRITEBATCH.spriteFlush = 0;
} }
errorret_t spriteBatchFlush() { errorret_t spriteBatchFlush() {
@@ -76,9 +79,19 @@ errorret_t spriteBatchFlush() {
} }
size_t vertexCount = QUAD_VERTEX_COUNT * SPRITEBATCH.spriteCount; size_t vertexCount = QUAD_VERTEX_COUNT * SPRITEBATCH.spriteCount;
errorChain(meshFlush(&SPRITEBATCH.mesh, 0, vertexCount)); size_t vertexOffset = (
errorChain(meshDraw(&SPRITEBATCH.mesh, 0, vertexCount)); SPRITEBATCH.spriteFlush * SPRITEBATCH_SPRITES_MAX_PER_FLUSH *
spriteBatchClear(); QUAD_VERTEX_COUNT
);
errorChain(meshFlush(&SPRITEBATCH.mesh, vertexOffset, vertexCount));
errorChain(meshDraw(&SPRITEBATCH.mesh, vertexOffset, vertexCount));
SPRITEBATCH.spriteFlush++;
if(SPRITEBATCH.spriteFlush >= SPRITEBATCH_FLUSH_COUNT) {
SPRITEBATCH.spriteFlush = 0;
}
SPRITEBATCH.spriteCount = 0;
errorOk(); errorOk();
} }

View File

@@ -8,12 +8,17 @@
#pragma once #pragma once
#include "display/mesh/quad.h" #include "display/mesh/quad.h"
#define SPRITEBATCH_SPRITES_MAX 16 #define SPRITEBATCH_SPRITES_MAX 32
#define SPRITEBATCH_VERTEX_COUNT (SPRITEBATCH_SPRITES_MAX * QUAD_VERTEX_COUNT) #define SPRITEBATCH_VERTEX_COUNT (SPRITEBATCH_SPRITES_MAX * QUAD_VERTEX_COUNT)
#define SPRITEBATCH_FLUSH_COUNT 4
#define SPRITEBATCH_SPRITES_MAX_PER_FLUSH (\
SPRITEBATCH_SPRITES_MAX / SPRITEBATCH_FLUSH_COUNT \
)
typedef struct { typedef struct {
mesh_t mesh; mesh_t mesh;
int32_t spriteCount; int32_t spriteCount;
int32_t spriteFlush;
} spritebatch_t; } spritebatch_t;
// Have to define these seperately because of alignment in certain platforms. // Have to define these seperately because of alignment in certain platforms.

View File

@@ -11,17 +11,19 @@
#include "display/spritebatch/spritebatch.h" #include "display/spritebatch/spritebatch.h"
#include "asset/asset.h" #include "asset/asset.h"
#include "display/shader/shaderunlit.h"
texture_t DEFAULT_FONT_TEXTURE; texture_t DEFAULT_FONT_TEXTURE;
tileset_t DEFAULT_FONT_TILESET; tileset_t DEFAULT_FONT_TILESET;
errorret_t textInit(void) { errorret_t textInit(void) {
// errorChain(assetLoad("ui/minogram.dpt", &DEFAULT_FONT_TEXTURE)); errorChain(assetLoad("ui/minogram.dtx", &DEFAULT_FONT_TEXTURE));
// errorChain(assetLoad("ui/minogram.dtf", &DEFAULT_FONT_TILESET)); errorChain(assetLoad("ui/minogram.dtf", &DEFAULT_FONT_TILESET));
errorOk(); errorOk();
} }
errorret_t textDispose(void) { errorret_t textDispose(void) {
// errorChain(textureDispose(&DEFAULT_FONT_TEXTURE)); errorChain(textureDispose(&DEFAULT_FONT_TEXTURE));
errorOk(); errorOk();
} }
@@ -45,6 +47,7 @@ errorret_t textDrawChar(
vec4 uv; vec4 uv;
tilesetTileGetUV(tileset, tileIndex, uv); tilesetTileGetUV(tileset, tileIndex, uv);
errorChain(spriteBatchPush( errorChain(spriteBatchPush(
// texture, // texture,
x, y, x, y,
@@ -70,6 +73,8 @@ errorret_t textDraw(
float_t posX = x; float_t posX = x;
float_t posY = y; float_t posY = y;
errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, texture));
char_t c; char_t c;
int32_t i = 0; int32_t i = 0;
while((c = text[i++]) != '\0') { while((c = text[i++]) != '\0') {

View File

@@ -12,8 +12,8 @@
#define PALETTE_COUNT 6 #define PALETTE_COUNT 6
typedef struct { typedef struct {
uint8_t count;
color_t colors[PALETTE_COLOR_COUNT]; color_t colors[PALETTE_COLOR_COUNT];
uint8_t count;
} palette_t; } palette_t;
extern palette_t PALETTES[PALETTE_COUNT]; extern palette_t PALETTES[PALETTE_COUNT];

View File

@@ -1,45 +0,0 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
ENTITY_DIR_SOUTH = 0
ENTITY_DIR_WEST = 1
ENTITY_DIR_EAST = 2
ENTITY_DIR_NORTH = 3
ENTITY_COUNT = 128
ENTITY_TYPE_NULL = 0
ENTITY_TYPE_PLAYER = 1
ENTITY_TYPE_NPC = 2
ENTITY_TYPE_COUNT = 3
CHUNK_WIDTH = 16
CHUNK_HEIGHT = 16
CHUNK_DEPTH = 4
# CHUNK_VERTEX_COUNT_MAX = QUAD_VERTEXES * CHUNK_WIDTH * CHUNK_HEIGHT * 4
CHUNK_VERTEX_COUNT_MAX=6144
CHUNK_MESH_COUNT_MAX = 14
CHUNK_ENTITY_COUNT_MAX = 8
TILE_WIDTH = 16.0
TILE_HEIGHT = 16.0
TILE_DEPTH = 16.0
TILE_SHAPE_NULL = 0
TILE_SHAPE_FLOOR = 1
TILE_SHAPE_RAMP_SOUTH = 2
TILE_SHAPE_RAMP_WEST = 3
TILE_SHAPE_RAMP_EAST = 4
TILE_SHAPE_RAMP_NORTH = 5
TILE_SHAPE_RAMP_SOUTHWEST = 6
TILE_SHAPE_RAMP_SOUTHEAST = 7
TILE_SHAPE_RAMP_NORTHWEST = 8
TILE_SHAPE_RAMP_NORTHEAST = 9
RPG_CAMERA_FOV = 70
RPG_CAMERA_PIXELS_PER_UNIT = 1.0
RPG_CAMERA_Z_OFFSET = 24.0
ASSET_LANG_CHUNK_CHAR_COUNT = 6144

View File

@@ -22,7 +22,7 @@ errorret_t sceneInit(void) {
errorret_t sceneUpdate(void) { errorret_t sceneUpdate(void) {
#ifdef DUSK_TIME_DYNAMIC #ifdef DUSK_TIME_DYNAMIC
if(!TIME.dynamicUpdate) { if(TIME.dynamicUpdate) {
errorOk(); errorOk();
} }
#endif #endif

View File

@@ -7,11 +7,8 @@
add_subdirectory(display) add_subdirectory(display)
add_subdirectory(event) add_subdirectory(event)
add_subdirectory(input) add_subdirectory(input)
add_subdirectory(item)
add_subdirectory(locale) add_subdirectory(locale)
add_subdirectory(map)
add_subdirectory(system) add_subdirectory(system)
add_subdirectory(scene) add_subdirectory(scene)
add_subdirectory(story)
add_subdirectory(time) add_subdirectory(time)
add_subdirectory(ui) add_subdirectory(ui)

View File

@@ -15,4 +15,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
modulescreen.c modulescreen.c
moduletileset.c moduletileset.c
moduletexture.c moduletexture.c
moduleshader.c
) )

View File

@@ -69,6 +69,16 @@ void moduleCamera(scriptcontext_t *context) {
// Methods // Methods
lua_register(context->luaState, "cameraCreate", moduleCameraCreate); lua_register(context->luaState, "cameraCreate", moduleCameraCreate);
lua_register(
context->luaState,
"cameraGetProjectionMatrix",
moduleCameraGetProjectionMatrix
);
lua_register(
context->luaState,
"cameraGetViewMatrix",
moduleCameraGetViewMatrix
);
} }
int moduleCameraCreate(lua_State *L) { int moduleCameraCreate(lua_State *L) {
@@ -289,3 +299,35 @@ int moduleCameraNewIndex(lua_State *l) {
return 0; return 0;
} }
int moduleCameraGetProjectionMatrix(lua_State *L) {
assertNotNull(L, "Lua state cannot be NULL.");
camera_t *cam = (camera_t *)luaL_checkudata(L, 1, "camera_mt");
assertNotNull(cam, "Camera pointer cannot be NULL.");
// Create mat4
mat4 test;
cameraGetProjectionMatrix(cam, test);
// Lua needs to own this matrix now
mat4 *m = (mat4 *)lua_newuserdata(L, sizeof(mat4));
memoryCopy(m, test, sizeof(mat4));
return 1;
}
int moduleCameraGetViewMatrix(lua_State *L) {
assertNotNull(L, "Lua state cannot be NULL.");
camera_t *cam = (camera_t *)luaL_checkudata(L, 1, "camera_mt");
assertNotNull(cam, "Camera pointer cannot be NULL.");
// Create mat4
mat4 test;
cameraGetViewMatrix(cam, test);
// Lua needs to own this matrix now
mat4 *m = (mat4 *)lua_newuserdata(L, sizeof(mat4));
memoryCopy(m, test, sizeof(mat4));
return 1;
}

View File

@@ -36,3 +36,19 @@ int moduleCameraIndex(lua_State *l);
* @param l The Lua state. * @param l The Lua state.
*/ */
int moduleCameraNewIndex(lua_State *l); int moduleCameraNewIndex(lua_State *l);
/**
* Script binding for getting a camera's projection matrix.
*
* @param L The Lua state.
* @return Number of return values on the Lua stack.
*/
int moduleCameraGetProjectionMatrix(lua_State *L);
/**
* Script binding for getting a camera's view matrix.
*
* @param L The Lua state.
* @return Number of return values on the Lua stack.
*/
int moduleCameraGetViewMatrix(lua_State *L);

View File

@@ -0,0 +1,120 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "moduleshader.h"
#include "assert/assert.h"
#include "display/shader/shader.h"
#include "display/shader/shaderunlit.h"
#include "display/camera/camera.h"
void moduleShader(scriptcontext_t *context) {
assertNotNull(context, "Context cannot be NULL.");
// Shader unlit defs
lua_pushlightuserdata(context->luaState, &SHADER_UNLIT);
lua_setglobal(context->luaState, "SHADER_UNLIT");
lua_pushstring(context->luaState, SHADER_UNLIT_PROJECTION);
lua_setglobal(context->luaState, "SHADER_UNLIT_PROJECTION");
lua_pushstring(context->luaState, SHADER_UNLIT_VIEW);
lua_setglobal(context->luaState, "SHADER_UNLIT_VIEW");
lua_pushstring(context->luaState, SHADER_UNLIT_MODEL);
lua_setglobal(context->luaState, "SHADER_UNLIT_MODEL");
lua_pushstring(context->luaState, SHADER_UNLIT_TEXTURE);
lua_setglobal(context->luaState, "SHADER_UNLIT_TEXTURE");
// Shader methods
lua_register(context->luaState, "shaderBind", moduleShaderBind);
lua_register(context->luaState, "shaderSetMatrix", moduleShaderSetMatrix);
lua_register(context->luaState, "shaderSetTexture", moduleShaderSetTexture);
}
int moduleShaderBind(lua_State *l) {
assertNotNull(l, "Lua state cannot be NULL.");
// Should be passed a shader userdata pointer only.
shader_t *shader = (shader_t *)lua_touserdata(l, 1);
assertNotNull(shader, "Shader pointer cannot be NULL.");
errorret_t ret = shaderBind(shader);
if(ret.code != ERROR_OK) {
luaL_error(l, "Failed to bind shader: %s", ret.state->message);
errorCatch(errorPrint(ret));
return 0;
}
return 0;
}
int moduleShaderSetMatrix(lua_State *l) {
assertNotNull(l, "Lua state cannot be NULL.");
// Expect shader, string and matrix.
if(!lua_isuserdata(l, 1)) {
luaL_error(l, "First argument must be a shader_mt userdata.");
return 0;
}
if(!lua_isstring(l, 2)) {
luaL_error(l, "Second argument must be a string.");
return 0;
}
if(!lua_isuserdata(l, 3)) {
luaL_error(l, "Third argument must be a mat4_mt userdata.");
return 0;
}
shader_t *shader = (shader_t *)lua_touserdata(l, 1);
assertNotNull(shader, "Shader pointer cannot be NULL.");
const char_t *uniformName = luaL_checkstring(l, 2);
assertStrLenMin(uniformName, 1, "Uniform name cannot be empty.");
mat4 *mat = (mat4 *)lua_touserdata(l, 3);
assertNotNull(mat, "Matrix pointer cannot be NULL.");
errorret_t ret = shaderSetMatrix(shader, uniformName, *mat);
if(ret.code != ERROR_OK) {
luaL_error(l, "Failed to set shader matrix: %s", ret.state->message);
errorCatch(errorPrint(ret));
return 0;
}
return 0;
}
int moduleShaderSetTexture(lua_State *l) {
assertNotNull(l, "Lua state cannot be NULL.");
shader_t *shader = (shader_t *)lua_touserdata(l, 1);
assertNotNull(shader, "Shader pointer cannot be NULL.");
const char_t *uniformName = luaL_checkstring(l, 2);
assertStrLenMin(uniformName, 1, "Uniform name cannot be empty.");
texture_t *texture;
// Texture can be Nil or a pointer, if not nil it must be a texture pointer.
if(lua_isnil(l, 3)) {
texture = NULL;
} else if(lua_isuserdata(l, 3)) {
texture = (texture_t *)lua_touserdata(l, 3);
assertNotNull(texture, "Texture pointer cannot be NULL.");
} else {
luaL_error(l, "Third argument must be a texture_mt userdata or nil.");
return 0;
}
errorret_t ret = shaderSetTexture(shader, uniformName, texture);
if(ret.code != ERROR_OK) {
luaL_error(l, "Failed to set shader texture: %s", ret.state->message);
errorCatch(errorPrint(ret));
return 0;
}
return 0;
}

View File

@@ -0,0 +1,42 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "script/scriptcontext.h"
/**
* Register shader functions to the given script context.
*
* @param context The script context to register shader functions to.
*/
void moduleShader(scriptcontext_t *context);
/**
* Script binding for binding a shader.
*
* @param l The Lua state.
* @return Number of return values on the Lua stack.
*/
int moduleShaderBind(lua_State *l);
/**
* Script binding for setting a matrix uniform in a shader.
*
* @param l The Lua state.
* @return Number of return values on the Lua stack.
*/
int moduleShaderSetMatrix(lua_State *l);
/**
* Script binding for setting a texture uniform in a shader.
*
* @param l The Lua state.
* @return Number of return values on the Lua stack.
*/
int moduleShaderSetTexture(lua_State *l);
errorret_t doThing();

View File

@@ -10,7 +10,6 @@
#include "script/module/input/moduleinput.h" #include "script/module/input/moduleinput.h"
#include "script/module/moduleplatform.h" #include "script/module/moduleplatform.h"
#include "script/module/scene/modulescene.h" #include "script/module/scene/modulescene.h"
#include "script/module/item/moduleitem.h"
#include "script/module/locale/modulelocale.h" #include "script/module/locale/modulelocale.h"
#include "script/module/time/moduletime.h" #include "script/module/time/moduletime.h"
#include "script/module/event/moduleevent.h" #include "script/module/event/moduleevent.h"
@@ -18,13 +17,13 @@
#include "script/module/display/modulespritebatch.h" #include "script/module/display/modulespritebatch.h"
#include "script/module/display/modulecamera.h" #include "script/module/display/modulecamera.h"
#include "script/module/display/moduleglm.h" #include "script/module/display/moduleglm.h"
#include "script/module/display/moduleshader.h"
#include "script/module/ui/moduleui.h" #include "script/module/ui/moduleui.h"
#include "script/module/display/moduletext.h" #include "script/module/display/moduletext.h"
#include "script/module/display/modulescreen.h" #include "script/module/display/modulescreen.h"
#include "script/module/story/modulestoryflag.h"
#include "script/module/map/modulemap.h"
#include "script/module/display/moduletexture.h" #include "script/module/display/moduletexture.h"
#include "script/module/display/moduletileset.h" #include "script/module/display/moduletileset.h"
#include "script/scriptgame.h"
#include "util/string.h" #include "util/string.h"
const scriptmodule_t SCRIPT_MODULE_LIST[] = { const scriptmodule_t SCRIPT_MODULE_LIST[] = {
@@ -33,7 +32,6 @@ const scriptmodule_t SCRIPT_MODULE_LIST[] = {
{ .name = "platform", .callback = modulePlatform }, { .name = "platform", .callback = modulePlatform },
{ .name = "color", .callback = moduleColor }, { .name = "color", .callback = moduleColor },
{ .name = "scene", .callback = moduleScene }, { .name = "scene", .callback = moduleScene },
{ .name = "item", .callback = moduleItem },
{ .name = "locale", .callback = moduleLocale }, { .name = "locale", .callback = moduleLocale },
{ .name = "time", .callback = moduleTime }, { .name = "time", .callback = moduleTime },
{ .name = "event", .callback = moduleEvent }, { .name = "event", .callback = moduleEvent },
@@ -43,10 +41,13 @@ const scriptmodule_t SCRIPT_MODULE_LIST[] = {
{ .name = "ui", .callback = moduleUi }, { .name = "ui", .callback = moduleUi },
{ .name = "text", .callback = moduleText }, { .name = "text", .callback = moduleText },
{ .name = "screen", .callback = moduleScreen }, { .name = "screen", .callback = moduleScreen },
{ .name = "storyflag", .callback = moduleStoryFlag },
{ .name = "map", .callback = moduleMap },
{ .name = "texture", .callback = moduleTexture }, { .name = "texture", .callback = moduleTexture },
{ .name = "tileset", .callback = moduleTileset }, { .name = "tileset", .callback = moduleTileset },
{ .name = "shader", .callback = moduleShader },
#ifdef SCRIPT_GAME_LIST
SCRIPT_GAME_LIST
#endif
}; };
#define SCRIPT_MODULE_COUNT ( \ #define SCRIPT_MODULE_COUNT ( \

View File

@@ -11,6 +11,10 @@
void cameraPushMatrixDolphin(camera_t *camera) { void cameraPushMatrixDolphin(camera_t *camera) {
assertNotNull(camera, "Camera cannot be null"); assertNotNull(camera, "Camera cannot be null");
assertTrue(
camera->nearClip > 0.0f,
"Camera near clip must be greater than 0 for Dolphin"
);
Mtx44 guProjection; Mtx44 guProjection;
Mtx guView; Mtx guView;

View File

@@ -77,7 +77,8 @@ errorret_t displayInitDolphin(void) {
// Setup cull modes // Setup cull modes
GX_SetCullMode(GX_CULL_NONE); GX_SetCullMode(GX_CULL_NONE);
GX_SetZMode(GX_FALSE, GX_ALWAYS, GX_FALSE); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
GX_SetZMode(GX_TRUE, GX_ALWAYS, GX_FALSE);
GX_SetDispCopyGamma(GX_GM_1_0); GX_SetDispCopyGamma(GX_GM_1_0);
GX_SetColorUpdate(GX_TRUE); GX_SetColorUpdate(GX_TRUE);

View File

@@ -47,8 +47,6 @@ errorret_t meshDrawDolphin(
assertTrue(offsetof(meshvertex_t, uv) == 4, "uv offset wrong"); assertTrue(offsetof(meshvertex_t, uv) == 4, "uv offset wrong");
assertTrue(offsetof(meshvertex_t, pos) == 12, "pos offset wrong"); assertTrue(offsetof(meshvertex_t, pos) == 12, "pos offset wrong");
textureDolphinUploadTEV();
DCFlushRange( DCFlushRange(
(void*)&mesh->vertices[vertexOffset], (void*)&mesh->vertices[vertexOffset],
sizeof(meshvertex_t) * vertexCount sizeof(meshvertex_t) * vertexCount
@@ -62,6 +60,8 @@ errorret_t meshDrawDolphin(
GX_SetArray(GX_VA_CLR0, (void*)&mesh->vertices[vertexOffset].color.r, stride); GX_SetArray(GX_VA_CLR0, (void*)&mesh->vertices[vertexOffset].color.r, stride);
GX_SetArray(GX_VA_TEX0, (void*)&mesh->vertices[vertexOffset].uv[0], stride); GX_SetArray(GX_VA_TEX0, (void*)&mesh->vertices[vertexOffset].uv[0], stride);
GX_InvVtxCache();
GX_Begin(mesh->primitiveType, GX_VTXFMT0, (uint16_t)vertexCount); GX_Begin(mesh->primitiveType, GX_VTXFMT0, (uint16_t)vertexCount);
for(uint16_t i = 0; i < (uint16_t)vertexCount; ++i) { for(uint16_t i = 0; i < (uint16_t)vertexCount; ++i) {
GX_Position1x16(i); GX_Position1x16(i);

View File

@@ -77,6 +77,88 @@ errorret_t shaderSetMatrixDolphin(
errorOk(); errorOk();
} }
errorret_t shaderSetTextureDolphin(
shaderdolphin_t *shader,
const char_t *name,
texture_t *texture
) {
assertNotNull(shader, "Shader must not be null");
assertNotNull(name, "Uniform name must not be null");
assertStrLenMin(name, 1, "Uniform name cannot be empty");
if(texture == NULL) {
// GX_SetNumChans(0);
GX_SetNumChans(1);
GX_SetChanCtrl(
GX_COLOR0A0,
GX_DISABLE,
GX_SRC_REG,
GX_SRC_VTX,
GX_LIGHTNULL,
GX_DF_NONE,
GX_AF_NONE
);
GX_SetChanAmbColor(GX_COLOR0A0, (GXColor){ 0, 0, 0, 0 });
GX_SetChanMatColor(GX_COLOR0A0, (GXColor){ 255, 255, 255, 255 });
GX_SetNumTexGens(0);
GX_SetNumTevStages(1);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
GX_SetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_CLEAR);
GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
errorOk();
}
// Add channel for vertex color
GX_LoadTexObj(&texture->texObj, GX_TEXMAP0);
GX_SetNumChans(1);
GX_SetChanCtrl(
GX_COLOR0A0,// Store in color channel 0
GX_DISABLE,// Lighting disabled
GX_SRC_REG,// Ambient color?
GX_SRC_VTX,// Material color?
GX_LIGHTNULL,// Light Mask
GX_DF_NONE,// Diffuse function
GX_AF_NONE// Attenuation function
);
// One set of UVs
GX_SetNumTexGens(1);
GX_SetTexCoordGen(
GX_TEXCOORD0,
GX_TG_MTX2x4,
GX_TG_TEX0,
GX_IDENTITY
);
// Basically the shader setup
switch(texture->format) {
case TEXTURE_FORMAT_RGBA:
// One TEV stage: vertex color * texture color
GX_SetNumTevStages(1);
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
GX_SetTevOrder(
GX_TEVSTAGE0,
GX_TEXCOORD0,
GX_TEXMAP0,
GX_COLOR0A0
);
GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
break;
default:
assertUnreachable("Unknown texture format in meshDraw");
break;
}
errorOk();
}
errorret_t shaderDisposeDolphin(shaderdolphin_t *shader) { errorret_t shaderDisposeDolphin(shaderdolphin_t *shader) {
assertNotNull(shader, "Shader must not be null"); assertNotNull(shader, "Shader must not be null");

View File

@@ -6,7 +6,7 @@
*/ */
#pragma once #pragma once
#include "error/error.h" #include "display/texture/texture.h"
typedef struct { typedef struct {
mat4 view; mat4 view;
@@ -66,6 +66,20 @@ errorret_t shaderSetMatrixDolphin(
mat4 matrix mat4 matrix
); );
/**
* Sets a texture uniform in the dolphin shader. Basically does nothing.
*
* @param shader Shader to set the texture in.
* @param name Name of the uniform to set.
* @param texture Texture to set.
* @return Error code if failure.
*/
errorret_t shaderSetTextureDolphin(
shaderdolphin_t *shader,
const char_t *name,
texture_t *texture
);
/** /**
* Disposes a dolphin shader. Basically does nothing. * Disposes a dolphin shader. Basically does nothing.
* *

View File

@@ -14,5 +14,5 @@ typedef shaderdefinitiondolphin_t shaderdefinitionplatform_t;
#define shaderInitPlatform shaderInitDolphin #define shaderInitPlatform shaderInitDolphin
#define shaderBindPlatform shaderBindDolphin #define shaderBindPlatform shaderBindDolphin
#define shaderSetMatrixPlatform shaderSetMatrixDolphin #define shaderSetMatrixPlatform shaderSetMatrixDolphin
// #define shaderSetTexturePlatform shaderSetTextureDolphin #define shaderSetTexturePlatform shaderSetTextureDolphin
#define shaderDisposePlatform shaderDisposeDolphin #define shaderDisposePlatform shaderDisposeDolphin

View File

@@ -7,6 +7,7 @@
#include "display/texture/texture.h" #include "display/texture/texture.h"
#include "assert/assert.h" #include "assert/assert.h"
#include "util/memory.h"
errorret_t textureInitDolphin( errorret_t textureInitDolphin(
texturedolphin_t *texture, texturedolphin_t *texture,
@@ -15,191 +16,101 @@ errorret_t textureInitDolphin(
const textureformatdolphin_t format, const textureformatdolphin_t format,
const texturedata_t data const texturedata_t data
) { ) {
// switch(format) { switch(format) {
// case TEXTURE_FORMAT_RGBA: case TEXTURE_FORMAT_RGBA: {
// assertTrue( size_t rgbaSize = width * height * sizeof(uint8_t) * 4;
// (width % 4) == 0 && (height % 4) == 0,
// "RGB5A3 requires w/h multiple of 4 (or pad)"
// );
// // Convert to RGB5A3 format // Dolphin takes the RGBA data as 4x4 tiled layout.
// size_t rgbaSize = width * height * sizeof(u16); texture->rgba = memoryAllocate(rgbaSize);
// texture->rgba = (u16*)memalign(32, rgbaSize);
// assertNotNull(texture->rgba, "Failed to allocate texture RGBA data");
// for(uint32_t y = 0; y < height; ++y) { for(uint32_t y = 0; y < height; ++y) {
// for(uint32_t x = 0; x < width; ++x) { for(uint32_t x = 0; x < width; ++x) {
// const int src = y * width + x; const int src = y * width + x;
// const int tileX = x >> 2; const int tileX = x >> 2;
// const int tileY = y >> 2; const int tileY = y >> 2;
// const int tilesPerRow = width >> 2; const int tilesPerRow = width >> 2;
// const int tileIndex = tileY * tilesPerRow + tileX; const int tileIndex = tileY * tilesPerRow + tileX;
// const int tileBaseWords = tileIndex * 16; const int inTile = ((y & 3) << 2) + (x & 3);
// const int inTile = ((y & 3) << 2) + (x & 3); const int tileBase = tileIndex * 64;
// const int dest = tileBaseWords + inTile;
// color4b_t col = data.rgba.colors[src]; color_t col = data.rgbaColors[src];
// u16 outCol; // AR plane
// if(col.a < 255) { texture->rgba[tileBase + inTile * 2 + 0] = col.a;
// // 0AAA RRRR GGGG BBBB texture->rgba[tileBase + inTile * 2 + 1] = col.r;
// outCol = (
// (0u << 15) |
// ((u16)(col.a >> 5) << 12) |
// ((u16)(col.r >> 4) << 8) |
// ((u16)(col.g >> 4) << 4) |
// ((u16)(col.b >> 4) << 0)
// );
// } else {
// // 1RRRR RRGG GGGB BBBB
// outCol = (
// (1u << 15) |
// ((u16)(col.r >> 3) << 10) |
// ((u16)(col.g >> 3) << 5) |
// ((u16)(col.b >> 3) << 0)
// );
// }
// texture->rgba[dest] = outCol;
// }
// }
// DCFlushRange(texture->rgba, rgbaSize); // GB plane
// GX_InitTexObj( texture->rgba[tileBase + 32 + inTile * 2 + 0] = col.g;
// &texture->texObj, texture->rgba[tileBase + 32 + inTile * 2 + 1] = col.b;
// texture->rgba, }
// width, height, }
// GX_TF_RGB5A3, DCFlushRange(texture->rgba, rgbaSize);
// GX_REPEAT, GX_REPEAT, GX_InitTexObj(
// GX_FALSE &texture->texObj,
// ); texture->rgba,
width, height,
format,
GX_REPEAT, GX_REPEAT,
GX_FALSE
);
// DCFlushRange(texture->rgba, rgbaSize); DCFlushRange(texture->rgba, rgbaSize);
// GX_InvalidateTexAll(); GX_InvalidateTexAll();
// GX_InitTexObjLOD( GX_InitTexObjLOD(
// &texture->texObj, &texture->texObj,
// GX_NEAR, GX_NEAR, GX_NEAR, GX_NEAR,
// 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
// GX_FALSE, GX_FALSE,
// GX_FALSE, GX_FALSE,
// GX_ANISO_1 GX_ANISO_1
// ); );
// break; break;
}
// case TEXTURE_FORMAT_PALETTE: { case TEXTURE_FORMAT_PALETTE: {
// // Not supported, convert to RGBA using lookup assertUnreachable("Paletted textures not yet implemented for Dolphin");
// color_t* formatted = memoryAllocate(width * height * sizeof(color_t)); break;
// for(int32_t i = 0; i < width * height; i++) { }
// uint8_t index = data.palette.data[i];
// assertTrue(
// index < data.palette.palette->colorCount,
// "Palette index out of range"
// );
// formatted[i] = data.palette.palette->colors[index];
// }
// textureInit( default: {
// texture, width, height, TEXTURE_FORMAT_RGBA, assertUnreachable("Unsupported texture format for Dolphin");
// (texturedata_t){ break;
// .rgba = { .colors = formatted } }
// } }
// );
// memoryFree(formatted);
// break;
// }
// default:
// assertUnreachable("Unsupported texture format for Dolphin");
// break;
// }
// texture->ready = true;
errorOk(); errorOk();
} }
errorret_t textureBindDolphin(texturedolphin_t *texture) {
if(texture == NULL) {
GX_SetNumChans(0);
errorOk();
}
GX_SetNumChans(1);
GX_LoadTexObj(&texture->texObj, GX_TEXMAP0);
errorOk();
}
errorret_t textureDisposeDolphin(texturedolphin_t *texture) { errorret_t textureDisposeDolphin(texturedolphin_t *texture) {
switch(texture->format) {
case TEXTURE_FORMAT_RGBA: {
if(texture->rgba) {
memoryFree(texture->rgba);
texture->rgba = NULL;
}
break;
}
// case TEXTURE_FORMAT_RGB4A3: {
// assertUnreachable("RGB4A3 texture format not yet implemented");
// }
// case TEXTURE_FORMAT_RGB5: {
// assertUnreachable("RGB5 texture format not yet implemented");
// }
// case TEXTURE_FORMAT_PALETTE: {
// assertUnreachable("Paletted textures not yet implemented for Dolphin");
// break;
// }
default: {
assertUnreachable("Unsupported texture format for Dolphin");
break;
}
}
errorOk(); errorOk();
} }
void textureDolphinUploadTEV(void) {
if(TEXTURE_BOUND == NULL) {
GX_SetNumChans(1);
GX_SetChanCtrl(
GX_COLOR0A0,
GX_DISABLE,
GX_SRC_REG,
GX_SRC_VTX,
GX_LIGHTNULL,
GX_DF_NONE,
GX_AF_NONE
);
GX_SetChanAmbColor(GX_COLOR0A0, (GXColor){0, 0, 0, 0});
GX_SetChanMatColor(GX_COLOR0A0, (GXColor){255, 255, 255, 255});
GX_SetNumTexGens(0);
GX_SetNumTevStages(1);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
GX_SetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_CLEAR);
GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
return;
}
// Add channel for vertex color
GX_SetNumChans(1);
GX_SetChanCtrl(
GX_COLOR0A0,// Store in color channel 0
GX_DISABLE,// Lighting disabled
GX_SRC_REG,// Ambient color?
GX_SRC_VTX,// Material color?
GX_LIGHTNULL,// Light Mask
GX_DF_NONE,// Diffuse function
GX_AF_NONE// Attenuation function
);
// One set of UVs
GX_SetNumTexGens(1);
GX_SetTexCoordGen(
GX_TEXCOORD0,
GX_TG_MTX2x4,
GX_TG_TEX0,
GX_IDENTITY
);
// Basically the shader setup
switch(TEXTURE_BOUND->format) {
case TEXTURE_FORMAT_RGBA:
// One TEV stage: vertex color * texture color
GX_SetNumTevStages(1);
GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
GX_SetTevOrder(
GX_TEVSTAGE0,
GX_TEXCOORD0,
GX_TEXMAP0,
GX_COLOR0A0
);
GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
break;
default:
assertUnreachable("Unknown texture format in meshDraw");
break;
}
}

View File

@@ -13,6 +13,8 @@ typedef union texturedata_u texturedata_t;
typedef enum { typedef enum {
TEXTURE_FORMAT_RGBA = GX_TF_RGBA8, TEXTURE_FORMAT_RGBA = GX_TF_RGBA8,
TEXTURE_FORMAT_PALETTE = GX_TF_CI8, TEXTURE_FORMAT_PALETTE = GX_TF_CI8,
// TEXTURE_FORMAT_RGB4A3 = GX_TF_RGB5A3,
// TEXTURE_FORMAT_RGB5 = GX_TF_RGB565,
} textureformatdolphin_t; } textureformatdolphin_t;
typedef struct { typedef struct {
@@ -20,6 +22,11 @@ typedef struct {
textureformatdolphin_t format; textureformatdolphin_t format;
int32_t width; int32_t width;
int32_t height; int32_t height;
union {
uint8_t *rgba;
// u16 *rgba;
};
} texturedolphin_t; } texturedolphin_t;
/** /**
@@ -55,9 +62,3 @@ errorret_t textureBindDolphin(texturedolphin_t *texture);
* @return An error if the texture failed to dispose, otherwise success. * @return An error if the texture failed to dispose, otherwise success.
*/ */
errorret_t textureDisposeDolphin(texturedolphin_t *texture); errorret_t textureDisposeDolphin(texturedolphin_t *texture);
/**
* Internal method that uploads the texture environment variables to the GPU
* for rendering. This is basically uploading the shader information.
*/
void textureDolphinUploadTEV(void);

View File

@@ -59,7 +59,7 @@ void cameraPushMatrixGL(camera_t *camera) {
switch(camera->viewType) { switch(camera->viewType) {
case CAMERA_VIEW_TYPE_MATRIX: case CAMERA_VIEW_TYPE_MATRIX:
glm_mat4_copy(camera->view, view); glm_mat4_ucopy(camera->view, view);
break; break;
case CAMERA_VIEW_TYPE_LOOKAT: case CAMERA_VIEW_TYPE_LOOKAT:

View File

@@ -11,13 +11,6 @@ errorret_t displayOpenGLInit(void) {
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
errorChain(errorGLCheck()); errorChain(errorGLCheck());
#if DUSK_OPENGL_LEGACY
glDisable(GL_LIGHTING);// PSP defaults this on?
errorChain(errorGLCheck());
glShadeModel(GL_SMOOTH); // Fixes color on PSP?
errorChain(errorGLCheck());
#endif
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
errorChain(errorGLCheck()); errorChain(errorGLCheck());
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
@@ -29,10 +22,15 @@ errorret_t displayOpenGLInit(void) {
errorChain(errorGLCheck()); errorChain(errorGLCheck());
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
errorChain(errorGLCheck()); errorChain(errorGLCheck());
glPixelStorei(GL_PACK_ALIGNMENT, 1);
errorChain(errorGLCheck());
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
errorChain(errorGLCheck()); errorChain(errorGLCheck());
#if DUSK_OPENGL_LEGACY
glDisable(GL_LIGHTING);// PSP defaults this on?
errorChain(errorGLCheck());
glShadeModel(GL_SMOOTH); // Fixes color on PSP?
errorChain(errorGLCheck());
#endif
errorOk(); errorOk();
} }

View File

@@ -113,8 +113,10 @@ errorret_t meshFlushGL(
errorChain(errorGLCheck()); errorChain(errorGLCheck());
glBufferData( glBufferData(
GL_ARRAY_BUFFER, GL_ARRAY_BUFFER,
vertCount * sizeof(meshvertex_t), mesh->vertexCount * sizeof(meshvertex_t),
&mesh->vertices[vertOffset], mesh->vertices,
// vertCount * sizeof(meshvertex_t),
// &mesh->vertices[vertOffset],
GL_DYNAMIC_DRAW GL_DYNAMIC_DRAW
); );
errorChain(errorGLCheck()); errorChain(errorGLCheck());

View File

@@ -28,6 +28,11 @@ errorret_t shaderInitGL(shadergl_t *shader, const shaderdefinitiongl_t *def) {
SHADER_LEGACY.boundShader = NULL; SHADER_LEGACY.boundShader = NULL;
errorOk(); errorOk();
#else #else
assertNotNull(def->vert, "Vertex shader source cannot be null");
assertNotNull(def->frag, "Fragment shader source cannot be null");
shader->setTexture = def->setTexture;
// Create vertex shader // Create vertex shader
shader->vertexShaderId = glCreateShader(GL_VERTEX_SHADER); shader->vertexShaderId = glCreateShader(GL_VERTEX_SHADER);
errorret_t err = errorGLCheck(); errorret_t err = errorGLCheck();
@@ -152,11 +157,10 @@ errorret_t shaderParamGetLocationGL(
#ifdef DUSK_OPENGL_LEGACY #ifdef DUSK_OPENGL_LEGACY
assertUnreachable("Cannot get uniform locations on legacy opengl."); assertUnreachable("Cannot get uniform locations on legacy opengl.");
#else #else
shadergl_t *shaderGL = (shadergl_t *)shader; *location = glGetUniformLocation(shader->shaderProgramId, name);
*location = glGetUniformLocation(shaderGL->shaderProgramId, name); errorChain(errorGLCheck());
errorret_t err = errorGLCheck(); if(*location == -1) {
if(err.code != ERROR_OK) { errorThrow("Uniform '%s' not found in shader.", name);
errorChain(err);
} }
#endif #endif
@@ -169,25 +173,26 @@ errorret_t shaderSetMatrixGL(
mat4 mat mat4 mat
) { ) {
assertNotNull(shader, "Shader cannot be null"); assertNotNull(shader, "Shader cannot be null");
assertNotNull(mat, "Matrix data cannot be null");
assertStrLenMin(name, 1, "Uniform name cannot be empty"); assertStrLenMin(name, 1, "Uniform name cannot be empty");
assertNotNull(mat, "Matrix data cannot be null");
#ifdef DUSK_OPENGL_LEGACY #ifdef DUSK_OPENGL_LEGACY
assertTrue( assertTrue(
SHADER_LEGACY.boundShader == shader, SHADER_LEGACY.boundShader == shader,
"Shader must be bound to set legacy matrices." "Shader must be bound to set legacy matrices."
); );
// Use unaligned copy to safely handle possibly unaligned input matrices
if(stringCompare(name, SHADER_UNLIT_PROJECTION) == 0) { if(stringCompare(name, SHADER_UNLIT_PROJECTION) == 0) {
SHADER_LEGACY.dirty |= SHADER_LEGACY_DIRTY_PROJ; SHADER_LEGACY.dirty |= SHADER_LEGACY_DIRTY_PROJ;
glm_mat4_copy(mat, shader->proj); glm_mat4_ucopy(mat, shader->proj);
} else if(stringCompare(name, SHADER_UNLIT_VIEW) == 0) { } else if(stringCompare(name, SHADER_UNLIT_VIEW) == 0) {
SHADER_LEGACY.dirty |= SHADER_LEGACY_DIRTY_VIEW; SHADER_LEGACY.dirty |= SHADER_LEGACY_DIRTY_VIEW;
glm_mat4_copy(mat, shader->view); glm_mat4_ucopy(mat, shader->view);
} else if(stringCompare(name, SHADER_UNLIT_MODEL) == 0) { } else if(stringCompare(name, SHADER_UNLIT_MODEL) == 0) {
SHADER_LEGACY.dirty |= SHADER_LEGACY_DIRTY_MODEL; SHADER_LEGACY.dirty |= SHADER_LEGACY_DIRTY_MODEL;
glm_mat4_copy(mat, shader->model); glm_mat4_ucopy(mat, shader->model);
} else { } else {
assertUnreachable("Cannot use a custom matrix on legacy opengl."); assertUnreachable("Cannot use a custom matrix on legacy opengl.");
@@ -212,6 +217,12 @@ errorret_t shaderSetTextureGL(
assertStrLenMin(name, 1, "Uniform name cannot be empty"); assertStrLenMin(name, 1, "Uniform name cannot be empty");
#ifdef DUSK_OPENGL_LEGACY #ifdef DUSK_OPENGL_LEGACY
assertStringEqual(
name,
SHADER_UNLIT_TEXTURE,
"Only one texture supported in legacy opengl."
);
if(texture == NULL) { if(texture == NULL) {
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
errorChain(errorGLCheck()); errorChain(errorGLCheck());
@@ -226,44 +237,10 @@ errorret_t shaderSetTextureGL(
errorChain(errorGLCheck()); errorChain(errorGLCheck());
#else #else
if(texture == NULL) { if(shader->setTexture == NULL) {
glActiveTexture(GL_TEXTURE0); assertUnreachable("Shader does not support setting textures.");
errorChain(errorGLCheck());
glBindTexture(GL_TEXTURE_2D, 0);
errorChain(errorGLCheck());
errorOk();
} }
errorChain(shader->setTexture(shader, name, texture));
GLint location;
errorChain(shaderParamGetLocationGL(shader, name, &location));
glActiveTexture(GL_TEXTURE0);
errorChain(errorGLCheck());
glBindTexture(GL_TEXTURE_2D, texture->id);
errorChain(errorGLCheck());
glUniform1i(location, 0);
errorChain(errorGLCheck());
if(texture->format == TEXTURE_FORMAT_PALETTE) {
shaderParamGetLocationGL(shader, "u_ColorCount", &location);
glUniform1i(location, texture->palette->count);
errorChain(errorGLCheck());
shaderParamGetLocationGL(shader, "u_Colors", &location);
GLuint paletteData[texture->palette->count];
for(size_t i = 0; i < texture->palette->count; i++) {
color_t color = texture->palette->colors[i];
paletteData[i] = (
((uint32_t)color.r << 24) |
((uint32_t)color.g << 16) |
((uint32_t)color.b << 8) |
((uint32_t)color.a << 0)
);
}
glUniform1uiv(location, texture->palette->count, paletteData);
errorChain(errorGLCheck());
}
#endif #endif
errorOk(); errorOk();

View File

@@ -9,28 +9,35 @@
#include "error/errorgl.h" #include "error/errorgl.h"
#include "display/texture/texture.h" #include "display/texture/texture.h"
typedef struct { typedef struct shadergl_s shadergl_t;
typedef errorret_t (*shadersettexturefn_t)(
shadergl_t *,
const char_t *,
texture_t *
);
typedef struct shadergl_s {
#ifdef DUSK_OPENGL_LEGACY #ifdef DUSK_OPENGL_LEGACY
void *nothing; mat4 view;
mat4 proj;
mat4 model;
#else #else
GLuint shaderProgramId; GLuint shaderProgramId;
GLuint vertexShaderId; GLuint vertexShaderId;
GLuint fragmentShaderId; GLuint fragmentShaderId;
#endif shadersettexturefn_t setTexture;
#if DUSK_OPENGL_LEGACY
mat4 view;
mat4 proj;
mat4 model;
#endif #endif
} shadergl_t; } shadergl_t;
typedef struct { typedef struct {
#ifdef DUSK_OPENGL_LEGACY #ifdef DUSK_OPENGL_LEGACY
void *nothing; void *nothing;
#else #else
const char_t *vert; const char_t *vert;
const char_t *frag; const char_t *frag;
shadersettexturefn_t setTexture;
#endif #endif
} shaderdefinitiongl_t; } shaderdefinitiongl_t;

View File

@@ -6,19 +6,89 @@
*/ */
#include "display/shader/shaderunlit.h" #include "display/shader/shaderunlit.h"
#include "assert/assertgl.h"
#ifdef DUSK_OPENGL_LEGACY #ifdef DUSK_OPENGL_LEGACY
shaderdefinition_t SHADER_UNLIT_DEFINITION = { 0 }; shaderdefinition_t SHADER_UNLIT_DEFINITION = { 0 };
#else #else
errorret_t shaderUnlitSetTextureGL(
shadergl_t *shader,
const char_t *name,
texture_t *texture
) {
assertNotNull(shader, "Shader cannot be null");
assertStrLenMin(name, 1, "Uniform name cannot be empty");
assertStringEqual(
name,
SHADER_UNLIT_TEXTURE,
"Only one texture supported in unlit shader."
);
GLint locTexture, locType, locColorCount, locColors;
errorChain(shaderParamGetLocationGL(shader, "u_TextureType", &locType));
// NULL textures
if(texture == NULL) {
glUniform1i(locType, 0);
errorChain(errorGLCheck());
errorOk();
}
// Set texture.
glActiveTexture(GL_TEXTURE0);
errorChain(errorGLCheck());
glBindTexture(GL_TEXTURE_2D, texture->id);
errorChain(errorGLCheck());
errorChain(shaderParamGetLocationGL(shader, name, &locTexture));
glUniform1i(locTexture, 0);
errorChain(errorGLCheck());
// Set texture type
if(texture->format == TEXTURE_FORMAT_PALETTE) {
glUniform1i(locType, 2);
errorChain(errorGLCheck());
shaderParamGetLocationGL(shader, "u_ColorCount", &locColorCount);
glUniform1i(locColorCount, texture->palette->count);
errorChain(errorGLCheck());
shaderParamGetLocationGL(shader, "u_Colors", &locColors);
GLuint paletteData[texture->palette->count];
for(size_t i = 0; i < texture->palette->count; i++) {
color_t color = texture->palette->colors[i];
paletteData[i] = (
((uint32_t)color.r << 24) |
((uint32_t)color.g << 16) |
((uint32_t)color.b << 8) |
((uint32_t)color.a << 0)
);
}
glUniform1uiv(locColors, texture->palette->count, paletteData);
errorChain(errorGLCheck());
} else {
glUniform1i(locType, 1);
errorChain(errorGLCheck());
}
errorOk();
}
shaderdefinition_t SHADER_UNLIT_DEFINITION = { shaderdefinition_t SHADER_UNLIT_DEFINITION = {
.vert = .vert =
"#version 330 core\n" #ifdef DUSK_OPENGL_ES
"#version 300 es\n"
"precision mediump float;\n"
// Attributes
"layout(location = 0) in vec3 a_Pos;\n" "layout(location = 0) in vec3 a_Pos;\n"
"layout(location = 1) in vec2 a_TexCoord;\n" "layout(location = 1) in vec2 a_TexCoord;\n"
"layout(location = 2) in vec4 a_Color;\n" "layout(location = 2) in vec4 a_Color;\n"
// Uniforms
"uniform mat4 u_Proj;\n" "uniform mat4 u_Proj;\n"
"uniform mat4 u_View;\n" "uniform mat4 u_View;\n"
"uniform mat4 u_Model;\n" "uniform mat4 u_Model;\n"
// Vertex shader outputs
"out vec4 v_Color;\n" "out vec4 v_Color;\n"
"out vec2 v_TexCoord;\n" "out vec2 v_TexCoord;\n"
"void main() {\n" "void main() {\n"
@@ -26,16 +96,49 @@
" v_Color = a_Color;\n" " v_Color = a_Color;\n"
" v_TexCoord = a_TexCoord;\n" " v_TexCoord = a_TexCoord;\n"
"}\n", "}\n",
#else
.frag =
"#version 330 core\n" "#version 330 core\n"
// Attributes
"layout(location = 0) in vec3 a_Pos;\n"
"layout(location = 1) in vec2 a_TexCoord;\n"
"layout(location = 2) in vec4 a_Color;\n"
// Uniforms
"uniform mat4 u_Proj;\n"
"uniform mat4 u_View;\n"
"uniform mat4 u_Model;\n"
// Vertex shader outputs
"out vec4 v_Color;\n"
"out vec2 v_TexCoord;\n"
"void main() {\n"
" gl_Position = u_Proj * u_View * u_Model * vec4(a_Pos, 1.0);\n"
" v_Color = a_Color;\n"
" v_TexCoord = a_TexCoord;\n"
"}\n",
#endif
.frag =
#ifdef DUSK_OPENGL_ES
"#version 300 es\n"
"precision mediump float;\n"
// Uniforms
"uniform sampler2D u_Texture;\n" "uniform sampler2D u_Texture;\n"
"uniform uint u_Colors[256];\n" "uniform int u_TextureType;\n"
"uniform uint u_Colors[256];\n"// For paletted textures.
"uniform int u_ColorCount;\n" "uniform int u_ColorCount;\n"
// Fragment shader inputs
"in vec4 v_Color;\n" "in vec4 v_Color;\n"
"in vec2 v_TexCoord;\n" "in vec2 v_TexCoord;\n"
// Fragment shader output
"out vec4 FragColor;\n" "out vec4 FragColor;\n"
"void main() {\n" "void main() {\n"
" if(u_TextureType == 0) {\n"// No texture
" FragColor = v_Color;\n"
" return;\n"
" }\n"
" if(u_TextureType == 1) {\n"// Regular texture
" FragColor = texture(u_Texture, v_TexCoord) * v_Color;\n"
" return;\n"
" }\n"
" if(u_TextureType == 2) {\n"// Paletted texture
" vec4 texColor = texture(u_Texture, v_TexCoord);\n" " vec4 texColor = texture(u_Texture, v_TexCoord);\n"
" uint index = uint(floor(texColor.r * 255.0));\n" " uint index = uint(floor(texColor.r * 255.0));\n"
" uint palColor = u_Colors[index];\n" " uint palColor = u_Colors[index];\n"
@@ -45,7 +148,47 @@
" float a = float((palColor >> 0) & 0xFFu) / 255.0;\n" " float a = float((palColor >> 0) & 0xFFu) / 255.0;\n"
" vec4 paletteColor = vec4(r, g, b, a);\n" " vec4 paletteColor = vec4(r, g, b, a);\n"
" FragColor = paletteColor;\n" " FragColor = paletteColor;\n"
// " FragColor = paletteColor * v_Color;\n" " return;\n"
" }\n" " }\n"
" FragColor = v_Color;\n"// Unknown texture type?
"}\n",
#else
"#version 330 core\n"
// Uniforms
"uniform sampler2D u_Texture;\n"
"uniform int u_TextureType;\n"
"uniform uint u_Colors[256];\n"// For paletted textures.
"uniform int u_ColorCount;\n"
// Fragment shader inputs
"in vec4 v_Color;\n"
"in vec2 v_TexCoord;\n"
// Fragment shader output
"out vec4 FragColor;\n"
"void main() {\n"
" if(u_TextureType == 0) {\n"// No texture
" FragColor = v_Color;\n"
" return;\n"
" }\n"
" if(u_TextureType == 1) {\n"// Regular texture
" FragColor = texture(u_Texture, v_TexCoord) * v_Color;\n"
" return;\n"
" }\n"
" if(u_TextureType == 2) {\n"// Paletted texture
" vec4 texColor = texture(u_Texture, v_TexCoord);\n"
" uint index = uint(floor(texColor.r * 255.0));\n"
" uint palColor = u_Colors[index];\n"
" float r = float((palColor >> 24) & 0xFFu) / 255.0;\n"
" float g = float((palColor >> 16) & 0xFFu) / 255.0;\n"
" float b = float((palColor >> 8) & 0xFFu) / 255.0;\n"
" float a = float((palColor >> 0) & 0xFFu) / 255.0;\n"
" vec4 paletteColor = vec4(r, g, b, a);\n"
" FragColor = paletteColor;\n"
" return;\n"
" }\n"
" FragColor = v_Color;\n"// Unknown texture type?
"}\n",
#endif
.setTexture = shaderUnlitSetTextureGL
}; };
#endif #endif

View File

@@ -25,16 +25,25 @@ errorret_t textureInitGL(
switch(format) { switch(format) {
case TEXTURE_FORMAT_RGBA: case TEXTURE_FORMAT_RGBA:
glTexImage2D( glTexImage2D(
GL_TEXTURE_2D, 0, format, width, height, 0, GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
format, GL_UNSIGNED_BYTE, (void*)data.rgbaColors GL_RGBA, GL_UNSIGNED_BYTE, (void*)data.rgbaColors
); );
errorChain(errorGLCheck()); errorChain(errorGLCheck());
break; break;
case TEXTURE_FORMAT_PALETTE: case TEXTURE_FORMAT_PALETTE:
texture->palette = data.paletted.palette; texture->palette = data.paletted.palette;
assertTrue(
texture->palette == &PALETTES[0],
"Only the first palette is supported in legacy opengl."
);
#ifdef DUSK_OPENGL_LEGACY #ifdef DUSK_OPENGL_LEGACY
glColorTableEXT(
GL_TEXTURE_2D, GL_RGBA, texture->palette->count, GL_RGBA,
GL_UNSIGNED_BYTE, (const void*)texture->palette->colors
);
errorChain(errorGLCheck());
glTexImage2D( glTexImage2D(
GL_TEXTURE_2D, GL_TEXTURE_2D,
0, GL_COLOR_INDEX8_EXT, 0, GL_COLOR_INDEX8_EXT,
@@ -42,13 +51,7 @@ errorret_t textureInitGL(
0, GL_COLOR_INDEX8_EXT, 0, GL_COLOR_INDEX8_EXT,
GL_UNSIGNED_BYTE, (void*)data.paletted.indices GL_UNSIGNED_BYTE, (void*)data.paletted.indices
); );
glColorTableEXT(
GL_TEXTURE_2D, GL_RGBA, texture->palette->count, GL_RGBA,
GL_UNSIGNED_BYTE, (const void*)texture->palette->colors
);
errorChain(errorGLCheck()); errorChain(errorGLCheck());
#else #else
// For modern systems we send to only the R channel and the shader does // For modern systems we send to only the R channel and the shader does
// the rest. // the rest.

View File

@@ -13,6 +13,7 @@ typedef union texturedata_u texturedata_t;
typedef enum { typedef enum {
TEXTURE_FORMAT_RGBA = GL_RGBA, TEXTURE_FORMAT_RGBA = GL_RGBA,
TEXTURE_FORMAT_PALETTE = GL_COLOR_INDEX8_EXT, TEXTURE_FORMAT_PALETTE = GL_COLOR_INDEX8_EXT,
// TEXTURE_FORMAT_DXT5 = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
} textureformatgl_t; } textureformatgl_t;
typedef struct { typedef struct {

View File

@@ -6,6 +6,20 @@
*/ */
#pragma once #pragma once
#ifdef DUSK_OPENGL_ES
#include <GLES3/gl3.h>
#define GL_COLOR_INDEX8_EXT 0x80E5
#define GL_FRAMEBUFFER_EXT GL_FRAMEBUFFER
#define GL_FRAMEBUFFER_COMPLETE_EXT GL_FRAMEBUFFER_COMPLETE
#define glCheckFramebufferStatusEXT glCheckFramebufferStatus
#define glDeleteFramebuffersEXT glDeleteFramebuffers
#define glGenFramebuffersEXT glGenFramebuffers
#define glBindFramebufferEXT glBindFramebuffer
#define glFramebufferTexture2DEXT glFramebufferTexture2D
#define GL_COLOR_ATTACHMENT0_EXT GL_COLOR_ATTACHMENT0
#define glClearDepth(depth) glClearDepthf(depth)
#else
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glext.h> #include <GL/glext.h>
#endif

View File

@@ -19,4 +19,5 @@ void logError(const char_t *message, ...) {
va_start(args, message); va_start(args, message);
vprintf(message, args); vprintf(message, args);
va_end(args); va_end(args);
fflush(stdout);
} }

View File

@@ -0,0 +1,16 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Includes
target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
# Subdirs
add_subdirectory(item)
add_subdirectory(map)
add_subdirectory(story)
add_subdirectory(script)

View File

@@ -0,0 +1,7 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Subdirs
add_subdirectory(module)

View File

@@ -0,0 +1,9 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Subdirectories
add_subdirectory(item)
add_subdirectory(map)
add_subdirectory(story)

View File

@@ -0,0 +1,16 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "script/module/item/moduleitem.h"
#include "script/module/story/modulestoryflag.h"
#include "script/module/map/modulemap.h"
#define SCRIPT_GAME_LIST \
{ .name = "item", .callback = moduleItem }, \
{ .name = "storyflag", .callback = moduleStoryFlag }, \
{ .name = "map", .callback = moduleMap },

Some files were not shown because too many files have changed in this diff Show More