Skip to content

Commit

Permalink
truss 0.2.2; changes from over a year
Browse files Browse the repository at this point in the history
  • Loading branch information
PyryM authored Aug 8, 2022
1 parent 4ad0b09 commit 330de7d
Show file tree
Hide file tree
Showing 47 changed files with 4,366 additions and 2,951 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ old_scripts/
*.cap
*.bin
*.ilk
*.bc
*.DS_Store
trusslog.txt
shader_errors.txt
Expand Down
9 changes: 6 additions & 3 deletions cmake/terra.cmake
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
include(ExternalProject)

# Use this version of terra.
set(terra_RELEASE_DATE "1.0.0-beta3")
set(terra_RELEASE_HASH "e4ec5d1")
set(terra_RELEASE_DATE "1.0.0-beta4")
set(terra_RELEASE_HASH "868748e")

if("${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
set(terra_SYSTEM_NAME "Windows")
set(terra_SHARED_LIBS_DIR "bin")
set(terra_LIBRARY_NAME "terra.dll")
set(terra_IMPLIB_NAME "terra.lib")
set(terra_RELEASE_EXT ".7z")
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
set(terra_SYSTEM_NAME "OSX")
set(terra_SHARED_LIBS_DIR "lib")
set(terra_LIBRARY_NAME "terra.dylib")
set(terra_RELEASE_EXT ".tar.xz")
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
set(terra_SYSTEM_NAME "Linux")
set(terra_SHARED_LIBS_DIR "lib")
set(terra_LIBRARY_NAME "libterra.so")
set(terra_RELEASE_EXT ".tar.xz")
else()
message(FATAL_ERROR "Terra does not have precompiled binaries for '${CMAKE_SYSTEM_NAME}'.")
endif()

# Download `terra` and unzip its binaries.
ExternalProject_Add(terra_EXTERNAL
URL "https://github.com/zdevito/terra/releases/download/release-${terra_RELEASE_DATE}/terra-${terra_SYSTEM_NAME}-x86_64-${terra_RELEASE_HASH}.zip"
URL "https://github.com/zdevito/terra/releases/download/release-${terra_RELEASE_DATE}/terra-${terra_SYSTEM_NAME}-x86_64-${terra_RELEASE_HASH}${terra_RELEASE_EXT}"
URL_MD5 "${terra_MD5}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
Expand Down
6,479 changes: 3,748 additions & 2,731 deletions dist/include/bgfx/bgfx.h

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions dist/include/bgfx/cimgui_terra.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ CIMGUI_API void igBGFXEndFrame();

CIMGUI_API void igBGFXPushFont(uint32_t _fontid);

// TODO: figure out the complicated includes for this
// Note that in practice `ImTextureID` is a void*
// CIMGUI_API ImTextureID igBGFXTexToId(bgfx_texture_handle_t _handle, uint8_t _flags, uint8_t _mip);

typedef struct
{
// private data
Expand Down Expand Up @@ -3465,6 +3461,9 @@ CIMGUI_API void igImFontAtlasBuildRender32bppRectFromString(ImFontAtlas* atlas,i
CIMGUI_API void igImFontAtlasBuildMultiplyCalcLookupTable(unsigned char out_table[256],float in_multiply_factor);
CIMGUI_API void igImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256],unsigned char* pixels,int x,int y,int w,int h,int stride);

// Just manually define a bgfx texture handle here
typedef struct bgfx_texture_handle { uint16_t idx; } bgfx_texture_handle_t;
CIMGUI_API ImTextureID igBGFXTexToId(bgfx_texture_handle_t _handle, uint8_t _flags, uint8_t _mip);

/////////////////////////hand written functions
//no LogTextV
Expand Down
1 change: 1 addition & 0 deletions dist/include/bgfx/shader/bgfx_compute.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
# define COMP_rg8 float2
# define COMP_r8 float
#endif // BGFX_SHADER_LANGUAGE_HLSL
#define COMP_rg32f float2
#define COMP_rgba32f float4

#define IMAGE2D_RO( _name, _format, _reg) \
Expand Down
2 changes: 1 addition & 1 deletion dist/include/compat/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int sscanf(const char *, const char *, ...);

typedef struct FILE FILE;
size_t fread(void* ptr, size_t size, size_t count, FILE* stream);
size_t fwrite(void *ptr, size_t size, size_t count, FILE *stream);
size_t fwrite(const void* ptr, size_t size, size_t count, FILE* stream);
FILE* fopen(const char* filename, const char* mode);
int fclose(FILE* stream);
int fseek(FILE* stream, long int offset, int origin);
Expand Down
27 changes: 21 additions & 6 deletions dist/include/sdl/sdl_minimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1728,10 +1728,8 @@ typedef enum
SDL_SYSWM_ANDROID
} SDL_SYSWM_TYPE;

// eh just hack these in for now
typedef void* HWND;
typedef void* HDC;

// Define all of these with void pointers because that's what
// we're casting to anyway
typedef struct SDL_SysWMinfo
{
SDL_version version;
Expand All @@ -1740,9 +1738,26 @@ typedef struct SDL_SysWMinfo
{
struct
{
HWND window; /**< The window handle */
HDC hdc; /**< The window device context */
void* window; /**< The window handle */
void* hdc; /**< The window device context */
} win;
struct
{
void* display; /**< The X11 display */
void* window; /**< The X11 window */
} x11;
struct
{
struct wl_display* display; /**< Wayland display */
struct wl_surface* surface; /**< Wayland surface */
void* shell_surface; /**< DEPRECATED Wayland shell_surface (window manager handle) */
struct wl_egl_window* egl_window; /**< Wayland EGL window (native window) */
struct xdg_surface* xdg_surface; /**< Wayland xdg surface (window manager handle) */
} wl;
struct
{
void* window; /**< The cocoa display */
} cocoa;
/* Can't have an empty union */
int dummy;
} info;
Expand Down
77 changes: 14 additions & 63 deletions dist/scripts/app/immediateapp.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,35 @@
--
-- a convenience class for immediate-mode only rendering

local class = require('class')
local math = require("math")
local gfx = require("gfx")
local ecs = require("ecs")
local graphics = require("graphics")
local imrender = require("gfx/imrender.t")
--local immediate = require("graphics/imrender.t")

local ImmediateApp = class('ImmediateApp')

function ImmediateApp:init(options)
log.debug("ImmediateApp: init")
options = options or {}
self.headless = options.headless
if not self.headless then
local sdl = require("addon/sdl.t")
sdl.create_window(options.width or 1280, options.height or 720,
options.title or 'truss',
options.fullscreen and 1,
options.display or 0)
self.width, self.height = sdl.get_window_size()
self.stats = options.stats
options.debugtext = options.stats
options.window = sdl
end
gfx.init_gfx(options)
log.debug("ImmediateApp: window+gfx initialized")
if (not self.headless) and options.error_console ~= false then
self:install_console()
end
self._init_options = options
local app = require("app/app.t")
local m = {}

self:init_ecs()
self:init_pipeline(options)
end
local ImmediateApp = app.App:extend("ImmediateApp")
m.ImmediateApp = ImmediateApp

function ImmediateApp:install_console()
require("dev/miniconsole.t").install()
local function terminate(msg)
if msg then print(msg) end
truss.quit()
end

function ImmediateApp:init_ecs()
-- create ecs
local ECS = ecs.ECS()
self.ECS = ECS
if not self.headless then
ECS:add_system(require("input/sdl_input.t").SDLInputSystem())
ECS.systems.input:on("keydown", self, self.keydown)
end
ECS:add_system(ecs.System("update", "update"))
if self.async ~= false then
ECS:add_system(require("async").AsyncSystem())
function ImmediateApp:init(options)
ImmediateApp.super.init(self, options)
if options.func then
self.imstage:run(options.func, terminate, terminate)
end
ECS:add_system(graphics.RenderSystem())
if self.stats then ECS:add_system(graphics.DebugTextStats()) end
end

-- this creates a pipeline with nothing but an immediate state
function ImmediateApp:init_pipeline(options)
local p = graphics.Pipeline({verbose = true})
self.imstage = p:add_stage(imrender.ImmediateStage{
num_views = options.num_views or 32,
func = options.immediate_func
self.imstage = p:add_stage(graphics.ImmediateStage{
num_views = options.num_views or 32
})
self.pipeline = p
self.ECS.systems.render:set_pipeline(p)
end

function ImmediateApp:keydown(evtname, evt)
local keyname, modifiers = evt.keyname, evt.modifiers
if keyname == "F12" then
print("Saving screenshot!")
gfx.save_screenshot("screenshot.png")
end
end

function ImmediateApp:update()
self.ECS:update()
end

local m = {}
m.ImmediateApp = ImmediateApp
return m
57 changes: 57 additions & 0 deletions dist/scripts/core/build.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
-- building/cross-compilation functions
local m = {}

function m.is_native()
return (not _modroot) or (_modroot.cross_target == nil)
end

function m.target_name()
if m.is_native() then
return truss.os
else
return _modroot.cross_target_name or "Unknown"
end
end

function m.includec(filename, args, target)
if not m.is_native() then
assert(target == nil, "cannot cross-compile within a cross-compilation context!")
args = _modroot.cross_args
target = _modroot.cross_target
end
print("including c [native? ", m.is_native(), "]: ", filename)
return terralib.includec(filename, args, target)
end

function m.includecstring(str, args, target)
if not m.is_native() then
assert(target == nil, "cannot cross-compile within a cross-compilation context!")
args = _modroot.cross_args
target = _modroot.cross_target
end
print("including cstr [native? ", m.is_native(), "]: ", str:sub(1, 80))
return terralib.includecstring(str, args, target)
end

function m.linklibrary(fn)
if not m.is_native() then return end
return terralib.linklibrary(fn)
end

function m.truss_link_library(...)
if not m.is_native() then return end
return truss.link_library(...)
end

function m.create_cross_compilation_root(options)
local resolve = require("core/resolve.t")
local root = resolve.create_root{
module_env = truss.clean_subenv
}
root.cross_args = options.include_args
root.cross_target = options.target
root.cross_target_name = options.target_name
return root
end

return m
1 change: 1 addition & 0 deletions dist/scripts/core/core.t
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ local function create_module_env(module_name, file_name, options)
modenv._module_name = module_name
local path = find_path(file_name)
modenv._path = path
modenv._modroot = false
modenv.require = create_module_require(path)
modenv._env = modenv
if not options.allow_globals then
Expand Down
Loading

0 comments on commit 330de7d

Please sign in to comment.