自从更新到iOS 9以来,不再呈现overlaySKScene.没有调用每帧 *** 作(update:,dIDEvaluateActions,…).
它适用于iOS 8,同样的SKScene仍然可以在同一个应用程序中的不同视图控制器中使用SCNVIEw.
上下文设置:
self.context = [[EAGLContext alloc] initWithAPI:context.API sharegroup:scnVIEwContext.sharegroup];
OpenGL初始化(主要从Vuforia样本复制):
- (voID)createFramebuffer{ if (self.context) { // Create default framebuffer object glGenFramebuffers(1,&_defaultFramebuffer); glBindFramebuffer(GL_FRAMEBUFFER,self.defaultFramebuffer); // Create colour renderbuffer and allocate backing store glGenRenderbuffers(1,&_colorRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER,self.colorRenderbuffer); // Allocate the renderbuffer's storage (shared with the drawable object) [self.context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer]; Glint framebufferWIDth; Glint framebufferHeight; glGetRenderbufferParameteriv(GL_RENDERBUFFER,GL_RENDERBUFFER_WIDTH,&framebufferWIDth); glGetRenderbufferParameteriv(GL_RENDERBUFFER,GL_RENDERBUFFER_HEIGHT,&framebufferHeight); // Create the depth render buffer and allocate storage glGenRenderbuffers(1,&_depthRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER,self.depthRenderbuffer); glrenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT16,framebufferWIDth,framebufferHeight); // Attach colour and depth render buffers to the frame buffer glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_color_ATTACHMENT0,GL_RENDERBUFFER,self.colorRenderbuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,self.depthRenderbuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,self.stencilRenderbuffer); // Leave the colour render buffer bound so future rendering operations will act on it glBindRenderbuffer(GL_RENDERBUFFER,self.colorRenderbuffer); }}- (voID)setFramebuffer{ // The EAGLContext must be set for each thread that wishes to use it. Set // it the first time this method is called (on the render thread) if (self.context != [EAGLContext currentContext]) { [EAGLContext setCurrentContext:self.context]; } if (!self.defaultFramebuffer) { // Perform on the main thread to ensure safe memory allocation for the // shared buffer. Block until the operation is complete to prevent // simultaneous access to the OpenGL context [self performSelectorOnMainThread:@selector(createFramebuffer) withObject:self waitUntilDone:YES]; } glBindFramebuffer(GL_FRAMEBUFFER,self.defaultFramebuffer);}- (BOol)presentFramebuffer{ // setFramebuffer must have been called before presentFramebuffer,therefore // we kNow the context is valID and has been set for this (render) thread // Bind the colour render buffer and present it glBindRenderbuffer(GL_RENDERBUFFER,self.colorRenderbuffer); return [self.context presentRenderbuffer:GL_RENDERBUFFER];}
SCNRenderer设置:
self.skScene = [[MarkerOverlayScene alloc] initWithSize:CGSizeMake(2048,2048)];self.renderer = [SCNRenderer rendererWithContext:self.context options:nil];self.renderer.autoenablesDefaultlighting = NO;self.renderer.delegate = self;self.renderer.overlaySKScene = self.skScene;self.renderer.playing = YES;if (self.sceneURL) { self.renderer.scene = [SCNScene sceneWithURL:self.sceneURL options:nil error:nil]; [self.renderer prepareObjects:@[self.renderer.scene] withCompletionHandler:^(BOol success) { }];}
Vuforia渲染回调:
- (voID)renderFrameQCAR{ [self setFramebuffer]; // Clear colour and depth buffers glClear(GL_color_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Render vIDeo background and retrIEve tracking state QCAR::State state = QCAR::Renderer::getInstance().begin(); QCAR::Renderer::getInstance().drawVIDeoBackground(); glEnable(GL_DEPTH_TEST); glEnable(GL_CulL_FACE); glCullFace(GL_BACK); if(QCAR::Renderer::getInstance().getVIDeoBackgroundConfig().mReflection == QCAR::VIDEO_BACKGROUND_REFLECTION_ON) { glFrontFace(GL_CW); //Front camera } else { glFrontFace(GL_ccw); //Back camera } for (int i = 0; i < state.getNumTrackableResults(); ++i) { // Get the trackable const QCAR::TrackableResult* result = state.getTrackableResult(i); QCAR::Matrix44F modelVIEwMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose()); SCNMatrix4 matrix = [self convertARMatrix:modelVIEwMatrix]; matrix = SCNMatrix4Mult(SCNMatrix4MakeRotation(M_PI_2,1,0),matrix); matrix = SCNMatrix4Mult(SCNMatrix4MakeScale(10,10,10),matrix); self.artransform = matrix; } if (state.getNumTrackableResults() == 0) { self.artransform = SCNMatrix4IDentity; } [self.renderer renderAtTime:CFabsoluteTimeGetCurrent() - self.startTime]; gldisable(GL_DEPTH_TEST); gldisable(GL_CulL_FACE); QCAR::Renderer::getInstance().end(); [self presentFramebuffer];}解决方法 与skScene混淆.设置.当我切换到ios9时,没有任何接触通过.我不得不添加skScene.userInteractionEnabled = NO;这在iOS8中是不需要的.我猜默认值已更改或将其设置为叠加层不再更改默认值.
无论如何,问题可能在于skScene设置.
总结以上是内存溢出为你收集整理的ios – 使用SCNRenderer时不呈现overlaySKScene全部内容,希望文章能够帮你解决ios – 使用SCNRenderer时不呈现overlaySKScene所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)