mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 21:12:53 +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() {
|
void DeferredLightingEffect::prepare() {
|
||||||
// clear the normal buffer
|
// clear the normal and specular buffers
|
||||||
Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(false, true);
|
Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(false, true, true);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false);
|
Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ TextureCache::TextureCache() :
|
||||||
_blueTextureID(0),
|
_blueTextureID(0),
|
||||||
_primaryDepthTextureID(0),
|
_primaryDepthTextureID(0),
|
||||||
_primaryNormalTextureID(0),
|
_primaryNormalTextureID(0),
|
||||||
|
_primarySpecularTextureID(0),
|
||||||
_primaryFramebufferObject(NULL),
|
_primaryFramebufferObject(NULL),
|
||||||
_secondaryFramebufferObject(NULL),
|
_secondaryFramebufferObject(NULL),
|
||||||
_tertiaryFramebufferObject(NULL),
|
_tertiaryFramebufferObject(NULL),
|
||||||
|
@ -48,6 +49,7 @@ TextureCache::~TextureCache() {
|
||||||
if (_primaryFramebufferObject) {
|
if (_primaryFramebufferObject) {
|
||||||
glDeleteTextures(1, &_primaryDepthTextureID);
|
glDeleteTextures(1, &_primaryDepthTextureID);
|
||||||
glDeleteTextures(1, &_primaryNormalTextureID);
|
glDeleteTextures(1, &_primaryNormalTextureID);
|
||||||
|
glDeleteTextures(1, &_primarySpecularTextureID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_primaryFramebufferObject) {
|
if (_primaryFramebufferObject) {
|
||||||
|
@ -75,6 +77,8 @@ void TextureCache::setFrameBufferSize(QSize frameBufferSize) {
|
||||||
_primaryDepthTextureID = 0;
|
_primaryDepthTextureID = 0;
|
||||||
glDeleteTextures(1, &_primaryNormalTextureID);
|
glDeleteTextures(1, &_primaryNormalTextureID);
|
||||||
_primaryNormalTextureID = 0;
|
_primaryNormalTextureID = 0;
|
||||||
|
glDeleteTextures(1, &_primarySpecularTextureID);
|
||||||
|
_primarySpecularTextureID = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_secondaryFramebufferObject) {
|
if (_secondaryFramebufferObject) {
|
||||||
|
@ -222,9 +226,18 @@ QOpenGLFramebufferObject* TextureCache::getPrimaryFramebufferObject() {
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
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();
|
_primaryFramebufferObject->bind();
|
||||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _primaryDepthTextureID, 0);
|
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_ATTACHMENT1, GL_TEXTURE_2D, _primaryNormalTextureID, 0);
|
||||||
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, _primarySpecularTextureID, 0);
|
||||||
_primaryFramebufferObject->release();
|
_primaryFramebufferObject->release();
|
||||||
}
|
}
|
||||||
return _primaryFramebufferObject;
|
return _primaryFramebufferObject;
|
||||||
|
@ -242,8 +255,13 @@ GLuint TextureCache::getPrimaryNormalTextureID() {
|
||||||
return _primaryNormalTextureID;
|
return _primaryNormalTextureID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureCache::setPrimaryDrawBuffers(bool color, bool normal) {
|
GLuint TextureCache::getPrimarySpecularTextureID() {
|
||||||
GLenum buffers[2];
|
getPrimaryFramebufferObject();
|
||||||
|
return _primarySpecularTextureID;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureCache::setPrimaryDrawBuffers(bool color, bool normal, bool specular) {
|
||||||
|
GLenum buffers[3];
|
||||||
int bufferCount = 0;
|
int bufferCount = 0;
|
||||||
if (color) {
|
if (color) {
|
||||||
buffers[bufferCount++] = GL_COLOR_ATTACHMENT0;
|
buffers[bufferCount++] = GL_COLOR_ATTACHMENT0;
|
||||||
|
@ -251,6 +269,9 @@ void TextureCache::setPrimaryDrawBuffers(bool color, bool normal) {
|
||||||
if (normal) {
|
if (normal) {
|
||||||
buffers[bufferCount++] = GL_COLOR_ATTACHMENT1;
|
buffers[bufferCount++] = GL_COLOR_ATTACHMENT1;
|
||||||
}
|
}
|
||||||
|
if (specular) {
|
||||||
|
buffers[bufferCount++] = GL_COLOR_ATTACHMENT2;
|
||||||
|
}
|
||||||
glDrawBuffers(bufferCount, buffers);
|
glDrawBuffers(bufferCount, buffers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,6 +329,7 @@ bool TextureCache::eventFilter(QObject* watched, QEvent* event) {
|
||||||
_primaryFramebufferObject = NULL;
|
_primaryFramebufferObject = NULL;
|
||||||
glDeleteTextures(1, &_primaryDepthTextureID);
|
glDeleteTextures(1, &_primaryDepthTextureID);
|
||||||
glDeleteTextures(1, &_primaryNormalTextureID);
|
glDeleteTextures(1, &_primaryNormalTextureID);
|
||||||
|
glDeleteTextures(1, &_primarySpecularTextureID);
|
||||||
}
|
}
|
||||||
if (_secondaryFramebufferObject && _secondaryFramebufferObject->size() != size) {
|
if (_secondaryFramebufferObject && _secondaryFramebufferObject->size() != size) {
|
||||||
delete _secondaryFramebufferObject;
|
delete _secondaryFramebufferObject;
|
||||||
|
|
|
@ -64,8 +64,11 @@ public:
|
||||||
/// Returns the ID of the primary framebuffer object's normal texture.
|
/// Returns the ID of the primary framebuffer object's normal texture.
|
||||||
GLuint getPrimaryNormalTextureID();
|
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.
|
/// 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
|
/// Returns a pointer to the secondary framebuffer object, used as an additional render target when performing full
|
||||||
/// screen effects.
|
/// screen effects.
|
||||||
|
@ -102,6 +105,7 @@ private:
|
||||||
|
|
||||||
GLuint _primaryDepthTextureID;
|
GLuint _primaryDepthTextureID;
|
||||||
GLuint _primaryNormalTextureID;
|
GLuint _primaryNormalTextureID;
|
||||||
|
GLuint _primarySpecularTextureID;
|
||||||
QOpenGLFramebufferObject* _primaryFramebufferObject;
|
QOpenGLFramebufferObject* _primaryFramebufferObject;
|
||||||
QOpenGLFramebufferObject* _secondaryFramebufferObject;
|
QOpenGLFramebufferObject* _secondaryFramebufferObject;
|
||||||
QOpenGLFramebufferObject* _tertiaryFramebufferObject;
|
QOpenGLFramebufferObject* _tertiaryFramebufferObject;
|
||||||
|
|
Loading…
Reference in a new issue