mouse picking
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
#ifndef OPENGL_FRAMEBUFFER_HPP
|
||||
#define OPENGL_FRAMEBUFFER_HPP
|
||||
|
||||
#include "core.hpp"
|
||||
#include <renderer/framebuffer.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace OpenEngine {
|
||||
class OpenGLFramebuffer : public FrameBuffer
|
||||
@@ -18,15 +20,24 @@ namespace OpenEngine {
|
||||
virtual void Unbind() override;
|
||||
|
||||
virtual void Resize(uint32_t width, uint32_t height) override;
|
||||
virtual int ReadPixel(uint32_t index, int x, int y) override;
|
||||
|
||||
virtual uint32_t GetColorAttachmentRendererID() const override { return color_attachment; }
|
||||
virtual uint32_t GetColorAttachmentRendererID(uint32_t index = 0) const override {
|
||||
OE_CORE_ASSERT(index < color_attachment_ids.size(), "Index is greater than color attachment count.");
|
||||
return color_attachment_ids[index];
|
||||
}
|
||||
|
||||
virtual const FramebufferSpecification& GetSpecification() const override { return specs; }
|
||||
|
||||
private:
|
||||
uint32_t id = 0;
|
||||
uint32_t color_attachment = 0, depth_attachment = 0;
|
||||
FramebufferSpecification specs;
|
||||
|
||||
std::vector<FramebufferTextureSpecification> color_attachment_specs;
|
||||
FramebufferTextureSpecification depth_attachment_specs = FramebufferTextureFormat::None;
|
||||
|
||||
std::vector<uint32_t> color_attachment_ids;
|
||||
uint32_t depth_attachment_id;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace OpenEngine {
|
||||
virtual void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) override;
|
||||
|
||||
virtual void SetClearColor(const glm::vec4& color) override;
|
||||
virtual void ClearBufferI(int buffer, int value) override;
|
||||
virtual void Clear() override;
|
||||
|
||||
virtual void DrawIndexed(const Ref<VertexArray>& vertex_array, uint32_t index_count = 0) override;
|
||||
|
||||
@@ -34,6 +34,9 @@ namespace OpenEngine {
|
||||
|
||||
float GetPitch() const { return pitch; }
|
||||
float GetYaw() const { return yaw; }
|
||||
|
||||
bool GetMoving() { return moving; };
|
||||
|
||||
private:
|
||||
void UpdateProjection();
|
||||
void UpdateView();
|
||||
@@ -49,6 +52,7 @@ namespace OpenEngine {
|
||||
std::pair<float, float> PanSpeed() const;
|
||||
float RotationSpeed() const;
|
||||
float ZoomSpeed() const;
|
||||
|
||||
private:
|
||||
float fov = 45.0f, aspect_ratio = 1.778f, near_clip = 0.1f, far_clip = 1000.0f;
|
||||
|
||||
@@ -61,6 +65,8 @@ namespace OpenEngine {
|
||||
float distance = 10.0f;
|
||||
float pitch = 0.0f, yaw = 0.0f;
|
||||
|
||||
bool moving = false;
|
||||
|
||||
float viewport_width = 1280, viewport_height = 720;
|
||||
};
|
||||
|
||||
|
||||
@@ -4,11 +4,50 @@
|
||||
#include "open_engine/ref_scope.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <initializer_list>
|
||||
#include <vector>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
enum class FramebufferTextureFormat
|
||||
{
|
||||
None = 0,
|
||||
|
||||
// Color
|
||||
RGBA8,
|
||||
RED_INTEGER,
|
||||
|
||||
// Depth/Stencil
|
||||
DEPTH24STENCIL8,
|
||||
|
||||
// Default
|
||||
Depth = DEPTH24STENCIL8
|
||||
};
|
||||
|
||||
struct FramebufferTextureSpecification
|
||||
{
|
||||
FramebufferTextureSpecification() = default;
|
||||
FramebufferTextureSpecification(FramebufferTextureFormat format)
|
||||
: texture_format(format)
|
||||
{};
|
||||
|
||||
FramebufferTextureFormat texture_format = FramebufferTextureFormat::None;
|
||||
};
|
||||
|
||||
struct FramebufferAttachmentSpecification
|
||||
{
|
||||
FramebufferAttachmentSpecification() = default;
|
||||
FramebufferAttachmentSpecification(std::initializer_list<FramebufferTextureSpecification> attachments)
|
||||
: attachments(attachments)
|
||||
{}
|
||||
|
||||
std::vector<FramebufferTextureSpecification> attachments;
|
||||
};
|
||||
|
||||
struct FramebufferSpecification
|
||||
{
|
||||
uint32_t width, height;
|
||||
FramebufferAttachmentSpecification attachments;
|
||||
uint32_t samples = 1;
|
||||
|
||||
bool swap_chain_target = false;
|
||||
@@ -22,8 +61,9 @@ namespace OpenEngine {
|
||||
virtual void Unbind() = 0;
|
||||
|
||||
virtual void Resize(uint32_t width, uint32_t height) = 0;
|
||||
virtual int ReadPixel(uint32_t index, int x, int y) = 0;
|
||||
|
||||
virtual uint32_t GetColorAttachmentRendererID() const = 0;
|
||||
virtual uint32_t GetColorAttachmentRendererID(uint32_t index = 0) const = 0;
|
||||
|
||||
virtual const FramebufferSpecification& GetSpecification() const = 0;
|
||||
|
||||
|
||||
@@ -24,6 +24,11 @@ namespace OpenEngine {
|
||||
api->SetClearColor(color);
|
||||
};
|
||||
|
||||
inline static void ClearBufferI(int buffer, int value)
|
||||
{
|
||||
api->ClearBufferI(buffer, value);
|
||||
};
|
||||
|
||||
inline static void Clear()
|
||||
{
|
||||
api->Clear();
|
||||
|
||||
@@ -39,13 +39,23 @@ namespace OpenEngine {
|
||||
static void EndScene();
|
||||
static void Flush();
|
||||
|
||||
static void DrawQuad(const Transform& transform_data, const glm::vec4& color);
|
||||
static void DrawQuad(const Transform& transform_data, const Ref<Texture2D>& texture, float tiling_factor = 1.0f);
|
||||
static void DrawQuad(const Transform& transform_data, const Ref<Subtexture2D>& subtexture, float tiling_factor = 1.0f);
|
||||
static void DrawQuad(const Transform& transform_data,
|
||||
const glm::vec4& color, int entity_id);
|
||||
static void DrawQuad(const Transform& transform_data,
|
||||
const Ref<Texture2D>& texture, int entity_id,
|
||||
float tiling_factor = 1.0f);
|
||||
static void DrawQuad(const Transform& transform_data,
|
||||
const Ref<Subtexture2D>& subtexture, int entity_id,
|
||||
float tiling_factor = 1.0f);
|
||||
|
||||
static void DrawQuad(const glm::mat4& transform, const glm::vec4& color);
|
||||
static void DrawQuad(const glm::mat4& transform, const Ref<Texture2D>& texture, float tiling_factor = 1.0f);
|
||||
static void DrawQuad(const glm::mat4& transform, const Ref<Subtexture2D>& subtexture, float tiling_factor = 1.0f);
|
||||
static void DrawQuad(const glm::mat4& transform,
|
||||
const glm::vec4& color, int entity_id);
|
||||
static void DrawQuad(const glm::mat4& transform,
|
||||
const Ref<Texture2D>& texture, int entity_id,
|
||||
float tiling_factor = 1.0f);
|
||||
static void DrawQuad(const glm::mat4& transform,
|
||||
const Ref<Subtexture2D>& subtexture, int entity_id,
|
||||
float tiling_factor = 1.0f);
|
||||
|
||||
static void ResetStats();
|
||||
static const Statistics& GetStats();
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace OpenEngine {
|
||||
virtual void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) = 0;
|
||||
|
||||
virtual void SetClearColor(const glm::vec4& color) = 0;
|
||||
virtual void ClearBufferI(int buffer, int value) = 0;
|
||||
virtual void Clear() = 0;
|
||||
|
||||
virtual void DrawIndexed(const Ref<VertexArray>& vertex_array, uint32_t count = 0) = 0;
|
||||
|
||||
Reference in New Issue
Block a user