Example #1
0
        public static EyeFrameBuffer Create(int width, int height)
        {
            int frameBuffer = OpenGLUtil.CreateFrameBuffer();

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer);

            int depthBuffer = OpenGLUtil.CreateRenderBuffer();

            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, depthBuffer);
            GL.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, 4, RenderbufferStorage.DepthComponent, width, height);
            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, depthBuffer);

            int renderTexture = OpenGLUtil.CreateTexture();

            GL.BindTexture(TextureTarget.Texture2DMultisample, renderTexture);
            GL.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, 4, PixelInternalFormat.Rgba8, width, height, true);
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2DMultisample, renderTexture, 0);

            int resolveFrameBuffer = OpenGLUtil.CreateFrameBuffer();

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, resolveFrameBuffer);

            int resolveTexture = OpenGLUtil.CreateTexture();

            GL.BindTexture(TextureTarget.Texture2D, resolveTexture);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, 0);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, resolveTexture, 0);

            OpenGLUtil.CheckInvalidFrameBuffer();
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); // go back to default frame buffer

            return(new EyeFrameBuffer(depthBuffer, renderTexture, frameBuffer, resolveTexture, resolveFrameBuffer));
        }
Example #2
0
            public static GLRenderModel Create(string name, RenderModel_t renderModel, RenderModel_TextureMap_t diffuseTexture)
            {
                // create and bind a VAO to hold the state for this model
                int vao = OpenGLUtil.CreateVertexArrayObject();

                GL.BindVertexArray(vao);

                // populate the vertex buffer
                int vbo = OpenGLUtil.CreateBufferObject();

                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
                GL.BufferData(BufferTarget.ArrayBuffer, Marshal.SizeOf <RenderModel_Vertex_t>() * (int)renderModel.unVertexCount, renderModel.rVertexData, BufferUsageHint.StaticDraw);

                // identity the components in teh vertex buffer
                GL.EnableVertexAttribArray(0);
                GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, Marshal.SizeOf <RenderModel_Vertex_t>(), Marshal.OffsetOf <RenderModel_Vertex_t>("vPosition")); // this might have to be size of 4?
                GL.EnableVertexAttribArray(1);
                GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, Marshal.SizeOf <RenderModel_Vertex_t>(), Marshal.OffsetOf <RenderModel_Vertex_t>("vNormal"));
                GL.EnableVertexAttribArray(2);
                GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, Marshal.SizeOf <RenderModel_Vertex_t>(), Marshal.OffsetOf <RenderModel_Vertex_t>("rfTextureCoord0"));

                // create and populate the index buffer
                int indexBuffer = OpenGLUtil.CreateBufferObject();

                GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer);
                GL.BufferData(BufferTarget.ElementArrayBuffer, Marshal.SizeOf <ushort>() * (int)renderModel.unTriangleCount * 3, renderModel.rIndexData, BufferUsageHint.StaticDraw);

                GL.BindVertexArray(0);

                // create and populate the texture
                int texture = OpenGLUtil.CreateTexture();

                GL.BindTexture(TextureTarget.Texture2D, texture);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, diffuseTexture.unWidth, diffuseTexture.unHeight,
                              0, PixelFormat.Rgba, PixelType.UnsignedByte, diffuseTexture.rubTextureMapData);
                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);

                GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, new[] { (int)TextureParameterName.ClampToEdge });
                GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, new[] { (int)TextureParameterName.ClampToEdge });
                GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, new[] { (int)TextureMagFilter.Linear });
                GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, new[] { (int)TextureMinFilter.LinearMipmapLinear });

                // *****missing stuff about anisotropy ***** // not sure if this is right
                float largest = GL.GetFloat((GetPName)0x84FF);

                GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)0x84FE, largest);

                GL.BindTexture(TextureTarget.Texture2D, 0);

                return(new GLRenderModel(vbo, indexBuffer, vao, texture, (int)renderModel.unTriangleCount * 3, name));
            }