OpenGL ES 3.0 Programming Guide 1-3

2023-11-20

一,introduction to OGLES 3.0

 

OGLES 3.0 Graphics Pipeline:

VertexBuffer/ArrayObj => VertexShader(texture)===(transform feedback)===> primitives assembler => Rasterizer Stage => fragment/Pixel shader stage(texture) => per fragment operations => framebuffer

 

1,Vertex Shader

 

Input:

Shader program : vertex shader program source code or executable,  that describes operations that will be performed on vertex.

Vertex shader inputs (or attributes):per-vertex data supplied using vertex arrays.

Uniforms:constant data, used by vertex or fragment shader

Samplers:specific特殊 types of uniforms that represent代表 textures used by vertex shader,

Output:

                Output(varying)0/1/2/…              

                Gl_Position

Gl_PointSize

 

In primitive restertization stage, vertex shader output values are calculated , for each generated fragment , and are passed in as input to fragment shader.

The mechanism , used to generate a value for each fragment  from the vertex shader outputs,  that is assigned to each vertex of the primitive is called interpolation插值,

 

Vertex shaders can be used for

traditional vertex-absed operations :

such as transforming the position by a matrix,

computing the lighting equation公式 to generate a per-vertex color

generating or transforming texture coordinates,

Alternatively,because vertex shader is specified by app,so can be used to perform custom math that enables:

                New transforms, lingting, or vertex-based effects not allowed in more traditional fixed-function pipeline,

 

Example:

vertex shader in it takes取得 a postion and its associated color data as input attributes,

transforms the position using a 4x4 matrix, and outputs the transformed position and color.

 

#version 300 es

uniform mat4 u_mvpMatrix;       //matrix to convert a_position from model space to normalized device space

//attributes input  to vertex shader

in vec4 a_position            //position value

in vec4 a_color                  //input vertex color

//output of the vertex shader – input to fragment

out vec4 v_color;             //output vertex color

void main()

{

                v_color = a_color;

                gl_Position = u_mvpMatrix * a_position;

}

 

Line1, provides version of shading language,

Line 2,describes a uniform variable u_mvpMatrix that stores the combined model view and projection matrix投影矩阵,

Line 12, declare the output v_color to store the ouput of the vertex shader that describes the per-vertex color.

The built-in variable called gl_Position is declared automatically, shader must write the transformed position to this variable.

Vertex or fragment shader has a single entry point called the main function.

 

1.1.2 Primitive Assembly图元装配

After vertex shader, next stage in pipeine is primitive assembnly.  Primitive is a geometric obj such as triangle ,line, or point sprite.

Each vertex of a primitive is sent to a diff copy of vertex shader. During primitive assembly, these vertices are grouped back into the primitive.

 

For each primitive, must be determined whether the primitive lies within the view frustums视锥体,(the region of 3D space that is visible on the screen)

If not, it need to be clipped裁剪 to the view frustum.

If primitive is completely outside this region it is discarded,

After clipping, the vertex position is converted to screen coordinates.

A culling淘汰 operation can also be performed that discards primitives based on whether they face forward or backwared.

After clipping and culling, the primitive  is ready to be passed to next stage of pipeline : rasterization stage

 

1.1.3 Rasterization

Rasterization phase, where the appropriate primitive is drawn.

Rasterization is the process that converts primitives into a set of two-dimensional fragments,which are then processed by fragment shader.

 

Output:

                For each fragment : scrren(x,y) coordinate, attributes such as color, texture coordinates. Etc.

 

1.1.4 Fragment Shader

Implements a general purpose programmabnle method for operating on fragments.

This shader is executed for each generated fragment by rasterization stage and tasked follow inputs :

                Shader program

                Inpuit variables : outputs of vertex shader , that are generated by rasterization unit for each fragment using interpolation插值。

                Uniforms

                Samplers

 

The color, depth ,stencil and scrren coordinate location, generated by rasterization stage become inputs to the per-fragment operations stage of pipeline.

 

Examples:

The input to fragment shader are linearly interpolated across the primitive before being passed into the fragment shader.

 

