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

s3c6410 2d 3d 基础

2018年01月23日 ⁄ 综合 ⁄ 共 10076字 ⁄ 字号 评论关闭
文章目录

GRAPHICS 2D

关键概念:

Ø  硬件加速:

硬件来完成基本图元的绘制

Ø  On-Screen Rendering:

在同一屏幕上,从一个位置复制到另一个位置。

Ø  Off-Screen Rendering(离屏渲染):

从内存复制数据到frame buffer.  

 

内部计算使用ARGB_8888颜色格式。

转换方式:

Ø  其它转ARGB_8888:在低位填充和高位相同的位。eg: RGB_565 format is      R: 11010-----à 11010 110

Ø  其它转ARGB_8888:直接截取

 

 

渲染管线:

 

一、三种原始图元:

1、        线点图

2、        位块传输

3、        颜色扩展

 

 

 

 

1、  线点图:渲染从(sx,sy)到(ex,ey)的线

操作一下的几个寄存器即可:

 

2、  位块传输:矩形块像素的整体转换,如改变图像大小……

Color space conversionisperformed automatically if SRC_COLOR_MODE differs from DEST_COLOR_MODE.

 

 

3、  颜色扩展:将单色扩展成背景或者前景色

二、旋转:绕(ox,oy)旋转90,180,270,X/Y

 

配置一下两个寄存器

三、剪切:

四、光栅操作(三元光栅操作):

实现图像的混合

 

光栅操作,无非就是: 
D 目的位图 
P 选中的模式(或者操作) 
S 源位图 
三者间的逻辑操作。 

下面是这些操作中所用到的布尔操作符:

操作符

意义

a

AND(按位与)

n

NOT(按位取反)

o

OR (按位或)

x

XOR(按位异或)

每一光栅操作码是一32位整数,其高位字(high-order word)是布尔操作索引,其低位字(low-order word)是操作码。16位的操作索引从0开始,8位值表示预定画刷、源位图和目的位图进行布尔操作的结果。

 

例如:结果=source,ROP=1111 0000

结果=source&Destination,ROP=1111 0000 & 1100 1100=1100 0000

结果=source|Destionation,ROP=1111 0000 | 1100 1100=1111 1100

 

五、  ALPHA BLENDING(a 混合)

 

Alpha 混合是源颜色数据和背景颜色数据之间逐个像素的混合。

应用alpha混合技术,可以实现出最眩目的火光、烟雾、阴影、动态光源等等一切你可以想象的出来的半透明效果。

ARGB8888颜色为 32 位值:alpha、红色、绿色和蓝色各 8 位。alpha 值指示颜色的透明度,即颜色与背景色的混合程度。Alpha 值的范围是 0 到 255,其中 0 表示完全透明的颜色,255 表示完全不透明的颜色。

Alpha 混合是源颜色数据和背景颜色数据之间逐个像素的混合。给定源颜色的三个分量(红色、绿色和蓝色)都按照以下公式与背景颜色的相应分量混合:

显示颜色 = 源颜色 × alpha / 255 + 背景颜色 × (255 - alpha) / 255

例如,假设源颜色的红色分量是 150,背景颜色的红色分量是 100。如果 alpha 值是 200,则结果颜色的红色分量按以下公式计算:

150 × 200 / 255 + 100 × (255 – 200) / 255 = 139

 

附:Understanding Hardware Acceleration on Mobile Browsers

http://rogeryi.wordpress.com/2011/07/17/understanding-hardware-acceleration-on-mobile-browser/

http://www.sencha.com/blog/understanding-hardware-acceleration-on-mobile-browsers/#date:17:00

 

 

GRAPHIC 3D

主要内容

Ø  3D模型基础:虚拟照相机模型

Ø  3D绘制流水线

Ø  6410硬件相关的3D 实现

参考:《交互式计算机图形学》、S3c6410手册

 

一、3D模型基础:虚拟照相机模型

 

理想的针孔照相机具有无穷大的景深:视角范围内的所有点不论与照相机的远近如何,都会被清晰成像,一个点还是一个点。

缺点:

1、光线进入不了相机

2、照相机不能调节视角

 

虚拟照相机模型:

第一、对象的确定不依赖于观察者。

第二、可以像对针孔照相机所做的那样,利用简单的几何方法计算图像。

 

投影线:从对象的一点到透镜的中心连一条线。

投影中心(COP):透镜中心。

 

三维API:

四要素:对象、观察者、光源、材质属性

大多数API提供图元集

有一些API提供读像素和写像素(像素流水线),从而允许用户直接访问帧缓存,并把曲线和曲面作为图元提供给用户。

 

定位观察者:

1、位置:COP

2、方向:

3、焦距:

4、胶片平面

 

借助一系列坐标系变换确定位置方向。变到以COP为中心的坐标系中。

光源:由位置、强度、颜色、方向性来定义。

 

材质属性:是对象的属性,定义对象时定义。

 

坐标系:

对象坐标系:对象自身,方便描述对象的大小、方向、位置。例如,在对象坐标系下,立方体的面和坐标轴平行,立方体的中心位于坐标原点。

世界坐标系:有很多的对象,通过一系列变换,从而将它们放到一个统一的坐标系中。

观察者坐标系(照相机坐标系):图像的生成依赖与照相机坐标系。

物理设备坐标、设备坐标、屏幕坐标:用显示器上的单位度量出的数据

 

其它:

 

加色模型:CRT   RGB

减色模型:打印机 CMY

模-视变换:把在这几个坐标系变换下的4*4矩阵合称

 

观察

正(交)投影orthographicprojection(平行投影)

投影线垂直于观察平面。焦距无限大,并且让照相机无限远离对象。在极限情况下,投影线依次平行,投影中心也被投影方向所替代。

 

透视投影(perspectiveview)

COP在有限远处。投影后尺寸会缩短。分为一点、二点、三点透视

         若有一个主方向平行于投影平面,则为两点投影。

         若有两个主方向平行于投影平面,则为一点投影

OpenGL中的投影:

 

矩阵模式——模-视变换矩阵和投影变换矩阵。

 

 

 

隐藏面消除算法:z-buffer algorithm

1、对象空间算法(排序对象绘制顺序)

2、图像空间算法(确定投影先与对象表面形成的所有交点之间的关系。只保留最近的,即z-buffer)

 

背面剔除:

像立方体这样的凸对象,法线方向背离观察者的面总是不可见的,因而可以在光栅化之前将其剔除掉。

 

背面剔除与z-buffer:

         作用的时机不一样,两者都需要。例如:有n个立方体,我们只是用z-buffer算法,那么绘制流水线要处理6n哥多边形。如果使用背面剔除功能,有一半的多边形可以在流水线初期被剔除。

图形绘制的几个主要任务:

建模----》几何处理----》光栅化-------》片元处理-------》帧缓存

 

1、建模:生成集合对象,表现为一组表示几何对象的顶点数据。

2、几何处理:投影、图元装配、裁剪和明暗处理

第一步:将几何对象的表示从对象坐标系变换到照相机坐标系。(使用了一个组合变换矩阵,模-视变换矩阵)

第二步:利用投影变换矩阵把对象的定点变换到规范化的视见体内,规范化的视见体是一个中心位于坐标原点的立方体,位于它里面的所有对象都是潜在的可见对象。(顶点位于裁剪坐标系中,把透视投影和正投影变换成一个简单的正投影,简化了以后的裁剪)

 

图元装配(primitiveassembly):在进行裁剪处理之前,必须把顶点组合成对象

 

3、光栅化:从图元转化成片元。光栅处理器处理的数据是规范化设备坐标系中的顶点数据,而输出的片元位于显示设备。

4、片元处理:例如半透明进行颜色融合……

 

 

离散技术:

回顾流水线(简化):

api函数直接对帧缓存里面的每个像素进行读写。

例如:纹理映射、反走样、图像合成、alpha融合

 

 

映射方法:

纹理映射:贴图

凹凸映射:在明暗处理中对法向量进行扰动

环境映射:光线跟踪的效果

 

共同点:作为片元处理过程的一部分,都改变了单个偏远的明暗值;降低了对象表示的几何复杂度,而生成的图像更像复杂的几何对象,都受到走样误差的影响。

二、3D绘制流水线

可编程着色器(program shader)

背景:

绘制流水线中每个绘制模块的功能都是固定的。例如,当希望通过光纤与材质的相互作用来计算对象表面的颜色时,就只能使用Phong光照模型,因为只是OpenGL规范中固定功能的绘制流水线唯一支持的光照模型。在这种情况下,只有一个光照模型可供使用,除此之外,光照计算也只能作用于每个顶点。固定功能的片元处理器在图元上对每个顶点的最终颜色通过插值计算图元上所有像素的颜色。如果想使用其它的光照模型,那就必须另想办法。所以产生了可编程着色器,来深处复杂的视觉效果,而绘制速度与标准的固定功能绘制流水线一样快。

 

 

几何绘制流水线:

 

解释:

处理顶点时,由于顶点处理过程要进行模-视变换和投影变换,所以顶点在观察坐标系里的表示只能发生在顶点处理器中。顶点处理结束后,每个顶点都经过了模-视变换和投影变换,从而得到了一个新的位置坐标,将颜色值赋给每个顶点,并且根据程序中状态的设置情况,可能还要将纹理坐标等其他属性赋给每个顶点。然后,把顶点组装成图元并进行裁剪处理。没有被裁减掉的潜在的可见图元经过光栅化后产生片元。最后,片元被处理后生成最终的显示预想。与固定功能的绘制流水线不同,顶点处理器和片元处理器是可编程的,即用户可以编写着色器的应用程序,这些程序经编译后装在到相应的图形处理器中。

 

顶点着色器(vertexshader)

用于计算顶点位置与颜色等属性。将使用其自定义的运算操作代替有顶点处理器执行的固定功能的运算操作。如果应用程序没有提供顶点着色器程序,那么可编程的顶点处理器就会执行OpenGL固定功能顶点处理器中得标准运算操作。通过绘制流水线顶点处理器的每个顶点都要执行依次顶点处理程序。

 

片元着色器(Fragmentshader)

对每个片元进行计算,最终计算出每个像素的颜色。

 

 

 

 

 

Perspective division : (透视除法)用w分量去除其他分量,就得到了在规范化的设备坐标系下的三维表示。

最后一步变换根据viewport(视口)提供的信息把规范化的设备坐标系下的表示变换成窗口坐标系(window coordinate system)。

窗口坐标是显示器上的像素表示的,但仍然保留了深度信息。如果去掉深度坐标,就得到了二维的屏幕坐标(screen coordinate)

 

 

OpenGL ES是基于绘制流水线模型。一个典型的绘制流水线会涉及6个坐标系,依次是:

1、  对象坐标系或者建模坐标系

2、  世界坐标系

3、  眼坐标系或者照相机坐标系

4、  裁剪坐标系

5、  规范化的设备坐标系

6、  窗口坐标系或者屏幕坐标系

 

 

三、6410硬件相关的3D 实现

BLOCK DIAGRAM

VERTEX SHADER

OVERVIEW

The vertex shader is the3D graphics specific processor that processes vertices instead of traditionalfixedfunctiongraphics pipeline. The vertex shader can enable the user-definedspecial effects more than the commontransform and lighting. This
vertex shader supports the shader model 3.0 includingthe features of vertex texture and various flow controls.

