mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 01:35:32 +00:00
[ES] Fixed loading of OpenGL ES core API
eglGetProcAddress cannot be used to retrieve entry points of core functions. Instead, we use [DllImport] for core functions and function pointers for extension functions. Squashed commit of the following: commit 0b84aa6ef78dfa3600b81fc412eb192f2a87e40c Author: thefiddler <stapostol@gmail.com> Date: Sat Mar 15 02:24:58 2014 +0100 [Examples] Rolled back changes to Example browser commit 1acfbaac3d17184debdbbe872c58ac07d1b37c0a Author: thefiddler <stapostol@gmail.com> Date: Sat Mar 15 02:20:57 2014 +0100 [Examples] Rolled back WinForms example commit 835d9d6035a890bd3426566929fbfd25c493eca0 Author: thefiddler <stapostol@gmail.com> Date: Sat Mar 15 01:15:01 2014 +0100 [Examples] Rolled back erroneous GLControl mods commit 056418014f0e835e83fb85b54b8749519a555364 Author: thefiddler <stapostol@gmail.com> Date: Fri Mar 14 23:11:11 2014 +0100 [Rewrite] Remove calli prototypes When a function is called indirectly via a function pointer, its prototype is not required (the prototype is added as a callsite at the calli invocation.) Removing these prototypes reduces binary size by roughly 400KB. commit 353a16ec2836c597150d2fab28581e7c264b2b39 Author: thefiddler <stapostol@gmail.com> Date: Fri Mar 14 22:31:25 2014 +0100 [Rewrite] Call DllImports directly When a function does not have an allocated slot (i.e. slot = -1), then we will call its DllImport signature directly. commit 9a5313e4b7afb10b698d255e4b5637887bf71cf3 Author: thefiddler <stapostol@gmail.com> Date: Fri Mar 14 22:30:04 2014 +0100 [Bind] Do not allocate slots for DllImports commit 6ac5342409363cac0e59f9dc669948b319bd20a9 Author: thefiddler <stapostol@gmail.com> Date: Fri Mar 14 22:29:07 2014 +0100 [Bind] Added option to use DllImports This is necessary for the core functionality of OpenGL ES, where eglGetProcAddress returns null or garbage (the latter on Android.)
This commit is contained in:
parent
242b8bbe6c
commit
02bf55ad7e
|
@ -173,7 +173,12 @@ namespace Bind
|
|||
sw.WriteLine("{");
|
||||
sw.Indent();
|
||||
foreach (var d in delegates.Values.Select(d => d.First()))
|
||||
sw.WriteLine("\"{0}{1}\",", Settings.FunctionPrefix, d.Name);
|
||||
{
|
||||
if (!Settings.IsEnabled(Settings.Legacy.UseDllImports) || d.Extension != "Core")
|
||||
{
|
||||
sw.WriteLine("\"{0}{1}\",", Settings.FunctionPrefix, d.Name);
|
||||
}
|
||||
}
|
||||
sw.Unindent();
|
||||
sw.WriteLine("};");
|
||||
sw.WriteLine("EntryPoints = new IntPtr[EntryPointNames.Length];");
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace Bind.ES
|
|||
// overloads using the "All" enum in addition to strongly-typed enums.
|
||||
// This can be disabled by passing "-o:-keep_untyped_enums" as a cmdline parameter.
|
||||
Settings.DefaultCompatibility |= Settings.Legacy.KeepUntypedEnums;
|
||||
Settings.DefaultCompatibility |= Settings.Legacy.UseDllImports;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,15 +136,26 @@ namespace Bind
|
|||
|
||||
#region Private Members
|
||||
|
||||
static void GenerateAddressTable(DelegateCollection delegates)
|
||||
void GenerateAddressTable(DelegateCollection delegates)
|
||||
{
|
||||
int slot = -1;
|
||||
foreach (var list in delegates.Values)
|
||||
{
|
||||
slot++;
|
||||
foreach (var d in list)
|
||||
if (!Settings.IsEnabled(Settings.Legacy.UseDllImports) || list.First().Extension != "Core")
|
||||
{
|
||||
d.Slot = slot;
|
||||
slot++;
|
||||
foreach (var d in list)
|
||||
{
|
||||
d.Slot = slot;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Core function routed through DllImport - no slot generated
|
||||
foreach (var d in list)
|
||||
{
|
||||
d.Slot = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,6 +154,8 @@ namespace Bind
|
|||
KeepUntypedEnums = 0x1000,
|
||||
/// <summary>Marks deprecated functions as [Obsolete]</summary>
|
||||
AddDeprecationWarnings = 0x2000,
|
||||
/// <summary>Use DllImport declaration for core functions (do not generate entry point slots)</summary>
|
||||
UseDllImports = 0x4000,
|
||||
Tao = ConstIntEnums |
|
||||
NoAdvancedEnumProcessing |
|
||||
NoPublicUnsafeFunctions |
|
||||
|
@ -164,9 +166,9 @@ namespace Bind
|
|||
NestedEnums |
|
||||
NoBoolParameters |
|
||||
NoDropMultipleTokens |
|
||||
NoDocumentation |
|
||||
NoDebugHelpers
|
||||
/*GenerateAllPermutations,*/
|
||||
NoDocumentation |
|
||||
NoDebugHelpers,
|
||||
/*GenerateAllPermutations,*/
|
||||
}
|
||||
|
||||
// Returns true if flag is enabled.
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.Text;
|
|||
using System.Windows.Forms;
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace Examples.WinForms
|
||||
|
|
|
@ -37,9 +37,10 @@
|
|||
// redButton
|
||||
//
|
||||
this.redButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.redButton.Location = new System.Drawing.Point(639, 13);
|
||||
this.redButton.Location = new System.Drawing.Point(1278, 25);
|
||||
this.redButton.Margin = new System.Windows.Forms.Padding(6);
|
||||
this.redButton.Name = "redButton";
|
||||
this.redButton.Size = new System.Drawing.Size(133, 23);
|
||||
this.redButton.Size = new System.Drawing.Size(266, 44);
|
||||
this.redButton.TabIndex = 1;
|
||||
this.redButton.Text = "Red";
|
||||
this.redButton.UseVisualStyleBackColor = true;
|
||||
|
@ -48,9 +49,10 @@
|
|||
// greenButton
|
||||
//
|
||||
this.greenButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.greenButton.Location = new System.Drawing.Point(639, 43);
|
||||
this.greenButton.Location = new System.Drawing.Point(1278, 83);
|
||||
this.greenButton.Margin = new System.Windows.Forms.Padding(6);
|
||||
this.greenButton.Name = "greenButton";
|
||||
this.greenButton.Size = new System.Drawing.Size(133, 23);
|
||||
this.greenButton.Size = new System.Drawing.Size(266, 44);
|
||||
this.greenButton.TabIndex = 2;
|
||||
this.greenButton.Text = "Green";
|
||||
this.greenButton.UseVisualStyleBackColor = true;
|
||||
|
@ -59,9 +61,10 @@
|
|||
// blueButton
|
||||
//
|
||||
this.blueButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.blueButton.Location = new System.Drawing.Point(639, 73);
|
||||
this.blueButton.Location = new System.Drawing.Point(1278, 140);
|
||||
this.blueButton.Margin = new System.Windows.Forms.Padding(6);
|
||||
this.blueButton.Name = "blueButton";
|
||||
this.blueButton.Size = new System.Drawing.Size(133, 23);
|
||||
this.blueButton.Size = new System.Drawing.Size(266, 44);
|
||||
this.blueButton.TabIndex = 3;
|
||||
this.blueButton.Text = "Blue";
|
||||
this.blueButton.UseVisualStyleBackColor = true;
|
||||
|
@ -69,27 +72,29 @@
|
|||
//
|
||||
// glControl1
|
||||
//
|
||||
this.glControl1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.glControl1.BackColor = System.Drawing.SystemColors.ControlDarkDark;
|
||||
this.glControl1.BackColor = System.Drawing.SystemColors.ControlDark;
|
||||
this.glControl1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.glControl1.Location = new System.Drawing.Point(0, 0);
|
||||
this.glControl1.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
|
||||
this.glControl1.Name = "glControl1";
|
||||
this.glControl1.Size = new System.Drawing.Size(629, 565);
|
||||
this.glControl1.TabIndex = 0;
|
||||
this.glControl1.Size = new System.Drawing.Size(1562, 1085);
|
||||
this.glControl1.TabIndex = 4;
|
||||
this.glControl1.VSync = false;
|
||||
this.glControl1.Resize += new System.EventHandler(this.glControl1_Resize);
|
||||
this.glControl1.Paint += new System.Windows.Forms.PaintEventHandler(this.glControl1_Paint);
|
||||
this.glControl1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.glControl1_KeyDown);
|
||||
this.glControl1.Resize += new System.EventHandler(this.glControl1_Resize);
|
||||
//
|
||||
// W01_First_Window
|
||||
// SimpleForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(781, 564);
|
||||
this.ClientSize = new System.Drawing.Size(1562, 1085);
|
||||
this.Controls.Add(this.blueButton);
|
||||
this.Controls.Add(this.greenButton);
|
||||
this.Controls.Add(this.redButton);
|
||||
this.Controls.Add(this.glControl1);
|
||||
this.Name = "W01_First_Window";
|
||||
this.Margin = new System.Windows.Forms.Padding(6);
|
||||
this.Name = "SimpleForm";
|
||||
this.Text = "OpenTK Windows Forms Tutorial 01 - Your first window";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
|
@ -97,9 +102,9 @@
|
|||
|
||||
#endregion
|
||||
|
||||
private OpenTK.GLControl glControl1;
|
||||
private System.Windows.Forms.Button redButton;
|
||||
private System.Windows.Forms.Button greenButton;
|
||||
private System.Windows.Forms.Button blueButton;
|
||||
private OpenTK.GLControl glControl1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,6 +164,18 @@ namespace OpenTK.Rewrite
|
|||
}
|
||||
}
|
||||
|
||||
int GetSlot(MethodDefinition signature)
|
||||
{
|
||||
var slot_attribute = signature.CustomAttributes
|
||||
.FirstOrDefault(a => a.AttributeType.Name == "SlotAttribute");
|
||||
int slot =
|
||||
slot_attribute != null ?
|
||||
(int)slot_attribute.ConstructorArguments[0].Value :
|
||||
-1;
|
||||
|
||||
return slot;
|
||||
}
|
||||
|
||||
void Rewrite(TypeDefinition type, FieldDefinition entry_points,
|
||||
List<MethodDefinition> entry_signatures, IEnumerable<string> options)
|
||||
{
|
||||
|
@ -180,10 +192,8 @@ namespace OpenTK.Rewrite
|
|||
{
|
||||
var signature_name = (string)autogenerated.First()
|
||||
.Fields.First(f => f.Name == "EntryPoint").Argument.Value;
|
||||
var signature = entry_signatures.First(s => s.Name == signature_name);
|
||||
var slot = (int)signature.CustomAttributes
|
||||
.First(a => a.AttributeType.Name == "SlotAttribute")
|
||||
.ConstructorArguments[0].Value;
|
||||
var signature = entry_signatures.FirstOrDefault(s => s.Name == signature_name);
|
||||
int slot = GetSlot(signature);
|
||||
|
||||
ProcessMethod(wrapper, signature, slot, entry_points, options);
|
||||
}
|
||||
|
@ -202,10 +212,12 @@ namespace OpenTK.Rewrite
|
|||
|
||||
void RemoveNativeSignatures(TypeDefinition type, List<MethodDefinition> methods)
|
||||
{
|
||||
while (methods.Count > 0)
|
||||
// Remove all DllImports for functions called through calli, since
|
||||
// their signatures are embedded directly into the calli callsite.
|
||||
// This reduces dll size by ~400KB.
|
||||
foreach (var m in methods.Where(s => GetSlot(s) != -1))
|
||||
{
|
||||
type.Methods.Remove(methods.Last());
|
||||
methods.RemoveAt(methods.Count - 1);
|
||||
type.Methods.Remove(m);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,11 +266,19 @@ namespace OpenTK.Rewrite
|
|||
EmitConvenienceWrapper(wrapper, native, difference, body, il);
|
||||
}
|
||||
|
||||
// push the entry point address on the stack
|
||||
EmitEntryPoint(entry_points, il, slot);
|
||||
if (slot != -1)
|
||||
{
|
||||
// push the entry point address on the stack
|
||||
EmitEntryPoint(entry_points, il, slot);
|
||||
|
||||
// issue calli
|
||||
EmitCall(il, native);
|
||||
// issue calli
|
||||
EmitCalli(il, native);
|
||||
}
|
||||
else
|
||||
{
|
||||
// issue DllImport call
|
||||
EmitCall(il, native);
|
||||
}
|
||||
|
||||
if (wrapper.ReturnType.Name != "Void")
|
||||
{
|
||||
|
@ -777,7 +797,7 @@ namespace OpenTK.Rewrite
|
|||
il.Emit(OpCodes.Ldelem_I);
|
||||
}
|
||||
|
||||
static void EmitCall(ILProcessor il, MethodReference reference)
|
||||
static void EmitCalli(ILProcessor il, MethodReference reference)
|
||||
{
|
||||
var signature = new CallSite(reference.ReturnType)
|
||||
{
|
||||
|
@ -793,5 +813,10 @@ namespace OpenTK.Rewrite
|
|||
// we do not need any special preparation before emiting calli.
|
||||
il.Emit(OpCodes.Calli, signature);
|
||||
}
|
||||
|
||||
static void EmitCall(ILProcessor il, MethodReference reference)
|
||||
{
|
||||
il.Emit(OpCodes.Call, reference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue