world previews demo
This commit is contained in:
@@ -41,8 +41,8 @@ ImageData* Atlas::getImage() const {
|
||||
return image.get();
|
||||
}
|
||||
|
||||
void AtlasBuilder::add(std::string name, ImageData* image) {
|
||||
entries.push_back(atlasentry{name, std::shared_ptr<ImageData>(image)});
|
||||
void AtlasBuilder::add(std::string name, std::unique_ptr<ImageData> image) {
|
||||
entries.push_back(atlasentry{name, std::shared_ptr<ImageData>(image.release())});
|
||||
names.insert(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class AtlasBuilder {
|
||||
std::set<std::string> names;
|
||||
public:
|
||||
AtlasBuilder() {}
|
||||
void add(std::string name, ImageData* image);
|
||||
void add(std::string name, std::unique_ptr<ImageData> image);
|
||||
bool has(const std::string& name) const;
|
||||
const std::set<std::string>& getNames() { return names; };
|
||||
|
||||
|
||||
@@ -13,17 +13,10 @@ Framebuffer::Framebuffer(uint fbo, uint depth, std::unique_ptr<Texture> texture)
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Framebuffer::Framebuffer(uint width, uint height, bool alpha)
|
||||
: width(width), height(height)
|
||||
{
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
|
||||
// Setup color attachment (texture)
|
||||
static std::unique_ptr<Texture> create_texture(int width, int height, int format) {
|
||||
GLuint tex;
|
||||
format = alpha ? GL_RGBA : GL_RGB;
|
||||
glGenTextures(1, &tex);
|
||||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, nullptr);
|
||||
@@ -32,7 +25,19 @@ Framebuffer::Framebuffer(uint width, uint height, bool alpha)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
|
||||
texture = std::make_unique<Texture>(tex, width, height);
|
||||
return std::make_unique<Texture>(tex, width, height);
|
||||
}
|
||||
|
||||
Framebuffer::Framebuffer(uint width, uint height, bool alpha)
|
||||
: width(width), height(height)
|
||||
{
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
|
||||
format = alpha ? GL_RGBA : GL_RGB;
|
||||
|
||||
// Setup color attachment (texture)
|
||||
texture = create_texture(width, height, format);
|
||||
|
||||
// Setup depth attachment
|
||||
glGenRenderbuffers(1, &depth);
|
||||
@@ -64,11 +69,11 @@ void Framebuffer::resize(uint width, uint height) {
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, depth);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
|
||||
texture->bind();
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, nullptr);
|
||||
texture->unbind();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
texture = create_texture(width, height, format);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
Texture* Framebuffer::getTexture() const {
|
||||
|
||||
@@ -40,3 +40,11 @@ void PostProcessing::render(const GfxContext& context, Shader* screenShader) {
|
||||
fbo->getTexture()->bind();
|
||||
quadMesh->draw();
|
||||
}
|
||||
|
||||
std::unique_ptr<ImageData> PostProcessing::toImage() {
|
||||
return fbo->getTexture()->readData();
|
||||
}
|
||||
|
||||
Framebuffer* PostProcessing::getFramebuffer() const {
|
||||
return fbo.get();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,11 @@ public:
|
||||
/// @param screenShader shader used for fullscreen quad
|
||||
/// @throws std::runtime_error if use(...) wasn't called before
|
||||
void render(const GfxContext& context, Shader* screenShader);
|
||||
|
||||
/// @brief Make an image from the last rendered frame
|
||||
std::unique_ptr<ImageData> toImage();
|
||||
|
||||
Framebuffer* getFramebuffer() const;
|
||||
};
|
||||
|
||||
#endif // GRAPHICS_CORE_POST_PROCESSING_H_
|
||||
|
||||
@@ -49,12 +49,12 @@ void Texture::reload(ubyte* data){
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
ImageData* Texture::readData() {
|
||||
std::unique_ptr<ImageData> Texture::readData() {
|
||||
std::unique_ptr<ubyte[]> data (new ubyte[width * height * 4]);
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data.get());
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
return new ImageData(ImageFormat::rgba8888, width, height, data.release());
|
||||
return std::make_unique<ImageData>(ImageFormat::rgba8888, width, height, data.release());
|
||||
}
|
||||
|
||||
void Texture::setNearestFilter() {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define GRAPHICS_CORE_TEXTURE_H_
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "../../typedefs.h"
|
||||
#include "ImageData.h"
|
||||
|
||||
@@ -23,7 +24,7 @@ public:
|
||||
|
||||
void setNearestFilter();
|
||||
|
||||
virtual ImageData* readData();
|
||||
virtual std::unique_ptr<ImageData> readData();
|
||||
|
||||
virtual uint getWidth() const;
|
||||
virtual uint getHeight() const;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "../core/Texture.h"
|
||||
#include "../core/Viewport.h"
|
||||
|
||||
ImageData* BlocksPreview::draw(
|
||||
std::unique_ptr<ImageData> BlocksPreview::draw(
|
||||
const ContentGfxCache* cache,
|
||||
Shader* shader,
|
||||
Framebuffer* fbo,
|
||||
|
||||
@@ -17,7 +17,7 @@ class Shader;
|
||||
class ContentGfxCache;
|
||||
|
||||
class BlocksPreview {
|
||||
static ImageData* draw(
|
||||
static std::unique_ptr<ImageData> draw(
|
||||
const ContentGfxCache* cache,
|
||||
Shader* shader,
|
||||
Framebuffer* framebuffer,
|
||||
|
||||
@@ -42,7 +42,6 @@ WorldRenderer::WorldRenderer(Engine* engine, LevelFrontend* frontend, Player* pl
|
||||
level(frontend->getLevel()),
|
||||
player(player)
|
||||
{
|
||||
postProcessing = std::make_unique<PostProcessing>();
|
||||
frustumCulling = std::make_unique<Frustum>();
|
||||
lineBatch = std::make_unique<LineBatch>();
|
||||
renderer = std::make_unique<ChunksRenderer>(
|
||||
@@ -148,6 +147,7 @@ void WorldRenderer::renderLevel(
|
||||
Assets* assets = engine->getAssets();
|
||||
Atlas* atlas = assets->getAtlas("blocks");
|
||||
Shader* shader = assets->getShader("main");
|
||||
|
||||
auto indices = level->content->getIndices();
|
||||
|
||||
float fogFactor = 15.0f / ((float)settings.chunks.loadDistance.get()-2);
|
||||
@@ -265,7 +265,15 @@ void WorldRenderer::renderDebugLines(
|
||||
lineBatch->render();
|
||||
}
|
||||
|
||||
void WorldRenderer::draw(const GfxContext& pctx, Camera* camera, bool hudVisible){
|
||||
void WorldRenderer::draw(
|
||||
const GfxContext& pctx,
|
||||
Camera* camera,
|
||||
bool hudVisible,
|
||||
PostProcessing* postProcessing
|
||||
){
|
||||
const Viewport& vp = pctx.getViewport();
|
||||
camera->aspect = vp.getWidth() / static_cast<float>(vp.getHeight());
|
||||
|
||||
EngineSettings& settings = engine->getSettings();
|
||||
skybox->refresh(pctx, level->getWorld()->daytime, 1.0f+fog*2.0f, 4);
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ class WorldRenderer {
|
||||
Engine* engine;
|
||||
Level* level;
|
||||
Player* player;
|
||||
std::unique_ptr<PostProcessing> postProcessing;
|
||||
std::unique_ptr<Frustum> frustumCulling;
|
||||
std::unique_ptr<LineBatch> lineBatch;
|
||||
std::unique_ptr<ChunksRenderer> renderer;
|
||||
@@ -40,16 +39,6 @@ class WorldRenderer {
|
||||
bool drawChunk(size_t index, Camera* camera, Shader* shader, bool culling);
|
||||
void drawChunks(Chunks* chunks, Camera* camera, Shader* shader);
|
||||
|
||||
/// @brief Render level without diegetic interface
|
||||
/// @param context graphics context
|
||||
/// @param camera active camera
|
||||
/// @param settings engine settings
|
||||
void renderLevel(
|
||||
const GfxContext& context,
|
||||
Camera* camera,
|
||||
const EngineSettings& settings
|
||||
);
|
||||
|
||||
/// @brief Render block selection lines
|
||||
/// @param camera active camera
|
||||
/// @param linesShader shader used
|
||||
@@ -70,9 +59,24 @@ public:
|
||||
WorldRenderer(Engine* engine, LevelFrontend* frontend, Player* player);
|
||||
~WorldRenderer();
|
||||
|
||||
void draw(const GfxContext& context, Camera* camera, bool hudVisible);
|
||||
void draw(
|
||||
const GfxContext& context,
|
||||
Camera* camera,
|
||||
bool hudVisible,
|
||||
PostProcessing* postProcessing
|
||||
);
|
||||
void drawBorders(int sx, int sy, int sz, int ex, int ey, int ez);
|
||||
|
||||
/// @brief Render level without diegetic interface
|
||||
/// @param context graphics context
|
||||
/// @param camera active camera
|
||||
/// @param settings engine settings
|
||||
void renderLevel(
|
||||
const GfxContext& context,
|
||||
Camera* camera,
|
||||
const EngineSettings& settings
|
||||
);
|
||||
|
||||
static float fog;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user