Skip to content

Commit

Permalink
Renderer: Added console effect for lens flares
Browse files Browse the repository at this point in the history
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
skyjake committed Nov 12, 2013
1 parent ff1f6ff commit aa098ef
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -297,6 +297,7 @@ DENG_HEADERS += \
include/render/drawlist.h \
include/render/drawlists.h \
include/render/fx/colorfilter.h \
include/render/fx/lensflares.h \
include/render/fx/vignette.h \
include/render/huecirclevisual.h \
include/render/lightdecoration.h \
Expand Down Expand Up @@ -660,6 +661,7 @@ SOURCES += \
src/render/drawlist.cpp \
src/render/drawlists.cpp \
src/render/fx/colorfilter.cpp \
src/render/fx/lensflares.cpp \
src/render/fx/vignette.cpp \
src/render/huecirclevisual.cpp \
src/render/lightdecoration.cpp \
Expand Down
3 changes: 3 additions & 0 deletions doomsday/client/include/render/consoleeffect.h
Expand Up @@ -38,6 +38,9 @@ class ConsoleEffect
*/
int console() const;

virtual void glInit();
virtual void glDeinit();

virtual void draw(de::Rectanglei const &viewRect) = 0;

private:
Expand Down
45 changes: 45 additions & 0 deletions doomsday/client/include/render/fx/lensflares.h
@@ -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
1 change: 1 addition & 0 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -1897,6 +1897,7 @@ boolean DD_Init(void)
#ifdef __CLIENT__
GL_Init();
GL_InitRefresh();
LensFx_Init();
#endif

#ifdef __CLIENT__
Expand Down
13 changes: 12 additions & 1 deletion doomsday/client/src/render/cameralensfx.cpp
Expand Up @@ -20,6 +20,7 @@
#include "render/rend_main.h"
#include "render/viewports.h"
#include "render/fx/colorfilter.h"
#include "render/fx/lensflares.h"
#include "render/fx/vignette.h"

#include <de/libdeng2.h>
Expand Down Expand Up @@ -54,14 +55,24 @@ void LensFx_Init()
ConsoleEffectStack &stack = fxConsole[i];
stack.effects.append(new fx::ColorFilter(i));
stack.effects.append(new fx::Vignette(i));
//stack.effects.append(new LensFlareConsoleEffect(i));
stack.effects.append(new fx::LensFlares(i));

foreach(ConsoleEffect *effect, stack.effects)
{
effect->glInit();
}
}
}

void LensFx_Shutdown()
{
for(int i = 0; i < DDMAXPLAYERS; ++i)
{
foreach(ConsoleEffect *effect, fxConsole[i].effects)
{
effect->glDeinit();
}

fxConsole[i].clear();
}
}
Expand Down
6 changes: 6 additions & 0 deletions doomsday/client/src/render/consoleeffect.cpp
Expand Up @@ -35,3 +35,9 @@ int ConsoleEffect::console() const
{
return d->console;
}

void ConsoleEffect::glInit()
{}

void ConsoleEffect::glDeinit()
{}
117 changes: 117 additions & 0 deletions doomsday/client/src/render/fx/lensflares.cpp
@@ -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
1 change: 0 additions & 1 deletion doomsday/client/src/render/r_main.cpp
Expand Up @@ -87,7 +87,6 @@ void R_Init()
R_InitRawTexs();
R_InitSvgs();
#ifdef __CLIENT__
LensFx_Init();
Viewports_Init();
#endif
}
Expand Down

0 comments on commit aa098ef

Please sign in to comment.