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

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

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

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

  • 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和图形管线)app

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(固然,若是你想的话,你也能够查询到这些显卡信息,这里想说明的问题是,你能够不用去知道这些鬼玩意)ide

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也须要继续发展)flex

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(好比物理模拟、人工智能甚至是音频处理)ui

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(下面的图就展现了图形流水线的处理过程)this

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

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,因此你没法接管那些过程,这些东西目前都是被显卡的制造商经过它们提供的驱动或者什么玩意管理的,总之你不要想那块的问题就是了)

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

东汉书院、等你来玩哦

相关文章
相关标签/搜索