Skip to content

Commit

Permalink
Changes from sokol branch and OpenGL fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-ushakov committed Jun 9, 2024
1 parent f574558 commit 7dbbe68
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 36 deletions.
19 changes: 12 additions & 7 deletions Source/Game/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ SET(perimeter_LINK_LIBS
${SDL2_MIXER_LIBRARY}
${SDL2_NET_LIBRARY}
${EXE_LINK_LIBS_POST}
)

IF(PERIMETER_WINDOWS)
SET(perimeter_LINK_LIBS ${perimeter_LINK_LIBS} ${SDL2MAIN_LIBRARY})
ENDIF()

IF(APPLE)
#TODO is this necessary?
SET(perimeter_LINK_LIBS ${perimeter_LINK_LIBS}
"-framework AppKit"
"-framework AudioToolbox"
"-framework Carbon"
Expand All @@ -158,22 +167,18 @@ SET(perimeter_LINK_LIBS
"-framework Metal"
"-framework QuartzCore"
"-framework Security"
)

IF(PERIMETER_WINDOWS)
SET(perimeter_LINK_LIBS ${perimeter_LINK_LIBS} ${SDL2MAIN_LIBRARY})
ENDIF()

IF(APPLE)
)
IF(PERIMETER_DEBUG)
SET_TARGET_PROPERTIES(perimeter PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/macos/DebugInfo.plist"
BUNDLE DESTINATION ${CMAKE_SOURCE_DIR}
)
ELSE()
SET_TARGET_PROPERTIES(perimeter PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/macos/Perimeter.app.template/Contents/Info.plist"
BUNDLE DESTINATION ${CMAKE_SOURCE_DIR}
)
ENDIF()
ENDIF()
Expand Down
4 changes: 2 additions & 2 deletions Source/Render/D3D/D3DRenderTilemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int cD3DRender::CreateTilemap(cTileMap *TileMap)
{
int err = cInterfaceRenderDevice::CreateTilemap(TileMap);
if (err == 0) {
cTileMapRender* p = TileMap->GetTilemapRender();
cTileMapRender* p = TileMap->GetTilemapRender(cTileMap::RenderType::DIRECT);
xassert(p);
if (p) {
tilemaps.push_back(p);
Expand All @@ -49,7 +49,7 @@ int cD3DRender::CreateTilemap(cTileMap *TileMap)

int cD3DRender::DeleteTilemap(cTileMap *TileMap)
{
cTileMapRender* p = TileMap->GetTilemapRender();
cTileMapRender* p = TileMap->GetTilemapRender(cTileMap::RenderType::DIRECT);
if (p) {
auto removed = std::remove(tilemaps.begin(), tilemaps.end(), p);
tilemaps.erase(removed, tilemaps.end());
Expand Down
15 changes: 7 additions & 8 deletions Source/Render/sokol/SokolRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int cSokolRender::Init(int xScr, int yScr, int mode, SDL_Window* wnd, int Refres
if (sdl_gl_context == nullptr) {
ErrH.Abort("Error creating SDL GL Context", XERR_CRITICAL, 0, SDL_GetError());
}
printf("GPU vendor: %s, renderer: %s\n", glGetString(GL_VENDOR), glGetString(GL_RENDER));
printf("GPU vendor: %s, renderer: %s\n", glGetString(GL_VENDOR), glGetString(GL_RENDERER));

swapchain.gl.framebuffer = 0;
#endif //PERIMETER_SOKOL_GL
Expand Down Expand Up @@ -280,13 +280,12 @@ int cSokolRender::Init(int xScr, int yScr, int mode, SDL_Window* wnd, int Refres
sampler_desc.mipmap_filter = SG_FILTER_LINEAR;
sampler = sg_make_sampler(sampler_desc);

sg_sampler_desc shadow_sampler_desc{
.min_filter = SG_FILTER_LINEAR,
.mag_filter = SG_FILTER_LINEAR,
.wrap_u = SG_WRAP_CLAMP_TO_EDGE,
.wrap_v = SG_WRAP_CLAMP_TO_EDGE,
.compare = SG_COMPAREFUNC_LESS
};
sg_sampler_desc shadow_sampler_desc = {};
shadow_sampler_desc.min_filter = SG_FILTER_LINEAR;
shadow_sampler_desc.mag_filter = SG_FILTER_LINEAR;
shadow_sampler_desc.wrap_u = SG_WRAP_CLAMP_TO_EDGE;
shadow_sampler_desc.wrap_v = SG_WRAP_CLAMP_TO_EDGE;
shadow_sampler_desc.compare = SG_COMPAREFUNC_LESS;
shadow_sampler = sg_make_sampler(&shadow_sampler_desc);

//Create empty texture
Expand Down
5 changes: 3 additions & 2 deletions Source/Render/sokol/SokolRenderDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,14 @@ bool cSokolRender::CreateShadowTexture(int xysize) {
DeleteShadowTexture();
return false;
}
SetupTexture(lightMapRenderTarget->texture->GetFrameImage(0)->sg, SG_PIXELFORMAT_BGRA8);
SetupTexture(lightMapRenderTarget->texture->GetFrameImage(0)->sg,
sg_query_desc().environment.defaults.color_format);

{
auto& render_pass = lightMapRenderTarget->render_pass;
render_pass.action.colors[0].load_action = SG_LOADACTION_CLEAR;
render_pass.action.colors[0].store_action = SG_STOREACTION_STORE;
render_pass.action.colors[0].clear_value = { 1.0f, 1.0f, 1.0f, 1.0f};
render_pass.action.colors[0].clear_value = { 1.0f, 1.0f, 1.0f, 1.0f };

sg_attachments_desc description{};
description.colors[0].image = lightMapRenderTarget->texture->GetFrameImage(0)->sg->image->res;
Expand Down
11 changes: 0 additions & 11 deletions Source/Render/sokol/SokolRenderPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,6 @@

#include "VertexFormat.h"

const uint32_t PIPELINE_ID_MODE_MASK = 0xFFFF;
const uint32_t PIPELINE_ID_MODE_BITS = 8;
static_assert((1 << PIPELINE_ID_MODE_BITS) - 1 < PIPELINE_ID_MODE_MASK);
const uint32_t PIPELINE_ID_VERTEX_FMT_BITS = (VERTEX_FMT_BITS - 1); //Remove 1 dedicated for Dot3 flag in D3D
const uint32_t PIPELINE_ID_VERTEX_FMT_MASK = (1 << PIPELINE_ID_VERTEX_FMT_BITS) - 1;
const uint32_t PIPELINE_ID_TYPE_MASK = 0xF;

const uint32_t PIPELINE_ID_MODE_SHIFT = 0;
const uint32_t PIPELINE_ID_VERTEX_FMT_SHIFT = 16;
const uint32_t PIPELINE_ID_TYPE_SHIFT = PIPELINE_ID_VERTEX_FMT_SHIFT + PIPELINE_ID_VERTEX_FMT_BITS;

const uint32_t PERIMETER_SOKOL_PIPELINES_MAX = 128;

struct SokolPipeline {
Expand Down
9 changes: 4 additions & 5 deletions Source/Render/sokol/SokolRenderState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void cSokolRender::DoSokolRendering(sg_pass& render_pass, const std::vector<Soko
const SokolPipeline* pipeline = command->pipeline;
if (pipeline == nullptr) {
//Not implemented vertex format
xxassert(0, "cSokolRender::EndScene missing pipeline for " + std::to_string(command->pipeline_id));
xxassert(0, "cSokolRender::EndScene missing pipeline");
continue;
}
#if defined(PERIMETER_DEBUG) && 0
Expand Down Expand Up @@ -496,7 +496,7 @@ void cSokolRender::CreateCommandEmpty() {
commands.emplace_back(cmd);

#ifdef PERIMETER_RENDER_TRACKER_COMMANDS
label = "Submit - Pipeline: " + std::to_string(pipeline_id)
label = "Submit"
+ " Vtxs: " + std::to_string(cmd->vertices)
+ " Idxs: " + std::to_string(cmd->indices)
+ " Tex0: " + std::to_string(reinterpret_cast<size_t>(cmd->sokol_textures[0]))
Expand Down Expand Up @@ -524,8 +524,7 @@ void cSokolRender::CreateCommand(VertexBuffer* vb, size_t vertices, IndexBuffer*
}

#ifdef PERIMETER_RENDER_TRACKER_COMMANDS
std::string label = "Pipeline: " + std::to_string(pipeline_id);
RenderSubmitEvent(RenderEvent::CREATE_COMMAND, label.c_str());
RenderSubmitEvent(RenderEvent::CREATE_COMMAND, "Start");
#endif

#ifdef PERIMETER_DEBUG
Expand Down Expand Up @@ -652,7 +651,7 @@ void cSokolRender::CreateCommand(VertexBuffer* vb, size_t vertices, IndexBuffer*
}

#ifdef PERIMETER_RENDER_TRACKER_COMMANDS
label = "Submit - Pipeline: " + std::to_string(pipeline_id)
label = "Submit"
+ " Vtxs: " + std::to_string(cmd->vertices)
+ " Idxs: " + std::to_string(cmd->indices)
+ " Tex0: " + std::to_string(reinterpret_cast<size_t>(cmd->sokol_textures[0]))
Expand Down
2 changes: 1 addition & 1 deletion Source/UserInterface/GameShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1687,8 +1687,8 @@ void GameShell::KeyPressed(sKey& Key)
MakeShot();
break;

case VK_F6 | KBD_SHIFT:
#ifdef PERIMETER_DEBUG
case VK_F6 | KBD_SHIFT:
terRenderDevice->StartCaptureFrame();
break;
#endif
Expand Down

0 comments on commit 7dbbe68

Please sign in to comment.