128 개의 입자를 렌더링하는 동안 프로그램이 느려지는 이유는 무엇입니까? 30fps 미만이면 충분하지 않다고 생각합니다.128 입자를 렌더링하는 동안 내 pyglet 프로그램이 느려지는 이유는 무엇입니까?
내가
on_draw 기능 128 개 입자를 렌더링하고 그들에게 몇 가지 기본적인 중력을주고있다 할 모든
def on_draw(self, time=None):
glClearColor(0.0, 0.0, 0.0, 1.0)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
self.particles.append(Particle())
for particle in self.particles:
particle.draw()
if particle.is_dead:
self.particles.remove(particle)
입자 클래스 내가이기 때문에 GL_TRIANGLE_FAN
사용에 대한 지나치게 행복하지 않다
class Particle:
def __init__(self, **kwargs):
self.acceleration = Vector2(0, 0.05)
self.velocity = Vector2(random.uniform(-1, 1), random.uniform(-1, 0))
self.position = Vector2()
self.time_to_live = 255
self.numpoints = 50
self._vertices = []
for i in range(self.numpoints):
angle = math.radians(float(i)/self.numpoints * 360.0)
x = 10 * math.cos(angle) + self.velocity[0] + 300
y = 10 * math.sin(angle) + self.velocity[1] + 400
self._vertices += [x, y]
def update(self, time=None):
self.velocity += self.acceleration
self.position -= self.velocity
self.time_to_live -= 2
def draw(self):
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glPushMatrix()
glTranslatef(self.position[0], self.position[1], 0)
pyglet.graphics.draw(self.numpoints, GL_TRIANGLE_FAN, ('v2f', self._vertices), ('c4B', self.color))
glPopMatrix()
self.update()
@property
def is_dead(self):
if self.time_to_live <= 0:
return True
return False
@property
def color(self):
return tuple(color for i in range(self.numpoints) for color in (255, 255, 255, self.time_to_live))
몇 가지 : OpenGL의 종류가 잘못되었습니다. "modern OpenGL"을 검색하고 다시 시작하십시오. 현재 코드는 모든 종류의 기존 OpenGL 헛소리로 흩어져 있습니다. 'Particle' 인스턴스에서'draw'를 호출 할 때마다 GL 상태를 중복 갱신합니다. 블렌드 상태 - 외부 렌더링 루프로 그 물건을 꺼내십시오. 그 외에도 문제의 원인이 무엇인지는 분명하지 않지만 1995 년부터 GPU를 사용하지 않는 한 CPU가 완전히 바운드되었을 가능성이 큽니다 (몇 가지 색상 포인트는 GL 구현이나 GPU에 스트레스를주지 않습니다. 일). – thokra