mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 19:04:32 +02:00
Working on specular bits for deferred lighting.
This commit is contained in:
parent
f954e4d7ea
commit
618f6415da
3 changed files with 31 additions and 5 deletions
|
@ -27,8 +27,8 @@ void DeferredLightingEffect::init() {
|
|||
}
|
||||
|
||||
void DeferredLightingEffect::prepare() {
|
||||
// clear the normal buffer
|
||||
Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(false, true);
|
||||
// clear the normal and specular buffers
|
||||
Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(false, true, true);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ TextureCache::TextureCache() :
|
|||
_blueTextureID(0),
|
||||
_primaryDepthTextureID(0),
|
||||
_primaryNormalTextureID(0),
|
||||
_primarySpecularTextureID(0),
|
||||
_primaryFramebufferObject(NULL),
|
||||
_secondaryFramebufferObject(NULL),
|
||||
_tertiaryFramebufferObject(NULL),
|
||||
|
@ -48,6 +49,7 @@ TextureCache::~TextureCache() {
|
|||
if (_primaryFramebufferObject) {
|
||||
glDeleteTextures(1, &_primaryDepthTextureID);
|
||||
glDeleteTextures(1, &_primaryNormalTextureID);
|
||||
glDeleteTextures(1, &_primarySpecularTextureID);
|
||||
}
|
||||
|
||||
if (_primaryFramebufferObject) {
|
||||
|
@ -75,6 +77,8 @@ void TextureCache::setFrameBufferSize(QSize frameBufferSize) {
|
|||
_primaryDepthTextureID = 0;
|
||||
glDeleteTextures(1, &_primaryNormalTextureID);
|
||||
_primaryNormalTextureID = 0;
|
||||
glDeleteTextures(1, &_primarySpecularTextureID);
|
||||
_primarySpecularTextureID = 0;
|
||||
}
|
||||
|
||||
if (_secondaryFramebufferObject) {
|
||||
|
@ -222,9 +226,18 @@ QOpenGLFramebufferObject* TextureCache::getPrimaryFramebufferObject() {
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
glGenTextures(1, &_primarySpecularTextureID);
|
||||
glBindTexture(GL_TEXTURE_2D, _primarySpecularTextureID);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _frameBufferSize.width(), _frameBufferSize.height(),
|
||||
0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
_primaryFramebufferObject->bind();
|
||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _primaryDepthTextureID, 0);
|
||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, _primaryNormalTextureID, 0);
|
||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, _primarySpecularTextureID, 0);
|
||||
_primaryFramebufferObject->release();
|
||||
}
|
||||
return _primaryFramebufferObject;
|
||||
|
@ -242,8 +255,13 @@ GLuint TextureCache::getPrimaryNormalTextureID() {
|
|||
return _primaryNormalTextureID;
|
||||
}
|
||||
|
||||
void TextureCache::setPrimaryDrawBuffers(bool color, bool normal) {
|
||||
GLenum buffers[2];
|
||||
GLuint TextureCache::getPrimarySpecularTextureID() {
|
||||
getPrimaryFramebufferObject();
|
||||
return _primarySpecularTextureID;
|
||||
}
|
||||
|
||||
void TextureCache::setPrimaryDrawBuffers(bool color, bool normal, bool specular) {
|
||||
GLenum buffers[3];
|
||||
int bufferCount = 0;
|
||||
if (color) {
|
||||
buffers[bufferCount++] = GL_COLOR_ATTACHMENT0;
|
||||
|
@ -251,6 +269,9 @@ void TextureCache::setPrimaryDrawBuffers(bool color, bool normal) {
|
|||
if (normal) {
|
||||
buffers[bufferCount++] = GL_COLOR_ATTACHMENT1;
|
||||
}
|
||||
if (specular) {
|
||||
buffers[bufferCount++] = GL_COLOR_ATTACHMENT2;
|
||||
}
|
||||
glDrawBuffers(bufferCount, buffers);
|
||||
}
|
||||
|
||||
|
@ -308,6 +329,7 @@ bool TextureCache::eventFilter(QObject* watched, QEvent* event) {
|
|||
_primaryFramebufferObject = NULL;
|
||||
glDeleteTextures(1, &_primaryDepthTextureID);
|
||||
glDeleteTextures(1, &_primaryNormalTextureID);
|
||||
glDeleteTextures(1, &_primarySpecularTextureID);
|
||||
}
|
||||
if (_secondaryFramebufferObject && _secondaryFramebufferObject->size() != size) {
|
||||
delete _secondaryFramebufferObject;
|
||||
|
|
|
@ -64,8 +64,11 @@ public:
|
|||
/// Returns the ID of the primary framebuffer object's normal texture.
|
||||
GLuint getPrimaryNormalTextureID();
|
||||
|
||||
/// Returns the ID of the primary framebuffer object's specular texture.
|
||||
GLuint getPrimarySpecularTextureID();
|
||||
|
||||
/// Enables or disables draw buffers on the primary framebuffer. Note: the primary framebuffer must be bound.
|
||||
void setPrimaryDrawBuffers(bool color, bool normal);
|
||||
void setPrimaryDrawBuffers(bool color, bool normal = false, bool specular = false);
|
||||
|
||||
/// Returns a pointer to the secondary framebuffer object, used as an additional render target when performing full
|
||||
/// screen effects.
|
||||
|
@ -102,6 +105,7 @@ private:
|
|||
|
||||
GLuint _primaryDepthTextureID;
|
||||
GLuint _primaryNormalTextureID;
|
||||
GLuint _primarySpecularTextureID;
|
||||
QOpenGLFramebufferObject* _primaryFramebufferObject;
|
||||
QOpenGLFramebufferObject* _secondaryFramebufferObject;
|
||||
QOpenGLFramebufferObject* _tertiaryFramebufferObject;
|
||||
|
|
Loading…
Reference in a new issue