Lock() static private method

static private Lock ( ) : ContextLock
return ContextLock
Beispiel #1
0
		public void Add(Shader item) {
			if (item == null)
				throw new ArgumentNullException("item");
			using (Context.Lock())
				GL.AttachShader(program.Id, item.Id);
			set.Add(item);
		}
Beispiel #2
0
 internal VertexArrayLock(VertexArray array)
 {
     this.context = Context.Lock();
     this.array   = array;
     GL.GetInteger(GetPName.VertexArrayBinding, out was);
     GL.BindVertexArray(array.Id);
 }
Beispiel #3
0
		int GetInt32(GetProgramParameterName pname) {
			int result;

			using (Context.Lock())
				GL.GetProgram(Id, pname, out result);
			return result;
		}
Beispiel #4
0
        int Get1i(ProgramStageParameter pname)
        {
            int value;

            using (Context.Lock())
                GL.GetProgramStage(program.Id, (ShaderType)stage, pname, out value);
            return(value);
        }
Beispiel #5
0
 internal void Used()
 {
     if (object.ReferenceEquals(Program, Device.Program))
     {
         using (Context.Lock())
             GL.UniformSubroutines(ShaderType, ids.Length, ids);
     }
 }
Beispiel #6
0
        protected ulong Get1ul(GetQueryObjectParam param)
        {
            ulong result;

            using (Context.Lock())
                GL.GetQueryObject((uint)Id, param, out result);
            return(result);
        }
Beispiel #7
0
		public bool Remove(Shader item) {
			if (set.Remove(item)) {
				using (Context.Lock())
					GL.DetachShader(program.Id, item.Id);
				return true;
			}
			return false;
		}
Beispiel #8
0
 /// <summary>
 /// Compiles the source code strings that have been stored in the shader object through <see cref="Source"/>, and return whether it compiles (which can also be checked through <see cref="CompileStatus"/>).
 /// </summary>
 /// <returns></returns>
 public bool Compile()
 {
     using (Context.Lock())
     {
         GL.CompileShader(Id);
         Context.CheckError();
         int result;
         GL.GetShader(Id, ShaderParameter.CompileStatus, out result);
         return(result != 0);
     }
 }
Beispiel #9
0
 public virtual void Begin()
 {
     using (Context.Lock())
         if (Indexed)
         {
             GL.BeginQueryIndexed(Target, Index, Id);
         }
         else
         {
             GL.BeginQuery(Target, Id);
         }
 }
Beispiel #10
0
 public virtual void End()
 {
     using (Context.Lock())
         if (Indexed)
         {
             GL.EndQueryIndexed(Target, Index);
         }
         else
         {
             GL.EndQuery(Target);
         }
 }
Beispiel #11
0
        public void Set(ref Matrix4d value)
        {
            using (Context.Lock())
                switch (type)
                {
                case ActiveUniformType.FloatMat4:
                    Matrix4f as4f = (Matrix4f)value;
                    GL.ProgramUniformMatrix4(Program.Id, location, 1, Transpose, ref as4f.XX); break;

                //case ActiveUniformType.DoubleMat4: GL.ProgramUniformMatrix4(Program.Id, location, 1, Transpose, ref value.XX); break;
                default: throw new NotImplementedException();
                }
        }
Beispiel #12
0
        public void Set(uint value)
        {
            using (Context.Lock())
                switch (type)
                {
                case ActiveUniformType.Bool: GL.ProgramUniform1(Program.Id, location, value != 0 ? 1 : 0); break;

                case ActiveUniformType.Double: GL.ProgramUniform1(Program.Id, location, (double)value); break;

                case ActiveUniformType.Int: GL.ProgramUniform1(Program.Id, location, (int)value); break;

                case ActiveUniformType.UnsignedInt: GL.ProgramUniform1(Program.Id, location, (uint)value); break;
                }
        }
Beispiel #13
0
        protected int Get1i(GetQueryParam param)
        {
            int result;

            using (Context.Lock())
                if (Indexed)
                {
                    GL.GetQueryIndexed(Target, Index, param, out result);
                }
                else
                {
                    GL.GetQuery(Target, param, out result);
                }
            return(result);
        }
Beispiel #14
0
        public void Set(float value)
        {
            using (Context.Lock())
                switch (type)
                {
                case ActiveUniformType.Bool: GL.ProgramUniform1(Program.Id, location, value != 0 ? 1 : 0); break;

                case ActiveUniformType.Double: GL.ProgramUniform1(Program.Id, location, (double)value); break;

                case ActiveUniformType.Int: GL.ProgramUniform1(Program.Id, location, (int)value); break;

                case ActiveUniformType.UnsignedInt: GL.ProgramUniform1(Program.Id, location, (uint)value); break;

                default: throw InvalidTypeException(typeof(int));
                }
        }
