fna-workbench

fna-workbench Commit Details


Date:2016-03-18 14:34:08 (8 years 9 months ago)
Author:Ethan Lee
Branch:master
Commit:0660f996e0512056252a3cf93c9257b877d7c742
Parents: 4e6d2f38ce432e130c7eff1de6ae898660d32930
Message:Pull GCHandles out of GetTextureDatas

Changes:

File differences

src/Graphics/IGLDevice.cs
219219
220220
221221
222
222
223223
224224
225225
226226
227227
228228
229
229
230230
231
232
233
234
231
232
233
234
235
235236
236237
237238
238239
239240
240241
241
242
242243
243
244
244
245
246
245247
246248
247249
int elementSizeInBytes
);
void SetTextureData2DPointer(Texture2D texture, IntPtr ptr);
void GetTextureData2D<T>(
void GetTextureData2D(
IGLTexture texture,
SurfaceFormat format,
int width,
int height,
int level,
Rectangle? rect,
T[] data,
IntPtr data,
int startIndex,
int elementCount
) where T : struct;
// void GetTextureData3D<T>();
void GetTextureDataCube<T>(
int elementCount,
int elementSizeInBytes
);
// void GetTextureData3D();
void GetTextureDataCube(
IGLTexture texture,
SurfaceFormat format,
int size,
CubeMapFace cubeMapFace,
int level,
Rectangle? rect,
T[] data,
IntPtr data,
int startIndex,
int elementCount
) where T : struct;
int elementCount,
int elementSizeInBytes
);
IGLRenderbuffer GenRenderbuffer(
int width,
src/Graphics/OpenGLDevice.cs
27992799
28002800
28012801
2802
2802
28032803
28042804
28052805
28062806
28072807
28082808
2809
2809
28102810
2811
2812
2811
2812
2813
28132814
28142815
28152816
......
28342835
28352836
28362837
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2838
2839
2840
2841
2842
2843
2844
28522845
28532846
28542847
28552848
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2849
2850
2851
2852
2853
2854
2855
2856
28722857
28732858
28742859
......
28882873
28892874
28902875
2891
2876
2877
2878
2879
2880
2881
28922882
28932883
2884
28942885
28952886
28962887
......
28982889
28992890
29002891
2901
2892
29022893
29032894
29042895
29052896
29062897
29072898
2908
2899
29092900
2910
2911
2901
2902
2903
29122904
29132905
29142906
......
29222914
29232915
29242916
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2917
2918
2919
2920
2921
2922
2923
29402924
29412925
29422926
29432927
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2928
2929
2930
2931
2932
2933
2934
2935
29602936
29612937
29622938
......
29762952
29772953
29782954
2979
2955
2956
2957
2958
2959
2960
29802961
29812962
2963
29822964
29832965
29842966
......
31193101
31203102
31213103
3122
3104
31233105
31243106
31253107
31263108
3127
3109
31283110
3129
3111
31303112
31313113
31323114
......
31743156
31753157
31763158
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3159
3160
3161
3162
3163
3164
3165
3166
3167
31943168
31953169
31963170
#region glGetTexImage Methods
public void GetTextureData2D<T>(
public void GetTextureData2D(
IGLTexture texture,
SurfaceFormat format,
int width,
int height,
int level,
Rectangle? rect,
T[] data,
IntPtr data,
int startIndex,
int elementCount
) where T : struct {
int elementCount,
int elementSizeInBytes
) {
#if !DISABLE_THREADING
ForceToMainThread(() => {
#endif
else if (rect == null)
{
// Just throw the whole texture into the user array.
GCHandle ptr = GCHandle.Alloc(data, GCHandleType.Pinned);
try
{
glGetTexImage(
GLenum.GL_TEXTURE_2D,
0,
glFormat,
XNAToGL.TextureDataType[(int) format],
ptr.AddrOfPinnedObject()
);
}
finally
{
ptr.Free();
}
glGetTexImage(
GLenum.GL_TEXTURE_2D,
0,
glFormat,
XNAToGL.TextureDataType[(int) format],
data
);
}
else
{
// Get the whole texture...
T[] texData = new T[width * height];
GCHandle ptr = GCHandle.Alloc(texData, GCHandleType.Pinned);
try
{
glGetTexImage(
GLenum.GL_TEXTURE_2D,
0,
glFormat,
XNAToGL.TextureDataType[(int) format],
ptr.AddrOfPinnedObject()
);
}
finally
{
ptr.Free();
}
IntPtr texData = Marshal.AllocHGlobal(width * height * elementSizeInBytes);
glGetTexImage(
GLenum.GL_TEXTURE_2D,
0,
glFormat,
XNAToGL.TextureDataType[(int) format],
texData
);
// Now, blit the rect region into the user array.
Rectangle region = rect.Value;
// If we're past the end, we're done!
return;
}
data[curPixel - startIndex] = texData[(row * width) + col];
// FIXME: Can we copy via pitch instead, or something? -flibit
memcpy(
data + ((curPixel - startIndex) * elementSizeInBytes),
texData + (((row * width) + col) * elementSizeInBytes),
(IntPtr) elementSizeInBytes
);
}
}
Marshal.FreeHGlobal(texData);
}
#if !DISABLE_THREADING
#endif
}
public void GetTextureDataCube<T>(
public void GetTextureDataCube(
IGLTexture texture,
SurfaceFormat format,
int size,
CubeMapFace cubeMapFace,
int level,
Rectangle? rect,
T[] data,
IntPtr data,
int startIndex,
int elementCount
) where T : struct {
int elementCount,
int elementSizeInBytes
) {
#if !DISABLE_THREADING
ForceToMainThread(() => {
#endif
else if (rect == null)
{
// Just throw the whole texture into the user array.
GCHandle ptr = GCHandle.Alloc(data, GCHandleType.Pinned);
try
{
glGetTexImage(
GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
0,
glFormat,
XNAToGL.TextureDataType[(int) format],
ptr.AddrOfPinnedObject()
);
}
finally
{
ptr.Free();
}
glGetTexImage(
GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
0,
glFormat,
XNAToGL.TextureDataType[(int) format],
data
);
}
else
{
// Get the whole texture...
T[] texData = new T[size * size];
GCHandle ptr = GCHandle.Alloc(texData, GCHandleType.Pinned);
try
{
glGetTexImage(
GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
0,
glFormat,
XNAToGL.TextureDataType[(int) format],
ptr.AddrOfPinnedObject()
);
}
finally
{
ptr.Free();
}
IntPtr texData = Marshal.AllocHGlobal(size * size * elementSizeInBytes);
glGetTexImage(
GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
0,
glFormat,
XNAToGL.TextureDataType[(int) format],
texData
);
// Now, blit the rect region into the user array.
Rectangle region = rect.Value;
// If we're past the end, we're done!
return;
}
data[curPixel - startIndex] = texData[(row * size) + col];
// FIXME: Can we copy via pitch instead, or something? -flibit
memcpy(
data + ((curPixel - startIndex) * elementSizeInBytes),
texData + (((row * size) + col) * elementSizeInBytes),
(IntPtr) elementSizeInBytes
);
}
}
Marshal.FreeHGlobal(texData);
}
#if !DISABLE_THREADING
/// <param name="data">The texture data array</param>
/// <param name="rect">The portion of the image to read from</param>
/// <returns>True if we successfully read the texture data</returns>
private bool ReadTargetIfApplicable<T>(
private bool ReadTargetIfApplicable(
IGLTexture texture,
int width,
int height,
int level,
T[] data,
IntPtr data,
Rectangle? rect
) where T : struct {
) {
bool texUnbound = (currentDrawBuffers != 1 ||
currentAttachments[0] != (texture as OpenGLTexture).Handle);
if (texUnbound && !useES2)
/* glReadPixels should be faster than reading
* back from the render target if we are already bound.
*/
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
try
{
glReadPixels(
x,
y,
w,
h,
GLenum.GL_RGBA, // FIXME: Assumption!
GLenum.GL_UNSIGNED_BYTE,
handle.AddrOfPinnedObject()
);
}
finally
{
handle.Free();
}
glReadPixels(
x,
y,
w,
h,
GLenum.GL_RGBA, // FIXME: Assumption!
GLenum.GL_UNSIGNED_BYTE,
data
);
if (texUnbound)
{
src/Graphics/Texture2D.cs
204204
205205
206206
207
207208
208209
209210
......
211212
212213
213214
214
215
215216
216
217
218
217219
220
218221
219222
220223
);
}
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
GraphicsDevice.GLDevice.GetTextureData2D(
texture,
Format,
Height,
level,
rect,
data,
handle.AddrOfPinnedObject(),
startIndex,
elementCount
elementCount,
Marshal.SizeOf(typeof(T))
);
handle.Free();
}
#endregion
src/Graphics/TextureCube.cs
190190
191191
192192
193
193194
194195
195196
......
197198
198199
199200
200
201
201202
202
203
204
203205
206
204207
205208
206209
);
}
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
GraphicsDevice.GLDevice.GetTextureDataCube(
texture,
Format,
cubeMapFace,
level,
rect,
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.08770s using 13 queries.