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
/******************************************************************************<br />
<br />
@File EAGLView.h<br />
<br />
@Title<br />
<br />
@Version<br />
<br />
@Copyright Copyright (c) Imagination Technologies Limited.<br />
<br />
@Platform<br />
<br />
@Description<br />
<br />
******************************************************************************/<br />
#ifndef _EAGLVIEW_H_<br />
#define _EAGLVIEW_H_<br />
<br />
<br />
#import <UIKit/UIKit.h><br />
#import <QCAR/UIGLViewProtocol.h><br />
<br />
#import <OpenGLES/EAGL.h><br />
#import <OpenGLES/EAGLDrawable.h><br />
<br />
#import <OpenGLES/ES2/gl.h><br />
#import <OpenGLES/ES2/glext.h><br />
<br />
#define MSAAx4 1<br />
<br />
//CONSTANTS<br />
const double c_TouchDistanceThreshold = 20.0;<br />
<br />
//CLASSES:<br />
<br />
@class EAGLView, QCARutils;<br />
<br />
//PROTOCOLS:<br />
<br />
@protocol EAGLViewDelegate <NSObject><br />
- (void) didResizeEAGLSurfaceForView:(EAGLView*)view; //Called whenever the EAGL surface has been resized<br />
@end<br />
<br />
//CLASS INTERFACE:<br />
<br />
/*<br />
This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.<br />
The view content is basically an EAGL surface you render your OpenGL scene into.<br />
Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.<br />
*/<br />
@interface EAGLView : UIView<br />
{<br />
<br />
@private<br />
NSString* _format;<br />
GLuint _depthFormat;<br />
BOOL _autoresize;<br />
EAGLContext *_context;<br />
GLuint _framebuffer;<br />
GLuint _renderbuffer;<br />
GLuint _depthBuffer;<br />
int _enableMSAA;<br />
int _enableFramebufferDiscard;<br />
GLuint _msaaMaxSamples;<br />
GLuint _msaaFrameBuffer;<br />
GLuint _msaaColourBuffer;<br />
GLuint _msaaDepthBuffer;<br />
CGSize _size;<br />
BOOL _hasBeenCurrent;<br />
id<EAGLViewDelegate> __unsafe_unretained _delegate;<br />
float _scale;<br />
}<br />
- (id) initWithFrame:(CGRect)frame; //These also set the current context<br />
- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format;<br />
- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained scale:(float)fscale msaaMaxSamples:(GLuint)maxSamples;<br />
<br />
@property(readonly) GLuint framebuffer;<br />
@property(readonly) NSString* pixelFormat;<br />
@property(readonly) GLuint depthFormat;<br />
@property(readonly) EAGLContext *context;<br />
<br />
@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<br />
@property(readonly, nonatomic) CGSize surfaceSize;<br />
<br />
@property (nonatomic, unsafe_unretained) id<EAGLViewDelegate> delegate;<br />
<br />
- (void) setCurrentContext;<br />
- (BOOL) isCurrentContext;<br />
- (void) clearCurrentContext;<br />
<br />
- (void) BeginRender;<br />
- (void) EndRender;<br />
- (void) swapBuffers; //This also checks the current OpenGL error and logs an error if needed<br />
<br />
- (CGPoint) convertPointFromViewToSurface:(CGPoint)point;<br />
- (CGRect) convertRectFromViewToSurface:(CGRect)rect;<br />
<br />
@end<br />
<br />
#endif // _EAGLVIEW_H_
```<br />
Note that I also erase the stencil buffer, since the bloom effect does not need one (right?). I also changed the default initWithFrame method:<br />
- (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<br />
[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...")<br />
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....")<br />
<br />
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.<br />
<br />
Anyway, if someone has the time and kindness to have a look https://www.dropbox.com/s/akbf6e4ib9jqgqe/AR_EAGL.zip<br />
Or to point me to the right direction, I've been hugely struggling with this.<br />
Thanks.