コード例 #1
0
        public PixelBufferGL3x(
            BufferTarget type,
            BufferHint usageHint,
            int sizeInBytes)
        {
            if (sizeInBytes <= 0)
            {
                throw new ArgumentOutOfRangeException("sizeInBytes", "sizeInBytes must be greater than zero.");
            }

            _name = new BufferNameGL3x();

            _sizeInBytes = sizeInBytes;
            _type        = type;
            _usageHint   = TypeConverterGL3x.To(usageHint);

            //
            // Allocating here with GL.BufferData, then writing with GL.BufferSubData
            // in CopyFromSystemMemory() should not have any serious overhead:
            //
            //   http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=267373#Post267373
            //
            // Alternately, we can delay GL.BufferData until the first
            // CopyFromSystemMemory() call.
            //
            Bind();
            GL.BufferData(_type, new IntPtr(sizeInBytes), new IntPtr(), _usageHint);

            GC.AddMemoryPressure(sizeInBytes);
        }
コード例 #2
0
        public override void Clear(ClearState clearState)
        {
            ApplyFramebuffer();

            ApplyScissorTest(clearState.ScissorTest);
            ApplyColorMask(clearState.ColorMask);
            ApplyDepthMask(clearState.DepthMask);
            // TODO: StencilMaskSeparate

            if (_clearColor != clearState.Color)
            {
                GL.ClearColor(clearState.Color);
                _clearColor = clearState.Color;
            }

            if (_clearDepth != clearState.Depth)
            {
                GL.ClearDepth((double)clearState.Depth);
                _clearDepth = clearState.Depth;
            }

            if (_clearStencil != clearState.Stencil)
            {
                GL.ClearStencil(clearState.Stencil);
                _clearStencil = clearState.Stencil;
            }

            GL.Clear(TypeConverterGL3x.To(clearState.Buffers));
        }
コード例 #3
0
        private static void ApplyStencil(StencilFace face, StencilTestFace currentTest, StencilTestFace test)
        {
            if ((currentTest.StencilFailOperation != test.StencilFailOperation) ||
                (currentTest.DepthFailStencilPassOperation != test.DepthFailStencilPassOperation) ||
                (currentTest.DepthPassStencilPassOperation != test.DepthPassStencilPassOperation))
            {
                GL.StencilOpSeparate(face,
                                     TypeConverterGL3x.To(test.StencilFailOperation),
                                     TypeConverterGL3x.To(test.DepthFailStencilPassOperation),
                                     TypeConverterGL3x.To(test.DepthPassStencilPassOperation));

                currentTest.StencilFailOperation          = test.StencilFailOperation;
                currentTest.DepthFailStencilPassOperation = test.DepthFailStencilPassOperation;
                currentTest.DepthPassStencilPassOperation = test.DepthPassStencilPassOperation;
            }

            if ((currentTest.Function != test.Function) ||
                (currentTest.ReferenceValue != test.ReferenceValue) ||
                (currentTest.Mask != test.Mask))
            {
                GL.StencilFuncSeparate(face,
                                       TypeConverterGL3x.To(test.Function),
                                       test.ReferenceValue,
                                       test.Mask);

                currentTest.Function       = test.Function;
                currentTest.ReferenceValue = test.ReferenceValue;
                currentTest.Mask           = test.Mask;
            }
        }
コード例 #4
0
        public override ReadPixelBuffer CopyToBuffer(
            ImageFormat format,
            ImageDatatype dataType,
            int rowAlignment)
        {
            if (format == ImageFormat.StencilIndex)
            {
                throw new ArgumentException("StencilIndex is not supported by CopyToBuffer.  Try DepthStencil instead.", "format");
            }

            VerifyRowAlignment(rowAlignment);

            ReadPixelBufferGL3x pixelBuffer = new ReadPixelBufferGL3x(PixelBufferHint.Stream,
                                                                      TextureUtility.RequiredSizeInBytes(_description.Width, _description.Height, format, dataType, rowAlignment));

            pixelBuffer.Bind();
            BindToLastTextureUnit();
            GL.PixelStore(PixelStoreParameter.PackAlignment, rowAlignment);
            GL.GetTexImage(_target, 0,
                           TypeConverterGL3x.To(format),
                           TypeConverterGL3x.To(dataType),
                           new IntPtr());

            return(pixelBuffer);
        }