Beispiel #15
0
        void Set(Texture texture, ActiveUniformType required, Type givenType)
        {
            if (type != required)
            {
                throw ConversionException(givenType);
            }

            if (object.ReferenceEquals(Context.Current.program, Program))
            {
                using (Context.Lock()) {
                    GL.ActiveTexture(Unit);
                    Context.CheckError();
                    GL.BindTexture(TextureTarget, texture != null ? texture.Id : 0);
                }
            }

            Texture = texture;
        }
Beispiel #16
0
        internal void Link()
        {
            Unlink();

            using (Context.Lock()) {
                int activeSubroutineMaxLength        = Get1i(ProgramStageParameter.ActiveSubroutineMaxLength);        // Longest subroutine name for the stage.
                int activeSubroutineUniformMaxLength = Get1i(ProgramStageParameter.ActiveSubroutineUniformMaxLength); // Longest subroutine uniform name for the stage.
                int activeSubroutines = Get1i(ProgramStageParameter.ActiveSubroutines);                               // The number of active subroutines in the stage.
                int activeSubroutineUniformLocations = Get1i(ProgramStageParameter.ActiveSubroutineUniformLocations); // The number of active subroutine variable locations in the stage.
                int activeSubroutineUniforms         = Get1i(ProgramStageParameter.ActiveSubroutineUniforms);         // The number of active subroutine variables in the stage.

                if (activeSubroutines != 0 || activeSubroutineUniforms != 0)
                {
                    StringBuilder builder = new StringBuilder(Math.Max(activeSubroutineUniformMaxLength, activeSubroutineMaxLength));
                    int           length;

                    ids = new int[activeSubroutineUniforms];

                    // Gather the subroutines
                    for (int index = 0; index < activeSubroutines; index++)
                    {
                        GL.GetActiveSubroutineName(Program.Id, ShaderType, index, activeSubroutineMaxLength, out length, builder);
                        subroutines.Add(new ProgramSubroutine(this, builder.ToString(), index));
                        builder.Clear();
                    }

                    // Gather the subroutine uniforms
                    for (int index = 0; index < activeSubroutineUniforms; index++)
                    {
                        GL.GetActiveSubroutineUniformName(Program.Id, ShaderType, index, activeSubroutineUniformMaxLength, out length, builder);
                        uniforms.Add(new ProgramSubroutineUniform(this, builder.ToString(), index));
                        builder.Clear();
                    }
                }
            }
        }
