[android] fixed artifacts in alpha blending, switched off periodical updates to get rid of incorrect z-buffer bug.

This commit is contained in:
rachytski 2011-12-15 23:05:20 +04:00 committed by Alex Zolotarev
parent 43d96e441a
commit 6050c6af18
34 changed files with 186 additions and 171 deletions

View file

@ -78,7 +78,7 @@ namespace android
LOG(LDEBUG, ("AF::InitRenderer 1"));
yg::ResourceManager::Params rmParams;
rmParams.m_videoMemoryLimit = 15 * 1024 * 1024;
rmParams.m_videoMemoryLimit = 20 * 1024 * 1024;
rmParams.m_rtFormat = yg::Data8Bpp;
rmParams.m_texFormat = yg::Data4Bpp;

View file

@ -859,31 +859,11 @@ void InitNVEvent(JavaVM* vm)
"()Z",
(void *) onDestroyNative
},
{
"postUserEvent",
"(IIIIZ)Z",
(void *) postUserEvent
},
{
"touchEvent",
"(IIILandroid/view/MotionEvent;)Z",
(void *) NVEventTouchEvent
},
{
"multiTouchEvent",
"(IZZIIIILandroid/view/MotionEvent;)Z",
(void *) NVEventMultiTouchEvent
},
{
"keyEvent",
"(IIILandroid/view/KeyEvent;)Z",
(void *) NVEventKeyEvent
},
{
"accelerometerEvent",
"(FFF)Z",
(void *) NVEventAccelerometerEvent
},
};
jclass k;

View file

@ -275,17 +275,17 @@ public abstract class NvEventQueueActivity
}
/** The number of bits requested for the red component */
protected int redSize = 8;
protected int redSize = 5;
/** The number of bits requested for the green component */
protected int greenSize = 8;
protected int greenSize = 6;
/** The number of bits requested for the blue component */
protected int blueSize = 8;
protected int blueSize = 5;
/** The number of bits requested for the alpha component */
protected int alphaSize = 8;
protected int alphaSize = 0;
/** The number of bits requested for the stencil component */
protected int stencilSize = 8;
/** The number of bits requested for the depth component */
protected int depthSize = 24;
protected int depthSize = 16;
/** Attributes used when selecting the EGLConfig */
protected int[] configAttrs = null;

View file

@ -131,7 +131,7 @@
shared_ptr<DrawerYG> drawer = framework->GetRenderPolicy()->GetDrawer();
drawer->screen()->beginFrame();
drawer->screen()->clear();
drawer->screen()->clear(yg::gl::Screen::s_bgColor);
drawer->screen()->endFrame();
}

View file

@ -6,6 +6,7 @@
#include "../yg/internal/opengl.hpp"
#include "../yg/render_state.hpp"
#include "../yg/base_texture.hpp"
#include "../geometry/transformations.hpp"
@ -29,7 +30,7 @@ PartialRenderPolicy::PartialRenderPolicy(VideoTimer * videoTimer,
4,
true,
false,
1,
2,
"primaryStorage");
rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(2000 * sizeof(yg::gl::Vertex),
@ -39,11 +40,11 @@ PartialRenderPolicy::PartialRenderPolicy(VideoTimer * videoTimer,
4,
true,
false,
3,
1,
"smallStorage");
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::AuxVertex),
sizeof(yg::gl::AuxVertex),
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
10 * sizeof(unsigned short),
sizeof(unsigned short),
50,
@ -122,7 +123,7 @@ PartialRenderPolicy::PartialRenderPolicy(VideoTimer * videoTimer,
m_renderQueue.reset(new RenderQueue(GetPlatform().SkinName(),
false,
true,
false,
0.1,
false,
GetPlatform().ScaleEtalonSize(),
@ -216,10 +217,12 @@ void PartialRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & e,
{
m_currentPacket.m_state->m_isDebugging = m_IsDebugging;
m_currentPacket.m_state->apply(m_curState.get());
// OGLCHECK(glFinish());
m_curState = m_currentPacket.m_state;
}
m_currentPacket.m_command->setIsDebugging(m_IsDebugging);
m_currentPacket.m_command->perform();
// OGLCHECK(glFinish());
}
else
break;
@ -245,11 +248,11 @@ void PartialRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & e,
guard.Signal();
}
OGLCHECK(glFinish());
// OGLCHECK(glFinish());
m_state->apply(m_curState.get());
OGLCHECK(glFinish());
// OGLCHECK(glFinish());
/// blitting actualTarget
@ -264,6 +267,8 @@ void PartialRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & e,
if (m_renderQueue->renderState().m_actualTarget.get() != 0)
{
if (m_IsDebugging)
LOG(LINFO, ("actualTarget: ", m_renderQueue->renderState().m_actualTarget->id()));
m2::PointD const ptShift = m_renderQueue->renderState().coordSystemShift(false);
math::Matrix<double, 3, 3> m = m_renderQueue->renderState().m_actualScreen.PtoGMatrix() * s.GtoPMatrix();
@ -273,7 +278,6 @@ void PartialRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & e,
}
OGLCHECK(glFinish());
}
void PartialRenderPolicy::BeginFrame(shared_ptr<PaintEvent> const & paintEvent,

View file

@ -42,8 +42,8 @@ RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer,
5,
"smallStorage");
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::AuxVertex),
sizeof(yg::gl::AuxVertex),
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
10 * sizeof(unsigned short),
sizeof(unsigned short),
7,

