colobot/colobot-base/graphics/core/framebuffer.h

167 lines
4.7 KiB
C
Raw Normal View History

2015-06-21 16:48:31 +00:00
/*
* This file is part of the Colobot: Gold Edition source code
2023-08-06 21:15:48 +00:00
* Copyright (C) 2001-2023, Daniel Roux, EPSITEC SA & TerranovaTeam
2015-08-22 14:40:02 +00:00
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
2015-06-21 16:48:31 +00:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
/**
* \file graphics/core/framebuffer.h
* \brief Abstract representation of framebuffer and offscreen buffers
*/
#pragma once
2015-08-02 09:40:47 +00:00
namespace Gfx
{
2015-06-21 16:48:31 +00:00
/**
* \struct FramebufferParams
* \brief Contains parameters for new framebuffer
*/
struct FramebufferParams
{
//! Requested width of buffers
int width = 1024;
2015-06-21 16:48:31 +00:00
//! Requested height of buffers
int height = 1024;
2015-06-21 16:48:31 +00:00
//! Requested depth buffer
int depth = 16;
2015-06-21 16:48:31 +00:00
//! Requested number of samples for multisampling
int samples = 1;
enum class AttachmentType
{
Texture,
Renderbuffer,
None,
};
AttachmentType colorAttachment = AttachmentType::Renderbuffer;
AttachmentType depthAttachment = AttachmentType::Renderbuffer;
2015-06-21 16:48:31 +00:00
//! Loads default values
void LoadDefault()
{
*this = FramebufferParams();
2015-06-21 16:48:31 +00:00
}
};
/**
* \class CFramebuffer
* \brief Abstract interface of default framebuffer and offscreen framebuffers
*
* This code encapsulates basics of default framebuffer and offscreen buffers
* and allows offscreen rendering in generic way. CDevice may or may not implement
* offscreen buffers depending on available hardware but is required to provide
* default framebuffer implementation. Because of some hardware restrictions
* and in order to simplify interface, you can't bind/unbind textures from
* offscreen buffers and you can't change it's parameters.
*/
class CFramebuffer
{
public:
2015-06-21 17:38:00 +00:00
virtual ~CFramebuffer() {}
2015-06-21 16:48:31 +00:00
//! Creates this framebuffer
virtual bool Create() = 0;
2015-06-21 16:48:31 +00:00
//! Destroys this framebuffer
virtual void Destroy() = 0;
//! Returns true if this is default framebuffer
virtual bool IsDefault() = 0;
//! Returns width of buffers in this framebuffer
virtual int GetWidth() = 0;
//! Returns height of buffers in this framebuffer
virtual int GetHeight() = 0;
//! Returns depth size in bits
virtual int GetDepth() = 0;
//! Returns number of samples or 1 if multisampling is not supported
virtual int GetSamples() = 0;
//! Returns texture that contains color buffer or 0 if not available
virtual int GetColorTexture() = 0;
//! Returns texture that contains depth buffer or 0 if not available
virtual int GetDepthTexture() = 0;
//! Binds this framebuffer to context
virtual void Bind() = 0;
//! Unbinds this framebuffer from context
virtual void Unbind() = 0;
2015-06-21 22:56:47 +00:00
//! Copies content of color buffer to screen
virtual void CopyToScreen(int fromX, int fromY, int fromWidth, int fromHeight, int toX, int toY, int toWidth, int toHeight) = 0;
2015-06-21 16:48:31 +00:00
};
/**
* \class CDefaultFramebuffer
* \brief Concrete implementation of default framebuffer.
*
* This class represents default framebuffer implementation.
*/
class CDefaultFramebuffer : public CFramebuffer
{
private:
int m_width, m_height, m_depth;
public:
explicit CDefaultFramebuffer(const FramebufferParams &params);
//! Creates default framebuffer
bool Create() override;
2015-06-21 16:48:31 +00:00
//! Destroys default framebuffer
2015-08-17 19:53:28 +00:00
void Destroy() override;
2015-06-21 16:48:31 +00:00
//! Returns true
2015-08-17 19:53:28 +00:00
bool IsDefault() override;
2015-06-21 16:48:31 +00:00
//! Returns width of buffers in this framebuffer
2015-08-17 19:53:28 +00:00
int GetWidth() override;
2015-06-21 16:48:31 +00:00
//! Returns height of buffers in this framebuffer
2015-08-17 19:53:28 +00:00
int GetHeight() override;
2015-06-21 16:48:31 +00:00
//! Returns depth size in bits
2015-08-17 19:53:28 +00:00
int GetDepth() override;
2015-06-21 16:48:31 +00:00
//! Returns number of samples or 1 if multisampling is not supported
2015-08-17 19:53:28 +00:00
int GetSamples() override;
2015-06-21 16:48:31 +00:00
//! Returns texture that contains color buffer or 0 if not available
2015-08-17 19:53:28 +00:00
int GetColorTexture() override;
2015-06-21 16:48:31 +00:00
//! Returns texture that contains depth buffer or 0 if not available
2015-08-17 19:53:28 +00:00
int GetDepthTexture() override;
2015-06-21 16:48:31 +00:00
//! Binds this framebuffer to context
2015-08-17 19:53:28 +00:00
void Bind() override;
2015-06-21 16:48:31 +00:00
//! Unbinds this framebuffer from context
2015-08-17 19:53:28 +00:00
void Unbind() override;
2015-06-21 22:56:47 +00:00
//! Copies content of color buffer to screen
2015-08-17 19:53:28 +00:00
void CopyToScreen(int fromX, int fromY, int fromWidth, int fromHeight, int toX, int toY, int toWidth, int toHeight) override;
2015-06-21 16:48:31 +00:00
};
} // end of Gfx