コード例 #5
0
 private void ApplyRasterizationMode(RasterizationMode rasterizationMode)
 {
     if (_renderState.RasterizationMode != rasterizationMode)
     {
         GL.PolygonMode(MaterialFace.FrontAndBack, TypeConverterGL3x.To(rasterizationMode));
         _renderState.RasterizationMode = rasterizationMode;
     }
 }
コード例 #6
0
        public Texture2DGL3x(Texture2DDescription description, TextureTarget textureTarget)
        {
            if (description.Width <= 0)
            {
                throw new ArgumentOutOfRangeException("description.Width", "description.Width must be greater than zero.");
            }

            if (description.Height <= 0)
            {
                throw new ArgumentOutOfRangeException("description.Height", "description.Height must be greater than zero.");
            }

            if (description.GenerateMipmaps)
            {
                if (textureTarget == TextureTarget.TextureRectangle)
                {
                    throw new ArgumentException("description.GenerateMipmaps cannot be true for texture rectangles.", "description");
                }

                if (!TextureUtility.IsPowerOfTwo(Convert.ToUInt32(description.Width)))
                {
                    throw new ArgumentException("When description.GenerateMipmaps is true, the width must be a power of two.", "description");
                }

                if (!TextureUtility.IsPowerOfTwo(Convert.ToUInt32(description.Height)))
                {
                    throw new ArgumentException("When description.GenerateMipmaps is true, the height must be a power of two.", "description");
                }
            }

            _name            = new TextureNameGL3x();
            _target          = textureTarget;
            _description     = description;
            _lastTextureUnit = OpenTKTextureUnit.Texture0 + (Device.NumberOfTextureUnits - 1);

            //
            // TexImage2D is just used to allocate the texture so a PBO can't be bound.
            //
            WritePixelBufferGL3x.UnBind();
            BindToLastTextureUnit();
            GL.TexImage2D(_target, 0,
                          TypeConverterGL3x.To(description.TextureFormat),
                          description.Width,
                          description.Height,
                          0,
                          TypeConverterGL3x.TextureToPixelFormat(description.TextureFormat),
                          TypeConverterGL3x.TextureToPixelType(description.TextureFormat),
                          new IntPtr());

            //
            // Default sampler, compatiable when attaching a non-mimapped
            // texture to a frame buffer object.
            //
            ApplySampler(Device.TextureSamplers.LinearClamp);

            GC.AddMemoryPressure(description.ApproximateSizeInBytes);
        }
コード例 #7
0
        public override void CopyFromBuffer(
            WritePixelBuffer pixelBuffer,
            int xOffset,
            int yOffset,
            int width,
            int height,
            ImageFormat format,
            ImageDatatype dataType,
            int rowAlignment)
        {
            if (pixelBuffer.SizeInBytes < TextureUtility.RequiredSizeInBytes(
                    width, height, format, dataType, rowAlignment))
            {
                throw new ArgumentException("Pixel buffer is not big enough for provided width, height, format, and datatype.");
            }

            if (xOffset < 0)
            {
                throw new ArgumentOutOfRangeException("xOffset", "xOffset must be greater than or equal to zero.");
            }

            if (yOffset < 0)
            {
                throw new ArgumentOutOfRangeException("yOffset", "yOffset must be greater than or equal to zero.");
            }

            if (xOffset + width > _description.Width)
            {
                throw new ArgumentOutOfRangeException("xOffset + width must be less than or equal to Description.Width");
            }

            if (yOffset + height > _description.Height)
            {
                throw new ArgumentOutOfRangeException("yOffset + height must be less than or equal to Description.Height");
            }

            VerifyRowAlignment(rowAlignment);

            WritePixelBufferGL3x bufferObjectGL = (WritePixelBufferGL3x)pixelBuffer;

            bufferObjectGL.Bind();
            BindToLastTextureUnit();
            GL.PixelStore(PixelStoreParameter.UnpackAlignment, rowAlignment);
            GL.TexSubImage2D(_target, 0,
                             xOffset,
                             yOffset,
                             width,
                             height,
                             TypeConverterGL3x.To(format),
                             TypeConverterGL3x.To(dataType),
                             new IntPtr());

            GenerateMipmaps();
        }