Beispiel #17
0
		/// <summary>Attempt to link a <see cref="Program"/> object, returning success.</summary>
		/// <remarks>
		/// If any <see cref="Shader"/> objects of type <see cref="VertexShader"/>​ are attached to the <see cref="Program"/>​, they will be used to create an executable that will run on the programmable vertex processor. If any shader objects of type <see cref="GeometryShader"/>​ are attached to the <see cref="Program"/>​, they will be used to create an executable that will run on the programmable geometry processor. If any shader objects of type <see cref="FragmentShader"/> are attached to the <see cref="Program"/>​, they will be used to create an executable that will run on the programmable fragment processor.
		///  
		/// The status of the link operation will be stored as part of the program object's state. This value will be set to <c>true</c>​ if the program object was linked without errors and is ready for use, and <c>false</c>​ otherwise. It can be queried through <see cref="IsLinked"/>.
		/// 
		/// As a result of a successful link operation, all active user-defined uniform variables belonging to program​ will be initialized to 0, and each of the program object's active uniform variables can be accessed through <see cref="Uniforms"/>. Also, any active user-defined attribute variables that have not been bound to a generic vertex attribute index will be bound to one at this time and accessed through <see cref="Attributes"/>.
		/// 
		/// Linking of a program object can fail for a number of reasons as specified in the OpenGL Shading Language Specification. The following lists some of the conditions that will cause a link error.
		/// <list type="bullet">
		/// <item><description>The number of active attribute variables supported by the implementation has been exceeded.</description></item>
		/// <item><description>The storage limit for uniform variables has been exceeded.</description></item>
		/// <item><description>The number of active uniform variables supported by the implementation has been exceeded.</description></item>
		/// <item><description>The main function is missing for the vertex, geometry or fragment shader.</description></item>
		/// <item><description>A varying variable actually used in the fragment shader is not declared in the same way (or is not declared at all) in the vertex shader, or geometry shader shader if present.</description></item>
		/// <item><description>A reference to a function or variable name is unresolved.</description></item>
		/// <item><description>A shared global is declared with two different types or two different initial values.</description></item>
		/// <item><description>One or more of the attached shader objects has not been successfully compiled.</description></item>
		/// <item><description>Binding a generic attribute matrix caused some rows of the matrix to fall outside the allowed maximum of <see cref="VertexShaderStageCapabilities.MaxAttributes"/>​.</description></item>
		/// <item><description>Not enough contiguous vertex attribute slots could be found to bind attribute matrices.</description></item>
		/// <item><description>The program object contains objects to form a fragment shader but does not contain objects to form a vertex shader.</description></item>
		/// <item><description>The program object contains objects to form a geometry shader but does not contain objects to form a vertex shader.</description></item>
		/// <item><description>The program object contains objects to form a geometry shader and the input primitive type, output primitive type, or maximum output vertex count is not specified in any compiled geometry shader object.</description></item>
		/// <item><description>The program object contains objects to form a geometry shader and the input primitive type, output primitive type, or maximum output vertex count is specified differently in multiple geometry shader objects.</description></item>
		/// <item><description>The number of active outputs in the fragment shader is greater than the value of <see cref="GraphicsProgram.MaxDrawBuffers"/>​.</description></item>
		/// <item><description>The program has an active output assigned to a location greater than or equal to the value of <see cref="GraphicsProgram.MaxDualSourceDrawBuffers"/> ​and has an active output assigned an index greater than or equal to one.</description></item>
		/// <item><description>More than one varying out variable is bound to the same number and index.</description></item>
		/// <item><description>The explicit binding assigments do not leave enough space for the linker to automatically assign a location for a varying out array, which requires multiple contiguous locations.</description></item>
		/// <item><description>The count​ specified by glTransformFeedbackVaryings​ is non-zero, but the program object has no vertex or geometry shader.</description></item>
		/// <item><description>Any variable name specified to glTransformFeedbackVaryings​ in the varyings​ array is not declared as an output in the vertex shader (or the geometry shader, if active).</description></item>
		/// <item><description>Any two entries in the varyings​ array given glTransformFeedbackVaryings​ specify the same varying variable.</description></item>
		/// <item><description>The total number of components to capture in any transform feedback varying variable is greater than the constant <see cref="Context.MaxTransformFeedbackSeparateComponents"/>​ and the buffer mode is <see cref="TransformFeedbackMode.SeparateAttributes"/>​.</description></item>
		/// </list>
		///
		/// When a program object has been successfully linked, the program object can be made part of current state by drawing with it​. Whether or not the link operation was successful, the program object's information log will be overwritten. The information log can be retrieved through <see cref="InfoLog"/>.
		/// 
		/// <see cref="Link"/> will also install the generated executables as part of the current rendering state if the link operation was successful and the specified program object is already currently in use as a result of a previous drawing call. If the program object currently in use is relinked unsuccessfully, its link status will be set to <c>false</c>​ , but the executables and associated state will remain part of the current state until a subsequent drawing operation removes it from use. After it is removed from use, it cannot be made part of current state until it has been successfully relinked.
		/// 
		/// If program​ contains shader objects of type <see cref="VertexShader"/>​, and optionally of type <see cref="GeometryShader"/>​, but does not contain shader objects of type <see cref="FragmentShader"/>​, the vertex shader executable will be installed on the programmable vertex processor, the geometry shader executable, if present, will be installed on the programmable geometry processor, but no executable will be installed on the fragment processor. The results of rasterizing primitives with such a program will be undefined.
		/// 
		/// The program object's information log is updated and the program is generated at the time of the link operation. After the link operation, applications are free to modify attached shader objects, compile attached shader objects, detach shader objects, delete shader objects, and attach additional shader objects. None of these operations affects the information log or the program that is part of the program object.
		/// </remarks>
		/// <returns></returns>
		public virtual bool Link() {
			using (Context.Lock()) {
				foreach (ProgramStage stage in stagesByShaderStage.Values)
					stage.Unlink();

				GL.LinkProgram(Id);
				Context.CheckError();
				int result;
				GL.GetProgram(Id, GetProgramParameterName.LinkStatus, out result);

				attributes.Clear();

				if (result != 0) {
					int count, maxNameLength, length;
					StringBuilder name;

					// Gather the attributes
					GL.GetProgram(Id, GetProgramParameterName.ActiveAttributes, out count);
					GL.GetProgram(Id, GetProgramParameterName.ActiveAttributeMaxLength, out maxNameLength);
					name = new StringBuilder(maxNameLength);
					for (int index = 0; index < count; index++) {
						ActiveAttribType type;
						int size;

						name.Clear();
						GL.GetActiveAttrib(Id, index, maxNameLength, out length, out size, out type, name);
						attributes.Add(new ProgramAttribute(this, name.ToString(), index, size, type));
					}

					// Gather the uniforms
					GL.GetProgram(Id, GetProgramParameterName.ActiveUniforms, out count);
					GL.GetProgram(Id, GetProgramParameterName.ActiveUniformMaxLength, out maxNameLength);
					name = new StringBuilder(maxNameLength);
					for (int index = 0; index < count; index++) {
						int size;
						ActiveUniformType type;

						GL.GetActiveUniform(Id, index, maxNameLength, out length, out size, out type, name);
						Context.CheckError();

						string nameString = name.ToString();
						int location = GL.GetUniformLocation(Id, nameString);
						Context.CheckError();

						uniforms.Add(new ProgramUniform(this, nameString, index, location, type, size));
					}

					// Find slots for the textures.
					for (int index = 0, slot = 0; index < count; index++) {
						var uniform = Uniforms[index];
						if (uniform.IsTexture)
							uniform.Unit = TextureUnit.Texture0 + slot++;
					}

					// Have the stages gather data.
					//foreach (ProgramStage stage in stagesByShaderStage.Values)
						//stage.Link();
				}

				return result != 0;
			}
		}
