Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
ed0aca8
Add initial software renderer implementation.
iProgramMC May 17, 2026
b813cff
Remove redundant src/image inclusion.
iProgramMC May 17, 2026
c6791e7
Add build rules for Makefile
iProgramMC May 17, 2026
8bb4bc1
Fix oopsie
iProgramMC May 17, 2026
0fe1273
* endFrameInit/endFrameEnd no longer print "NYI"
iProgramMC May 17, 2026
01b7312
fix build
Un1q32 May 17, 2026
560d035
Merge pull request #2 from Un1q32/sw-pr
iProgramMC May 17, 2026
d978ae5
Merge branch 'sw-renderer' of github.com:iProgramMC/Butterscotch into…
iProgramMC May 17, 2026
9a01740
Prepare for surface work
iProgramMC May 17, 2026
a443be3
Relocate a function
iProgramMC May 17, 2026
0e1ccac
chmod -x
Un1q32 May 17, 2026
c2a71bd
no binary litterals in C99
Un1q32 May 17, 2026
d7249d7
likely macro compat
Un1q32 May 17, 2026
9e2c1d8
Merge pull request #4 from Un1q32/sw-pr
iProgramMC May 18, 2026
1032617
Attempt to fix a big-endian issue by byte-swapping the color channel …
iProgramMC May 18, 2026
deb760d
Don't call Runner_setNextFrame twice in a frame.
iProgramMC May 18, 2026
0d9a25f
Merge remote-tracking branch 'upstream/main' into sw-pr
Un1q32 May 18, 2026
e72eb28
fix
Un1q32 May 18, 2026
81ea0e9
Merge pull request #5 from Un1q32/sw-pr
iProgramMC May 18, 2026
1bddaaf
Implement big endian mode for the software renderer.
iProgramMC May 18, 2026
05d57f1
* Add initial support for sprite surfaces.
iProgramMC May 19, 2026
a70e786
* Fix yet another rotation pivot issue.
iProgramMC May 19, 2026
83c3c17
* Fix a bug where createSpriteFromSurface completely ignored screen s…
iProgramMC May 19, 2026
c2aac32
* Fix a bug where pivotX/Y didn't take into account the diff between …
iProgramMC May 19, 2026
5e43ec9
* SDL Frontend: Use fbWidth/fbHeight instead of reqW/reqH for the SDL…
iProgramMC May 19, 2026
66d1235
Revert "* SDL Frontend: Use fbWidth/fbHeight instead of reqW/reqH for…
iProgramMC May 19, 2026
d08d786
Merge branch 'main' of https://github.com/MrPowerGamerBR/Butterscotch…
iProgramMC May 19, 2026
cb5c0be
Add enableApplicationSurface.
iProgramMC May 20, 2026
ee34b16
Merge branch 'main' of github.com:iProgramMC/Butterscotch into sw-ren…
iProgramMC May 23, 2026
c951bd6
* Update drawText / drawTextColor definitions
iProgramMC May 23, 2026
e8eef6d
* Fix a bug with rotations
iProgramMC May 23, 2026
c2980fb
Merge branch 'main' of https://github.com/MrPowerGamerBR/Butterscotch…
iProgramMC May 23, 2026
1024353
* Add support for drawLineColor.
iProgramMC May 23, 2026
a81e9c0
* Add support for gradient lines.
iProgramMC May 23, 2026
2eafb16
Merge branch 'main' of https://github.com/MrPowerGamerBR/Butterscotch…
iProgramMC May 24, 2026
cea76f1
* Add initial implementation of the triangle render function.
iProgramMC May 25, 2026
3f3b3d0
* Actually apply transforms to this triangle + remove the test code.
iProgramMC May 25, 2026
140304e
* Bugfixes with the triangle renderer
iProgramMC May 25, 2026
23bd43d
* Fix a bug where drawSpritePart was doubly handling sprite flipping.
iProgramMC May 25, 2026
08090dc
* Small 8bpp renderer fix
iProgramMC May 25, 2026
29bd1d3
* Attempt at optimization that I'll revert
iProgramMC May 27, 2026
30150cb
Revert "* Attempt at optimization that I'll revert"
iProgramMC May 27, 2026
7e09706
Merge pull request #6 from Un1q32/sw-pr
Un1q32 May 27, 2026
7b961d9
add letterboxing and pillarboxing instead of streching (#7)
Un1q32 May 27, 2026
ad8ee62
* Increase precision of fixed point increment when scaling sprites.
iProgramMC May 27, 2026
c7b1fa9
Merge remote-tracking branch 'upstream/main' into software
Un1q32 May 29, 2026
d3de480
cmake sw renderer
Un1q32 May 29, 2026
80a831e
remove fflush
Un1q32 May 29, 2026
00fa71d
include
Un1q32 May 29, 2026
c21237b
fix
Un1q32 May 29, 2026
8092689
fix
Un1q32 May 29, 2026
2729f2d
Merge remote-tracking branch 'upstream/main' into software
Un1q32 May 29, 2026
4d6ccdf
Merge remote-tracking branch 'upstream/main' into software
Un1q32 May 30, 2026
af77e15
no more sdl
Un1q32 May 30, 2026
29f1b9e
remove newline to reduce diff
Un1q32 May 30, 2026
e993813
Merge remote-tracking branch 'upstream/main' into software
Un1q32 Jun 4, 2026
2bf8fc8
Merge remote-tracking branch 'upstream/main' into software
Un1q32 Jun 7, 2026
965a3a0
Merge remote-tracking branch 'upstream/main' into software
Un1q32 Jun 8, 2026
41ca240
gcc 2.95
Un1q32 Jun 9, 2026
5c2b420
Merge remote-tracking branch 'upstream/main' into software
Un1q32 Jun 9, 2026
71e7229
Merge remote-tracking branch 'upstream/main' into software
Un1q32 Jun 10, 2026
7ebcc22
use the float version
Un1q32 Jun 10, 2026
f26e0b1
* Expand texture LRU length.
iProgramMC Jun 16, 2026
7138b18
Merge pull request #8 from Un1q32/software
iProgramMC Jun 16, 2026
5a7c7aa
Merge branch 'main' of https://github.com/MrPowerGamerBR/Butterscotch…
iProgramMC Jun 16, 2026
04c5ebe
Fix warnings (marked as errors) in the swrenderer code
iProgramMC Jun 16, 2026
ecdab99
Implement no-op "requireNonnull" functions
iProgramMC Jun 16, 2026
c6bcacb
* Fix a bug where text rotation positions were incorrectly computed.
iProgramMC Jun 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ option(ENABLE_WAD16 "Enable support for WAD Version 15/16" ON)
option(ENABLE_WAD17 "Enable support for WAD Version 17" ON)
option(ENABLE_LEGACY_GL "Enable the legacy OpenGL renderer" ON)
option(ENABLE_MODERN_GL "Enable the modern OpenGL renderer" ON)
option(ENABLE_SW_RENDERER "Enable the software renderer" ON)
if(NOT ENABLE_WAD14 AND NOT ENABLE_WAD16 AND NOT ENABLE_WAD17)
message(FATAL_ERROR "You need to build Butterscotch with at least one WAD version enabled!")
endif()
Expand All @@ -80,6 +81,9 @@ endif()
if(ENABLE_MODERN_GL)
add_compile_definitions(ENABLE_MODERN_GL)
endif()
if(ENABLE_SW_RENDERER)
add_compile_definitions(ENABLE_SW_RENDERER)
endif()

if(PLATFORM STREQUAL "web-meta")
# Metadata-only build: just the data.win parser and its direct deps. No VM, no runner, no I/O subsystems.
Expand Down Expand Up @@ -165,20 +169,27 @@ if(PLATFORM STREQUAL "desktop")
# Matches the GitHub Actions container flags (FORTIFY requires building with optimizations enabled!)
target_compile_options(butterscotch PRIVATE "$<$<CONFIG:Release,RelWithDebInfo>:-U_FORTIFY_SOURCE;-D_FORTIFY_SOURCE=2>")

if(NOT ENABLE_LEGACY_GL AND NOT ENABLE_MODERN_GL)
if(NOT ENABLE_LEGACY_GL AND NOT ENABLE_MODERN_GL AND NOT ENABLE_SW_RENDERER)
message(FATAL_ERROR "You must enable at least one renderer!")
endif()
file(GLOB GL_SOURCES src/image/*.c src/gl_common/*.c)
file(GLOB GL_SOURCES src/image/*.c)
if(ENABLE_LEGACY_GL OR ENABLE_MODERN_GL)
file(GLOB GL_SOURCES ${GL_SOURCES} src/gl_common/*.c)
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/gl)
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/gl_common)
endif()
if(ENABLE_LEGACY_GL)
file(GLOB GL_SOURCES ${GL_SOURCES} src/gl_legacy/*.c)
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/gl_legacy)
endif()
if(ENABLE_MODERN_GL)
file(GLOB GL_SOURCES ${GL_SOURCES} src/gl/*.c)
endif()
if(ENABLE_SW_RENDERER)
file(GLOB GL_SOURCES ${GL_SOURCES} src/sw/*.c)
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/sw)
endif()
target_sources(butterscotch PRIVATE ${GL_SOURCES})
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/gl)
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/gl_common)
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/image)

# Butterscotch VM/interpreter profiler
Expand Down Expand Up @@ -212,19 +223,25 @@ if(PLATFORM STREQUAL "desktop")
endif()

# GLAD
if(ENABLE_GLES)
add_compile_definitions(ENABLE_GLES)
add_library(glad STATIC vendor/glad-gles/src/glad.c)
target_include_directories(glad PUBLIC vendor/glad-gles/include)
else()
add_library(glad STATIC vendor/glad/src/glad.c)
target_include_directories(glad PUBLIC vendor/glad/include)
if(ENABLE_LEGACY_GL OR ENABLE_MODERN_GL OR DESKTOP_BACKEND STREQUAL "glfw3" OR DESKTOP_BACKEND STREQUAL "glfw2")
if(ENABLE_GLES)
add_compile_definitions(ENABLE_GLES)
add_library(glad STATIC vendor/glad-gles/src/glad.c)
target_include_directories(glad PUBLIC vendor/glad-gles/include)
else()
add_library(glad STATIC vendor/glad/src/glad.c)
target_include_directories(glad PUBLIC vendor/glad/include)
endif()
set(PLATFORM_LIBRARIES glad)
endif()

# stb_image
target_include_directories(butterscotch PUBLIC vendor/stb/image)

set(PLATFORM_LIBRARIES glad m bzip2 stb_ds sha1 stb_vorbis)
# stb_vorbis
target_include_directories(butterscotch PUBLIC vendor/stb/vorbis)

set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} m bzip2 stb_ds sha1 stb_vorbis)
if(MINGW)
set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} opengl32 gdi32 winmm)
elseif(NOT CMAKE_SYSTEM_NAME STREQUAL "Haiku")
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,18 @@ GLFW3_LIBS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs glfw3)
LIBS += $(GLFW3_LIBS)
DEFINES += -DUSE_GLFW3
ENABLE_GLAD := 1
ifdef ENABLE_GLES
DISABLE_SW_RENDERER := 1
endif
endif
ifeq ($(DESKTOP_BACKEND),glfw2)
GLFW2_LIBS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs libglfw)
LIBS += $(GLFW2_LIBS)
DEFINES += -DUSE_GLFW2
ENABLE_GLAD := 1
ifdef ENABLE_GLES
DISABLE_SW_RENDERER := 1
endif
endif
ifeq ($(DESKTOP_BACKEND),sdl1)
SDL1_LIBS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs sdl)
Expand Down Expand Up @@ -114,6 +120,13 @@ SRCS += $(wildcard src/gl/*.c)
HEADERS += $(wildcard src/gl/*.h)
endif

ifndef DISABLE_SW_RENDERER
DEFINES += -DENABLE_SW_RENDERER
SRCS += $(wildcard src/sw/*.c)
HEADERS += $(wildcard src/sw/*.h)
INCLUDES += -Isrc/sw
endif

ifdef DISABLE_WAD14
ifdef DISABLE_WAD16
ifdef DISABLE_WAD17
Expand All @@ -124,9 +137,11 @@ endif

ifdef DISABLE_LEGACY_GL
ifdef DISABLE_MODERN_GL
ifdef DISABLE_SW_RENDERER
$(error must enable at least 1 renderer)
endif
endif
endif

ifdef ENABLE_GLES
DEFINES += -DENABLE_GLES
Expand Down
24 changes: 24 additions & 0 deletions src/sw/defines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "common.h"

// CONFIG: Change the size of a pixel.
//
// 32-bit: 0xAARRGGBB
// 16-bit: 0b0RRRRRGGGGGBBBBB
// 8-bit: 0bBBGGGRRR
#define PIXEL_SIZE 32
//#define PIXEL_SIZE 16
//#define PIXEL_SIZE 8

#if defined(__GNUC__) && (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
#define LIKELY(cond) __builtin_expect(!!(cond), 1)
#define UNLIKELY(cond) __builtin_expect(!!(cond), 0)
#else
#define LIKELY(cond) (cond)
#define UNLIKELY(cond) (cond)
#endif

#define UNUSED __attribute__ ((unused))
#define FORCE_INLINE static inline __attribute__((always_inline))

105 changes: 105 additions & 0 deletions src/sw/pixel_convert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#pragma once

#include "defines.h"
#include "binary_utils.h"

#if PIXEL_SIZE == 32
typedef uint32_t uintpixel_t;
#elif PIXEL_SIZE == 16
typedef uint16_t uintpixel_t;
#elif PIXEL_SIZE == 8
typedef uint8_t uintpixel_t;
#define PXL_TRANSPARENT (0xAA)
#else
#error "Unknown pixel size!"
#endif

// The native format coming out of GameMaker Studio's assets.
typedef union
{
struct {
uint8_t r, g, b, a;
} p;
uint32_t l;
}
Pixel32ABGR;

// This is the format the renderer knows how to work with.
typedef union
{
struct {
#ifdef IS_BIG_ENDIAN
uint8_t a, r, g, b;
#else
uint8_t b, g, r, a;
#endif
} p;
uint32_t l;
}
Pixel32ARGB;

FORCE_INLINE UNUSED
uint16_t abgr8888_to_rgb1555(uint32_t xl)
{
Pixel32ABGR x;
x.l = xl;
return (x.p.b >> 3) | ((x.p.g >> 3) << 5) | ((x.p.r >> 3) << 10) | ((x.p.a >> 7) << 15);
}

FORCE_INLINE UNUSED
uint8_t abgr8888_to_rgb332(uint32_t xl)
{
Pixel32ABGR x;
x.l = xl;

#if PIXEL_SIZE == 8
//check if transparent
if (x.p.a < 128)
return PXL_TRANSPARENT;
#endif

uint8_t pxl = (x.p.r >> 5) | ((x.p.g >> 5) << 3) | ((x.p.b >> 6) << 6);

#if PIXEL_SIZE == 8
//hacky fixup
if (pxl == PXL_TRANSPARENT)
pxl++;
#endif

return pxl;
}

FORCE_INLINE UNUSED
uintpixel_t swrConvertPixelBase(uint32_t gmPixel)
{
#if PIXEL_SIZE == 32
return (gmPixel & 0xFF00FF00) | ((gmPixel & 0xFF) << 16) | ((gmPixel >> 16) & 0xFF);
#elif PIXEL_SIZE == 16
return abgr8888_to_rgb1555(gmPixel);
#elif PIXEL_SIZE == 8
return abgr8888_to_rgb332(gmPixel);
#endif
}

#if PIXEL_SIZE == 32
#define TRANSPARENT_MASK 0xFF000000
#elif PIXEL_SIZE == 16
#define TRANSPARENT_MASK 0x8000
#endif

#if PIXEL_SIZE == 8

#define swrConvertPixel(x) swrConvertPixelBase((x) | 0xFF000000)
#define swrConvertPixelTexture(x) swrConvertPixelBase(x)

#elif defined IS_BIG_ENDIAN

#define swrConvertPixel(x) swrConvertPixelBase(x)
#define swrConvertPixelTexture(x) swrConvertPixelBase(BinaryUtils_bswap32(x))

#else

#define swrConvertPixel swrConvertPixelBase
#define swrConvertPixelTexture swrConvertPixelBase

#endif
Loading
Loading