【发布时间】:2014-06-09 01:08:40
【问题描述】:
我刚刚在我的 pygame 应用程序中实现了基本的 opengl 渲染,我认为硬件加速会使程序运行得更快。相反,它要慢得多。
看起来问题出在绘图功能上。
这是我的opengl绘图功能
def draw(self, screen):
rect = self.texture.imagerect.copy()
rect.x += self.xoffset
rect.y += self.yoffset
halfWidth = self.getWidth()/2
halfHeight = self.getHeight()/2
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, self.texture.getTexID())
self.color.setGLColor()
glPushMatrix()
glTranslatef(rect.x,rect.y,0)
glRotatef(self.angle, 0, 0, 1);
glBegin(GL_QUADS)
glTexCoord2d(0,0)
glVertex2f(-halfWidth + self.pivot.x, -halfHeight + self.pivot.y)
glTexCoord2d(0,1)
glVertex2f(-halfWidth + self.pivot.x,-halfHeight + self.getHeight() + self.pivot.y)
glTexCoord2d(1,1)
glVertex2f(-halfWidth + self.getWidth() + self.pivot.x,-halfHeight + self.getHeight() + self.pivot.y)
glTexCoord2d(1,0)
glVertex2f(-halfWidth + self.getWidth() + self.pivot.x,-halfHeight + self.pivot.y)
glEnd()
glPopMatrix()
我的分析器为绘图功能提供了什么
ncalls tottime percall cumtime percall filename:lineno(function)
312792 20.395 0.000 34.637 0.000 image.py:61(draw)
我的探查器文本的其余部分:(1 个月后到期)
我的源代码
https://bitbucket.org/claysmithr/warbots/src
注意:当我将其设置为不绘制任何图块时,我得到 60 fps!如果我限制只绘制出现在屏幕上的图块,我也可以获得 20 fps,但这仍然比 blitting 慢得多
我尝试绘制的图块数 (64x64):15,625
有什么方法可以测试我是否真的是硬件加速的?
我应该回到 blitting 吗?
edit:blitting 不会自动绘制不在屏幕上的图块吗?这可能是opengl如此缓慢的原因!
【问题讨论】:
-
如果您关心性能,您所做的一些事情会有些奇怪。最重要的是,您将纹理坐标作为双精度传递。 1.0 并不比 1.0f 更精确,但是 GL 必须将 1.0 转换为单精度,这样会浪费 CPU 周期。