Beispiel #18
0
 protected override double Get1d(SamplerParameterName pname)
 {
     float result; using (Context.Lock()) GL.GetSamplerParameter(Id, pname, out result); return(result);
 }
Beispiel #19
0
 int Get1i(ActiveSubroutineUniformParameter pname)
 {
     int value; using (Context.Lock()) GL.GetActiveSubroutineUniform(Program.Id, ShaderType, Index, pname, out value); return(value);
 }
Beispiel #20
0
 protected override void Set(SamplerParameterName pname, double value)
 {
     using (Context.Lock()) GL.SamplerParameter(Id, pname, checked ((float)value));
 }
Beispiel #21
0
		public void Clear() {
			using (Context.Lock())
				foreach (var item in set)
					GL.DetachShader(program.Id, item.Id);
			set.Clear();
		}
Beispiel #22
0
		internal ProgramBinding(Program program) {
			contextLock = Context.Lock();
			GL.UseProgram(program.Id);
			Context.CheckError();
		}
Beispiel #23
0
 static int AllocateId()
 {
     using (Context.Lock())
         return(GL.GenRenderbuffer());
 }
Beispiel #24
0
 internal int GetInt(ShaderParameter pname)
 {
     int result; using (Context.Lock()) GL.GetShader(Id, pname, out result); return(result);
 }
Beispiel #25
0
 static int AllocateId()
 {
     using (Context.Lock())
         return(GL.GenSampler());
 }
Beispiel #26
0
        /*
         * public readonly ModelAttributeChannel Channel;
         *
         * /// <summary>Get the buffer to bind this to.</summary>
         * public readonly GraphicsBuffer Buffer;
         *
         * /// <summary>Get the zero-based index of the <see cref="Channel"/> to bind to.</summary>
         * public readonly int Index;
         *
         * /// <summary>Get the name of the channel to bind to,</summary>
         * public readonly string Name;
         *
         * /// <summary>Get the offset in bytes from the start of the <see cref="Buffer"/> to the attribute of the first vertex.</summary>
         * public readonly int OffsetInBytes;
         *
         * /// <summary>Get the data format of the attribute. This must be a member of <see cref="VectorFormats"/>.</summary>
         * public readonly Format Format;
         *
         * /// <summary>Get the number of bytes between each attribute value, or 0 to use the size of the <see cref="Format"/>.</summary>
         * public readonly int Stride;*/

        static int AllocateId()
        {
            using (Context.Lock())
                return(GL.GenVertexArray());
        }
Beispiel #27
0
 protected override int Get1i(SamplerParameterName pname)
 {
     int result; using (Context.Lock()) GL.GetSamplerParameter(Id, pname, out result); return(result);
 }
Beispiel #28
0
		static int AllocateId() {
			using (Context.Lock())
				return GL.CreateProgram();
		}
Beispiel #29
0
 protected override void Set(SamplerParameterName pname, int value)
 {
     using (Context.Lock()) GL.SamplerParameter(Id, pname, value);
 }
Beispiel #30
0
 static int AllocateId(ShaderType shaderType)
 {
     using (Context.Lock())
         return(GL.CreateShader(shaderType));
 }