openspades/Sources/Draw/GLFramebufferManager.h

122 lines
3.2 KiB
C
Raw Normal View History

2013-08-29 11:45:22 +09:00
/*
Copyright (c) 2013 yvt
2013-08-29 11:45:22 +09:00
This file is part of OpenSpades.
2013-08-29 11:45:22 +09:00
OpenSpades 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.
2013-08-29 11:45:22 +09:00
OpenSpades 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.
2013-08-29 11:45:22 +09:00
You should have received a copy of the GNU General Public License
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
2013-08-29 11:45:22 +09:00
*/
2013-08-18 16:18:06 +09:00
#pragma once
#include "IGLDevice.h"
namespace spades {
namespace draw {
class GLSettings;
2013-08-18 16:18:06 +09:00
class GLFramebufferManager {
public:
class BufferHandle {
GLFramebufferManager *manager;
size_t bufferIndex;
bool valid;
2013-08-18 16:18:06 +09:00
public:
BufferHandle();
BufferHandle(GLFramebufferManager *manager, size_t index);
BufferHandle(const BufferHandle &);
2013-08-18 16:18:06 +09:00
~BufferHandle();
void operator=(const BufferHandle &);
bool IsValid() const { return valid; }
2013-08-18 16:18:06 +09:00
void Release();
IGLDevice::UInteger GetFramebuffer();
IGLDevice::UInteger GetTexture();
int GetWidth();
int GetHeight();
IGLDevice::Enum GetInternalFormat();
GLFramebufferManager *GetManager() { return manager; }
2013-08-18 16:18:06 +09:00
};
2013-08-18 16:18:06 +09:00
private:
IGLDevice *device;
GLSettings &settings;
2013-08-18 16:18:06 +09:00
struct Buffer {
IGLDevice::UInteger framebuffer;
IGLDevice::UInteger texture;
int refCount;
int w, h;
IGLDevice::Enum internalFormat;
2013-08-18 16:18:06 +09:00
};
2013-08-18 16:18:06 +09:00
bool useMultisample;
bool useHighPrec;
2014-04-08 01:23:50 +09:00
bool useHdr;
2017-01-01 16:35:14 +09:00
bool doingPostProcessing;
2013-08-18 16:18:06 +09:00
IGLDevice::UInteger multisampledFramebuffer;
2013-08-18 16:18:06 +09:00
// for multisample
IGLDevice::UInteger multisampledColorRenderbuffer;
IGLDevice::UInteger multisampledDepthRenderbuffer;
2013-08-18 16:18:06 +09:00
// common
IGLDevice::UInteger renderFramebuffer;
IGLDevice::UInteger renderColorTexture;
IGLDevice::UInteger renderDepthTexture;
2017-01-11 22:18:14 +09:00
IGLDevice::UInteger renderFramebufferWithoutDepth;
2013-09-04 22:11:39 +09:00
IGLDevice::Enum fbInternalFormat;
IGLDevice::UInteger mirrorFramebuffer;
IGLDevice::UInteger mirrorColorTexture;
IGLDevice::UInteger mirrorDepthTexture;
2013-08-18 16:18:06 +09:00
std::vector<Buffer> buffers;
2013-08-18 16:18:06 +09:00
public:
2016-11-19 23:22:18 +09:00
GLFramebufferManager(IGLDevice *, GLSettings &);
2013-08-18 16:18:06 +09:00
~GLFramebufferManager();
2013-08-18 16:18:06 +09:00
/** setups device for scene rendering. */
void PrepareSceneRendering();
BufferHandle PrepareForWaterRendering(IGLDevice::UInteger tempFb,
IGLDevice::UInteger tempDepthTex);
2013-08-18 16:18:06 +09:00
BufferHandle StartPostProcessing();
2013-08-18 16:18:06 +09:00
void MakeSureAllBuffersReleased();
IGLDevice::UInteger GetDepthTexture() { return renderDepthTexture; }
BufferHandle CreateBufferHandle(int w = -1, int h = -1, bool alpha = false);
BufferHandle CreateBufferHandle(int w, int h, IGLDevice::Enum internalFormat);
void CopyToMirrorTexture(IGLDevice::UInteger fb = 0);
void ClearMirrorTexture(Vector3);
IGLDevice::UInteger GetMirrorTexture() { return mirrorColorTexture; }
IGLDevice::UInteger GetMirrorDepthTexture() { return mirrorDepthTexture; }
2013-08-18 16:18:06 +09:00
};
2013-08-18 16:18:06 +09:00
// name is too long, so shorten it!
typedef GLFramebufferManager::BufferHandle GLColorBuffer;
}
}