1.1.5 Per-Fragment Operations

Fragment produced by rasterization with (x,y) scrren coordinates can only modify the pixel at location(x,y ) in framebuffer.

 

Per-Freagment Operations:

Fragment data => Pixel Ownership Test => Scissor Test => Stencil test => Depth Test => Blending => Dithering抖动 => to Frambuffer

Pixel ownership test:

 

Stencil and depth tests:

                These test are performed on the stencil and depth value of incoming fragment to determine whether the fragment should be rejected.

 

Blending :

                Blending combines the newly generated freagment color value with color values stored in framebuffer at location(x,y)

 

 

1.4 EGL

 

GLES commands require rendering context and drawing surface.

Renmdering contrext stores appropriate GLES state.

Drawing surface is surface to whch primitives whill be drawn.

Drawing surrace specifies types of buffer that are required or rendering, such as color buffer, depth buffer, stencil buffer.

Drawing surface aloso specified bit depths of each of required buffers.

 

Perform follow tasks using EGL before any rendering :

                Query displays and init

                Create rendering surface. Can be categorized as on-screeen surfces or off-screen surface.

                                On-screen surface attached to native window system, whereas off-screen surface are pixel buffers that do not get displayed but can be used as rendering surface.

                Create Rendering Context.context need to be attached to appropriate surface before rendering can actuially begin.

 

1.4.2 libraries and include files

                GLES3.0 lib named libGLESv2.lib

                EGL lib named libGL.lib

Head file:

                #include <EGL/egl.h>

                #include <GLES3/gl3.h>

 

 

 

 

第二章:Hello Triangle

 

Hello_Triangle.c

Typedef struct

{

                //Handle to a grogram object

                GLuint programObject;

}UserData;

 

//Create a shader object, load shader source , compile shader

GLuint LoadShader(GLenum type, const cahr* shaderSRc)

{

                GLuint shader;

Glint compiled;

                //create shader obj

                Shader = glCreateShader(type);

                If(shaer == 0)     return 0;

 

                //load shader source

                glShaderSource(shader, 1, &shaderSrc, NULL);

 

 

                //Compile shader

                glCompileShader(shader);

 

                //check compile status

                glGetShaderiv*shdaer, GL_COMILE_STATUS, &compiled);

 

                if(!compiled)

                ….

 

                Return shader;

}

 

//init shader and program obj

Int init(ESContext *esContxt)

{

                UserData *userData = esContext->userData;

                Char vShaderStr[] =

                                “#version 300 es \n”

                                “layout(location = 0 ) in vec4 vPosition; \n”

                                “void main() \n”

                                “{ gl_Position = vPosition }\n ”

 

                Char fShaderStr[] =

                                “#verfssion 300 es \n”

                                “precision medium float ;\n”

                                “out vec4 fragColor;\n”

                                “void main() \n”

                                “{ fragColor = vec4(1.0, 0.0, 0.0, 1.0) }”

 

                GLuint vertexShader;

GLuint fragmentShader;

GLuint programobjk;

Glint linked

 

                //Load vertex/fragment shader

                vertexShader = loadShader(GL_VERTEX_SHADER, vShaderStr);

                fragmentShader = LoadShader(GL_FRAGMENT_SHADER, fShaderStr);

 

                //Create program obj

                programOBject = glCreateProgram();

 

                glAttachShader(programOBj, verttexShader);

                glAttachShader(programObj, gragmentShader);

 

                //link program

                glLinkProgram(ProgramObj);

               

                //store program obnk

                userData->programobnjk = programObject;

glClearColor(0.0f, 0.0f, 0.0f ,0.0f);

return TRUE;

}

 

//Draw a triangle using the shader pair created in INIt()

Void Draw(ESContext * escontext)

