sokol: studio impl wip

This commit is contained in:
Vadim Grigoruk 2018-09-27 18:25:14 +03:00
parent 9507749ff1
commit f002911f22
5 changed files with 116 additions and 45 deletions

View File

@ -229,38 +229,32 @@ if(NOT EMSCRIPTEN)
endif() endif()
################################ ################################
# Sokol renderer example # Sokol
################################ ################################
set(SOKOL_SRC
${EXAMPLE_DIR}/sokol/main.c
)
if(APPLE) if(APPLE)
set(SOKOL_SRC ${SOKOL_SRC} ${EXAMPLE_DIR}/sokol/sokol.m) add_library(sokol src/ext/sokol_impl.m)
else() else()
set(SOKOL_SRC ${SOKOL_SRC} ${EXAMPLE_DIR}/sokol/sokol.c) add_library(sokol src/ext/sokol_impl.c)
endif() endif()
if(APPLE) if(APPLE)
set_source_files_properties(${SOKOL_SRC} PROPERTIES COMPILE_FLAGS -DSOKOL_METAL) target_compile_definitions(sokol PRIVATE SOKOL_METAL)
elseif(WIN32) elseif(WIN32)
set_source_files_properties(${SOKOL_SRC} PROPERTIES COMPILE_FLAGS "-DSOKOL_D3D11 -DSOKOL_D3D11_SHADER_COMPILER") target_compile_definitions(sokol PRIVATE SOKOL_D3D11 SOKOL_D3D11_SHADER_COMPILER)
elseif(LINUX) elseif(LINUX)
set_source_files_properties(${SOKOL_SRC} PROPERTIES COMPILE_FLAGS -DSOKOL_GLCORE33) target_compile_definitions(sokol PRIVATE SOKOL_GLCORE33)
endif() endif()
if(WIN32) #set_source_files_properties(${SOKOL_SRC} PROPERTIES COMPILE_FLAGS -DSOKOL_METAL)
add_executable(sokol-renderer WIN32 ${SOKOL_SRC}) # set_source_files_properties(${SOKOL_SRC} PROPERTIES COMPILE_FLAGS "-DSOKOL_D3D11 -DSOKOL_D3D11_SHADER_COMPILER")
else() #set_source_files_properties(${SOKOL_SRC} PROPERTIES COMPILE_FLAGS -DSOKOL_GLCORE33)
add_executable(sokol-renderer ${SOKOL_SRC})
endif()
if(APPLE) if(APPLE)
set_property (TARGET sokol-renderer APPEND_STRING PROPERTY set_property (TARGET sokol APPEND_STRING PROPERTY
COMPILE_FLAGS "-fobjc-arc") COMPILE_FLAGS "-fobjc-arc")
target_link_libraries(sokol-renderer target_link_libraries(sokol
"-framework Cocoa" "-framework Cocoa"
"-framework QuartzCore" "-framework QuartzCore"
"-framework Metal" "-framework Metal"
@ -268,22 +262,51 @@ if(APPLE)
"-framework AudioToolbox" "-framework AudioToolbox"
) )
elseif(WIN32) elseif(WIN32)
target_link_libraries(sokol-renderer D3D11) target_link_libraries(sokol D3D11)
if(MINGW) if(MINGW)
target_link_libraries(sokol-renderer D3dcompiler_47 mingw32) target_link_libraries(sokol D3dcompiler_47)
endif() endif()
elseif(LINUX) elseif(LINUX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
target_link_libraries(sokol-renderer X11 GL m dl asound) target_link_libraries(sokol X11 GL m dl asound)
endif()
target_include_directories(sokol PRIVATE 3rd-party/sokol)
################################
# Sokol renderer example
################################
set(SOKOL_SRC
${EXAMPLE_DIR}/sokol/main.c
)
if(WIN32)
add_executable(sokol-renderer WIN32 ${SOKOL_SRC})
else()
add_executable(sokol-renderer ${SOKOL_SRC})
endif()
if(MINGW)
target_link_libraries(sokol-renderer mingw32)
endif()
# TODO: remove this and define shaders in the sokol lib
if(APPLE)
target_compile_definitions(sokol-renderer PRIVATE SOKOL_METAL)
elseif(WIN32)
target_compile_definitions(sokol-renderer PRIVATE SOKOL_D3D11)
elseif(LINUX)
target_compile_definitions(sokol-renderer PRIVATE SOKOL_GLCORE33)
endif() endif()
target_include_directories(sokol-renderer PRIVATE include) target_include_directories(sokol-renderer PRIVATE include)
target_include_directories(sokol-renderer PRIVATE 3rd-party/sokol) target_include_directories(sokol-renderer PRIVATE 3rd-party/sokol)
target_include_directories(sokol-renderer PRIVATE src) target_include_directories(sokol-renderer PRIVATE src)
add_dependencies(sokol-renderer tic80core) add_dependencies(sokol-renderer tic80core sokol)
target_link_libraries(sokol-renderer tic80core) target_link_libraries(sokol-renderer tic80core sokol)
################################ ################################
# SDL GPU # SDL GPU
@ -470,19 +493,32 @@ target_compile_definitions(tic80prolib PRIVATE TIC80_PRO)
# TIC-80 app # TIC-80 app
################################ ################################
set(TIC80_DIR src) set(TIC80_OUTPUTS ${TIC80_OUTPUTS} tic80-sokol tic80pro-sokol)
set(TIC80_SRC
${TIC80_DIR}/net.c
${TIC80_DIR}/system/sdlgpu.c
${TIC80_DIR}/ext/file_dialog.c
)
if(APPLE) if(APPLE)
set(TIC80_SRC ${TIC80_SRC} ${TIC80_DIR}/ext/file_dialog.m) set(TIC80_SRC_COMMON ${TIC80_SRC_COMMON} src/ext/file_dialog.m)
else()
set(TIC80_SRC_COMMON ${TIC80_SRC_COMMON} src/ext/file_dialog.c)
endif() endif()
foreach(TIC80_OUTPUT ${TIC80_OUTPUTS}) foreach(TIC80_OUTPUT ${TIC80_OUTPUTS})
if(TIC80_OUTPUT MATCHES "-sokol")
set(SOKOL_RENDERER TRUE)
else()
set(SOKOL_RENDERER FALSE)
endif()
message("SOKOL_RENDERER ${SOKOL_RENDERER}")
set(TIC80_SRC ${TIC80_SRC_COMMON})
if(SOKOL_RENDERER)
set(TIC80_SRC ${TIC80_SRC} src/system/sokol.c)
else()
set(TIC80_SRC ${TIC80_SRC} src/net.c src/system/sdlgpu.c)
endif()
if(WIN32) if(WIN32)
set(TIC80_SRC ${TIC80_SRC} build/windows/tic80.rc) set(TIC80_SRC ${TIC80_SRC} build/windows/tic80.rc)
add_executable(${TIC80_OUTPUT} WIN32 ${TIC80_SRC}) add_executable(${TIC80_OUTPUT} WIN32 ${TIC80_SRC})
@ -496,21 +532,31 @@ foreach(TIC80_OUTPUT ${TIC80_OUTPUTS})
target_include_directories(${TIC80_OUTPUT} PRIVATE include) target_include_directories(${TIC80_OUTPUT} PRIVATE include)
target_include_directories(${TIC80_OUTPUT} PRIVATE src) target_include_directories(${TIC80_OUTPUT} PRIVATE src)
target_include_directories(${TIC80_OUTPUT} PRIVATE 3rd-party/SDL2-2.0.8/include)
target_include_directories(${TIC80_OUTPUT} PRIVATE 3rd-party/sdl-gpu/include)
target_include_directories(${TIC80_OUTPUT} PRIVATE 3rd-party/SDL2_net-2.0.1) target_include_directories(${TIC80_OUTPUT} PRIVATE 3rd-party/SDL2_net-2.0.1)
target_include_directories(${TIC80_OUTPUT} PRIVATE 3rd-party/SDL2-2.0.8/include)
if(SOKOL_RENDERER)
target_include_directories(${TIC80_OUTPUT} PRIVATE 3rd-party/sokol)
else()
target_include_directories(${TIC80_OUTPUT} PRIVATE 3rd-party/sdl-gpu/include)
endif()
if(MINGW) if(MINGW)
target_link_libraries(${TIC80_OUTPUT} mingw32) target_link_libraries(${TIC80_OUTPUT} mingw32)
endif() endif()
if(NOT EMSCRIPTEN) if(SOKOL_RENDERER)
add_dependencies(${TIC80_OUTPUT} SDL2main SDL2-static) add_dependencies(${TIC80_OUTPUT} sokol)
target_link_libraries(${TIC80_OUTPUT} SDL2-static SDL2main) target_link_libraries(${TIC80_OUTPUT} sokol)
endif() else()
if(NOT EMSCRIPTEN)
add_dependencies(${TIC80_OUTPUT} SDL2main SDL2-static)
target_link_libraries(${TIC80_OUTPUT} SDL2-static SDL2main)
endif()
add_dependencies(${TIC80_OUTPUT} ${TIC80_OUTPUT}lib sdlnet sdlgpu) add_dependencies(${TIC80_OUTPUT} ${TIC80_OUTPUT}lib sdlnet sdlgpu)
target_link_libraries(${TIC80_OUTPUT} ${TIC80_OUTPUT}lib sdlnet sdlgpu) target_link_libraries(${TIC80_OUTPUT} ${TIC80_OUTPUT}lib sdlnet sdlgpu)
endif()
if(LINUX) if(LINUX)
include(FindPkgConfig) include(FindPkgConfig)

View File

@ -22,9 +22,9 @@
#include "file_dialog.h" #include "file_dialog.h"
#include <SDL.h> #include <tic80_config.h>
#if defined(__WINDOWS__) #if defined(__TIC_WINDOWS__)
#include <windows.h> #include <windows.h>
#include <commdlg.h> #include <commdlg.h>
@ -36,7 +36,7 @@ wchar_t* wcscpy(wchar_t *, const wchar_t *);
void file_dialog_load(file_dialog_load_callback callback, void* data) void file_dialog_load(file_dialog_load_callback callback, void* data)
{ {
OPENFILENAMEW ofn; OPENFILENAMEW ofn;
SDL_zero(ofn); memset(&ofn, 0, sizeof ofn);
wchar_t filename[MAX_PATH]; wchar_t filename[MAX_PATH];
memset(filename, 0, sizeof(filename)); memset(filename, 0, sizeof(filename));
@ -83,7 +83,7 @@ void file_dialog_load(file_dialog_load_callback callback, void* data)
void file_dialog_save(file_dialog_save_callback callback, const char* name, const u8* buffer, size_t size, void* data, u32 mode) void file_dialog_save(file_dialog_save_callback callback, const char* name, const u8* buffer, size_t size, void* data, u32 mode)
{ {
OPENFILENAMEW ofn; OPENFILENAMEW ofn;
SDL_zero(ofn); memset(&ofn, 0, sizeof ofn);
wchar_t filename[MAX_PATH]; wchar_t filename[MAX_PATH];
mbstowcs(filename, name, MAX_PATH); mbstowcs(filename, name, MAX_PATH);
@ -102,7 +102,7 @@ void file_dialog_save(file_dialog_save_callback callback, const char* name, cons
fwrite(buffer, 1, size, file); fwrite(buffer, 1, size, file);
fclose(file); fclose(file);
#if !defined(__WINDOWS__) #if !defined(__TIC_WINDOWS__)
chmod(filename, mode); chmod(filename, mode);
#endif #endif
callback(true, data); callback(true, data);
@ -157,7 +157,7 @@ void file_dialog_save(file_dialog_save_callback callback, const char* name, cons
callback(true, data); callback(true, data);
} }
#elif defined(__LINUX__) #elif defined(__TIC_LINUX__)
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -267,7 +267,7 @@ void file_dialog_save(file_dialog_save_callback callback, const char* name, cons
callback(false, data); callback(false, data);
} }
#elif defined(__MACOSX__) #elif defined(__TIC_MACOSX__)
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -345,7 +345,7 @@ void file_dialog_save(file_dialog_save_callback callback, const char* name, cons
callback(false, data); callback(false, data);
} }
#elif defined(__ANDROID__) #elif defined(__TIC_ANDROID__)
#include <jni.h> #include <jni.h>
#include <sys/stat.h> #include <sys/stat.h>

25
src/system/sokol.c Normal file
View File

@ -0,0 +1,25 @@
#include "sokol_app.h"
#include "sokol_gfx.h"
#include "sokol_time.h"
#include "sokol_audio.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <tic80.h>
sapp_desc sokol_main(int argc, char* argv[])
{
return (sapp_desc) {0};
// .init_cb = app_init,
// .frame_cb = app_frame,
// .event_cb = app_input,
// .cleanup_cb = app_cleanup,
// .width = 3 * TIC80_FULLWIDTH,
// .height = 3 * TIC80_FULLHEIGHT,
// .window_title = "TIC-80 with Sokol renderer",
// .ios_keyboard_resizes_canvas = true
// };
}