mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 20:41:49 +00:00
move some code there and here
This commit is contained in:
parent
a7ad219261
commit
28b7713648
12 changed files with 84 additions and 76 deletions
|
|
@ -74,6 +74,18 @@ DrawContext::~DrawContext() {
|
|||
if (lineWidth != parent->lineWidth) {
|
||||
glLineWidth(parent->lineWidth);
|
||||
}
|
||||
|
||||
for (int i = 0; i < textures.size(); i++) {
|
||||
auto texture = parent->textures[i];
|
||||
if (textures[i] != texture) {
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
if (texture == nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
} else {
|
||||
texture->bind();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const glm::uvec2& DrawContext::getViewport() const {
|
||||
|
|
@ -154,3 +166,13 @@ void DrawContext::setLineWidth(float width) {
|
|||
lineWidth = width;
|
||||
glLineWidth(width);
|
||||
}
|
||||
|
||||
void DrawContext::useTexture(int target, const Bindable* texture) {
|
||||
glActiveTexture(GL_TEXTURE0 + target);
|
||||
if (texture == nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
} else {
|
||||
texture->bind();
|
||||
}
|
||||
textures.at(target) = texture;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
|
||||
|
|
@ -23,6 +24,7 @@ class DrawContext {
|
|||
BlendMode blendMode = BlendMode::normal;
|
||||
int scissorsCount = 0;
|
||||
float lineWidth = 1.0f;
|
||||
std::array<const Bindable*, advanced_pipeline::TARGETS_COUNT> textures {};
|
||||
public:
|
||||
DrawContext(
|
||||
const DrawContext* parent,
|
||||
|
|
@ -44,4 +46,5 @@ public:
|
|||
void setBlendMode(BlendMode mode);
|
||||
void setScissors(const glm::vec4& area);
|
||||
void setLineWidth(float width);
|
||||
void useTexture(int target, const Bindable* texture);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -84,11 +84,11 @@ void Framebuffer::setTexture(std::unique_ptr<Texture> texture) {
|
|||
this->texture = std::move(texture);
|
||||
}
|
||||
|
||||
void Framebuffer::bind() {
|
||||
void Framebuffer::bind() const {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
}
|
||||
|
||||
void Framebuffer::unbind() {
|
||||
void Framebuffer::unbind() const {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ public:
|
|||
void setTexture(std::unique_ptr<Texture> texture);
|
||||
|
||||
/// @brief Use framebuffer
|
||||
void bind() override;
|
||||
void bind() const override;
|
||||
|
||||
/// @brief Stop using framebuffer
|
||||
void unbind() override;
|
||||
void unbind() const override;
|
||||
|
||||
/// @brief Update framebuffer texture size
|
||||
/// @param width new width
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ GBuffer::~GBuffer() {
|
|||
glDeleteFramebuffers(1, &ssaoFbo);
|
||||
}
|
||||
|
||||
void GBuffer::bind() {
|
||||
void GBuffer::bind() const {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
|
@ -198,7 +198,7 @@ void GBuffer::bindSSAO() const {
|
|||
glBindFramebuffer(GL_FRAMEBUFFER, ssaoFbo);
|
||||
}
|
||||
|
||||
void GBuffer::unbind() {
|
||||
void GBuffer::unbind() const {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ public:
|
|||
GBuffer(uint width, uint height);
|
||||
~GBuffer() override;
|
||||
|
||||
void bind() override;
|
||||
void bind() const override;
|
||||
void bindSSAO() const;
|
||||
void unbind() override;
|
||||
void unbind() const override;
|
||||
|
||||
void bindBuffers() const;
|
||||
void bindSSAOBuffer() const;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "typedefs.hpp"
|
||||
#include "maths/UVRegion.hpp"
|
||||
#include "ImageData.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Texture {
|
||||
#include "ImageData.hpp"
|
||||
#include "commons.hpp"
|
||||
#include "maths/UVRegion.hpp"
|
||||
#include "typedefs.hpp"
|
||||
|
||||
class Texture : public Bindable {
|
||||
protected:
|
||||
uint id;
|
||||
uint width;
|
||||
|
|
@ -17,8 +18,8 @@ public:
|
|||
Texture(const ubyte* data, uint width, uint height, ImageFormat format);
|
||||
virtual ~Texture();
|
||||
|
||||
virtual void bind() const;
|
||||
virtual void unbind() const;
|
||||
virtual void bind() const override;
|
||||
virtual void unbind() const override;
|
||||
virtual void reload(const ubyte* data, uint w, uint h);
|
||||
void reloadPartial(const ImageData& image, uint x, uint y, uint w, uint h);
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ namespace advanced_pipeline {
|
|||
inline constexpr int TARGET_SSAO = 5;
|
||||
inline constexpr int TARGET_SHADOWS0 = 6;
|
||||
inline constexpr int TARGET_SHADOWS1 = 7;
|
||||
|
||||
inline constexpr int TARGETS_COUNT = 8;
|
||||
}
|
||||
|
||||
VC_ENUM_METADATA(CursorShape)
|
||||
|
|
@ -85,6 +87,6 @@ class Bindable {
|
|||
public:
|
||||
virtual ~Bindable() = default;
|
||||
|
||||
virtual void bind() = 0;
|
||||
virtual void unbind() = 0;
|
||||
virtual void bind() const = 0;
|
||||
virtual void unbind() const = 0;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue