Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- var dynMethod = new DynamicMethod(
- string.Empty,
- Texture2DType,
- new Type[] { typeof(GraphicsDevice), typeof(int), typeof(int), typeof(SurfaceFormat), typeof(Enum) },
- Texture2DType
- );
- var ilGen = dynMethod.GetILGenerator();
- ilGen.Emit(OpCodes.Ldarg_0); // graphicsDevice
- ilGen.Emit(OpCodes.Ldarg_1); // width
- ilGen.Emit(OpCodes.Ldarg_2); // height
- ilGen.Emit(OpCodes.Ldc_I4_0); // mipmap
- ilGen.Emit(OpCodes.Ldarg_3); // format
- ilGen.Emit(OpCodes.Ldarg_S, 4); // type
- ilGen.Emit(OpCodes.Ldc_I4_0); // shared
- ilGen.Emit(OpCodes.Ldc_I4_0); // arraySize
- ilGen.Emit(OpCodes.Newobj, Texture2DConstructor);
- ilGen.Emit(OpCodes.Ret);
- CreateInstance = dynMethod.CreateDelegate<Func<GraphicsDevice, int, int, SurfaceFormat, Enum, Texture2D>>();
- }
- catch (Exception ex) {
- throw;
- }
- ...
- try {
- var p0 = System.Linq.Expressions.Expression.Parameter(typeof(GraphicsDevice));
- var p1 = System.Linq.Expressions.Expression.Parameter(typeof(int));
- var p2 = System.Linq.Expressions.Expression.Parameter(typeof(int));
- var p3 = System.Linq.Expressions.Expression.Parameter(typeof(SurfaceFormat));
- var p4 = System.Linq.Expressions.Expression.Parameter(typeof(Enum));
- CreateInstance = System.Linq.Expressions.Expression.Lambda<Func<GraphicsDevice, int, int, SurfaceFormat, Enum, Texture2D>>(
- System.Linq.Expressions.Expression.New(
- Texture2DConstructor,
- p0, // graphicsDevice
- p1, // width
- p2, // height
- System.Linq.Expressions.Expression.Constant(false), // mipmap
- p3, // format
- System.Linq.Expressions.Expression.Convert(p4, SurfaceTypeType), // type
- System.Linq.Expressions.Expression.Constant(false), // shared
- System.Linq.Expressions.Expression.Constant(0) // arraySize
- ),
- p0, p1, p2, p3, p4
- ).Compile();
- }
- catch (Exception ex) {
- throw;
- }
- ...
- var newObj = CreateInstance(DrawState.Device, size.Width, size.Height, SurfaceFormat.Dxt5, SwapChainRenderTarget);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement