Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renderer: Added console effect for lens flares
fx::LensFlares instances use a shared data instance for common GL resources: texture atlas for flare images and a shader program. This commit sets up the basic mechanism using de::Counted.
- Loading branch information
Showing
8 changed files
with
186 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** @file lensflares.h | ||
* | ||
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>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 2 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://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#ifndef DENG_CLIENT_FX_LENSFLARES_H | ||
#define DENG_CLIENT_FX_LENSFLARES_H | ||
|
||
#include "render/consoleeffect.h" | ||
|
||
namespace fx { | ||
|
||
/** | ||
* Draws lens flares for all visible light sources in the current frame. | ||
*/ | ||
class LensFlares : public ConsoleEffect | ||
{ | ||
public: | ||
LensFlares(int console); | ||
|
||
void glInit(); | ||
void glDeinit(); | ||
|
||
void draw(de::Rectanglei const &viewRect); | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
}; | ||
|
||
} // namespace fx | ||
|
||
#endif // DENG_CLIENT_FX_LENSFLARES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/** @file lensflares.cpp | ||
* | ||
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>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 2 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://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#include "render/fx/lensflares.h" | ||
#include "gl/gl_main.h" | ||
|
||
#include <de/concurrency.h> | ||
#include <de/Counted> | ||
#include <de/Log> | ||
|
||
using namespace de; | ||
|
||
namespace fx { | ||
|
||
/** | ||
* Shared GL resources for rendering lens flares. | ||
*/ | ||
struct SharedFlareData : public Counted | ||
{ | ||
static SharedFlareData *instance; | ||
|
||
SharedFlareData() | ||
{ | ||
DENG_ASSERT_IN_MAIN_THREAD(); | ||
DENG_ASSERT_GL_CONTEXT_ACTIVE(); | ||
} | ||
|
||
~SharedFlareData() | ||
{ | ||
DENG_ASSERT_IN_MAIN_THREAD(); | ||
DENG_ASSERT_GL_CONTEXT_ACTIVE(); | ||
|
||
LOG_DEBUG("Releasing shared data"); | ||
instance = 0; | ||
} | ||
|
||
static SharedFlareData *hold() | ||
{ | ||
if(!instance) | ||
{ | ||
instance = new SharedFlareData; | ||
LOG_DEBUG("Allocated shared data"); | ||
} | ||
else | ||
{ | ||
// Hold a reference to the shared data. | ||
instance->ref<Counted>(); | ||
} | ||
return instance; | ||
} | ||
}; | ||
|
||
SharedFlareData *SharedFlareData::instance = 0; | ||
|
||
DENG2_PIMPL(LensFlares) | ||
{ | ||
SharedFlareData *res; | ||
|
||
Instance(Public *i) : Base(i), res(0) | ||
{ | ||
} | ||
|
||
~Instance() | ||
{ | ||
releaseRef(res); | ||
} | ||
|
||
void glInit() | ||
{ | ||
// Acquire a reference to the shared flare data. | ||
res = SharedFlareData::hold(); | ||
} | ||
|
||
void glDeinit() | ||
{ | ||
releaseRef(res); | ||
} | ||
}; | ||
|
||
LensFlares::LensFlares(int console) : ConsoleEffect(console), d(new Instance(this)) | ||
{} | ||
|
||
void LensFlares::glInit() | ||
{ | ||
LOG_AS("fx::LensFlares"); | ||
|
||
d->glInit(); | ||
} | ||
|
||
void LensFlares::glDeinit() | ||
{ | ||
LOG_AS("fx::LensFlares"); | ||
|
||
d->glDeinit(); | ||
} | ||
|
||
void LensFlares::draw(Rectanglei const &viewRect) | ||
{ | ||
|
||
} | ||
|
||
} // namespace fx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters