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

查看:122
本文介绍了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. 否,因为将ES作为一个子集,所以将OpenGL用于桌面并不等同于将OpenGL 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()
    • 将诸如glClearColor()之类的某些调用替换为glClearColorf()
    • 之类的调用
    • 重写您的窗口和输入系统
    • 如果将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天全站免登陆