Skip to content
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
60 changes: 36 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ include(${PROJECT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake)
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ".")
include(InstallRequiredSystemLibraries)

find_package(unofficial-angle CONFIG REQUIRED)
find_package(CMakeRC CONFIG REQUIRED)
find_package(CURL CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(glfw3 CONFIG REQUIRED)
find_package(gli CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
find_package(LuaJIT REQUIRED)
find_package(Microsoft.GSL CONFIG REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(re2 CONFIG REQUIRED)
find_package(sol2 CONFIG REQUIRED)
find_package(Threads REQUIRED)
find_package(zstd REQUIRED)
find_package(ZLIB REQUIRED)
find_package(WebP)

set(SIMPLEGRAPHIC_SOURCES
"config.h"
"dep/stb/stb_image.h"
Expand Down Expand Up @@ -75,28 +92,36 @@ set(SIMPLEGRAPHIC_SOURCES
"ui_subscript.h"
)

set (SIMPLEGRAPHIC_PLATFORM_SOURCES)
add_library(SimpleGraphic SHARED
${SIMPLEGRAPHIC_SOURCES}
)

cmrc_add_resource_library(SimpleGraphic-Assets ALIAS SimpleGraphic::Assets NAMESPACE SimpleGraphic)

cmrc_add_resources(SimpleGraphic-Assets
"assets/gles/display_render_target.frag"
"assets/gles/display_render_target.vert"
"assets/gles/tinted_texture.frag"
"assets/gles/tinted_texture.vert"
)

if (APPLE)
set (SIMPLEGRAPHIC_PLATFORM_SOURCES
target_sources(SimpleGraphic PRIVATE
"engine/system/win/sys_macos.mm"
)
endif()

if (WIN32)
set (SIMPLEGRAPHIC_PLATFORM_SOURCES
target_sources(SimpleGraphic PRIVATE
"engine/system/win/sys_console.cpp"
"SimpleGraphic.rc"
)
else()
set (SIMPLEGRAPHIC_PLATFORM_SOURCES
target_sources(SimpleGraphic PRIVATE
"engine/system/win/sys_console_unix.cpp"
)
endif()

add_library(SimpleGraphic SHARED
${SIMPLEGRAPHIC_SOURCES}
${SIMPLEGRAPHIC_PLATFORM_SOURCES}
)
target_compile_definitions(SimpleGraphic
PRIVATE
"_CRT_SECURE_NO_DEPRECATE"
Expand All @@ -111,28 +136,14 @@ target_compile_definitions(SimpleGraphic
"UNICODE"
)

target_compile_options(SimpleGraphic PRIVATE "$<$<CXX_COMPILER_ID:MSVC>:/MP>")

target_include_directories(SimpleGraphic
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/engine"
)

find_package(unofficial-angle CONFIG REQUIRED)
find_package(CURL CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(glfw3 CONFIG REQUIRED)
find_package(gli CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
find_package(LuaJIT REQUIRED)
find_package(Microsoft.GSL CONFIG REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(re2 CONFIG REQUIRED)
find_package(sol2 CONFIG REQUIRED)
find_package(Threads REQUIRED)
find_package(zstd REQUIRED)
find_package(ZLIB REQUIRED)
find_package(WebP)

add_library(cmp_core STATIC
dep/compressonator/cmp_core/source/cmp_core.cpp
dep/compressonator/cmp_core/source/cmp_core.h
Expand Down Expand Up @@ -239,6 +250,7 @@ target_link_libraries(SimpleGraphic
LuaJIT::LuaJIT
Microsoft.GSL::GSL
re2::re2
SimpleGraphic::Assets
Threads::Threads
WebP::webpdecoder
ZLIB::ZLIB
Expand Down
13 changes: 13 additions & 0 deletions assets/gles/display_render_target.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version 300 es
precision mediump float;

uniform highp sampler2D s_tex;

in vec2 v_texcoord;

out vec4 f_fragColor;

void main(void) {
vec3 color = texture(s_tex, v_texcoord).rgb;
f_fragColor = vec4(color, 1.0);
}
10 changes: 10 additions & 0 deletions assets/gles/display_render_target.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 300 es
in vec4 a_position;
in vec2 a_texcoord;

out vec2 v_texcoord;

void main(void) {
gl_Position = a_position;
v_texcoord = a_texcoord;
}
18 changes: 18 additions & 0 deletions assets/gles/tinted_texture.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#version 300 es
precision mediump float;

uniform highp sampler2DArray s_tex[{SG_TEXTURE_COUNT}];

in vec2 v_screenPos;
in vec2 v_texcoord;
in vec4 v_tint;
in vec2 v_texId;

out vec4 f_fragColor;

void main(void)
{{
vec4 color;
{SG_TEXTURE_SWITCH}
f_fragColor = color * v_tint;
}}
28 changes: 28 additions & 0 deletions assets/gles/tinted_texture.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#version 300 es

uniform vec2 u_screenSize;

in vec2 a_vertex;
in vec2 a_texcoord;
in vec4 a_tint;
in vec2 a_texId;

out vec2 v_screenPos;
out vec2 v_texcoord;
out vec4 v_tint;
out vec2 v_texId;

vec2 SceneToNdc(vec2 scenePos) {
vec2 unitPos = scenePos / u_screenSize;
return mix(vec2(-1.0, 1.0), vec2(1.0, -1.0), unitPos);
}

void main(void)
{
v_texcoord = a_texcoord;
v_tint = a_tint;
v_texId = a_texId;
vec2 pos = SceneToNdc(a_vertex);
v_screenPos = pos;
gl_Position = vec4(pos, 0, 1);
}
13 changes: 3 additions & 10 deletions engine/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//

#include <glm/vec2.hpp>
#include <glm/gtc/type_ptr.hpp>

// =======
// Classes
Expand Down Expand Up @@ -44,13 +45,6 @@ enum r_texFlag_e {
TF_ASYNC = 0x08, // Load asynchronously
};

// Blend modes
enum r_blendMode_e {
RB_ALPHA,
RB_PRE_ALPHA,
RB_ADDITIVE
};

// Shader handle
class r_shaderHnd_c {
friend class r_renderer_c;
Expand Down Expand Up @@ -93,12 +87,11 @@ class r_IRenderer {
virtual void SetDrawSubLayer(int subLayer) = 0;
virtual int GetDrawLayer() = 0;
virtual void SetViewport(int x = 0, int y = 0, int width = 0, int height = 0) = 0;
virtual void SetBlendMode(int mode) = 0;
virtual void DrawColor(const col4_t col = NULL) = 0;
virtual void DrawColor(dword col) = 0;
virtual void GetDrawColor(col4_t color) = 0;
virtual void DrawImage(r_shaderHnd_c* hnd, glm::vec2 pos, glm::vec2 extent, glm::vec2 uv1 = { 0, 0 }, glm::vec2 uv2 = { 1, 1 }, int stackLayer = 0, std::optional<int> maskLayer = {}) = 0;
virtual void DrawImageQuad(r_shaderHnd_c* hnd, glm::vec2 p0, glm::vec2 p1, glm::vec2 p2, glm::vec2 p3, glm::vec2 uv0 = { 0, 0 }, glm::vec2 uv1 = { 1, 0 }, glm::vec2 uv2 = { 1, 1 }, glm::vec2 uv3 = { 0, 1 }, int stackLayer = 0, std::optional<int> maskLayer = {}) = 0;
virtual void DrawImage(r_shaderHnd_c* hnd, glm::vec2 pos, glm::vec2 extent, glm::vec2 uv1 = { 0, 0 }, glm::vec2 uv2 = { 1, 1 }, int stackLayer = 0) = 0;
virtual void DrawImageQuad(r_shaderHnd_c* hnd, glm::vec2 p0, glm::vec2 p1, glm::vec2 p2, glm::vec2 p3, glm::vec2 uv0 = { 0, 0 }, glm::vec2 uv1 = { 1, 0 }, glm::vec2 uv2 = { 1, 1 }, glm::vec2 uv3 = { 0, 1 }, int stackLayer = 0) = 0;
virtual void DrawString(float x, float y, int align, int height, const col4_t col, int font, const char* str) = 0;
virtual void DrawStringFormat(float x, float y, int align, int height, const col4_t col, int font, const char* fmt, ...) = 0;
virtual int DrawStringWidth(int height, int font, const char* str) = 0;
Expand Down
Loading
Loading