Closed AnBi2199 closed 8 years ago
Hi @AnBi2199 I've run into the same issue as you described. The issue seems to be the glClear that is used for each drawEyeWithEye call. Something inside SceneKit/SpriteKit/Apple's OpenGLES implementation is causing the glScissor to become disabled and it clears the whole screen instead of just the expected Scissor Box. My tests quite strongly pointed to setting a SpriteKit Scene as a Material contents as being the issue. I've had a look at your commit and I think a better solution is instead to call the glClear prior to rendering with either Eye. (I don't think your solution would even work with the way my app was setup anyway, but I've gone beyond this now and don't feel like going back to try your method sorry xD) Since then I've ran into another issue (no idea on the exact cause of this one yet though...) and now doing the glClear prior to the first drawEyeWithEye call wasn't actually clearing the whole screen (it was leaving bars on the top and right of the screen that weren't cleared of their color and depth values). To resolve this I just disabled the glScissor prior to the glClear that was happening. Now everything seems to be working perfectly! :D Hope this helps you out! incase you run into the same secondary issue I've run into. Nice port btw @rsanchezsaez ! :+1:
You can try to simply add glDisable(GL_SCISSOR_TEST);
in the end of drawFrameWithHeadTransform
method will solve this problem.Like the following code
- (void)drawFrameWithHeadTransform:(CardboardSDK::HeadTransform *)headTransform
leftEye:(CardboardSDK::Eye *)leftEye
rightEye:(CardboardSDK::Eye *)rightEye
{
GLCheckForError();
// NSLog(@"%@", NSStringFromGLKMatrix4(leftEyeParams->transform()->eyeView()));
[self.stereoRendererDelegate prepareNewFrameWithHeadViewMatrix:headTransform->headView()];
GLCheckForError();
glEnable(GL_SCISSOR_TEST);
leftEye->viewport()->setGLViewport();
leftEye->viewport()->setGLScissor();
GLCheckForError();
_leftEyeWrapper.eye = leftEye;
[self.stereoRendererDelegate drawEyeWithEye:_leftEyeWrapper];
GLCheckForError();
if (rightEye == nullptr) { return; }
rightEye->viewport()->setGLViewport();
rightEye->viewport()->setGLScissor();
GLCheckForError();
_rightEyeWrapper.eye = rightEye;
[self.stereoRendererDelegate drawEyeWithEye:_rightEyeWrapper];
glDisable(GL_SCISSOR_TEST);
GLCheckForError();
}
@ljfdestiny This doesn't actually solve the issue of rendering with SpriteKit. The issue is that SpriteKit is doing something behind the scenes to disable/break the scissor. This means we are unable to call glClear within the drawEyeWithEye because that will clear the left side of the screen when it is called for the drawEyeWithEye for the right eye. Personally I don't see any actual NEED for having the clear within the drawEyeWithEye call so the solution to put it prior to the drawEyeWithEye calls works for me. Is there a situation you have that needs the glClear within the drawEyeWithEye? From all of my testing I have come to the conclusion that it is SpriteKit being used as a material on a SceneKit object that is the issue. I noticed that when it was the scene object was not on the screen then there was no issue (the left side was not cleared) but as soon as that object came into view and was rendered then the left side was cleared.
@GuyDavis90 Calling glClear before both of the drawEyeWithEye doesnt work for me. It might just be my inexperience with OpenGL though. Would you mind to post code on how to do what you're suggesting? I'd appreciate it
@AnBi2199 I have made a PR that includes a sample project utilizing SceneKit for rendering a Collada scene. I have applied a SpriteKit scene to one of the cubes as a texture. You can see where I am calling glClear in the - (void)prepareNewFrameWithHeadViewMatrix:(GLKMatrix4)headViewMatrix function. (This is called prior to both of the drawEyeWithEye functions (in the CBDViewController.mm inside the function - (void)drawFrameWithHeadTransform:(CardboardSDK::HeadTransform )headTransform leftEye:(CardboardSDK::Eye )leftEye rightEye:(CardboardSDK::Eye *)rightEye
If you move the glClear to the drawEyeWithEye function you will be able to see the Scissor become disabled/broken whenever the SpriteKit scene is rendered on the cube. If you have any more questions don't hesitate to ask!
@GuyDavis90 Thanks for the PR Did the clear before draweyewitheye (inside prepareNewFrameWithHeadViewMatrix) like you described and it worked!
Going to delete my PR to the issue
Thanks @AnBi2199, @GuyDavis90 and @ljfdestiny! CBDSceneKit
example fix added as part of PR #24.
Closing now, please let me know if there are further issues related to this.
I made a video player with spritekit and scenekit and was able to get it to work perfectly on iOS8. But running the same code on iOS9 will result in the video only being rendered on the right viewport