gpt4 book ai didi

opengl - 如何设计我的 GL 应用程序以实现可移植性?

转载 作者:行者123 更新时间:2023-12-01 15:41:36 25 4
gpt4 key购买 nike

我发现 GL 需要在不同的系统上进行不同的设置才能正常运行。例如,在我的桌面上,如果我请求 3.3 版核心配置文件上下文,一切正常。在 Mac 上,我还必须设置向前兼容标志。我的上网本声称只支持 2.1 版,但扩展了 3.1 版的大部分功能。 (所以我必须要求 2.1。)

我的问题是,有没有一种通用的方法可以确定:

  1. 是否支持我的应用程序需要的所有 GL 功能,以及
  2. 我需要什么版本、配置文件(核心或非核心)和前向兼容性标志的组合才能使其正常工作?

最佳答案

我认为这里没有任何 Elixir 。执行适当的运行时检查并提供可充分利用可用功能的备用路径几乎完全取决于您。

当我编写 OpenGL 应用程序时,我通常定义一个“caps”表,如下所示:

struct GLInfo {

// GL extensions/features as booleans for direct access:
int hasVAO; // GL_ARB_vertex_array_object........: Has VAO support? Allows faster switching between vertex formats.
int hasPBO; // GL_ARB_pixel_buffer_object........: Supports Pixel Buffer Objects?
int hasFBO; // GL_ARB_framebuffer_object.........: Supports Framebuffer objects for offscreen rendering?
int hasGPUMemoryInfo; // GL_NVX_gpu_memory_info............: GPU memory info/stats.
int hasDebugOutput; // GL_ARB_debug_output...............: Allows GL to generate debug and profiling messages.
int hasExplicitAttribLocation; // GL_ARB_explicit_attrib_location...: Allows the use of "layout(location = N)" in GLSL code.
int hasSeparateShaderObjects; // GL_ARB_separate_shader_objects....: Allows creation of "single stage" programs that can be combined at use time.
int hasUniformBuffer; // GL_ARB_uniform_buffer_object......: Uniform buffer objects (UBOs).
int hasTextureCompressionS3TC; // GL_EXT_texture_compression_s3tc...: Direct use of S3TC compressed textures.
int hasTextureCompressionRGTC; // GL_ARB_texture_compression_rgtc...: Red/Green texture compression: RGTC/AT1N/ATI2N.
int hasTextureFilterAnisotropic; // GL_EXT_texture_filter_anisotropic.: Anisotropic texture filtering!
};

我在哪里放置启动时使用 glGet 收集的所有功能信息并通过测试函数指针。然后,在使用特性/功能时,我总是首先检查可用性,如果可能的话提供后备。例如:

if (glInfo.hasVAO) 
{
draw_with_VAO();
}
else
{
draw_with_VB_only();
}

当然,您可能会决定硬件必须具备一些最低限度的功能才能运行您的软件。例如:必须至少有支持 GLSL v120 的 OpenGL 2.1。这是完全正常和意料之中的。

关于核心和兼容性配置文件之间的差异,如果您希望同时支持两者,则必须避免一些 OpenGL 功能。例如:始终使用 VBO 绘制。它们是 Core 上的规范,之前通过扩展存在。

关于opengl - 如何设计我的 GL 应用程序以实现可移植性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25389250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com