コード例 #8
0
        private void ApplySampler(TextureSampler sampler)
        {
            TextureMinFilter minFilter = TypeConverterGL3x.To(sampler.MinificationFilter);
            TextureMagFilter magFilter = TypeConverterGL3x.To(sampler.MagnificationFilter);
            TextureWrapMode  wrapS     = TypeConverterGL3x.To(sampler.WrapS);
            TextureWrapMode  wrapT     = TypeConverterGL3x.To(sampler.WrapT);

            GL.TexParameter(_target, TextureParameterName.TextureMinFilter, (int)minFilter);
            GL.TexParameter(_target, TextureParameterName.TextureMagFilter, (int)magFilter);
            GL.TexParameter(_target, TextureParameterName.TextureWrapS, (int)wrapS);
            GL.TexParameter(_target, TextureParameterName.TextureWrapT, (int)wrapT);
        }
コード例 #9
0
        private static void ForceApplyRenderStateStencil(StencilFace face, StencilTestFace test)
        {
            GL.StencilOpSeparate(face,
                                 TypeConverterGL3x.To(test.StencilFailOperation),
                                 TypeConverterGL3x.To(test.DepthFailStencilPassOperation),
                                 TypeConverterGL3x.To(test.DepthPassStencilPassOperation));

            GL.StencilFuncSeparate(face,
                                   TypeConverterGL3x.To(test.Function),
                                   test.ReferenceValue,
                                   test.Mask);
        }
コード例 #10
0
        private void Attach(int index)
        {
            GL.EnableVertexAttribArray(index);

            VertexBufferAttribute attribute      = _attributes[index].VertexBufferAttribute;
            VertexBufferGL3x      bufferObjectGL = (VertexBufferGL3x)attribute.VertexBuffer;

            bufferObjectGL.Bind();
            GL.VertexAttribPointer(index,
                                   attribute.NumberOfComponents,
                                   TypeConverterGL3x.To(attribute.ComponentDatatype),
                                   attribute.Normalize,
                                   attribute.StrideInBytes,
                                   attribute.OffsetInBytes);
        }
コード例 #11
0
        private void ApplyDepthTest(DepthTest depthTest)
        {
            if (_renderState.DepthTest.Enabled != depthTest.Enabled)
            {
                Enable(EnableCap.DepthTest, depthTest.Enabled);
                _renderState.DepthTest.Enabled = depthTest.Enabled;
            }

            if (depthTest.Enabled)
            {
                if (_renderState.DepthTest.Function != depthTest.Function)
                {
                    GL.DepthFunc(TypeConverterGL3x.To(depthTest.Function));
                    _renderState.DepthTest.Function = depthTest.Function;
                }
            }
        }
コード例 #12
0
        private void ApplyBlending(Blending blending)
        {
            if (_renderState.Blending.Enabled != blending.Enabled)
            {
                Enable(EnableCap.Blend, blending.Enabled);
                _renderState.Blending.Enabled = blending.Enabled;
            }

            if (blending.Enabled)
            {
                if ((_renderState.Blending.SourceRGBFactor != blending.SourceRGBFactor) ||
                    (_renderState.Blending.DestinationRGBFactor != blending.DestinationRGBFactor) ||
                    (_renderState.Blending.SourceAlphaFactor != blending.SourceAlphaFactor) ||
                    (_renderState.Blending.DestinationAlphaFactor != blending.DestinationAlphaFactor))
                {
                    GL.BlendFuncSeparate(
                        TypeConverterGL3x.To(blending.SourceRGBFactor),
                        TypeConverterGL3x.To(blending.DestinationRGBFactor),
                        TypeConverterGL3x.To(blending.SourceAlphaFactor),
                        TypeConverterGL3x.To(blending.DestinationAlphaFactor));

                    _renderState.Blending.SourceRGBFactor        = blending.SourceRGBFactor;
                    _renderState.Blending.DestinationRGBFactor   = blending.DestinationRGBFactor;
                    _renderState.Blending.SourceAlphaFactor      = blending.SourceAlphaFactor;
                    _renderState.Blending.DestinationAlphaFactor = blending.DestinationAlphaFactor;
                }

                if ((_renderState.Blending.RGBEquation != blending.RGBEquation) ||
                    (_renderState.Blending.AlphaEquation != blending.AlphaEquation))
                {
                    GL.BlendEquationSeparate(
                        TypeConverterGL3x.To(blending.RGBEquation),
                        TypeConverterGL3x.To(blending.AlphaEquation));

                    _renderState.Blending.RGBEquation   = blending.RGBEquation;
                    _renderState.Blending.AlphaEquation = blending.AlphaEquation;
                }

                if (_renderState.Blending.Color != blending.Color)
                {
                    GL.BlendColor(blending.Color);
                    _renderState.Blending.Color = blending.Color;
                }
            }
        }