{

                UserData *userData = esContext->userData;

                GLfloat vVertices[] = {

                                0.0f, 0.5f, 0.0f,

                                -0.5f, -0.5f, 0.0f,

                                0.5f, -0.5f, 0.0f };

 

                //Set viewport

                glViewport(0,0,esContext->width,esContext0>height);

 

                //Clear color buffer

                glClear(GL_COLOR_BUFFER_BIT);

 

                //Use program object

                glUseProgram(userData->programObj);

 

                //Load vertex data

                glVertexAttribPointer(0,3,GL_FLOAT, GL_FLSE, 0, vVertices);

                glEnableVertexAttribArtrray(0);

 

                glDrawArrays(GL_TRIANGLES, 0, 3);

}

 

 

2.5 Create Simple Vertex and fragment shader

In GLES 3.0, no geometry can be drawn unless a valid vetex and fragment shader have been loaded.

To do any rendering at all, OpenGLES3 program must have at least on vetex shader and one fragment shader.

 

Vertex shader that is given in program is simple:

Vettex shader declares one input attribute array – a four-compnent 4分量 vector向量 named vPosition. Later on , the draw function will send-in positions for each vertex顶点 that will be places in this variable.

Layout(location = 0) qualifier signifies that location of this variable is vertex attribute 0.

Every vertex shader must output a position into gl_Position variable.this variable defines position that is passed through to next stage in pipeline.

 

Fragment shader:

Fragment shader declears a single output variable fragColor, which is a vector of four components 4分量的向量.

Value written to this variable is what will be writeen out into the color buffer.

In this case, the sahder output a red color(1.0, 0.0, 0.0, 1.0) for all fragments. …

 

2.6 Compiling and loading shaders

2.7 Creating program obj and link shaders

Once app has created shader obj for vertex and fragment shader. It need to crteate program object.

Conceptually, program obj can be thought of as final linked program.

Once various shaders are compiled into shader object, they must be attached to program object and linked together before drawing.

 

Program obj and link is fully described in chapter 4.

To use program obj for rendering , we bind it using glUseProgram.

After calling glUseProgram with the program object handle, all subsequent rendering will occur suing the vertex and fragment shader attached to program obj.

 

2.8 set Viewport and clearing color buffer

First command that we execute in draw is glViewport, informs OpenGLES of origin,width,height, of 2D rendering surface that will be drawn to.

More detail in chapter 7 “Primitive Assembly and Rasterization” when we discuss coordinate sytstems and clipping.

After setting viewport, next step is to clear screen.,in ES, multiple types of buffers are involved in drawing : color, depth, stencil. Chapter 11讲。

In this example, only the color buffer is dran to . At beginning of each frame, we clear color buffer using glClear()

 

2.9 Loading Geometry and drawing primitive

Now that we have the color buffer cleared , viewport set, program object loaded, we need to specify geometry ofr tringle.

Vertices顶点 for the tringle are specified with three(x,y,z) coordinates in the vVertices array.

The vertex positions need to be loaded to GL and connected to vPosition attribute decleared in vertex shader.

We bound the vPosition variable to input attribute location 0.

Each attribute in vertex sahder has a location that is uniquely identified by an unsinged integer value.

To load the data into vertex attribute 0, we call the glVertexAttribPointer function, 6章讲。

 

We use func glDrawAttays for draws a primitive such as a triangle, line, strip.  7章讲。

 

EglSwapBuffer(display, surface)下章讲。

 

 

Chapter  3 , introduction to EGL

EGL provides mechanisms for following:

                Communicating with native windowing system of your device

                Querying available types and configurations of drawing surface

                Create drawing surface

                Managing rendering resoures such as texture maps纹理贴图

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

