fna-workbench

fna-workbench Commit Details


Date:2016-03-18 14:15:38 (8 years 9 months ago)
Author:Ethan Lee
Branch:master
Commit:4e6d2f38ce432e130c7eff1de6ae898660d32930
Parents: 0d69d3a8939a38e140db493394383f157165f9bf
Message:Pull GCHandles out of SetTextureDatas

Changes:

File differences

src/Graphics/IGLDevice.cs
176176
177177
178178
179
179
180180
181181
182182
......
184184
185185
186186
187
187
188188
189
190
191
189
190
191
192
192193
193194
194195
......
198199
199200
200201
201
202
202203
203
204
205
204
205
206
207
206208
207209
208210
......
211213
212214
213215
214
216
215217
216
217
218
219
220
218221
219222
220223
int levelCount
);
void AddDisposeTexture(IGLTexture texture);
void SetTextureData2D<T>(
void SetTextureData2D(
IGLTexture texture,
SurfaceFormat format,
int x,
int w,
int h,
int level,
T[] data,
IntPtr data,
int startIndex,
int elementCount
) where T : struct;
void SetTextureData3D<T>(
int elementCount,
int elementSizeInBytes
);
void SetTextureData3D(
IGLTexture texture,
SurfaceFormat format,
int level,
int bottom,
int front,
int back,
T[] data,
IntPtr data,
int startIndex,
int elementCount
) where T : struct;
void SetTextureDataCube<T>(
int elementCount,
int elementSizeInBytes
);
void SetTextureDataCube(
IGLTexture texture,
SurfaceFormat format,
int xOffset,
int height,
CubeMapFace cubeMapFace,
int level,
T[] data,
IntPtr data,
int startIndex,
int elementCount
) where T : struct;
int elementCount,
int elementSizeInBytes
);
void SetTextureData2DPointer(Texture2D texture, IntPtr ptr);
void GetTextureData2D<T>(
IGLTexture texture,
src/Graphics/OpenGLDevice.cs
25862586
25872587
25882588
2589
2589
25902590
25912591
25922592
......
25942594
25952595
25962596
2597
2597
25982598
2599
2600
2599
2600
2601
26012602
26022603
26032604
26042605
26052606
2606
2607
2608
2609
2610
26112607
2612
2608
26132609
2614
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
26152633
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2634
2635
2636
26422637
26432638
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
26552639
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
26672651
2668
2669
2670
2671
2672
2673
2674
2675
2652
2653
2654
2655
2656
2657
2658
26762659
26772660
2678
2679
2680
2681
26822661
26832662
26842663
26852664
26862665
26872666
2688
2667
26892668
26902669
26912670
......
26952674
26962675
26972676
2698
2677
26992678
2700
2701
2679
2680
2681
27022682
27032683
27042684
27052685
27062686
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
27282700
27292701
27302702
27312703
27322704
27332705
2734
2706
27352707
27362708
27372709
......
27402712
27412713
27422714
2743
2715
27442716
2745
2746
2717
2718
2719
27472720
27482721
27492722
27502723
27512724
2752
2753
2754
2755
2756
27572725
2758
2726
27592727
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
28042745
2805
2746
28062747
2807
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
28082759
28092760
28102761
#region glTexSubImage Methods
public void SetTextureData2D<T>(
public void SetTextureData2D(
IGLTexture texture,
SurfaceFormat format,
int x,
int w,
int h,
int level,
T[] data,
IntPtr data,
int startIndex,
int elementCount
) where T : struct {
int elementCount,
int elementSizeInBytes
) {
#if !DISABLE_THREADING
ForceToMainThread(() => {
#endif
BindTexture(texture);
GCHandle dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned);
int elementSizeInBytes = Marshal.SizeOf(typeof(T));
int startByte = startIndex * elementSizeInBytes;
IntPtr dataPtr = (IntPtr) (dataHandle.AddrOfPinnedObject().ToInt64() + startByte);
GLenum glFormat = XNAToGL.TextureFormat[(int) format];
try
if (glFormat == GLenum.GL_COMPRESSED_TEXTURE_FORMATS)
{
if (glFormat == GLenum.GL_COMPRESSED_TEXTURE_FORMATS)
/* Note that we're using glInternalFormat, not glFormat.
* In this case, they should actually be the same thing,
* but we use glFormat somewhat differently for
* compressed textures.
* -flibit
*/
glCompressedTexSubImage2D(
GLenum.GL_TEXTURE_2D,
level,
x,
y,
w,
h,
XNAToGL.TextureInternalFormat[(int) format],
elementCount * elementSizeInBytes,
data + (startIndex * elementSizeInBytes)
);
}
else
{
// Set pixel alignment to match texel size in bytes
int packSize = Texture.GetFormatSize(format);
if (packSize != 4)
{
int dataLength;
if (elementCount > 0)
{
dataLength = elementCount * elementSizeInBytes;
}
else
{
dataLength = data.Length - startByte;
}
/* Note that we're using glInternalFormat, not glFormat.
* In this case, they should actually be the same thing,
* but we use glFormat somewhat differently for
* compressed textures.
* -flibit
*/
glCompressedTexSubImage2D(
GLenum.GL_TEXTURE_2D,
level,
x,
y,
w,
h,
XNAToGL.TextureInternalFormat[(int) format],
dataLength,
dataPtr
glPixelStorei(
GLenum.GL_UNPACK_ALIGNMENT,
packSize
);
}
else
{
// Set pixel alignment to match texel size in bytes
int packSize = Texture.GetFormatSize(format);
if (packSize != 4)
{
glPixelStorei(
GLenum.GL_UNPACK_ALIGNMENT,
packSize
);
}
glTexSubImage2D(
GLenum.GL_TEXTURE_2D,
level,
x,
y,
w,
h,
glFormat,
XNAToGL.TextureDataType[(int) format],
dataPtr
);
glTexSubImage2D(
GLenum.GL_TEXTURE_2D,
level,
x,
y,
w,
h,
glFormat,
XNAToGL.TextureDataType[(int) format],
data + (startIndex * elementSizeInBytes)
);
// Keep this state sane -flibit
if (packSize != 4)
{
glPixelStorei(
GLenum.GL_UNPACK_ALIGNMENT,
4
);
}
// Keep this state sane -flibit
if (packSize != 4)
{
glPixelStorei(
GLenum.GL_UNPACK_ALIGNMENT,
4
);
}
}
finally
{
dataHandle.Free();
}
#if !DISABLE_THREADING
});
#endif
}
public void SetTextureData3D<T>(
public void SetTextureData3D(
IGLTexture texture,
SurfaceFormat format,
int level,
int bottom,
int front,
int back,
T[] data,
IntPtr data,
int startIndex,
int elementCount
) where T : struct {
int elementCount,
int elementSizeInBytes
) {
#if !DISABLE_THREADING
ForceToMainThread(() => {
#endif
BindTexture(texture);
GCHandle dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned);
try
{
glTexSubImage3D(
GLenum.GL_TEXTURE_3D,
level,
left,
top,
front,
right - left,
bottom - top,
back - front,
XNAToGL.TextureFormat[(int) format],
XNAToGL.TextureDataType[(int) format],
(IntPtr) (dataHandle.AddrOfPinnedObject().ToInt64() + startIndex * Marshal.SizeOf(typeof(T)))
);
}
finally
{
dataHandle.Free();
}
glTexSubImage3D(
GLenum.GL_TEXTURE_3D,
level,
left,
top,
front,
right - left,
bottom - top,
back - front,
XNAToGL.TextureFormat[(int) format],
XNAToGL.TextureDataType[(int) format],
data + (startIndex * elementSizeInBytes)
);
#if !DISABLE_THREADING
});
#endif
}
public void SetTextureDataCube<T>(
public void SetTextureDataCube(
IGLTexture texture,
SurfaceFormat format,
int xOffset,
int height,
CubeMapFace cubeMapFace,
int level,
T[] data,
IntPtr data,
int startIndex,
int elementCount
) where T : struct {
int elementCount,
int elementSizeInBytes
) {
#if !DISABLE_THREADING
ForceToMainThread(() => {
#endif
BindTexture(texture);
GCHandle dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned);
int elementSizeInBytes = Marshal.SizeOf(typeof(T));
int startByte = startIndex * elementSizeInBytes;
IntPtr dataPtr = (IntPtr) (dataHandle.AddrOfPinnedObject().ToInt64() + startByte);
GLenum glFormat = XNAToGL.TextureFormat[(int) format];
try
if (glFormat == GLenum.GL_COMPRESSED_TEXTURE_FORMATS)
{
if (glFormat == GLenum.GL_COMPRESSED_TEXTURE_FORMATS)
{
int dataLength;
if (elementCount > 0)
{
dataLength = elementCount * elementSizeInBytes;
}
else
{
dataLength = data.Length - startByte;
}
/* Note that we're using glInternalFormat, not glFormat.
* In this case, they should actually be the same thing,
* but we use glFormat somewhat differently for
* compressed textures.
* -flibit
*/
glCompressedTexSubImage2D(
GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
level,
xOffset,
yOffset,
width,
height,
XNAToGL.TextureInternalFormat[(int) format],
dataLength,
dataPtr
);
}
else
{
glTexSubImage2D(
GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
level,
xOffset,
yOffset,
width,
height,
glFormat,
XNAToGL.TextureDataType[(int) format],
dataPtr
);
}
/* Note that we're using glInternalFormat, not glFormat.
* In this case, they should actually be the same thing,
* but we use glFormat somewhat differently for
* compressed textures.
* -flibit
*/
glCompressedTexSubImage2D(
GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
level,
xOffset,
yOffset,
width,
height,
XNAToGL.TextureInternalFormat[(int) format],
elementCount * elementSizeInBytes,
data + (startIndex * elementSizeInBytes)
);
}
finally
else
{
dataHandle.Free();
glTexSubImage2D(
GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
level,
xOffset,
yOffset,
width,
height,
glFormat,
XNAToGL.TextureDataType[(int) format],
data + (startIndex * elementSizeInBytes)
);
}
#if !DISABLE_THREADING
src/Graphics/Texture2D.cs
1010
1111
1212
13
1314
1415
1516
......
138139
139140
140141
142
141143
142144
143145
......
146148
147149
148150
149
151
150152
151
153
154
152155
156
153157
154158
155159
#region Using Statements
using System;
using System.IO;
using System.Runtime.InteropServices;
#endregion
namespace Microsoft.Xna.Framework.Graphics
h = Math.Max(Height >> level, 1);
}
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
GraphicsDevice.GLDevice.SetTextureData2D(
texture,
Format,
w,
h,
level,
data,
handle.AddrOfPinnedObject(),
startIndex,
elementCount
elementCount,
Marshal.SizeOf(typeof(T))
);
handle.Free();
}
#endregion
src/Graphics/Texture3D.cs
99
1010
1111
12
1213
1314
1415
......
117118
118119
119120
121
120122
121123
122124
......
127129
128130
129131
130
132
131133
132
134
135
133136
134137
135138
#region Using Statements
using System;
using System.Runtime.InteropServices;
#endregion
namespace Microsoft.Xna.Framework.Graphics
throw new ArgumentNullException("data");
}
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
GraphicsDevice.GLDevice.SetTextureData3D(
texture,
Format,
bottom,
front,
back,
data,
handle.AddrOfPinnedObject(),
startIndex,
elementCount
elementCount,
Marshal.SizeOf(typeof(T))
);
}
src/Graphics/TextureCube.cs
99
1010
1111
12
1213
1314
1415
......
117118
118119
119120
121
120122
121123
122124
......
126128
127129
128130
129
131
130132
131
133
134
132135
136
133137
134138
135139
#region Using Statements
using System;
using System.Runtime.InteropServices;
#endregion
namespace Microsoft.Xna.Framework.Graphics
height = Math.Max(1, Size >> level);
}
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
GraphicsDevice.GLDevice.SetTextureDataCube(
texture,
Format,
height,
cubeMapFace,
level,
data,
handle.AddrOfPinnedObject(),
startIndex,
elementCount
elementCount,
Marshal.SizeOf(typeof(T))
);
handle.Free();
}
#endregion

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.09504s using 13 queries.