コード例 #13
0
        private static ShaderVertexAttributeCollection FindVertexAttributes(ShaderProgramNameGL3x program)
        {
            int programHandle = program.Value;

            int numberOfAttributes;

            GL.GetProgram(programHandle, ProgramParameter.ActiveAttributes, out numberOfAttributes);

            int attributeNameMaxLength;

            GL.GetProgram(programHandle, ProgramParameter.ActiveAttributeMaxLength, out attributeNameMaxLength);

            ShaderVertexAttributeCollection vertexAttributes = new ShaderVertexAttributeCollection();

            for (int i = 0; i < numberOfAttributes; ++i)
            {
                int attributeNameLength;
                int attributeLength;
                ActiveAttribType attributeType;
                StringBuilder    attributeNameBuilder = new StringBuilder(attributeNameMaxLength);

                GL.GetActiveAttrib(programHandle, i, attributeNameMaxLength,
                                   out attributeNameLength, out attributeLength, out attributeType, attributeNameBuilder);

                string attributeName = attributeNameBuilder.ToString();

                if (attributeName.StartsWith("gl_", StringComparison.InvariantCulture))
                {
                    //
                    // Names starting with the reserved prefix of "gl_" have a location of -1.
                    //
                    continue;
                }

                int attributeLocation = GL.GetAttribLocation(programHandle, attributeName);

                vertexAttributes.Add(new ShaderVertexAttribute(
                                         attributeName, attributeLocation, TypeConverterGL3x.To(attributeType), attributeLength));
            }

            return(vertexAttributes);
        }
コード例 #14
0
        public override void Draw(PrimitiveType primitiveType, DrawState drawState, SceneState sceneState)
        {
            VerifyDraw(drawState, sceneState);
            ApplyBeforeDraw(drawState, sceneState);

            VertexArrayGL3x vertexArray = (VertexArrayGL3x)drawState.VertexArray;
            IndexBufferGL3x indexBuffer = vertexArray.IndexBuffer as IndexBufferGL3x;

            if (indexBuffer != null)
            {
                GL.DrawRangeElements(TypeConverterGL3x.To(primitiveType),
                                     0, vertexArray.MaximumArrayIndex(), indexBuffer.Count,
                                     TypeConverterGL3x.To(indexBuffer.Datatype), new IntPtr());
            }
            else
            {
                GL.DrawArrays(TypeConverterGL3x.To(primitiveType), 0,
                              vertexArray.MaximumArrayIndex() + 1);
            }
        }
