Compare commits

..

2 Commits

Author SHA1 Message Date
Attila Uygun 0a78316bce warnings 2023-08-12 21:22:54 +02:00
Attila Uygun f372fbed8e tmp 2023-08-12 20:25:02 +02:00
12 changed files with 137 additions and 63 deletions

View File

@ -164,6 +164,14 @@ config("release") {
} }
} }
config("third_party_warnings") {
if (is_win) {
cflags = [
"/wd4242", # tmp:conversion from 'int' to 'uint8_t'
]
}
}
config("warnings") { config("warnings") {
if (is_win) { if (is_win) {
cflags = [ cflags = [
@ -187,51 +195,50 @@ config("warnings") {
# switch specified. # switch specified.
# TODO: Not sure how I feel about these conversion warnings. # TODO: Not sure how I feel about these conversion warnings.
"/Wv:18", # tmp "/Wv:18",
"/wd4191", # tmp:'type cast': unsafe conversion "/wd4191", # 'type cast': unsafe conversion
"/wd4242", # tmp:conversion from 'int' to 'uint8_t'
"/wd4245", # tmp:conversion from 'int' to 'const unsigned int'
"/wd4244", # conversion, possible loss of data. 'int' to 'float' "/wd4244", # conversion, possible loss of data. 'int' to 'float'
"/wd4267", # conversion, possible loss of data. "/wd4245", # tmp:conversion from 'int' to 'const unsigned int'
# "/wd4267", # conversion, possible loss of data.
"/wd4305", # truncation from 'double' to 'float'. "/wd4305", # truncation from 'double' to 'float'.
"/wd4365", # conversion, signed/unsigned mismatch. "/wd4365", # conversion, signed/unsigned mismatch.
"/wd5219", # conversion, possible loss of data. 'int' to 'float' # "/wd5219", # conversion, possible loss of data. 'int' to 'float'
# Possible compiler bug? Needs investigation. # Possible compiler bug? Needs investigation.
"/wd4668", # '__STDC_WANT_SECURE_LIB__' is not defined as a preprocessor "/wd4668", # '__STDC_WANT_SECURE_LIB__' is not defined as a preprocessor
# macro, replacing with '0' for '#if/#elif' # macro, replacing with '0' for '#if/#elif'
# TODO: # TODO:
"/wd4263", # member function does not override any base class virtual # "/wd4263", # member function does not override any base class virtual
# member function # member function
"/wd4264", # no override available for virtual member function, function # "/wd4264", # no override available for virtual member function, function
# is hidden # is hidden
"/wd4266", # no override available for virtual member function from base, # "/wd4266", # no override available for virtual member function from base,
# function is hidden # function is hidden
"/wd4355", # 'this' used in base member initializer list # "/wd4355", # 'this' used in base member initializer list
"/wd4457", # declaration hides function parameter # "/wd4457", # declaration hides function parameter
"/wd4464", # relative include path contains '..'. # "/wd4464", # relative include path contains '..'.
"/wd4625", # copy constructor was implicitly defined as deleted "/wd4625", # copy constructor was implicitly defined as deleted
"/wd4626", # assignment operator was implicitly defined as deleted "/wd4626", # assignment operator was implicitly defined as deleted
"/wd4706", # assignment withing conditional expression. # "/wd4706", # assignment withing conditional expression.
"/wd4774", # format string expected in argument X is not a string literal # "/wd4774", # format string expected in argument X is not a string literal
"/wd4828", # The file contains a character that is illegal in the current # "/wd4828", # The file contains a character that is illegal in the current
# source character set # source character set
"/wd4946", # reinterpret_cast used between related # "/wd4946", # reinterpret_cast used between related
"/wd5026", # move constructor was implicitly defined as deleted # "/wd5026", # move constructor was implicitly defined as deleted
"/wd5027", # move assignment operator was implicitly defined as deleted # "/wd5027", # move assignment operator was implicitly defined as deleted
"/wd5039", # pointer or reference to potentially throwing function passed # "/wd5039", # pointer or reference to potentially throwing function passed
# to 'extern "C"' function under -EHc. Undefined behavior may # to 'extern "C"' function under -EHc. Undefined behavior may
# occur if this function throws an exception. # occur if this function throws an exception.
# TODO: I don't understand these or how to fix them: # TODO: I don't understand these or how to fix them:
"/wd4458", # declaration hides class member # "/wd4458", # declaration hides class member
# [ GameObject::rtti ] # [ GameObject::rtti ]
"/wd4582", # constructor is not implicitly called # "/wd4582", # constructor is not implicitly called
# [ intersection.h Contact ] # [ intersection.h Contact ]
"/wd4623", # default constructor was implicitly defined as deleted # "/wd4623", # default constructor was implicitly defined as deleted
# [ intersection.h Contact ] # [ intersection.h Contact ]
"/wd5243", # using incomplete class can cause potential one definition # "/wd5243", # using incomplete class can cause potential one definition
# rule violation due to ABI limitation # rule violation due to ABI limitation
] ]

View File

@ -61,11 +61,16 @@ source_set("engine") {
libs = [] libs = []
if (target_os == "linux" || target_os == "win") {
sources += [
"platform/asset_file_generic.cc",
]
}
if (target_os == "linux") { if (target_os == "linux") {
sources += [ sources += [
"audio/audio_sink_alsa.cc", "audio/audio_sink_alsa.cc",
"audio/audio_sink_alsa.h", "audio/audio_sink_alsa.h",
"platform/asset_file_generic.cc",
"platform/platform_linux.cc", "platform/platform_linux.cc",
"renderer/opengl/renderer_opengl_linux.cc", "renderer/opengl/renderer_opengl_linux.cc",
"renderer/vulkan/renderer_vulkan_linux.cc", "renderer/vulkan/renderer_vulkan_linux.cc",
@ -82,7 +87,6 @@ source_set("engine") {
if (target_os == "win") { if (target_os == "win") {
sources += [ sources += [
"audio/audio_sink_null.h", "audio/audio_sink_null.h",
"platform/asset_file_generic.cc",
"platform/platform_win.cc", "platform/platform_win.cc",
"renderer/opengl/renderer_opengl_win.cc", "renderer/opengl/renderer_opengl_win.cc",
"renderer/vulkan/renderer_vulkan_win.cc", "renderer/vulkan/renderer_vulkan_win.cc",
@ -90,6 +94,7 @@ source_set("engine") {
] ]
libs = [ libs = [
"gdi32.lib", # Graphics
"user32.lib", # Win32 API core functionality. "user32.lib", # Win32 API core functionality.
"opengl32.lib", "opengl32.lib",
] ]

View File

@ -12,12 +12,7 @@
#include "third_party/texture_compressor/texture_compressor.h" #include "third_party/texture_compressor/texture_compressor.h"
// Use aligned memory for SIMD in texture compressor. // Use aligned memory for SIMD in texture compressor.
#define STB_IMAGE_IMPLEMENTATION
#define STBI_NO_STDIO #define STBI_NO_STDIO
#define STBI_MALLOC(sz) base::AlignedAlloc(sz, 16)
#define STBI_REALLOC_SIZED(p, oldsz, newsz) \
base::AlignedRealloc(p, oldsz, newsz, 16)
#define STBI_FREE(p) base::AlignedFree(p)
#include "third_party/stb/stb_image.h" #include "third_party/stb/stb_image.h"
using namespace base; using namespace base;

View File

@ -3,11 +3,8 @@
#include <array> #include <array>
#include "base/log.h" #include "base/log.h"
#define MINIMP3_ONLY_MP3
#define MINIMP3_ONLY_SIMD
#define MINIMP3_FLOAT_OUTPUT #define MINIMP3_FLOAT_OUTPUT
#define MINIMP3_NO_STDIO #define MINIMP3_NO_STDIO
#define MINIMP3_IMPLEMENTATION
#include "engine/engine.h" #include "engine/engine.h"
#include "engine/platform/asset_file.h" #include "engine/platform/asset_file.h"
#include "third_party/minimp3/minimp3_ex.h" #include "third_party/minimp3/minimp3_ex.h"

View File

@ -27,8 +27,7 @@ AudioMixer::AudioMixer()
audio_sink_{std::make_unique<AudioSinkAlsa>(this)} { audio_sink_{std::make_unique<AudioSinkAlsa>(this)} {
#elif defined(_WIN32) #elif defined(_WIN32)
// TODO: Implement AudioSinkWindows // TODO: Implement AudioSinkWindows
audio_sink_{std::make_unique<AudioSinkNull>()}, audio_sink_{std::make_unique<AudioSinkNull>()} {
audio_enabled_(false) {
#endif #endif
bool res = audio_sink_->Initialize(); bool res = audio_sink_->Initialize();
CHECK(res) << "Failed to initialize audio sink."; CHECK(res) << "Failed to initialize audio sink.";

View File

@ -1,10 +1,5 @@
#include "engine/platform/platform.h" #include "engine/platform/platform.h"
// #include <limits.h>
// #include <stdio.h>
// #include <cstring>
// #include <memory>
//
#include "base/log.h" #include "base/log.h"
#include "base/vecmath.h" #include "base/vecmath.h"
#include "engine/input_event.h" #include "engine/input_event.h"
@ -122,28 +117,32 @@ LRESULT CALLBACK Platform::WndProc(HWND wnd,
platform->observer_->OnWindowDestroyed(); platform->observer_->OnWindowDestroyed();
PostQuitMessage(0); PostQuitMessage(0);
break; break;
case WM_ACTIVATEAPP:
case WM_MOUSEMOVE: { if (wparam == TRUE)
Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y); platform->observer_->GainedFocus(false);
auto input_event = else
std::make_unique<InputEvent>(InputEvent::kDrag, 0, v); platform->observer_->LostFocus();
platform->observer_->AddInputEvent(std::move(input_event)); break;
} break; case WM_MOUSEMOVE:
if (wparam == MK_LBUTTON) {
Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y);
auto input_event =
std::make_unique<InputEvent>(InputEvent::kDrag, 0, v);
platform->observer_->AddInputEvent(std::move(input_event));
}
break;
case WM_LBUTTONDOWN: { case WM_LBUTTONDOWN: {
Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y); Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y);
auto input_event = auto input_event =
std::make_unique<InputEvent>(InputEvent::kDragStart, 0, v); std::make_unique<InputEvent>(InputEvent::kDragStart, 0, v);
platform->observer_->AddInputEvent(std::move(input_event)); platform->observer_->AddInputEvent(std::move(input_event));
} break; } break;
case WM_LBUTTONUP: { case WM_LBUTTONUP: {
Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y); Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y);
auto input_event = auto input_event =
std::make_unique<InputEvent>(InputEvent::kDragEnd, 0, v); std::make_unique<InputEvent>(InputEvent::kDragEnd, 0, v);
platform->observer_->AddInputEvent(std::move(input_event)); platform->observer_->AddInputEvent(std::move(input_event));
} break; } break;
default: default:
return DefWindowProc(wnd, message, wparam, lparam); return DefWindowProc(wnd, message, wparam, lparam);
} }

View File

@ -7,26 +7,20 @@
// do not. // do not.
#include "third_party/android/gl3stub.h" #include "third_party/android/gl3stub.h"
#include <GLES2/gl2ext.h> #include <GLES2/gl2ext.h>
#elif defined(__linux__) #elif defined(__linux__)
#include "third_party/glew/glew.h" #include "third_party/glew/glew.h"
#include "third_party/glew/glxew.h" #include "third_party/glew/glxew.h"
// Define the missing format for the etc1
#ifndef GL_ETC1_RGB8_OES
#define GL_ETC1_RGB8_OES 0x8D64
#endif
#elif defined(_WIN32) #elif defined(_WIN32)
#define GLEW_STATIC #define GLEW_STATIC
#include "third_party/glew/glew.h" #include "third_party/glew/glew.h"
#include "third_party/glew/wglew.h" #include "third_party/glew/wglew.h"
#endif
#if defined(__linux__) || defined(_WIN32)
// Define the missing format for the etc1 // Define the missing format for the etc1
#ifndef GL_ETC1_RGB8_OES #ifndef GL_ETC1_RGB8_OES
#define GL_ETC1_RGB8_OES 0x8D64 #define GL_ETC1_RGB8_OES 0x8D64
#endif #endif
#endif #endif
#endif // ENGINE_RENDERER_OPENGL_OPENGL_H #endif // ENGINE_RENDERER_OPENGL_OPENGL_H

View File

@ -122,11 +122,15 @@ class RendererOpenGL final : public Renderer {
int screen_height_ = 0; int screen_height_ = 0;
#if defined(__ANDROID__) #if defined(__ANDROID__)
ANativeWindow* window_; ANativeWindow* window_ = nullptr;
#elif defined(__linux__) #elif defined(__linux__)
Display* display_ = NULL; Display* display_ = NULL;
Window window_ = 0; Window window_ = 0;
GLXContext glx_context_ = NULL; GLXContext glx_context_ = NULL;
#elif defined(_WIN32)
HWND wnd_ = nullptr;
HDC dc_ = nullptr;
HGLRC glrc_ = nullptr;
#endif #endif
bool InitCommon(); bool InitCommon();

View File

@ -8,6 +8,49 @@ namespace eng {
bool RendererOpenGL::Initialize(Platform* platform) { bool RendererOpenGL::Initialize(Platform* platform) {
LOG(0) << "Initializing renderer."; LOG(0) << "Initializing renderer.";
wnd_ = platform->GetWindow();
dc_ = GetDC(wnd_);
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), 1,
PFD_DRAW_TO_WINDOW | // format must support window
PFD_SUPPORT_OPENGL | // format must support OpenGL
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32, // color depth
// Color bits ignored
0, 0, 0, 0, 0, 0,
0, // alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
// Accumulation bits ignored
0, 0, 0, 0,
24, // z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE,
0, // reserved
// layer masks ignored
0, 0, 0};
int pf = ChoosePixelFormat(dc_, &pfd);
if (pf == 0) {
LOG(0) << "ChoosePixelFormat failed.";
return false;
}
SetPixelFormat(dc_, pf, &pfd);
glrc_ = wglCreateContext(dc_);
wglMakeCurrent(dc_, glrc_);
if (GLEW_OK != glewInit()) {
LOG(0) << "Couldn't initialize OpenGL extension wrangler.";
return false;
}
RECT rect;
GetClientRect(platform->GetWindow(), &rect);
OnWindowResized(rect.right, rect.bottom);
return InitCommon(); return InitCommon();
} }
@ -16,9 +59,18 @@ void RendererOpenGL::OnDestroy() {}
void RendererOpenGL::Shutdown() { void RendererOpenGL::Shutdown() {
LOG(0) << "Shutting down renderer."; LOG(0) << "Shutting down renderer.";
is_initialized_ = false; is_initialized_ = false;
if (dc_ && glrc_) {
wglMakeCurrent(nullptr, nullptr);
wglDeleteContext(glrc_);
ReleaseDC(wnd_, dc_);
dc_ = nullptr;
glrc_ = nullptr;
}
} }
void RendererOpenGL::Present() { void RendererOpenGL::Present() {
SwapBuffers(dc_);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
active_shader_id_ = 0; active_shader_id_ = 0;
active_texture_id_ = 0; active_texture_id_ = 0;
fps_++; fps_++;

View File

@ -59,9 +59,11 @@ source_set("third_party") {
"glslang/glslang/MachineIndependent/reflection.cpp", "glslang/glslang/MachineIndependent/reflection.cpp",
"jsoncpp/json.h", "jsoncpp/json.h",
"jsoncpp/jsoncpp.cpp", "jsoncpp/jsoncpp.cpp",
"minimp3/minimp3.cc",
"minimp3/minimp3.h", "minimp3/minimp3.h",
"minimp3/minimp3_ex.h", "minimp3/minimp3_ex.h",
"spirv-reflect/spirv_reflect.c", "spirv-reflect/spirv_reflect.c",
"stb/stb_image.cc",
"stb/stb_image.h", "stb/stb_image.h",
"stb/stb_truetype.h", "stb/stb_truetype.h",
"texture_compressor/dxt_encoder.cc", "texture_compressor/dxt_encoder.cc",
@ -77,12 +79,17 @@ source_set("third_party") {
"volk/volk.c", "volk/volk.c",
] ]
defines = [ "VMA_STATIC_VULKAN_FUNCTIONS=1" ] defines = [ "VMA_STATIC_VULKAN_FUNCTIONS=1", "GLEW_STATIC" ]
if (target_os == "linux") { if (target_os == "linux" || target_os == "win") {
sources += [ sources += [
"glew/glew.c", "glew/glew.c",
"glew/glew.h", "glew/glew.h",
]
}
if (target_os == "linux") {
sources += [
"glew/glxew.h", "glew/glxew.h",
"glslang/glslang/OSDependent/Unix/ossource.cpp", "glslang/glslang/OSDependent/Unix/ossource.cpp",
] ]
@ -90,14 +97,13 @@ source_set("third_party") {
if (target_os == "win") { if (target_os == "win") {
sources += [ sources += [
"glew/glew.c",
"glew/glew.h",
"glew/wglew.h", "glew/wglew.h",
"glslang/glslang/OSDependent/Windows/ossource.cpp", "glslang/glslang/OSDependent/Windows/ossource.cpp",
] ]
} }
configs -= [ "//build:warnings" ] configs -= [ "//build:warnings" ]
configs += [ "//build:third_party_warnings" ]
deps = [] deps = []
} }

6
src/third_party/minimp3/minimp3.cc vendored Normal file
View File

@ -0,0 +1,6 @@
#define MINIMP3_ONLY_MP3
#define MINIMP3_ONLY_SIMD
#define MINIMP3_FLOAT_OUTPUT
#define MINIMP3_NO_STDIO
#define MINIMP3_IMPLEMENTATION
#include "third_party/minimp3/minimp3_ex.h"

10
src/third_party/stb/stb_image.cc vendored Normal file
View File

@ -0,0 +1,10 @@
#include "base/mem.h"
// Use aligned memory for SIMD in texture compressor.
#define STB_IMAGE_IMPLEMENTATION
#define STBI_NO_STDIO
#define STBI_MALLOC(sz) base::AlignedAlloc(sz, 16)
#define STBI_REALLOC_SIZED(p, oldsz, newsz) \
base::AlignedRealloc(p, oldsz, newsz, 16)
#define STBI_FREE(p) base::AlignedFree(p)
#include "third_party/stb/stb_image.h"