Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 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
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
24 changes: 17 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,24 @@ if(PLATFORM STREQUAL "glfw")
$<TARGET_FILE_DIR:butterscotch>/gamecontrollerdb.txt
)
elseif(PLATFORM STREQUAL "sdl")
if (NOT ENABLE_LEGACY_GL)
message(FATAL_ERROR "SDL requires legacy GL!")
option(ENABLE_SW_RENDERER "Enable the software renderer (SDL 1.2 only)" ON)

if (NOT ENABLE_LEGACY_GL AND NOT ENABLE_SW_RENDERER)
message(FATAL_ERROR "SDL requires legacy GL or the software renderer!")
endif()

if(ENABLE_LEGACY_GL)
file(GLOB GL_SOURCES src/gl_legacy/*.c src/gl_common/*.c src/image/*.c)
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/gl_legacy)
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/gl_common)
target_sources(butterscotch PRIVATE ${GL_SOURCES})
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/gl)
elseif(ENABLE_SW_RENDERER)
file(GLOB SWR_SOURCES src/sw/*.c src/image/*.c)
add_compile_definitions(ENABLE_SW_RENDERER)
target_sources(butterscotch PRIVATE ${SWR_SOURCES})
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/sw)
endif()
file(GLOB GL_SOURCES src/gl_legacy/*.c src/gl_common/*.c src/image/*.c)
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/gl_legacy)
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/gl_common)
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/image)

# Butterscotch VM/interpreter profiler
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ ifndef DISABLE_BC17
DEFINES += -DENABLE_BC17
endif

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

# GNU make doesn't have a way to do OR in conditionals, stupid language for clowns
ifndef DISABLE_LEGACY_GL
ENABLE_GL := 1
Expand Down Expand Up @@ -86,7 +95,9 @@ endif

ifdef DISABLE_LEGACY_GL
ifeq ($(PLATFORM),sdl)
ifdef DISABLE_SW_RENDERER
$(error must enable at least 1 renderer)
endif
else
ifdef DISABLE_MODERN_GL
$(error must enable at least 1 renderer)
Expand Down
10 changes: 5 additions & 5 deletions src/sdl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,10 @@ void Runner_setNextFrame(uint32_t* framebuffer, int width, int height)
height,
32,
width * 4,
0xff0000,
0x00ff00,
0x0000ff,
0
0x00ff0000, // Rmask
0x0000ff00, // Gmask
0x000000ff, // Bmask
0x00000000 // Amask
);
}

Expand Down Expand Up @@ -1215,7 +1215,7 @@ int main(int argc, char* argv[]) {
if (!args.headless && runner->currentRoom->speed > 0) {
static bool fastForwardActive = false;
static bool fastForwardTabPrev = false;
bool fastForwardTabNow = false;
bool fastForwardTabNow = RunnerKeyboard_checkPressed(runner->keyboard, '\t');
if (args.fastForwardSpeed > 0.0 && fastForwardTabNow && !fastForwardTabPrev) {
fastForwardActive = !fastForwardActive;
lastFrameTime = (SDL_GetTicks()/1000.0f);
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