コード例 #15
0
        private static void ForceApplyRenderState(RenderState renderState)
        {
            Enable(EnableCap.PrimitiveRestart, renderState.PrimitiveRestart.Enabled);
            GL.PrimitiveRestartIndex(renderState.PrimitiveRestart.Index);

            Enable(EnableCap.CullFace, renderState.FacetCulling.Enabled);
            GL.CullFace(TypeConverterGL3x.To(renderState.FacetCulling.Face));
            GL.FrontFace(TypeConverterGL3x.To(renderState.FacetCulling.FrontFaceWindingOrder));

            Enable(EnableCap.ProgramPointSize, renderState.ProgramPointSize == ProgramPointSize.Enabled);
            GL.PolygonMode(MaterialFace.FrontAndBack, TypeConverterGL3x.To(renderState.RasterizationMode));

            Enable(EnableCap.ScissorTest, renderState.ScissorTest.Enabled);
            Rectangle rectangle = renderState.ScissorTest.Rectangle;

            GL.Scissor(rectangle.Left, rectangle.Bottom, rectangle.Width, rectangle.Height);

            Enable(EnableCap.StencilTest, renderState.StencilTest.Enabled);
            ForceApplyRenderStateStencil(StencilFace.Front, renderState.StencilTest.FrontFace);
            ForceApplyRenderStateStencil(StencilFace.Back, renderState.StencilTest.BackFace);

            Enable(EnableCap.DepthTest, renderState.DepthTest.Enabled);
            GL.DepthFunc(TypeConverterGL3x.To(renderState.DepthTest.Function));

            GL.DepthRange(renderState.DepthRange.Near, renderState.DepthRange.Far);

            Enable(EnableCap.Blend, renderState.Blending.Enabled);
            GL.BlendFuncSeparate(
                TypeConverterGL3x.To(renderState.Blending.SourceRGBFactor),
                TypeConverterGL3x.To(renderState.Blending.DestinationRGBFactor),
                TypeConverterGL3x.To(renderState.Blending.SourceAlphaFactor),
                TypeConverterGL3x.To(renderState.Blending.DestinationAlphaFactor));
            GL.BlendEquationSeparate(
                TypeConverterGL3x.To(renderState.Blending.RGBEquation),
                TypeConverterGL3x.To(renderState.Blending.AlphaEquation));
            GL.BlendColor(renderState.Blending.Color);

            GL.DepthMask(renderState.DepthMask);
            GL.ColorMask(renderState.ColorMask.Red, renderState.ColorMask.Green,
                         renderState.ColorMask.Blue, renderState.ColorMask.Alpha);
        }
コード例 #16
0
        private void ApplyFacetCulling(FacetCulling facetCulling)
        {
            if (_renderState.FacetCulling.Enabled != facetCulling.Enabled)
            {
                Enable(EnableCap.CullFace, facetCulling.Enabled);
                _renderState.FacetCulling.Enabled = facetCulling.Enabled;
            }

            if (facetCulling.Enabled)
            {
                if (_renderState.FacetCulling.Face != facetCulling.Face)
                {
                    GL.CullFace(TypeConverterGL3x.To(facetCulling.Face));
                    _renderState.FacetCulling.Face = facetCulling.Face;
                }

                if (_renderState.FacetCulling.FrontFaceWindingOrder != facetCulling.FrontFaceWindingOrder)
                {
                    GL.FrontFace(TypeConverterGL3x.To(facetCulling.FrontFaceWindingOrder));
                    _renderState.FacetCulling.FrontFaceWindingOrder = facetCulling.FrontFaceWindingOrder;
                }
            }
        }
コード例 #17
0
        public TextureSamplerGL3x(
            TextureMinificationFilter minificationFilter,
            TextureMagnificationFilter magnificationFilter,
            TextureWrap wrapS,
            TextureWrap wrapT,
            float maximumAnistropy)
            : base(
                minificationFilter,
                magnificationFilter,
                wrapS,
                wrapT,
                maximumAnistropy)
        {
            _name = new SamplerNameGL3x();

            int glMinificationFilter  = (int)TypeConverterGL3x.To(minificationFilter);
            int glMagnificationFilter = (int)TypeConverterGL3x.To(magnificationFilter);
            int glWrapS = (int)TypeConverterGL3x.To(wrapS);
            int glWrapT = (int)TypeConverterGL3x.To(wrapT);

            GL.SamplerParameterI(_name.Value, (ArbSamplerObjects)All.TextureMinFilter, ref glMinificationFilter);
            GL.SamplerParameterI(_name.Value, (ArbSamplerObjects)All.TextureMagFilter, ref glMagnificationFilter);
            GL.SamplerParameterI(_name.Value, (ArbSamplerObjects)All.TextureWrapS, ref glWrapS);
            GL.SamplerParameterI(_name.Value, (ArbSamplerObjects)All.TextureWrapT, ref glWrapT);

            if (Device.Extensions.AnisotropicFiltering)
            {
                GL.SamplerParameter(_name.Value, (ArbSamplerObjects)All.TextureMaxAnisotropyExt, maximumAnistropy);
            }
            else
            {
                if (maximumAnistropy != 1)
                {
                    throw new InsufficientVideoCardException("Anisotropic filtering is not supported.  The extension GL_EXT_texture_filter_anisotropic was not found.");
                }
            }
        }
