Skip to content

Commit

Permalink
Merge PR KD-lab-Open-Source#151 - Sokol shadows support
Browse files Browse the repository at this point in the history
  • Loading branch information
IonAgorria committed Oct 23, 2024
2 parents 4b1d4d9 + 7ea85a6 commit b92f17b
Show file tree
Hide file tree
Showing 61 changed files with 13,549 additions and 10,176 deletions.
29 changes: 5 additions & 24 deletions .github/workflows/macos_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ on:
- ready_for_review

env:
VULKAN_SDK_VERSION: '1.3.250.1'
VULKAN_LIB_VERSION: '1.3.250'
MACOSX_DEPLOYMENT_TARGET: '10.15'
GH_CACHE_KEY: 10
GH_CACHE_KEY: 1

jobs:
build:
Expand All @@ -32,28 +30,14 @@ jobs:
- name: install libs
run: |
brew install ninja yasm dylibbundler \
libvpx boost meson cmake zlib \
libvpx boost cmake zlib \
sdl2 sdl2_image sdl2_mixer sdl2_net
- uses: actions/cache@v4
id: cache
with:
path: |
vulkansdk-macos.dmg
ffmpeg
key: MacOS-${{ env.VULKAN_SDK_VERSION }}-${{ env.GH_CACHE_KEY }}
- name: download Vulkan SDK
if: steps.cache.outputs.cache-hit != 'true'
run: |
wget https://sdk.lunarg.com/sdk/download/${{ env.VULKAN_SDK_VERSION }}/mac/vulkansdk-macos-${{ env.VULKAN_SDK_VERSION }}.dmg?Human=true -O vulkansdk-macos.dmg
- name: install Vulkan SDK
run: |
hdiutil attach vulkansdk-macos.dmg
sudo /Volumes/VulkanSDK/InstallVulkan.app/Contents/MacOS/InstallVulkan --root ~/VulkanSDK --accept-licenses --default-answer --confirm-command install
sync
cd ~/VulkanSDK/
sudo ./install_vulkan.py
sleep 10
hdiutil detach /Volumes/VulkanSDK
key: MacOS-${{ env.GH_CACHE_KEY }}
- name: ffmpeg -- download
if: steps.cache.outputs.cache-hit != 'true'
run: git clone --depth 1 --branch n6.1 https://git.ffmpeg.org/ffmpeg.git ffmpeg
Expand Down Expand Up @@ -94,7 +78,7 @@ jobs:
- name: perimeter -- create build dir
run: mkdir build
- name: perimeter -- configure
run: cmake .. -G Ninja -DCMAKE_BUILD_TYPE=${{matrix.env.build_type}} ${{matrix.env.cmake}}
run: cmake .. -G Ninja -DCMAKE_BUILD_TYPE=${{matrix.env.build_type}} -DOPTION_D3D9=OFF ${{matrix.env.cmake}}
working-directory: build
- name: perimeter -- build project
run: ninja
Expand All @@ -104,10 +88,7 @@ jobs:
working-directory: build
- name: perimeter -- strip
run: |
if [[ -d output/lib ]]; then
strip -x output/lib/*
fi
strip -x output/bin/*
strip -x output/bundle/perimeter.app/Contents/MacOS/*
working-directory: build
#TODO update package.sh to handle cmake install result
#- name: perimeter -- package app
Expand Down
43 changes: 41 additions & 2 deletions Source/Game/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,47 @@ SET(perimeter_LINK_LIBS
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"
"-framework Cocoa"
"-framework CoreAudio"
"-framework CoreBluetooth"
"-framework CoreGraphics"
"-framework CoreHaptics"
"-framework CoreMedia"
"-framework CoreMotion"
"-framework ForceFeedback"
"-framework Foundation"
"-framework GameController"
"-framework IOKit"
"-framework Metal"
"-framework QuartzCore"
"-framework Security"
)
IF(PERIMETER_DEBUG)
SET_TARGET_PROPERTIES(perimeter PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/macos/DebugInfo.plist"
)
ELSE()
SET_TARGET_PROPERTIES(perimeter PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/macos/Perimeter.app.template/Contents/Info.plist"
)
ENDIF()
ENDIF()

#message("Link Libs: ${perimeter_LINK_LIBS}")
target_link_libraries(perimeter PRIVATE ${perimeter_LINK_LIBS})

#Install rules
install (TARGETS perimeter RUNTIME)
#Install ruless
install(TARGETS perimeter
RUNTIME
LIBRARY
BUNDLE DESTINATION bundle
)
10 changes: 2 additions & 8 deletions Source/Render/D3D/D3DRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ void cD3DRender::UpdateRenderMode()
else if(lpD3D->CheckDeviceFormat(Adapter,D3DDEVTYPE_HAL,d3ddm.Format,D3DUSAGE_RENDERTARGET,D3DRTYPE_TEXTURE,D3DFMT_X1R5G5B5)==0)
TexFmtData[SURFMT_RENDERMAP16].Set(2,5,5,5,1,10,5,0,15,D3DFMT_X1R5G5B5);

TexFmtData[SURFMT_RENDERMAP_FLOAT].Set(0,0,0,0,0,0,0,0,0,0);
TexFmtData[SURFMT_RENDERMAP_DEPTH].Set(0,0,0,0,0,0,0,0,0,0);
if(lpD3D->CheckDeviceFormat(Adapter,D3DDEVTYPE_HAL,d3ddm.Format,D3DUSAGE_RENDERTARGET,D3DRTYPE_TEXTURE,D3DFMT_R32F)==0)
TexFmtData[SURFMT_RENDERMAP_FLOAT].Set(0,0,0,0,0,0,0,0,0,D3DFMT_R32F);
TexFmtData[SURFMT_RENDERMAP_DEPTH].Set(0,0,0,0,0,0,0,0,0,D3DFMT_R32F);

{
if(lpD3D->CheckDeviceFormat(Adapter,D3DDEVTYPE_HAL,d3ddm.Format,0,D3DRTYPE_TEXTURE,D3DFMT_A8)==0) {
Expand Down Expand Up @@ -1242,8 +1242,6 @@ const uint32_t D3D_LOCK_FLAGS_STATIC = D3DLOCK_NOSYSLOCK | D3DLOCK_NO_DIRTY_UPDA
const uint32_t D3D_LOCK_FLAGS_DYNAMIC = D3D_LOCK_FLAGS_STATIC | D3DLOCK_DISCARD;

void cD3DRender::UpdateD3DVertexBuffer(VertexBuffer* vb, size_t len) {
xassert(!vb->burned);
vb->burned = true;
xassert(len <= vb->data_len);
if (!vb->d3d) {
MTG();
Expand Down Expand Up @@ -1284,8 +1282,6 @@ void cD3DRender::UpdateD3DVertexBuffer(VertexBuffer* vb, size_t len) {
}

void cD3DRender::UpdateD3DIndexBuffer(IndexBuffer* ib, size_t len) {
xassert(!ib->burned);
ib->burned = true;
xassert(len <= ib->data_len);
if (!ib->d3d) {
MTG();
Expand Down Expand Up @@ -1444,8 +1440,6 @@ void cD3DRender::SubmitBuffers(ePrimitiveType primitive, VertexBuffer* vb, size_
xassert(0);
RDCALL(gb_RenderDevice3D->lpD3DDevice->DrawPrimitive(d3dType, offset, vertices));
}
if (vb->dynamic) vb->burned = false;
if (ib->dynamic) ib->burned = false;
}

void cD3DRender::SetGlobalFog(const sColor4f &color,const Vect2f &v)
Expand Down
7 changes: 7 additions & 0 deletions Source/Render/D3D/D3DRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class cD3DRender : public cInterfaceRenderDevice
int xScrMin,yScrMin,xScrMax,yScrMax;

bool isOrthographicProjSet = false;
bool WireframeMode = false;

void UpdateD3DVertexBuffer(VertexBuffer* vb, size_t len);
void UpdateD3DIndexBuffer(IndexBuffer* ib, size_t len);
Expand Down Expand Up @@ -166,6 +167,12 @@ class cD3DRender : public cInterfaceRenderDevice
void SetMaterialTilemapShadow() override;
void SetTileColor(sColor4f color) override;

bool CreateShadowTexture(int xysize) override;
void DeleteShadowTexture() override;

cTexture* GetShadowMap() override;
cTexture* GetLightMap() override;

// //// cInterfaceRenderDevice impls end ////

///Converts flag based vertex format to D3D9 FVF format
Expand Down
46 changes: 46 additions & 0 deletions Source/Render/D3D/D3DRenderDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,49 @@ void cD3DRender::DrawElasticSphere(class ElasticSphere *es) {
NumberPolygon += (is+1) * (js+1) + (is+2) * (js-1) - 2;
NumDrawObject++;
}

bool cD3DRender::CreateShadowTexture(int xysize) {
if (!gb_RenderDevice3D) {
return false;
}
DrawType* draw;
if (cTileMap::CheckLightMapType()) {
draw = gb_RenderDevice3D->dtAdvance;
}
else {
draw = gb_RenderDevice3D->dtFixed;
}
return draw->CreateShadowTexture(xysize);
}

void cD3DRender::DeleteShadowTexture() {
if (!gb_RenderDevice3D) {
return;
}
dtFixed->DeleteShadowTexture();
dtAdvance->DeleteShadowTexture();
}

cTexture* cD3DRender::GetShadowMap() {
if (!gb_RenderDevice3D) {
return nullptr;
}
if (cTileMap::CheckLightMapType()) {
return gb_RenderDevice3D->dtAdvance->GetShadowMap();
}
else {
return gb_RenderDevice3D->dtFixed->GetShadowMap();
}
}

cTexture* cD3DRender::GetLightMap() {
if (!gb_RenderDevice3D) {
return nullptr;
}
if (cTileMap::CheckLightMapType()) {
return gb_RenderDevice3D->dtAdvance->GetLightMap();
}
else {
return gb_RenderDevice3D->dtFixed->GetLightMap();
}
}
2 changes: 1 addition & 1 deletion Source/Render/D3D/D3DRenderTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ IDirect3DTexture9* cD3DRender::CreateSurface(int x, int y, eSurfaceFormat Textur
int Usage=0;
D3DPOOL Pool=D3DPOOL_MANAGED;

if(TextureFormat==SURFMT_RENDERMAP16 || TextureFormat==SURFMT_RENDERMAP32 || TextureFormat==SURFMT_RENDERMAP_FLOAT)
if(TextureFormat==SURFMT_RENDERMAP16 || TextureFormat==SURFMT_RENDERMAP32 || TextureFormat==SURFMT_RENDERMAP_DEPTH)
{
Usage=D3DUSAGE_RENDERTARGET;
Pool=D3DPOOL_DEFAULT;
Expand Down
4 changes: 0 additions & 4 deletions Source/Render/D3D/DrawType.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class DrawType
virtual void SetMaterialTilemapShadow()=0;

virtual IDirect3DTexture9* GetTZBuffer(){return NULL;}
virtual IDirect3DTexture9* GetTilemapShadow0(){return NULL;}

virtual void SetTileColor(sColor4f color)=0;//r,g,b=[0..2], a=ignored etc

Expand Down Expand Up @@ -197,9 +196,6 @@ class DrawTypeRadeon8500:public DrawType
virtual bool CreateShadowTexture(int xysize);
virtual void SetMaterialTilemap(cTileMap *TileMap);
virtual void SetMaterialTilemapShadow();
virtual IDirect3DTexture9* GetTilemapShadow0() {
return pLookupMap->GetFrameImage(0)->d3d;
}
virtual void SetTileColor(sColor4f color);
protected:
void SetMaterial(float Phase,cTexture *Texture0,cTexture *Texture1,sDataRenderMaterial *Data);
Expand Down
2 changes: 1 addition & 1 deletion Source/Render/D3D/DrawTypeRadeon8500.inl
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void DrawTypeRadeon8500::SetSimplyMaterialShadow(cObjMesh *Mesh,cTexture *Textur
mat.MaterialAnimPhase=0;

SetMaterialSimply(0,Texture,pShadowMap,&mat,GetOffsetTextureNumber());
TextureImage teximg(GetTilemapShadow0());
TextureImage teximg(pLookupMap->GetFrameImage(0)->d3d);
gb_RenderDevice3D->SetTextureImage(1, &teximg);

pPSObjectShadow->Select();
Expand Down
2 changes: 1 addition & 1 deletion Source/Render/D3D/DrawTypeRadeon9700.inl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void DrawTypeRadeon9700::DrawNoMaterialShadow(cObjMesh *Mesh)
bool DrawTypeRadeon9700::CreateShadowTexture(int xysize)
{
DeleteShadowTexture();
pShadowMap=GetTexLibrary()->CreateRenderTexture(xysize,xysize,TEXTURE_RENDER_SHADOW_9700,false);
pShadowMap=GetTexLibrary()->CreateRenderTexture(xysize,xysize,TEXTURE_RENDER_DEPTH,false);
if(!pShadowMap)
{
DeleteShadowTexture();
Expand Down
26 changes: 18 additions & 8 deletions Source/Render/inc/IRenderDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class cInterfaceRenderDevice : public cUnknownClass
std::unordered_map<uint64_t, class DrawBuffer*> drawBuffers;
Mat4f orthoVP;
eCullMode CameraCullMode = CULL_NONE;
bool WireframeMode = false;
bool debugUIEnabled = false;

virtual void DrawFieldDispatcher(class FieldDispatcher* ffd, uint8_t transparent);

Expand Down Expand Up @@ -269,6 +269,16 @@ class cInterfaceRenderDevice : public cUnknownClass
virtual void DrawPoint(const Vect3f &v1, const sColor4c& color);
virtual void FlushPrimitive3D();

virtual void DebugUISetEnable(bool enabled);
virtual bool DebugUIIsEnabled();
virtual bool DebugUIMouseMove(const Vect2f& pos);
virtual bool DebugUIMousePress(const Vect2f& pos, uint8_t button, bool pressed);
virtual bool DebugUIKeyPress(struct sKey* key, bool pressed);

#ifdef PERIMETER_DEBUG
virtual void StartCaptureFrame();
#endif

// Decl only methods

virtual eRenderDeviceSelection GetRenderSelection() const = 0;
Expand Down Expand Up @@ -328,13 +338,13 @@ class cInterfaceRenderDevice : public cUnknownClass
virtual void SetMaterialTilemapShadow() = 0;
virtual void SetTileColor(sColor4f color) = 0;

/*
virtual bool CreateShadowTexture(int xysize);
virtual void DeleteShadowTexture();
virtual bool CreateShadowTexture(int xysize) = 0;
virtual void DeleteShadowTexture() = 0;

virtual cTexture* GetShadowMap();
virtual cTexture* GetLightMap();
*/
virtual cTexture* GetShadowMap() = 0;
virtual cTexture* GetLightMap() = 0;

// Decl only methods end
};

cInterfaceRenderDevice* CreateIRenderDevice(eRenderDeviceSelection selection);
Expand All @@ -351,7 +361,7 @@ enum eSurfaceFormat
SURFMT_BUMP,
SURFMT_COLOR32,
SURFMT_COLORALPHA32,
SURFMT_RENDERMAP_FLOAT,
SURFMT_RENDERMAP_DEPTH,
SURFMT_GRAYALPHA,//A8L8 - в лудшем случае
SURFMT_UV,
SURFMT_U16V16,
Expand Down
1 change: 0 additions & 1 deletion Source/Render/inc/MemoryResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class MemoryResource {
size_t data_len = 0;
bool dirty = true;
bool locked = false;
bool burned = false;

explicit MemoryResource(size_t _data_len) {
AllocData(_data_len);
Expand Down
1 change: 1 addition & 0 deletions Source/Render/inc/StdAfxRD.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <list>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>

#if (!defined(_FINAL_VERSION_) || defined(_DEBUG)) && !defined(NASSERT)
Expand Down
Loading

0 comments on commit b92f17b

Please sign in to comment.