OpenGL ES 3.0 Programming Guide 1-3 的相关文章

  • Unity UGUI Image共享材质

    Unity UGUI Image共享材质 问题 当我们在Unity中创建了一个prefab 这个prefab包含的UGUI Image使用了一个自定义的材质 当我们创建出多个prefab示例 然后修改其中一个实例的材质参数 会发现其他使用同
  • openGL之API学习(五十四)glDepthFunc

    指定深度测试比较的方法 如果满足深度测试条件则赢得深度测试并会被渲染出来 void glDepthFunc GLenum func func Specifies the depth comparison function Symbolic
  • openGL之API学习(五十六)低模、高模的区别以及各自的使用领域

    高模是高细节高精度的3D模型 高模看上去十分逼真细节非常丰富模型的面数也相当的高 低模是游戏里的说法 可以理解为游戏所使用的模型 高模有很多作用可以用于电影制作 广告等等 在游戏里高模主要是为了烘焙NormalMap 并且运用在游戏低模型上
  • 计算机图形学【GAMES-101】3、着色计算(深度缓存、着色模型、着色频率)

    快速跳转 1 矩阵变换原理Transform 旋转 位移 缩放 正交投影 透视投影 2 光栅化 反走样 傅里叶变换 卷积 3 着色计算 深度缓存 着色模型 着色频率 4 纹理映射 重心坐标插值 透视投影矫正 双线性插值MipMap 环境光遮
  • Unity3D关于两个物体直接用圆柱进行连接画线(简单画线连接)

    最近做的东西需要用圆柱画线 网上找了些 没找到合适的 所以自己简单写了一个 这个函数只需要输入起始点和终点即可 材质可以自己调整 void DrawLS GameObject startP GameObject finalP Vector3
  • openGL之API学习(五十二)透视分割 透视除法的执行位置

    根据文章https blog csdn net hankern article details 89220736 的分析 透视分割 又叫透视除法 执行的位置在栅格化阶段
  • 图形学/OpenGL/3D数学/Unity

    1 场景管理的数据结构 总结 游戏开发最常用的空间数据结构是四叉 八叉树和BVH树 而BSP树基本上只能应用于编辑器上 k d树则只能用在特殊问题应用场景 2 帧同步与状态同步 https gameinstitute qq com comm
  • 四元数 旋转 旋转矩阵 欧拉角互相转换

    四元数的作用 表达旋转 旋转的表达方式有很多种 有欧拉角 旋转矩阵 轴角 四元数 unit quaternion unit quaternion是一种表达旋转的方式 不同的旋转表达方式概览 1 欧拉角 欧拉角使用最简单的x y z值来分别表
  • openGL之API学习(七十四)opengl版本的历史沿革

    OpenGL源于SGI公司为其图形工作站开发的IRIS GL 在跨平台移植过程中发展成为OpenGL SGI在1992年7月发布1 0版 后成为工业标准 由成立于1992年的独立财团OpenGL Architecture Review Bo
  • openGL之API学习(七十七)glDrawElements

    通过索引方式来绘制几何图元 如果要 glDrawArrays 和 glDrawElements 正确进行绘制的话 必须在之前 调用带有相应参数的 glEnableClientState 方法 glDrawArrays使用的是顶点 而glDr
  • WebGL系列 - 裁剪空间矩阵优化

    该系列仅为记录自己的学习相关知识 以 2d 的顶点着色器为例
  • 【openGL2021版】天空盒

    openGL2021版 天空盒 大家好 我是Lampard猿奋 欢迎来到船新的openGL基础系列的博客 今天主要实现的是天空盒 1 什么是天空盒 上周我们已经实现了FPS式的摄像机控制 键盘的 WSAD 可以控制摄像头的前后左右移动 鼠标
  • B样条曲线

    学习B样条曲线需要先学习贝塞尔曲线 若未了解 看我一篇上博客https blog csdn net weixin 42513339 article details 83019610 贝塞尔函数不足 由于贝塞尔曲线存在以下不足 1 缺乏局部修
  • games101,作业1

    正交变换 左边是缩放变换 右边是平移变换 对图形进行正交变换需要 先平移 再缩放 但是做矩阵乘法时 先相乘的矩阵放在右边 后相乘的矩阵放在左边 视口平移 Translate M ortho trans lt lt 1 0 0 r l 2 0
  • 光线追踪渲染实战(五):低差异序列与重要性采样,加速收敛!

    项目代码仓库 GitHub https github com AKGWSB EzRT gitee https gitee com AKGWSB EzRT 目录 前言 1 低差异序列介绍 2 sobol 序列及其实现 2 1 生成矩阵与递推式
  • openGL之API学习(三十三)查看opengl、显卡的信息

    const GLubyte name glGetString GL VENDOR 返回负责当前OpenGL实现厂商的名字 const GLubyte biaoshifu glGetString GL RENDERER 返回一个渲染器标识符
  • Game101现代计算机图形学入门学习笔记(七)

    光线追踪 一 光线追踪 1 为什么要使用光线追踪 二 基础光线追踪算法 1 光线 2 光线投射 1 着色过程 3 递归光线追踪 Whitted Style 1 基本过程 2 光线 表面相交 1 光线方程 3 轴对称包围盒 AABB 1 Un
  • 【翻译】Dagre-D3 文档整理和翻译

    地址 github Dagre D3 目录 文章目录 dagre d3 设计优先级 安装 npm Bower Browser Scripts 源代码构建 如何使用Darge 聚焦渲染 例子 配置布局 生成的图像 第三部分例子 推荐阅读 da
  • 全局光照算法:reflective shadow maps

    1 技术理解 RSM的全称是reflective shadow maps 受到Instant Radiosity这个离线技术的启发 其思想和ShadowMap的思想近似 在正式介绍和了解这个技术之前 我需要确定RSM用处何在 我想 RTR4
  • Game101现代计算机图形学作业1

    Game101现代计算机图形学作业1 一 作业描述 二 解决方法 一 模型变换 二 投影变换 绕任意轴旋转 三 总结 四 参考和引用 一 作业描述 给定三维下三个点 v 0 2 0 0

