美文网首页
cocos2d源码分析(三):Configuration查看Op

cocos2d源码分析(三):Configuration查看Op

作者: 奔向火星005 | 来源:发表于2018-12-31 12:04 被阅读0次

cocos2d的单例Configuration会在初始化阶段先读取OpenGL的一些信息并存储,如下代码:

void Configuration::gatherGPUInfo()
{
    _valueDict["gl.vendor"] = Value((const char*)glGetString(GL_VENDOR));
    _valueDict["gl.renderer"] = Value((const char*)glGetString(GL_RENDERER));
    _valueDict["gl.version"] = Value((const char*)glGetString(GL_VERSION));
   
    _glExtensions = (char *)glGetString(GL_EXTENSIONS);

    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_maxTextureSize);
    _valueDict["gl.max_texture_size"] = Value((int)_maxTextureSize);

    glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &_maxTextureUnits);
    _valueDict["gl.max_texture_units"] = Value((int)_maxTextureUnits);

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    glGetIntegerv(GL_MAX_SAMPLES_APPLE, &_maxSamplesAllowed);
    _valueDict["gl.max_samples_allowed"] = Value((int)_maxSamplesAllowed);
#endif
    
    _supportsETC1 = checkForGLExtension("GL_OES_compressed_ETC1_RGB8_texture");
    _valueDict["gl.supports_ETC1"] = Value(_supportsETC1);
    
    _supportsS3TC = checkForGLExtension("GL_EXT_texture_compression_s3tc");
    _valueDict["gl.supports_S3TC"] = Value(_supportsS3TC);
    
    _supportsATITC = checkForGLExtension("GL_AMD_compressed_ATC_texture");
    _valueDict["gl.supports_ATITC"] = Value(_supportsATITC);
    
    _supportsPVRTC = checkForGLExtension("GL_IMG_texture_compression_pvrtc");
    _valueDict["gl.supports_PVRTC"] = Value(_supportsPVRTC);

    _supportsNPOT = true;
    _valueDict["gl.supports_NPOT"] = Value(_supportsNPOT);
    
    _supportsBGRA8888 = checkForGLExtension("GL_IMG_texture_format_BGRA8888");
    _valueDict["gl.supports_BGRA8888"] = Value(_supportsBGRA8888);

    _supportsDiscardFramebuffer = checkForGLExtension("GL_EXT_discard_framebuffer");
    _valueDict["gl.supports_discard_framebuffer"] = Value(_supportsDiscardFramebuffer);

#ifdef CC_PLATFORM_PC
    _supportsShareableVAO = checkForGLExtension("vertex_array_object");
#else
    _supportsShareableVAO = checkForGLExtension("GL_OES_vertex_array_object");
#endif
    _valueDict["gl.supports_vertex_array_object"] = Value(_supportsShareableVAO);

    _supportsOESMapBuffer = checkForGLExtension("GL_OES_mapbuffer");
    _valueDict["gl.supports_OES_map_buffer"] = Value(_supportsOESMapBuffer);

    _supportsOESDepth24 = checkForGLExtension("GL_OES_depth24");
    _valueDict["gl.supports_OES_depth24"] = Value(_supportsOESDepth24);

    
    _supportsOESPackedDepthStencil = checkForGLExtension("GL_OES_packed_depth_stencil");
    _valueDict["gl.supports_OES_packed_depth_stencil"] = Value(_supportsOESPackedDepthStencil);


    CHECK_GL_ERROR_DEBUG();
}

可以看到主要调用OpenGL的glGetString接口读取,查看OpenGLES 2.0手册,如下:
The GL_VENDOR and GL_RENDERER queries are formatted for human con- sumption, and have no set format; they’re initialized with whatever the implementer felt were useful descriptions.
The GL_VERSION query will return a string starting with “OpenGL ES 2.0” for all OpenGL ES 2.0 implementations. The version string can additionally include vendor-specific information after those tokens, and will always have the format of:
OpenGL ES <version> <vendor-specific information>

意思是GL_VENDOR和GL_RENDERER的请求结果是由实现者自由定义的,而GL_VERSION需要遵循一定的格式。我的手机是5s,可看到返回的结果为:
GL_VENDOR :"Apple Inc."
GL_RENDERER : "Apple A7 GPU"
GL_VERSION :"OpenGL ES 2.0 Apple A7 GPU - 96.27.1"

GL_EXTENSIONS返回当前系统支持的OpenGLES支持的扩展,我手机上返回的是:
"GL_OES_depth_texture GL_OES_depth_texture_cube_map GL_OES_depth24 GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_mapbuffer GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_float GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_vertex_array_object GL_EXT_blend_minmax GL_EXT_color_buffer_half_float GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_draw_instanced GL_EXT_instanced_arrays GL_EXT_map_buffer_range GL_EXT_occlusion_query_boolean GL_EXT_pvrtc_sRGB GL_EXT_read_format_bgra GL_EXT_separate_shader_objects GL_EXT_shader_framebuffer_fetch GL_EXT_shader_texture_lod GL_EXT_shadow_samplers GL_EXT_sRGB GL_EXT_texture_filter_anisotropic GL_EXT_texture_rg GL_EXT_texture_storage GL_APPLE_clip_distance GL_APPLE_color_buffer_packed_float GL_APPLE_copy_texture_levels GL_APPLE_framebuffer_multisample GL_APPLE_rgb_422 GL_APPLE_sync GL_APPLE_texture_format_BGRA8888 GL_APPLE_texture_max_level GL_APPLE_texture_packed_float GL_IMG_re"

另外还有glGetIntegerv接口:
GL_MAX_TEXTURE_SIZE读取支持的纹理最大尺寸,5s上返回4096.
GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS读取是顶点着色器和纹理着色器加起来允许的最大的纹理单元数量,5s上返回8.
GL_MAX_SAMPLES_APPLE是IOS系统才有的枚举,字面意思貌似是允许的最大采样器数量,不太确定,先记着。返回的是4.

相关文章

网友评论

      本文标题:cocos2d源码分析(三):Configuration查看Op

      本文链接:https://www.haomeiwen.com/subject/hmpilqtx.html