Coco2d 2.1和Xcode 7 iOS 9崩溃ccShader [英] Coco2d 2.1 and Xcode 7 iOS 9 crash ccShader

查看:619
本文介绍了Coco2d 2.1和Xcode 7 iOS 9崩溃ccShader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模拟器或设备上测试了Xcode 7,但是我的cocos2d 2.1游戏崩溃了:

I tested Xcode 7 with but my cocos2d 2.1 games crash on simulator or on devices:

ccShader_PositionColorLenghtTexture_frag.h

ccShader_PositionColorLenghtTexture_frag.h

2015-06-15 22:36:13.319 NanoWar[18789:456971] cocos2d: ERROR: 0:12: '' : syntax error: #extension must always be before any non-preprocessor tokens

cocos2d: ERROR: 0:26: Invalid call of undeclared identifier 'fwidth'

此类崩溃游戏

#extension GL_OES_standard_derivatives : enable                                                                             

#ifdef GL_ES                                                                                                                
varying mediump vec4 v_color;                                                                                               
varying mediump vec2 v_texcoord;                                                                                            
#else                                                                                                                       
varying vec4 v_color;                                                                                                       
varying vec2 v_texcoord;                                                                                                    
#endif                                                                                                                      

void main()                                                                                                                 
{                                                                                                                           
#ifdef GL_OES_standard_derivatives                                                                                          
#if defined GL_OES_standard_derivatives                                                                                     
    gl_FragColor = v_color*smoothstep(0.0, length(fwidth(v_texcoord)), 1.0 - length(v_texcoord));                           
#else                                                                                                                       
    gl_FragColor = v_color*step(0.0, 1.0 - length(v_texcoord));                                                             
#endif                                                                                                                      
#endif                                                                                                                      
}


推荐答案

我是 forum.cocos2d-objc.org 的rae,我也可以把我的答案在这里,因为所有的道路通往StackOverflow。 : - )

I'm "rae" on forum.cocos2d-objc.org and I might as well put my answer here as well, since all roads lead to StackOverflow. :-)

如果您使用的是旧版本的Cocos 2D,这可能会有帮助。我编辑CCGLProgram.m以更改 - (BOOL)compileShader:方法的开头:

If you are using an older release of Cocos 2D, this may help. I edited CCGLProgram.m to change the beginning of the -(BOOL)compileShader: method thusly:

#define EXTENSION_STRING "#extension GL_OES_standard_derivatives : enable"
static NSString * g_extensionStr = @EXTENSION_STRING;

- (BOOL)compileShader:(GLuint *)shader type:(GLenum)type byteArray:(const GLchar *)source
{
    GLint status;

    if (!source)
        return NO;

    // BEGIN workaround for Xcode 7 bug
    BOOL hasExtension = NO;
    NSString *sourceStr = [NSString stringWithUTF8String:source];
    if([sourceStr rangeOfString:g_extensionStr].location != NSNotFound) {
        hasExtension = YES;
        NSArray *strs = [sourceStr componentsSeparatedByString:g_extensionStr];
        assert(strs.count == 2);
        sourceStr = [strs componentsJoinedByString:@"\n"];
        source = (GLchar *)[sourceStr UTF8String];
    }

    const GLchar *sources[] = {
        (hasExtension ? EXTENSION_STRING "\n" : ""),
    #ifdef __CC_PLATFORM_IOS
        (type == GL_VERTEX_SHADER ? "precision highp float;\n" : "precision mediump float;\n"),
    #endif
        "uniform mat4 CC_PMatrix;\n"
        "uniform mat4 CC_MVMatrix;\n"
        "uniform mat4 CC_MVPMatrix;\n"
        "uniform vec4 CC_Time;\n"
        "uniform vec4 CC_SinTime;\n"
        "uniform vec4 CC_CosTime;\n"
        "uniform vec4 CC_Random01;\n"
        "//CC INCLUDES END\n\n",
        source,
    };
    // END workaround for Xcode 7 bug

这是一个黑客,希望这有助于有人为此搜索。

It's a hack, but it works for up to Xcode 7 beta 2. Hope this is helpful to someone googling for this.

Reid

这篇关于Coco2d 2.1和Xcode 7 iOS 9崩溃ccShader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