Compare commits

...

5 Commits

Author SHA1 Message Date
e1835e6282 Merge pull request 'Pull shader code into main' (#1) from shader into main
Some checks failed
Build Dusk / build-linux (push) Has been cancelled
Build Dusk / build-psp (push) Has been cancelled
Build Dusk / run-tests (push) Has been cancelled
Build Dusk / build-gamecube (push) Has been cancelled
Build Dusk / build-wii (push) Has been cancelled
Reviewed-on: #1
2026-03-22 15:46:37 +00:00
5ac21db997 Shaders adapted for Legacy GL
Some checks failed
Build Dusk / run-tests (pull_request) Failing after 24s
Build Dusk / build-linux (pull_request) Failing after 18s
Build Dusk / build-psp (pull_request) Failing after 18s
Build Dusk / build-gamecube (pull_request) Failing after 15s
Build Dusk / build-wii (pull_request) Failing after 16s
2026-03-22 10:44:28 -05:00
ca0e9fc3b2 Implement spritebatch properly. 2026-03-22 09:13:42 -05:00
66ebcb1608 shader prog 2026-03-17 17:05:39 -05:00
ff92a78dda Shader first pass 2026-03-17 08:42:43 -05:00
41 changed files with 1071 additions and 175 deletions

View File

@@ -156,7 +156,7 @@ class Map:
newTopLeftChunkY = y // CHUNK_HEIGHT - (MAP_HEIGHT // 2) newTopLeftChunkY = y // CHUNK_HEIGHT - (MAP_HEIGHT // 2)
newTopLeftChunkZ = z // CHUNK_DEPTH - (MAP_DEPTH // 2) newTopLeftChunkZ = z // CHUNK_DEPTH - (MAP_DEPTH // 2)
if (newTopLeftChunkX != self.topLeftX or if(newTopLeftChunkX != self.topLeftX or
newTopLeftChunkY != self.topLeftY or newTopLeftChunkY != self.topLeftY or
newTopLeftChunkZ != self.topLeftZ): newTopLeftChunkZ != self.topLeftZ):
@@ -166,7 +166,7 @@ class Map:
chunkWorldX = chunk.x chunkWorldX = chunk.x
chunkWorldY = chunk.y chunkWorldY = chunk.y
chunkWorldZ = chunk.z chunkWorldZ = chunk.z
if (chunkWorldX < newTopLeftChunkX or if(chunkWorldX < newTopLeftChunkX or
chunkWorldX >= newTopLeftChunkX + MAP_WIDTH or chunkWorldX >= newTopLeftChunkX + MAP_WIDTH or
chunkWorldY < newTopLeftChunkY or chunkWorldY < newTopLeftChunkY or
chunkWorldY >= newTopLeftChunkY + MAP_HEIGHT or chunkWorldY >= newTopLeftChunkY + MAP_HEIGHT or

View File

@@ -192,7 +192,7 @@ function sceneRender()
spriteBatchPush( spriteBatchPush(
nil, nil,
x, y, x + 32, y + 32, x, y, x + 32, y + 32,
colorBlue() colorWhite()
) )
-- Update mouse position -- Update mouse position

View File

@@ -29,6 +29,7 @@ target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
DUSK_SDL2 DUSK_SDL2
DUSK_OPENGL DUSK_OPENGL
DUSK_LINUX DUSK_LINUX
DUSK_OPENGL_LEGACY
DUSK_DISPLAY_SIZE_DYNAMIC DUSK_DISPLAY_SIZE_DYNAMIC
DUSK_DISPLAY_WIDTH_DEFAULT=640 DUSK_DISPLAY_WIDTH_DEFAULT=640
DUSK_DISPLAY_HEIGHT_DEFAULT=480 DUSK_DISPLAY_HEIGHT_DEFAULT=480

View File

@@ -36,6 +36,7 @@ target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
DUSK_PSP DUSK_PSP
DUSK_INPUT_GAMEPAD DUSK_INPUT_GAMEPAD
DUSK_PLATFORM_ENDIAN_LITTLE DUSK_PLATFORM_ENDIAN_LITTLE
DUSK_OPENGL_LEGACY
DUSK_DISPLAY_WIDTH=480 DUSK_DISPLAY_WIDTH=480
DUSK_DISPLAY_HEIGHT=272 DUSK_DISPLAY_HEIGHT=272
) )

View File

@@ -14,6 +14,7 @@ add_subdirectory(camera)
add_subdirectory(framebuffer) add_subdirectory(framebuffer)
add_subdirectory(mesh) add_subdirectory(mesh)
add_subdirectory(screen) add_subdirectory(screen)
add_subdirectory(shader)
add_subdirectory(spritebatch) add_subdirectory(spritebatch)
add_subdirectory(text) add_subdirectory(text)
add_subdirectory(texture) add_subdirectory(texture)

View File

@@ -45,13 +45,63 @@ void cameraInitOrthographic(camera_t *camera) {
camera->_2d.zoom = 1.0f; camera->_2d.zoom = 1.0f;
} }
void cameraPushMatrix(camera_t *camera) { void cameraGetProjectionMatrix(camera_t *camera, mat4 dest) {
assertNotNull(camera, "Invalid camera"); assertNotNull(camera, "Not a camera component");
cameraPushMatrixPlatform(camera); assertNotNull(dest, "Destination matrix must not be null");
if(
camera->projType == CAMERA_PROJECTION_TYPE_PERSPECTIVE ||
camera->projType == CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED
) {
glm_mat4_identity(dest);
glm_perspective(
camera->perspective.fov,
SCREEN.aspect,
camera->nearClip,
camera->farClip,
dest
);
if(camera->projType == CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED) {
dest[1][1] *= -1.0f;
}
} else if(camera->projType == CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) {
glm_mat4_identity(dest);
glm_ortho(
camera->orthographic.left,
camera->orthographic.right,
camera->orthographic.top,
camera->orthographic.bottom,
camera->nearClip,
camera->farClip,
dest
);
}
} }
void cameraPopMatrix(void) { void cameraGetViewMatrix(camera_t *camera, mat4 dest) {
#ifdef cameraPopMatrixPlatform assertNotNull(camera, "Not a camera component");
cameraPopMatrixPlatform(); assertNotNull(dest, "Destination matrix must not be null");
#endif
if(camera->viewType == CAMERA_VIEW_TYPE_MATRIX) {
glm_mat4_copy(camera->view, dest);
} else if(camera->viewType == CAMERA_VIEW_TYPE_LOOKAT) {
glm_mat4_identity(dest);
glm_lookat(
camera->lookat.position,
camera->lookat.target,
camera->lookat.up,
dest
);
} else if(camera->viewType == CAMERA_VIEW_TYPE_2D) {
glm_mat4_identity(dest);
glm_lookat(
(vec3){ camera->_2d.position[0], camera->_2d.position[1], 0.5f },
(vec3){ camera->_2d.position[0], camera->_2d.position[1], 0.0f },
(vec3){ 0.0f, 1.0f, 0.0f },
dest
);
} else if(camera->viewType == CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT) {
assertUnreachable("LOOKAT_PIXEL_PERFECT view type is not implemented yet");
}
} }

View File

@@ -86,13 +86,17 @@ void cameraInitPerspective(camera_t *camera);
void cameraInitOrthographic(camera_t *camera); void cameraInitOrthographic(camera_t *camera);
/** /**
* Pushes the camera's view matrix onto the matrix stack. * Gets the projection matrix for a camera.
* *
* @param id The ID of the camera entity to use. * @param camera Camera to get the projection matrix for
* @param dest Matrix to store the projection matrix in
*/ */
void cameraPushMatrix(camera_t *camera); void cameraGetProjectionMatrix(camera_t *camera, mat4 dest);
/** /**
* Pops the camera's view matrix off the matrix stack. * Gets the view matrix for a camera.
*
* @param camera Camera to get the view matrix for
* @param dest Matrix to store the view matrix in
*/ */
void cameraPopMatrix(void); void cameraGetViewMatrix(camera_t *camera, mat4 dest);

View File

