Skip to content

Commit

Permalink
libgui|GLFramebuffer: Use a Property to track the default sample count
Browse files Browse the repository at this point in the history
All existing GLFramebuffer instances observe the default sample count
and update their contents accordingly when it’s changed.
  • Loading branch information
skyjake committed Jan 14, 2014
1 parent 8d7272d commit fab3c29
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions doomsday/libgui/src/glframebuffer.cpp
Expand Up @@ -22,24 +22,11 @@
#include <de/Canvas>
#include <de/Drawable>
#include <de/GLInfo>
#include <de/Property>

namespace de {

struct DefaultSampleCount {
int samples;

DENG2_DEFINE_AUDIENCE(Change, void defaultSampleCountChanged())

DefaultSampleCount() : samples(1) {}
void set(int value) {
samples = value;
DENG2_FOR_AUDIENCE(Change, i) {
i->defaultSampleCountChanged();
}
}
};

static DefaultSampleCount defaultSampleCount;
DENG2_STATIC_PROPERTY(DefaultSampleCount, int)

DENG2_PIMPL(GLFramebuffer)
, DENG2_OBSERVES(DefaultSampleCount, Change)
Expand All @@ -65,17 +52,17 @@ DENG2_PIMPL(GLFramebuffer)
, uMvpMatrix("uMvpMatrix", GLUniform::Mat4)
, uBufTex ("uTex", GLUniform::Sampler2D)
{
defaultSampleCount.audienceForChange += this;
pDefaultSampleCount.audienceForChange += this;
}

~Instance()
{
defaultSampleCount.audienceForChange -= this;
pDefaultSampleCount.audienceForChange -= this;
}

int sampleCount() const
{
if(_samples <= 0) return defaultSampleCount.samples;
if(_samples <= 0) return pDefaultSampleCount;
return _samples;
}

Expand All @@ -89,7 +76,7 @@ DENG2_PIMPL(GLFramebuffer)
return sampleCount() > 1;
}

void defaultSampleCountChanged()
void valueOfDefaultSampleCountChanged()
{
reconfigure();
}
Expand Down Expand Up @@ -358,17 +345,17 @@ bool GLFramebuffer::setDefaultMultisampling(int sampleCount)
LOG_AS("GLFramebuffer");

int const newCount = max(1, sampleCount);
if(defaultSampleCount.samples != newCount)
if(pDefaultSampleCount != newCount)
{
defaultSampleCount.set(newCount);
pDefaultSampleCount = newCount;
return true;
}
return false;
}

int GLFramebuffer::defaultMultisampling()
{
return defaultSampleCount.samples;
return pDefaultSampleCount;
}

} // namespace de

0 comments on commit fab3c29

Please sign in to comment.