Skip to content

Commit 864c436

Browse files
authored
Add shader rendering (#79)
1 parent 2e7dd5d commit 864c436

File tree

24 files changed

+1314
-347
lines changed

24 files changed

+1314
-347
lines changed

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_policy(SET CMP0141 NEW)
33
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<CONFIG:Debug>,EditAndContinue,ProgramDatabase>" CACHE STRING "MSVC debug information format")
44
project(
55
NavKit
6-
VERSION 2.9.0
6+
VERSION 2.10.0
77
DESCRIPTION "An app to create NAVP and AIRG files for use with Hitman: World of Assassination"
88
LANGUAGES CXX)
99
set(CMAKE_CXX_STANDARD 20)
@@ -20,8 +20,10 @@ find_package(OpenSSL CONFIG REQUIRED)
2020
find_package(PNG REQUIRED)
2121
find_package(SDL2 CONFIG REQUIRED)
2222
find_package(ZLIB REQUIRED)
23+
find_package(assimp CONFIG REQUIRED)
2324
find_package(httplib CONFIG REQUIRED)
2425
find_package(cpptrace CONFIG REQUIRED)
26+
find_package(glm CONFIG REQUIRED)
2527
find_package(nfd CONFIG REQUIRED)
2628
find_package(recastnavigation CONFIG REQUIRED)
2729
find_package(simdjson CONFIG REQUIRED)
@@ -41,9 +43,11 @@ endif ()
4143
set(THIRD_PARTY_DLL_PATHS
4244
"$<TARGET_FILE:GLEW::glew>"
4345
"$<TARGET_FILE:SDL2::SDL2>"
46+
"$<TARGET_FILE:assimp::assimp>"
4447
"$<TARGET_FILE:cpptrace::cpptrace>"
4548
"$<TARGET_FILE:freetype>"
4649
"$<TARGET_FILE:ftgl>"
50+
"$<TARGET_FILE:glm::glm>"
4751
"$<TARGET_FILE:nfd::nfd>"
4852
"$<TARGET_FILE:simdjson::simdjson>"
4953
"$<TARGET_FILE:unofficial::brotli::brotlicommon>"
@@ -85,7 +89,7 @@ if(BUILD_INSTALLER)
8589
RUNTIME DESTINATION .
8690
)
8791
install(FILES
88-
$<TARGET_FILE:glacier2obj>
92+
$<TARGET_FILE:navkit-rpkg-lib>
8993
$<TARGET_FILE:NavWeakness>
9094
$<TARGET_FILE:ResourceLib_HM3>
9195
DESTINATION .

extern/vcpkg

Submodule vcpkg updated 3725 files

include/NavKit/NavKitConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#define NavKit_VERSION_MAJOR "2"
2-
#define NavKit_VERSION_MINOR "9"
2+
#define NavKit_VERSION_MINOR "10"
33
#define NavKit_VERSION_PATCH "0"

include/NavKit/module/Airg.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
#include <vector>
66
#define WIN32_LEAN_AND_MEAN
77
#include <map>
8+
#include <GL/glew.h>
9+
#include <glm/vec3.hpp>
10+
#include <glm/vec4.hpp>
811
#include <windows.h>
12+
#include "../model/ReasoningGrid.h"
913

1014
struct Vec3;
1115
struct ResourceConverter;
@@ -16,12 +20,23 @@ enum CellColorDataSource {
1620
OFF, AIRG_BITMAP, VISION_DATA, LAYER
1721
};
1822

23+
struct AirgVertex {
24+
glm::vec3 pos;
25+
glm::vec3 normal;
26+
glm::vec4 color;
27+
};
1928
class Airg {
2029
public:
2130
explicit Airg();
2231

2332
~Airg();
2433

34+
static GLuint airgLineVAO;
35+
36+
static GLuint airgTriVBO;
37+
38+
static GLuint airgTriVAO;
39+
2540
static Airg &getInstance() {
2641
static Airg instance;
2742
return instance;
@@ -51,8 +66,10 @@ class Airg {
5166

5267
void finalizeSave();
5368

54-
void build();
69+
int visibilityDataSize(ReasoningGrid* reasoningGrid, int waypointIndex);
5570

71+
void build();
72+
static void addWaypointGeometry(std::vector<AirgVertex>& triVerts, std::vector<AirgVertex>& lineVerts, const Waypoint& waypoint, bool selected, const glm::vec4& color, bool forceFan = false);
5673
void renderLayerIndices(int waypointIndex) const;
5774

5875
void renderCellBitmaps(int waypointIndex, bool selected);
@@ -112,6 +129,22 @@ class Airg {
112129
static std::map<std::string, std::string> airgHashIoiStringMap;
113130

114131
private:
132+
static GLuint airgLineVBO;
133+
134+
static int airgTriCount;
135+
136+
static int airgLineCount;
137+
138+
static bool airgDirty;
139+
140+
static GLuint airgHitTestVAO;
141+
142+
static GLuint airgHitTestVBO;
143+
144+
static int airgHitTestCount;
145+
146+
static bool airgHitTestDirty;
147+
115148
static INT_PTR CALLBACK AirgDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
116149

117150
static char *openSaveAirgFileDialog(char *lastAirgFolder);

include/NavKit/module/Navp.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <vector>
55
#define WIN32_LEAN_AND_MEAN
66
#include <windows.h>
7+
#include <GL/glew.h>
78

89
#include "../model/ZPathfinding.h"
910

@@ -25,8 +26,36 @@ class Navp {
2526

2627
~Navp();
2728

29+
static int navMeshTriCount;
30+
31+
static GLuint hitTestVBO;
32+
33+
static GLuint hitTestVAO;
34+
35+
static GLuint navMeshLineVBO;
36+
37+
static GLuint navMeshLineVAO;
38+
39+
static GLuint navMeshTriVBO;
40+
41+
static GLuint navMeshTriVAO;
42+
2843
static HWND hNavpDialog;
2944

45+
static int navMeshLineCount;
46+
47+
static int hitTestTriCount;
48+
49+
static bool navMeshDirty;
50+
51+
static bool hitTestDirty;
52+
53+
static int lastSelectedArea;
54+
55+
static void updateNavMeshBuffers(const NavPower::NavMesh* navMesh, int selectedIndex);
56+
57+
static void updateHitTestBuffers(const NavPower::NavMesh* navMesh);
58+
3059
void renderPfSeedPoints() const;
3160
void renderPfSeedPointsForHitTest() const;
3261

include/NavKit/module/Obj.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
#include <vector>
77
#define WIN32_LEAN_AND_MEAN
88
#include <windows.h>
9+
#include <GL/glew.h>
910

11+
#include "../../include/NavKit/render/Model.h"
12+
#include "../../include/NavKit/render/Shader.h"
1013
enum MeshType {
1114
ALOC,
1215
PRIM
@@ -20,6 +23,10 @@ enum SceneMeshBuildType {
2023
class Obj {
2124
explicit Obj();
2225

26+
static GLuint tileTextureId;
27+
28+
static void loadTileTexture();
29+
2330
static void updateObjDialogControls(HWND hDlg);
2431

2532
public:
@@ -58,6 +65,7 @@ class Obj {
5865
bool primLods[8];
5966
bool blendFileBuilt;
6067
static HWND hObjDialog;
68+
Model model;
6169

6270
static char *openSetBlenderFileDialog(const char *lastBlenderFile);
6371

@@ -79,7 +87,9 @@ class Obj {
7987

8088
void finalizeObjBuild();
8189

82-
static void renderObj();
90+
void renderObj() const;
91+
92+
void renderObjUsingRecast();
8393

8494
static char *openLoadObjFileDialog();
8595

include/NavKit/module/Renderer.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
#include <SDL_syswm.h>
44
#include "../../NavWeakness/Vec3.h"
55
#include "../util/Math.h"
6-
class FTPixmapFont;
6+
#include "../render/Shader.h"
7+
#include <glm/mat4x4.hpp>
8+
9+
class FTPolygonFont;
710

811
typedef double GLdouble;
912
typedef int GLint;
@@ -33,6 +36,8 @@ class Renderer {
3336

3437
void handleMoved();
3538

39+
void initShaders();
40+
3641
static Renderer &getInstance() {
3742
static Renderer instance;
3843
return instance;
@@ -70,7 +75,7 @@ class Renderer {
7075
unsigned int framebuffer;
7176
unsigned int color_rb;
7277
unsigned int depth_rb;
73-
FTPixmapFont *font;
78+
FTPolygonFont* font;
7479
int width;
7580
int height;
7681
float frameRate;
@@ -82,8 +87,11 @@ class Renderer {
8287
GLdouble projectionMatrix[16];
8388
GLdouble modelviewMatrix[16];
8489
GLint viewport[4];
90+
Shader shader;
8591

8692
SDL_Window *window;
93+
glm::mat4 projection;
94+
glm::mat4 view;
8795
static HWND hwnd;
8896
Uint32 prevFrameTime;
8997
};

include/NavKit/render/Mesh.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#pragma once
2+
#include <string>
3+
#include <vector>
4+
#include <assimp/types.h>
5+
#include <glm/vec2.hpp>
6+
#include <glm/vec3.hpp>
7+
8+
#include "Shader.h"
9+
10+
struct Vertex {
11+
glm::vec3 Position;
12+
glm::vec3 Normal;
13+
glm::vec2 TexCoords;
14+
};
15+
16+
struct Texture {
17+
unsigned int id;
18+
std::string type;
19+
aiString path;
20+
};
21+
class Mesh {
22+
public:
23+
std::vector<Vertex> vertices;
24+
std::vector<unsigned int> indices;
25+
std::vector<Texture> textures;
26+
unsigned int VAO, VBO, EBO;
27+
glm::vec3 aabbMin;
28+
glm::vec3 aabbMax;
29+
30+
Mesh(const std::vector<Vertex>& vertices, const std::vector<unsigned int>& indices, const std::vector<Texture>& textures);
31+
32+
void draw(Shader& shader) const;
33+
34+
void setupMesh();
35+
};

include/NavKit/render/Model.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
#include "Mesh.h"
3+
#include <future>
4+
#include <assimp/scene.h>
5+
6+
struct SortContext {
7+
std::vector<unsigned int> drawOrder;
8+
std::future<std::vector<unsigned int>> sortFuture;
9+
};
10+
11+
class Model {
12+
public:
13+
std::vector<Mesh> meshes;
14+
void initGL();
15+
16+
static std::map<const Model*, SortContext> sortContexts;
17+
18+
static Mesh processBatchedMeshes(const std::vector<aiMesh*>& batch);
19+
20+
void loadModelData(std::string const& path);
21+
22+
void draw(Shader& shader, const glm::mat4& viewProj) const;
23+
};

include/NavKit/render/Shader.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <sstream>
5+
#include <glm/fwd.hpp>
6+
7+
class Shader {
8+
public:
9+
unsigned int ID;
10+
11+
Shader();
12+
13+
void loadShaders(const char* vertexPath, const char* fragmentPath);
14+
15+
void use() const;
16+
17+
void setBool(const std::string& name, bool value) const;
18+
19+
void setInt(const std::string& name, int value) const;
20+
21+
void setFloat(const std::string& name, float value) const;
22+
23+
void setVec4(const std::string& name, const glm::vec4& value) const;
24+
25+
void setMat3(const std::string& name, const glm::mat3& mat) const;
26+
27+
void setMat4(const std::string& name, const glm::mat4& mat) const;
28+
};

0 commit comments

Comments
 (0)