Chapter 1. Introduction(第一章:介绍)

周一到周五,每天一篇,北京时间早上7点准时更新~,中英文对照,一边学编程一边弹吉他,做一个奇葩码农!

请不要怀疑翻译是否有问题,我们的翻译工程师是蓝翔毕业的呢!

What You’ll Learn in This Chapter(你将会学到啥)

  • What the graphics pipeline is and how OpenGL relates to it(什么是图形管线以及OpenGL与它之间的关系)
  • The origins of OpenGL and how it came to be the way that it is today(OpenGL的起源以及它是怎么发展到现在这个样子的)
  • Some of the fundamental concepts that we’ll be building on throughout the book(一些基本的贯穿本书我们都会用到的概念)

This book is about OpenGL(这本书是关于OpenGL的). OpenGL is an interface that your application can use to access and control the graphics subsystem of the device on which it runs(OpenGL是你的应用程序可以通过它来访问和控制图形子系统硬件设备的编程接口). This could be anything from a high-end graphics workstation(这些硬件设备可以是任何东西,从高端的图形工作站), to a commodity desktop computer(到商用的桌面电脑), to a video game console(到游戏主机), to a mobile phone(甚至是手机). Standardizing the interface to a subsystem increases portability and allows software developers to concentrate on creating quality products(标准化这些硬件系统的接口之后,可以增加代码的可移植性并且可以让软件开发者更集中精力在产品质量), producing interesting content(开发更有趣的内容), and ensuring the overall performance of their applications(以及保证他们应用程序的综合性能的事情上面), rather than worrying about the specifics of the platforms they want them to run on(而没必要去担心他们的应用程序无法发布到某些特殊的平台上去). These standard interfaces are called application programming interfaces (APIs)(这些标准接口被称为应用程序编程接口), of which OpenGL is one(OpenGL就是众多编程接口中的一个). This chapter introduces OpenGL(本章节介绍OpenGL), describes how it relates to the underlying graphics subsystem(阐述它是如何跟底层的图形子系统进行关联的), and provides some history on the origin and(并且提供一些关于OpenGL起源以及OpenGL迭代进化方面的历史) evolution of OpenGL

 

OpenGL and the Graphics Pipeline(OpenGL和图形管线)

Generating a product at high efficiency and volume generally requires two things(要在生产的时候保持高性能以及很产能,通常来说需要把握两个关键点): scalability and parallelism(可扩展性和并行性). In factories, this is achieved by using production lines(在工厂里面,我们通过流水线来达到这一目的). While one worker installs the engine in a car(当某一个工人在给汽车安装发动机的时候), another can be installing the doors(另一个工人在给汽车装窗户), and yet another can be installing the wheels(而别的工人在给汽车装轮胎). By overlapping the phases of production of the product(通过把产品的生产过程分割成各个小段,然后让这些小段并行起来), with each phase being executed by a skilled technician who concentrates his or her energy on that single task(每个小段上安排一个牛叉的技工,他可以把他的全部精力集中在他自己的那一小段工作任务上), each phase becomes more efficient and overall productivity goes up(这样一来,所有的小段任务都会变得更加的高效,并且全局的产能会得到提高,这尼玛就是典型的资本主义剥削的写照). Also, by making many cars at the same time(如果同时安排多个车辆制作的流水线), a factory can have multiple workers installing multiple engines or wheels or doors and many cars can be on the production line at the same time(这样一来多个工人就可以同时安装多个发动机或者轮子或者门窗,更多的车子可以被在同一时间生产出来), each at a different stage of completion(每个步骤在不同的小段中完成). The same is true in computer graphics(这个原理同样适用于计算机图形学). The commands from your program are taken by OpenGL and sent to the underlying graphics hardware(你程序发出的渲染指令会通过OpenGL发送给底层的图形硬件), which works on them in an efficient manner to produce the desired result as quickly and efficiently as possible(这些图形硬件会通过非常高效的手段尽可能快的计算出你预期的结果). There could be many commands lined up to execute on the hardware (a status referred to as in flight)(可能会有很多个指令同时在硬件上执行), and some may even be partially completed(其中可能会有一部分只执行了某个大操作的一半). This allows their execution to be overlapped such that a later stage of one command might run concurrently with an earlier stage of another command(这种只执行了一半的指令可能会与后面某些指令进行结合,完成最终的功能). Futhermore, computer graphics generally consists of many repititions of very similar tasks (such as figuring out what color a pixel should be)(比如说,在计算机图形学中通常会有很多重复的小操作,比如查询当前状态机中颜色是啥颜色的), and these tasks are usually indpendent of one another—that is(这样的操作往往是互相之间独立开来的), the result of coloring one pixel doesn’t depend on any other(查询的结果不会依赖于其他的那些查询颜色的指令). Just as a car plant can build multiple carssimultaneously, so OpenGL can break up the work you give it and work on its fundamental elements in parallel(就如同之前的汽车流水线一样,你应用程序调用OpenGL的API之后,OpenGL会自动把他们切割成小元素,然后让他们并行执行). Through a combination of pipelining and parallelism, incredible performance of modern graphics processors is realized(通过流水线和并行操作,现代的图形显卡表现出了难以置信的效率). The goal of OpenGL is to provide an abstraction layer between your application and the underlying graphics subsystem(OpenGL的目标是提供一个处于应用程序和底层图形硬件之间的一个抽象层), which is often a hardware accelerator made up of one or more custom, high-performance processors with dedicated memory, display outputs, and so on(通常情况下,硬件加速器由一个或者更多的高性能处理器以及显存和显示输出等等之类的玩意组成). This abstraction layer allows your application to not need to know who made the graphics processor (or graphics processing unit [GPU])(OpenGL提供的抽象层使得你在写程序的时候不用去管到底是谁造了这个显卡、它是如何工作的或者说它性能到底如何,你通通不用管), how it works, or how well it performs. Certainly it is possible to determine this information, but the point is that applications don’t need to(当然,如果你想的话,你也可以查询到这些显卡信息,这里想说明的问题是,你可以不用去知道这些鬼玩意)

As a design principle(作为一个设计的原则), OpenGL must strike a balance between too high and too low an abstraction level(OpenGL必须注意设计时不要搞得太抽象,也不要搞得太具体,这个平衡是很难把握的). On the one hand(另一方面), it must hide differences between various manufacturers’ products (or between the various products of a single manufacturer) and system-specific traits such as screen resolution(它必须隐藏掉系统特性的差异,比如屏幕分辨率这样的东西啦、处理器的架构啦、装在什么操作系统上等等这种东西), processor architecture, installed operating system, and so on. On the other hand, the level of abstraction must be low enough that programmers can gain access to the underlying hardware and make best use of it(在另一方面,为何老外写文章连续写了两次在另一方面,OpenGL又必须让抽闲的级别足够的接近底层,以让编程人员能够更好的使用底层硬件). If OpenGL presented too high of an abstraction level, then it would be easy to create programs that fit the model(如果抽象层次太高,那么是非常容易写程序的), but very hard to use advanced features of the graphics hardware that weren’t included(但这样一来带来的问题就是,编程人员很难使用系统的一些比较高级的特性). This is the type of model followed by software such as game engines—new features of the graphics hardware generally require relatively large changes in the engine for games built on top of it to gain access to them(需要访问高级特性的软件比如说游戏引擎就是其中一种,通常来说,为了使用新的硬件特性,游戏引擎需要撸很多代码). If the abstraction level is too low, applications need to start worrying about architectural peculiarities of the system they’re running on(如果抽象层次太接近硬件了,那么回带来程序员需要自己去适应各种不同硬件的问题). Low levels of abstraction are common in video game consoles(比较接近硬件的代码通常会时候会让人想到游戏主机这种玩意,各种主机游戏都有自家的独特的代码和硬件以及操作系统), for example, but don’t fit well into a graphics library that must support devices ranging from mobile phones to gaming PCs to highpowered professional graphics workstations(主机游戏的代码往往无法很好的适配一些在手机游戏或者PC游戏需要使用的图形库)

As technology advances, more and more research is being conducted in computer graphics(随着技术的发展,图形学领域出现了越来越多的研究成功), best practices are being developed(优秀的写代码的方式已经得到了证明,咱们跟着那些规矩来写就可以了), and bottlenecks and requirements are moving—and so OpenGL must also move to keep up(面临的瓶颈和需求也在随着时代在变化,所以OpenGL也需要继续发展)

The current state of the art in graphics processing units(在图形处理单元中的当前状态的概念,是绝大多数OpenGL的实现的基础), on which most OpenGL implementations are based, is capable of many teraflops of computing power(这些处理器现在已经强大到每秒可以做万亿次浮点运算), has gigabytes of memory that can be accessed at hundreds of gigabytes per second(每秒钟可以访问几百GB的内存数据), and can drive multiple, multi-megapixel displays at high refresh rates(并且可以同时控制多台显示器以非常快的频率进行画面更新). GPUs are also extremely flexible(显卡也非常的易用), and are able to work on tasks that might not be considered graphics at all(已经可以用它来干那些本来不会被认为是显卡该干的事情了呢), such as physical simulations, artificial intelligence, and even audio processing(比如物理模拟、人工智能甚至是音频处理)

Current GPUs consist of large numbers of small programmable processors called shader cores that run mini-programs called shaders(现在的这些显卡由很多可编程的处理器组成,这些处理器被称为着色核心,在处理器上运行的程序被称为着色器). Each core has a relatively low throughput(每个核心计算能力相对来说较低), processing a single instruction of the shader in one or more clock cycles and normally lacking advanced features such as out-of-order execution(比如在一个或者多个时间片内处理单一的一个来自shader的指令,并且通常来说是没有什么高级特性的), branch prediction,super-scalar issues, and so on. However, each GPU might contain anywhere from a few tens to a few thousands of these cores(但是显卡通常有几十个甚至上千个这样的计算能力不那么好的核心), and together they can perform an immense amount of work(这些家伙一起干活的时候,还是很牛的呢). The graphics system is broken into a number of stages(图形系统被分解成了很多个处理部分), each represented either by a shader or by a fixed-function(每一个部分要么被shader处理,要么被显卡中固定的硬件处理), possibly configurable processing block. Figure 1.1 shows a simplified schematic of the graphics pipeline(下面的图就展示了图形流水线的处理过程)

In Figure 1.1, the boxes with rounded corners are considered fixed-function stages(上图中,圆角矩形被认为是由硬件的固定处理单元来处理的), whereas the boxes with square corners are programmable(非圆角矩形的部分,是可编程部分,就是你可以塞一个shader进去,想干嘛干嘛的), which means that they execute shaders that you supply. In practice(按道理来讲,部分甚至全部那些固定硬件处理的部分也是可以让程序员来写shader的), some or all of the fixed-function stages may really be implemented in shader code, too—it’s just that you don’t supply that code, but rather the GPU manufacturer generally supplies it as part of a driver, firmware, or other system software(然而现在的情况是,你没办法往那里塞shader,所以你无法接管那些过程,这些东西目前都是被显卡的制造商通过它们提供的驱动或者什么玩意管理的,总之你不要想那块的问题就是了)

第一时间获取最新桥段,请关注东汉书院以及图形之心公众号

东汉书院、等你来玩哦

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值