mirror of https://github.com/auygun/kaliber.git
Compare commits
5 Commits
5ca5ed763a
...
daa3a8c06f
Author | SHA1 | Date |
---|---|---|
Attila Uygun | daa3a8c06f | |
Attila Uygun | 449ac3f386 | |
Attila Uygun | beba055645 | |
Attila Uygun | 0a2f1bd7c3 | |
Attila Uygun | 58cc270e24 |
|
@ -26,3 +26,4 @@ cd build/android
|
|||
[spirv-reflect](https://github.com/KhronosGroup/SPIRV-Reflect),
|
||||
[vma](https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator),
|
||||
[vulkan-sdk](https://vulkan.lunarg.com)
|
||||
[volk](https://github.com/zeux/volk)
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
#ifdef GL_ES
|
||||
precision highp float;
|
||||
#else
|
||||
#define lowp
|
||||
#define mediump
|
||||
#define highp
|
||||
#endif
|
||||
|
||||
IN(0) vec2 tex_coord_0;
|
||||
|
@ -17,19 +13,25 @@ UNIFORM_END
|
|||
|
||||
FRAG_COLOR_OUT(frag_color)
|
||||
|
||||
const float PHI = 1.61803398874989484820459; // Golden Ratio
|
||||
|
||||
float random(vec2 p) {
|
||||
float sd = sin(dot(p, vec2(54.90898, 18.233)));
|
||||
return fract(sd * 2671.6182);
|
||||
}
|
||||
|
||||
float random2(in vec2 xy) {
|
||||
return fract(tan(distance(xy * PHI, xy)) * (xy.x + 0.1));
|
||||
}
|
||||
|
||||
float nebula(in vec2 p) {
|
||||
vec2 i = floor(p);
|
||||
vec2 f = fract(p);
|
||||
|
||||
float a = random(i);
|
||||
float b = random(i + vec2(1.0, 0.0));
|
||||
float c = random(i + vec2(0.0, 1.0));
|
||||
float d = random(i + vec2(1.0, 1.0));
|
||||
float a = random2(i);
|
||||
float b = random2(i + vec2(1.0, 0.0));
|
||||
float c = random2(i + vec2(0.0, 1.0));
|
||||
float d = random2(i + vec2(1.0, 1.0));
|
||||
|
||||
vec2 u = smoothstep(0.0, 1.0, f);
|
||||
|
||||
|
@ -52,7 +54,7 @@ float stars(in vec2 p, float num_cells, float size) {
|
|||
void main() {
|
||||
vec2 layer1_coord = tex_coord_0 + PARAM(sky_offset);
|
||||
vec2 layer2_coord = tex_coord_0 + PARAM(sky_offset) * 0.7;
|
||||
mediump vec3 result = vec3(0.);
|
||||
vec3 result = vec3(0.);
|
||||
|
||||
float c = nebula(layer2_coord * 3.0) * 0.35 - 0.05;
|
||||
result += PARAM(nebula_color) * floor(c * 60.0) / 60.0;
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
#ifdef GL_ES
|
||||
precision highp float;
|
||||
#else
|
||||
#define lowp
|
||||
#define mediump
|
||||
#define highp
|
||||
#endif
|
||||
|
||||
IN(0) vec2 tex_coord_0;
|
||||
|
@ -35,7 +31,7 @@ float stars(in vec2 p, float num_cells, float size) {
|
|||
void main() {
|
||||
vec2 layer1_coord = tex_coord_0 + PARAM(sky_offset);
|
||||
vec2 layer2_coord = tex_coord_0 + PARAM(sky_offset) * 0.7;
|
||||
mediump vec3 result = vec3(0.);
|
||||
vec3 result = vec3(0.);
|
||||
|
||||
float c = stars(layer1_coord, 8.0, 0.05);
|
||||
result += vec3(0.97, 0.74, 0.74) * c;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:versionCode="16"
|
||||
android:versionName="1.0.1">
|
||||
android:versionCode="17"
|
||||
android:versionName="1.0.2">
|
||||
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
|
|
|
@ -447,9 +447,9 @@ void Demo::StartNextStage(bool boss) {
|
|||
Vector4f c = {Lerp(0.75f, 0.95f, rnd.Rand()) * weights[0],
|
||||
Lerp(0.75f, 0.95f, rnd.Rand()) * weights[1],
|
||||
Lerp(0.75f, 0.95f, rnd.Rand()) * weights[2], 1};
|
||||
c += {Lerp(0.1f, 0.5f, rnd.Rand()) * (1 - weights[0]),
|
||||
Lerp(0.1f, 0.5f, rnd.Rand()) * (1 - weights[1]),
|
||||
Lerp(0.1f, 0.5f, rnd.Rand()) * (1 - weights[2]), 1};
|
||||
c += {Lerp(0.1f, 0.7f, rnd.Rand()) * (1 - weights[0]),
|
||||
Lerp(0.1f, 0.7f, rnd.Rand()) * (1 - weights[1]),
|
||||
Lerp(0.1f, 0.7f, rnd.Rand()) * (1 - weights[2]), 1};
|
||||
sky_.SwitchColor(c);
|
||||
|
||||
++wave_;
|
||||
|
@ -457,9 +457,9 @@ void Demo::StartNextStage(bool boss) {
|
|||
hud_.SetProgress(1);
|
||||
|
||||
if (boss_fight_)
|
||||
player_.TakeDamage(-3);
|
||||
player_.TakeDamage(-1);
|
||||
|
||||
total_enemies_ = 20.0f + 23.0897f * log((float)wave_);
|
||||
total_enemies_ = 23.0897f * log((float)wave_ + 1.0f) - 10.0f;
|
||||
last_num_enemies_killed_ = 0;
|
||||
boss_fight_ = false;
|
||||
DLOG << "wave: " << wave_ << " total_enemies_: " << total_enemies_;
|
||||
|
@ -489,6 +489,7 @@ void Demo::Dimmer(bool enable) {
|
|||
dimmer_.SetColor(kBgColor * Vector4f(0, 0, 0, 0));
|
||||
dimmer_animator_.SetBlending(kBgColor, kFadeSpeed);
|
||||
dimmer_animator_.Play(Animator::kBlending, false);
|
||||
dimmer_animator_.SetEndCallback(Animator::kBlending, nullptr);
|
||||
dimmer_animator_.SetVisible(true);
|
||||
} else if (!enable && dimmer_active_) {
|
||||
dimmer_active_ = false;
|
||||
|
|
|
@ -18,20 +18,20 @@
|
|||
|
||||
// #define LOAD_TEST
|
||||
|
||||
class Demo : public eng::Game {
|
||||
class Demo final : public eng::Game {
|
||||
public:
|
||||
Demo();
|
||||
~Demo() override;
|
||||
~Demo() final;
|
||||
|
||||
bool Initialize() override;
|
||||
bool Initialize() final;
|
||||
|
||||
void Update(float delta_time) override;
|
||||
void Update(float delta_time) final;
|
||||
|
||||
void ContextLost() override;
|
||||
void ContextLost() final;
|
||||
|
||||
void LostFocus() override;
|
||||
void LostFocus() final;
|
||||
|
||||
void GainedFocus(bool from_interstitial_ad) override;
|
||||
void GainedFocus(bool from_interstitial_ad) final;
|
||||
|
||||
void AddScore(size_t score);
|
||||
|
||||
|
|
|
@ -148,7 +148,8 @@ void Enemy::Update(float delta_time) {
|
|||
|
||||
if (it->chromatic_aberration_active_) {
|
||||
it->sprite.SetCustomUniform(
|
||||
"aberration_offset", Lerp(0.0f, 0.01f, chromatic_aberration_offset_));
|
||||
"aberration_offset",
|
||||
Lerp(0.0f, 0.015f, chromatic_aberration_offset_));
|
||||
}
|
||||
#if defined(LOAD_TEST)
|
||||
else if (it->kill_timer <= 0 &&
|
||||
|
@ -406,6 +407,8 @@ bool Enemy::IsBossAlive() const {
|
|||
}
|
||||
|
||||
void Enemy::PauseProgress() {
|
||||
DeselectTarget(kDamageType_Green);
|
||||
DeselectTarget(kDamageType_Blue);
|
||||
progress_paused_ = true;
|
||||
}
|
||||
|
||||
|
@ -784,8 +787,7 @@ void Enemy::SpawnBoss() {
|
|||
auto& e = enemies_.emplace_front();
|
||||
e.enemy_type = kEnemyType_Boss;
|
||||
e.damage_type = kDamageType_Any;
|
||||
e.total_health = e.hit_points =
|
||||
-15.0845f + 41.1283f * log((float)game->wave());
|
||||
e.total_health = e.hit_points = 41.1283f * log((float)game->wave()) - 20.0f;
|
||||
DLOG << " Boss health: " << e.total_health;
|
||||
|
||||
Vector2f hit_box_pos =
|
||||
|
@ -1080,7 +1082,7 @@ void Enemy::UpdateWave(float delta_time) {
|
|||
SpawnUnit(kEnemyType_PowerUp, kDamageType_Any, pos, 6);
|
||||
}
|
||||
seconds_since_last_power_up_ = 0;
|
||||
seconds_to_next_power_up_ = Lerp(1.3f * 60.0f, 1.8f * 60.0f, rnd.Rand());
|
||||
seconds_to_next_power_up_ = Lerp(60.0f, 80.0f, rnd.Rand());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1100,9 +1102,6 @@ void Enemy::UpdateBoss(float delta_time) {
|
|||
if (boss_spawn_factor < 0.1f)
|
||||
boss_spawn_factor = 0.1f;
|
||||
|
||||
DLOG << "boss_spawn_time_: " << boss_spawn_time_
|
||||
<< " boss_spawn_factor: " << boss_spawn_factor;
|
||||
|
||||
EnemyType enemy_type = kEnemyType_Invalid;
|
||||
|
||||
for (int i = 0; i < kEnemyType_Unit_Last + 1; ++i) {
|
||||
|
|
|
@ -22,7 +22,7 @@ using namespace eng;
|
|||
|
||||
namespace {
|
||||
|
||||
constexpr char kVersionStr[] = "Version 1.0.1";
|
||||
constexpr char kVersionStr[] = "Version 1.0.2";
|
||||
|
||||
constexpr char kMenuOption[Menu::kOption_Max][10] = {"continue", "start",
|
||||
"credits", "exit"};
|
||||
|
@ -81,6 +81,11 @@ bool Menu::Initialize() {
|
|||
|
||||
items_[i].select_item_cb_ = [&, i]() -> void {
|
||||
items_[i].text_animator.SetEndCallback(Animator::kBlending, nullptr);
|
||||
// Wait until click sound ends before exiting.
|
||||
if (i == kExit)
|
||||
click_.SetEndCallback(
|
||||
[&, i]() -> void { selected_option_ = (Option)i; });
|
||||
else
|
||||
selected_option_ = (Option)i;
|
||||
};
|
||||
items_[i].text_animator.Attach(&items_[i].text);
|
||||
|
|
|
@ -288,7 +288,7 @@ void Player::SetupWeapons() {
|
|||
|
||||
weapon_[i].SetFrame(wepon_warmup_frame[i]);
|
||||
warmup_animator_[i].SetFrames(wepon_warmup_frame_count, wepon_anim_speed);
|
||||
warmup_animator_[i].SetRotation(M_PI * 2, 8.0f);
|
||||
warmup_animator_[i].SetRotation(M_PI * 2, 20.0f);
|
||||
warmup_animator_[i].Attach(&weapon_[i]);
|
||||
warmup_animator_[i].Play(Animator::kRotation, true);
|
||||
|
||||
|
|
|
@ -27,14 +27,14 @@ class SkyQuad : public eng::Animatable {
|
|||
void Update(float delta_time);
|
||||
|
||||
// Animatable interface.
|
||||
void SetFrame(size_t frame) override {}
|
||||
size_t GetFrame() const override { return 0; }
|
||||
size_t GetNumFrames() const override { return 0; }
|
||||
void SetColor(const base::Vector4f& color) override { nebula_color_ = color; }
|
||||
base::Vector4f GetColor() const override { return nebula_color_; }
|
||||
void SetFrame(size_t frame) final {}
|
||||
size_t GetFrame() const final { return 0; }
|
||||
size_t GetNumFrames() const final { return 0; }
|
||||
void SetColor(const base::Vector4f& color) final { nebula_color_ = color; }
|
||||
base::Vector4f GetColor() const final { return nebula_color_; }
|
||||
|
||||
// Drawable interface.
|
||||
void Draw(float frame_frac) override;
|
||||
void Draw(float frame_frac) final;
|
||||
|
||||
void ContextLost();
|
||||
|
||||
|
|
|
@ -180,9 +180,13 @@ void Animator::Update(float delta_time) {
|
|||
UpdateAnimTime(delta_time, kFrames, frame_speed_, frame_time_, frame_cb_);
|
||||
if (play_flags_ & kTimer)
|
||||
UpdateAnimTime(delta_time, kTimer, timer_speed_, timer_time_, timer_cb_);
|
||||
|
||||
did_evaluate_ = false;
|
||||
}
|
||||
|
||||
void Animator::Evaluate(float frame_frac_time) {
|
||||
did_evaluate_ = true;
|
||||
|
||||
Vector2f pos = {0, 0};
|
||||
if (play_flags_ & kMovement) {
|
||||
float time = movement_time_ + movement_speed_ * frame_frac_time;
|
||||
|
@ -248,6 +252,8 @@ void Animator::UpdateAnimTime(float delta_time,
|
|||
if (loop_flags_ & anim) {
|
||||
anim_time = fmod(anim_time, 1.0f);
|
||||
} else {
|
||||
if (!did_evaluate_)
|
||||
Evaluate(0);
|
||||
anim_time = 0;
|
||||
play_flags_ &= ~anim;
|
||||
if (cb) {
|
||||
|
|
|
@ -120,6 +120,8 @@ class Animator {
|
|||
base::Closure pending_cb_;
|
||||
Flags inside_cb_ = kNone;
|
||||
|
||||
bool did_evaluate_ = false;
|
||||
|
||||
void UpdateAnimTime(float delta_time,
|
||||
int anim,
|
||||
float anim_speed,
|
||||
|
|
|
@ -25,17 +25,17 @@ class AudioOboe : public AudioBase {
|
|||
int GetHardwareSampleRate();
|
||||
|
||||
private:
|
||||
class StreamCallback : public oboe::AudioStreamCallback {
|
||||
class StreamCallback final : public oboe::AudioStreamCallback {
|
||||
public:
|
||||
StreamCallback(AudioOboe* audio);
|
||||
~StreamCallback() override;
|
||||
~StreamCallback() final;
|
||||
|
||||
oboe::DataCallbackResult onAudioReady(oboe::AudioStream* oboe_stream,
|
||||
void* audio_data,
|
||||
int32_t num_frames) override;
|
||||
int32_t num_frames) final;
|
||||
|
||||
void onErrorAfterClose(oboe::AudioStream* oboe_stream,
|
||||
oboe::Result error) override;
|
||||
oboe::Result error) final;
|
||||
|
||||
private:
|
||||
AudioOboe* audio_;
|
||||
|
|
|
@ -222,31 +222,27 @@ void Engine::SetImageSource(const std::string& asset_name,
|
|||
void Engine::SetImageSource(const std::string& asset_name,
|
||||
CreateImageCB create_image,
|
||||
bool persistent) {
|
||||
Texture* texture;
|
||||
auto it = textures_.find(asset_name);
|
||||
if (it != textures_.end()) {
|
||||
texture = it->second.texture.get();
|
||||
it->second.create_image = create_image;
|
||||
it->second.persistent = persistent;
|
||||
} else {
|
||||
if (textures_.contains(asset_name) && textures_[asset_name].use_count > 0) {
|
||||
DLOG << "Texture in use: " << asset_name;
|
||||
return;
|
||||
}
|
||||
|
||||
auto& t = textures_[asset_name] = {CreateRenderResource<Texture>(),
|
||||
create_image, persistent, 0};
|
||||
texture = t.texture.get();
|
||||
}
|
||||
|
||||
if (persistent) {
|
||||
auto image = create_image();
|
||||
if (image)
|
||||
texture->Update(std::move(image));
|
||||
else
|
||||
texture->Destroy();
|
||||
t.texture->Update(std::move(image));
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::RefreshImage(const std::string& asset_name) {
|
||||
auto it = textures_.find(asset_name);
|
||||
if (it == textures_.end())
|
||||
if (it == textures_.end()) {
|
||||
DLOG << "Texture not found: " << asset_name;
|
||||
return;
|
||||
}
|
||||
|
||||
auto image = it->second.create_image();
|
||||
if (image)
|
||||
|
@ -257,22 +253,23 @@ void Engine::RefreshImage(const std::string& asset_name) {
|
|||
|
||||
Texture* Engine::AcquireTexture(const std::string& asset_name) {
|
||||
auto it = textures_.find(asset_name);
|
||||
if (it != textures_.end()) {
|
||||
if (it == textures_.end()) {
|
||||
DLOG << "Texture not found: " << asset_name;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!it->second.texture->IsValid())
|
||||
RefreshImage(it->first);
|
||||
it->second.use_count++;
|
||||
return it->second.texture.get();
|
||||
}
|
||||
|
||||
auto& t = textures_[asset_name] = {CreateRenderResource<Texture>(), nullptr,
|
||||
false, 1};
|
||||
return t.texture.get();
|
||||
}
|
||||
|
||||
void Engine::ReleaseTexture(const std::string& asset_name) {
|
||||
auto it = textures_.find(asset_name);
|
||||
if (it == textures_.end())
|
||||
if (it == textures_.end()) {
|
||||
DLOG << "Texture not found: " << asset_name;
|
||||
return;
|
||||
}
|
||||
|
||||
DCHECK(it->second.use_count > 0);
|
||||
it->second.use_count--;
|
||||
|
@ -510,10 +507,7 @@ std::unique_ptr<Image> Engine::PrintStats() {
|
|||
line = "fps: ";
|
||||
line += std::to_string(fps_);
|
||||
lines.push_back(line);
|
||||
// line = "cmd: ";
|
||||
// line += std::to_string(renderer_->global_queue_size() +
|
||||
// renderer_->render_queue_size());
|
||||
// lines.push_back(line);
|
||||
lines.push_back(renderer_->GetDebugName());
|
||||
|
||||
constexpr int margin = 5;
|
||||
int line_height = system_font_->GetLineHeight();
|
||||
|
|
|
@ -38,14 +38,14 @@ class GameFactoryBase {
|
|||
};
|
||||
|
||||
template <typename Type>
|
||||
class GameFactory : public GameFactoryBase {
|
||||
class GameFactory final : public GameFactoryBase {
|
||||
public:
|
||||
~GameFactory() override = default;
|
||||
~GameFactory() final = default;
|
||||
|
||||
private:
|
||||
using GameType = Type;
|
||||
|
||||
std::unique_ptr<Game> CreateGame() override {
|
||||
std::unique_ptr<Game> CreateGame() final {
|
||||
return std::make_unique<GameType>();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
#include "base/interpolation.h"
|
||||
#include "base/log.h"
|
||||
#include "base/misc.h"
|
||||
#include "third_party/texture_compressor/texture_compressor.h"
|
||||
#include "engine/engine.h"
|
||||
#include "engine/platform/asset_file.h"
|
||||
#include "third_party/texture_compressor/texture_compressor.h"
|
||||
|
||||
// This 3rd party library is written in C and uses malloc, which means that we
|
||||
// have to do the same.
|
||||
|
|
|
@ -33,8 +33,10 @@ void ImageQuad::Create(const std::string& asset_name,
|
|||
}
|
||||
|
||||
void ImageQuad::Destory() {
|
||||
if (texture_) {
|
||||
Engine::Get().ReleaseTexture(asset_name_);
|
||||
texture_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageQuad::AutoScale() {
|
||||
|
|
|
@ -14,10 +14,10 @@ namespace eng {
|
|||
class Shader;
|
||||
class Texture;
|
||||
|
||||
class ImageQuad : public Animatable {
|
||||
class ImageQuad final : public Animatable {
|
||||
public:
|
||||
ImageQuad();
|
||||
~ImageQuad() override;
|
||||
~ImageQuad() final;
|
||||
|
||||
void Create(const std::string& asset_name,
|
||||
std::array<int, 2> num_frames = {1, 1},
|
||||
|
@ -36,14 +36,14 @@ class ImageQuad : public Animatable {
|
|||
}
|
||||
|
||||
// Animatable interface.
|
||||
void SetFrame(size_t frame) override;
|
||||
size_t GetFrame() const override { return current_frame_; }
|
||||
size_t GetNumFrames() const override;
|
||||
void SetColor(const base::Vector4f& color) override { color_ = color; }
|
||||
base::Vector4f GetColor() const override { return color_; }
|
||||
void SetFrame(size_t frame) final;
|
||||
size_t GetFrame() const final { return current_frame_; }
|
||||
size_t GetNumFrames() const final;
|
||||
void SetColor(const base::Vector4f& color) final { color_ = color; }
|
||||
base::Vector4f GetColor() const final { return color_; }
|
||||
|
||||
// Drawable interface.
|
||||
void Draw(float frame_frac) override;
|
||||
void Draw(float frame_frac) final;
|
||||
|
||||
private:
|
||||
using UniformValue = std::variant<base::Vector2f,
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "base/log.h"
|
||||
#include "third_party/jsoncpp/json.h"
|
||||
#include "engine/engine.h"
|
||||
#include "engine/platform/asset_file.h"
|
||||
#include "third_party/jsoncpp/json.h"
|
||||
|
||||
namespace eng {
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
#include "engine/renderer/opengl/renderer_opengl.h"
|
||||
#include "engine/renderer/vulkan/renderer_vulkan.h"
|
||||
|
||||
#define VULKAN_RENDERER
|
||||
|
||||
using namespace base;
|
||||
|
||||
namespace eng {
|
||||
|
@ -31,11 +29,13 @@ void Platform::InitializeCommon() {
|
|||
throw internal_error;
|
||||
}
|
||||
|
||||
#if defined(VULKAN_RENDERER)
|
||||
renderer_ = std::make_unique<RendererVulkan>();
|
||||
#else
|
||||
auto context = std::make_unique<VulkanContext>();
|
||||
if (context->Initialize()) {
|
||||
renderer_ = std::make_unique<RendererVulkan>(std::move(context));
|
||||
} else {
|
||||
LOG << "Failed to initialize Vulkan context. Fallback to OpenGL.";
|
||||
renderer_ = std::make_unique<RendererOpenGL>();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void Platform::ShutdownCommon() {
|
||||
|
|
|
@ -35,63 +35,62 @@ namespace eng {
|
|||
|
||||
struct RenderCommand;
|
||||
|
||||
class RendererOpenGL : public Renderer {
|
||||
class RendererOpenGL final : public Renderer {
|
||||
public:
|
||||
RendererOpenGL();
|
||||
~RendererOpenGL() override;
|
||||
~RendererOpenGL() final;
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
bool Initialize(ANativeWindow* window) override;
|
||||
bool Initialize(ANativeWindow* window) final;
|
||||
#elif defined(__linux__)
|
||||
bool Initialize(Display* display, Window window) override;
|
||||
bool Initialize(Display* display, Window window) final;
|
||||
#endif
|
||||
|
||||
void Shutdown() override;
|
||||
void Shutdown() final;
|
||||
|
||||
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) override;
|
||||
void DestroyGeometry(uint64_t resource_id) override;
|
||||
void Draw(uint64_t resource_id) override;
|
||||
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final;
|
||||
void DestroyGeometry(uint64_t resource_id) final;
|
||||
void Draw(uint64_t resource_id) final;
|
||||
|
||||
uint64_t CreateTexture() override;
|
||||
void UpdateTexture(uint64_t resource_id,
|
||||
std::unique_ptr<Image> image) override;
|
||||
void DestroyTexture(uint64_t resource_id) override;
|
||||
void ActivateTexture(uint64_t resource_id) override;
|
||||
uint64_t CreateTexture() final;
|
||||
void UpdateTexture(uint64_t resource_id, std::unique_ptr<Image> image) final;
|
||||
void DestroyTexture(uint64_t resource_id) final;
|
||||
void ActivateTexture(uint64_t resource_id) final;
|
||||
|
||||
uint64_t CreateShader(std::unique_ptr<ShaderSource> source,
|
||||
const VertexDescripton& vertex_description,
|
||||
Primitive primitive,
|
||||
bool enable_depth_test) override;
|
||||
void DestroyShader(uint64_t resource_id) override;
|
||||
void ActivateShader(uint64_t resource_id) override;
|
||||
bool enable_depth_test) final;
|
||||
void DestroyShader(uint64_t resource_id) final;
|
||||
void ActivateShader(uint64_t resource_id) final;
|
||||
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Vector2f& val) override;
|
||||
const base::Vector2f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Vector3f& val) override;
|
||||
const base::Vector3f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Vector4f& val) override;
|
||||
const base::Vector4f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Matrix4f& val) override;
|
||||
const base::Matrix4f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
float val) override;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
int val) override;
|
||||
void UploadUniforms(uint64_t resource_id) override {}
|
||||
float val) final;
|
||||
void SetUniform(uint64_t resource_id, const std::string& name, int val) final;
|
||||
void UploadUniforms(uint64_t resource_id) final {}
|
||||
|
||||
void PrepareForDrawing() override {}
|
||||
void Present() override;
|
||||
void PrepareForDrawing() final {}
|
||||
void Present() final;
|
||||
|
||||
size_t GetAndResetFPS() override;
|
||||
size_t GetAndResetFPS() final;
|
||||
|
||||
const char* GetDebugName() final { return "OpenGL"; }
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
XVisualInfo* GetXVisualInfo(Display* display) override;
|
||||
XVisualInfo* GetXVisualInfo(Display* display) final;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
|
|
@ -92,6 +92,8 @@ class Renderer {
|
|||
|
||||
virtual size_t GetAndResetFPS() = 0;
|
||||
|
||||
virtual const char* GetDebugName() = 0;
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
virtual XVisualInfo* GetXVisualInfo(Display* display) = 0;
|
||||
#endif
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "third_party/glslang/glslang/Include/Types.h"
|
||||
#include "third_party/glslang/glslang/Public/ShaderLang.h"
|
||||
#include "third_party/spirv-reflect/spirv_reflect.h"
|
||||
#include "third_party/vulkan/vk_enum_string_helper.h"
|
||||
|
||||
using namespace base;
|
||||
|
||||
|
@ -345,7 +346,7 @@ std::pair<int, int> GetBlockSizeForImageFormat(VkFormat format) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
NOTREACHED << "Invalid format: " << format;
|
||||
NOTREACHED << "Invalid format: " << string_VkFormat(format);
|
||||
return {0, 0};
|
||||
}
|
||||
|
||||
|
@ -361,7 +362,7 @@ std::pair<int, int> GetNumBlocksForImageFormat(VkFormat format,
|
|||
default:
|
||||
break;
|
||||
}
|
||||
NOTREACHED << "Invalid format: " << format;
|
||||
NOTREACHED << "Invalid format: " << string_VkFormat(format);
|
||||
return {width, height};
|
||||
}
|
||||
|
||||
|
@ -369,7 +370,8 @@ std::pair<int, int> GetNumBlocksForImageFormat(VkFormat format,
|
|||
|
||||
namespace eng {
|
||||
|
||||
RendererVulkan::RendererVulkan() = default;
|
||||
RendererVulkan::RendererVulkan(std::unique_ptr<VulkanContext> context)
|
||||
: context_{std::move(context)} {}
|
||||
|
||||
RendererVulkan::~RendererVulkan() = default;
|
||||
|
||||
|
@ -466,13 +468,13 @@ void RendererVulkan::UpdateTexture(uint64_t resource_id,
|
|||
(it->second.width != image->GetWidth() ||
|
||||
it->second.height != image->GetHeight())) {
|
||||
// Size mismatch. Recreate the texture.
|
||||
FreeTexture(std::move(it->second.image), it->second.view,
|
||||
FreeImage(std::move(it->second.image), it->second.view,
|
||||
std::move(it->second.desc_set));
|
||||
it->second = {};
|
||||
}
|
||||
|
||||
if (it->second.view == VK_NULL_HANDLE) {
|
||||
CreateTexture(it->second.image, it->second.view, it->second.desc_set,
|
||||
AllocateImage(it->second.image, it->second.view, it->second.desc_set,
|
||||
format, image->GetWidth(), image->GetHeight(),
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
VMA_MEMORY_USAGE_GPU_ONLY);
|
||||
|
@ -514,7 +516,7 @@ void RendererVulkan::DestroyTexture(uint64_t resource_id) {
|
|||
if (it == textures_.end())
|
||||
return;
|
||||
|
||||
FreeTexture(std::move(it->second.image), it->second.view,
|
||||
FreeImage(std::move(it->second.image), it->second.view,
|
||||
std::move(it->second.desc_set));
|
||||
textures_.erase(it);
|
||||
}
|
||||
|
@ -705,7 +707,7 @@ uint64_t RendererVulkan::CreateShader(
|
|||
pipeline_info.pDepthStencilState = &depth_stencil;
|
||||
pipeline_info.pDynamicState = &dynamic_state_create_info;
|
||||
pipeline_info.layout = shader.pipeline_layout;
|
||||
pipeline_info.renderPass = context_.GetRenderPass();
|
||||
pipeline_info.renderPass = context_->GetRenderPass();
|
||||
pipeline_info.subpass = 0;
|
||||
pipeline_info.basePipelineHandle = VK_NULL_HANDLE;
|
||||
|
||||
|
@ -826,7 +828,7 @@ void RendererVulkan::UploadUniforms(uint64_t resource_id) {
|
|||
}
|
||||
|
||||
void RendererVulkan::PrepareForDrawing() {
|
||||
context_.PrepareBuffers();
|
||||
context_->PrepareBuffers();
|
||||
DrawListBegin();
|
||||
}
|
||||
|
||||
|
@ -838,20 +840,20 @@ void RendererVulkan::Present() {
|
|||
bool RendererVulkan::InitializeInternal() {
|
||||
glslang::InitializeProcess();
|
||||
|
||||
device_ = context_.GetDevice();
|
||||
device_ = context_->GetDevice();
|
||||
|
||||
// Allocate one extra frame to ensure it's unused at any time without having
|
||||
// to use a fence.
|
||||
int frame_count = context_.GetSwapchainImageCount() + 1;
|
||||
int frame_count = context_->GetSwapchainImageCount() + 1;
|
||||
frames_.resize(frame_count);
|
||||
frames_drawn_ = frame_count;
|
||||
|
||||
// Initialize allocator
|
||||
VmaAllocatorCreateInfo allocator_info;
|
||||
memset(&allocator_info, 0, sizeof(VmaAllocatorCreateInfo));
|
||||
allocator_info.physicalDevice = context_.GetPhysicalDevice();
|
||||
allocator_info.physicalDevice = context_->GetPhysicalDevice();
|
||||
allocator_info.device = device_;
|
||||
allocator_info.instance = context_.GetInstance();
|
||||
allocator_info.instance = context_->GetInstance();
|
||||
vmaCreateAllocator(&allocator_info, &allocator_);
|
||||
|
||||
for (size_t i = 0; i < frames_.size(); i++) {
|
||||
|
@ -859,20 +861,20 @@ bool RendererVulkan::InitializeInternal() {
|
|||
VkCommandPoolCreateInfo cmd_pool_info;
|
||||
cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||
cmd_pool_info.pNext = nullptr;
|
||||
cmd_pool_info.queueFamilyIndex = context_.GetGraphicsQueue();
|
||||
cmd_pool_info.queueFamilyIndex = context_->GetGraphicsQueue();
|
||||
cmd_pool_info.flags = 0;
|
||||
|
||||
VkResult err = vkCreateCommandPool(device_, &cmd_pool_info, nullptr,
|
||||
&frames_[i].setup_command_pool);
|
||||
if (err) {
|
||||
DLOG << "vkCreateCommandPool failed with error " << std::to_string(err);
|
||||
DLOG << "vkCreateCommandPool failed with error " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
err = vkCreateCommandPool(device_, &cmd_pool_info, nullptr,
|
||||
&frames_[i].draw_command_pool);
|
||||
if (err) {
|
||||
DLOG << "vkCreateCommandPool failed with error " << std::to_string(err);
|
||||
DLOG << "vkCreateCommandPool failed with error " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -888,7 +890,7 @@ bool RendererVulkan::InitializeInternal() {
|
|||
&frames_[i].setup_command_buffer);
|
||||
if (err) {
|
||||
DLOG << "vkAllocateCommandBuffers failed with error "
|
||||
<< std::to_string(err);
|
||||
<< string_VkResult(err);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -897,7 +899,7 @@ bool RendererVulkan::InitializeInternal() {
|
|||
&frames_[i].draw_command_buffer);
|
||||
if (err) {
|
||||
DLOG << "vkAllocateCommandBuffers failed with error "
|
||||
<< std::to_string(err);
|
||||
<< string_VkResult(err);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -918,10 +920,10 @@ bool RendererVulkan::InitializeInternal() {
|
|||
ds_layout_info.bindingCount = 1;
|
||||
ds_layout_info.pBindings = &ds_layout_binding;
|
||||
|
||||
VkResult res = vkCreateDescriptorSetLayout(device_, &ds_layout_info, nullptr,
|
||||
VkResult err = vkCreateDescriptorSetLayout(device_, &ds_layout_info, nullptr,
|
||||
&descriptor_set_layout_);
|
||||
if (res) {
|
||||
DLOG << "Error (" << std::to_string(res)
|
||||
if (err) {
|
||||
DLOG << "Error (" << string_VkResult(err)
|
||||
<< ") creating descriptor set layout for set";
|
||||
return false;
|
||||
}
|
||||
|
@ -947,9 +949,9 @@ bool RendererVulkan::InitializeInternal() {
|
|||
sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
|
||||
sampler_info.unnormalizedCoordinates = VK_FALSE;
|
||||
|
||||
res = vkCreateSampler(device_, &sampler_info, nullptr, &sampler_);
|
||||
if (res) {
|
||||
DLOG << "vkCreateSampler failed with error " << std::to_string(res);
|
||||
err = vkCreateSampler(device_, &sampler_info, nullptr, &sampler_);
|
||||
if (err) {
|
||||
DLOG << "vkCreateSampler failed with error " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -971,7 +973,7 @@ bool RendererVulkan::InitializeInternal() {
|
|||
// Begin the first command buffer for the first frame.
|
||||
BeginFrame();
|
||||
|
||||
if (context_lost_cb_) {
|
||||
if (context_lost_ && context_lost_cb_) {
|
||||
LOG << "Context lost.";
|
||||
context_lost_cb_();
|
||||
}
|
||||
|
@ -984,6 +986,7 @@ void RendererVulkan::Shutdown() {
|
|||
|
||||
LOG << "Shutting down renderer.";
|
||||
DestroyAllResources();
|
||||
context_lost_ = true;
|
||||
|
||||
quit_.store(true, std::memory_order_relaxed);
|
||||
semaphore_.release();
|
||||
|
@ -1011,8 +1014,8 @@ void RendererVulkan::Shutdown() {
|
|||
current_staging_buffer_ = 0;
|
||||
staging_buffer_used_ = false;
|
||||
|
||||
context_.DestroyWindow();
|
||||
context_.Shutdown();
|
||||
context_->DestroyWindow();
|
||||
context_->Shutdown();
|
||||
|
||||
glslang::FinalizeProcess();
|
||||
}
|
||||
|
@ -1020,8 +1023,8 @@ void RendererVulkan::Shutdown() {
|
|||
void RendererVulkan::BeginFrame() {
|
||||
FreePendingResources(current_frame_);
|
||||
|
||||
context_.AppendCommandBuffer(frames_[current_frame_].setup_command_buffer);
|
||||
context_.AppendCommandBuffer(frames_[current_frame_].draw_command_buffer);
|
||||
context_->AppendCommandBuffer(frames_[current_frame_].setup_command_buffer);
|
||||
context_->AppendCommandBuffer(frames_[current_frame_].draw_command_buffer);
|
||||
|
||||
vkResetCommandPool(device_, frames_[current_frame_].setup_command_pool, 0);
|
||||
vkResetCommandPool(device_, frames_[current_frame_].draw_command_pool, 0);
|
||||
|
@ -1035,14 +1038,14 @@ void RendererVulkan::BeginFrame() {
|
|||
VkResult err = vkBeginCommandBuffer(
|
||||
frames_[current_frame_].setup_command_buffer, &cmdbuf_begin);
|
||||
if (err) {
|
||||
DLOG << "vkBeginCommandBuffer failed with error " << std::to_string(err);
|
||||
DLOG << "vkBeginCommandBuffer failed with error " << string_VkResult(err);
|
||||
return;
|
||||
}
|
||||
|
||||
err = vkBeginCommandBuffer(frames_[current_frame_].draw_command_buffer,
|
||||
&cmdbuf_begin);
|
||||
if (err) {
|
||||
DLOG << "vkBeginCommandBuffer failed with error " << std::to_string(err);
|
||||
DLOG << "vkBeginCommandBuffer failed with error " << string_VkResult(err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1060,7 +1063,7 @@ void RendererVulkan::BeginFrame() {
|
|||
void RendererVulkan::FlushSetupBuffer() {
|
||||
vkEndCommandBuffer(frames_[current_frame_].setup_command_buffer);
|
||||
|
||||
context_.Flush(false);
|
||||
context_->Flush(false);
|
||||
|
||||
vkResetCommandPool(device_, frames_[current_frame_].setup_command_pool, 0);
|
||||
|
||||
|
@ -1073,10 +1076,10 @@ void RendererVulkan::FlushSetupBuffer() {
|
|||
VkResult err = vkBeginCommandBuffer(
|
||||
frames_[current_frame_].setup_command_buffer, &cmdbuf_begin);
|
||||
if (err) {
|
||||
DLOG << "vkBeginCommandBuffer failed with error " << std::to_string(err);
|
||||
DLOG << "vkBeginCommandBuffer failed with error " << string_VkResult(err);
|
||||
return;
|
||||
}
|
||||
context_.AppendCommandBuffer(frames_[current_frame_].setup_command_buffer,
|
||||
context_->AppendCommandBuffer(frames_[current_frame_].setup_command_buffer,
|
||||
true);
|
||||
}
|
||||
|
||||
|
@ -1286,7 +1289,7 @@ bool RendererVulkan::InsertStagingBuffer() {
|
|||
&std::get<0>(block.buffer),
|
||||
&std::get<1>(block.buffer), &block.alloc_info);
|
||||
if (err) {
|
||||
DLOG << "vmaCreateBuffer failed with error " << std::to_string(err);
|
||||
DLOG << "vmaCreateBuffer failed with error " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1324,11 +1327,11 @@ RendererVulkan::DescPool* RendererVulkan::AllocateDescriptorPool() {
|
|||
descriptor_pool_create_info.pPoolSizes = &sizes;
|
||||
|
||||
VkDescriptorPool desc_pool;
|
||||
VkResult res = vkCreateDescriptorPool(device_, &descriptor_pool_create_info,
|
||||
VkResult err = vkCreateDescriptorPool(device_, &descriptor_pool_create_info,
|
||||
nullptr, &desc_pool);
|
||||
if (res) {
|
||||
if (err) {
|
||||
DLOG << "vkCreateDescriptorPool failed with error "
|
||||
<< std::to_string(res);
|
||||
<< string_VkResult(err);
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
|
@ -1384,7 +1387,7 @@ bool RendererVulkan::AllocateBuffer(Buffer<VkBuffer>& buffer,
|
|||
&vk_buffer, &allocation, nullptr);
|
||||
if (err) {
|
||||
DLOG << "Can't create buffer of size: " << std::to_string(size)
|
||||
<< ", error " << std::to_string(err);
|
||||
<< ", error " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1458,7 +1461,7 @@ void RendererVulkan::BufferMemoryBarrier(VkBuffer buffer,
|
|||
&buffer_mem_barrier, 0, nullptr);
|
||||
}
|
||||
|
||||
bool RendererVulkan::CreateTexture(Buffer<VkImage>& image,
|
||||
bool RendererVulkan::AllocateImage(Buffer<VkImage>& image,
|
||||
VkImageView& view,
|
||||
DescSet& desc_set,
|
||||
VkFormat format,
|
||||
|
@ -1500,7 +1503,7 @@ bool RendererVulkan::CreateTexture(Buffer<VkImage>& image,
|
|||
VkResult err = vmaCreateImage(allocator_, &image_create_info, &allocInfo,
|
||||
&vk_image, &allocation, nullptr);
|
||||
if (err) {
|
||||
DLOG << "vmaCreateImage failed with error " << std::to_string(err);
|
||||
DLOG << "vmaCreateImage failed with error " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1526,7 +1529,7 @@ bool RendererVulkan::CreateTexture(Buffer<VkImage>& image,
|
|||
|
||||
if (err) {
|
||||
vmaDestroyImage(allocator_, vk_image, allocation);
|
||||
DLOG << "vkCreateImageView failed with error " << std::to_string(err);
|
||||
DLOG << "vkCreateImageView failed with error " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1543,11 +1546,11 @@ bool RendererVulkan::CreateTexture(Buffer<VkImage>& image,
|
|||
descriptor_set_allocate_info.pSetLayouts = &descriptor_set_layout_;
|
||||
|
||||
VkDescriptorSet descriptor_set;
|
||||
VkResult res = vkAllocateDescriptorSets(
|
||||
device_, &descriptor_set_allocate_info, &descriptor_set);
|
||||
if (res) {
|
||||
err = vkAllocateDescriptorSets(device_, &descriptor_set_allocate_info,
|
||||
&descriptor_set);
|
||||
if (err) {
|
||||
--std::get<1>(*desc_pool);
|
||||
DLOG << "Cannot allocate descriptor sets, error " << std::to_string(res);
|
||||
DLOG << "Cannot allocate descriptor sets, error " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1575,7 +1578,7 @@ bool RendererVulkan::CreateTexture(Buffer<VkImage>& image,
|
|||
return true;
|
||||
}
|
||||
|
||||
void RendererVulkan::FreeTexture(Buffer<VkImage> image,
|
||||
void RendererVulkan::FreeImage(Buffer<VkImage> image,
|
||||
VkImageView image_view,
|
||||
DescSet desc_set) {
|
||||
frames_[current_frame_].images_to_destroy.push_back(
|
||||
|
@ -1904,8 +1907,8 @@ void RendererVulkan::DrawListBegin() {
|
|||
VkRenderPassBeginInfo render_pass_begin;
|
||||
render_pass_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||
render_pass_begin.pNext = nullptr;
|
||||
render_pass_begin.renderPass = context_.GetRenderPass();
|
||||
render_pass_begin.framebuffer = context_.GetFramebuffer();
|
||||
render_pass_begin.renderPass = context_->GetRenderPass();
|
||||
render_pass_begin.framebuffer = context_->GetFramebuffer();
|
||||
|
||||
render_pass_begin.renderArea.extent.width = screen_width_;
|
||||
render_pass_begin.renderArea.extent.height = screen_height_;
|
||||
|
@ -1971,7 +1974,7 @@ void RendererVulkan::SwapBuffers() {
|
|||
vkEndCommandBuffer(frames_[current_frame_].setup_command_buffer);
|
||||
vkEndCommandBuffer(frames_[current_frame_].draw_command_buffer);
|
||||
|
||||
context_.SwapBuffers();
|
||||
context_->SwapBuffers();
|
||||
current_frame_ = (current_frame_ + 1) % frames_.size();
|
||||
|
||||
active_pipeline_ = VK_NULL_HANDLE;
|
||||
|
@ -2030,13 +2033,13 @@ bool RendererVulkan::SetUniformInternal(ShaderVulkan& shader,
|
|||
|
||||
bool RendererVulkan::IsFormatSupported(VkFormat format) {
|
||||
VkFormatProperties properties;
|
||||
vkGetPhysicalDeviceFormatProperties(context_.GetPhysicalDevice(), format,
|
||||
vkGetPhysicalDeviceFormatProperties(context_->GetPhysicalDevice(), format,
|
||||
&properties);
|
||||
return properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
|
||||
}
|
||||
|
||||
size_t RendererVulkan::GetAndResetFPS() {
|
||||
return context_.GetAndResetFPS();
|
||||
return context_->GetAndResetFPS();
|
||||
}
|
||||
|
||||
void RendererVulkan::DestroyAllResources() {
|
||||
|
|
|
@ -20,63 +20,62 @@ namespace eng {
|
|||
|
||||
class Image;
|
||||
|
||||
class RendererVulkan : public Renderer {
|
||||
class RendererVulkan final : public Renderer {
|
||||
public:
|
||||
RendererVulkan();
|
||||
~RendererVulkan() override;
|
||||
RendererVulkan(std::unique_ptr<VulkanContext> context);
|
||||
~RendererVulkan() final;
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
bool Initialize(ANativeWindow* window) override;
|
||||
bool Initialize(ANativeWindow* window) final;
|
||||
#elif defined(__linux__)
|
||||
bool Initialize(Display* display, Window window) override;
|
||||
bool Initialize(Display* display, Window window) final;
|
||||
#endif
|
||||
|
||||
void Shutdown() override;
|
||||
void Shutdown() final;
|
||||
|
||||
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) override;
|
||||
void DestroyGeometry(uint64_t resource_id) override;
|
||||
void Draw(uint64_t resource_id) override;
|
||||
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final;
|
||||
void DestroyGeometry(uint64_t resource_id) final;
|
||||
void Draw(uint64_t resource_id) final;
|
||||
|
||||
uint64_t CreateTexture() override;
|
||||
void UpdateTexture(uint64_t resource_id,
|
||||
std::unique_ptr<Image> image) override;
|
||||
void DestroyTexture(uint64_t resource_id) override;
|
||||
void ActivateTexture(uint64_t resource_id) override;
|
||||
uint64_t CreateTexture() final;
|
||||
void UpdateTexture(uint64_t resource_id, std::unique_ptr<Image> image) final;
|
||||
void DestroyTexture(uint64_t resource_id) final;
|
||||
void ActivateTexture(uint64_t resource_id) final;
|
||||
|
||||
uint64_t CreateShader(std::unique_ptr<ShaderSource> source,
|
||||
const VertexDescripton& vertex_description,
|
||||
Primitive primitive,
|
||||
bool enable_depth_test) override;
|
||||
void DestroyShader(uint64_t resource_id) override;
|
||||
void ActivateShader(uint64_t resource_id) override;
|
||||
bool enable_depth_test) final;
|
||||
void DestroyShader(uint64_t resource_id) final;
|
||||
void ActivateShader(uint64_t resource_id) final;
|
||||
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Vector2f& val) override;
|
||||
const base::Vector2f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Vector3f& val) override;
|
||||
const base::Vector3f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Vector4f& val) override;
|
||||
const base::Vector4f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Matrix4f& val) override;
|
||||
const base::Matrix4f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
float val) override;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
int val) override;
|
||||
void UploadUniforms(uint64_t resource_id) override;
|
||||
float val) final;
|
||||
void SetUniform(uint64_t resource_id, const std::string& name, int val) final;
|
||||
void UploadUniforms(uint64_t resource_id) final;
|
||||
|
||||
void PrepareForDrawing() override;
|
||||
void Present() override;
|
||||
void PrepareForDrawing() final;
|
||||
void Present() final;
|
||||
|
||||
size_t GetAndResetFPS() override;
|
||||
size_t GetAndResetFPS() final;
|
||||
|
||||
const char* GetDebugName() final { return "Vulkan"; }
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
XVisualInfo* GetXVisualInfo(Display* display) override;
|
||||
XVisualInfo* GetXVisualInfo(Display* display) final;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
@ -155,7 +154,9 @@ class RendererVulkan : public Renderer {
|
|||
std::unordered_map<uint64_t, TextureVulkan> textures_;
|
||||
uint64_t last_resource_id_ = 0;
|
||||
|
||||
VulkanContext context_;
|
||||
bool context_lost_ = false;
|
||||
|
||||
std::unique_ptr<VulkanContext> context_;
|
||||
|
||||
VmaAllocator allocator_ = nullptr;
|
||||
|
||||
|
@ -224,7 +225,7 @@ class RendererVulkan : public Renderer {
|
|||
VkAccessFlags src_access,
|
||||
VkAccessFlags dst_sccess);
|
||||
|
||||
bool CreateTexture(Buffer<VkImage>& image,
|
||||
bool AllocateImage(Buffer<VkImage>& image,
|
||||
VkImageView& view,
|
||||
DescSet& desc_set,
|
||||
VkFormat format,
|
||||
|
@ -232,7 +233,7 @@ class RendererVulkan : public Renderer {
|
|||
int height,
|
||||
VkImageUsageFlags usage,
|
||||
VmaMemoryUsage mapping);
|
||||
void FreeTexture(Buffer<VkImage> image,
|
||||
void FreeImage(Buffer<VkImage> image,
|
||||
VkImageView image_view,
|
||||
DescSet desc_set);
|
||||
void UpdateImage(VkImage image,
|
||||
|
|
|
@ -12,11 +12,7 @@ bool RendererVulkan::Initialize(ANativeWindow* window) {
|
|||
screen_width_ = ANativeWindow_getWidth(window);
|
||||
screen_height_ = ANativeWindow_getHeight(window);
|
||||
|
||||
if (!context_.Initialize()) {
|
||||
LOG << "Failed to initialize Vulkan context.";
|
||||
return false;
|
||||
}
|
||||
if (!context_.CreateWindow(window, screen_width_, screen_height_)) {
|
||||
if (!context_->CreateWindow(window, screen_width_, screen_height_)) {
|
||||
LOG << "Vulkan context failed to create window.";
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -12,11 +12,7 @@ bool RendererVulkan::Initialize(Display* display, Window window) {
|
|||
screen_width_ = xwa.width;
|
||||
screen_height_ = xwa.height;
|
||||
|
||||
if (!context_.Initialize()) {
|
||||
LOG << "Failed to initialize Vulkan context.";
|
||||
return false;
|
||||
}
|
||||
if (!context_.CreateWindow(display, window, screen_width_, screen_height_)) {
|
||||
if (!context_->CreateWindow(display, window, screen_width_, screen_height_)) {
|
||||
LOG << "Vulkan context failed to create window.";
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,6 @@ void VulkanContext::Shutdown() {
|
|||
vkDestroyDevice(device_, nullptr);
|
||||
device_ = VK_NULL_HANDLE;
|
||||
}
|
||||
buffers_prepared_ = false;
|
||||
queues_initialized_ = false;
|
||||
separate_present_queue_ = false;
|
||||
swapchain_image_count_ = 0;
|
||||
|
@ -215,7 +214,8 @@ bool VulkanContext::CreateValidationLayers() {
|
|||
uint32_t instance_layer_count = 0;
|
||||
err = vkEnumerateInstanceLayerProperties(&instance_layer_count, nullptr);
|
||||
if (err) {
|
||||
DLOG << "vkEnumerateInstanceLayerProperties failed. Error: " << err;
|
||||
DLOG << "vkEnumerateInstanceLayerProperties failed. Error: "
|
||||
<< string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -228,7 +228,8 @@ bool VulkanContext::CreateValidationLayers() {
|
|||
err = vkEnumerateInstanceLayerProperties(&instance_layer_count,
|
||||
instance_layers.get());
|
||||
if (err) {
|
||||
DLOG << "vkEnumerateInstanceLayerProperties failed. Error: " << err;
|
||||
DLOG << "vkEnumerateInstanceLayerProperties failed. Error: "
|
||||
<< string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -284,7 +285,8 @@ bool VulkanContext::InitializeExtensions() {
|
|||
err = vkEnumerateInstanceExtensionProperties(
|
||||
nullptr, &instance_extension_count, nullptr);
|
||||
if (err) {
|
||||
DLOG << "vkEnumerateInstanceExtensionProperties failed. Error: " << err;
|
||||
DLOG << "vkEnumerateInstanceExtensionProperties failed. Error: "
|
||||
<< string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -294,7 +296,8 @@ bool VulkanContext::InitializeExtensions() {
|
|||
err = vkEnumerateInstanceExtensionProperties(
|
||||
nullptr, &instance_extension_count, instance_extensions.get());
|
||||
if (err) {
|
||||
DLOG << "vkEnumerateInstanceExtensionProperties failed. Error: " << err;
|
||||
DLOG << "vkEnumerateInstanceExtensionProperties failed. Error: "
|
||||
<< string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
for (uint32_t i = 0; i < instance_extension_count; i++) {
|
||||
|
@ -409,7 +412,7 @@ bool VulkanContext::CreatePhysicalDevice() {
|
|||
return false;
|
||||
}
|
||||
if (err) {
|
||||
DLOG << "vkCreateInstance failed. Error: " << err;
|
||||
DLOG << "vkCreateInstance failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -419,7 +422,8 @@ bool VulkanContext::CreatePhysicalDevice() {
|
|||
// Make initial call to query gpu_count.
|
||||
VkResult err = vkEnumeratePhysicalDevices(instance_, &gpu_count, nullptr);
|
||||
if (err) {
|
||||
DLOG << "vkEnumeratePhysicalDevices failed. Error: " << err;
|
||||
DLOG << "vkEnumeratePhysicalDevices failed. Error: "
|
||||
<< string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -432,7 +436,8 @@ bool VulkanContext::CreatePhysicalDevice() {
|
|||
err =
|
||||
vkEnumeratePhysicalDevices(instance_, &gpu_count, physical_devices.get());
|
||||
if (err) {
|
||||
DLOG << "vkEnumeratePhysicalDevices failed. Error: " << err;
|
||||
DLOG << "vkEnumeratePhysicalDevices failed. Error: "
|
||||
<< string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
// Grab the first physical device for now.
|
||||
|
@ -447,7 +452,8 @@ bool VulkanContext::CreatePhysicalDevice() {
|
|||
err = vkEnumerateDeviceExtensionProperties(gpu_, nullptr,
|
||||
&device_extension_count, nullptr);
|
||||
if (err) {
|
||||
DLOG << "vkEnumerateDeviceExtensionProperties failed. Error: " << err;
|
||||
DLOG << "vkEnumerateDeviceExtensionProperties failed. Error: "
|
||||
<< string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -457,7 +463,8 @@ bool VulkanContext::CreatePhysicalDevice() {
|
|||
err = vkEnumerateDeviceExtensionProperties(
|
||||
gpu_, nullptr, &device_extension_count, device_extensions.get());
|
||||
if (err) {
|
||||
DLOG << "vkEnumerateDeviceExtensionProperties failed. Error: " << err;
|
||||
DLOG << "vkEnumerateDeviceExtensionProperties failed. Error: "
|
||||
<< string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -601,7 +608,7 @@ bool VulkanContext::CreateDevice() {
|
|||
}
|
||||
err = vkCreateDevice(gpu_, &sdevice, nullptr, &device_);
|
||||
if (err) {
|
||||
DLOG << "vkCreateDevice failed. Error: " << err;
|
||||
DLOG << "vkCreateDevice failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -679,14 +686,16 @@ bool VulkanContext::InitializeQueues(VkSurfaceKHR surface) {
|
|||
VkResult err =
|
||||
GetPhysicalDeviceSurfaceFormatsKHR(gpu_, surface, &format_count, nullptr);
|
||||
if (err) {
|
||||
DLOG << "GetPhysicalDeviceSurfaceFormatsKHR failed. Error: " << err;
|
||||
DLOG << "GetPhysicalDeviceSurfaceFormatsKHR failed. Error: "
|
||||
<< string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
auto surf_formats = std::make_unique<VkSurfaceFormatKHR[]>(format_count);
|
||||
err = GetPhysicalDeviceSurfaceFormatsKHR(gpu_, surface, &format_count,
|
||||
surf_formats.get());
|
||||
if (err) {
|
||||
DLOG << "GetPhysicalDeviceSurfaceFormatsKHR failed. Error: " << err;
|
||||
DLOG << "GetPhysicalDeviceSurfaceFormatsKHR failed. Error: "
|
||||
<< string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -744,26 +753,26 @@ bool VulkanContext::CreateSemaphores() {
|
|||
for (uint32_t i = 0; i < kFrameLag; i++) {
|
||||
err = vkCreateFence(device_, &fence_ci, nullptr, &fences_[i]);
|
||||
if (err) {
|
||||
DLOG << "vkCreateFence failed. Error: " << err;
|
||||
DLOG << "vkCreateFence failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
err = vkCreateSemaphore(device_, &semaphoreCreateInfo, nullptr,
|
||||
&image_acquired_semaphores_[i]);
|
||||
if (err) {
|
||||
DLOG << "vkCreateSemaphore failed. Error: " << err;
|
||||
DLOG << "vkCreateSemaphore failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
err = vkCreateSemaphore(device_, &semaphoreCreateInfo, nullptr,
|
||||
&draw_complete_semaphores_[i]);
|
||||
if (err) {
|
||||
DLOG << "vkCreateSemaphore failed. Error: " << err;
|
||||
DLOG << "vkCreateSemaphore failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
if (separate_present_queue_) {
|
||||
err = vkCreateSemaphore(device_, &semaphoreCreateInfo, nullptr,
|
||||
&image_ownership_semaphores_[i]);
|
||||
if (err) {
|
||||
DLOG << "vkCreateSemaphore failed. Error: " << err;
|
||||
DLOG << "vkCreateSemaphore failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -788,10 +797,7 @@ void VulkanContext::DestroyWindow() {
|
|||
}
|
||||
|
||||
VkFramebuffer VulkanContext::GetFramebuffer() {
|
||||
return buffers_prepared_
|
||||
? window_.swapchain_image_resources[window_.current_buffer]
|
||||
.frame_buffer
|
||||
: VK_NULL_HANDLE;
|
||||
return window_.swapchain_image_resources[window_.current_buffer].frame_buffer;
|
||||
}
|
||||
|
||||
bool VulkanContext::CleanUpSwapChain(Window* window) {
|
||||
|
@ -838,7 +844,8 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
|
|||
err = GetPhysicalDeviceSurfaceCapabilitiesKHR(gpu_, window->surface,
|
||||
&surf_capabilities);
|
||||
if (err) {
|
||||
DLOG << "GetPhysicalDeviceSurfaceCapabilitiesKHR failed. Error: " << err;
|
||||
DLOG << "GetPhysicalDeviceSurfaceCapabilitiesKHR failed. Error: "
|
||||
<< string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -846,7 +853,8 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
|
|||
err = GetPhysicalDeviceSurfacePresentModesKHR(gpu_, window->surface,
|
||||
&present_mode_count, nullptr);
|
||||
if (err) {
|
||||
DLOG << "GetPhysicalDeviceSurfacePresentModesKHR failed. Error: " << err;
|
||||
DLOG << "GetPhysicalDeviceSurfacePresentModesKHR failed. Error: "
|
||||
<< string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -855,7 +863,8 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
|
|||
err = GetPhysicalDeviceSurfacePresentModesKHR(
|
||||
gpu_, window->surface, &present_mode_count, present_modes.get());
|
||||
if (err) {
|
||||
DLOG << "GetPhysicalDeviceSurfacePresentModesKHR failed. Error: " << err;
|
||||
DLOG << "GetPhysicalDeviceSurfacePresentModesKHR failed. Error: "
|
||||
<< string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1002,7 +1011,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
|
|||
|
||||
err = CreateSwapchainKHR(device_, &swapchain_ci, nullptr, &window->swapchain);
|
||||
if (err) {
|
||||
DLOG << "CreateSwapchainKHR failed. Error: " << err;
|
||||
DLOG << "CreateSwapchainKHR failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1010,7 +1019,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
|
|||
err = GetSwapchainImagesKHR(device_, window->swapchain, &sp_image_count,
|
||||
nullptr);
|
||||
if (err) {
|
||||
DLOG << "CreateSwapchainKHR failed. Error: " << err;
|
||||
DLOG << "CreateSwapchainKHR failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1027,7 +1036,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
|
|||
err = GetSwapchainImagesKHR(device_, window->swapchain,
|
||||
&swapchain_image_count_, swapchain_images.get());
|
||||
if (err) {
|
||||
DLOG << "GetSwapchainImagesKHR failed. Error: " << err;
|
||||
DLOG << "GetSwapchainImagesKHR failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1064,7 +1073,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
|
|||
err = vkCreateImageView(device_, &color_image_view, nullptr,
|
||||
&window->swapchain_image_resources[i].view);
|
||||
if (err) {
|
||||
DLOG << "vkCreateImageView failed. Error: " << err;
|
||||
DLOG << "vkCreateImageView failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1148,7 +1157,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
|
|||
|
||||
err = vkCreateRenderPass(device_, &rp_info, nullptr, &window->render_pass);
|
||||
if (err) {
|
||||
DLOG << "vkCreateRenderPass failed. Error: " << err;
|
||||
DLOG << "vkCreateRenderPass failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1173,7 +1182,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
|
|||
device_, &fb_info, nullptr,
|
||||
&window->swapchain_image_resources[i].frame_buffer);
|
||||
if (err) {
|
||||
DLOG << "vkCreateFramebuffer failed. Error: " << err;
|
||||
DLOG << "vkCreateFramebuffer failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1191,7 +1200,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
|
|||
err = vkCreateCommandPool(device_, &present_cmd_pool_info, nullptr,
|
||||
&window->present_cmd_pool);
|
||||
if (err) {
|
||||
DLOG << "vkCreateCommandPool failed. Error: " << err;
|
||||
DLOG << "vkCreateCommandPool failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1207,7 +1216,8 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
|
|||
device_, &present_cmd_info,
|
||||
&window->swapchain_image_resources[i].graphics_to_present_cmd);
|
||||
if (err) {
|
||||
DLOG << "vkAllocateCommandBuffers failed. Error: " << err;
|
||||
DLOG << "vkAllocateCommandBuffers failed. Error: "
|
||||
<< string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1221,7 +1231,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
|
|||
window->swapchain_image_resources[i].graphics_to_present_cmd,
|
||||
&cmd_buf_info);
|
||||
if (err) {
|
||||
DLOG << "vkBeginCommandBuffer failed. Error: " << err;
|
||||
DLOG << "vkBeginCommandBuffer failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1245,7 +1255,7 @@ bool VulkanContext::UpdateSwapChain(Window* window) {
|
|||
err = vkEndCommandBuffer(
|
||||
window->swapchain_image_resources[i].graphics_to_present_cmd);
|
||||
if (err) {
|
||||
DLOG << "vkEndCommandBuffer failed. Error: " << err;
|
||||
DLOG << "vkEndCommandBuffer failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1284,7 +1294,7 @@ bool VulkanContext::CreateDepthImage(Window* window) {
|
|||
VkResult err =
|
||||
vkCreateImage(device_, &depth_image_ci, nullptr, &window->depth_image);
|
||||
if (err) {
|
||||
DLOG << "vkCreateImage failed. Error: " << err;
|
||||
DLOG << "vkCreateImage failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1316,7 +1326,7 @@ bool VulkanContext::CreateDepthImage(Window* window) {
|
|||
err = vkAllocateMemory(device_, &alloc_info, nullptr,
|
||||
&window->depth_image_memory);
|
||||
if (err) {
|
||||
DLOG << "vkAllocateMemory failed. Error: " << err;
|
||||
DLOG << "vkAllocateMemory failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1386,7 +1396,7 @@ void VulkanContext::Flush(bool all) {
|
|||
vkQueueSubmit(graphics_queue_, 1, &submit_info, VK_NULL_HANDLE);
|
||||
command_buffers_[0] = nullptr;
|
||||
if (err) {
|
||||
DLOG << "vkQueueSubmit failed. Error: " << err;
|
||||
DLOG << "vkQueueSubmit failed. Error: " << string_VkResult(err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1421,23 +1431,20 @@ bool VulkanContext::PrepareBuffers() {
|
|||
if (err == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||
// swapchain is out of date (e.g. the window was resized) and must be
|
||||
// recreated:
|
||||
DLOG << "Swapchain is out of date.";
|
||||
DLOG << "Swapchain is out of date, recreating.";
|
||||
UpdateSwapChain(&window_);
|
||||
} else if (err == VK_SUBOPTIMAL_KHR) {
|
||||
DLOG << "Swapchain is suboptimal.";
|
||||
// swapchain is not as optimal as it could be, but the platform's
|
||||
// presentation engine will still present the image correctly.
|
||||
DLOG << "Swapchain is suboptimal, recreating.";
|
||||
UpdateSwapChain(&window_);
|
||||
break;
|
||||
} else {
|
||||
if (err) {
|
||||
DLOG << "AcquireNextImageKHR failed. Error: " << err;
|
||||
} else if (err != VK_SUCCESS) {
|
||||
DLOG << "AcquireNextImageKHR failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} while (err != VK_SUCCESS);
|
||||
|
||||
buffers_prepared_ = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1470,7 +1477,7 @@ bool VulkanContext::SwapBuffers() {
|
|||
submit_info.pSignalSemaphores = &draw_complete_semaphores_[frame_index_];
|
||||
err = vkQueueSubmit(graphics_queue_, 1, &submit_info, fences_[frame_index_]);
|
||||
if (err) {
|
||||
DLOG << "vkQueueSubmit failed. Error: " << err;
|
||||
DLOG << "vkQueueSubmit failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1501,7 +1508,7 @@ bool VulkanContext::SwapBuffers() {
|
|||
submit_info.pSignalSemaphores = &image_ownership_semaphores_[frame_index_];
|
||||
err = vkQueueSubmit(present_queue_, 1, &submit_info, null_fence);
|
||||
if (err) {
|
||||
DLOG << "vkQueueSubmit failed. Error: " << err;
|
||||
DLOG << "vkQueueSubmit failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1548,11 +1555,10 @@ bool VulkanContext::SwapBuffers() {
|
|||
// presentation engine will still present the image correctly.
|
||||
DLOG << "Swapchain is Suboptimal.";
|
||||
} else if (err) {
|
||||
DLOG << "QueuePresentKHR failed. Error: " << err;
|
||||
DLOG << "QueuePresentKHR failed. Error: " << string_VkResult(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
buffers_prepared_ = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,8 +96,6 @@ class VulkanContext {
|
|||
uint32_t queue_family_count_ = 0;
|
||||
std::unique_ptr<VkQueueFamilyProperties[]> queue_props_ = nullptr;
|
||||
|
||||
bool buffers_prepared_ = false;
|
||||
|
||||
bool queues_initialized_ = false;
|
||||
bool separate_present_queue_ = false;
|
||||
|
||||
|
|
|
@ -5,20 +5,20 @@
|
|||
|
||||
namespace eng {
|
||||
|
||||
class SolidQuad : public Animatable {
|
||||
class SolidQuad final : public Animatable {
|
||||
public:
|
||||
SolidQuad() = default;
|
||||
~SolidQuad() override = default;
|
||||
~SolidQuad() final = default;
|
||||
|
||||
// Animatable interface.
|
||||
void SetFrame(size_t frame) override {}
|
||||
size_t GetFrame() const override { return 0; }
|
||||
size_t GetNumFrames() const override { return 0; }
|
||||
void SetColor(const base::Vector4f& color) override { color_ = color; }
|
||||
base::Vector4f GetColor() const override { return color_; }
|
||||
void SetFrame(size_t frame) final {}
|
||||
size_t GetFrame() const final { return 0; }
|
||||
size_t GetNumFrames() const final { return 0; }
|
||||
void SetColor(const base::Vector4f& color) final { color_ = color; }
|
||||
base::Vector4f GetColor() const final { return color_; }
|
||||
|
||||
// Drawable interface.
|
||||
void Draw(float frame_frac) override;
|
||||
void Draw(float frame_frac) final;
|
||||
|
||||
private:
|
||||
base::Vector4f color_ = {1, 1, 1, 1};
|
||||
|
|
Loading…
Reference in New Issue