Skip to content

Commit

Permalink
change files structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jintaoyugithub committed Oct 12, 2024
1 parent a2344dc commit 96fac9e
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 54 deletions.
File renamed without changes.
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": "x64-Debug"
}
Binary file added .vs/Shift/v17/workspaceFileList.bin
Binary file not shown.
19 changes: 19 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"OutputFoldersPerTargetSystem": {
"本地计算机": [
"out\\build\\x64-Debug",
"out\\install\\x64-Debug"
]
},
"ExpandedNodes": [
"",
"\\examples",
"\\examples\\helloTri",
"\\include",
"\\include\\utils",
"\\src",
"\\src\\utils"
],
"SelectedNode": "\\examples\\helloTri\\helloTri.cpp",
"PreviewInSolutionExplorer": true
}
Binary file added .vs/cmake.db
Binary file not shown.
12 changes: 12 additions & 0 deletions .vs/launch.vs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "helloTri.exe (examples\\helloTri\\helloTri.exe)",
"name": "helloTri.exe (examples\\helloTri\\helloTri.exe)"
}
]
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ cmake_minimum_required(VERSION 3.25.0)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(
IPS
Shift
VERSION 0.1.0
LANGUAGES C CXX
)

LANGUAGES C CXX)

# bx lib require c++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
Expand Down
2 changes: 1 addition & 1 deletion examples/helloTri/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ target_include_directories(
target_link_libraries(
helloTri
PUBLIC
Shift
shift_lib
)
59 changes: 54 additions & 5 deletions examples/helloTri/helloTri.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,56 @@
#include <bgfx/bgfx.h>
#include <iostream>
#include <utilsBgfx.hpp>
#include <utilsGLFW.hpp>
#include <utils/bgfx.hpp>
#include <utils/glfw.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

struct PosColorVertex {
float _x;
float _y;
float _z;
uint32_t _rgba;

static void init() {
_layout
.begin()
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
.end();
};

static bgfx::VertexLayout _layout;
};

bgfx::VertexLayout PosColorVertex::_layout;

PosColorVertex cubeVertices[] = {
{-1.0f, 1.0f, 1.0f, 0xff000000 },
{ 1.0f, 1.0f, 1.0f, 0xff0000ff },
{-1.0f, -1.0f, 1.0f, 0xff00ff00 },
{ 1.0f, -1.0f, 1.0f, 0xff00ffff },
{-1.0f, 1.0f, -1.0f, 0xffff0000 },
{ 1.0f, 1.0f, -1.0f, 0xffff00ff },
{-1.0f, -1.0f, -1.0f, 0xffffff00 },
{ 1.0f, -1.0f, -1.0f, 0xffffffff },
};

static const uint16_t s_cubeTriList[] = {
2, 1, 0,
2, 3, 1,
5, 6, 4,
7, 6, 5,
4, 2, 0,
6, 2, 4,
3, 5, 1,
3, 7, 5,
1, 4, 0,
1, 5, 4,
6, 3, 2,
7, 3, 6
};


int main(int _agrc, const char **_argv) {
std::cout << "Hello tri" << std::endl;
Expand All @@ -17,9 +66,9 @@ int main(int _agrc, const char **_argv) {
bgfx::Init init;
init.type = bgfx::RendererType::OpenGL;
init.vendorId = BGFX_PCI_ID_NONE;
init.platformData.nwh = ips::glfwNativeWindowHandle(window);
init.platformData.ndt = ips::glfwNativeDisplayHandle();
init.platformData.type = ips::getNativeWindowHandleType();
init.platformData.nwh = shift::glfwNativeWindowHandle(window);
init.platformData.ndt = shift::glfwNativeDisplayHandle();
init.platformData.type = shift::getNativeWindowHandleType();
init.resolution.width = 800;
init.resolution.height = 600;
init.resolution.reset = BGFX_RESET_VSYNC;
Expand Down
4 changes: 2 additions & 2 deletions include/appBase.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ips {
namespace shift {

class AppBase {
public:
Expand All @@ -9,4 +9,4 @@ class AppBase {
};

int runApp(AppBase *_app, int _argc, char **_agrv);
} // namespace ips
} // namespace shift
22 changes: 22 additions & 0 deletions include/utils/bgfx.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <bgfx/bgfx.h>
#include <bx/allocator.h>
#include <bx/readerwriter.h>
#include <string_view>
#include <bx/file.h>
#include <bx/readerwriter.h>
#include <bx/string.h>
#include <iostream>

namespace shift {
/* bgfx utils */
/// Get native handle type
bgfx::NativeWindowHandleType::Enum getNativeWindowHandleType();

/// Load resources from memory
bgfx::ShaderHandle loadShader(const std::string_view& _name);

bgfx::ProgramHandle loadProgram(const std::string_view& _vsName, const std::string_view& _fsName);

} // namespace shift
4 changes: 2 additions & 2 deletions include/utilsGLFW.hpp → include/utils/glfw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#endif //
#include <GLFW/glfw3native.h>

namespace ips {
namespace shift {

static void *glfwNativeWindowHandle(GLFWwindow *_window) {
#if BX_PLATFORM_LINUX
Expand Down Expand Up @@ -51,4 +51,4 @@ static void *glfwNativeDisplayHandle() {
#endif // BX_PLATFORM_
}

} // namespace ips
} // namespace shift
Empty file added include/utils/imgui.hpp
Empty file.
11 changes: 0 additions & 11 deletions include/utilsBgfx.hpp

This file was deleted.

40 changes: 11 additions & 29 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
set( LIB_NAME
Shift
)
set(LIB_NAME shift_lib)

set( SOURCES
appBase.cpp
)
set(SOURCES appBase.cpp "utils/bgfx.cpp")

add_library(
${LIB_NAME}
STATIC
${SOURCES}
)
add_library(${LIB_NAME} STATIC ${SOURCES})

target_include_directories(
${LIB_NAME}
PUBLIC
"${CMAKE_SOURCE_DIR}/include/"
"${CMAKE_SOURCE_DIR}/ext/bgfx.cmake/bgfx/3rdparty/"
"${CMAKE_SOURCE_DIR}/ext/bgfx.cmake/bgfx/include/"
"${CMAKE_SOURCE_DIR}/ext/bgfx.cmake/bx/include/"
"${CMAKE_SOURCE_DIR}/ext/bgfx.cmake/bimg/include/"
)

target_link_libraries(
${LIB_NAME}
PUBLIC
glm
glfw
bgfx
bx
bimg
)
${LIB_NAME}
PUBLIC "${CMAKE_SOURCE_DIR}/include/"
"${CMAKE_SOURCE_DIR}/ext/bgfx.cmake/bgfx/3rdparty/"
"${CMAKE_SOURCE_DIR}/ext/bgfx.cmake/bgfx/include/"
"${CMAKE_SOURCE_DIR}/ext/bgfx.cmake/bx/include/"
"${CMAKE_SOURCE_DIR}/ext/bgfx.cmake/bimg/include/")

target_link_libraries(${LIB_NAME} PUBLIC glm glfw bgfx bx bimg)
39 changes: 39 additions & 0 deletions src/utils/bgfx.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <utils/bgfx.hpp>

namespace shift {
static const bgfx::Memory* loadMem(const std::string_view& _filePath) {
return nullptr;
}

static bgfx::ShaderHandle loadShader(bx::FileReaderI* _reader, const std::string_view& _name) {
std::string_view shaderPath;

switch (bgfx::getRendererType()) {
case bgfx::RendererType::Noop:
case bgfx::RendererType::Direct3D11:
case bgfx::RendererType::Direct3D12: shaderPath = ""; break;
case bgfx::RendererType::Agc:
case bgfx::RendererType::Gnm: shaderPath; break;
case bgfx::RendererType::Metal: shaderPath; break;
case bgfx::RendererType::Nvn: shaderPath; break;
case bgfx::RendererType::OpenGL: shaderPath; break;
case bgfx::RendererType::OpenGLES: shaderPath; break;
case bgfx::RendererType::Vulkan: shaderPath; break;

case bgfx::RendererType::Count:
BX_ASSERT(false, "You should not be here!");
break;
};

bgfx::ShaderHandle handle = bgfx::createShader(loadMem(_name));
return handle;
}

bgfx::NativeWindowHandleType::Enum getNativeWindowHandleType() {
return bgfx::NativeWindowHandleType::Default;
}

bgfx::ShaderHandle loadShader(const std::string_view& _name) {
return loadShader(_name);
}
}

0 comments on commit 96fac9e

Please sign in to comment.