Tobias Bohnen avatar Tobias Bohnen committed 55c4d14

Comments (0)

Files changed (14)

CgNet.OpenTK/CgGLContext.cs

 
         public static Buffer CreateBuffer(this Context context, int size, IntPtr data, BufferUsageHint bufferUsage)
         {
-            return new Buffer(NativeMethods.cgGLCreateBuffer(context.Handle, size, data, bufferUsage));
+            return new Buffer(NativeMethods.cgGLCreateBuffer(context.Handle, size, data, bufferUsage), true);
         }
 
         public static Buffer CreateBufferFromObject(this Context context, OpenTK.Graphics.OpenGL.BufferUsageHint flags, bool manageObject)
         {
-            var retValue = new Buffer(NativeMethods.cgGLCreateBufferFromObject(context.Handle, flags, manageObject));
-            retValue.OwnsHandle = !manageObject;
+            var retValue = new Buffer(NativeMethods.cgGLCreateBufferFromObject(context.Handle, flags, manageObject), !manageObject);
             return retValue;
         }
 

CgNet/Annotation.cs

     {
         #region Constructors
 
-        internal Annotation(IntPtr handle)
-            : base(handle)
+        internal Annotation(IntPtr handle, bool ownsHandle)
+            : base(handle, ownsHandle)
         {
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetNextAnnotation(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Annotation(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Annotation(ptr, false);
             }
         }
 
         public Parameter GetDependentParameter(int index)
         {
             var ptr = NativeMethods.cgGetDependentAnnotationParameter(this.Handle, index);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         /// <summary>
     {
         #region Constructors
 
-        internal Buffer(IntPtr handle)
-            : base(handle)
+        internal Buffer(IntPtr handle, bool ownsHandle)
+            : base(handle, ownsHandle)
         {
         }
 
         /// <returns>Returns a Buffer on success.</returns>
         public static Buffer Create(Context context, int size, IntPtr data, BufferUsage bufferUsage)
         {
-            return new Buffer(NativeMethods.cgCreateBuffer(context.Handle, size, data, bufferUsage));
+            return new Buffer(NativeMethods.cgCreateBuffer(context.Handle, size, data, bufferUsage), true);
         }
 
         #endregion Public Static Methods
 
         #region Constructors
 
-        internal Context(IntPtr handle)
-            : base(handle)
+        internal Context(IntPtr handle, bool ownsHandle)
+            : base(handle, ownsHandle)
         {
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstEffect(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Effect(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Effect(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstProgram(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Program(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Program(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstSamplerState(this.Handle);
-                return ptr == IntPtr.Zero ? null : new State(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new State(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstState(this.Handle);
-                return ptr == IntPtr.Zero ? null : new State(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new State(ptr, false);
             }
         }
-
+        
         public bool IsContext
         {
             get
         public static Context Create()
         {
             var ptr = NativeMethods.cgCreateContext();
-            return ptr == IntPtr.Zero ? null : new Context(ptr);
+            return ptr == IntPtr.Zero ? null : new Context(ptr, true);
         }
 
         #endregion Public Static Methods
         public State CreateArraySamplerState(string name, ParameterType type, int elementCount)
         {
             var ptr = NativeMethods.cgCreateArraySamplerState(this.Handle, name, type, elementCount);
-            return ptr == IntPtr.Zero ? null : new State(ptr);
+            return ptr == IntPtr.Zero ? null : new State(ptr, true);
         }
 
         public State CreateArrayState(string name, ParameterType type, int elementCount)
         {
             var ptr = NativeMethods.cgCreateArrayState(this.Handle, name, type, elementCount);
-            return ptr == IntPtr.Zero ? null : new State(ptr);
+            return ptr == IntPtr.Zero ? null : new State(ptr, true);
         }
 
         public Buffer CreateBuffer(int size, IntPtr data, BufferUsage bufferUsage)
         {
             var ptr = NativeMethods.cgCreateBuffer(this.Handle, size, data, bufferUsage);
-            return ptr == IntPtr.Zero ? null : new Buffer(ptr);
+            return ptr == IntPtr.Zero ? null : new Buffer(ptr, true);
         }
 
         public Effect CreateEffect(string code, params string[] args)
         {
             var ptr = NativeMethods.cgCreateEffect(this.Handle, code, args);
-            return ptr == IntPtr.Zero ? null : new Effect(ptr);
+            return ptr == IntPtr.Zero ? null : new Effect(ptr, true);
         }
 
         public Effect CreateEffectFromFile(string filename, params string[] args)
         {
             var ptr = NativeMethods.cgCreateEffectFromFile(this.Handle, filename, args);
-            return ptr == IntPtr.Zero ? null : new Effect(ptr);
+            return ptr == IntPtr.Zero ? null : new Effect(ptr, true);
         }
 
         public Parameter CreateEffectParameter(string name, ParameterType type)
         {
             var ptr = NativeMethods.cgCreateEffectParameter(this.Handle, name, type);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr);
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, true);
         }
 
         public Obj CreateObj(ProgramType programType, string source, ProfileType profile, params string[] args)
         {
             var ptr = NativeMethods.cgCreateObj(this.Handle, programType, source, profile, args);
-            return ptr == IntPtr.Zero ? null : new Obj(ptr);
+            return ptr == IntPtr.Zero ? null : new Obj(ptr, true);
         }
 
         public Obj CreateObjFromFile(ProgramType programType, string sourceFile, ProfileType profile, params string[] args)
         {
             var ptr = NativeMethods.cgCreateObjFromFile(this.Handle, programType, sourceFile, profile, args);
-            return ptr == IntPtr.Zero ? null : new Obj(ptr);
+            return ptr == IntPtr.Zero ? null : new Obj(ptr, true);
         }
 
         public Parameter CreateParameter(ParameterType type)
         {
             var ptr = NativeMethods.cgCreateParameter(this.Handle, type);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr);
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, true);
         }
 
         public Parameter CreateParameterArray(ParameterType type, int length)
         {
             var ptr = NativeMethods.cgCreateParameterArray(this.Handle, type, length);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr);
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, true);
         }
 
         public Parameter CreateParameterMultiDimArray(ParameterType type, int dim, int[] lengths)
         {
             var ptr = NativeMethods.cgCreateParameterMultiDimArray(this.Handle, type, dim, lengths);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr);
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, true);
         }
 
         public Program CreateProgram(ProgramType type, string source, ProfileType profile, string entry, params string[] args)
         {
             var ptr = NativeMethods.cgCreateProgram(this.Handle, type, source, profile, entry, args);
-            return ptr == IntPtr.Zero ? null : new Program(ptr)
-                                               {
-                                                   Type = type,
-                                               };
+            return ptr == IntPtr.Zero ? null : new Program(ptr, true)
+            {
+                Type = type,
+            };
         }
 
         public Program CreateProgramFromFile(ProgramType type, string file, ProfileType profile, string entry, params string[] args)
         {
             var ptr = NativeMethods.cgCreateProgramFromFile(this.Handle, type, file, profile, entry, args);
-            return ptr == IntPtr.Zero ? null : new Program(ptr)
-                                               {
-                                                   Type = type,
-                                               };
+            return ptr == IntPtr.Zero ? null : new Program(ptr, true)
+            {
+                Type = type,
+            };
         }
 
         public State CreateSamplerState(string name, ParameterType type)
         {
             var ptr = NativeMethods.cgCreateSamplerState(this.Handle, name, type);
-            return ptr == IntPtr.Zero ? null : new State(ptr);
+            return ptr == IntPtr.Zero ? null : new State(ptr, true);
         }
 
         public State CreateState(string name, ParameterType type)
         {
             var ptr = NativeMethods.cgCreateState(this.Handle, name, type);
-            return ptr == IntPtr.Zero ? null : new State(ptr);
+            return ptr == IntPtr.Zero ? null : new State(ptr, true);
         }
 
         public Effect GetNamedEffect(string name)
         {
             var ptr = NativeMethods.cgGetNamedEffect(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Effect(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Effect(ptr, false);
         }
 
         public State GetNamedSamplerState(string name)
         {
             var ptr = NativeMethods.cgGetNamedSamplerState(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new State(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new State(ptr, false);
         }
 
         public State GetNamedState(string name)
         {
             var ptr = NativeMethods.cgGetNamedState(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new State(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new State(ptr, false);
         }
 
         public void SetCompilerIncludeFile(string name, string filename)
     {
         #region Constructors
 
-        internal Effect(IntPtr handle)
-            : base(handle)
+        internal Effect(IntPtr handle, bool ownsHandle)
+            : base(handle, ownsHandle)
         {
         }
 
         {
             get
             {
-                return new Context(NativeMethods.cgGetEffectContext(this.Handle))
-                       {
-                           OwnsHandle = false
-                       };
+                return new Context(NativeMethods.cgGetEffectContext(this.Handle), false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstEffectAnnotation(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Annotation(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Annotation(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstLeafEffectParameter(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstEffectParameter(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
             }
         }
-
+        
         public Technique FirstTechnique
         {
             get
             {
                 var ptr = NativeMethods.cgGetFirstTechnique(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Technique(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Technique(ptr, false);
             }
         }
-
+        
         public bool IsEffect
         {
             get
             get
             {
                 var ptr = NativeMethods.cgGetNextEffect(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Effect(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Effect(ptr, false);
             }
         }
 
         public Effect Copy()
         {
             var ptr = NativeMethods.cgCopyEffect(this.Handle);
-            return ptr == IntPtr.Zero ? null : new Effect(ptr);
+            return ptr == IntPtr.Zero ? null : new Effect(ptr, true);
         }
 
         public Annotation CreateAnnotation(string name, ParameterType type)
         {
             var ptr = NativeMethods.cgCreateEffectAnnotation(this.Handle, name, type);
-            return ptr == IntPtr.Zero ? null : new Annotation(ptr);
+            return ptr == IntPtr.Zero ? null : new Annotation(ptr, true);
         }
 
         public Parameter CreateParameterArray(string name, ParameterType type, int length)
         {
             var ptr = NativeMethods.cgCreateEffectParameterArray(this.Handle, name, type, length);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr);
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, true);
         }
 
         public Parameter CreateParameterMultiDimArray(string name, ParameterType type, int dim, int[] lengths)
         {
             var ptr = NativeMethods.cgCreateEffectParameterMultiDimArray(this.Handle, name, type, dim, lengths);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr);
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, true);
         }
 
         public Program CreateProgram(ProfileType profile, string entry, params string[] args)
         {
             var ptr = NativeMethods.cgCreateProgramFromEffect(this.Handle, profile, entry, args);
-            return ptr == IntPtr.Zero ? null : new Program(ptr);
+            return ptr == IntPtr.Zero ? null : new Program(ptr, true);
         }
 
         public Technique CreateTechnique(string name)
         {
             var ptr = NativeMethods.cgCreateTechnique(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Technique(ptr);
+            return ptr == IntPtr.Zero ? null : new Technique(ptr, true);
         }
 
         public Annotation GetNamedAnnotation(string name)
         {
             var ptr = NativeMethods.cgGetNamedEffectAnnotation(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Annotation(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Annotation(ptr, false);
         }
 
         public Parameter GetNamedParameter(string name)
         {
             var ptr = NativeMethods.cgGetNamedEffectParameter(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public Technique GetNamedTechnique(string name)
         {
             var ptr = NativeMethods.cgGetNamedTechnique(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Technique(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Technique(ptr, false);
         }
 
         public Parameter GetNamedUniformBuffer(string blockName)
         {
             var ptr = NativeMethods.cgGetNamedEffectUniformBuffer(this.Handle, blockName);
-                return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public ParameterType GetNamedUserType(string name)
         public Parameter GetParameterBySemantic(string name)
         {
             var ptr = NativeMethods.cgGetEffectParameterBySemantic(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public ParameterType GetUserType(int index)
     {
         #region Constructors
 
-        internal Obj(IntPtr handle)
-            : base(handle)
+        internal Obj(IntPtr handle, bool ownsHandle)
+            : base(handle, ownsHandle)
         {
         }
 

CgNet/Parameter.cs

     {
         #region Constructors
 
-        internal Parameter(IntPtr handle)
-            : base(handle)
+        internal Parameter(IntPtr handle, bool ownsHandle)
+            : base(handle, ownsHandle)
         {
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetConnectedParameter(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                {
-                    OwnsHandle = false
-                };
+                return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetParameterContext(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Context(ptr)
-                {
-                    OwnsHandle = false
-                };
+                return ptr == IntPtr.Zero ? null : new Context(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetParameterEffect(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Effect(ptr)
-                {
-                    OwnsHandle = false
-                };
+                return ptr == IntPtr.Zero ? null : new Effect(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstParameterAnnotation(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Annotation(ptr)
-                {
-                    OwnsHandle = false
-                };
+                return ptr == IntPtr.Zero ? null : new Annotation(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstSamplerStateAssignment(this.Handle);
-                return ptr == IntPtr.Zero ? null : new StateAssignment(ptr)
-                {
-                    OwnsHandle = false
-                };
+                return ptr == IntPtr.Zero ? null : new StateAssignment(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstUniformBufferParameter(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                {
-                    OwnsHandle = false
-                };
+                return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetNextLeafParameter(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                {
-                    OwnsHandle = false
-                };
+                return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetNextParameter(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                {
-                    OwnsHandle = false
-                };
+                return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetParameterProgram(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Program(ptr)
-                {
-                    OwnsHandle = false
-                };
+                return ptr == IntPtr.Zero ? null : new Program(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetUniformBufferParameter(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Buffer(ptr)
-                {
-                    OwnsHandle = false
-                };
+                return ptr == IntPtr.Zero ? null : new Buffer(ptr, false);
             }
 
             set
         public Annotation CreateAnnotation(string name, ParameterType type)
         {
             var ptr = NativeMethods.cgCreateParameterAnnotation(this.Handle, name, type);
-            return ptr == IntPtr.Zero ? null : new Annotation(ptr);
+            return ptr == IntPtr.Zero ? null : new Annotation(ptr, true);
         }
 
         public void Disconnect()
         public Parameter GetArrayParameter(int index)
         {
             var ptr = NativeMethods.cgGetArrayParameter(this.Handle, index);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public int GetArraySize(int dimension)
         public Parameter GetConnectedToParameter(int index)
         {
             var ptr = NativeMethods.cgGetConnectedToParameter(this.Handle, index);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public int GetDefaultValue(ref double[] values)
         public Buffer GetEffectParameterBuffer()
         {
             var ptr = NativeMethods.cgGetEffectParameterBuffer(this.Handle);
-            return ptr == IntPtr.Zero ? null : new Buffer(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Buffer(ptr, false);
         }
 
         public Parameter GetFirstDependentParameter()
         {
             var ptr = NativeMethods.cgGetFirstDependentParameter(this.Handle);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public Parameter GetFirstStructParameter()
         {
             var ptr = NativeMethods.cgGetFirstStructParameter(this.Handle);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public void GetMatrix(out int[] values)
         public Annotation GetNamedAnnotation(string name)
         {
             var ptr = NativeMethods.cgGetNamedParameterAnnotation(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Annotation(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Annotation(ptr, false);
         }
 
         public StateAssignment GetNamedStateAssignment(string name)
         {
             var ptr = NativeMethods.cgGetNamedSamplerStateAssignment(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new StateAssignment(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new StateAssignment(ptr, false);
         }
 
         public Parameter GetNamedStructParameter(string name)
         {
             var ptr = NativeMethods.cgGetNamedStructParameter(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public Parameter GetNamedSubParameter(string name)
         {
             var ptr = NativeMethods.cgGetNamedSubParameter(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public Parameter GetNamedUniformBufferParameter(string name)
         {
             var ptr = NativeMethods.cgGetNamedUniformBufferParameter(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public string GetStringValue()
     {
         #region Constructors
 
-        internal Pass(IntPtr handle)
-            : base(handle)
+        internal Pass(IntPtr handle, bool ownsHandle)
+            : base(handle, ownsHandle)
         {
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstPassAnnotation(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Annotation(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Annotation(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstStateAssignment(this.Handle);
-                return ptr == IntPtr.Zero ? null : new StateAssignment(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new StateAssignment(ptr, false);
             }
         }
 
             {
                 var ptr = NativeMethods.cgGetNextPass(this.Handle);
 
-                return ptr == IntPtr.Zero ? null : new Pass(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Pass(ptr, false);
             }
         }
 
             {
                 var ptr = NativeMethods.cgGetPassTechnique(this.Handle);
 
-                return ptr == IntPtr.Zero ? null : new Technique(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Technique(ptr, false);
             }
         }
 
         public Annotation CreateAnnotation(string name, ParameterType type)
         {
             var ptr = NativeMethods.cgCreatePassAnnotation(this.Handle, name, type);
-            return ptr == IntPtr.Zero ? null : new Annotation(ptr);
+            return ptr == IntPtr.Zero ? null : new Annotation(ptr, true);
         }
 
         public StateAssignment CreateSamplerStateAssignment(State state)
         {
             var ptr = NativeMethods.cgCreateSamplerStateAssignment(this.Handle, state.Handle);
-            return ptr == IntPtr.Zero ? null : new StateAssignment(ptr);
+            return ptr == IntPtr.Zero ? null : new StateAssignment(ptr, true);
         }
 
         public StateAssignment CreateStateAssignment(State state)
         {
             var ptr = NativeMethods.cgCreateStateAssignment(this.Handle, state.Handle);
-            return ptr == IntPtr.Zero ? null : new StateAssignment(ptr);
+            return ptr == IntPtr.Zero ? null : new StateAssignment(ptr, true);
         }
 
         public StateAssignment CreateStateAssignmentIndex(State state, int index)
         {
             var ptr = NativeMethods.cgCreateStateAssignmentIndex(this.Handle, state.Handle, index);
-            return ptr == IntPtr.Zero ? null : new StateAssignment(ptr);
+            return ptr == IntPtr.Zero ? null : new StateAssignment(ptr, true);
         }
 
         public Annotation GetNamedAnnotation(string name)
         {
             var ptr = NativeMethods.cgGetNamedPassAnnotation(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Annotation(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Annotation(ptr, false);
         }
 
         public StateAssignment GetNamedStateAssignment(string name)
         {
             var ptr = NativeMethods.cgGetNamedStateAssignment(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new StateAssignment(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new StateAssignment(ptr, false);
         }
 
         public Program GetProgram(Domain domain)
         {
             var ptr = NativeMethods.cgGetPassProgram(this.Handle, domain);
-
-            return ptr == IntPtr.Zero ? null : new Program(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Program(ptr, false);
         }
 
         public void ResetState()
     {
         #region Constructors
 
-        internal Program(IntPtr handle)
-            : base(handle)
+        internal Program(IntPtr handle, bool ownsHandle)
+            : base(handle, ownsHandle)
         {
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetProgramContext(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Context(ptr)
-                {
-                    OwnsHandle = false
-                };
+                return ptr == IntPtr.Zero ? null : new Context(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstProgramAnnotation(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Annotation(ptr)
-                {
-                    OwnsHandle = false
-                };
+                return ptr == IntPtr.Zero ? null : new Annotation(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetNextProgram(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Program(ptr)
-                {
-                    OwnsHandle = false
-                };
+                return ptr == IntPtr.Zero ? null : new Program(ptr, false);
             }
         }
 
             }
 
             var ptr = NativeMethods.cgCombinePrograms(buf.Length, buf);
-            return ptr == IntPtr.Zero ? null : new Program(ptr);
+            return ptr == IntPtr.Zero ? null : new Program(ptr, true);
         }
 
         public static Program Create(Context context, ProgramType type, string source, ProfileType profile, string entry, params string[] args)
         public Program Combine(Program exe1)
         {
             var ptr = NativeMethods.cgCombinePrograms2(this.Handle, exe1.Handle);
-            return ptr == IntPtr.Zero ? null : new Program(ptr);
+            return ptr == IntPtr.Zero ? null : new Program(ptr, true);
         }
 
         public void Compile()
         public Program Copy()
         {
             var ptr = NativeMethods.cgCopyProgram(this.Handle);
-            return ptr == IntPtr.Zero ? null : new Program(ptr);
+            return ptr == IntPtr.Zero ? null : new Program(ptr, true);
         }
 
         public Annotation CreateAnnotation(string name, ParameterType type)
         {
             var ptr = NativeMethods.cgCreateProgramAnnotation(this.Handle, name, type);
-            return new Annotation(ptr);
+            return new Annotation(ptr, true);
         }
 
         public float[] Evaluate(int ncomps, int nx, int ny, int nz)
         public Buffer GetBuffer(int bufferIndex)
         {
             var ptr = NativeMethods.cgGetProgramBuffer(this.Handle, bufferIndex);
-            return ptr == IntPtr.Zero ? null : new Buffer(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Buffer(ptr, false);
         }
 
         public ProfileType GetDomainProfile(int index)
         public Program GetDomainProgram(int index)
         {
             var ptr = NativeMethods.cgGetProgramDomainProgram(this.Handle, index);
-            return ptr == IntPtr.Zero ? null : new Program(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Program(ptr, false);
         }
 
         public Parameter GetFirstLeafParameter(NameSpace nameSpace)
         {
             var ptr = NativeMethods.cgGetFirstLeafParameter(this.Handle, nameSpace);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public Parameter GetFirstParameter(NameSpace nameSpace)
         {
             var ptr = NativeMethods.cgGetFirstParameter(this.Handle, nameSpace);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public Annotation GetNamedAnnotation(string name)
         {
             var ptr = NativeMethods.cgGetNamedProgramAnnotation(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Annotation(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Annotation(ptr, false);
         }
 
         public Parameter GetNamedParameter(NameSpace nameSpace, string name)
         {
             var ptr = NativeMethods.cgGetNamedProgramParameter(this.Handle, nameSpace, name);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public Parameter GetNamedParameter(string parameter)
         {
             var ptr = NativeMethods.cgGetNamedParameter(this.Handle, parameter);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public Parameter GetNamedUniformBuffer(string blockName)
         {
             var ptr = NativeMethods.cgGetNamedProgramUniformBuffer(this.Handle, blockName);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-            {
-                OwnsHandle = false
-            };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public ParameterType GetNamedUserType(string name)

CgNet/Properties/AssemblyInfo.cs

 using System;
 using System.Reflection;
+using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 
 // General Information about an assembly is controlled through the following
 // set of attributes. Change these attribute values to modify the information
 // [assembly: AssemblyVersion("1.0.*")]
 [assembly: AssemblyVersion("1.0.0.0")]
 [assembly: AssemblyFileVersion("1.0.0.0")]
-
 [assembly: InternalsVisibleTo("CgNet.OpenTK")]
 [assembly: InternalsVisibleTo("CgNet.SlimDX")]
     {
         #region Constructors
 
-        internal State(IntPtr handle)
-            : base(handle)
+        internal State(IntPtr handle, bool ownsHandle)
+            : base(handle, ownsHandle)
         {
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetStateContext(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Context(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Context(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetNextState(this.Handle);
-                return ptr == IntPtr.Zero ? null : new State(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new State(ptr, false);
             }
         }
 

CgNet/StateAssignment.cs

     {
         #region Constructors
 
-        internal StateAssignment(IntPtr handle)
-            : base(handle)
+        internal StateAssignment(IntPtr handle, bool ownsHandle)
+            : base(handle, ownsHandle)
         {
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetConnectedStateAssignmentParameter(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetNextStateAssignment(this.Handle);
-                return ptr == IntPtr.Zero ? null : new StateAssignment(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new StateAssignment(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetStateAssignmentPass(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Pass(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Pass(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetStateAssignmentState(this.Handle);
-                return ptr == IntPtr.Zero ? null : new State(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new State(ptr, false);
             }
         }
 
         public Parameter GetDependentParameter(int index)
         {
             var ptr = NativeMethods.cgGetDependentStateAssignmentParameter(this.Handle, index);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public Parameter GetDependentProgramArrayParameter(int index)
         {
             var ptr = NativeMethods.cgGetDependentProgramArrayStateAssignmentParameter(this.Handle, index);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public float[] GetFloatValues()
         public Program GetProgramValue()
         {
             var ptr = NativeMethods.cgGetProgramStateAssignmentValue(this.Handle);
-            return ptr == IntPtr.Zero ? null : new Program(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Program(ptr, false);
         }
 
         public Parameter GetSamplerParameter()
         {
             var ptr = NativeMethods.cgGetSamplerStateAssignmentParameter(this.Handle);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public State GetSamplerState()
         {
             var ptr = NativeMethods.cgGetSamplerStateAssignmentState(this.Handle);
-            return ptr == IntPtr.Zero ? null : new State(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new State(ptr, false);
         }
 
         public Parameter GetSamplerStateAssignmentValue()
         {
             var ptr = NativeMethods.cgGetSamplerStateAssignmentValue(this.Handle);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public string GetStringValue()
         public Parameter GetTextureStateAssignmentValue()
         {
             var ptr = NativeMethods.cgGetTextureStateAssignmentValue(this.Handle);
-            return ptr == IntPtr.Zero ? null : new Parameter(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Parameter(ptr, false);
         }
 
         public bool Set(float value)

CgNet/Technique.cs

     {
         #region Constructors
 
-        internal Technique(IntPtr handle)
-            : base(handle)
+        internal Technique(IntPtr handle, bool ownsHandle)
+            : base(handle, ownsHandle)
         {
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetTechniqueEffect(this.Handle);
-
-                return ptr == IntPtr.Zero ? null : new Effect(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Effect(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstTechniqueAnnotation(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Annotation(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Annotation(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetFirstPass(this.Handle);
-
-                return ptr == IntPtr.Zero ? null : new Pass(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Pass(ptr, false);
             }
         }
 
             get
             {
                 var ptr = NativeMethods.cgGetNextTechnique(this.Handle);
-                return ptr == IntPtr.Zero ? null : new Technique(ptr)
-                                                   {
-                                                       OwnsHandle = false
-                                                   };
+                return ptr == IntPtr.Zero ? null : new Technique(ptr, false);
             }
         }
 
         public Annotation CreateAnnotation(string name, ParameterType type)
         {
             var ptr = NativeMethods.cgCreateTechniqueAnnotation(this.Handle, name, type);
-            return ptr == IntPtr.Zero ? null : new Annotation(ptr);
+            return ptr == IntPtr.Zero ? null : new Annotation(ptr, true);
         }
 
         public Pass CreatePass(string name)
         {
             var ptr = NativeMethods.cgCreatePass(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Pass(ptr);
+            return ptr == IntPtr.Zero ? null : new Pass(ptr, true);
         }
 
         public Annotation GetNamedAnnotation(string name)
         {
             var ptr = NativeMethods.cgGetNamedTechniqueAnnotation(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Annotation(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Annotation(ptr, false);
         }
 
         public Pass GetNamedPass(string name)
         {
             var ptr = NativeMethods.cgGetNamedPass(this.Handle, name);
-            return ptr == IntPtr.Zero ? null : new Pass(ptr)
-                                               {
-                                                   OwnsHandle = false
-                                               };
+            return ptr == IntPtr.Zero ? null : new Pass(ptr, false);
         }
 
         public void SetLastListing(string listing)

CgNet/WrapperObject.cs

     {
         #region Constructors
 
-        protected WrapperObject(IntPtr handle)
+        protected WrapperObject(IntPtr handle, bool ownsHandle)
         {
             if (handle == IntPtr.Zero)
             {
                 throw new ArgumentException("handle is invalid", "handle");
             }
 
-            this.OwnsHandle = true;
+            this.OwnsHandle = ownsHandle;
             this.Handle = handle;
         }
 
             private set;
         }
 
-        #endregion Public Properties
-
-        #region Internal Properties
-
         /// <summary>
         /// Gets or sets a value indicating whether the WrapperObject owns the handle.
         /// </summary>
-        internal bool OwnsHandle
+        public bool OwnsHandle
         {
             get;
-            set;
+            private set;
         }
 
-        #endregion Internal Properties
+        #endregion Public Properties
 
         #endregion Properties
 
         /// Returns a hash code for this instance.
         /// </summary>
         /// <returns>
-        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
+        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
         /// </returns>
         public override int GetHashCode()
         {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.