Skip to main content
Notice removed Draw attention by CommunityBot
Bounty Ended with Jerry Coffin's answer chosen by CommunityBot
added 201 characters in body
Source Link
user40773
user40773

EDIT: Sleepy profile times:

enter image description here

enter image description here

EDIT: Sleepy profile times:

enter image description here

enter image description here

Tweeted twitter.com/#!/StackCodeReview/status/457300197849448448
added 4 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Sprite drawing class improvement

I have written a very XnaXNA spritebatch like interface for drawing sprites in openglOpenGL. When begin is called the vertex data buffer is mapped to a float*. The index buffer and vertex buffer are bound in begin, and it's assumed no other drawing is done in this openglOpenGL context between begin and end. In between begin and end, "DrawSprite"DrawSprite is called. DrawSpriteDrawSprite has a bunch of overloads allowing one to draw with a scale, and matrix, a source rectangle etc. However, they all take their parameters and call "BufferSprite"BufferSprite which actually writes the sprite data to memory  ( thethe x,y,z position, the x,y texture coordinates, and the rgba colour values.  ) When end is called, the vertices are drawn in as few "glDrawElements"glDrawElements calls as possible.

I know it's a lot, but I'd appreciate it if someone could help me make this faster. If there is only one texture begin drawn over and over again in release mode, I get about 60fps60FPS for about 33k sprites( The SAME texture ). This only gets worse as I interleave textures. I've done a bit of profiling and omitting code, and it looks to me like BufferSpriteBufferSprite is taking the most time by far. I'd just like to know if there's anything obvious I'm not doing right, such as writing to the buffer in a poor way, or maybe I should be uploading different data to the shader.

Also, I realise a lot of openglOpenGL stuff in this is wrapped in my own classes, so if you need any specific source code I'll edit this post.

Sprite drawing class improvement

I have written a very Xna spritebatch like interface for drawing sprites in opengl. When begin is called the vertex data buffer is mapped to a float*. The index buffer and vertex buffer are bound in begin, and it's assumed no other drawing is done in this opengl context between begin and end. In between begin and end, "DrawSprite" is called. DrawSprite has a bunch of overloads allowing one to draw with a scale, and matrix, a source rectangle etc. However, they all take their parameters and call "BufferSprite" which actually writes the sprite data to memory( the x,y,z position, the x,y texture coordinates, and the rgba colour values.  ) When end is called, the vertices are drawn in as few "glDrawElements" calls as possible.

I know it's a lot, but I'd appreciate it if someone could help me make this faster. If there is only one texture begin drawn over and over again in release mode, I get about 60fps for about 33k sprites( The SAME texture ). This only gets worse as I interleave textures. I've done a bit of profiling and omitting code, and it looks to me like BufferSprite is taking the most time by far. I'd just like to know if there's anything obvious I'm not doing right, such as writing to the buffer in a poor way, or maybe I should be uploading different data to the shader.

Also, I realise a lot of opengl stuff in this is wrapped in my own classes, so if you need any specific source code I'll edit this post.

Sprite drawing class

I have written a very XNA spritebatch like interface for drawing sprites in OpenGL. When begin is called the vertex data buffer is mapped to a float*. The index buffer and vertex buffer are bound in begin, and it's assumed no other drawing is done in this OpenGL context between begin and end. In between begin and end, DrawSprite is called. DrawSprite has a bunch of overloads allowing one to draw with a scale, and matrix, a source rectangle etc. However, they all take their parameters and call BufferSprite which actually writes the sprite data to memory  (the x,y,z position, the x,y texture coordinates, and the rgba colour values.) When end is called, the vertices are drawn in as few glDrawElements calls as possible.

I know it's a lot, but I'd appreciate it if someone could help me make this faster. If there is only one texture begin drawn over and over again in release mode, I get about 60FPS for about 33k sprites( The SAME texture ). This only gets worse as I interleave textures. I've done a bit of profiling and omitting code, and it looks to me like BufferSprite is taking the most time by far. I'd just like to know if there's anything obvious I'm not doing right, such as writing to the buffer in a poor way, or maybe I should be uploading different data to the shader.

Also, I realise a lot of OpenGL stuff in this is wrapped in my own classes, so if you need any specific source code I'll edit this post.

Notice added Draw attention by user40773
Bounty Started worth 100 reputation by CommunityBot
Edited tags.
Link
Morwenn
  • 20.2k
  • 3
  • 69
  • 132
Source Link
user40773
user40773
Loading