OpenGL vs OpenGL ES 2.0 - 可以轻松移植 OpenGL 应用程序吗? [英] OpenGL vs OpenGL ES 2.0 - Can an OpenGL Application Be Easily Ported?

查看:44
本文介绍了OpenGL vs OpenGL ES 2.0 - 可以轻松移植 OpenGL 应用程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发各种游戏框架,并且是 OpenGL 的新手.大多数书籍似乎都没有对这个问题给出非常明确的答案,我想在我的桌面上使用 OpenGL 进行开发,但在 OpenGL ES 2.0 环境中执行代码.那么我的问题是双重的:

I am working on a gaming framework of sorts, and am a newcomer to OpenGL. Most books seem to not give a terribly clear answer to this question, and I want to develop on my desktop using OpenGL, but execute the code in an OpenGL ES 2.0 environment. My question is twofold then:

  1. 如果我将我的框架用于桌面上的 OpenGL,它会在 OpenGL ES 2.0 环境中直接运行而无需修改吗?
  2. 如果没有,那么有没有好的模拟器,PC 或 Mac;是否有我可以运行的脚本将我的 OpenGL 代码转换为 OpenGL ES 代码,或者标记那些不起作用的东西?

推荐答案

我上一次做任何 ES 工作已经过去了大约三年,所以我可能已经过时或者只是记错了一些东西.

It's been about three years since I was last doing any ES work, so I may be out of date or simply remembering some stuff incorrectly.

  1. 不,针对桌面的 OpenGL 不等于针对 OpenGL ES,因为 ES 是一个子集.ES 没有实现立即模式函数(glBegin()/glEnd(), glVertex*(), ...)顶点数组是将内容发送到管道的主要方式.

  1. No, targeting OpenGL for desktop does not equal targeting OpenGL ES, because ES is a subset. ES does not implement immediate mode functions (glBegin()/glEnd(), glVertex*(), ...) Vertex arrays are the main way of sending stuff into the pipeline.

此外,这取决于您所针对的配置文件:至少在 Lite 配置文件中,ES 不需要实现浮点函数.相反,您会得到定点函数;考虑 32 位整数,其中前 16 位表示小数点前的数字,后面的 16 位表示小数点后的数字.

Additionally, it depends on what profile you are targetting: at least in the Lite profile, ES does not need to implement floating point functions. Instead you get fixed point functions; think 32-bit integers where first 16 bits mean digits before decimal point, and the following 16 bits mean digits after the decimal point.

换句话说,如果使用浮点数,即使是简单的代码可能也无法移植(您必须将对 gl*f() 函数的调用替换为对 <代码>gl*x() 函数.

In other words, even simple code might be unportable if it uses floats (you'd have to replace calls to gl*f() functions with calls to gl*x() functions.

Trolltech 的示例中查看如何解决此问题(特别是 qtwidget.cpp 文件;它是 Qt 示例,但仍然...).你会看到他们打了这个电话:

See how you might solve this problem in Trolltech's example (specifically the qtwidget.cpp file; it's Qt example, but still...). You'll see they make this call:

q_glClearColor(f2vt(0.1f), f2vt(0.1f), f2vt(0.2f), f2vt(1.0f));

这是为了替换对 glClearColorf() 的调用.此外,他们使用宏 f2vt() - 意思是 float 到顶点类型 - 它自动将参数从 float 转换为正确的数据类型.

This is meant to replace call to glClearColorf(). Additionally, they use macro f2vt() - meaning float to vertex type - which automagically converts the argument from float to the correct data type.

三年前我在为一家公司开发一些小型演示时,我已经成功地使用了 PowerVR 的 SDK.它适用于 Windows 下的 Visual C++;Linux下没试过(因为我在公司PC上工作,没必要).

While I was developing some small demos three years ago for a company, I've had success working with PowerVR's SDK. It's for Visual C++ under Windows; I haven't tried it under Linux (no need since I was working on company PC).

<小时>

一个小更新,以反映我最近使用 ES 的经验.(2011 年 6 月 7 日)


A small update to reflect my recent experiences with ES. (June 7th 2011)

  • 当今的平台可能不使用 Lite 配置文件,因此您可能不必担心定点小数
  • 在将桌面代码移植到移动设备(例如 iOS)时,很可能您主要需要做的是这些,其他的不多:
    • glBegin()/glEnd() 替换为顶点数组
    • 用诸如 glClearColorf()
    • 之类的调用替换一些对诸如 glClearColor() 之类的函数的调用
    • 重写您的窗口和输入系统
    • 如果以 OpenGL ES 2.0 为目标来获得着色器功能,您现在必须用着色器完全替换固定功能管道的内置行为 - 至少是重新实现固定功能管道的基本行为
    • Today's platforms probably don't use the Lite profile, so you probably don't have to worry about fixed-point decimals
    • When porting your desktop code for mobile (e.g. iOS), quite probably you'll have to do primarily these, and not much else:
      • replace glBegin()/glEnd() with vertex arrays
      • replace some calls to functions such as glClearColor() with calls such as glClearColorf()
      • rewrite your windowing and input system
      • if targeting OpenGL ES 2.0 to get shader functionality, you'll now have to completely replace fixed-function pipeline's built in behavior with shaders - at least the basic ones that reimplement fixed-function pipeline

      这篇关于OpenGL vs OpenGL ES 2.0 - 可以轻松移植 OpenGL 应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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