(shader model 3.0 :http://msdn.microsoft.com/en-us/library/bb147365(v=vs.85).aspx)

INITIAL OPERATION

Vertex shader program iscomposed of instruction sequences, constantfloating-point values for the arithmeticoperations, constant integer andboolean values for the flow control. These should be stored in theregister ormemory region before executing
the program.Vertex shader starts automatically when the host writes allattributes for avertex.

 

操作定义vertex shader相关寄存器:

compat.cshaders.c

 

PRIMITIVE ENGINES

 

Primitive engine is ahardware-wired block that is processing a series of operations including primitive assembly,flat shading(平面明暗处理), view frustumclipping(视椎裁剪体), perspective division and viewport mapping. View frustum clipping is dividedinto
near/far plane clipping operationsand left/right/top/bottom plane clipping operations. In primitive engine,onlynear/far plane clipping is processed, except when the w-coordinates ofclipped vertex is zero. Using the windowclipping operation, other clippingoperations
are processed by triangle setup engine and rasterizer. When thewcoordinatesof a vertex is zero, the primitive engine perform other clippingoperations to avoid the w-coordinates ofthe output vertex to be zero.Thefollowing figure represents the conceptual functional
level block diagram ofprimitive engine to illustrate

operations of theprimitive engine.

 

 

VERTEX CONTEXT REGISTER

VIEWPORT PARAMETERREGISTERS

View port :是显示窗口中的一块矩形区域。默认情况下,视口是整个显示窗口。

操作定义 primitive engine 相关寄存器:

primitive.c

 

RASTER ENGINES

Raster engine includetriangle setup engine and rasterizer.

Triangle setup engineoverview

•Primitive y-valuebounding

•Back face culling(背面剔除)

•Edge interpolation(边缘插值法)

•Triangle gradients calculation

•Depth offset calculation

Rasterizer overview

•Triangle, Line, Point,and Point Sprite are supported.(aliased only)

•1-fragment is generatedper cycle by a 1x1 stamp.

•Fragment position valuecalculation. (screen coordinates[x, y], depth[z, iw])

•Fragment valuecalculation. (color / fog / normal / texture coordinates)

•Coefficients calculationfor LOD selection.

操作定义 RASTER ENGINES 相关寄存器:

compat.cfimg.h glesBase.cppglesGet.cpp raster.c

 

PIXEL SHADER

OVERVIEW

The proposed shaderconsists of 4-way floating point SIMD architecture and small scalar core. Eachdata pathhas 4-way float type register and scalar register, respectively.

The simplified pixelshader block diagram and its interface are shown in the Figure 6-1. The input data is pixel attributes such as position, colorand texture coordinate coming from rasterizer. Instruction andpredefinedconstants are downloaded
from host processor for the shaderexecution. Temporary register, loop counter

register, predicateregister are cooperated for pixel processing. For the texture mapping, thepixel shader interactswith texture unit. The processed pixel data is finallytransferred to per-fragment units through output register.

Programmable shader hastwo register groups according to its usage. One is specialfunction register (SFR) forHW configuration and the other is program registerfor shader program. SFR can be accessed by onlyHOSTCPU. Some of program registers such
as instruction memory, constantfloat register, constant integer register and

constant Booleanregister can be access by both HOST CPU and shader itself according toprogrammable shaderoperation mode. Other program register can be access byprogrammable shader and interface block such asrasterizer or per-fragment unit.In
this document, the register which can be accessed by HOST CPU isbrieflyoverviewed. The details of pixel shader operation are covered separateddocument “the Programmable Shader

S/W Developer’s Guide”.

 

操作定义 pixel shader相关寄存器:

compat.cshaders.c

 

TEXTURE UNITS

OVERVIEW

Texture unit (for pixel)

Texture unit includesaddress generation logic, filtering unit, texture cache, and decompressionunit. Vertex texture unit includes address generation unit and vertex texturecache.

Texture unit supportsNon 2N-sized Textures (Arbitrary Rectangular Texture).

•Up to Eight SimultaneousTextures (Max. 8 Texture Samplers)

♦Each texture context isfully configured by dedicated register sets.

♦Controllable Min./Max.Mipmap levels for each texture.

•Max. Width/Height ofTextures: 2048x2048

•Min. Width/Height ofTextures: 1x1

•Max. Mipmap Levels: 12Levels

•Texture Size foMipmapLevel i

♦Max[1, floor{(Width oflevel 0 texture) / 2i}] x Max[1, floor{(Height of level 0 texture) / 2i}]

•Texture unit supports 2Dtexture, Cubemap, and 3D texture.

♦For 3D textures, Level 0texture only

•Bilinear, TrilinearFiltering is supported. Also S3TC compression format and paletted textureformat are

supported.

♦For S3TC compressionformat, Min. Width/Height of Textures is 4 x 4.

♦Paletted texture format:1bpp, 2bpp, 4bpp, 8bpp

•Mipmapping and thefollowing Wrap Modes are supported

♦Non-parametriccoordinate: Clamp to edge

♦Parametric coordinate:Repeat, Flip (Mirrored repeat), Clamp to edge

Vertex texture unit (forvertex)

Filtering is notsupported. Vertex texture unit is only used to fetch 32-bit texture data.

Both compress format andpaletted texture are not supported.

 

操作定义 texture units 相关寄存器:

fimg.h glesBase.cppglesTex.cpp Texture.c

 

 

PER-FRAGMENT UNIT

 

OVERVIEW

All OpenGL 2.0per-fragment operations are supported. Depth Buffer and Stencil Buffer aresupported, depth

buffer bit depth is24-bit and stencil buffer bit depth is 8-bit.

•Per-Fragment Unitsupport Scissor Test

•Per-Fragment Unitsupport Alpha Test

•Per-Fragment Unitsupport Stencil Test (Stencil Buffer is 8-bit ) and Stencil Operation. Alsosupport both front

stencil buffer and backstencil buffer.

•Per-Fragment Unitsupport Depth Test (Depth Buffer is 24-bit)

•Per-Fragment UnitSupport Alpha Blending

•Per-Fragment Unit SupportLogical Operation

•Per-Fragment UnitSupport 16/32bit color mode

•For Enhanced ColorPer-Fragment Unit support Dithering

Pixel ownership test isdetermining whether the destination pixel is visible or obscured by anoverlapping window.

操作定义 per-fragment unit 相关寄存器:

compat.c eglBase.cppfimg.hfragment.c glesBase.cpp glesGet.cpp glesPixel.cpp

抱歉!评论已关闭.