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") {
if (is_win) {
cflags = [
@ -187,51 +195,50 @@ config("warnings") {
# switch specified.
# TODO: Not sure how I feel about these conversion warnings.
"/Wv:18", # tmp
"/wd4191", # tmp:'type cast': unsafe conversion
"/wd4242", # tmp:conversion from 'int' to 'uint8_t'
"/wd4245", # tmp:conversion from 'int' to 'const unsigned int'
"/Wv:18",
"/wd4191", # 'type cast': unsafe conversion
"/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'.
"/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.
"/wd4668", # '__STDC_WANT_SECURE_LIB__' is not defined as a preprocessor
# macro, replacing with '0' for '#if/#elif'
# TODO:
"/wd4263", # member function does not override any base class virtual
# "/wd4263", # member function does not override any base class virtual
# member function
"/wd4264", # no override available for virtual member function, function
# "/wd4264", # no override available for virtual member function, function
# 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
"/wd4355", # 'this' used in base member initializer list
"/wd4457", # declaration hides function parameter
"/wd4464", # relative include path contains '..'.
# "/wd4355", # 'this' used in base member initializer list
# "/wd4457", # declaration hides function parameter
# "/wd4464", # relative include path contains '..'.
"/wd4625", # copy constructor was implicitly defined as deleted
"/wd4626", # assignment operator was implicitly defined as deleted
"/wd4706", # assignment withing conditional expression.
"/wd4774", # format string expected in argument X is not a string literal
"/wd4828", # The file contains a character that is illegal in the current
# "/wd4706", # assignment withing conditional expression.
# "/wd4774", # format string expected in argument X is not a string literal
# "/wd4828", # The file contains a character that is illegal in the current
# source character set
"/wd4946", # reinterpret_cast used between related
"/wd5026", # move constructor was implicitly defined as deleted
"/wd5027", # move assignment operator was implicitly defined as deleted
"/wd5039", # pointer or reference to potentially throwing function passed
# "/wd4946", # reinterpret_cast used between related
# "/wd5026", # move constructor was implicitly defined as deleted
# "/wd5027", # move assignment operator was implicitly defined as deleted
# "/wd5039", # pointer or reference to potentially throwing function passed
# to 'extern "C"' function under -EHc. Undefined behavior may
# occur if this function throws an exception.
# TODO: I don't understand these or how to fix them:
"/wd4458", # declaration hides class member
# "/wd4458", # declaration hides class member
# [ GameObject::rtti ]
"/wd4582", # constructor is not implicitly called
# "/wd4582", # constructor is not implicitly called
# [ intersection.h Contact ]
"/wd4623", # default constructor was implicitly defined as deleted
# "/wd4623", # default constructor was implicitly defined as deleted
# [ 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
]

View File

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

View File

@ -12,12 +12,7 @@
#include "third_party/texture_compressor/texture_compressor.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"
using namespace base;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,6 +8,49 @@ namespace eng {
bool RendererOpenGL::Initialize(Platform* platform) {
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();
}
@ -16,9 +59,18 @@ void RendererOpenGL::OnDestroy() {}
void RendererOpenGL::Shutdown() {
LOG(0) << "Shutting down renderer.";
is_initialized_ = false;
if (dc_ && glrc_) {
wglMakeCurrent(nullptr, nullptr);
wglDeleteContext(glrc_);
ReleaseDC(wnd_, dc_);
dc_ = nullptr;
glrc_ = nullptr;
}
}
void RendererOpenGL::Present() {
SwapBuffers(dc_);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
active_shader_id_ = 0;
active_texture_id_ = 0;
fps_++;

View File

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