Skip to content
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
45 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
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 @@ -228,14 +228,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
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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
2 changes: 1 addition & 1 deletion src/sdl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,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
8 changes: 8 additions & 0 deletions src/sw/defines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#define LIKELY(cond) __builtin_expect(!!(cond), 1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should have a windows path and be in common.h
Also is there any reason to have UNUSED when we have MAYBE_UNUSED?

#define UNLIKELY(cond) __builtin_expect(!!(cond), 0)

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

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

#include "defines.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 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 (0b10101010)
#else
#error "Unknown pixel size!"
#endif

typedef union
{
struct {
uint8_t r, g, b, a;
} p;
uint32_t l;
}
Pixel32ABGR;

typedef union
{
struct {
uint8_t b, g, r, a;
} 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 swrConvertPixelTexture(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 == 8
#define swrConvertPixel(x) swrConvertPixelTexture((x) | 0xFF000000)
#else
#define swrConvertPixel swrConvertPixelTexture
#endif
Loading
Loading