现在的位置: 首页 > 综合 > 正文

/LGC图形渲染/OpenGL ES 概述

2012年09月20日 ⁄ 综合 ⁄ 共 3760字 ⁄ 字号 评论关闭
OpenGL ES 概述
作者:
刘鹏
日期:

2009-05-10

本文对 OpenGL ES 做了综合性的介绍,包括 OpenGL ES 的由来、主要版本及其特点、OpenGL ES 与 OpenGL 的主要区别等等。

简介2

OpenGL_ES是khronos协会从OpenGL裁剪定制而来的,专为手机,游戏机等嵌入式
设备而设计。它的接口其实和 Open GL很类似。

OpenGL_ES有几个主要版本,但对游戏开发来说,需要关注的只有两个:
OpenGL_ES_1.x_和 OpenGL_ES_2.x。

两者的特性和主要区别如下:

OpenGL_ES_1.x
为固定渲染管线(Fixed_Function)而设计。子版本包括:1.0,1.1。1.0从OpenGL_1.3裁减而来;1.1从
OpenGL_1.5裁减而来。1.1向下兼容1.0。经研究,1.1因为更先进,而且相比1.0增加的特性也都很有用,所以基本上不用考虑1.0了。
1.1和1.0的变化不算很大,应该芯片的价格也不会高出很多?1.1的技术规范参见:es_full_spec.1.1.12.pdf 或者
es_cm_spec_1.1.12.pdf。

OpenGL_ES_2.x 为可编程渲染管线(Programmable)而设计。目前只有2.0这一
个子版本,从OpenGL_2.0裁减而来。和1.x的区别是可以支持vertex和pixel
shader,因此能够实现更多的特效。另外2.0就不再支持1.x里面的固定管线功能
了,也就是说2.x并不向下兼容1.x。技术规范参见:es_full_spec_2.0.22.pdf
或者:es_cm_spec_2.0.22.pdf。

OpenGL ES相对OpenGL删减了一切低效能的操作方式,有高性能的决不留低效能
的,即只求效能不求兼容性。比如

  • 没有double型数据类型,但加入了高性能的定点小数数据类型;
  • 没有glBegin/glEnd/glVertex,只能用glDrawArrays/glDraw......;
  • 没有实时将非压缩图片数据转成压缩贴图的功能,程序必须直接提供压缩好
    的贴图;

OpenGL ES 与 OpenGL 的区别3

数据类型:

  1. i GLint 整数型
  2. f GLfixed 定点小数
  3. x GLclampx 限定型定点小数

删除的功能:

  1. glBegin/glEnd
  2. glArrayElement
  3. 显示列表
  4. 求值器
  5. 索引色模式
  6. 自定义裁剪平面
  7. glRect
  8. 图像处理(这个一般显卡也没有,FireGL/Quadro显卡有)
  9. 反馈缓冲
  10. 选择缓冲
  11. 累积缓冲
  12. 边界标志
  13. glPolygonMode
  14. GL_QUADS,GL_QUAD_STRIP,GL_POLYGON
  15. glPushAttrib,glPopAttrib,glPushClientAttrib,glPopClientAttrib
  16. TEXTURE_1D、TEXTURE_3D、TEXTURE_RECT、TEXTURE_CUBE_MAP
  17. GL_COMBINE
  18. 自动纹理坐标生成
  19. 纹理边界
  20. GL_CLAMP、GL_CLAMP_TO_BORDER
  21. 消失纹理代表
  22. 纹理LOD限定
  23. 纹理偏好限定
  24. 纹理自动压缩、解压缩
  25. glDrawPixels,glPixelTransfer,glPixelZoom
  26. glReadBuffer,glDrawBuffer,glCopyPixels

其它注意事项:

  1. glDrawArrays等函数中数据必须紧密排列,即间隔为0
  2. 各种数据的堆栈深度较低

OpenGL based Graphics
: A state machine4

It's a state machine - Setup the stage, lighting, actors... Then draw
it.

Sample OpenGL ES 2.0 program as following:

// Setup

Handle = get_platform_specific_window_handle();
eglGetDisplay (handle);
eglInitialize ();
eglBindAPI (EGL_OPENGL_ES_API);
eglChooseConfig ();
eglCreateWindowSurface ();
eglCreateContex ();
eglMakeCurrent ();

//Actors

float afVertices [] = {...};
glEnableVertexAttribArray (0);
glVertexAttribPointer (VERTEX_ARRAY, GL_FLOAT, GL_FALSE, afVertices);
glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);

//Show
eglSwapBuffers (eglDisplay, eglSurface);

OpenGL ES 2.0, OpenGL ES 1.1 and Full Function4

  • ES2.0 offers Programmable pipeline vs Fixed function in ES1.1

    1. Ex, Lighting, Fog functions in ES1.1 not present in ES2.0, so need to write code to generate these effects.
    2. More flexibility, little more work, but lot of available code
    3. Android
      uses ES1.1
  • ES2.0 NOT backward compatible with ES1.1
    1. See Companion paper for definitive comparison of available functions in ES1.1 and ES2.0.
  • See "Difference Specification" documents in Khronos OpenGL website,
    for summary of changes compared to OpenGL "full" function
    specification

OpenGL ES 2.x

简介

OpenGL ES 2.0 is very different thank ES 1.1. You don't have a
fixed-function pipeline anymore, so your faimilar "push matrix,
translate, rotate", etc are all gone.

Instead you have the concept of shaders: vertex and frament. They're
little programs that get executed for each vertex and each pixel. That's
where all the transformation and other effects happen. Your code will
prepare the vertex data, tell OpenGL how it's structured, and hand it
over to the shaders.

怎样上手
如何 port 应用 from OpenGL ES 1.1 to OpenGL ES 2.05

You can translate easily:

  1. textures management
  2. framebuffer objects
  3. blending

More difficult (Need shaders):

  1. fixed pipeline transformations (rotation, scale ...)
  2. fog
  3. lighting

To port your code, i recommand you:

  1. Learn GLSL 1.2: you can read WebGL tutorials try to write some shaders in shader toy.
  2. List all material you have (or rendering technics);List all vertices
    informations as vertices coordinates, normal,textures coord, color
    informations you need for each material.With theses informations, you
    will know which GLSL Programs (vertex + fragment shaders) you must
    write.
  3. Write your shader compil functions and log each informations;
    Implement a minimal program OpenGL ES 2.X with a quad (two triangles);
    Implement and test your GLSL programs one by one.
  4. Optimize

Reference

  1. Official Website
  2. OpenGL ES概述
  3. OpenGL 与 OpenGL ES 的区别
  4. OpenGL ES based UI Development on TI Platforms
  5. Port 3D app from OpenGL ES1.x to OpenGL ES 2.x

抱歉!评论已关闭.