How could I implement the bloom sample in EAGLView without the PVRShell ?

This topic contains 4 replies, has 2 voices, and was last updated by  penumbra 4 years, 5 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #31247

    penumbra
    Member

    Hello.
    I’m working on an AR application and I can’t render my object properly: I want it to receive the bloom effect from the samples, but if the object is rendered and textured, the camera capture behind disappeared (black screen) and there is no bloom effect.

    So my question is fairly simple : How does the cpp sample renders to the EAGLView, I know the PVRShell is involved somewhere, but how? To be more specific: I tried to implement the EAGLView by getting rid of everything that is tied to the PVRShell because I have to implement the UIGLViewProtocol provided by vuforia, it has a single method which sync the GL render to the AR calculations, which give me that header file

    /******************************************************************************

    @File EAGLView.h

    @Title

    @Version

    @Copyright Copyright (c) Imagination Technologies Limited.

    @Platform

    @Description

    ******************************************************************************/
    #ifndef _EAGLVIEW_H_
    #define _EAGLVIEW_H_


    #import
    #import

    #import
    #import


    #import

    #import


    #define MSAAx4 1

    //CONSTANTS
    const double c_TouchDistanceThreshold = 20.0;

    //CLASSES:

    @class EAGLView, QCARutils;

    //PROTOCOLS:

    @protocol EAGLViewDelegate
    - (void) didResizeEAGLSurfaceForView:(EAGLView*)view; //Called whenever the EAGL surface has been resized
    @end

    //CLASS INTERFACE:

    /*
    This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
    The view content is basically an EAGL surface you render your OpenGL scene into.
    Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
    */
    @interface EAGLView : UIView
    {

    @private
    NSString* _format;
    GLuint _depthFormat;
    BOOL _autoresize;
    EAGLContext *_context;
    GLuint _framebuffer;
    GLuint _renderbuffer;
    GLuint _depthBuffer;
    int _enableMSAA;
    int _enableFramebufferDiscard;
    GLuint _msaaMaxSamples;
    GLuint _msaaFrameBuffer;
    GLuint _msaaColourBuffer;
    GLuint _msaaDepthBuffer;
    CGSize _size;
    BOOL _hasBeenCurrent;
    id __unsafe_unretained _delegate;
    float _scale;
    }
    - (id) initWithFrame:(CGRect)frame; //These also set the current context
    - (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format;
    - (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained scale:(float)fscale msaaMaxSamples:(GLuint)maxSamples;

    @property(readonly) GLuint framebuffer;
    @property(readonly) NSString* pixelFormat;
    @property(readonly) GLuint depthFormat;
    @property(readonly) EAGLContext *context;

    @property BOOL autoresizesSurface; //NO by default - Set to YES to have the EAGL surface automatically resized when the view bounds change, otherwise the EAGL surface contents is rendered scaled
    @property(readonly, nonatomic) CGSize surfaceSize;

    @property (nonatomic, unsafe_unretained) id
    delegate;

    - (void) setCurrentContext;
    - (BOOL) isCurrentContext;
    - (void) clearCurrentContext;

    - (void) BeginRender;
    - (void) EndRender;
    - (void) swapBuffers; //This also checks the current OpenGL error and logs an error if needed

    - (CGPoint) convertPointFromViewToSurface:(CGPoint)point;
    - (CGRect) convertRectFromViewToSurface:(CGRect)rect;

    @end

    #endif // _EAGLVIEW_H_

    Note that I also erase the stencil buffer, since the bloom effect does not need one (right?). I also changed the default initWithFrame method:

    - (id) initWithFrame:(CGRect)frame
    {
    return [self initWithFrame:frame pixelFormat:kEAGLColorFormatRGBA8 depthFormat:GL_DEPTH_COMPONENT24_OES preserveBackbuffer:NO scale:1.0f msaaMaxSamples:0];
    }

    So I can simply add the view in a UIViewController with [[UIView alloc] initWithFrame: viewBounds]. I have no error when trying to implement the renderFrameQCAR mehod with this

    [self BeginRender];

    // Clear colour and depth buffers
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Retrieve tracking state and render video background and
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    QCAR::Renderer::getInstance().drawVideoBackground();

    QCAR::Renderer::getInstance().end();
    //[self swapBuffers];
    [self EndRender];

    Nothing is drawn, when I run Instrument, I have a severe “Present of Non-Existent Renderbuffer” (“Your application attempted to present a non-existent renderbuffer…”)
    When calling the swapBuffers method, I have an “Uninitialized Color Attachment” warning (“Your application presented a renderbuffer, but did not render content to all pixels in the renderbuffer….”)

    My questions are all tied to my misunderstanding of how the EAGLView _framebuffer, _renderBuffer and _depthbuffer communicate with the other buffers used in the samples. I also tried to extend the PVR EAGLView, merge the Bloom sample in it, use it on a view controller and prayed that some kind of magic will present an existing renderbuffer or fill the color attachment, but I end up with a “Present of Not Layer Backed Renderbuffer”, basically saying that the “renderbufferStorage:fromDrawable” is not called.

    Anyway, if someone has the time and kindness to have a look https://www.dropbox.com/s/akbf6e4ib9jqgqe/AR_EAGL.zip
    Or to point me to the right direction, I’ve been hugely struggling with this.
    Thanks.

    #37170

    Arron
    Member

    Hi,

    I’ve looked through your code and couldn’t see anything which seemed obviously incorrect.
    The 3 variables you mentioned in the EAGLView class (_renderBuffer, _depthBuffer and _frameBuffer) are for OS usage. On iOS, developers are required to render to a user-initialised renderbuffer/framebuffer which is then passed to UIKit and composited by the OS. The Bloom example doesn’t use these variables directly – they should be used only in EAGLView code however they are essentially the frame buffer which your application should write to. The Bloom example uses several framebuffer objects in order to implement the technique which require similar handles and function calls. This could be the cause of your issue having incorrect framebuffers bound at a particular point in time. It’s hard to determine the exact problem in your case just by reading the code but my suggestion would be to inspect the handle ID’s of _renderBuffer and _frameBuffer when they are initialised and then in the calls to swapBuffer and/or EndRender to verify that the same handles are bound.

    Does you application work correctly with no Bloom code implemented at all? Could it be that the AR library is setting an incorrect GL state?

    #37171

    penumbra
    Member

    Hi Arron. Thank you for an answer I was not expecting anymore.
    Given tests I’ve made, I think you’re probably right when you say that my problem rests on the AR lib. So for debug purposes I just forgot my AR_EAGLView extends and used the EAGLView, implemented the UIGLViewProtocol so I have a renderFrameQCAR. Given that I just had warnings saying that I have uninitialized pixels (“MSAA Resolve of Uninitialized Color Attachment” if I use AA, “Present of uninitialized color attachment” if not), because nothing is drawn. OK…

    If I now call the method that is supposed to draw my video background, I have the exact same warnings coming from the EndRender method…

        [self BeginRender];

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // draw video background
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    QCAR::Renderer::getInstance().drawVideoBackground();

    QCAR::Renderer::getInstance().end();

    [self EndRender];

    which brings me back to zero. Either my code is wrong, or the QCAR does not guess, find the correct renderBuffer it’s supposed to draw on… which means my code is wrong… You talked about inspecting the handle ID’s, how can I do that ? I also looked the EAGLView from the QCAR samples and it basically follows the same procedure I’m trying to grab from your’s, so I will be surprised if it comes from QCAR. Anyway, here is the last EAGLView I’m working with :https://www.dropbox.com/s/6yxqhhs2guf1l1h/EAGLView.mm

    Thank you.

    #37172

    Arron
    Member

    Hi.

    What happens if you just strip your code back-to-basics? Call glClearColor(1.0f,0.0f,0.0f,1.0f); to set the clear colour to red, and remove the QCAR::* calls. If this still fails and you see nothing there’s some error somewhere in the EAGLView code which needs to be solved.

    Try dropping some NSLog(@”Framebuffer binding: %dn”, _framebuffer); calls in strategic places in the render code for instance _createSurface or BeginRender and then in EndRender call glGetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer); and make sure ‘_framebuffer’ and ‘framebuffer’ are the same.

    Also check that _hasBeenCurrent is initialised to NO somewhere otherwise the call to glViewport will never be called.

    #37173

    penumbra
    Member

    Hey Arron, thanks for your insightful feedback and sorry for my very late reply.
    It was probably something messy with the default frame buffer since I have not been able to draw anything on it and always ended with an empty frame buffer error. Somehow, somewhere, I was missing something… Since I’m not that skilled with OpenGL I decided to use a GLKViewController and TADAH, the rest went smoothly. Thanks for pointing the origin of my problem and let’s call that post answered…

Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic.