1,爲什麼每一幀都調用glclear?
https://stackoverflow.com/questions/15506110/opengl-espurpose-of-calling-glclear-on-every-frame
清空framebuffer,否則framebuffer會包含上一幀內容
2,vbo,vao,ibo
https://www.photoneray.com/opengl-vao-vbo/
一個是傳輸數據的方式,爲了提高頂點傳輸數據效率的,一個是爲了簡化繪製代碼的,繪製的狀態切換。
bio和vbo類似,是索引緩衝對象,存儲的是索引數組。
3,batch,batching,set pass call
https://zhuanlan.zhihu.com/p/40900056
batch是cpu給每個draw call創建一個數據包,每個batch必須包含一個draw call
batching合併不同的數據到一個draw call裏面叫batching
set pass call cpu發出指令使gpu改變渲染狀態,這個指令稱爲set pass call,他通知gpu如何渲染下一個網格。
某些情形下draw call並不耗費,反而是傳輸數據和設置狀態比較耗,所以這裏需要注意。
4,gldrawarray和gldrawelements
都是繪製函數,一個是用具體數據,一個是用索引數據,因此前一個效能好(有待研究),一個節省內存。
5,python相關opengl
glReadPixels
opengl獲取繪製的內容,存入數組。array可直接傳入,也可傳值
glReadPixels (
x,
y,
width,
height,
format,
type,
array: NoneType=None,
outputType: )
datatmp = glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, outputType=None)
# datatmp是numpy數組array的一個數據結構,可以直接存。
def save_screenshot(self, name="screenshot.png"):
width = glutGet(GLUT_WINDOW_WIDTH)
height = glutGet(GLUT_WINDOW_HEIGHT)
pixelset = (GLubyte * (3 * width * height))(0)
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixelset)
image = Image.fromstring(mode="RGB", size=(width, height), data=pixelset)
image = image.transpose(Image.FLIP_TOP_BOTTOM)
image.save(name)
print("Screenshot saved as '{0}'.".format(name))
im = Image.open(xpath,"r")
img = np.array(im)
# 200,100
# 數組1維 2維
h,w,d = img.shape
xpath = "test1.png"
image = Image.frombytes("RGB", (w,h), img.tobytes())
image.save("test2.png")