@@ -17,6 +17,8 @@
#include "util/memory.h" #include "util/memory.h"
#include "util/string.h" #include "util/string.h"
#include "asset/asset.h" #include "asset/asset.h"
#include "display/shader/shaderunlit.h"
#include "time/time.h"
display_t DISPLAY = { 0 }; display_t DISPLAY = { 0 };
@@ -27,6 +29,7 @@ errorret_t displayInit(void) {
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());
@@ -46,16 +49,40 @@ errorret_t displayUpdate(void) {
errorChain(frameBufferBind(NULL)); errorChain(frameBufferBind(NULL));
// Bind screen and render scene // Bind screen and render scene
screenBind(); errorChain(screenBind());
frameBufferClear( frameBufferClear(
FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH, FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH,
SCREEN.background SCREEN.background
); );
errorChain(sceneRender()); errorChain(shaderBind(&SHADER_UNLIT));
camera_t camera;
cameraInitOrthographic(&camera);
camera.orthographic.left = 0.0f;
camera.orthographic.right = SCREEN.width;
camera.orthographic.top = SCREEN.height;
camera.orthographic.bottom = 0.0f;
mat4 proj, view, model;
cameraGetProjectionMatrix(&camera, proj);
cameraGetViewMatrix(&camera, view);
glm_mat4_identity(model);
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(spriteBatchPush(
NULL,
TIME.time * 2.0f, TIME.time * 3.0f, 100, 100, COLOR_WHITE, 0, 0, 1, 1
));
errorChain(spriteBatchFlush());
// errorCatch(errorPrint(sceneRender()));
// Render UI // Render UI
uiRender(); // uiRender();
// Finish up // Finish up
screenUnbind(); screenUnbind();
@@ -69,6 +96,7 @@ errorret_t displayUpdate(void) {
} }
errorret_t displayDispose(void) { errorret_t displayDispose(void) {
errorChain(shaderDispose(&SHADER_UNLIT));
errorChain(spriteBatchDispose()); errorChain(spriteBatchDispose());
screenDispose(); screenDispose();
errorChain(textDispose()); errorChain(textDispose());

View File

@@ -25,6 +25,29 @@ errorret_t meshInit(
errorOk(); errorOk();
} }
errorret_t meshFlush(
mesh_t *mesh,
const int32_t vertexOffset,
const int32_t vertexCount
) {
#ifdef meshFlushPlatform
assertNotNull(mesh, "Mesh cannot be NULL");
assertTrue(vertexOffset >= 0, "Vertex offset must be non-negative.");
assertTrue(vertexCount == -1 || vertexCount > 0, "Vertex count incorrect.");
int32_t vertCount = meshGetVertexCount(mesh);
assertTrue(vertexOffset < (vertCount - 1), "Need at least one vert to draw");
int32_t drawCount = vertexCount;
if(vertexCount == -1) {
drawCount = vertCount - vertexOffset;
}
errorChain(meshFlushPlatform(mesh, vertexOffset, vertexCount));
#endif
errorOk();
}
errorret_t meshDraw( errorret_t meshDraw(
const mesh_t *mesh, const mesh_t *mesh,
const int32_t vertexOffset, const int32_t vertexOffset,
@@ -32,7 +55,7 @@ errorret_t meshDraw(
) { ) {
assertNotNull(mesh, "Mesh cannot be NULL"); assertNotNull(mesh, "Mesh cannot be NULL");
assertTrue(vertexOffset >= 0, "Vertex offset must be non-negative"); assertTrue(vertexOffset >= 0, "Vertex offset must be non-negative");
assertTrue(vertexCount >= -1, "Vertex count must be -1 or non-negative"); assertTrue(vertexCount == -1 || vertexCount > 0, "Incorrect vert count");
int32_t vertDrawCount = vertexCount; int32_t vertDrawCount = vertexCount;
if(vertexCount == -1) { if(vertexCount == -1) {

View File

@@ -40,6 +40,22 @@ errorret_t meshInit(
const meshvertex_t *vertices const meshvertex_t *vertices
); );
/**
* Instructs the mesh to flush the vertices to the GPU. This is surprisingly
* only really necessary on modern devices, as we tend to let older devices
* read the vertices from the main memory directly.
*
* @param mesh Mesh to flush the vertices for.
* @param vertexOffset Start vertex to flush.
* @param vertexCount Count of vertices to flush, set to -1 for all.
* @return Error state.
*/
errorret_t meshFlush(
mesh_t *mesh,
const int32_t vertexOffset,
const int32_t vertexCount
);
/** /**
* Draws a mesh. * Draws a mesh.
* *

View File

@@ -9,6 +9,7 @@
#include "assert/assert.h" #include "assert/assert.h"
#include "util/memory.h" #include "util/memory.h"
#include "display/mesh/quad.h" #include "display/mesh/quad.h"
#include "display/shader/shaderunlit.h"
screen_t SCREEN; screen_t SCREEN;
@@ -44,11 +45,11 @@ errorret_t screenInit() {
#endif #endif
// Init screen to backbuffer mode by default // Init screen to backbuffer mode by default
screenBind(); errorChain(screenBind());
errorOk(); errorOk();
} }
void screenBind() { errorret_t screenBind() {
// Assume backbuffer is currently bound. // Assume backbuffer is currently bound.
switch(SCREEN.mode) { switch(SCREEN.mode) {
case SCREEN_MODE_BACKBUFFER: { case SCREEN_MODE_BACKBUFFER: {
@@ -59,7 +60,7 @@ void screenBind() {
// No needd for a framebuffer. // No needd for a framebuffer.
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC #ifdef DUSK_DISPLAY_SIZE_DYNAMIC
if(SCREEN.framebufferReady) { if(SCREEN.framebufferReady) {
frameBufferDispose(&SCREEN.framebuffer); errorChain(frameBufferDispose(&SCREEN.framebuffer));
SCREEN.framebufferReady = false; SCREEN.framebufferReady = false;
} }
#endif #endif
@@ -79,19 +80,21 @@ void screenBind() {
curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer); curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer);
if(curFbWidth == SCREEN.width && curFbHeight == SCREEN.height) { if(curFbWidth == SCREEN.width && curFbHeight == SCREEN.height) {
// Correct size, nothing to do. // Correct size, nothing to do.
frameBufferBind(&SCREEN.framebuffer); errorChain(frameBufferBind(&SCREEN.framebuffer));
return; errorOk();
} }
// Need a new framebuffer. // Need a new framebuffer.
frameBufferDispose(&SCREEN.framebuffer); errorChain(frameBufferDispose(&SCREEN.framebuffer));
SCREEN.framebufferReady = false; SCREEN.framebufferReady = false;
} }
// Create new framebuffer // Create new framebuffer
frameBufferInit(&SCREEN.framebuffer, SCREEN.width, SCREEN.height); errorChain(frameBufferInit(
&SCREEN.framebuffer, SCREEN.width, SCREEN.height
));
SCREEN.framebufferReady = true; SCREEN.framebufferReady = true;
frameBufferBind(&SCREEN.framebuffer); errorChain(frameBufferBind(&SCREEN.framebuffer));
break; break;
} }
@@ -109,10 +112,10 @@ void screenBind() {
SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height; SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height;
if(SCREEN.framebufferReady) { if(SCREEN.framebufferReady) {
frameBufferDispose(&SCREEN.framebuffer); errorChain(frameBufferDispose(&SCREEN.framebuffer));
SCREEN.framebufferReady = false; SCREEN.framebufferReady = false;
} }
return; errorOk();
} }
int32_t newFbWidth, newFbHeight; int32_t newFbWidth, newFbHeight;
@@ -136,24 +139,26 @@ void screenBind() {
SCREEN.width = newFbWidth; SCREEN.width = newFbWidth;
SCREEN.height = newFbHeight; SCREEN.height = newFbHeight;
SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height; SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height;
frameBufferBind(&SCREEN.framebuffer); errorChain(frameBufferBind(&SCREEN.framebuffer));
return; errorOk();
} }
// Need a new framebuffer. // Need a new framebuffer.
frameBufferDispose(&SCREEN.framebuffer); errorChain(frameBufferDispose(&SCREEN.framebuffer));
SCREEN.framebufferReady = false; SCREEN.framebufferReady = false;
} }
// Create new framebuffer // Create new framebuffer
frameBufferInit(&SCREEN.framebuffer, newFbWidth, newFbHeight); errorChain(frameBufferInit(
&SCREEN.framebuffer, newFbWidth, newFbHeight
));
SCREEN.width = newFbWidth; SCREEN.width = newFbWidth;
SCREEN.height = newFbHeight; SCREEN.height = newFbHeight;
SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height; SCREEN.aspect = (float_t)SCREEN.width / (float_t)SCREEN.height;
SCREEN.framebufferReady = true; SCREEN.framebufferReady = true;
// Bind FB // Bind FB
frameBufferBind(&SCREEN.framebuffer); errorChain(frameBufferBind(&SCREEN.framebuffer));
break; break;
} }
@@ -173,10 +178,10 @@ void screenBind() {
if(fbWidth == newFbWidth && fbHeight == newFbHeight) { if(fbWidth == newFbWidth && fbHeight == newFbHeight) {
// No need to use framebuffer. // No need to use framebuffer.
if(SCREEN.framebufferReady) { if(SCREEN.framebufferReady) {
frameBufferDispose(&SCREEN.framebuffer); errorChain(frameBufferDispose(&SCREEN.framebuffer));
SCREEN.framebufferReady = false; SCREEN.framebufferReady = false;
} }
return; errorOk();
} }
if(SCREEN.framebufferReady) { if(SCREEN.framebufferReady) {
@@ -185,19 +190,21 @@ void screenBind() {
curFbWidth = frameBufferGetWidth(&SCREEN.framebuffer); curFbWidth = frameBufferGetWidth(&SCREEN.framebuffer);
curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer); curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer);
if(curFbWidth == newFbWidth && curFbHeight == newFbHeight) { if(curFbWidth == newFbWidth && curFbHeight == newFbHeight) {
frameBufferBind(&SCREEN.framebuffer); errorChain(frameBufferBind(&SCREEN.framebuffer));
return; errorOk();
} }
// Need a new framebuffer. // Need a new framebuffer.
frameBufferDispose(&SCREEN.framebuffer); errorChain(frameBufferDispose(&SCREEN.framebuffer));
SCREEN.framebufferReady = false; SCREEN.framebufferReady = false;
} }
// Create a new framebuffer. // Create a new framebuffer.
frameBufferInit(&SCREEN.framebuffer, newFbWidth, newFbHeight); errorChain(frameBufferInit(
&SCREEN.framebuffer, newFbWidth, newFbHeight
));
SCREEN.framebufferReady = true; SCREEN.framebufferReady = true;
frameBufferBind(&SCREEN.framebuffer); errorChain(frameBufferBind(&SCREEN.framebuffer));
break; break;
} }
@@ -217,10 +224,10 @@ void screenBind() {
if(fbWidth == newFbWidth && fbHeight == newFbHeight) { if(fbWidth == newFbWidth && fbHeight == newFbHeight) {
// No need to use framebuffer. // No need to use framebuffer.
if(SCREEN.framebufferReady) { if(SCREEN.framebufferReady) {
frameBufferDispose(&SCREEN.framebuffer); errorChain(frameBufferDispose(&SCREEN.framebuffer));
SCREEN.framebufferReady = false; SCREEN.framebufferReady = false;
} }
return; errorOk();
} }
if(SCREEN.framebufferReady) { if(SCREEN.framebufferReady) {
@@ -229,19 +236,21 @@ void screenBind() {
curFbWidth = frameBufferGetWidth(&SCREEN.framebuffer); curFbWidth = frameBufferGetWidth(&SCREEN.framebuffer);
curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer); curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer);
if(curFbWidth == newFbWidth && curFbHeight == newFbHeight) { if(curFbWidth == newFbWidth && curFbHeight == newFbHeight) {
frameBufferBind(&SCREEN.framebuffer); errorChain(frameBufferBind(&SCREEN.framebuffer));
return; errorOk();
} }
// Need a new framebuffer. // Need a new framebuffer.
frameBufferDispose(&SCREEN.framebuffer); errorChain(frameBufferDispose(&SCREEN.framebuffer));
SCREEN.framebufferReady = false; SCREEN.framebufferReady = false;
} }
// Create a new framebuffer. // Create a new framebuffer.
frameBufferInit(&SCREEN.framebuffer, newFbWidth, newFbHeight); errorChain(frameBufferInit(
&SCREEN.framebuffer, newFbWidth, newFbHeight
));
SCREEN.framebufferReady = true; SCREEN.framebufferReady = true;
frameBufferBind(&SCREEN.framebuffer); errorChain(frameBufferBind(&SCREEN.framebuffer));
break; break;
} }
@@ -262,9 +271,11 @@ void screenBind() {
break; break;
} }
} }
errorOk();
} }
void screenUnbind() { errorret_t screenUnbind() {
switch(SCREEN.mode) { switch(SCREEN.mode) {
// Nothing to do here. // Nothing to do here.
case SCREEN_MODE_BACKBUFFER: case SCREEN_MODE_BACKBUFFER:
@@ -275,7 +286,9 @@ void screenUnbind() {
case SCREEN_MODE_FIXED_HEIGHT: case SCREEN_MODE_FIXED_HEIGHT:
case SCREEN_MODE_FIXED_SIZE: case SCREEN_MODE_FIXED_SIZE:
case SCREEN_MODE_FIXED_WIDTH: case SCREEN_MODE_FIXED_WIDTH:
if(SCREEN.framebufferReady) frameBufferBind(NULL); if(SCREEN.framebufferReady) {
errorChain(frameBufferBind(NULL));
}
break; break;
case SCREEN_MODE_FIXED_VIEWPORT_HEIGHT: case SCREEN_MODE_FIXED_VIEWPORT_HEIGHT:
@@ -286,17 +299,19 @@ void screenUnbind() {
assertUnreachable("Invalid screen mode."); assertUnreachable("Invalid screen mode.");
break; break;
} }
errorOk();
} }
void screenRender() { errorret_t screenRender() {
if(SCREEN.mode == SCREEN_MODE_BACKBUFFER) { if(SCREEN.mode == SCREEN_MODE_BACKBUFFER) {
return; errorOk();
} }
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC #ifdef DUSK_DISPLAY_SIZE_DYNAMIC
if(SCREEN.mode == SCREEN_MODE_FIXED_VIEWPORT_HEIGHT) { if(SCREEN.mode == SCREEN_MODE_FIXED_VIEWPORT_HEIGHT) {
glViewport(0, 0, SCREEN.width, SCREEN.height); glViewport(0, 0, SCREEN.width, SCREEN.height);
return; errorOk();
} }
if( if(
@@ -307,7 +322,7 @@ void screenRender() {
) { ) {
if(!SCREEN.framebufferReady) { if(!SCREEN.framebufferReady) {
// Nothing to do here. // Nothing to do here.
return; errorOk();
} }
float_t bbWidth, bbHeight; float_t bbWidth, bbHeight;
@@ -356,23 +371,34 @@ void screenRender() {
FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH, FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH,
COLOR_BLACK COLOR_BLACK
); );
cameraPushMatrix(&SCREEN.framebufferCamera);
textureBind(&SCREEN.framebuffer.texture);
meshDraw(&SCREEN.frameBufferMesh, 0, -1);
cameraPopMatrix();
return; shaderBind(&SHADER_UNLIT);
mat4 proj, view, model;
cameraGetProjectionMatrix(&SCREEN.framebufferCamera, proj);
cameraGetViewMatrix(&SCREEN.framebufferCamera, view);
glm_mat4_identity(model);
shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj);
shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, view);
shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, model);
// errorChain(textureBind(&SCREEN.framebuffer.texture));
errorChain(meshDraw(&SCREEN.frameBufferMesh, 0, -1));
errorOk();
}; };
#endif #endif
assertUnreachable("Invalid screen mode."); assertUnreachable("Invalid screen mode.");
errorThrow("Invalid screen mode.");
} }
void screenDispose() { errorret_t screenDispose() {
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC #ifdef DUSK_DISPLAY_SIZE_DYNAMIC
if(SCREEN.framebufferReady) { if(SCREEN.framebufferReady) {
frameBufferDispose(&SCREEN.framebuffer); errorChain(frameBufferDispose(&SCREEN.framebuffer));
SCREEN.framebufferReady = false; SCREEN.framebufferReady = false;
} }
#endif #endif
errorOk();
} }

View File

@@ -90,20 +90,28 @@ errorret_t screenInit();
/** /**
* Binds the screen, this is done before rendering game content. * Binds the screen, this is done before rendering game content.
*
* @return Error code and state, if error occurs.
*/ */
void screenBind(); errorret_t screenBind();
/** /**
* Unbinds the screen, does nothing for now. * Unbinds the screen, does nothing for now.
*
* @return Error code and state, if error occurs.
*/ */
void screenUnbind(); errorret_t screenUnbind();
/** /**
* Renders the screen to the current framebuffer. * Renders the screen to the current framebuffer.
*
* @return Error code and state, if error occurs.
*/ */
void screenRender(); errorret_t screenRender();
/** /**
* Disposes the screen system. * Disposes the screen system.
*
* @return Error code and state, if error occurs.
*/ */
void screenDispose(); errorret_t screenDispose();

View File

@@ -0,0 +1,10 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
shader.c
)

View File

@@ -0,0 +1,39 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "shader.h"
#include "assert/assert.h"
errorret_t shaderInit(shader_t *shader, const shaderdefinition_t *def) {
assertNotNull(shader, "Shader cannot be null");
errorChain(shaderInitPlatform(shader, def));
errorOk();
}
errorret_t shaderBind(shader_t *shader) {
assertNotNull(shader, "Shader cannot be null");
errorChain(shaderBindPlatform(shader));
errorOk();
}
errorret_t shaderSetMatrix(
shader_t *shader,
const char_t *name,
mat4 matrix
) {
assertNotNull(shader, "Shader cannot be null");
assertStrLenMin(name, 1, "Uniform name cannot be empty");
assertNotNull(matrix, "Matrix cannot be null");
errorChain(shaderSetMatrixPlatform(shader, name, matrix));
errorOk();
}
errorret_t shaderDispose(shader_t *shader) {
assertNotNull(shader, "Shader cannot be null");
errorChain(shaderDisposePlatform(shader));
errorOk();
}

View File

@@ -0,0 +1,80 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "error/error.h"
#include "display/texture/texture.h"
#include "display/shader/shaderplatform.h"
#ifndef shaderInitPlatform
#error "shaderInitPlatform must be defined to use shader.h"
#endif
#ifndef shaderBindPlatform
#error "shaderBindPlatform must be defined to use shader.h"
#endif
#ifndef shaderSetMatrixPlatform
#error "shaderSetMatrixPlatform must be defined to use shader.h"
#endif
#ifndef shaderDisposePlatform
#error "shaderDisposePlatform must be defined to use shader.h"
#endif
typedef shaderplatform_t shader_t;
typedef shaderdefinitionplatform_t shaderdefinition_t;
/**
* Initializes a shader. This is platform dependant.
*
* @param shader Shader to initialize
* @param def Definition of the shader to initialize with.
* @return Error if failure, otherwise errorOk
*/
errorret_t shaderInit(shader_t *shader, const shaderdefinition_t *def);
/**
* Binds a shader. This is platform dependant.
*
* @param shader Shader to bind
* @return Error if failure, otherwise errorOk
*/
errorret_t shaderBind(shader_t *shader);
/**
* Sets a matrix uniform in the shader. This is platform dependant.
*
* @param shader Shader to set the matrix in
* @param name Name of the uniform to set
* @param matrix Matrix to set
* @return Error if failure, otherwise errorOk
*/
errorret_t shaderSetMatrix(
shader_t *shader,
const char_t *name,
mat4 matrix
);
/**
* Sets a texture uniform in the shader. This is platform dependant.
*
* @param shader Shader to set the texture in
* @param name Name of the uniform to set
* @param texture Texture to set
* @return Error if failure, otherwise errorOk
*/
errorret_t shaderSetTexture(
shader_t *shader,
const char_t *name,
texture_t *texture
);
/**
* Disposes of a shader. This is platform dependant.
*
* @param shader Shader to dispose
* @return Error if failure, otherwise errorOk
*/
errorret_t shaderDispose(shader_t *shader);

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 "shader.h"
#define SHADER_UNLIT_PROJECTION "u_Proj"
#define SHADER_UNLIT_VIEW "u_View"
#define SHADER_UNLIT_MODEL "u_Model"
extern shaderdefinition_t SHADER_UNLIT_DEFINITION;
static shader_t SHADER_UNLIT;

View File

@@ -19,7 +19,7 @@ errorret_t spriteBatchInit() {
&SPRITEBATCH.mesh, &SPRITEBATCH.mesh,
QUAD_PRIMITIVE_TYPE, QUAD_PRIMITIVE_TYPE,
SPRITEBATCH_VERTEX_COUNT, SPRITEBATCH_VERTEX_COUNT,
&SPRITEBATCH_VERTICES[0] SPRITEBATCH_VERTICES
)); ));
errorOk(); errorOk();
} }
@@ -83,10 +83,10 @@ errorret_t spriteBatchFlush() {
errorOk(); errorOk();
} }
size_t vertexCount = QUAD_VERTEX_COUNT * SPRITEBATCH.spriteCount;
errorChain(meshFlush(&SPRITEBATCH.mesh, 0, vertexCount));
errorChain(textureBind(SPRITEBATCH.currentTexture)); errorChain(textureBind(SPRITEBATCH.currentTexture));
errorChain(meshDraw( errorChain(meshDraw(&SPRITEBATCH.mesh, 0, vertexCount));
&SPRITEBATCH.mesh, 0, QUAD_VERTEX_COUNT * SPRITEBATCH.spriteCount
));
spriteBatchClear(); spriteBatchClear();
errorOk(); errorOk();
} }

View File

@@ -9,7 +9,7 @@
#include "display/mesh/quad.h" #include "display/mesh/quad.h"
#include "display/texture/texture.h" #include "display/texture/texture.h"
#define SPRITEBATCH_SPRITES_MAX 16 #define SPRITEBATCH_SPRITES_MAX 1
#define SPRITEBATCH_VERTEX_COUNT (SPRITEBATCH_SPRITES_MAX * QUAD_VERTEX_COUNT) #define SPRITEBATCH_VERTEX_COUNT (SPRITEBATCH_SPRITES_MAX * QUAD_VERTEX_COUNT)

View File

@@ -69,8 +69,6 @@ void moduleCamera(scriptcontext_t *context) {
// Methods // Methods
lua_register(context->luaState, "cameraCreate", moduleCameraCreate); lua_register(context->luaState, "cameraCreate", moduleCameraCreate);
lua_register(context->luaState, "cameraPushMatrix", moduleCameraPushMatrix);
lua_register(context->luaState, "cameraPopMatrix", moduleCameraPopMatrix);
} }
int moduleCameraCreate(lua_State *L) { int moduleCameraCreate(lua_State *L) {
@@ -118,26 +116,7 @@ int moduleCameraCreate(lua_State *L) {
return 1; return 1;
} }
int moduleCameraPushMatrix(lua_State *L) { int moduleCameraIndex(lua_State *l) {
assertNotNull(L, "Lua state cannot be NULL.");
assertTrue(lua_gettop(L) >= 1, "cameraPushMatrix requires 1 arg.");
assertTrue(lua_isuserdata(L, 1), "cameraPushMatrix arg must be userdata.");
// Camera should be provided (pointer to camera_t).
camera_t *cam = (camera_t *)luaL_checkudata(L, 1, "camera_mt");
assertNotNull(cam, "Camera pointer cannot be NULL.");
cameraPushMatrix(cam);
return 0;
}
int moduleCameraPopMatrix(lua_State *L) {
assertNotNull(L, "Lua state cannot be NULL.");
cameraPopMatrix();
return 0;
}
int moduleCameraIndex(lua_State *l) {
assertNotNull(l, "Lua state cannot be NULL."); assertNotNull(l, "Lua state cannot be NULL.");
const char_t *key = luaL_checkstring(l, 2); const char_t *key = luaL_checkstring(l, 2);

View File

@@ -23,22 +23,6 @@ void moduleCamera(scriptcontext_t *context);
*/ */
int moduleCameraCreate(lua_State *L); int moduleCameraCreate(lua_State *L);
/**
* Script binding for pushing the camera matrix onto the matrix stack.
*
* @param L The Lua state.
* @return Number of return values on the Lua stack.
*/
int moduleCameraPushMatrix(lua_State *L);
/**
* Script binding for popping the camera matrix from the matrix stack.
*
* @param L The Lua state.
* @return Number of return values on the Lua stack.
*/
int moduleCameraPopMatrix(lua_State *L);
/** /**
* Getter for camera structure fields. * Getter for camera structure fields.
* *

View File

@@ -91,7 +91,7 @@ int moduleSpriteBatchPush(lua_State *L) {
float_t maxX = (float_t)lua_tonumber(L, 4); float_t maxX = (float_t)lua_tonumber(L, 4);
float_t maxY = (float_t)lua_tonumber(L, 5); float_t maxY = (float_t)lua_tonumber(L, 5);
spriteBatchPush( errorret_t ret = spriteBatchPush(
tex, tex,
minX, minX,
minY, minY,
@@ -103,6 +103,14 @@ int moduleSpriteBatchPush(lua_State *L) {
u1, u1,
v1 v1
); );
if(ret.code != ERROR_OK) {
int err = luaL_error(L,
"Failed to push sprite to batch: %s",
ret.state->message
);
errorCatch(errorPrint(ret));
return err;
}
return 0; return 0;
} }

View File

@@ -19,7 +19,7 @@ int moduleSceneSet(lua_State *L) {
assertNotNull(L, "Lua state cannot be NULL"); assertNotNull(L, "Lua state cannot be NULL");
// Need string // Need string
if (!lua_isstring(L, 1)) { if(!lua_isstring(L, 1)) {
luaL_error(L, "sceneSet requires a string argument"); luaL_error(L, "sceneSet requires a string argument");
return 0; return 0;
} }

View File

@@ -26,12 +26,12 @@ int moduleSysPrint(lua_State *L) {
luaL_Buffer b; luaL_Buffer b;
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
for (int i = 1; i <= n; ++i) { for(int i = 1; i <= n; ++i) {
size_t len; size_t len;
const char *s = luaL_tolstring(L, i, &len); // converts any value to string const char *s = luaL_tolstring(L, i, &len); // converts any value to string
luaL_addlstring(&b, s, len); luaL_addlstring(&b, s, len);
lua_pop(L, 1); // pop result of luaL_tolstring lua_pop(L, 1); // pop result of luaL_tolstring
if (i < n) luaL_addlstring(&b, "\t", 1); if(i < n) luaL_addlstring(&b, "\t", 1);
} }
luaL_pushresult(&b); luaL_pushresult(&b);

View File

@@ -30,11 +30,11 @@ void uiRender(void) {
UI.camera.orthographic.right = SCREEN.width; UI.camera.orthographic.right = SCREEN.width;
UI.camera.orthographic.top = SCREEN.height; UI.camera.orthographic.top = SCREEN.height;
cameraPushMatrix(&UI.camera); // cameraPushMatrix(&UI.camera);
spriteBatchClear(); spriteBatchClear();
spriteBatchFlush(); spriteBatchFlush();
cameraPopMatrix(); // cameraPopMatrix();
} }
void uiDispose(void) { void uiDispose(void) {

View File

@@ -0,0 +1,15 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "assert/assert.h"
#include "error/errorgl.h"
#define assertNoGLError(message) \
assertTrue(errorGLCheck().code == ERROR_OK, message)
// EOF

View File

@@ -14,3 +14,4 @@ add_subdirectory(camera)
add_subdirectory(framebuffer) add_subdirectory(framebuffer)
add_subdirectory(texture) add_subdirectory(texture)
add_subdirectory(mesh) add_subdirectory(mesh)
add_subdirectory(shader)

View File

@@ -8,7 +8,7 @@
#include "display/camera/camera.h" #include "display/camera/camera.h"
#include "display/framebuffer/framebuffer.h" #include "display/framebuffer/framebuffer.h"
#include "display/screen/screen.h" #include "display/screen/screen.h"
#include "assert/assert.h" #include "assert/assertgl.h"
void cameraPushMatrixGL(camera_t *camera) { void cameraPushMatrixGL(camera_t *camera) {
assertNotNull(camera, "Not a camera component"); assertNotNull(camera, "Not a camera component");
@@ -117,16 +117,19 @@ void cameraPushMatrixGL(camera_t *camera) {
assertUnreachable("Invalid camera view type"); assertUnreachable("Invalid camera view type");
} }
glPushMatrix(); // glPushMatrix();
glMatrixMode(GL_PROJECTION); // glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // glLoadIdentity();
glLoadMatrixf((const GLfloat*)projection); // glLoadMatrixf((const GLfloat*)projection);
assertNoGLError("Failed to set projection matrix");
glMatrixMode(GL_MODELVIEW); // glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); // glLoadIdentity();
glLoadMatrixf((const GLfloat*)view); // glLoadMatrixf((const GLfloat*)view);
assertNoGLError("Failed to set view matrix");
} }
void cameraPopMatrixGL(void) { void cameraPopMatrixGL(void) {
glPopMatrix(); // glPopMatrix();
assertNoGLError("Failed to pop camera matrix");
} }

View File

@@ -9,8 +9,8 @@
errorret_t displayOpenGLInit(void) { errorret_t displayOpenGLInit(void) {
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);// PSP defaults this on? // glDisable(GL_LIGHTING);// PSP defaults this on?
glShadeModel(GL_SMOOTH); // Fixes color on PSP? // glShadeModel(GL_SMOOTH); // Fixes color on PSP?
errorChain(errorGLCheck()); errorChain(errorGLCheck());
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@@ -24,9 +24,5 @@ errorret_t displayOpenGLInit(void) {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
errorChain(errorGLCheck()); errorChain(errorGLCheck());
glEnableClientState(GL_COLOR_ARRAY);// To confirm: every frame on PSP?
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
errorChain(errorGLCheck());
errorOk(); errorOk();
} }

View File

@@ -10,5 +10,7 @@
/** /**
* Initializes the OpenGL specific contexts for rendering. * Initializes the OpenGL specific contexts for rendering.
*
* @return An errorret_t indicating success or failure of the initialization.
*/ */
errorret_t displayOpenGLInit(void); errorret_t displayOpenGLInit(void);

View File

@@ -7,7 +7,7 @@
#include "display/display.h" #include "display/display.h"
#include "display/framebuffer/framebuffer.h" #include "display/framebuffer/framebuffer.h"
#include "assert/assert.h" #include "assert/assertgl.h"
#include "util/memory.h" #include "util/memory.h"
errorret_t frameBufferGLInitBackBuffer(void) { errorret_t frameBufferGLInitBackBuffer(void) {
@@ -86,6 +86,7 @@ void frameBufferGLClear(const uint8_t flags, const color_t color) {
color.b / 255.0f, color.b / 255.0f,
color.a / 255.0f color.a / 255.0f
); );
assertNoGLError("Failed to set clear color");
} }
if(flags & FRAMEBUFFER_CLEAR_DEPTH) { if(flags & FRAMEBUFFER_CLEAR_DEPTH) {
@@ -93,6 +94,7 @@ void frameBufferGLClear(const uint8_t flags, const color_t color) {
} }
glClear(glFlags); glClear(glFlags);
assertNoGLError("Failed to clear framebuffer");
} }
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC #ifdef DUSK_DISPLAY_SIZE_DYNAMIC

View File

@@ -6,7 +6,9 @@
*/ */
#include "display/mesh/mesh.h" #include "display/mesh/mesh.h"
#include "assert/assert.h" #include "assert/assertgl.h"
#include "error/errorgl.h"
#include "display/shader/shadergl.h"
errorret_t meshInitGL( errorret_t meshInitGL(
meshgl_t *mesh, meshgl_t *mesh,
@@ -22,6 +24,99 @@ errorret_t meshInitGL(
mesh->vertexCount = vertexCount; mesh->vertexCount = vertexCount;
mesh->vertices = vertices; mesh->vertices = vertices;
#ifdef DUSK_OPENGL_LEGACY
// Nothing needed.
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
errorChain(errorGLCheck());
#else
// Generate Vertex Buffer Object
glGenBuffers(1, &mesh->vboId);
errorChain(errorGLCheck());
glBindBuffer(GL_ARRAY_BUFFER, mesh->vboId);
errorChain(errorGLCheck());
glBufferData(
GL_ARRAY_BUFFER,
vertexCount * sizeof(meshvertex_t),
vertices,
GL_DYNAMIC_DRAW
);
errorChain(errorGLCheck());
// Generate Vertex Array Object
glGenVertexArrays(1, &mesh->vaoId);
errorChain(errorGLCheck());
glBindVertexArray(mesh->vaoId);
errorChain(errorGLCheck());
glBindBuffer(GL_ARRAY_BUFFER, mesh->vboId);
errorChain(errorGLCheck());
// Set up vertex attribute pointers
glVertexAttribPointer(
0,
MESH_VERTEX_POS_SIZE,
GL_FLOAT,
GL_FALSE,
sizeof(meshvertex_t),
(const GLvoid*)offsetof(meshvertex_t, pos)
);
errorChain(errorGLCheck());
glEnableVertexAttribArray(0);
errorChain(errorGLCheck());
glVertexAttribPointer(
1,
MESH_VERTEX_UV_SIZE,
GL_FLOAT,
GL_FALSE,
sizeof(meshvertex_t),
(const GLvoid*)offsetof(meshvertex_t, uv)
);
errorChain(errorGLCheck());
glEnableVertexAttribArray(1);
errorChain(errorGLCheck());
glVertexAttribPointer(
2,
sizeof(color_t) / sizeof(GLubyte),
GL_UNSIGNED_BYTE,
GL_TRUE,
sizeof(meshvertex_t),
(const GLvoid*)offsetof(meshvertex_t, color)
);
errorChain(errorGLCheck());
glEnableVertexAttribArray(2);
errorChain(errorGLCheck());
// Unbind VAO and VBO to prevent accidental modification
glBindBuffer(GL_ARRAY_BUFFER, 0);
errorChain(errorGLCheck());
glBindVertexArray(0);
errorChain(errorGLCheck());
#endif
errorOk();
}
errorret_t meshFlushGL(
meshgl_t *mesh,
const int32_t vertOffset,
const int32_t vertCount
) {
#ifdef DUSK_OPENGL_LEGACY
// Nothing doing, we use the glClientState stuff.
#else
glBindBuffer(GL_ARRAY_BUFFER, mesh->vboId);
errorChain(errorGLCheck());
glBufferData(
GL_ARRAY_BUFFER,
vertCount * sizeof(meshvertex_t),
&mesh->vertices[vertOffset],
GL_DYNAMIC_DRAW
);
errorChain(errorGLCheck());
#endif
errorOk(); errorOk();
} }
@@ -30,7 +125,8 @@ errorret_t meshDrawGL(
const int32_t offset, const int32_t offset,
const int32_t count const int32_t count
) { ) {
// PSP style pointer legacy OpenGL #ifdef DUSK_OPENGL_LEGACY
// Legacy pointer style rendering
const GLsizei stride = sizeof(meshvertex_t); const GLsizei stride = sizeof(meshvertex_t);
glColorPointer( glColorPointer(
@@ -52,7 +148,22 @@ errorret_t meshDrawGL(
(const GLvoid*)&mesh->vertices[offset].pos (const GLvoid*)&mesh->vertices[offset].pos
); );
// Shader may have model matrix here
#ifdef DUSK_OPENGL_LEGACY
errorChain(shaderLegacyMatrixUpdate());
#endif
glDrawArrays(mesh->primitiveType, offset, count); glDrawArrays(mesh->primitiveType, offset, count);
errorChain(errorGLCheck());
#else
// Modern VAO/VBO rendering
glBindVertexArray(mesh->vaoId);
errorChain(errorGLCheck());
glDrawArrays(mesh->primitiveType, offset, count);
errorChain(errorGLCheck());
glBindVertexArray(0);
errorChain(errorGLCheck());
#endif
errorOk(); errorOk();
} }
@@ -62,6 +173,13 @@ int32_t meshGetVertexCountGL(const meshgl_t *mesh) {
} }
errorret_t meshDisposeGL(meshgl_t *mesh) { errorret_t meshDisposeGL(meshgl_t *mesh) {
#ifdef DUSK_OPENGL_LEGACY
// No dynamic resources to free for this mesh implementation // No dynamic resources to free for this mesh implementation
#else
glDeleteBuffers(1, &mesh->vboId);
errorChain(errorGLCheck());
glDeleteVertexArrays(1, &mesh->vaoId);
errorChain(errorGLCheck());
#endif
errorOk(); errorOk();
} }

View File

@@ -16,9 +16,16 @@ typedef enum {
} meshprimitivetypegl_t; } meshprimitivetypegl_t;
typedef struct { typedef struct {
const meshvertex_t *vertices;
int32_t vertexCount; int32_t vertexCount;
meshprimitivetypegl_t primitiveType; meshprimitivetypegl_t primitiveType;
const meshvertex_t *vertices;
#ifdef DUSK_OPENGL_LEGACY
// Nothing needed
#else
GLuint vaoId;
GLuint vboId;
#endif
} meshgl_t; } meshgl_t;
/** /**
@@ -37,6 +44,20 @@ errorret_t meshInitGL(
const meshvertex_t *vertices const meshvertex_t *vertices
); );
/**
* Flushes the vertices (stored in memory) to the GPU.
*
* @param mesh Mesh to flush vertices for.
* @param vertOffset First vertice index to flush.
* @param vertCount Count of vertices to flush.
* @return Error state.
*/
errorret_t meshFlushGL(
meshgl_t *mesh,
const int32_t vertOffset,
const int32_t vertCount
);
/** /**
* Draws a mesh using OpenGL. * Draws a mesh using OpenGL.
* *

View File

@@ -12,6 +12,7 @@ typedef meshprimitivetypegl_t meshprimitivetypeplatform_t;
typedef meshgl_t meshplatform_t; typedef meshgl_t meshplatform_t;
#define meshInitPlatform meshInitGL #define meshInitPlatform meshInitGL
#define meshFlushPlatform meshFlushGL
#define meshDrawPlatform meshDrawGL #define meshDrawPlatform meshDrawGL
#define meshGetVertexCountPlatform meshGetVertexCountGL #define meshGetVertexCountPlatform meshGetVertexCountGL
#define meshDisposePlatform meshDisposeGL #define meshDisposePlatform meshDisposeGL

View File

@@ -0,0 +1,11 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
shadergl.c
shaderunlitgl.c
)

View File

@@ -0,0 +1,282 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "shadergl.h"
#include "util/memory.h"
#include "util/string.h"
#include "assert/assertgl.h"
#include "display/shader/shaderunlit.h"
#ifdef DUSK_OPENGL_LEGACY
shaderlegacygl_t SHADER_LEGACY = { 0 };
#endif
errorret_t shaderInitGL(shadergl_t *shader, const shaderdefinitiongl_t *def) {
assertNotNull(shader, "Shader cannot be null");
assertNotNull(def, "Shader definition cannot be null");
memoryZero(shader, sizeof(shadergl_t));
#ifdef DUSK_OPENGL_LEGACY
glm_mat4_identity(shader->view);
glm_mat4_identity(shader->proj);
glm_mat4_identity(shader->model);
SHADER_LEGACY.boundShader = NULL;
errorOk();
#else
// Create vertex shader
shader->vertexShaderId = glCreateShader(GL_VERTEX_SHADER);
errorret_t err = errorGLCheck();
errorChain(err);
glShaderSource(shader->vertexShaderId, 1, &def->vert, NULL);
err = errorGLCheck();
if(err.code != ERROR_OK) {
glDeleteShader(shader->vertexShaderId);
errorChain(err);
}
glCompileShader(shader->vertexShaderId);
err = errorGLCheck();
if(err.code != ERROR_OK) {
glDeleteShader(shader->vertexShaderId);
errorChain(err);
}
GLint ok = 0;
glGetShaderiv(shader->vertexShaderId, GL_COMPILE_STATUS, &ok);
if(!ok) {
GLchar log[1024];
glGetShaderInfoLog(shader->vertexShaderId, sizeof(log), NULL, log);
glDeleteShader(shader->vertexShaderId);
errorThrow("Vertex shader compilation failed: %s", log);
}
// Create fragment shader
shader->fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER);
err = errorGLCheck();
if(err.code != ERROR_OK) {
glDeleteShader(shader->vertexShaderId);
errorChain(err);
}
glShaderSource(shader->fragmentShaderId, 1, &def->frag, NULL);
err = errorGLCheck();
if(err.code != ERROR_OK) {
glDeleteShader(shader->vertexShaderId);
glDeleteShader(shader->fragmentShaderId);
errorChain(err);
}
glCompileShader(shader->fragmentShaderId);
err = errorGLCheck();
if(err.code != ERROR_OK) {
glDeleteShader(shader->vertexShaderId);
glDeleteShader(shader->fragmentShaderId);
errorChain(err);
}
glGetShaderiv(shader->fragmentShaderId, GL_COMPILE_STATUS, &ok);
if(!ok) {
GLchar log[1024];
glGetShaderInfoLog(shader->fragmentShaderId, sizeof(log), NULL, log);
glDeleteShader(shader->vertexShaderId);
glDeleteShader(shader->fragmentShaderId);
errorThrow("Fragment shader compilation failed: %s", log);
}
// Create shader program
shader->shaderProgramId = glCreateProgram();
err = errorGLCheck();
if(err.code != ERROR_OK) {
glDeleteShader(shader->vertexShaderId);
glDeleteShader(shader->fragmentShaderId);
errorChain(err);
}
glAttachShader(shader->shaderProgramId, shader->vertexShaderId);
err = errorGLCheck();
if(err.code != ERROR_OK) {
glDeleteProgram(shader->shaderProgramId);
glDeleteShader(shader->vertexShaderId);
glDeleteShader(shader->fragmentShaderId);
errorChain(err);
}
glAttachShader(shader->shaderProgramId, shader->fragmentShaderId);
err = errorGLCheck();
if(err.code != ERROR_OK) {
glDeleteProgram(shader->shaderProgramId);
glDeleteShader(shader->vertexShaderId);
glDeleteShader(shader->fragmentShaderId);
errorChain(err);
}
glLinkProgram(shader->shaderProgramId);
err = errorGLCheck();
if(err.code != ERROR_OK) {
glDeleteProgram(shader->shaderProgramId);
glDeleteShader(shader->vertexShaderId);
glDeleteShader(shader->fragmentShaderId);
errorChain(err);
}
ok = 0;
glGetProgramiv(shader->shaderProgramId, GL_LINK_STATUS, &ok);
if(!ok) {
GLchar log[1024];
glGetProgramInfoLog(shader->shaderProgramId, sizeof(log), NULL, log);
glDeleteProgram(shader->shaderProgramId);
glDeleteShader(shader->vertexShaderId);
glDeleteShader(shader->fragmentShaderId);
errorThrow("Shader program linking failed: %s", log);
}
#endif
errorOk();
}
errorret_t shaderParamGetLocationGL(
shadergl_t *shader,
const char_t *name,
GLint *location
) {
assertNotNull(shader, "Shader cannot be null");
assertStrLenMin(name, 1, "Uniform name cannot be empty");
assertNotNull(location, "Location cannot be null");
#ifdef DUSK_OPENGL_LEGACY
assertUnreachable("Cannot get uniform locations on legacy opengl.");
#else
shadergl_t *shaderGL = (shadergl_t *)shader;
*location = glGetUniformLocation(shaderGL->shaderProgramId, name);
errorret_t err = errorGLCheck();
if(err.code != ERROR_OK) {
errorChain(err);
}
#endif
errorOk();
}
errorret_t shaderSetMatrixGL(
shadergl_t *shader,
const char_t *name,
mat4 mat
) {
assertNotNull(shader, "Shader cannot be null");
assertNotNull(mat, "Matrix data cannot be null");
assertStrLenMin(name, 1, "Uniform name cannot be empty");
#ifdef DUSK_OPENGL_LEGACY
assertTrue(
SHADER_LEGACY.boundShader == shader,
"Shader must be bound to set legacy matrices."
);
if(stringCompare(name, SHADER_UNLIT_PROJECTION) == 0) {
SHADER_LEGACY.dirty |= SHADER_LEGACY_DIRTY_PROJ;
glm_mat4_copy(mat, shader->proj);
} else if(stringCompare(name, SHADER_UNLIT_VIEW) == 0) {
SHADER_LEGACY.dirty |= SHADER_LEGACY_DIRTY_VIEW;
glm_mat4_copy(mat, shader->view);
} else if(stringCompare(name, SHADER_UNLIT_MODEL) == 0) {
SHADER_LEGACY.dirty |= SHADER_LEGACY_DIRTY_MODEL;
glm_mat4_copy(mat, shader->model);
} else {
assertUnreachable("Cannot use a custom matrix on legacy opengl.");
}
#else
GLint location;
errorChain(shaderParamGetLocationGL(shader, name, &location));
glUniformMatrix4fv(location, 1, GL_FALSE, (const GLfloat *)mat);
errorChain(errorGLCheck());
#endif
errorOk();
}
errorret_t shaderBindGL(shadergl_t *shader) {
#ifdef DUSK_OPENGL_LEGACY
assertNotNull(shader, "Cannot bind a null shader.");
SHADER_LEGACY.boundShader = shader;
SHADER_LEGACY.dirty = (
SHADER_LEGACY_DIRTY_MODEL |
SHADER_LEGACY_DIRTY_PROJ |
SHADER_LEGACY_DIRTY_VIEW
);
#else
assertNotNull(shader, "Shader cannot be null");
glUseProgram(shader->shaderProgramId);
errorChain(errorGLCheck());
#endif
errorOk();
}
errorret_t shaderDisposeGL(shadergl_t *shader) {
assertNotNull(shader, "Shader cannot be null");
#ifdef DUSK_OPENGL_LEGACY
SHADER_LEGACY.boundShader = NULL;
#else
if(shader->shaderProgramId != 0) {
glDeleteProgram(shader->shaderProgramId);
}
if(shader->vertexShaderId != 0) {
glDeleteShader(shader->vertexShaderId);
}
if(shader->fragmentShaderId != 0) {
glDeleteShader(shader->fragmentShaderId);
}
assertNoGLError("Failed disposing shader");
#endif
memoryZero(shader, sizeof(shadergl_t));
errorOk();
}
#ifdef DUSK_OPENGL_LEGACY
errorret_t shaderLegacyMatrixUpdate() {
assertNotNull(SHADER_LEGACY.boundShader, "No shader is currently bound.");
if((SHADER_LEGACY.dirty & SHADER_LEGACY_DIRTY_PROJ) != 0) {
glMatrixMode(GL_PROJECTION);
errorChain(errorGLCheck());
glLoadIdentity();
errorChain(errorGLCheck());
glMultMatrixf((const GLfloat *)SHADER_LEGACY.boundShader->proj);
errorChain(errorGLCheck());
}
if((SHADER_LEGACY.dirty & SHADER_LEGACY_DIRTY_VIEW) != 0) {
glMatrixMode(GL_MODELVIEW);
errorChain(errorGLCheck());
glLoadIdentity();
errorChain(errorGLCheck());
glMultMatrixf((const GLfloat *)SHADER_LEGACY.boundShader->view);
errorChain(errorGLCheck());
}
if((SHADER_LEGACY.dirty & SHADER_LEGACY_DIRTY_MODEL) != 0) {
glMatrixMode(GL_MODELVIEW);
errorChain(errorGLCheck());
glMultMatrixf((const GLfloat *)SHADER_LEGACY.boundShader->model);
errorChain(errorGLCheck());
}
SHADER_LEGACY.dirty = 0;
errorOk();
}
#endif

View File

@@ -0,0 +1,109 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "error/errorgl.h"
typedef struct {
#ifdef DUSK_OPENGL_LEGACY
void *nothing;
#else
GLuint shaderProgramId;
GLuint vertexShaderId;
GLuint fragmentShaderId;
#endif
#if DUSK_OPENGL_LEGACY
mat4 view;
mat4 proj;
mat4 model;
#endif
} shadergl_t;
typedef struct {
#ifdef DUSK_OPENGL_LEGACY
void *nothing;
#else
const char_t *vert;
const char_t *frag;
#endif
} shaderdefinitiongl_t;
#if DUSK_OPENGL_LEGACY
typedef struct {
shadergl_t *boundShader;
uint_fast8_t dirty;
} shaderlegacygl_t;
extern shaderlegacygl_t SHADER_LEGACY;
#define SHADER_LEGACY_DIRTY_PROJ (1 << 0)
#define SHADER_LEGACY_DIRTY_VIEW (1 << 1)
#define SHADER_LEGACY_DIRTY_MODEL (1 << 2)
#endif
/**
* Initializes a shader.
*
* @param shader The shader to initialize.
* @param def The definition of the shader to initialize with.
* @return An errorret_t indicating success or failure.
*/
errorret_t shaderInitGL(shadergl_t *shader, const shaderdefinitiongl_t *def);
/**
* Binds a shader for use in rendering.
*
* @param shader The shader to bind.
* @return An errorret_t indicating success or failure.
*/
errorret_t shaderBindGL(shadergl_t *shader);
/**
* Retrieves the location of a shader uniform parameter.
*
* @param shader The shader to query.
* @param name The name of the uniform parameter.
* @param location Output parameter to receive the location of the uniform.
* @return An errorret_t indicating success or failure.
*/
errorret_t shaderParamGetLocationGL(
shadergl_t *shader,
const char_t *name,
GLint *location
);
/**
* Sets a mat4 uniform parameter in the shader.
*
* @param shader The shader to update.
* @param name The name of the uniform parameter.
* @param mat The 4x4 matrix data to set.
* @return An errorret_t indicating success or failure.
*/
errorret_t shaderSetMatrixGL(
shadergl_t *shader,
const char_t *name,
mat4 matrix
);
/**
* Disposes of a shader, freeing any associated resources.
*
* @param shader The shader to dispose.
*/
errorret_t shaderDisposeGL(shadergl_t *shader);
#ifdef DUSK_OPENGL_LEGACY
/**
* During mesh rendering, this is requesting the legacy system to push all
* shaders necessary to render the currently bound shader's matrices.
*
* @return Any error state.
*/
errorret_t shaderLegacyMatrixUpdate();
#endif

View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "shadergl.h"
typedef shadergl_t shaderplatform_t;
typedef shaderdefinitiongl_t shaderdefinitionplatform_t;
#define shaderInitPlatform shaderInitGL
#define shaderBindPlatform shaderBindGL
#define shaderSetMatrixPlatform shaderSetMatrixGL
// #define shaderSetTexturePlatform shaderSetTextureGL
#define shaderDisposePlatform shaderDisposeGL

View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "display/shader/shaderunlit.h"
#ifdef DUSK_OPENGL_LEGACY
shaderdefinition_t SHADER_UNLIT_DEFINITION = { 0 };
#else
shaderdefinition_t SHADER_UNLIT_DEFINITION = {
.vert =
"#version 330 core\n"
"layout(location = 0) in vec3 aPos;\n"
"uniform mat4 u_Proj;\n"
"uniform mat4 u_View;\n"
"uniform mat4 u_Model;\n"
"void main() {\n"
" gl_Position = u_Proj * u_View * u_Model * vec4(aPos, 1.0);\n"
"}\n",
.frag =
"#version 330 core\n"
"out vec4 FragColor;\n"
"void main() {\n"
" FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
"}\n"
};
#endif

View File

@@ -19,7 +19,7 @@ void logDebug(const char_t *message, ...) {
// print to file // print to file
FILE *file = fopen("ms0:/PSP/GAME/Dusk/debug.log", "a"); FILE *file = fopen("ms0:/PSP/GAME/Dusk/debug.log", "a");
if (file) { if(file) {
va_copy(copy, args); va_copy(copy, args);
vfprintf(file, message, copy); vfprintf(file, message, copy);
va_end(copy); va_end(copy);
@@ -41,7 +41,7 @@ void logError(const char_t *message, ...) {
// print to file // print to file
FILE *file = fopen("ms0:/PSP/GAME/Dusk/error.log", "a"); FILE *file = fopen("ms0:/PSP/GAME/Dusk/error.log", "a");
if (file) { if(file) {
va_copy(copy, args); va_copy(copy, args);
vfprintf(file, message, copy); vfprintf(file, message, copy);
va_end(copy); va_end(copy);

View File

@@ -21,6 +21,16 @@ errorret_t displaySDL2Init(void) {
// Set OpenGL attributes (Needs to be done now or later?) // Set OpenGL attributes (Needs to be done now or later?)
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
// SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
// SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
#ifdef DUSK_OPENGL_LEGACY
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
#else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
#endif
// Create window with OpenGL flag. // Create window with OpenGL flag.
DISPLAY.window = SDL_CreateWindow( DISPLAY.window = SDL_CreateWindow(
@@ -44,7 +54,6 @@ errorret_t displaySDL2Init(void) {
errorChain(errorGLCheck()); errorChain(errorGLCheck());
SDL_GL_SetSwapInterval(1); SDL_GL_SetSwapInterval(1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
errorChain(errorGLCheck()); errorChain(errorGLCheck());
errorChain(displayOpenGLInit()); errorChain(displayOpenGLInit());
@@ -82,6 +91,9 @@ errorret_t displaySDL2Update(void) {
} }
SDL_GL_MakeCurrent(DISPLAY.window, DISPLAY.glContext); SDL_GL_MakeCurrent(DISPLAY.window, DISPLAY.glContext);
// errorChain(shaderPaletteTextureBindGL(&testShader));
errorOk(); errorOk();
} }

View File

@@ -247,13 +247,13 @@
// Draw red grid lines for tile boundaries // Draw red grid lines for tile boundaries
ctx.strokeStyle = 'rgba(255,0,0,1)'; ctx.strokeStyle = 'rgba(255,0,0,1)';
for (let x = v.scaledTileWidth; x < elOutputPreview.width; x += v.scaledTileWidth) { for(let x = v.scaledTileWidth; x < elOutputPreview.width; x += v.scaledTileWidth) {
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(x, 0); ctx.moveTo(x, 0);
ctx.lineTo(x, elOutputPreview.height); ctx.lineTo(x, elOutputPreview.height);
ctx.stroke(); ctx.stroke();
} }
for (let y = v.scaledTileHeight; y < elOutputPreview.height; y += v.scaledTileHeight) { for(let y = v.scaledTileHeight; y < elOutputPreview.height; y += v.scaledTileHeight) {
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(0, y); ctx.moveTo(0, y);
ctx.lineTo(elOutputPreview.width, y); ctx.lineTo(elOutputPreview.width, y);
@@ -289,7 +289,7 @@
btnBackgroundGreen.addEventListener('click', () => document.body.style.background = 'green'); btnBackgroundGreen.addEventListener('click', () => document.body.style.background = 'green');
elDefineBySize.addEventListener('change', () => { elDefineBySize.addEventListener('change', () => {
if (elDefineBySize.checked) { if(elDefineBySize.checked) {
elTileSizes.style.display = ''; elTileSizes.style.display = '';
elTileCounts.style.display = 'none'; elTileCounts.style.display = 'none';
} }
@@ -297,7 +297,7 @@
}); });
elDefineByCount.addEventListener('change', () => { elDefineByCount.addEventListener('change', () => {
if (elDefineByCount.checked) { if(elDefineByCount.checked) {
elTileSizes.style.display = 'none'; elTileSizes.style.display = 'none';
elTileCounts.style.display = ''; elTileCounts.style.display = '';
} }
@@ -332,7 +332,7 @@
elOutputError.style.display = 'none'; elOutputError.style.display = 'none';
pixels = null; pixels = null;
if (!elFileInput.files.length) { if(!elFileInput.files.length) {
elOutputError.textContent = 'No file selected'; elOutputError.textContent = 'No file selected';
elOutputError.style.display = 'block'; elOutputError.style.display = 'block';
return; return;
@@ -340,18 +340,18 @@
const file = elFileInput.files[0]; const file = elFileInput.files[0];
if (file.name.endsWith('.dpt')) { if(file.name.endsWith('.dpt')) {
// Load DPT file // Load DPT file
const reader = new FileReader(); const reader = new FileReader();
reader.onload = () => { reader.onload = () => {
const arrayBuffer = reader.result; const arrayBuffer = reader.result;
const data = new Uint8Array(arrayBuffer); const data = new Uint8Array(arrayBuffer);
if (data[0] !== 'D'.charCodeAt(0) || data[1] !== 'P'.charCodeAt(0) || data[2] !== 'T'.charCodeAt(0)) { if(data[0] !== 'D'.charCodeAt(0) || data[1] !== 'P'.charCodeAt(0) || data[2] !== 'T'.charCodeAt(0)) {
elOutputError.textContent = 'Invalid DPT file'; elOutputError.textContent = 'Invalid DPT file';
elOutputError.style.display = 'block'; elOutputError.style.display = 'block';
return; return;
} else if (data[3] !== 0x01) { } else if(data[3] !== 0x01) {
elOutputError.textContent = 'Unsupported DPT version'; elOutputError.textContent = 'Unsupported DPT version';
elOutputError.style.display = 'block'; elOutputError.style.display = 'block';
return; return;
@@ -381,15 +381,15 @@
} }
const uniqueIndexes = []; const uniqueIndexes = [];
for (let i = 0; i < width * height; i++) { for(let i = 0; i < width * height; i++) {
const colorIndex = data[12 + i]; const colorIndex = data[12 + i];
if (!uniqueIndexes.includes(colorIndex)) { if(!uniqueIndexes.includes(colorIndex)) {
uniqueIndexes.push(colorIndex); uniqueIndexes.push(colorIndex);
} }
} }
const adhocPalette = []; const adhocPalette = [];
for (let i = 0; i < uniqueIndexes.length; i++) { for(let i = 0; i < uniqueIndexes.length; i++) {
const index = uniqueIndexes[i]; const index = uniqueIndexes[i];
// Get the most different possible color for this index // Get the most different possible color for this index
const color = [ const color = [
@@ -402,7 +402,7 @@
} }
pixels = new Uint8Array(width * height * 4); pixels = new Uint8Array(width * height * 4);
for (let i = 0; i < width * height; i++) { for(let i = 0; i < width * height; i++) {
const colorIndex = data[12 + i]; const colorIndex = data[12 + i];
const color = adhocPalette[colorIndex]; const color = adhocPalette[colorIndex];
pixels[i * 4] = color[0]; pixels[i * 4] = color[0];
@@ -487,13 +487,13 @@
input.accept = '.dtf'; input.accept = '.dtf';
input.addEventListener('change', (e) => { input.addEventListener('change', (e) => {
const files = e?.target?.files; const files = e?.target?.files;
if (!files || !files.length || !files[0]) { if(!files || !files.length || !files[0]) {
alert('No file selected'); alert('No file selected');
return; return;
} }
const file = files[0]; const file = files[0];
if (!file.name.endsWith('.dtf')) { if(!file.name.endsWith('.dtf')) {
alert('Invalid file type. Please select a .dtf file.'); alert('Invalid file type. Please select a .dtf file.');
return; return;
} }
@@ -502,12 +502,12 @@
reader.onload = () => { reader.onload = () => {
const arrayBuffer = reader.result; const arrayBuffer = reader.result;
const data = new Uint8Array(arrayBuffer); const data = new Uint8Array(arrayBuffer);
if (data[0] !== 'D'.charCodeAt(0) || data[1] !== 'T'.charCodeAt(0) || data[2] !== 'F'.charCodeAt(0)) { if(data[0] !== 'D'.charCodeAt(0) || data[1] !== 'T'.charCodeAt(0) || data[2] !== 'F'.charCodeAt(0)) {
alert('Invalid DTF file'); alert('Invalid DTF file');
return; return;
} }
if (data[3] !== 0x00) { if(data[3] !== 0x00) {
alert('Unsupported DTF version'); alert('Unsupported DTF version');
return; return;
} }