コード例 #18
0
        private static UniformBlockCollection FindUniformBlocks(ShaderProgramNameGL3x program)
        {
            int programHandle = program.Value;

            int numberOfUniformBlocks;

            GL.GetProgram(programHandle, ProgramParameter.ActiveUniformBlocks, out numberOfUniformBlocks);

            UniformBlockCollection uniformBlocks = new UniformBlockCollection();

            for (int i = 0; i < numberOfUniformBlocks; ++i)
            {
                string uniformBlockName = GL.GetActiveUniformBlockName(programHandle, i);

                int uniformBlockSizeInBytes;
                GL.GetActiveUniformBlock(programHandle, i, ActiveUniformBlockParameter.UniformBlockDataSize, out uniformBlockSizeInBytes);

                int numberOfUniformsInBlock;
                GL.GetActiveUniformBlock(programHandle, i, ActiveUniformBlockParameter.UniformBlockActiveUniforms, out numberOfUniformsInBlock);

                int[] uniformIndicesInBlock = new int[numberOfUniformsInBlock];
                GL.GetActiveUniformBlock(programHandle, i, ActiveUniformBlockParameter.UniformBlockActiveUniformIndices, uniformIndicesInBlock);

                //
                // Query uniforms in this named uniform block
                //
                int[] uniformTypes                = new int[numberOfUniformsInBlock];
                int[] uniformOffsetsInBytes       = new int[numberOfUniformsInBlock];
                int[] uniformLengths              = new int[numberOfUniformsInBlock];
                int[] uniformArrayStridesInBytes  = new int[numberOfUniformsInBlock];
                int[] uniformmatrixStrideInBytess = new int[numberOfUniformsInBlock];
                int[] uniformRowMajors            = new int[numberOfUniformsInBlock];
                GL.GetActiveUniforms(programHandle, numberOfUniformsInBlock, uniformIndicesInBlock, ActiveUniformParameter.UniformType, uniformTypes);
                GL.GetActiveUniforms(programHandle, numberOfUniformsInBlock, uniformIndicesInBlock, ActiveUniformParameter.UniformOffset, uniformOffsetsInBytes);
                GL.GetActiveUniforms(programHandle, numberOfUniformsInBlock, uniformIndicesInBlock, ActiveUniformParameter.UniformSize, uniformLengths);
                GL.GetActiveUniforms(programHandle, numberOfUniformsInBlock, uniformIndicesInBlock, ActiveUniformParameter.UniformArrayStride, uniformArrayStridesInBytes);
                GL.GetActiveUniforms(programHandle, numberOfUniformsInBlock, uniformIndicesInBlock, ActiveUniformParameter.UniformMatrixStride, uniformmatrixStrideInBytess);
                GL.GetActiveUniforms(programHandle, numberOfUniformsInBlock, uniformIndicesInBlock, ActiveUniformParameter.UniformIsRowMajor, uniformRowMajors);

                UniformBlock uniformBlock = new UniformBlockGL3x(uniformBlockName, uniformBlockSizeInBytes, i);

                for (int j = 0; j < numberOfUniformsInBlock; ++j)
                {
                    string uniformName = GL.GetActiveUniformName(programHandle, uniformIndicesInBlock[j]);
                    uniformName = CorrectUniformName(uniformName);

                    UniformType uniformType = TypeConverterGL3x.To((ActiveUniformType)uniformTypes[j]);

                    uniformBlock.Members.Add(CreateUniformBlockMember(uniformName,
                                                                      uniformType, uniformOffsetsInBytes[j], uniformLengths[j], uniformArrayStridesInBytes[j],
                                                                      uniformmatrixStrideInBytess[j], uniformRowMajors[j]));
                }

                uniformBlocks.Add(uniformBlock);

                //
                // Create a one to one mapping between uniform blocks and uniform buffer objects.
                //
                GL.UniformBlockBinding(programHandle, i, i);
            }

            return(uniformBlocks);
        }