View file

@ -41,8 +41,8 @@ RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer,
1,
"smallStorage");
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::AuxVertex),
sizeof(yg::gl::AuxVertex),
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
10 * sizeof(unsigned short),
sizeof(unsigned short),
50,

View file

@ -222,6 +222,7 @@ void RenderQueueRoutine::Do()
params.m_frameBuffer = m_frameBuffer;
params.m_renderState = m_renderState;
params.m_doPeriodicalUpdate = m_doPeriodicalUpdate;
params.m_auxFrameBuffer = m_auxFrameBuffer;
params.m_updateInterval = m_updateInterval;
params.m_skinName = m_skinName;
params.m_visualScale = m_visualScale;

View file

@ -42,8 +42,8 @@ TilingRenderPolicyMT::TilingRenderPolicyMT(VideoTimer * videoTimer,
1,
"smallStorage");
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::AuxVertex),
sizeof(yg::gl::AuxVertex),
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
10 * sizeof(unsigned short),
sizeof(unsigned short),
50,
@ -52,8 +52,8 @@ TilingRenderPolicyMT::TilingRenderPolicyMT(VideoTimer * videoTimer,
1,
"blitStorage");
rmp.m_multiBlitStoragesParams = yg::ResourceManager::StoragePoolParams(500 * sizeof(yg::gl::AuxVertex),
sizeof(yg::gl::AuxVertex),
rmp.m_multiBlitStoragesParams = yg::ResourceManager::StoragePoolParams(500 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
500 * sizeof(unsigned short),
sizeof(unsigned short),
10,

View file

@ -44,8 +44,8 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer,
1,
"smallStorage");
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::AuxVertex),
sizeof(yg::gl::AuxVertex),
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
10 * sizeof(unsigned short),
sizeof(unsigned short),
50,
@ -54,8 +54,8 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer,
1,
"blitStorage");
rmp.m_multiBlitStoragesParams = yg::ResourceManager::StoragePoolParams(500 * sizeof(yg::gl::AuxVertex),
sizeof(yg::gl::AuxVertex),
rmp.m_multiBlitStoragesParams = yg::ResourceManager::StoragePoolParams(500 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
500 * sizeof(unsigned short),
sizeof(unsigned short),
10,

View file

@ -69,4 +69,3 @@ SOURCES += \
video_timer.cpp \
http_request.cpp \
chunks_download_strategy.cpp \
pthread_video_timer.cpp \

View file

@ -1,16 +1,18 @@
#pragma once
#include "widgets.hpp"
//#include "widgets.hpp"
#include "../map/window_handle.hpp"
#include "../map/framework.hpp"
#include "../map/navigator.hpp"
#include "../map/qgl_render_context.hpp"
#include "../platform/video_timer.hpp"
#include "../std/scoped_ptr.hpp"
#include <QtCore/QTimer>
#include <QtOpenGL/qgl.h>
namespace qt
{

View file

@ -1,4 +1,4 @@
#include "widgets.hpp"
/*#include "widgets.hpp"
#include "../qt_tstfrm/widgets_impl.hpp"
@ -45,3 +45,4 @@ namespace qt
return m_resourceManager;
}
}
*/

View file

@ -1,7 +1,7 @@
#pragma once
#include "../qt_tstfrm/widgets.hpp"
#include "../map/qgl_render_context.hpp"
//#include "../qt_tstfrm/widgets.hpp"
/*#include "../map/qgl_render_context.hpp"
#include "../yg/resource_manager.hpp"
class DrawerYG;
@ -42,4 +42,4 @@ namespace qt
protected:
virtual void initializeGL();
};
}
}*/

View file

@ -110,7 +110,7 @@ public:
virtual void DoDraw(shared_ptr<yg::gl::Screen> p)
{
p->beginFrame();
p->clear();
p->clear(yg::gl::Screen::s_bgColor);
test.DoDraw(p);
p->endFrame();
}

View file

@ -21,3 +21,5 @@ SOURCES += \
main_tester.cpp \
tstwidgets.cpp \
screen_qt.cpp \

View file

@ -62,8 +62,8 @@ void GLDrawWidget::initializeGL()
1,
"smallStorage");
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::AuxVertex),
sizeof(yg::gl::AuxVertex),
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
10 * sizeof(unsigned short),
sizeof(unsigned short),
30,
@ -72,8 +72,8 @@ void GLDrawWidget::initializeGL()
1,
"blitStorage");
rmp.m_multiBlitStoragesParams = yg::ResourceManager::StoragePoolParams(500 * sizeof(yg::gl::AuxVertex),
sizeof(yg::gl::AuxVertex),
rmp.m_multiBlitStoragesParams = yg::ResourceManager::StoragePoolParams(500 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
500 * sizeof(unsigned short),
sizeof(unsigned short),
10,

View file

@ -3,21 +3,13 @@
#include "internal/opengl.hpp"
#include "base_texture.hpp"
#include "utils.hpp"
#include "../base/logging.hpp"
namespace yg
{
namespace gl
{
void BaseTexture::checkID() const
{
if (!m_hasID)
{
m_hasID = true;
init();
}
}
void BaseTexture::init() const
{
OGLCHECK(glGenTextures(1, &m_id));
@ -31,20 +23,20 @@ namespace yg
}
BaseTexture::BaseTexture(m2::PointU const & size)
: m_id(0), m_hasID(false), m_width(size.x), m_height(size.y)
: m_id(0), m_width(size.x), m_height(size.y)
{
// init();
init();
}
BaseTexture::BaseTexture(unsigned width, unsigned height)
: m_id(0), m_hasID(false), m_width(width), m_height(height)
: m_id(0), m_width(width), m_height(height)
{
// init();
init();
}
BaseTexture::~BaseTexture()
{
if ((m_hasID) && (g_doDeleteOnDestroy))
if (g_doDeleteOnDestroy)
OGLCHECK(glDeleteTextures(1, &m_id));
}
@ -60,7 +52,6 @@ namespace yg
void BaseTexture::attachToFrameBuffer()
{
checkID();
OGLCHECK(glFramebufferTexture2DFn(GL_FRAMEBUFFER_MWM,
GL_COLOR_ATTACHMENT0_MWM, GL_TEXTURE_2D, id(), 0));
utils::setupCoordinates(width(), height(), false);
@ -75,7 +66,6 @@ namespace yg
void BaseTexture::makeCurrent() const
{
checkID();
#ifndef OMIM_OS_ANDROID
if (current() != m_id)
#endif
@ -84,7 +74,6 @@ namespace yg
unsigned BaseTexture::id() const
{
checkID();
return m_id;
}

View file

@ -15,7 +15,6 @@ namespace yg
/// OpenGL texture ID
mutable unsigned m_id;
mutable bool m_hasID;
/// texture dimensions
/// @{
unsigned m_width;
@ -23,7 +22,6 @@ namespace yg
/// @}
void init() const;
void checkID() const;
public:

View file

@ -9,6 +9,7 @@
#include "utils.hpp"
#include "storage.hpp"
#include "vertex.hpp"
#include "defines.hpp"
#include "texture.hpp"
#include "../geometry/screenbase.hpp"
@ -49,6 +50,7 @@ namespace yg
m_texture = texture;
m_hasTexture = true;
m_hasColor = false;
m_color = yg::Color(255, 255, 255, 255);
m_resourceManager = rm;
}
@ -112,24 +114,26 @@ namespace yg
yg::gl::Storage storage = resourceManager()->multiBlitStorages()->Reserve();
AuxVertex * pointsData = (AuxVertex*)storage.m_vertices->lock();
Vertex * pointsData = (Vertex*)storage.m_vertices->lock();
for (size_t i = 0; i < s * 4; ++i)
{
pointsData[i].pt.x = geomPts[i].x;
pointsData[i].pt.y = geomPts[i].y;
pointsData[i].texPt.x = texPts[i].x;
pointsData[i].texPt.y = texPts[i].y;
pointsData[i].color = yg::Color(255, 255, 255, 255);
pointsData[i].depth = yg::maxDepth;
pointsData[i].tex.x = texPts[i].x;
pointsData[i].tex.y = texPts[i].y;
// pointsData[i].color = yg::Color(255, 255, 255, 255);
}
storage.m_vertices->unlock();
storage.m_vertices->makeCurrent();
setupAuxVertexLayout(false, true, storage.m_vertices->glPtr());
Vertex::setupLayout(storage.m_vertices->glPtr());
OGLCHECK(glDisable(GL_BLEND));
OGLCHECK(glDisable(GL_DEPTH_TEST));
OGLCHECK(glDepthMask(GL_FALSE));
memcpy(storage.m_indices->lock(), &idxData[0], idxData.size() * sizeof(unsigned short));
@ -147,6 +151,7 @@ namespace yg
OGLCHECK(glEnable(GL_DEPTH_TEST));
OGLCHECK(glEnable(GL_TEXTURE_2D));
OGLCHECK(glEnable(GL_BLEND));
OGLCHECK(glDepthMask(GL_TRUE));
// /// This call is necessary to avoid parasite blitting in updateActualTarget() on IPhone.
// OGLCHECK(glFinish());
@ -290,31 +295,6 @@ namespace yg
processCommand(command);
}
void Blitter::setupAuxVertexLayout(bool hasColor, bool hasTexture, void * glPtr)
{
OGLCHECK(glEnableClientState(GL_VERTEX_ARRAY));
OGLCHECK(glVertexPointer(2, GL_FLOAT, sizeof(AuxVertex), (void*)((char*)glPtr + AuxVertex::vertexOffs)));
if (hasColor)
{
OGLCHECK(glEnableClientState(GL_COLOR_ARRAY));
OGLCHECK(glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(AuxVertex), (void*)((char*)glPtr + AuxVertex::colorOffs)));
}
else
OGLCHECK(glDisableClientState(GL_COLOR_ARRAY));
if (hasTexture)
{
OGLCHECK(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
OGLCHECK(glTexCoordPointer(2, GL_FLOAT, sizeof(AuxVertex), (void*)((char*)glPtr + AuxVertex::texCoordsOffs)));
}
else
{
OGLCHECK(glDisableClientState(GL_TEXTURE_COORD_ARRAY));
OGLCHECK(glDisable(GL_TEXTURE_2D));
}
}
void Blitter::IMMDrawTexturedPrimitives::perform()
{
if (isDebugging())
@ -327,36 +307,43 @@ namespace yg
if (!blitStorage.m_indices->isLocked())
blitStorage.m_indices->lock();
AuxVertex * pointsData = (AuxVertex*)blitStorage.m_vertices->data();
Vertex * pointsData = (Vertex*)blitStorage.m_vertices->data();
for (size_t i = 0; i < m_ptsCount; ++i)
{
pointsData[i].pt.x = m_pts[i].x;
pointsData[i].pt.y = m_pts[i].y;
pointsData[i].texPt.x = m_texPts[i].x;
pointsData[i].texPt.y = m_texPts[i].y;
pointsData[i].color = m_color;
pointsData[i].depth = yg::maxDepth;
pointsData[i].tex.x = m_texPts[i].x;
pointsData[i].tex.y = m_texPts[i].y;
}
blitStorage.m_vertices->unlock();
blitStorage.m_vertices->makeCurrent();
Blitter::setupAuxVertexLayout(m_hasColor, m_hasTexture, blitStorage.m_vertices->glPtr());
Vertex::setupLayout(blitStorage.m_vertices->glPtr());
if (m_texture)
{
OGLCHECK(glEnable(GL_TEXTURE_2D));
m_texture->makeCurrent();
}
unsigned short idxData[4] = {0, 1, 2, 3};
memcpy(blitStorage.m_indices->data(), idxData, sizeof(idxData));
blitStorage.m_indices->unlock();
blitStorage.m_indices->makeCurrent();
OGLCHECK(glDisable(GL_ALPHA_TEST));
OGLCHECK(glDisable(GL_BLEND));
OGLCHECK(glDisable(GL_DEPTH_TEST));
OGLCHECK(glDepthMask(GL_FALSE));
OGLCHECK(glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, blitStorage.m_indices->glPtr()));
OGLCHECK(glDepthMask(GL_TRUE));
OGLCHECK(glEnable(GL_DEPTH_TEST));
OGLCHECK(glEnable(GL_TEXTURE_2D));
OGLCHECK(glEnable(GL_BLEND));
OGLCHECK(glEnable(GL_ALPHA_TEST));
// /// This call is necessary to avoid parasite blitting in updateActualTarget() on IPhone.
// OGLCHECK(glFinish());

View file

@ -36,8 +36,6 @@ namespace yg
yg::gl::Storage m_blitStorage;
static void setupAuxVertexLayout(bool hasColor, bool hasTexture, void * glPtr);
protected:
typedef Clipper base_t;

View file

@ -2,7 +2,7 @@
namespace yg
{
static const int maxDepth = 12000;
static const int maxDepth = 20000;
enum EPosition
{

View file

@ -2,6 +2,7 @@
#include "framebuffer.hpp"
#include "render_target.hpp"
#include "renderbuffer.hpp"
#include "internal/opengl.hpp"
#include "utils.hpp"
@ -40,20 +41,38 @@ namespace yg
#ifndef OMIM_OS_ANDROID
if (m_id != current())
#endif
{
OGLCHECK(glBindFramebufferFn(GL_FRAMEBUFFER_MWM, m_id));
// LOG(LINFO, ("FrameBuffer::makeCurrent", m_id));
}
if (m_renderTarget)
m_renderTarget->attachToFrameBuffer();
else
{
if (m_id != 0)
OGLCHECK(glFramebufferRenderbufferFn(
GL_FRAMEBUFFER_MWM,
GL_COLOR_ATTACHMENT0_MWM,
GL_RENDERBUFFER_MWM,
0));
utils::setupCoordinates(width(), height(), true);
}
if (m_depthBuffer)
m_depthBuffer->attachToFrameBuffer();
else
{
if (m_id != 0)
OGLCHECK(glFramebufferRenderbufferFn(
GL_FRAMEBUFFER_MWM,
GL_DEPTH_ATTACHMENT_MWM,
GL_RENDERBUFFER_MWM,
0));
}
/// !!! it's a must for a correct work.
checkStatus();
/// update: it was necessary for multisampling,
/// but without it on KindleFire this function produces bug
/* if (m_id != 0)
checkStatus();*/
}
void FrameBuffer::setRenderTarget(shared_ptr<RenderTarget> const & renderTarget)
@ -71,12 +90,12 @@ namespace yg
m_renderTarget.reset();
}
void FrameBuffer::setDepthBuffer(shared_ptr<RenderTarget> const & depthBuffer)
void FrameBuffer::setDepthBuffer(shared_ptr<RenderBuffer> const & depthBuffer)
{
m_depthBuffer = depthBuffer;
}
shared_ptr<RenderTarget> const & FrameBuffer::depthBuffer() const
shared_ptr<RenderBuffer> const & FrameBuffer::depthBuffer() const
{
return m_depthBuffer;
}
@ -110,6 +129,7 @@ namespace yg
void FrameBuffer::checkStatus()
{
GLenum res = glCheckFramebufferStatusFn(GL_FRAMEBUFFER_MWM);
OGLCHECKAFTER;
if (res == GL_FRAMEBUFFER_UNSUPPORTED_MWM)
LOG(LINFO, ("unsupported combination of attached target formats. could be possibly skipped"));
else if (res == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_MWM)

View file

@ -17,7 +17,7 @@ namespace yg
unsigned int m_id;
shared_ptr<RenderTarget> m_renderTarget;
shared_ptr<RenderTarget> m_depthBuffer;
shared_ptr<RenderBuffer> m_depthBuffer;
unsigned m_width;
unsigned m_height;
@ -33,8 +33,8 @@ namespace yg
shared_ptr<RenderTarget> const & renderTarget() const;
void resetRenderTarget();
void setDepthBuffer(shared_ptr<RenderTarget> const & depthBuffer);
shared_ptr<RenderTarget> const & depthBuffer() const;
void setDepthBuffer(shared_ptr<RenderBuffer> const & depthBuffer);
shared_ptr<RenderBuffer> const & depthBuffer() const;
void resetDepthBuffer();
void makeCurrent();

View file

@ -152,7 +152,7 @@ namespace yg
void enableClipRect(bool flag);
void setClipRect(m2::RectI const & rect);
void clear(yg::Color const & c = yg::Color(187, 187, 187, 255), bool clearRT = true, float depth = 1.0, bool clearDepth = true);
void clear(yg::Color const & c, bool clearRT = true, float depth = 1.0, bool clearDepth = true);
/// @}
void setRenderTarget(shared_ptr<RenderTarget> const & rt);

View file

@ -2,8 +2,10 @@
#include "render_state_updater.hpp"
#include "render_state.hpp"
#include "renderbuffer.hpp"
#include "framebuffer.hpp"
#include "base_texture.hpp"
#include "utils.hpp"
#include "internal/opengl.hpp"
@ -21,9 +23,12 @@ namespace yg
RenderStateUpdater::RenderStateUpdater(Params const & params)
: base_t(params),
m_renderState(params.m_renderState),
m_auxFrameBuffer(params.m_auxFrameBuffer),
m_doPeriodicalUpdate(params.m_doPeriodicalUpdate),
m_updateInterval(params.m_updateInterval)
{
if ((m_doPeriodicalUpdate) && (!m_auxFrameBuffer))
m_auxFrameBuffer.reset(new FrameBuffer());
}
shared_ptr<RenderState> const & RenderStateUpdater::renderState() const
@ -51,6 +56,9 @@ namespace yg
void RenderStateUpdater::UpdateActualTarget::perform()
{
if (isDebugging())
LOG(LINFO, ("performing UpdateActualTarget command"));
OGLCHECK(glFinish());
if (m_doSynchronize)
@ -75,7 +83,13 @@ namespace yg
OGLCHECK(glDisable(GL_SCISSOR_TEST));
OGLCHECK(glClearColor(192 / 255.0, 192 / 255.0, 192 / 255.0, 1.0));
m_auxFrameBuffer->setRenderTarget(m_renderState->m_backBuffer);
m_auxFrameBuffer->makeCurrent();
OGLCHECK(glClearColor(s_bgColor.r / 255.0,
s_bgColor.g / 255.0,
s_bgColor.b / 255.0,
s_bgColor.a / 255.0));
OGLCHECK(glClear(GL_COLOR_BUFFER_BIT));
@ -85,8 +99,11 @@ namespace yg
m_renderState->m_actualTarget,
m_resourceManager));
immDrawTexturedRect->setIsDebugging(isDebugging());
immDrawTexturedRect->perform();
m_frameBuffer->makeCurrent();
if (m_isClipRectEnabled)
OGLCHECK(glEnable(GL_SCISSOR_TEST));
@ -123,9 +140,9 @@ namespace yg
command1->m_resourceManager = resourceManager();
command1->m_isClipRectEnabled = clipRectEnabled();
command1->m_doSynchronize = renderQueue();
command1->m_auxFrameBuffer = m_auxFrameBuffer;
command1->m_frameBuffer = frameBuffer();
/// blitting will be performed through
/// non-multisampled framebuffer for the sake of speed
setRenderTarget(m_renderState->m_shadowBackBuffer);
m_renderState->m_mutex->Unlock();

View file

@ -19,6 +19,7 @@ namespace yg
typedef GeometryRenderer base_t;
shared_ptr<RenderState> m_renderState;
shared_ptr<FrameBuffer> m_auxFrameBuffer;
int m_indicesCount;
bool m_doPeriodicalUpdate;
@ -38,6 +39,8 @@ namespace yg
{
shared_ptr<RenderState> m_renderState;
shared_ptr<ResourceManager> m_resourceManager;
shared_ptr<FrameBuffer> m_auxFrameBuffer;
shared_ptr<FrameBuffer> m_frameBuffer;
bool m_isClipRectEnabled;
bool m_doSynchronize;
@ -57,6 +60,7 @@ namespace yg
bool m_doPeriodicalUpdate;
double m_updateInterval;
shared_ptr<RenderState> m_renderState;
shared_ptr<FrameBuffer> m_auxFrameBuffer;
Params();
};

View file

@ -21,12 +21,13 @@ namespace yg
return id;
}
void RenderBuffer::checkID() const
RenderBuffer::RenderBuffer(size_t width, size_t height, bool isDepthBuffer)
: m_id(0), m_isDepthBuffer(isDepthBuffer), m_width(width), m_height(height)
{
if (!m_hasID)
// if (!m_isDepthBuffer)
{
m_hasID = true;
OGLCHECK(glGenRenderbuffersFn(1, &m_id));
makeCurrent();
GLenum target = GL_RENDERBUFFER_MWM;
@ -37,35 +38,56 @@ namespace yg
m_width,
m_height));
}
}
/* else
{
OGLCHECK(glGenTextures(1, &m_id));
RenderBuffer::RenderBuffer(size_t width, size_t height, bool isDepthBuffer)
: m_hasID(false), m_id(0), m_isDepthBuffer(isDepthBuffer), m_width(width), m_height(height)
{}
OGLCHECK(glBindTexture(GL_TEXTURE_2D, m_id));
OGLCHECK(glTexImage2D(GL_TEXTURE_2D,
0,
GL_DEPTH_COMPONENT24_MWM,
m_width,
m_height,
0,
GL_DEPTH_COMPONENT24_MWM,
GL_UNSIGNED_INT_24_8_MWM,
0));
}*/
}
RenderBuffer::~RenderBuffer()
{
if ((m_hasID) && (g_doDeleteOnDestroy))
if (g_doDeleteOnDestroy)
{
OGLCHECK(glDeleteRenderbuffersFn(1, &m_id));
// if(m_isDepthBuffer)
// OGLCHECK(glDeleteTextures(1, &m_id));
// else
OGLCHECK(glDeleteRenderbuffersFn(1, &m_id));
}
}
unsigned int RenderBuffer::id() const
{
checkID();
return m_id;
}
void RenderBuffer::attachToFrameBuffer()
{
checkID();
OGLCHECK(glFramebufferRenderbufferFn(
GL_FRAMEBUFFER_MWM,
isDepthBuffer() ? GL_DEPTH_ATTACHMENT_MWM : GL_COLOR_ATTACHMENT0_MWM,
GL_RENDERBUFFER_MWM,
id()));
/* if (m_isDepthBuffer)
OGLCHECK(glFramebufferTexture2DFn(
GL_FRAMEBUFFER_MWM,
GL_DEPTH_ATTACHMENT_MWM,
GL_TEXTURE_2D,
id(),
0
));
else*/
OGLCHECK(glFramebufferRenderbufferFn(
GL_FRAMEBUFFER_MWM,
isDepthBuffer() ? GL_DEPTH_ATTACHMENT_MWM : GL_COLOR_ATTACHMENT0_MWM,
GL_RENDERBUFFER_MWM,
id()));
if (!isDepthBuffer())
utils::setupCoordinates(width(), height(), false);
@ -73,7 +95,6 @@ namespace yg
void RenderBuffer::makeCurrent() const
{
checkID();
#ifndef OMIM_OS_ANDROID
if (m_id != current())
#endif

View file

@ -11,15 +11,12 @@ namespace yg
{
private:
mutable bool m_hasID;
mutable unsigned int m_id;
bool m_isDepthBuffer;
size_t m_width;
size_t m_height;
void checkID() const;
public:
RenderBuffer(size_t width, size_t height, bool isDepthBuffer = false);

View file

@ -11,6 +11,8 @@ namespace yg
{
namespace gl
{
const yg::Color Renderer::s_bgColor(192, 192, 192, 255);
Renderer::BaseState::BaseState()
: m_isDebugging(false)
{}
@ -271,12 +273,12 @@ namespace yg
}
}
shared_ptr<RenderTarget> const & Renderer::depthBuffer() const
shared_ptr<RenderBuffer> const & Renderer::depthBuffer() const
{
return m_depthBuffer;
}
void Renderer::setDepthBuffer(shared_ptr<RenderTarget> const & rt)
void Renderer::setDepthBuffer(shared_ptr<RenderBuffer> const & rt)
{
m_depthBuffer = rt;
@ -304,6 +306,8 @@ namespace yg
if (m_clearDepth)
mask |= GL_DEPTH_BUFFER_BIT;
OGLCHECK(glDepthMask(GL_TRUE));
OGLCHECK(glClear(mask));
}

View file

@ -33,7 +33,7 @@ namespace yg
{
shared_ptr<FrameBuffer> m_frameBuffer;
shared_ptr<RenderTarget> m_renderTarget;
shared_ptr<RenderTarget> m_depthBuffer;
shared_ptr<RenderBuffer> m_depthBuffer;
shared_ptr<ResourceManager> m_resourceManager;
void apply(BaseState const * prev);
@ -96,7 +96,7 @@ namespace yg
shared_ptr<FrameBuffer> m_frameBuffer;
shared_ptr<RenderTarget> m_renderTarget;
shared_ptr<RenderTarget> m_depthBuffer;
shared_ptr<RenderBuffer> m_depthBuffer;
shared_ptr<ResourceManager> m_resourceManager;
ThreadedList<Packet> * m_renderQueue;
@ -110,6 +110,8 @@ namespace yg
public:
static const yg::Color s_bgColor;
Renderer(Params const & params = Params());
void beginFrame();
@ -124,15 +126,15 @@ namespace yg
void setRenderTarget(shared_ptr<RenderTarget> const & rt);
shared_ptr<RenderTarget> const & renderTarget() const;
void setDepthBuffer(shared_ptr<RenderTarget> const & rt);
shared_ptr<RenderTarget> const & depthBuffer() const;
void setDepthBuffer(shared_ptr<RenderBuffer> const & rt);
shared_ptr<RenderBuffer> const & depthBuffer() const;
/// @param clearRT - should we clear the renderTarget data (visible pixels)?
/// @param clearDepth - should we clear depthBuffer data?
/// @warning this function respects the clipping rect set and enabled(!)
/// by the setClipRect/enableClipRect. Whether the clipping is
/// not enabled - the entire currently bound render surface is used.
void clear(yg::Color const & c = yg::Color(187, 187, 187, 255), bool clearRT = true, float depth = 1.0, bool clearDepth = true);
void clear(yg::Color const & c, bool clearRT = true, float depth = 1.0, bool clearDepth = true);
void onSize(unsigned width, unsigned height);

View file

@ -25,16 +25,5 @@ namespace yg
static void setupLayout(void * glPtr);
};
struct AuxVertex
{
m2::PointF pt;
m2::PointF texPt;
yg::Color color;
static const int vertexOffs = 0;
static const int texCoordsOffs = sizeof(m2::PointF);
static const int colorOffs = sizeof(m2::PointF) + sizeof(m2::PointF);
};
}
}

View file

@ -383,7 +383,7 @@ namespace
p->beginFrame();
p->setClipRect(r);
p->enableClipRect(true);
p->clear();
p->clear(yg::gl::Screen::s_bgColor);
}
};

View file

@ -28,7 +28,7 @@ namespace
for (size_t i = 0; i < 30; ++i)
{
m_pScreen->beginFrame();
m_pScreen->clear();
m_pScreen->clear(yg::gl::Screen::s_bgColor);
m_pScreen->immDrawRect(
m2::RectF(i * 15 + 20, 10, i * 15 + 30, 20),
m2::RectF(),
@ -59,7 +59,7 @@ namespace
for (size_t i = 0; i < 30; ++i)
{
p->beginFrame();
p->clear();
p->clear(yg::gl::Screen::s_bgColor);
p->immDrawSolidRect(
m2::RectF(i * 15 + 20, 30, i * 15 + 30, 40),
yg::Color(0, 0, 255, (globalCounter++) * (255 / 60) ));