QQuickFramebufferObject: where is the custom FBO used ? How can this cause flickering? - qtquick2

I am currently integrating a custom OpenGL viewport within QML via QQuickFramebufferObject. I observe some flickering of the whole app window (not only of the QQuickFramebufferObject window) and I am wondering why.
My custom QQuickFramebufferObject::Renderer does create a separate FPO:
QOpenGLFramebufferObject* OsgRenderer::createFramebufferObject(const QSize &size)
{
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
return new QOpenGLFramebufferObject(size, format);
}
So I understand that Qt defines its own FBO type (QOpenGLFramebufferObject) so it can later use the FBO to mix it with its own GL rendering, is that right?
I then do all my rendering
void OsgRenderer::render()
{
assert(m_osgItem);
if ( !m_osgItem->getViewer() )
return;
// Without this line the model is not displayed in the second
// and subsequent frames.
QOpenGLContext::currentContext()->functions()->glUseProgram(0);
// Ask OSG to render.
m_osgItem->getViewer()->frame(); // WARNING: non-blocking (executed in a thread of its own - in a thread-safe way).
// Reset OpenGl state for QtQuick.
m_osgItem->window()->resetOpenGLState();
}
I expect QtQuick to actually gather my custom rendered FBO with its own rendering of the window after the call to render(), is that right?
My rendering is actually achieved in a separate context. In this context, how can it cause flickering? Any idea?

Related

Change motion using script in Unity Editor

Hi how do we change motion in an AnimatorController using script in Unity Editor?
The red highlight is the one I'd like to change, but using script
My use case is to copy animations from one object, process the animation e.g. adding offset rotation, then add to another object. Since my object has many child objects, I need to create a script to automate this.
Changing the AnimatorController via editor scripts is always quite tricky!
First of all you need to have your AnimationClip from somewhere
// somewhere get the AnimationClip from
var clip = new AnimationClip();
Then you will have to cast the runtimeAnimatorController to an AnimatorController which is only available in the Editor! (put using UnityEditor; at the top of the script!)
var controller = (AnimatorController)animator.runtimeAnimatorController;
Now you can get all its information. In your case you can probably use the default layer (layers[0]) and its stateMachine and according to your image retrieve the defaultState:
var state = controller.layers[0].stateMachine.defaultState;
or find it using Linq FirstOrdefault (put using System.Linq; at the top of the script) like e.g.
var state = controller.layers[0].stateMachine.states.FirstOrDefault(s => s.state.name.Equals("SwimmingAnim")).state;
if (state == null)
{
Debug.LogError("Couldn't get the state!");
return;
}
Finally assign the AnimationClip to this state using SetStateEffectiveMotion
controller.SetStateEffectiveMotion(state, clip);
Note however that even though you can write individual animation curves for an animation clip using SetCurve unfortunately it is not possible to read them properly so it will be very difficult to do what you want
copy animations from one object, process the animation e.g. adding offset rotation, then add to another object.
You will have to go through AnimationUtility.GetCurveBindings which gets quite complex ;)
Good Luck!

QQuick + OpenSceneGraph flickering

I am using QQuickControls 2 (SwipeView) with OpenSceneGraph for the 3d rendering. Using QQuickFramebufferObject for the integration.
Since I have introduced a SwipeView, I observe some flickering of my GUI.
I have looked for ages in the doc (it probably sums literally up to weeks) and have absolutely no idea why I have this flickering.
Here is a video of the faulty behavior (flickering starts at ~20s).
And here is my rendering code:
class OsgRenderer : public QQuickFramebufferObject::Renderer
{
public:
explicit OsgRenderer();
QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) LC_OVERRIDE;
void synchronize(QQuickFramebufferObject* item) LC_OVERRIDE;
void render() LC_OVERRIDE;
protected:
friend class OsgWindow;
OsgItem* m_osgItem;
};
void OsgRenderer::render()
{
assert(m_osgItem);
if ( !m_osgItem->getViewer() )
return;
// Without this line the model is not displayed in the second
// and subsequent frames.
QOpenGLContext::currentContext()->functions()->glUseProgram(0);
// Ask OSG to render.
m_osgItem->getViewer()->frame(); // WARNING: non-blocking (executed in a thread of its own - in a thread-safe way).
// Reset OpenGl state for QtQuick.
m_osgItem->window()->resetOpenGLState();
}
Any idea of where that can come from?
In general it's not a good idea to have QtQuick and OSG both render to the same OpenGL context.
OSG it's keeping its GL state internally between frames, but Qt might modify it from "outside" without notifying osg, and this might cause rendering issues.
A more solid approach is have them use separate (and shared) GL context, and copy the context of the fbo osg redners to in a texture used by Qt.
I've successfully implemented this approach here: https://github.com/rickyviking/qmlosg
but haven't tested it with recent versions of QtQuick.
A more up-to-date integration can be found here: https://github.com/podsvirov/osgqtquick

How to find when GtkWidget was validated in Gtk+2

I need to know when a GtkWidget was redrawn and validated after I change it's content (schedule a redraw).
Is anyway to get whether it's redrawn complete or need to wait more to get redrawn.
The way to get around what you need is to delay the scroll until GTK knowns how big the scroll area is. Probably the easiest way is to use g_idle_add(). Call-backs added to it will be executed in priority order when there are no other tasks needed to be done. GTK does use the idle functions at a high priority to do its redraws, but a default priority should be OK for you.
gboolena my_delayed_function(gpointer user_data)
{
// The function that does the scroll goes here.
return FALSE;
}
void my_function_that_shows_something()
{
// Do some drawing.
// ...
// Schedule a scroll.
g_idle_add(my_delayed_function, NULL);
}
As a note you must return FALSE from that call-back otherwise it will be called repeatedly.

TTImageView shows black image (OR: replacement for TTImageView)

I'm using Three20's TTImageView for it's async image loading + caching.
I've noticed this issue a bunch of times where an image will show up as completely black, and never finish loading. Here's an example of what I'm seeing:
http://screencast.com/t/7O7fnedX5Z2
So...basically I'm wondering if this is a bug in three20, and if so, how I might go about fixing it (is there a patch out there that might fix it)...OR:
Is there a good TTImageView replacement that performs async image loading + caching?
Turns out I was seeing the following in my log:
TTRequestLoader connection:didReceiveResponse:: TTDASSERT failed: 0 == _queue.maxContentLength || contentLength <=_queue\
.maxContentLength
(one for each failed image)
After that, a little bit of googling rendered:
http://groups.google.com/group/three20/browse_thread/thread/8bfac3654a6d9674/caf797f265445971?pli=1
Jeff Verkoeyen:
The comment immediately before that
assert should shed some light on the
situation.
// If you hit this assertion it's because a massive file is about to be downloaded.
// If you're sure you want to do this, add the following line to your app delegate startup
// method. Setting the max content length to zero allows anything to go through. If you just
// want to raise the limit, set it to any positive byte size.
// [[TTURLRequestQueue mainQueue] setMaxContentLength:0]

OpenGL ES clarifying question regarding FBOs -- sorry can't find this info anywhere else?

If I instantiate an FBO without binding a rendering buffer or a texture to it, what happens when I draw to it, nothing?
Do I need to associate a rendering target (renderbuffer or texture) to have an FBO do anything? What I'm trying to do is precache some buffers and then merge them later, but that doesn't seem to work at all.
Ideally I'd like to do something like
glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo1);
// Draw some stuff to fbo1
glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo2);
// Draw some stuff to fbo2
// ...
// ...
// glRenderFbo(fbo1); -- Not a func
// Set blending, etc. etc.
// glRenderFbo(fbo2); -- Not a func
Yes, the answer is nothing. I'd like you to read my response to your other question.
How to merge two FBOs?