Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements #35

Merged
merged 6 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Framework/Graphics/Graphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void Clear(Color color)
/// <summary>
/// Clears the Back Buffer
/// </summary>
public static void Clear(Color color, int depth, int stencil, ClearMask mask)
public static void Clear(Color color, float depth, int stencil, ClearMask mask)
{
Platform.FosterClearCommand clear = new()
{
Expand Down Expand Up @@ -152,4 +152,4 @@ internal static void QueueDeleteResource(IntPtr ptr, Action<IntPtr> deleteMethod
}
}
}
}
}
2 changes: 1 addition & 1 deletion Framework/Graphics/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void Clear(Color color)
/// <summary>
/// Clears the Target
/// </summary>
public void Clear(Color color, int depth, int stencil, ClearMask mask)
public void Clear(Color color, float depth, int stencil, ClearMask mask)
{
Debug.Assert(!IsDisposed, "Target is Disposed");

Expand Down
4 changes: 2 additions & 2 deletions Framework/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public struct FosterClearCommand
public IntPtr target;
public FosterRect clip;
public Color color;
public int depth;
public float depth;
public int stencil;
public ClearMask mask;
}
Expand Down Expand Up @@ -265,4 +265,4 @@ public static void FreeUTF8(IntPtr ptr)
public static extern void FosterDraw(ref FosterDrawCommand command);
[DllImport(DLL)]
public static extern void FosterClear(ref FosterClearCommand command);
}
}
37 changes: 27 additions & 10 deletions Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

add_library(FosterPlatform SHARED
# Define target name
set (TARGET_NAME FosterPlatform)

add_library(${TARGET_NAME} SHARED
include/foster_platform.h
src/foster_platform.c
src/foster_image.c
src/foster_renderer.c
src/foster_renderer_d3d11.c
src/foster_renderer_opengl.c
)

target_include_directories(FosterPlatform
target_include_directories(${TARGET_NAME}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
)
Expand All @@ -42,7 +46,7 @@ else()
endif()

# Output libs to platform-specific library
set_target_properties(FosterPlatform
set_target_properties(${TARGET_NAME}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/libs/${FosterTarget}"
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/libs/${FosterTarget}"
Expand All @@ -52,25 +56,38 @@ set_target_properties(FosterPlatform
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/libs/${FosterTarget}"
)

if (MSVC)
# Set warning level 3
target_compile_options(${TARGET_NAME} PRIVATE /W3)

# Warnings as Errors Enabled
target_compile_options(${TARGET_NAME} PRIVATE /WX)
endif()

if(WIN32)
target_compile_definitions(${TARGET_NAME} PRIVATE _UNICODE UNICODE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(${TARGET_NAME} PRIVATE NOMINMAX)
endif ()

# tracks which libraries we need to link, depends on Options above
set(LIBS "")

# use the OpenGL Renderer Backend
if (FOSTER_OPENGL_ENABLED)
add_compile_definitions(FOSTER_OPENGL_ENABLED)
target_compile_definitions(${TARGET_NAME} PRIVATE FOSTER_OPENGL_ENABLED)
endif()

# use the D3D11 Renderer Backend
if (FOSTER_D3D11_ENABLED)
add_compile_definitions(FOSTER_D3D11_ENABLED)
target_compile_definitions(${TARGET_NAME} PRIVATE FOSTER_D3D11_ENABLED)
set(LIBS ${LIBS} d3d11.lib dxguid.lib D3Dcompiler.lib)
endif()

# Emscripten can import SDL2 directly
if (EMSCRIPTEN)

set_target_properties(FosterPlatform PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
target_link_libraries(FosterPlatform "-s USE_SDL=2 -s USE_WEBGL2=1")
set_target_properties(${TARGET_NAME} PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
target_link_libraries(${TARGET_NAME} "-s USE_SDL=2 -s USE_WEBGL2=1")

# Pull SDL2 from its Github repo
else()
Expand All @@ -84,7 +101,7 @@ else()
FetchContent_Declare(
SDL2
GIT_REPOSITORY https://github.com/libsdl-org/SDL
GIT_TAG release-2.28.2
GIT_TAG release-2.28.5
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(SDL2)
Expand All @@ -94,11 +111,11 @@ else()

# statically link SDL2 since we're building it ourselve
set(LIBS ${LIBS} ${FOSTER_SDL2_LIBS})
target_include_directories(FosterPlatform PRIVATE ${FOSTER_SDL2_INCLUDE})
target_include_directories(${TARGET_NAME} PRIVATE ${FOSTER_SDL2_INCLUDE})
endif()

# Tell SDL it's going to be a shared lib
set_property(TARGET ${FOSTER_SDL2_LIBS} PROPERTY POSITION_INDEPENDENT_CODE ON)

# Link SDL
target_link_libraries(FosterPlatform PRIVATE ${LIBS})
target_link_libraries(${TARGET_NAME} PRIVATE ${LIBS})
4 changes: 2 additions & 2 deletions Platform/include/foster_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ typedef struct FosterClearCommand
FosterTarget* target;
FosterRect clip;
FosterColor color;
int depth;
float depth;
int stencil;
FosterClearMask mask;
} FosterClearCommand;
Expand Down Expand Up @@ -624,4 +624,4 @@ FOSTER_API void FosterClear(FosterClearCommand* clear);
}
#endif

#endif
#endif
Binary file modified Platform/libs/osx/libFosterPlatform.dylib
Binary file not shown.
Binary file modified Platform/libs/x64/FosterPlatform.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Platform/src/foster_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void FosterPollEvents()
}
else if (event.type == SDL_MOUSEWHEEL)
{
fstate.desc.onMouseWheel(event.wheel.x, event.wheel.y);
fstate.desc.onMouseWheel((float)event.wheel.x, (float)event.wheel.y);
}
// Keyboard
else if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
Expand Down
Loading