Пример #1
0
        public Shader(string vertexShaderSource, string fragmentShaderSource)
        {
            ContextManager.ActivateDefaultIfNoCurrent();

            m_uniformCache   = new Dictionary <string, int>();
            m_attributeCache = new Dictionary <string, int>();

            m_GLprogramID = GL.CreateProgram();

            if (!string.IsNullOrEmpty(vertexShaderSource))
            {
                CreateShader(ShaderType.VertexShader, vertexShaderSource, m_GLprogramID, out m_GLvertexShaderID);
            }
            if (!string.IsNullOrEmpty(fragmentShaderSource))
            {
                CreateShader(ShaderType.FragmentShader, fragmentShaderSource, m_GLprogramID, out m_GLfragmentShaderID);
            }

            GL.LinkProgram(m_GLprogramID);
            int success = 0;

            GL.GetProgram(m_GLprogramID, GetProgramParameterName.LinkStatus, out success);
            if (success <= 0)
            {
                throw new ShaderException("Failed to LINK shader");
            }
        }
Пример #2
0
        protected VertexBuffer(BufferUsageHint usageHint)
        {
            ContextManager.ActivateDefaultIfNoCurrent();

            GL.GenBuffers(1, out m_GLVBOID);

            m_usageHint = usageHint;
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="result">Allocated memory of the size of texture and specified PixelType</param>
        public void GetPixels(IntPtr result)
        {
            ContextManager.ActivateDefaultIfNoCurrent();
            Bind();

            GL.GetTexImage(TextureTarget.Texture2D, 0, m_pixelFormat, m_pixelType, result);

            Unbind();
        }
Пример #4
0
        public void GetPixels(IntPtr result, OpenTK.Graphics.OpenGL.PixelFormat pixelFormat, PixelType pixelType = PixelType.UnsignedByte)
        {
            ContextManager.ActivateDefaultIfNoCurrent();
            Bind();

            GL.GetTexImage(TextureTarget.Texture2D, 0, pixelFormat, pixelType, result);

            Unbind();
        }
Пример #5
0
        public void Update(RectangleInt area, IntPtr dataPtr, OpenTK.Graphics.OpenGL.PixelFormat pixelFormat, PixelType pixelType = PixelType.UnsignedByte)
        {
            ContextManager.ActivateDefaultIfNoCurrent();
            Bind();

            GL.TexSubImage2D(TextureTarget.Texture2D, 0, area.Position.X, area.Position.Y, area.Size.X, area.Size.Y, pixelFormat, pixelType, dataPtr);

            Unbind();
        }
Пример #6
0
        public void Update(RectangleInt area, IntPtr dataPtr)
        {
            ContextManager.ActivateDefaultIfNoCurrent();
            Bind();

            GL.TexSubImage2D(TextureTarget.Texture2D, 0, area.Position.X, area.Position.Y, area.Size.X, area.Size.Y, m_pixelFormat, m_pixelType, dataPtr);

            Unbind();
        }
Пример #7
0
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                if (disposing)
                {
                }

                ContextManager.ActivateDefaultIfNoCurrent();
                GL.DeleteTexture(m_GLTextureID);

                m_disposed = true;
            }
        }
Пример #8
0
        private void CreateFromPtr(Point2 size, IntPtr dataPtr, OpenTK.Graphics.OpenGL.PixelFormat inputPixelFormat, PixelInternalFormat internalPixelFormat, PixelType pixelType)
        {
            ContextManager.ActivateDefaultIfNoCurrent();

            GL.GenTextures(1, out m_GLTextureID);
            GL.BindTexture(TextureTarget.Texture2D, m_GLTextureID);

            GL.TexImage2D(TextureTarget.Texture2D, 0, internalPixelFormat, size.X, size.Y, 0, inputPixelFormat, pixelType, dataPtr);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);

            GL.BindTexture(TextureTarget.Texture2D, 0);

            ApplySize(size);

            m_pixelFormat         = inputPixelFormat;
            m_pixelType           = pixelType;
            m_pixelInternalFormat = internalPixelFormat;
        }
Пример #9
0
        public static void Unbind(bool pixelUnpackBuffer = true)
        {
            ContextManager.ActivateDefaultIfNoCurrent();

            GL.BindBuffer((pixelUnpackBuffer ? BufferTarget.PixelUnpackBuffer : BufferTarget.PixelPackBuffer), 0);
        }
Пример #10
0
        public void Bind()
        {
            ContextManager.ActivateDefaultIfNoCurrent();

            GL.BindBuffer(m_bufferTarget, m_GLPBOID);
        }