public GBuffer(Game game, int width, int height) { this.fbo = new Framebuffer (FramebufferTarget.Framebuffer, width, height) .AttachTexture (FboAttachment.DiffuseAttachment, DrawBuffersEnum.ColorAttachment0, PixelInternalFormat.Srgb, PixelFormat.Rgb, PixelType.UnsignedByte, InterpolationMode.Linear) .AttachTexture (FboAttachment.NormalAttachment, DrawBuffersEnum.ColorAttachment1, PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.Float, InterpolationMode.Linear) .AttachTexture (FboAttachment.SpecularAttachment, DrawBuffersEnum.ColorAttachment2, PixelInternalFormat.Rgb10A2, PixelFormat.Rgb, PixelType.UnsignedByte, InterpolationMode.Linear) .AttachDepth (PixelInternalFormat.DepthComponent32, PixelFormat.DepthComponent, PixelType.Float, InterpolationMode.Linear) .Construct (); GeometryPass = game.Content.Load<ShaderProgram> ("geometryPass"); }
public RenderingPipeline(Game game) { this.game = game; this.GBuffer = new GBuffer (game, game.Configuration.Width * 2, game.Configuration.Height * 2); Framebuffer = new Framebuffer (FramebufferTarget.Framebuffer, game.Configuration.Width, game.Configuration.Height) .AttachTexture (FboAttachment.DiffuseAttachment, DrawBuffersEnum.ColorAttachment0, PixelInternalFormat.Rgb10A2, PixelFormat.Rgb, PixelType.UnsignedByte, InterpolationMode.Linear) .Construct (); DeferredDirectional = game.Content.Load<ShaderProgram> ("deferredDirectional"); DeferredPoint = game.Content.Load<ShaderProgram> ("deferredPoint"); AmbientShader = game.Content.Load<ShaderProgram> ("deferredAmbient"); this.AmbientColor = new Vector3 (.25f, .25f, .25f); }
public static void Unbind(Framebuffer @this) { GL.BindFramebuffer (@this.Target, 0); }
public static void Bind(Framebuffer @this) { GL.BindFramebuffer (@this.Target, @this.FramebufferId); GL.Viewport (0, 0, @this.Width, @this.Height); }
/// <summary> /// Initializes a new instance of the <see cref="nginz.SpriteBatch"/> class. /// </summary> /// <param name = "game">The game.</param> /// <param name="shader">Shader.</param> public SpriteBatch(Game game, ShaderProgram shader = null) { // Set the game Game = game; // Compile predefined shaders if no shader program is given if (shader == null) { var vertShader = new VertexShader (vert_source); var fragShader = new FragmentShader (frag_source); Program = new ShaderProgram (vertShader, fragShader); Program.Link (); } else Program = shader; // Create the optimal buffer settings var settings = new GLBufferSettings { AttribSize = 0, Hint = BufferUsageHint.DynamicDraw, Normalized = false, Offset = 0, Target = BufferTarget.ArrayBuffer, Type = VertexAttribPointerType.Float }; // Create temp variables for indices int indPtr = 0; var tempIndices = new uint[MAX_INDICES]; // Fill temporary indices for (uint i = 0; i < MAX_VERTICES; i += 4) { // Triangle 1 tempIndices [indPtr++] = i; tempIndices [indPtr++] = i + 1; tempIndices [indPtr++] = i + 2; // Triangle 2 tempIndices [indPtr++] = i + 1; tempIndices [indPtr++] = i + 3; tempIndices [indPtr++] = i + 2; } // Set camera InternalCamera = new Camera (60f, game.Resolution, 0, 16, type: ProjectionType.Orthographic); // Set current texture CurrentTexture = Texture2D.Dot; // Generate array buffer object abo = GL.GenVertexArray (); // Create vertex buffer object vbo = new GLBufferDynamic<Vertex2D> (settings, Vertex2D.Size, MAX_VERTICES); // Create index buffer object ibo = new GLBuffer<uint> (GLBufferSettings.DynamicIndices, tempIndices); // Initialize vertices Vertices = new Vertex2D[MAX_VERTICES]; framebuffer = new Framebuffer (FramebufferTarget.Framebuffer, Game.Resolution.Width, game.Resolution.Height) .AttachTexture (FboAttachment.DiffuseAttachment, DrawBuffersEnum.ColorAttachment0, PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.UnsignedByte, InterpolationMode.Linear); }
/// <summary> /// Initializes a new instance of the <see cref="nginz.SpriteBatch"/> class. /// </summary> /// <param name = "game">The game.</param> /// <param name="shader">Shader.</param> public SpriteBatch(Game game, ShaderProgram shader = null) { // Set the game Game = game; // Compile predefined shaders if no shader program is given if (shader == null) { var vertShader = new VertexShader(vert_source); var fragShader = new FragmentShader(frag_source); Program = new ShaderProgram(vertShader, fragShader); Program.Link(); } else { Program = shader; } // Create the optimal buffer settings var settings = new GLBufferSettings { AttribSize = 0, Hint = BufferUsageHint.DynamicDraw, Normalized = false, Offset = 0, Target = BufferTarget.ArrayBuffer, Type = VertexAttribPointerType.Float }; // Create temp variables for indices int indPtr = 0; var tempIndices = new uint[MAX_INDICES]; // Fill temporary indices for (uint i = 0; i < MAX_VERTICES; i += 4) { // Triangle 1 tempIndices [indPtr++] = i; tempIndices [indPtr++] = i + 1; tempIndices [indPtr++] = i + 2; // Triangle 2 tempIndices [indPtr++] = i + 1; tempIndices [indPtr++] = i + 3; tempIndices [indPtr++] = i + 2; } // Set camera InternalCamera = new Camera(60f, game.Resolution, 0, 16, type: ProjectionType.Orthographic); // Set current texture CurrentTexture = Texture2D.Dot; // Generate array buffer object abo = GL.GenVertexArray(); // Create vertex buffer object vbo = new GLBufferDynamic <Vertex2D> (settings, Vertex2D.Size, MAX_VERTICES); // Create index buffer object ibo = new GLBuffer <uint> (GLBufferSettings.DynamicIndices, tempIndices); // Initialize vertices Vertices = new Vertex2D[MAX_VERTICES]; framebuffer = new Framebuffer(FramebufferTarget.Framebuffer, Game.Resolution.Width, game.Resolution.Height) .AttachTexture(FboAttachment.DiffuseAttachment, DrawBuffersEnum.ColorAttachment0, PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.UnsignedByte, InterpolationMode.Linear); }