随机推荐

  • 深入理解Android之AOP

    深入理解Android之AOP 格式更加精美的PDF版请到 http vdisk weibo com s z68f8l0xTgCLK 下载 一 闲谈AOP 大家都知道OOP 即ObjectOriented Programming 面向对象编
  • OpenGL 创建OpenGL上下文(OpenGL Context WGL)

    文章目录 OpenGL Context 窗口 Pixel Format 创建上下文 Create Context MakeCurrent 删除上下文 Delete Context 如何正确创建Context 创建一个假的Context 获取
  • 2023华为OD机试真题【双指针/优雅子数组】

    题目内容 如果一个数组中出现次数最多的元素出现大于等于K次 被称为K 优雅数组 k也可以被称为优雅阈值 例如 数组1 2 3 1 2 3 1 它是一个3 优雅数组 因为元素1出现次数大于等于3次 数组1 2 3 1 2就不是一个3 优雅数组
  • 蓝桥杯 填字母游戏(博弈论)

    小明经常玩 LOL 游戏上瘾 一次他想挑战K大师 不料K大师说 我们先来玩个空格填字母的游戏 要是你不能赢我 就再别玩LOL了 K大师在纸上画了一行n个格子 要小明和他交替往其中填入字母 并且 1 轮到某人填的时候 只能在某个空格中填入L或
  • 寻找3的幂

    目录 题目 题目接口 题目思路 第一点 第二点 第三点 代码实现 普通版本 提交 递归版本 提交 结语 题目 在ledcode刷题网站上 有这样一道题 寻找3的幂 题目接口 bool isPowerOfThree int n 题目思路 第一
  • 【HTML】HTML5的拖放你用了吗

    HTML HTML5的拖放你用了吗 引言 github HTML HTML5的拖放你用了吗 内容速递 看了本文您能了解到的知识 在 HTML5 中 拖放是标准的一部分 任何元素都能够拖放 拖放的操作 多用在拖拽排序列表 游戏拼图等 下文中出
  • 华为OD机试 - 贪吃蛇(Java)

    题目描述 贪吃蛇是一个经典游戏 蛇的身体由若干方格连接而成 身体随蛇头移动 蛇头触碰到食物时 蛇的长度会增加一格 蛇头和身体的任一方格或者游戏版图边界碰撞时 游戏结束 下面让我们来完成贪吃蛇游戏的模拟 给定一个N M的数组arr 代表N M
  • roslaunch error: ERROR: cannot launch node of type

    今天在因为github上有个之前的包更新了 重新git clone后出现了一个问题 ERROR cannot launch node of type crazyflie demo controller py can t locate nod
  • 【FPGA】通俗理解从VGA显示到HDMI显示

    注 大部分参考内容来自 征途Pro FPGA Verilog开发实战指南 基于Altera EP4CE10 2021 7 10 上 贴个下载地址 野火FPGA Altera EP4CE10征途开发板 核心板 野火产品资料下载中心 文档 hd
  • MySQL报错的解决Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘

    使用数据库工具连接或还原数据库数据时 提示Can t connect to local MySQL server through socket var lib mysql mysql sock 处理方法 1 修改配置文件 vim etc m
  • 二叉树结构的建立与遍历

    实验项目 1 编写建立二叉树的二叉链表存储结构 左右链表示 的程序 并以适当的形式显示和保存二叉树 2 完成二叉树的7种遍历操作 3 给定一个二叉树 编写算法完成下列应用 1 判断其是否为完全二叉树 2 求二叉树中任意两个结点的公共祖先 输
  • wps日期加减算天数_日期相减之后的天数怎么用公式计算 - 卡饭网

    如何在Excel中得到两个日期相减的天数 如何在Excel中得到两个日期相减的天数 有的小伙伴在使用Excel软件时 想要知道两个日期相减后的天数 但是却不知道使用什么公式 也不知道公式中的数据的含义 那么小编就来为大家介绍一下吧 具体如下
  • Python安装教程(版本3.8.10)windows10

    Python目前已支持市面上的各大主流操作系统 在Linux Unix Mac系统已经自带Python环境 本章将介绍在Windows系统上安装Python 一般下载 executable installer x86 表示是 32 位的机器
  • 基于Python Django 搜索的目标站点内容监测系统设计

    1 简介 基于搜索的目标站点内容监测系统 包括登陆 首页 数据采集 爬虫分析 数据管理 修改密码和用户管理等功能 2 技术栈 说明 技术栈 备注 后台 Python Django 前端 HTML 数据库 MYSql 架构 B S 结构 3
  • MySQL数据库保姆级安装教程

    俗话说从入门到放弃 从入门到入土 开始学习MySQL之前我们一定是要做环境准备的 接下来我们来讲解一下MySQL的安装 一 MySQL下载 MySQL 1 大家可以尝试在官网首页寻找下载入口 也可以使用我提供的MySQL的安装包进行下载安装
  • 数据结构之双向链表,实现双向链表的增删改查

    目录 一 双向链表的定义 1 双向链表节点的定义 2 双向链表的初始化 二 双向链表的函数接口实现 1 双链表的尾插 2 双向链表的尾删 3 双向链表的头插 4 双向链表的头删 6 双向链表在pos前面插入 7 双向链表删除pos位置的节点
  • 1.Twitter开发者之如何申请一个twitter开发者账号

    Twitter开发者之如何申请一个twitter开发者账号 教大家申请一个推特开发者账号满足后面的使用 保证每一步都给大家介绍到 非常详细 希望帮助大家注册好自己的账号 1 先打开Twitter的账号注册界面 选择使用手机号码或电子邮箱注册
  • C51单片机实验——脉冲计数显示(proteus+asm)

    前言 脉冲信号输入进2级74LS14整形 T1接收脉冲信号并计数 显示在LED 外部中断0控制计数器的启动 停止 外部中断1控制计数器的清零复位 P1 0控制LED的段选口使能信号 P1 1控制LED的位选口使能信号 Proteus电路图
  • ios代码大全】代码例子区全区搜索索引

    IOS 类代码 我自己做的翻书效果 小猫咪再次登场 2011 03 02 如何实现QQLive HD界面 附代码 2011 03 02 tabelviewcell 点击设置背景图片 2011 03 02 基于UDP的聊天程序 借鉴iphon
  • OpenGL ES 3.0 Programming Guide 1-3

    一 introduction to OGLES 3 0 OGLES 3 0 Graphics Pipeline VertexBuffer ArrayObj gt VertexShader texture transform feedback