コード例 #19
0
        private Uniform CreateUniform(
            string name,
            int location,
            ActiveUniformType type)
        {
            switch (type)
            {
            case ActiveUniformType.Float:
                return(new UniformFloatGL3x(name, location, this));

            case ActiveUniformType.FloatVec2:
                return(new UniformFloatVector2GL3x(name, location, this));

            case ActiveUniformType.FloatVec3:
                return(new UniformFloatVector3GL3x(name, location, this));

            case ActiveUniformType.FloatVec4:
                return(new UniformFloatVector4GL3x(name, location, this));

            case ActiveUniformType.Int:
                return(new UniformIntGL3x(name, location, UniformType.Int, this));

            case ActiveUniformType.IntVec2:
                return(new UniformIntVector2GL3x(name, location, this));

            case ActiveUniformType.IntVec3:
                return(new UniformIntVector3GL3x(name, location, this));

            case ActiveUniformType.IntVec4:
                return(new UniformIntVector4GL3x(name, location, this));

            case ActiveUniformType.Bool:
                return(new UniformBoolGL3x(name, location, this));

            case ActiveUniformType.BoolVec2:
                return(new UniformBoolVector2GL3x(name, location, this));

            case ActiveUniformType.BoolVec3:
                return(new UniformBoolVector3GL3x(name, location, this));

            case ActiveUniformType.BoolVec4:
                return(new UniformBoolVector4GL3x(name, location, this));

            case ActiveUniformType.FloatMat2:
                return(new UniformFloatMatrix22GL3x(name, location, this));

            case ActiveUniformType.FloatMat3:
                return(new UniformFloatMatrix33GL3x(name, location, this));

            case ActiveUniformType.FloatMat4:
                return(new UniformFloatMatrix44GL3x(name, location, this));

            case ActiveUniformType.FloatMat2x3:
                return(new UniformFloatMatrix23GL3x(name, location, this));

            case ActiveUniformType.FloatMat2x4:
                return(new UniformFloatMatrix24GL3x(name, location, this));

            case ActiveUniformType.FloatMat3x2:
                return(new UniformFloatMatrix32GL3x(name, location, this));

            case ActiveUniformType.FloatMat3x4:
                return(new UniformFloatMatrix34GL3x(name, location, this));

            case ActiveUniformType.FloatMat4x2:
                return(new UniformFloatMatrix42GL3x(name, location, this));

            case ActiveUniformType.FloatMat4x3:
                return(new UniformFloatMatrix43GL3x(name, location, this));

            case ActiveUniformType.Sampler1D:
            case ActiveUniformType.Sampler2D:
            case ActiveUniformType.Sampler2DRect:
            case ActiveUniformType.Sampler2DRectShadow:
            case ActiveUniformType.Sampler3D:
            case ActiveUniformType.SamplerCube:
            case ActiveUniformType.Sampler1DShadow:
            case ActiveUniformType.Sampler2DShadow:
            case ActiveUniformType.Sampler1DArray:
            case ActiveUniformType.Sampler2DArray:
            case ActiveUniformType.Sampler1DArrayShadow:
            case ActiveUniformType.Sampler2DArrayShadow:
            case ActiveUniformType.SamplerCubeShadow:
            case ActiveUniformType.IntSampler1D:
            case ActiveUniformType.IntSampler2D:
            case ActiveUniformType.IntSampler2DRect:
            case ActiveUniformType.IntSampler3D:
            case ActiveUniformType.IntSamplerCube:
            case ActiveUniformType.IntSampler1DArray:
            case ActiveUniformType.IntSampler2DArray:
            case ActiveUniformType.UnsignedIntSampler1D:
            case ActiveUniformType.UnsignedIntSampler2D:
            case ActiveUniformType.UnsignedIntSampler2DRect:
            case ActiveUniformType.UnsignedIntSampler3D:
            case ActiveUniformType.UnsignedIntSamplerCube:
            case ActiveUniformType.UnsignedIntSampler1DArray:
            case ActiveUniformType.UnsignedIntSampler2DArray:
                return(new UniformIntGL3x(name, location, TypeConverterGL3x.To(type), this));
            }

            //
            // A new Uniform derived class needs to be added to support this uniform type.
            //
            throw new NotSupportedException("An implementation for uniform type " + type.ToString() + " does not exist.");
        }