public override void Initialize() { var vertexBuffer = Context.Create.Buffer(BufferTarget.Array, 3 * 8 * sizeof(float), BufferUsageHint.StaticDraw, new[] { new Vertex { Position = new Vector4(-0.5f, -0.5f, 0f, 1f), Color = new Color4(1, 0, 0, 1) }, new Vertex { Position = new Vector4(0.0f, 0.5f, 0f, 1f), Color = new Color4(0, 1, 0, 1) }, new Vertex { Position = new Vector4(0.5f, -0.5f, 0f, 1f), Color = new Color4(1, 1, 0, 1) } }); var indexBuffer = Context.Create.Buffer(BufferTarget.ElementArray, 3 * sizeof(ushort), BufferUsageHint.StaticDraw, new ushort[] { 0, 1, 2 }); vertexArray = Context.Create.VertexArray(); vertexArray.SetElementArrayBuffer(indexBuffer); vertexArray.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, 32, 0); vertexArray.SetVertexAttributeF(1, vertexBuffer, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, 32, 16); IVertexShader vsh = Context.Create.VertexShader(VertexShaderText); IFragmentShader fsh = Context.Create.FragmentShader(FragmentShaderText); program = Context.Create.Program(new ShaderProgramDescription { VertexShaders = new[] { vsh }, FragmentShaders = new[] { fsh }, VertexAttributeNames = new[] { "in_position", "in_color" } }); }
public FullTextureProcessor(IClientSettings settings, IContext context, string fragmentShaderText, string[] samplerNames) { var header = settings.IsEs ? EsHeader : DesktopHeader; var vertexShader = context.Create.VertexShader(header + VertexShaderText); var decodeFragmentShader = context.Create.FragmentShader(header + fragmentShaderText); program = context.Create.Program(new ShaderProgramDescription { VertexShaders = new[] { vertexShader }, FragmentShaders = new[] { decodeFragmentShader }, VertexAttributeNames = new[] { "in_position" }, SamplerNames = samplerNames }); var vertexBuffer = context.Create.Buffer(BufferTarget.ArrayBuffer, 4 * Vertex.Size, BufferUsageHint.StaticDraw, new[] { new Vertex(-1f, 1f), new Vertex(1f, 1f), new Vertex(1f, -1f), new Vertex(-1f, -1f) }); var elementArrayBuffer = context.Create.Buffer(BufferTarget.ElementArrayBuffer, 6 * sizeof(ushort), BufferUsageHint.StaticDraw, new ushort[] { 0, 1, 2, 0, 2, 3 }); vertexArray = context.Create.VertexArray(); vertexArray.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Two, VertexAttribPointerType.Float, false, Vertex.Size, 0); vertexArray.SetElementArrayBuffer(elementArrayBuffer); }
public IVertexArray GetGlVao() { if (!dirty) { return(glVertexArray); } if (glVertexArray == null) { glVertexArray = infra.GlContext.Create.VertexArray(); } glVertexArray.DisableVertexAttributesStartingFrom(0); var indexOfPosition = vertexSet.ElementInfos.IndexOf(x => x.CommonSemantic == CommonVertexSemantic.Position); var indexOfNormal = vertexSet.ElementInfos.IndexOf(x => x.CommonSemantic == CommonVertexSemantic.Normal); var indexOfTexCoord = vertexSet.ElementInfos.IndexOf(x => x.CommonSemantic == CommonVertexSemantic.TexCoord); if (indexOfPosition.HasValue) { SetVertexAttrF(0, indexOfPosition.Value, VertexAttributeDimension.Three, VertexAttribPointerType.Float); } if (indexOfNormal.HasValue) { SetVertexAttrF(1, indexOfNormal.Value, VertexAttributeDimension.Three, VertexAttribPointerType.Float); } if (indexOfTexCoord.HasValue) { SetVertexAttrF(2, indexOfTexCoord.Value, VertexAttributeDimension.Two, VertexAttribPointerType.Float); } if (vertexSet.IndicesInfo != null) { var arraySubrange = vertexSet.ArraySubranges[vertexSet.IndicesInfo.ArrayIndex]; var rawDataRes = arraySubrange.RawDataResource; var arrayCache = rawDataRes.CacheContainer.GetOrAddCache(Tuples.Pair(infra, rawDataRes), x => new RawDataResCache(x.First, x.Second)); var glBuffer = arrayCache.GetGlIndexBuffer(arraySubrange.StartOffset); glVertexArray.SetElementArrayBuffer(glBuffer); } else { glVertexArray.SetElementArrayBuffer(null); } dirty = false; return(glVertexArray); }
public override void Initialize() { var vertexBuffer = Context.Create.Buffer(BufferTarget.Array, 4 * 8 * sizeof(float), BufferUsageHint.StaticDraw, new[] { new Vertex(-1f, -1f, 0f, 1f), new Vertex(-1f, 1f, 0f, 0f), new Vertex(1f, 1f, 1f, 0f), new Vertex(1f, -1f, 1f, 1f), }); var indexBuffer = Context.Create.Buffer(BufferTarget.ElementArray, 6 * sizeof(ushort), BufferUsageHint.StaticDraw, new ushort[] { 0, 1, 2, 0, 2, 3 }); vertexArray = Context.Create.VertexArray(); vertexArray.SetElementArrayBuffer(indexBuffer); vertexArray.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, 32, 0); vertexArray.SetVertexAttributeF(1, vertexBuffer, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, 32, 16); using (var textureLoader = new TextureLoader("../Textures/Chess256.png")) { diffuseMap = Context.Create.Texture2D(textureLoader.Width, textureLoader.Height, TextureHelper.CalculateMipCount(textureLoader.Width, textureLoader.Height, 1), Format.Srgb8Alpha8); for (int i = 0; i < diffuseMap.MipCount; i++) { diffuseMap.SetData(i, textureLoader.GetMipData(i), FormatColor.Rgba, FormatType.UnsignedByte); } } sampler = Context.Create.Sampler(); sampler.SetMagFilter(TextureMagFilter.Linear); sampler.SetMinFilter(TextureMinFilter.LinearMipmapLinear); sampler.SetMaxAnisotropy(16f); var vsh = Context.Create.VertexShader(VertexShaderText); var fsh = Context.Create.FragmentShader(FragmentShaderText); program = Context.Create.Program(new ShaderProgramDescription { VertexShaders = new[] { vsh }, FragmentShaders = new[] { fsh }, VertexAttributeNames = new[] { "in_position", "in_tex_coord" }, SamplerNames = new[] { "DiffuseMap" } }); }
public override void Initialize() { var vertexBuffer = Context.Create.Buffer(BufferTarget.Array, 4 * 8 * sizeof(float), BufferUsageHint.StaticDraw, new[] { new Vertex(-1f, -1f, 0f, 1f), new Vertex(-1f, 1f, 0f, 0f), new Vertex(1f, 1f, 1f, 0f), new Vertex(1f, -1f, 1f, 1f), }); var indexBuffer = Context.Create.Buffer(BufferTarget.ElementArray, 6 * sizeof(ushort), BufferUsageHint.StaticDraw, new ushort[] { 0, 1, 2, 0, 2, 3 }); vertexArray = Context.Create.VertexArray(); vertexArray.SetElementArrayBuffer(indexBuffer); vertexArray.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, 32, 0); vertexArray.SetVertexAttributeF(1, vertexBuffer, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, 32, 16); pixelUnpackBuffer = Context.Create.Buffer(BufferTarget.PixelUnpack, 1024 * 1024 * 4, BufferUsageHint.StreamDraw); data = Enumerable.Range(0, 1024 * 1024 * 4 * 2).Select(x => (byte)(128.0 + 128.0 * Math.Sin((2.0 / 3.0) * Math.PI * (x % 4) + (double)x / 4 / 11111))).ToArray(); diffuseMap = Context.Create.Texture2D(640, 360, 1, Format.Rgba8); sampler = Context.Create.Sampler(); sampler.SetMagFilter(TextureMagFilter.Nearest); sampler.SetMinFilter(TextureMinFilter.Nearest); sampler.SetMaxAnisotropy(16f); var vsh = Context.Create.VertexShader(VertexShaderText); var fsh = Context.Create.FragmentShader(FragmentShaderText); program = Context.Create.Program(new ShaderProgramDescription { VertexShaders = new[] { vsh }, FragmentShaders = new[] { fsh }, VertexAttributeNames = new[] { "in_position", "in_tex_coord" }, SamplerNames = new[] { "DiffuseMap" } }); }
public override void Initialize() { renderTarget = Context.Create.Texture2D(RenderTargetSize, RenderTargetSize, TextureHelper.CalculateMipCount(RenderTargetSize, 1, 1), Format.Rgba8); depthStencil = Context.Create.Renderbuffer(RenderTargetSize, RenderTargetSize, Format.Depth24Stencil8); framebuffer = Context.Create.Framebuffer(); framebuffer.AttachTextureImage(FramebufferAttachmentPoint.Color0, renderTarget, 0); framebuffer.AttachRenderbuffer(FramebufferAttachmentPoint.DepthStencil, depthStencil); var vertexBuffer = Context.Create.Buffer(BufferTarget.Array, 24 * 8 * sizeof(float), BufferUsageHint.StaticDraw, new[] { new Vertex(1f, -1f, 1f, 1f, 0f, 0f, 0f, 0f), new Vertex(1f, 1f, 1f, 1f, 0f, 0f, 1f, 0f), new Vertex(1f, 1f, -1f, 1f, 0f, 0f, 1f, 1f), new Vertex(1f, -1f, -1f, 1f, 0f, 0f, 0f, 1f), new Vertex(1f, 1f, 1f, 0f, 1f, 0f, 0f, 0f), new Vertex(-1f, 1f, 1f, 0f, 1f, 0f, 1f, 0f), new Vertex(-1f, 1f, -1f, 0f, 1f, 0f, 1f, 1f), new Vertex(1f, 1f, -1f, 0f, 1f, 0f, 0f, 1f), new Vertex(-1f, 1f, 1f, -1f, 0f, 0f, 0f, 0f), new Vertex(-1f, -1f, 1f, -1f, 0f, 0f, 1f, 0f), new Vertex(-1f, -1f, -1f, -1f, 0f, 0f, 1f, 1f), new Vertex(-1f, 1f, -1f, -1f, 0f, 0f, 0f, 1f), new Vertex(-1f, -1f, 1f, 0f, -1f, 0f, 0f, 0f), new Vertex(1f, -1f, 1f, 0f, -1f, 0f, 1f, 0f), new Vertex(1f, -1f, -1f, 0f, -1f, 0f, 1f, 1f), new Vertex(-1f, -1f, -1f, 0f, -1f, 0f, 0f, 1f), new Vertex(-1f, -1f, 1f, 0f, 0f, 1f, 0f, 0f), new Vertex(-1f, 1f, 1f, 0f, 0f, 1f, 1f, 0f), new Vertex(1f, 1f, 1f, 0f, 0f, 1f, 1f, 1f), new Vertex(1f, -1f, 1f, 0f, 0f, 1f, 0f, 1f), new Vertex(-1f, 1f, -1f, 0f, 0f, -1f, 0f, 0f), new Vertex(-1f, -1f, -1f, 0f, 0f, -1f, 1f, 0f), new Vertex(1f, -1f, -1f, 0f, 0f, -1f, 1f, 1f), new Vertex(1f, 1f, -1f, 0f, 0f, -1f, 0f, 1f) }); var indexBuffer = Context.Create.Buffer(BufferTarget.ElementArray, 36 * sizeof(ushort), BufferUsageHint.StaticDraw, new ushort[] { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23 }); vertexArray = Context.Create.VertexArray(); vertexArray.SetElementArrayBuffer(indexBuffer); vertexArray.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Three, VertexAttribPointerType.Float, false, 32, 0); vertexArray.SetVertexAttributeF(1, vertexBuffer, VertexAttributeDimension.Three, VertexAttribPointerType.Float, false, 32, 12); vertexArray.SetVertexAttributeF(2, vertexBuffer, VertexAttributeDimension.Two, VertexAttribPointerType.Float, false, 32, 24); transformBuffer = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw); cameraBuffer = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw); #if INTEL_WORKAROUND cameraOutsideBuffer = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw); #endif cameraExtraBuffer = Context.Create.Buffer(BufferTarget.Uniform, 12, BufferUsageHint.DynamicDraw); lightBuffer = Context.Create.Buffer(BufferTarget.Uniform, 12, BufferUsageHint.DynamicDraw); using (var textureLoader = new TextureLoader("../Textures/DiffuseTest.png")) { diffuseMap = Context.Create.Texture2D(textureLoader.Width, textureLoader.Height, TextureHelper.CalculateMipCount(textureLoader.Width, textureLoader.Height, 1), Format.Rgba8); for (int i = 0; i < diffuseMap.MipCount; i++) diffuseMap.SetData(i, textureLoader.GetMipData(i), FormatColor.Rgba, FormatType.UnsignedByte); } sampler = Context.Create.Sampler(); sampler.SetMagFilter(TextureMagFilter.Linear); sampler.SetMinFilter(TextureMinFilter.LinearMipmapLinear); sampler.SetMaxAnisotropy(16f); IVertexShader vsh = Context.Create.VertexShader(VertexShaderText); IFragmentShader fsh = Context.Create.FragmentShader(FragmentShaderText); program = Context.Create.Program(new ShaderProgramDescription { VertexShaders = new[] {vsh}, FragmentShaders = new[] {fsh}, VertexAttributeNames = new[] {"in_position", "in_normal", "in_tex_coord"}, UniformBufferNames = new[] {"Transform", "Camera", "Light"}, SamplerNames = new[] {"DiffuseMap"} }); }
public CursorRenderer(IClientSettings settings, IContext context, ITextureLoader textureLoader) { var header = settings.IsEs ? EsHeader : DesktopHeader; var vertexShader = context.Create.VertexShader(header + VertexShaderText); var fragmentShader = context.Create.FragmentShader(header + FragmentShaderText); program = context.Create.Program(new ShaderProgramDescription { VertexShaders = new[] { vertexShader }, FragmentShaders = new[] { fragmentShader }, VertexAttributeNames = new[] { "in_position", "in_tex_coord" }, SamplerNames = new[] { "DiffTexture" } }); var vertexBuffer = context.Create.Buffer(BufferTarget.ArrayBuffer, 4 * Vertex.Size, BufferUsageHint.StaticDraw, new[] { new Vertex(-1f, 1f, 0f, 0f), new Vertex(1f, 1f, 1f, 0f), new Vertex(1f, -1f, 1f, 1f), new Vertex(-1f, -1f, 0f, 1f) }); var indexBuffer = context.Create.Buffer(BufferTarget.ElementArrayBuffer, 6 * sizeof(ushort), BufferUsageHint.StaticDraw, new ushort[] { 0, 1, 2, 0, 2, 3 }); vertexArray = context.Create.VertexArray(); vertexArray.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Two, VertexAttribPointerType.Float, false, Vertex.Size, 0); vertexArray.SetVertexAttributeF(1, vertexBuffer, VertexAttributeDimension.Two, VertexAttribPointerType.Float, false, Vertex.Size, 2 * sizeof(float)); vertexArray.SetElementArrayBuffer(indexBuffer); texture = textureLoader.LoadTexture(context, "Cursor.png"); sampler = context.Create.Sampler(); sampler.SetMagFilter(TextureMagFilter.Nearest); }
public override void Initialize() { var vertexBuffer = Context.Create.Buffer(BufferTarget.Array, 3 * 8 * sizeof(float), BufferUsageHint.StaticDraw, new[] { new Vertex { Position = new Vector4(-0.5f, -0.5f, 0f, 1f), Color = new Color4(1, 0, 0, 1)}, new Vertex { Position = new Vector4(0.0f, 0.5f, 0f, 1f), Color = new Color4(0, 1, 0, 1)}, new Vertex { Position = new Vector4(0.5f, -0.5f, 0f, 1f), Color = new Color4(1, 1, 0, 1)} }); var indexBuffer = Context.Create.Buffer(BufferTarget.ElementArray, 3 * sizeof(ushort), BufferUsageHint.StaticDraw, new ushort[] { 0, 1, 2 }); vertexArray = Context.Create.VertexArray(); vertexArray.SetElementArrayBuffer(indexBuffer); vertexArray.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, 32, 0); vertexArray.SetVertexAttributeF(1, vertexBuffer, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, 32, 16); IVertexShader vsh = Context.Create.VertexShader(VertexShaderText); IFragmentShader fsh = Context.Create.FragmentShader(FragmentShaderText); program = Context.Create.Program(new ShaderProgramDescription { VertexShaders = new[] {vsh}, FragmentShaders = new[] {fsh}, VertexAttributeNames = new[] {"in_position", "in_color"} }); }
public override void Initialize() { var vertexBuffer = Context.Create.Buffer(BufferTarget.Array, 4 * 8 * sizeof(float), BufferUsageHint.StaticDraw, new[] { new Vertex(-1f, -1f, 0f, 1f), new Vertex(-1f, 1f, 0f, 0f), new Vertex(1f, 1f, 1f, 0f), new Vertex(1f, -1f, 1f, 1f), }); var indexBuffer = Context.Create.Buffer(BufferTarget.ElementArray, 6 * sizeof(ushort), BufferUsageHint.StaticDraw, new ushort[] { 0, 1, 2, 0, 2, 3 }); vertexArray = Context.Create.VertexArray(); vertexArray.SetElementArrayBuffer(indexBuffer); vertexArray.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, 32, 0); vertexArray.SetVertexAttributeF(1, vertexBuffer, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, 32, 16); using (var textureLoader = new TextureLoader("../Textures/Chess256.png")) { diffuseMap = Context.Create.Texture2D(textureLoader.Width, textureLoader.Height, TextureHelper.CalculateMipCount(textureLoader.Width, textureLoader.Height, 1), Format.Srgb8Alpha8); for (int i = 0; i < diffuseMap.MipCount; i++) diffuseMap.SetData(i, textureLoader.GetMipData(i), FormatColor.Rgba, FormatType.UnsignedByte); } sampler = Context.Create.Sampler(); sampler.SetMagFilter(TextureMagFilter.Linear); sampler.SetMinFilter(TextureMinFilter.LinearMipmapLinear); sampler.SetMaxAnisotropy(16f); var vsh = Context.Create.VertexShader(VertexShaderText); var fsh = Context.Create.FragmentShader(FragmentShaderText); program = Context.Create.Program(new ShaderProgramDescription { VertexShaders = new[] {vsh}, FragmentShaders = new[] {fsh}, VertexAttributeNames = new[] {"in_position", "in_tex_coord"}, SamplerNames = new[] {"DiffuseMap"} }); }
public unsafe SkyboxDrawer(IContext glContext) { this.glContext = glContext; sampler = glContext.Create.Sampler(); sampler.SetMagFilter(TextureMagFilter.Linear); sampler.SetMinFilter(TextureMinFilter.LinearMipmapLinear); sampler.SetWrapR(TextureWrapMode.Clamp); sampler.SetWrapS(TextureWrapMode.Clamp); sampler.SetWrapT(TextureWrapMode.Clamp); sampler.SetMaxAnisotropy(16f); #region Shader Text const string vertexShaderText = @"#version 150 layout(std140) uniform Camera { mat4 ViewProjection; }; in vec3 in_position; out vec3 v_tex_coord; void main() { vec4 worldPosition = vec4(in_position, 1.0f); gl_Position = worldPosition * ViewProjection; gl_Position.y = -gl_Position.y; gl_Position.z = 2.0 * gl_Position.z - gl_Position.w; v_tex_coord = vec3(-worldPosition.x, worldPosition.y, worldPosition.z); } "; const string fragmentShaderText = @"#version 150 uniform samplerCube Texture; in vec3 v_tex_coord; out vec4 out_color; void main() { out_color = texture(Texture, v_tex_coord); } "; #endregion var vs = glContext.Create.VertexShader(vertexShaderText); var fs = glContext.Create.FragmentShader(fragmentShaderText); shaderProgram = glContext.Create.Program(new ShaderProgramDescription { VertexShaders = new[] { vs }, FragmentShaders = new[] { fs }, VertexAttributeNames = new[] { "in_position" }, UniformBufferNames = new[] { "Camera" }, SamplerNames = new[] { "Texture" } }); var vertices = new[] { new Vector4(-10, -10, -1, 1), new Vector4(-10, 10, -1, 1), new Vector4(10, 10, -1, 1), new Vector4(10, -10, -1, 1), new Vector4(-10, -10, 1, 1), new Vector4(-10, 10, 1, 1), new Vector4(10, 10, 1, 1), new Vector4(10, -10, 1, 1), }; var indices = new[] { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 0, 4, 7, 0, 7, 3, 0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 3, 7, 6, 3, 6, 2 }; IBuffer vertexBuffer; fixed(Vector4 *data = vertices) vertexBuffer = glContext.Create.Buffer(BufferTarget.Array, 4 * sizeof(float) * vertices.Length, BufferUsageHint.StaticDraw, (IntPtr)data); IBuffer indexBuffer; fixed(int *data = indices) indexBuffer = glContext.Create.Buffer(BufferTarget.ElementArray, sizeof(int) * indices.Length, BufferUsageHint.StaticDraw, (IntPtr)data); vao = glContext.Create.VertexArray(); vao.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Three, VertexAttribPointerType.Float, false, 4 * sizeof(float), 0); vao.SetElementArrayBuffer(indexBuffer); cameraUb = new UniformBufferSugar <Matrix4x4>(glContext); }
public override void Initialize() { renderTarget = Context.Create.Texture2D(RenderTargetSize, RenderTargetSize, TextureHelper.CalculateMipCount(RenderTargetSize, 1, 1), Format.Rgba8); depthStencil = Context.Create.Renderbuffer(RenderTargetSize, RenderTargetSize, Format.Depth24Stencil8); framebuffer = Context.Create.Framebuffer(); framebuffer.AttachTextureImage(FramebufferAttachmentPoint.Color0, renderTarget, 0); framebuffer.AttachRenderbuffer(FramebufferAttachmentPoint.DepthStencil, depthStencil); var vertexBuffer = Context.Create.Buffer(BufferTarget.Array, 24 * 8 * sizeof(float), BufferUsageHint.StaticDraw, new[] { new Vertex(1f, -1f, 1f, 1f, 0f, 0f, 0f, 0f), new Vertex(1f, 1f, 1f, 1f, 0f, 0f, 1f, 0f), new Vertex(1f, 1f, -1f, 1f, 0f, 0f, 1f, 1f), new Vertex(1f, -1f, -1f, 1f, 0f, 0f, 0f, 1f), new Vertex(1f, 1f, 1f, 0f, 1f, 0f, 0f, 0f), new Vertex(-1f, 1f, 1f, 0f, 1f, 0f, 1f, 0f), new Vertex(-1f, 1f, -1f, 0f, 1f, 0f, 1f, 1f), new Vertex(1f, 1f, -1f, 0f, 1f, 0f, 0f, 1f), new Vertex(-1f, 1f, 1f, -1f, 0f, 0f, 0f, 0f), new Vertex(-1f, -1f, 1f, -1f, 0f, 0f, 1f, 0f), new Vertex(-1f, -1f, -1f, -1f, 0f, 0f, 1f, 1f), new Vertex(-1f, 1f, -1f, -1f, 0f, 0f, 0f, 1f), new Vertex(-1f, -1f, 1f, 0f, -1f, 0f, 0f, 0f), new Vertex(1f, -1f, 1f, 0f, -1f, 0f, 1f, 0f), new Vertex(1f, -1f, -1f, 0f, -1f, 0f, 1f, 1f), new Vertex(-1f, -1f, -1f, 0f, -1f, 0f, 0f, 1f), new Vertex(-1f, -1f, 1f, 0f, 0f, 1f, 0f, 0f), new Vertex(-1f, 1f, 1f, 0f, 0f, 1f, 1f, 0f), new Vertex(1f, 1f, 1f, 0f, 0f, 1f, 1f, 1f), new Vertex(1f, -1f, 1f, 0f, 0f, 1f, 0f, 1f), new Vertex(-1f, 1f, -1f, 0f, 0f, -1f, 0f, 0f), new Vertex(-1f, -1f, -1f, 0f, 0f, -1f, 1f, 0f), new Vertex(1f, -1f, -1f, 0f, 0f, -1f, 1f, 1f), new Vertex(1f, 1f, -1f, 0f, 0f, -1f, 0f, 1f) }); var indexBuffer = Context.Create.Buffer(BufferTarget.ElementArray, 36 * sizeof(ushort), BufferUsageHint.StaticDraw, new ushort[] { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23 }); vertexArray = Context.Create.VertexArray(); vertexArray.SetElementArrayBuffer(indexBuffer); vertexArray.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Three, VertexAttribPointerType.Float, false, 32, 0); vertexArray.SetVertexAttributeF(1, vertexBuffer, VertexAttributeDimension.Three, VertexAttribPointerType.Float, false, 32, 12); vertexArray.SetVertexAttributeF(2, vertexBuffer, VertexAttributeDimension.Two, VertexAttribPointerType.Float, false, 32, 24); transformBuffer = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw); cameraBuffer = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw); #if INTEL_WORKAROUND cameraOutsideBuffer = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw); #endif cameraExtraBuffer = Context.Create.Buffer(BufferTarget.Uniform, 12, BufferUsageHint.DynamicDraw); lightBuffer = Context.Create.Buffer(BufferTarget.Uniform, 12, BufferUsageHint.DynamicDraw); using (var textureLoader = new TextureLoader("../Textures/DiffuseTest.png")) { diffuseMap = Context.Create.Texture2D(textureLoader.Width, textureLoader.Height, TextureHelper.CalculateMipCount(textureLoader.Width, textureLoader.Height, 1), Format.Rgba8); for (int i = 0; i < diffuseMap.MipCount; i++) { diffuseMap.SetData(i, textureLoader.GetMipData(i), FormatColor.Rgba, FormatType.UnsignedByte); } } sampler = Context.Create.Sampler(); sampler.SetMagFilter(TextureMagFilter.Linear); sampler.SetMinFilter(TextureMinFilter.LinearMipmapLinear); sampler.SetMaxAnisotropy(16f); IVertexShader vsh = Context.Create.VertexShader(VertexShaderText); IFragmentShader fsh = Context.Create.FragmentShader(FragmentShaderText); program = Context.Create.Program(new ShaderProgramDescription { VertexShaders = new[] { vsh }, FragmentShaders = new[] { fsh }, VertexAttributeNames = new[] { "in_position", "in_normal", "in_tex_coord" }, UniformBufferNames = new[] { "Transform", "Camera", "Light" }, SamplerNames = new[] { "DiffuseMap" } }); }
public override void Initialize() { var vertexBuffer = Context.Create.Buffer(BufferTarget.Array, 4 * 8 * sizeof(float), BufferUsageHint.StaticDraw, new[] { new Vertex(-1f, -1f, 0f, 1f), new Vertex(-1f, 1f, 0f, 0f), new Vertex(1f, 1f, 1f, 0f), new Vertex(1f, -1f, 1f, 1f), }); var indexBuffer = Context.Create.Buffer(BufferTarget.ElementArray, 6 * sizeof(ushort), BufferUsageHint.StaticDraw, new ushort[] { 0, 1, 2, 0, 2, 3 }); vertexArray = Context.Create.VertexArray(); vertexArray.SetElementArrayBuffer(indexBuffer); vertexArray.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, 32, 0); vertexArray.SetVertexAttributeF(1, vertexBuffer, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, 32, 16); pixelUnpackBuffer = Context.Create.Buffer(BufferTarget.PixelUnpack, 1024 * 1024 * 4, BufferUsageHint.StreamDraw); data = Enumerable.Range(0, 1024 * 1024 * 4 * 2).Select(x => (byte)(128.0 + 128.0 * Math.Sin((2.0 / 3.0) * Math.PI * (x % 4) + (double)x / 4 / 11111))).ToArray(); diffuseMap = Context.Create.Texture2D(640, 360, 1, Format.Rgba8); sampler = Context.Create.Sampler(); sampler.SetMagFilter(TextureMagFilter.Nearest); sampler.SetMinFilter(TextureMinFilter.Nearest); sampler.SetMaxAnisotropy(16f); var vsh = Context.Create.VertexShader(VertexShaderText); var fsh = Context.Create.FragmentShader(FragmentShaderText); program = Context.Create.Program(new ShaderProgramDescription { VertexShaders = new[] {vsh}, FragmentShaders = new[] {fsh}, VertexAttributeNames = new[] {"in_position", "in_tex_coord"}, SamplerNames = new[] {"DiffuseMap"} }); }