private static void ConfigureGraphicsContext(Application application, Surface surface) { GraphicsContext graphicsContext = new GLGraphicsContext(GraphicsBackend.WebGL2); graphicsContext.CreateDevice(); SwapChainDescription swapChainDescription = new SwapChainDescription() { SurfaceInfo = surface.SurfaceInfo, Width = surface.Width, Height = surface.Height, ColorTargetFormat = PixelFormat.R8G8B8A8_UNorm, ColorTargetFlags = TextureFlags.RenderTarget | TextureFlags.ShaderResource, DepthStencilTargetFormat = PixelFormat.D24_UNorm_S8_UInt, DepthStencilTargetFlags = TextureFlags.DepthStencil, SampleCount = TextureSampleCount.None, IsWindowed = true, RefreshRate = 60 }; var swapChain = graphicsContext.CreateSwapChain(swapChainDescription); swapChain.VerticalSync = true; var graphicsPresenter = application.Container.Resolve <GraphicsPresenter>(); var firstDisplay = new Display(surface, swapChain); graphicsPresenter.AddDisplay("DefaultDisplay", firstDisplay); application.Container.RegisterInstance(graphicsContext); }
private GLFrameBuffer(GLGraphicsContext context) { this.context = context; OGL.GenFramebuffers(1, out fboId); context.CheckForErrorsIfDebugging(); }
protected override void OnLoad(EventArgs e) { base.OnLoad (e); String version = GL.GetString(StringName.Version); Console.WriteLine("GL version: " + version); context = GLGraphics.NewContext(Context, true); program = context.NewProgramFromFiles("Render.vert", "Render.frag"); texture0 = context.NewTexture(TextureMinFilter.Nearest, TextureMagFilter.Nearest, TextureWrapMode.Clamp, TextureWrapMode.Clamp); texture0.UploadImage(sourceImage); sourceImage.Dispose(); texture1 = context.NewTexture(TextureMinFilter.Nearest, TextureMagFilter.Nearest, TextureWrapMode.Clamp, TextureWrapMode.Clamp); texture1.UploadImage(new byte[4 * 4 * 4], 4, 4, PixelInternalFormat.Four, PixelFormat.Rgba, PixelType.UnsignedByte); CreateAndFillBuffers(); paramSpec = ImmutableList<Tuple<String, Object>>.List(new Tuple<String, Object>[] { Tuple.Create<String, Object>("a_position", positions), Tuple.Create<String, Object>("a_texPos", textureCoords), Tuple.Create<String, Object>("u_texture0", texture0), Tuple.Create<String, Object>("u_texture1", texture1)}); }
internal GLFrameBuffer(GLRenderBuffer colorBuffer, GLRenderBuffer depthBuffer, FramebufferTarget fbTarget, bool disposeRenderBuffers, GLGraphicsContext context) : this(context) { this.disposeRenderBuffers = disposeRenderBuffers; this.colorBuffer = colorBuffer; this.depthBuffer = depthBuffer; this.fbTarget = fbTarget; OGL.BindFramebuffer(fbTarget, fboId); OGL.FramebufferRenderbuffer(fbTarget, FramebufferAttachment.ColorAttachment0, RenderbufferTarget.Renderbuffer, colorBuffer.Id); OGL.FramebufferRenderbuffer(fbTarget, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, depthBuffer.Id); FramebufferErrorCode err = OGL.CheckFramebufferStatus(fbTarget); switch(err) { case FramebufferErrorCode.FramebufferComplete: break; default: this.Dispose(); throw new Exception(String.Format("Invalid frame buffer status: {0}", err)); } OGL.BindFramebuffer(fbTarget, 0); context.CheckForErrorsIfDebugging(); }
internal GLProgram(GLGraphicsContext context, String vertexShader, String fragmentShader) { this.context = context; this.vertexShader = new GLVertexShader(vertexShader); this.fragmentShader = new GLFragmentShader(fragmentShader); programId = OGL.CreateProgram(); OGL.AttachShader(programId, this.vertexShader.Id); OGL.AttachShader(programId, this.fragmentShader.Id); Link(); }
public TextRenderer(GLGraphicsContext context, int height, int width, String text) { this.text = text; texture = context.NewEmptyTexture(OpenTK.Graphics.OpenGL.TextureMinFilter.Linear, OpenTK.Graphics.OpenGL.TextureMagFilter.Linear, OpenTK.Graphics.OpenGL.TextureWrapMode.ClampToBorder, OpenTK.Graphics.OpenGL.TextureWrapMode.ClampToBorder, width, height, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, OpenTK.Graphics.OpenGL.PixelType.UnsignedByte); texRenderer = new TextureRenderer(context, texture); Resize (width, height); }
internal GLRenderBuffer(int width, int height, RenderbufferStorage storage, GLGraphicsContext context) { this.width = width; this.height = height; OGL.GenRenderbuffers(1, out renderBufferId); context.CheckForErrorsIfDebugging(); OGL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, renderBufferId); OGL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, storage, width, height); OGL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0); context.CheckForErrorsIfDebugging(); }
public TextureRenderer(GLGraphicsContext context, GLTexture texture) { this.context = context; texture = context.NewTexture(OpenTK.Graphics.OpenGL.TextureMinFilter.Nearest, OpenTK.Graphics.OpenGL.TextureMagFilter.Nearest, OpenTK.Graphics.OpenGL.TextureWrapMode.Clamp, OpenTK.Graphics.OpenGL.TextureWrapMode.Clamp); vertices = context.NewVertexBuffer<Vector3>(OpenTK.Graphics.OpenGL.VertexAttribPointerType.Float, 3); vertices.UploadVertices(new Vector3[] { new Vector3(-1, -1, 0), new Vector3(1, -1, 0), new Vector3(-1, 1, 0), new Vector3(1, 1, 0)}); texCoords = context.NewVertexBuffer<Vector2>(OpenTK.Graphics.OpenGL.VertexAttribPointerType.Float, 2); texCoords.UploadVertices(new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(0, 1), new Vector2(1, 1)}); prog = context.NewProgram(MVP_VERTEX_SHADER, TEXTURE_SHADER); paramSpec = ImmutableList<Tuple<String, Object>>.List( Tuple.Create<String, Object>("a_position", vertices), Tuple.Create<String, Object>("a_texPos", texCoords), Tuple.Create<String, Object>("u_texture0", texture)); }