Merge pull request #588 from Frassle/issue517

Change StringBuilder parameters to out Strings
This commit is contained in:
Jarl Gullberg 2017-07-28 11:22:05 +02:00 committed by GitHub
commit 876b234872
22 changed files with 22548 additions and 22370 deletions

View file

@ -695,13 +695,45 @@ namespace Bind
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
List<string> attributes = new List<string>();
if (p.Flow == FlowDirection.Out) if (p.Flow == FlowDirection.Out)
{ {
sb.Append("[OutAttribute] "); attributes.Add("OutAttribute");
} }
else if (p.Flow == FlowDirection.Undefined) else if (p.Flow == FlowDirection.Undefined)
{ {
sb.Append("[InAttribute, OutAttribute] "); attributes.Add("InAttribute");
attributes.Add("OutAttribute");
}
if (!String.IsNullOrEmpty(p.ComputeSize))
{
int count;
if(Int32.TryParse(p.ComputeSize, out count))
{
attributes.Add(String.Format("CountAttribute(Count = {0})", count));
}
else
{
if(p.ComputeSize.StartsWith("COMPSIZE"))
{
//remove the compsize hint, just keep comma delimited param names
var len = "COMPSIZE(".Length;
var computed = p.ComputeSize.Substring(len, (p.ComputeSize.Length - len) - 1);
attributes.Add(String.Format("CountAttribute(Computed = \"{0}\")", computed));
}
else
{
attributes.Add(String.Format("CountAttribute(Parameter = \"{0}\")", p.ComputeSize));
}
}
}
if(attributes.Count != 0)
{
sb.Append("[");
sb.Append(string.Join(", ", attributes));
sb.Append("] ");
} }
if (p.Reference) if (p.Reference)

View file

@ -358,7 +358,7 @@ namespace Bind
} }
else if (enum_override.Value == "StringBuilder") else if (enum_override.Value == "StringBuilder")
{ {
type.QualifiedType = "StringBuilder"; throw new NotSupportedException("StringBuilder enum overrides are no longer supported");
} }
else else
{ {
@ -1237,13 +1237,10 @@ namespace Bind
var p = wrapper.Parameters[i]; var p = wrapper.Parameters[i];
if ((p.WrapperType & WrapperTypes.StringParameter) != 0) if ((p.WrapperType & WrapperTypes.StringParameter) != 0)
{ {
p.QualifiedType = "String";
if (p.Flow == FlowDirection.Out) if (p.Flow == FlowDirection.Out)
{ {
p.QualifiedType = "StringBuilder"; p.Reference = true;
}
else
{
p.QualifiedType = "String";
} }
} }

View file

@ -14,7 +14,7 @@
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout> <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
<DefaultTargetSchema>IE50</DefaultTargetSchema> <DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign> <DelaySign>false</DelaySign>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<AppDesignerFolder> <AppDesignerFolder>
</AppDesignerFolder> </AppDesignerFolder>

View file

@ -319,13 +319,6 @@ namespace Bind
} }
p.ComputeSize = param.GetAttribute("count", String.Empty).Trim(); p.ComputeSize = param.GetAttribute("count", String.Empty).Trim();
if (p.ComputeSize.StartsWith("COMPSIZE"))
{
//remove the compsize hint, just keep comma delimited param names
var len = "COMPSIZE(".Length;
p.ComputeSize = p.ComputeSize.Substring(len, (p.ComputeSize.Length - len) - 1);
}
p.Flow = Parameter.GetFlowDirection(param.GetAttribute("flow", String.Empty).Trim()); p.Flow = Parameter.GetFlowDirection(param.GetAttribute("flow", String.Empty).Trim());
d.Parameters.Add(p); d.Parameters.Add(p);

View file

@ -0,0 +1,10 @@

namespace OpenTK.Rewrite
{
internal class CountAttribute
{
public int Count;
public string Parameter;
public string Computed;
}
}

View file

@ -53,6 +53,7 @@
<Reference Include="System.Core" /> <Reference Include="System.Core" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CountAttribute.cs" />
<Compile Include="GeneratedVariableIdentifier.cs" /> <Compile Include="GeneratedVariableIdentifier.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View file

@ -51,7 +51,6 @@ namespace OpenTK.Rewrite
private static AssemblyDefinition mscorlib; private static AssemblyDefinition mscorlib;
private static TypeDefinition TypeMarshal; private static TypeDefinition TypeMarshal;
private static TypeDefinition TypeStringBuilder;
private static TypeDefinition TypeVoid; private static TypeDefinition TypeVoid;
private static TypeDefinition TypeIntPtr; private static TypeDefinition TypeIntPtr;
private static TypeDefinition TypeInt32; private static TypeDefinition TypeInt32;
@ -123,7 +122,6 @@ namespace OpenTK.Rewrite
return; return;
} }
TypeMarshal = mscorlib.MainModule.GetType("System.Runtime.InteropServices.Marshal"); TypeMarshal = mscorlib.MainModule.GetType("System.Runtime.InteropServices.Marshal");
TypeStringBuilder = mscorlib.MainModule.GetType("System.Text.StringBuilder");
TypeVoid = mscorlib.MainModule.GetType("System.Void"); TypeVoid = mscorlib.MainModule.GetType("System.Void");
TypeIntPtr = mscorlib.MainModule.GetType("System.IntPtr"); TypeIntPtr = mscorlib.MainModule.GetType("System.IntPtr");
TypeInt32 = mscorlib.MainModule.GetType("System.Int32"); TypeInt32 = mscorlib.MainModule.GetType("System.Int32");
@ -256,6 +254,19 @@ namespace OpenTK.Rewrite
i--; i--;
} }
} }
foreach (var parameter in method.Parameters)
{
var pattr = parameter.CustomAttributes;
for (int i = 0; i < pattr.Count; i++)
{
if (pattr[i].AttributeType.Name == "CountAttribute")
{
pattr.RemoveAt(i);
i--;
}
}
}
} }
} }
@ -534,9 +545,9 @@ namespace OpenTK.Rewrite
{ {
foreach (var p in wrapper.Parameters) foreach (var p in wrapper.Parameters)
{ {
if (p.ParameterType.Name == "StringBuilder") if (!p.ParameterType.IsArray && p.ParameterType.Name == "String" && p.IsOut)
{ {
EmitStringBuilderEpilogue(wrapper, native, p, body, il, GetGeneratedVariable(generatedVariables, p.Name + "_sb_ptr", body)); EmitStringOutEpilogue(wrapper, native, p, body, il, GetGeneratedVariable(generatedVariables, p.Name + "_string_ptr", body));
} }
if (!p.ParameterType.IsArray && p.ParameterType.Name == "String") if (!p.ParameterType.IsArray && p.ParameterType.Name == "String")
@ -564,44 +575,73 @@ namespace OpenTK.Rewrite
body.Variables.Contains(v.Definition)); body.Variables.Contains(v.Definition));
} }
private static GeneratedVariableIdentifier EmitStringBuilderParameter(MethodDefinition method, ParameterDefinition parameter, MethodBody body, ILProcessor il) private static GeneratedVariableIdentifier EmitStringOutParameter(MethodDefinition method, ParameterDefinition parameter, MethodBody body, ILProcessor il)
{ {
var p = parameter.ParameterType; var p = parameter.ParameterType;
// void GetShaderInfoLog(..., StringBuilder foo) // void GetShaderInfoLog(..., out String foo)
// IntPtr foo_sb_ptr; // IntPtr foo_string_ptr;
// try { // try {
// foo_sb_ptr = Marshal.AllocHGlobal(sb.Capacity + 1); // foo_string_ptr = Marshal.AllocHGlobal(count + 1);
// glGetShaderInfoLog(..., foo_sb_ptr); // glGetShaderInfoLog(..., foo_string_ptr);
// MarshalPtrToStringBuilder(foo_sb_ptr, sb); // foo = MarshalPtrToString(foo_string_ptr);
// } // }
// finally { // finally {
// Marshal.FreeHGlobal(sb_ptr); // Marshal.FreeHGlobal(foo_string_ptr);
// } // }
// Make sure we have imported StringBuilder::Capacity and Marshal::AllocHGlobal // Make sure we have imported Marshal::AllocHGlobal
var sb_get_capacity = method.Module.ImportReference(TypeStringBuilder.Methods.First(m => m.Name == "get_Capacity"));
var alloc_hglobal = method.Module.ImportReference(TypeMarshal.Methods.First(m => m.Name == "AllocHGlobal")); var alloc_hglobal = method.Module.ImportReference(TypeMarshal.Methods.First(m => m.Name == "AllocHGlobal"));
// IntPtr ptr; // IntPtr ptr;
var variableDefinition = new VariableDefinition(TypeIntPtr); var variableDefinition = new VariableDefinition(TypeIntPtr);
body.Variables.Add(variableDefinition); body.Variables.Add(variableDefinition);
int stringBuilderPtrIndex = body.Variables.Count - 1; int stringPtrIndex = body.Variables.Count - 1;
GeneratedVariableIdentifier stringBuilderPtrVar = new GeneratedVariableIdentifier(body, variableDefinition, parameter.Name + "_sb_ptr"); GeneratedVariableIdentifier stringPtrVar = new GeneratedVariableIdentifier(body, variableDefinition, parameter.Name + "_string_ptr");
// ptr = Marshal.AllocHGlobal(sb.Capacity + 1); // ptr = Marshal.AllocHGlobal(count + 1);
il.Emit(OpCodes.Callvirt, sb_get_capacity); var count = GetCountAttribute(parameter);
if (count == null)
{
// We need a count attribute so we know what size to make the
// string buffer. Currently every string out parameter has a
// count attribute but this check is in place to make things
// clearer if this case is ever hit.
throw new InvalidOperationException(string.Format("{0}({1}) doesn't have a count attribute", method.Name, parameter.Name));
}
if (count.Count != 0)
{
// Fixed size
il.Emit(OpCodes.Ldc_I4, count.Count);
}
else if (count.Parameter != null)
{
// Parameter sized
var countVariable = EmitCountVariable(method, body, il, count.Parameter);
il.Emit(OpCodes.Ldloc, countVariable.Index);
}
else if (count.Computed != null)
{
// We don't handle count.Computed. Computed counts are hard and
// require manual reading of the specification for each one.
// But currently no string out parameters require it.
throw new NotSupportedException(string.Format("{0}({1}) requires a computed count: {2}", method.Name, parameter.Name, count.Computed));
}
il.Emit(OpCodes.Ldc_I4, 1);
il.Emit(OpCodes.Add);
il.Emit(OpCodes.Call, alloc_hglobal); il.Emit(OpCodes.Call, alloc_hglobal);
il.Emit(OpCodes.Stloc, stringBuilderPtrIndex); il.Emit(OpCodes.Stloc, stringPtrIndex);
il.Emit(OpCodes.Ldloc, stringBuilderPtrIndex); il.Emit(OpCodes.Ldloc, stringPtrIndex);
// We'll emit the try-finally block in the epilogue implementation, // We'll emit the try-finally block in the epilogue implementation,
// because we haven't yet emitted all necessary instructions here. // because we haven't yet emitted all necessary instructions here.
return stringBuilderPtrVar; return stringPtrVar;
} }
private static void EmitStringBuilderEpilogue(MethodDefinition wrapper, MethodDefinition native, private static void EmitStringOutEpilogue(MethodDefinition wrapper, MethodDefinition native,
ParameterDefinition parameter, MethodBody body, ILProcessor il, GeneratedVariableIdentifier generatedPtrVar) ParameterDefinition parameter, MethodBody body, ILProcessor il, GeneratedVariableIdentifier generatedPtrVar)
{ {
if (generatedPtrVar == null) if (generatedPtrVar == null)
@ -609,38 +649,36 @@ namespace OpenTK.Rewrite
throw new ArgumentNullException(nameof(generatedPtrVar)); throw new ArgumentNullException(nameof(generatedPtrVar));
} }
var p = parameter.ParameterType; // void GetShaderInfoLog(..., out String foo)
if (p.Name == "StringBuilder") // IntPtr foo_string_ptr;
{ // try {
// void GetShaderInfoLog(..., StringBuilder foo) // foo_string_ptr = Marshal.AllocHGlobal(count + 1);
// try { // glGetShaderInfoLog(..., foo_string_ptr);
// foo_sb_ptr = Marshal.AllocHGlobal(sb.Capacity + 1); -- already emitted // foo = MarshalPtrToString(foo_string_ptr);
// glGetShaderInfoLog(..., foo_sb_ptr); -- already emitted // }
// MarshalPtrToStringBuilder(foo_sb_ptr, foo); // finally {
// } // Marshal.FreeHGlobal(foo_string_ptr);
// finally { // }
// Marshal.FreeHGlobal(foo_sb_ptr);
// }
// Make sure we have imported BindingsBase::MasrhalPtrToStringBuilder and Marshal::FreeHGlobal // Make sure we have imported BindingsBase::MasrhalPtrToString and Marshal::FreeHGlobal
var ptr_to_sb = wrapper.Module.ImportReference(TypeBindingsBase.Methods.First(m => m.Name == "MarshalPtrToStringBuilder")); var ptr_to_str = wrapper.Module.ImportReference(TypeBindingsBase.Methods.First(m => m.Name == "MarshalPtrToString"));
var free_hglobal = wrapper.Module.ImportReference(TypeMarshal.Methods.First(m => m.Name == "FreeHGlobal")); var free_hglobal = wrapper.Module.ImportReference(TypeMarshal.Methods.First(m => m.Name == "FreeHGlobal"));
var block = new ExceptionHandler(ExceptionHandlerType.Finally); var block = new ExceptionHandler(ExceptionHandlerType.Finally);
block.TryStart = body.Instructions[0]; block.TryStart = body.Instructions[0];
il.Emit(OpCodes.Ldloc, generatedPtrVar.Definition.Index); il.Emit(OpCodes.Ldloc, generatedPtrVar.Definition.Index);
il.Emit(OpCodes.Ldarg, parameter.Index); il.Emit(OpCodes.Ldarg, parameter.Index);
il.Emit(OpCodes.Call, ptr_to_sb); il.Emit(OpCodes.Call, ptr_to_str);
il.Emit(OpCodes.Starg, parameter.Index);
block.TryEnd = body.Instructions.Last(); block.TryEnd = body.Instructions.Last();
block.HandlerStart = body.Instructions.Last(); block.HandlerStart = body.Instructions.Last();
il.Emit(OpCodes.Ldloc, generatedPtrVar.Definition.Index); il.Emit(OpCodes.Ldloc, generatedPtrVar.Definition.Index);
il.Emit(OpCodes.Call, free_hglobal); il.Emit(OpCodes.Call, free_hglobal);
block.HandlerEnd = body.Instructions.Last(); block.HandlerEnd = body.Instructions.Last();
}
} }
private static GeneratedVariableIdentifier EmitStringParameter(MethodDefinition wrapper, ParameterDefinition parameter, MethodBody body, private static GeneratedVariableIdentifier EmitStringParameter(MethodDefinition wrapper, ParameterDefinition parameter, MethodBody body,
@ -804,6 +842,64 @@ namespace OpenTK.Rewrite
return generatedVariables; return generatedVariables;
} }
private static object GetAttributeField(CustomAttribute attribute, string name)
{
try
{
var field = attribute.Fields.First(f => f.Name == name);
return field.Argument.Value;
}
catch (InvalidOperationException)
{
return null;
}
}
private static CountAttribute GetCountAttribute(ParameterDefinition parameter)
{
var attribute = parameter.CustomAttributes
.FirstOrDefault(a => a.AttributeType.Name == "CountAttribute");
var count = new CountAttribute();
if (attribute != null)
{
count.Count = (int)(GetAttributeField(attribute, "Count") ?? 0);
count.Parameter = (string)(GetAttributeField(attribute, "Parameter"));
count.Computed = (string)(GetAttributeField(attribute, "Computed"));
}
return count;
}
private static VariableDefinition EmitCountVariable(MethodDefinition method, MethodBody body, ILProcessor il, string countParameter)
{
var countVariable = new VariableDefinition(TypeInt32);
body.Variables.Add(countVariable);
// Parameter will either by a simple name or an
// expression like "name*5"
var parameter = method.Parameters.FirstOrDefault(
param => param.Name == countParameter);
if (parameter != null)
{
il.Emit(OpCodes.Ldarg, parameter.Index);
il.Emit(OpCodes.Stloc, countVariable.Index);
}
else
{
var operands = countParameter.Split('*');
parameter = method.Parameters.FirstOrDefault(
param => param.Name == operands[0]);
var scale = int.Parse(operands[1]);
il.Emit(OpCodes.Ldarg, parameter.Index);
il.Emit(OpCodes.Ldc_I4, scale);
il.Emit(OpCodes.Mul);
il.Emit(OpCodes.Stloc, countVariable.Index);
}
return countVariable;
}
private static List<GeneratedVariableIdentifier> EmitParameters(MethodDefinition method, MethodDefinition native, MethodBody body, ILProcessor il) private static List<GeneratedVariableIdentifier> EmitParameters(MethodDefinition method, MethodDefinition native, MethodBody body, ILProcessor il)
{ {
List<GeneratedVariableIdentifier> generatedVariables = new List<GeneratedVariableIdentifier>(); List<GeneratedVariableIdentifier> generatedVariables = new List<GeneratedVariableIdentifier>();
@ -819,9 +915,9 @@ namespace OpenTK.Rewrite
// We need to convert the loaded argument to IntPtr. // We need to convert the loaded argument to IntPtr.
il.Emit(OpCodes.Conv_I); il.Emit(OpCodes.Conv_I);
} }
else if (p.Name == "StringBuilder") else if (p.Name == "String" && !p.IsArray && parameter.IsOut)
{ {
generatedVariables.Add(EmitStringBuilderParameter(method, parameter, body, il)); generatedVariables.Add(EmitStringOutParameter(method, parameter, body, il));
} }
else if (p.Name == "String" && !p.IsArray) else if (p.Name == "String" && !p.IsArray)
{ {

View file

@ -76,27 +76,24 @@ namespace OpenTK
/// This method supports OpenTK and is not intended to be called by user code. /// This method supports OpenTK and is not intended to be called by user code.
/// </summary> /// </summary>
/// <param name="ptr">A pointer to a null-terminated byte array.</param> /// <param name="ptr">A pointer to a null-terminated byte array.</param>
/// <param name="sb">The StringBuilder to receive the contents of the pointer.</param> protected static string MarshalPtrToString(IntPtr ptr)
protected static void MarshalPtrToStringBuilder(IntPtr ptr, StringBuilder sb)
{ {
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
{ {
throw new ArgumentException("ptr"); throw new ArgumentException("ptr");
} }
if (sb == null)
{
throw new ArgumentNullException("sb");
}
sb.Length = 0; unsafe
for (int i = 0; ; i++)
{ {
byte b = Marshal.ReadByte(ptr, i); sbyte* str = (sbyte*)ptr.ToPointer();
if (b == 0) int len = 0;
while(*str != 0)
{ {
return; ++len;
++str;
} }
sb.Append((char)b);
return new string(str, 0, len, null);
} }
} }

View file

@ -0,0 +1,63 @@
//
// The Open Toolkit Library License
//
// Copyright (c) 2017 the Open Toolkit library, except where noted.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenTK
{
/// <summary>
/// Used to indicate how to calculate the count/length of a parameter.
///
/// Only one of Parameter, Count, or Computed should be set.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
public sealed class CountAttribute : Attribute
{
/// <summary>
/// Specifies another parameter to look at for the count of this parameter.
/// </summary>
public string Parameter;
/// <summary>
/// Specifies a fixed count.
/// </summary>
public int Count;
/// <summary>
/// Specifies a computed count based on other parameters.
/// </summary>
public string Computed;
/// <summary>
/// Constructs a new CountAttribute instance.
/// </summary>
public CountAttribute()
{
}
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -175,10 +175,10 @@ namespace OpenTK.Graphics.ES20
{ {
int length; int length;
GetProgram(program, GetProgramParameterName.ActiveAttributeMaxLength, out length); GetProgram(program, GetProgramParameterName.ActiveAttributeMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2); string str;
GetActiveAttrib(program, index, sb.Capacity, out length, out size, out type, sb); GetActiveAttrib(program, index, length == 0 ? 1 : length * 2, out length, out size, out type, out str);
return sb.ToString(); return str;
} }
public static string GetActiveUniform(int program, int uniformIndex, out int size, out ActiveUniformType type) public static string GetActiveUniform(int program, int uniformIndex, out int size, out ActiveUniformType type)
@ -186,9 +186,9 @@ namespace OpenTK.Graphics.ES20
int length; int length;
GetProgram(program, GetProgramParameterName.ActiveUniformMaxLength, out length); GetProgram(program, GetProgramParameterName.ActiveUniformMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length); string str;
GetActiveUniform(program, uniformIndex, sb.Capacity, out length, out size, out type, sb); GetActiveUniform(program, uniformIndex, length == 0 ? 1 : length, out length, out size, out type, out str);
return sb.ToString(); return str;
} }
public static void ShaderSource(Int32 shader, System.String @string) public static void ShaderSource(Int32 shader, System.String @string)
@ -218,9 +218,7 @@ namespace OpenTK.Graphics.ES20
info = String.Empty; info = String.Empty;
return; return;
} }
StringBuilder sb = new StringBuilder(length * 2); GL.GetShaderInfoLog((UInt32)shader, length * 2, &length, out info);
GL.GetShaderInfoLog((UInt32)shader, sb.Capacity, &length, sb);
info = sb.ToString();
} }
} }
@ -241,9 +239,7 @@ namespace OpenTK.Graphics.ES20
info = String.Empty; info = String.Empty;
return; return;
} }
StringBuilder sb = new StringBuilder(length * 2); GL.GetProgramInfoLog((UInt32)program, length * 2, &length, out info);
GL.GetProgramInfoLog((UInt32)program, sb.Capacity, &length, sb);
info = sb.ToString();
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -175,10 +175,10 @@ namespace OpenTK.Graphics.ES30
{ {
int length; int length;
GetProgram(program, ES30.GetProgramParameterName.ActiveAttributeMaxLength, out length); GetProgram(program, ES30.GetProgramParameterName.ActiveAttributeMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2); string str;
GetActiveAttrib(program, index, sb.Capacity, out length, out size, out type, sb); GetActiveAttrib(program, index, length == 0 ? 1 : length * 2, out length, out size, out type, out str);
return sb.ToString(); return str;
} }
public static string GetActiveUniform(int program, int uniformIndex, out int size, out ActiveUniformType type) public static string GetActiveUniform(int program, int uniformIndex, out int size, out ActiveUniformType type)
@ -186,9 +186,9 @@ namespace OpenTK.Graphics.ES30
int length; int length;
GetProgram(program, ES30.GetProgramParameterName.ActiveUniformMaxLength, out length); GetProgram(program, ES30.GetProgramParameterName.ActiveUniformMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length); string str;
GetActiveUniform(program, uniformIndex, sb.Capacity, out length, out size, out type, sb); GetActiveUniform(program, uniformIndex, length == 0 ? 1 : length, out length, out size, out type, out str);
return sb.ToString(); return str;
} }
public static void ShaderSource(Int32 shader, System.String @string) public static void ShaderSource(Int32 shader, System.String @string)
@ -218,9 +218,7 @@ namespace OpenTK.Graphics.ES30
info = String.Empty; info = String.Empty;
return; return;
} }
StringBuilder sb = new StringBuilder(length * 2); GL.GetShaderInfoLog((UInt32)shader, length * 2, &length, out info);
GL.GetShaderInfoLog((UInt32)shader, sb.Capacity, &length, sb);
info = sb.ToString();
} }
} }
@ -241,9 +239,7 @@ namespace OpenTK.Graphics.ES30
info = String.Empty; info = String.Empty;
return; return;
} }
StringBuilder sb = new StringBuilder(length * 2); GL.GetProgramInfoLog((UInt32)program, length * 2, &length, out info);
GL.GetProgramInfoLog((UInt32)program, sb.Capacity, &length, sb);
info = sb.ToString();
} }
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1889,10 +1889,10 @@ namespace OpenTK.Graphics.OpenGL
{ {
int length; int length;
GetProgram(program, OpenTK.Graphics.OpenGL.GetProgramParameterName.ActiveAttributeMaxLength, out length); GetProgram(program, OpenTK.Graphics.OpenGL.GetProgramParameterName.ActiveAttributeMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2); string str;
GetActiveAttrib(program, index, sb.Capacity, out length, out size, out type, sb); GetActiveAttrib(program, index, length == 0 ? 1 : length * 2, out length, out size, out type, out str);
return sb.ToString(); return str;
} }
/// <summary> /// <summary>
@ -1919,9 +1919,9 @@ namespace OpenTK.Graphics.OpenGL
int length; int length;
GetProgram(program, OpenTK.Graphics.OpenGL.GetProgramParameterName.ActiveUniformMaxLength, out length); GetProgram(program, OpenTK.Graphics.OpenGL.GetProgramParameterName.ActiveUniformMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length); string str;
GetActiveUniform(program, uniformIndex, sb.Capacity, out length, out size, out type, sb); GetActiveUniform(program, uniformIndex, length == 0 ? 1 : length, out length, out size, out type, out str);
return sb.ToString(); return str;
} }
/// <summary> /// <summary>
@ -1941,10 +1941,10 @@ namespace OpenTK.Graphics.OpenGL
{ {
int length; int length;
GetProgram(program, OpenTK.Graphics.OpenGL.GetProgramParameterName.ActiveUniformMaxLength, out length); GetProgram(program, OpenTK.Graphics.OpenGL.GetProgramParameterName.ActiveUniformMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2); string str;
GetActiveUniformName(program, uniformIndex, sb.Capacity, out length, sb); GetActiveUniformName(program, uniformIndex, length == 0 ? 1 : length * 2, out length, out str);
return sb.ToString(); return str;
} }
/// <summary> /// <summary>
@ -1964,10 +1964,10 @@ namespace OpenTK.Graphics.OpenGL
{ {
int length; int length;
GetProgram(program, OpenTK.Graphics.OpenGL.GetProgramParameterName.ActiveUniformBlockMaxNameLength, out length); GetProgram(program, OpenTK.Graphics.OpenGL.GetProgramParameterName.ActiveUniformBlockMaxNameLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2); string str;
GetActiveUniformBlockName(program, uniformIndex, sb.Capacity, out length, sb); GetActiveUniformBlockName(program, uniformIndex, length == 0 ? 1 : length * 2, out length, out str);
return sb.ToString(); return str;
} }
/// <summary> /// <summary>
@ -2027,9 +2027,7 @@ namespace OpenTK.Graphics.OpenGL
info = String.Empty; info = String.Empty;
return; return;
} }
StringBuilder sb = new StringBuilder(length * 2); GL.GetShaderInfoLog((UInt32)shader, length * 2, &length, out info);
GL.GetShaderInfoLog((UInt32)shader, sb.Capacity, &length, sb);
info = sb.ToString();
} }
} }
@ -2070,9 +2068,7 @@ namespace OpenTK.Graphics.OpenGL
info = String.Empty; info = String.Empty;
return; return;
} }
StringBuilder sb = new StringBuilder(length * 2); GL.GetProgramInfoLog((UInt32)program, length * 2, &length, out info);
GL.GetProgramInfoLog((UInt32)program, sb.Capacity, &length, sb);
info = sb.ToString();
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -246,10 +246,10 @@ namespace OpenTK.Graphics.OpenGL4
{ {
int length; int length;
GetProgram(program, OpenGL4.GetProgramParameterName.ActiveAttributeMaxLength, out length); GetProgram(program, OpenGL4.GetProgramParameterName.ActiveAttributeMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2); string str;
GetActiveAttrib(program, index, sb.Capacity, out length, out size, out type, sb); GetActiveAttrib(program, index, length == 0 ? 1 : length * 2, out length, out size, out type, out str);
return sb.ToString(); return str;
} }
public static string GetActiveUniform(int program, int uniformIndex, out int size, out ActiveUniformType type) public static string GetActiveUniform(int program, int uniformIndex, out int size, out ActiveUniformType type)
@ -257,9 +257,9 @@ namespace OpenTK.Graphics.OpenGL4
int length; int length;
GetProgram(program, OpenGL4.GetProgramParameterName.ActiveUniformMaxLength, out length); GetProgram(program, OpenGL4.GetProgramParameterName.ActiveUniformMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length); string str;
GetActiveUniform(program, uniformIndex, sb.Capacity, out length, out size, out type, sb); GetActiveUniform(program, uniformIndex, length == 0 ? 1 : length, out length, out size, out type, out str);
return sb.ToString(); return str;
} }
public static void ShaderSource(Int32 shader, System.String @string) public static void ShaderSource(Int32 shader, System.String @string)
@ -289,9 +289,7 @@ namespace OpenTK.Graphics.OpenGL4
info = String.Empty; info = String.Empty;
return; return;
} }
StringBuilder sb = new StringBuilder(length * 2); GL.GetShaderInfoLog((UInt32)shader, length * 2, &length, out info);
GL.GetShaderInfoLog((UInt32)shader, sb.Capacity, &length, sb);
info = sb.ToString();
} }
} }
@ -312,9 +310,7 @@ namespace OpenTK.Graphics.OpenGL4
info = String.Empty; info = String.Empty;
return; return;
} }
StringBuilder sb = new StringBuilder(length * 2); GL.GetProgramInfoLog((UInt32)program, length * 2, &length, out info);
GL.GetProgramInfoLog((UInt32)program, sb.Capacity, &length, sb);
info = sb.ToString();
} }
} }

View file

@ -56,6 +56,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AutoGeneratedAttribute.cs" /> <Compile Include="AutoGeneratedAttribute.cs" />
<Compile Include="CountAttribute.cs" />
<Compile Include="BindingsBase.cs" /> <Compile Include="BindingsBase.cs" />
<Compile Include="BlittableValueType.cs" /> <Compile Include="BlittableValueType.cs" />
<Compile Include="Configuration.cs" /> <Compile Include="Configuration.cs" />

View file

@ -167,6 +167,9 @@
<Compile Include="AutoGeneratedAttribute.cs"> <Compile Include="AutoGeneratedAttribute.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="CountAttribute.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="NativeWindow.cs"> <Compile Include="NativeWindow.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>

View file

@ -47,6 +47,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AutoGeneratedAttribute.cs" /> <Compile Include="AutoGeneratedAttribute.cs" />
<Compile Include="CountAttribute.cs" />
<Compile Include="BindingsBase.cs" /> <Compile Include="BindingsBase.cs" />
<Compile Include="BlittableValueType.cs" /> <Compile Include="BlittableValueType.cs" />
<Compile Include="Configuration.cs" /> <Compile Include="Configuration.cs" />