日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

opengl如何画出一个球_OpenGL-Controlling and Monitoring the Pipeline

發(fā)布時(shí)間:2023/12/3 编程问答 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 opengl如何画出一个球_OpenGL-Controlling and Monitoring the Pipeline 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

全球圖形學(xué)領(lǐng)域教育的領(lǐng)先者、自研引擎的倡導(dǎo)者、底層技術(shù)研究領(lǐng)域的技術(shù)公開(kāi)者,東漢書院在致力于使得更多人群具備內(nèi)核級(jí)競(jìng)爭(zhēng)力的道路上,將帶給小伙伴們更多的公開(kāi)技術(shù)教學(xué)和視頻,感謝一路以來(lái)有你的支持。我們正在用實(shí)際行動(dòng)來(lái)幫助小伙伴們構(gòu)建一套成體系的圖形學(xué)知識(shí)架構(gòu),你在我們這里獲得的不止于那些毫無(wú)意義的代碼,我們這里更多的是代碼背后的故事,以及精準(zhǔn)、透徹的理解。我們不會(huì)扔給人們一本書或者給個(gè)思路讓人們?nèi)プ詫W(xué),我們是親自來(lái)設(shè)計(jì)出好的資源,讓人們明白到底背后還有哪些細(xì)節(jié)。

這里插播一個(gè)引擎大賽的消息,感興趣的同學(xué)可以看一眼,這也是東漢書院的立項(xiàng)使命:

瘋狂的程序員:自研引擎大賽?zhuanlan.zhihu.com

大賽官方主頁(yè)

東漢書院-自己動(dòng)手寫游戲引擎?edu.battlefire.cn

參賽作品列表

瘋狂的程序員:參賽作品1-NaturalEngine?zhuanlan.zhihu.com瘋狂的程序員:參賽作品2-Colble離線室內(nèi)渲染器和Juziimo實(shí)時(shí)外觀渲染器?zhuanlan.zhihu.com

Chapter 12. Controlling and Monitoring the Pipeline

What You’ll Learn in This Chapter

  • How to ask OpenGL about the progress of your commands down the graphics pipeline.
  • How to measure the time taken for your commands to execute.
  • How to synchronize your application with OpenGL and how to synchronize multiple OpenGL contexts with each other.

你將會(huì)在本章學(xué)到啥

  • 如何詢問(wèn)OpenGL你的指令在圖形管線中的執(zhí)行進(jìn)度
  • 如何計(jì)算出你的指令花費(fèi)了多少時(shí)間
  • 如何處理OpenGL與你的程序的同步問(wèn)題以及如何同步多個(gè)OpenGL的渲染上下文

This chapter is about the OpenGL pipeline and how it executes your commands. As your application makes OpenGL function calls, work is placed in the OpenGL pipeline and makes its way down it one stage at a time. This takes time, and you can measure that span. This allows you to tune your application’s complexity to match the performance of the graphics system and to measure and control latency, which is important for real-time applications. In this chapter, you’ll also learn how to synchronize your application’s execution to that of OpenGL commands you’ve issued and even how to synchronize multiple OpenGL contexts with each other.

本章是介紹OpenGL的管線的以及它如何執(zhí)行你的指令。當(dāng)你的程序調(diào)用OpenGL的API的時(shí)候,這些指令都會(huì)在OpenGL的管線里得到執(zhí)行并且每次執(zhí)行一個(gè)階段。這個(gè)操作是耗費(fèi)時(shí)間的,你可以計(jì)算出花費(fèi)了多少時(shí)間。 這可以讓你去測(cè)試你程序的復(fù)雜度然后去很好適配你的圖形系統(tǒng)的性能,并且掌握并處理好延遲,這對(duì)于實(shí)時(shí)應(yīng)用程序來(lái)說(shuō)是非常重要的。在本章中,你將同樣會(huì)學(xué)到如何去同步你程序發(fā)送給OpenGL的那些指令甚至能學(xué)到 如何去同步多個(gè)OpenGL的渲染上下文。

Queries

Queries are a mechanism to ask OpenGL what’s happening in the graphics pipeline. There’s plenty of information that OpenGL can tell you; you just need to know what to ask—and how to ask the question.

Queries是一種查詢OpenGL圖形管線里正在發(fā)生什么的一種機(jī)制。你可以查詢到很多東西,你需要做的就是知道可以查詢什么以及如何去查詢。

Remember your early days in school? The teacher wanted you to raise your hand before asking a question. This was almost like reserving your place in line for asking the question—the teacher didn’t know yet what your question was going to be, but she knew that you had something to ask. OpenGL is similar. Before we can ask a question, we have to reserve a spot so that OpenGL knows the question is coming. Questions in OpenGL are represented by query objects, and much like any other object in OpenGL, query objects must be reserved, or generated. To do this, call glGenQueries(), passing it the number of queries you want to reserve and the address of a variable (or array) where you would like the names of the query objects to be placed:

回想起在學(xué)校里的那些日子會(huì)想到啥?老師們會(huì)希望你在提問(wèn)之前先舉手。你這么做就非常類似于在一個(gè)隊(duì)列里面占據(jù)一個(gè)問(wèn)問(wèn)題的位置,這時(shí)候老師還不知道你想問(wèn)什么,但是他們知道你有東西要問(wèn)。OpenGL是類似的。 在你問(wèn)問(wèn)題之前,你必須讓我們知道你想要問(wèn)問(wèn)題。OpenGL里面使用query object來(lái)表現(xiàn)問(wèn)題的,就跟OpenGL里面的其他object一樣,query object必須實(shí)現(xiàn)申明然后生成。我們可以調(diào)用glGenQueries,傳入你希望 預(yù)留多少個(gè)query object以及傳入一個(gè)地址,告訴OpenGL你希望那些query object名字被寫進(jìn)哪里:

void glGenQueries(GLsizei n,GLuint *ids);

The function reserves some query objects for you and gives you their names so that you can refer to them later. You can generate as many query objects you need in one go:

這個(gè)函數(shù)預(yù)留了一些query object并且給出了他們的名字,你可以在后面的代碼中使用這些名字來(lái)引用這些query object。你可以一次性生成很多個(gè)query object:

GLuint one_query; GLuint ten_queries[10]; glGenQueries(1, &one_query); glGenQueries(10, ten_queries);

In this example, the first call to glGenQueries() generates a single query object and returns its name in the variable one_query. The second call to glGenQueries() generates ten query objects and returns ten names in the array ten_queries. In total, 11 query objects have been created, and OpenGL has reserved 11 unique names to represent them. It is very unlikely, but still possible, that OpenGL will not be able to create a query for you; in this case it returns 0 as the name of the query. A well-written application always checks that glGenQueries() returns a non-zero value for the name of each requested query object. If there is a failure, OpenGL keeps track of the reason, and you can find that out by calling glGetError().

在本例子中,第一個(gè)對(duì)glGenQueries的調(diào)用中生成了一個(gè)query object并且把它的名字寫入了one_query這個(gè)變量里面。第二次對(duì)glGenQueries的調(diào)用生成了10個(gè)query object并且把10個(gè)名字寫入了ten_queries 變量里面。你總共生成了11個(gè)query object,OpenGL為你預(yù)留了11個(gè)獨(dú)一無(wú)二的名字來(lái)表示這些query object。當(dāng)name里面的值是0的時(shí)候,就表示OpenGL不能給你創(chuàng)建query object。一個(gè)良好的編程習(xí)慣就是 在調(diào)用了glGenQueries之后,去檢查一下返回值是不是非0。如果這個(gè)操作失敗了,OpenGL會(huì)保留一份錯(cuò)誤原因,你可以通過(guò)glGetError()來(lái)獲取到為什么失敗了。

Each query object reserves a small but measurable amount of resources from OpenGL. These resources must be returned to OpenGL because, if they are not, OpenGL may run out of space for queries and fail to generate more for the application later. To return the resources to OpenGL, call glDeleteQueries():

每一個(gè)query object會(huì)從OpenGL里面占有一份小的,但是可以度量的資源。這些資源必須最后回收給OpenGL,因?yàn)槿绻鼈儧](méi)有被回收的話,那么OpenGL可能會(huì)沒(méi)有內(nèi)存了并且無(wú)法為應(yīng)用程序創(chuàng)建更多的queries。 我們可以調(diào)用glDeleteQueries來(lái)把query object的資源回收給OpenGL。

void glDeleteQueries(GLsizei n,const GLuint *ids);

This works similarly to glGenQueries()—it takes the number of query objects to delete and the address of a variable or array holding their names:

這個(gè)跟glGenQueries類似,它會(huì)接受兩個(gè)參數(shù),第一個(gè)是你想回收多少query object,第二個(gè)參數(shù)就是具體的這些你想回收的query object的存放位置。

glDeleteQueries(10, ten_queries); glDeleteQueries(1, &one_query);

After the queries are deleted, they are essentially gone for good. The names of the queries can’t be used again unless they are given back to you by another call to glGenQueries().

當(dāng)你的queries被刪除了之后,他們基本上都是沒(méi)問(wèn)題的,這些名字是不會(huì)被重用的,直到你下次調(diào)用glGenQueries的時(shí)候再次獲得它們。

我們核心關(guān)注和討論的領(lǐng)域是引擎的底層技術(shù)以及商業(yè)化方面的信息,可能并不適合初級(jí)入門的同學(xué)。另外官方維護(hù)兩個(gè)公眾號(hào),第一個(gè)公眾號(hào)是關(guān)于我們企業(yè)自身產(chǎn)品的信息與動(dòng)態(tài)的公眾號(hào),如果對(duì)我們自身信息與動(dòng)態(tài)感興趣的同學(xué),可以關(guān)注圖形之心。

除此之外,我們?yōu)榱烁l繁的發(fā)布一些咨詢與文章,我們維護(hù)的第二個(gè)公眾號(hào)是“內(nèi)核觀察”,內(nèi)核觀察提供的主要是一些與我們無(wú)關(guān)的咨詢與文章。

只言片語(yǔ),無(wú)法描繪出整套圖形學(xué)領(lǐng)域的方方面面,只有成體系的知識(shí)結(jié)構(gòu),才能夠充分理解和掌握一門科學(xué),這是藝術(shù)。我們已經(jīng)為你準(zhǔn)備好各式各樣的內(nèi)容了,東漢書院,等你來(lái)玩。

總結(jié)

以上是生活随笔為你收集整理的opengl如何画出一个球_OpenGL-Controlling and Monitoring the Pipeline的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。