public shader(string vertexshader, string fragmentshader, vertices vertices = null) { this.vertices = vertices; vertexShader = GL.CreateShader(ShaderType.VertexShader); GL.ShaderSource(vertexShader, vertexshader); GL.CompileShader(vertexShader); vertexShader.CheckShaderLog(); fragmentShader = GL.CreateShader(ShaderType.FragmentShader); GL.ShaderSource(fragmentShader, fragmentshader); GL.CompileShader(fragmentShader); fragmentShader.CheckShaderLog(); shaderProgram = GL.CreateProgram(); GL.AttachShader(shaderProgram, vertexShader); GL.AttachShader(shaderProgram, fragmentShader); GL.LinkProgram(shaderProgram); shaderProgram.GetProgramInfoLog(); /* GL.GetProgramiv(ProgramID, GL_LINK_STATUS, &Result); * // GL.(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength); * if (InfoLogLength > 0) * { * std::vector<char> ProgramErrorMessage(InfoLogLength+1); * glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]); * printf("%s\n", &ProgramErrorMessage[0]); * } */ int outcolor = GL.GetFragDataLocation(shaderProgram, "outColor"); // Debug.Assert(outcolor == 0); // int outcolor = GL.GetFragDataLocation(shaderProgram, "outColor"); // GL.GenVertexArrays(1, out this.vao); // GL.BindVertexArray(vertices.vao); // GL.UseProgram(this.shaderProgram); // GL.BindBuffer(BufferTarget.ArrayBuffer, (int)vertices); this.pos1 = GL.GetAttribLocation(shaderProgram, "position"); this.pos2 = GL.GetAttribLocation(shaderProgram, "texcoord"); // GL.BindVertexArray(vao); // GL.UseProgram(0); }
public void Bind(vertices vertices) { GL.BindVertexArray(vertices.vao); GL.BindBuffer(BufferTarget.ArrayBuffer, (int)vertices); if (pos1 != -1) { GL.VertexAttribPointer(pos1, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 0); GL.EnableVertexAttribArray(pos1); } if (pos2 != -1) { GL.VertexAttribPointer(pos2, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 2 * sizeof(float)); GL.EnableVertexAttribArray(pos2); } GL.UseProgram((int)this); }
void IRenderer.Present(IVideoFrame renderedframe, rectangle dstrec, IntPtr ctl) { try { if (!this.stopevent.WaitOne(0, false)) { if (renderedframe == null) { // this.Xwt.SwapBuffers(this.window); } else { if (presentshader == null) { this.vertices3 = new vertices <vertex>(_vertices3); this.presentshader = new shader(shadervertex, shaderfragment, vertices3); // presentshader.Bind(this.vertices3); this.vertices3.define("position", "position"); this.vertices3.define("texcoord", "texcoord"); GL.UseProgram(this.presentshader); var pos = GL.GetUniformLocation(this.presentshader, "tex"); GL.Uniform1(pos, 0); } vertices3.Apply(this.presentshader); var frame = (RenderFrame)renderedframe; GL.Viewport(dstrec.x, dstrec.y, dstrec.width, dstrec.height);// new Rectangle(this.window.Location,this.window.ClientSize)); GL.ClearColor(1, 1, 0, 1); GL.Clear(ClearBufferMask.ColorBufferBit); // We're not using stencil buffer so why bother with clearing? GL.Disable(EnableCap.DepthTest); GL.Disable(EnableCap.StencilTest); GL.Disable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.One, BlendingFactor.OneMinusSrcAlpha); GL.BindTexture(TextureTarget.Texture2D, frame.Textures[0]); // GL.DrawElements(BeginMode.Triangles,6,DrawElementsType.UnsignedInt,0) GL.DrawArrays(PrimitiveType.Triangles, 0, 6); GL.DisableVertexAttribArray(0); GL.Disable(EnableCap.Blend); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindTexture(TextureTarget.Texture2D, 0); GL.UseProgram(0); GL.BindVertexArray(0); // this.Xwt.SwapBuffers(this.window); // GL.Flush(); } } } catch (Exception e) { // Log.LogException(e); } finally { } }
internal OpenTKRenderer(FrameFactory owner, IXwtRender xwtrender, Xwt.Canvas window, IRenderOwner renderer, size videosize) { // OpenTKRenderer.usecnt = 1; this.owner = owner; this.Xwt = xwtrender; this.videosize = videosize; this.window = window; this.renderer = renderer; this.viewsize = window.Size; window.BoundsChanged += viewsizechanged; this.actionthread = new Thread(run) { Name = "opentk" }; this.actionthread.Start(); var _this = this; this.Xwt.CreateForWidgetContext(this, this.renderer, window); // Invoke(() => // { this.Lock(false); try { try { // GL.GetInternalformat(TextureTarget.Texture2D, SizedInternalFormat.Rgba8, InternalFormatParameter..TEXTUREIMAGEFORMAT, 1, &preferred_format). this.vertices1 = new vertices(_vertices); this.vertices2 = new vertices(_vertices2); /* GL.GenBuffers(1, out buf_vertices2); // Generate 1 buffer * GL.BindBuffer(BufferTarget.ArrayBuffer, buf_vertices2); * GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 0); * GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 2 * sizeof(float)); * GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * vertices2.Length, vertices2, BufferUsageHint.StaticDraw); * GL.EnableVertexAttribArray(0); * GL.EnableVertexAttribArray(1); * * GL.GenBuffers(1, out buf_vertices3); // Generate 1 buffer * GL.BindBuffer(BufferTarget.ArrayBuffer, buf_vertices3); * GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 0); * GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 2 * sizeof(float)); * GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * vertices3.Length, vertices3, BufferUsageHint.StaticDraw); * GL.EnableVertexAttribArray(0); * GL.EnableVertexAttribArray(1);*/ // GL.BindBuffer(BufferTarget.ArrayBuffer, 0); /* this.presentshader = new shader(shadervertex, shaderfragment, vertices1); * GL.UseProgram(this.presentshader); * var pos = GL.GetUniformLocation(this.presentshader, "tex"); * GL.Uniform1(pos, 0); */ /* this.combineshader = new shader(combineshadervertex, combineshaderfragment, vertices1); * * GL.UseProgram(combineshader); * var pos = GL.GetUniformLocation(this.combineshader, "tex"); * GL.Uniform1(pos, 0); * pos = GL.GetUniformLocation(this.combineshader, "vpHeight"); * GL.Uniform1(pos, (float)videosize.height); * * this.deinterlaceblendshader = new shader(combineshadervertex, blendshaderfragment, vertices1); * GL.UseProgram(deinterlaceblendshader); * pos = GL.GetUniformLocation(this.deinterlaceblendshader, "vpHeight"); * GL.Uniform1(pos, (float)videosize.height); * * this.deinterlacesplitshader = new shader(combineshadervertex, splitshaderfragment, vertices1); * * GL.UseProgram(deinterlacesplitshader); * pos = GL.GetUniformLocation(this.deinterlacesplitshader, "vpHeight"); * GL.Uniform1(pos, (float)videosize.height);*/ } catch (Exception e) { // Log.LogException(e); Dispose(true); GC.SuppressFinalize(this); throw; } } finally { Unlock(false); } // }); }