Skip to content

Commit

Permalink
Merge pull request #1817 from flibitijibibo/texture2d-gl-getdata
Browse files Browse the repository at this point in the history
Texture2D: Fix OpenGL GetData with null Rect
  • Loading branch information
dellis1972 committed Jul 5, 2013
2 parents 1380c04 + 9480286 commit 1c5bea5
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions MonoGame.Framework/Graphics/Texture2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,28 +667,27 @@ public int Height
}

#else
var temp = new T[this.width*this.height];

GL.BindTexture(TextureTarget.Texture2D, this.glTexture);

if (glFormat == (GLPixelFormat)All.CompressedTextureFormats) {
throw new NotImplementedException();
} else {
GL.GetTexImage(TextureTarget.Texture2D, level, this.glFormat, this.glType, temp);
}

if (rect.HasValue) {
int z = 0, w = 0;

for(int y= rect.Value.Y; y < rect.Value.Y+ rect.Value.Height; y++) {
for(int x=rect.Value.X; x < rect.Value.X + rect.Value.Width; x++) {
data[z*rect.Value.Width+w] = temp[(y*width)+x];
w++;
if (rect.HasValue) {
var temp = new T[this.width*this.height];
GL.GetTexImage(TextureTarget.Texture2D, level, this.glFormat, this.glType, temp);
int z = 0, w = 0;

for(int y= rect.Value.Y; y < rect.Value.Y+ rect.Value.Height; y++) {
for(int x=rect.Value.X; x < rect.Value.X + rect.Value.Width; x++) {
data[z*rect.Value.Width+w] = temp[(y*width)+x];
w++;
}
z++;
}
z++;
} else {
GL.GetTexImage(TextureTarget.Texture2D, level, this.glFormat, this.glType, data);
}
} else {
data = temp;
}

#endif
Expand Down

0 comments on commit 1c5bea5

Please sign in to comment.