Beispiel #1
0
        public bool CreateContext(IntPtr windowHandle, int colorBits, int depthBits, int stencilBits)
        {
            fGLContext = new GLContext(windowHandle, colorBits, depthBits, PFDFlags.DoubleBuffer);
            fGI = new GraphicsInterface(fGLContext);

            return (null != fGLContext);
        }
Beispiel #2
0
        public virtual void OnSetContext(GLContext GI)
        {
            aRectTest = new RectangleTest(new System.Drawing.Size(640, 480));
            randomRectTest = new RandomRect(new System.Drawing.Size(640, 480));
            sineTest = new SineWave(new System.Drawing.Size(640, 480), 100);
            lineTest = new LineDemo1(new System.Drawing.Size(640, 480));
            graphTest = new GraphTest(new System.Drawing.Size(640, 480));

            fDemos.Add(aRectTest);
            fDemos.Add(randomRectTest);
            fDemos.Add(sineTest);
            fDemos.Add(lineTest);
            fDemos.Add(graphTest);
        }
        public GraphicsInterface(GLContext GI)
        {
            fGlu = new Glu(this);
            fGI = GI;
            fExtensions = new GLExtensions(this);

            LoadExtensions();

            fState = new GLState(this);

            fServerFeatureList = new GLFeatureList(this);
            fClientFeatureList = new GLClientFeatureList(this);
            fBufferList = new GLFrameBuffer(this);
            fDrawingList = new GLPrimitiveDrawing(this);
        }
        //Update all existing cubemap uint objects
        public static void GenerateCubemaps(List <GenericRenderer> targetModels, bool isWiiU)
        {
            var texture = isWiiU ? CubeMapTextureArray : CubeMapTexture;

            if (texture != null)
            {
                texture.Dispose();
            }

            if (isWiiU)
            {
                texture = GLTexture2DArray.CreateUncompressedTexture(CUBEMAP_SIZE, CUBEMAP_SIZE, MAX_LAYER_COUNT * 6, MAX_MIP_LEVEL,
                                                                     PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.Float);
            }
            else
            {
                texture = GLTextureCubeArray.CreateEmptyCubemap(CUBEMAP_SIZE, MAX_LAYER_COUNT, MAX_MIP_LEVEL,
                                                                PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.Float);
            }

            GLTextureCube cubemapTexture = GLTextureCube.CreateEmptyCubemap(
                CUBEMAP_UPSCALE_SIZE, PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.Float, 9);

            //Get a list of cubemaps in the scene
            //The lighting engine has cube map objects with the object placement to draw
            var lightingEngine   = LightingEngine.LightSettings;
            var cubemapEnvParams = lightingEngine.Resources.CubeMapFiles.FirstOrDefault().Value;
            var cubeMapUints     = cubemapEnvParams.CubeMapObjects;
            int layer            = 0;

            foreach (var cubeMap in cubeMapUints)
            {
                var cUint = cubeMap.CubeMapUint;
                //Cubemap has no area assigned skip it
                if (cubeMap.CubeMapUint.Name == string.Empty)
                {
                    continue;
                }

                //Setup the camera to render the cube map faces
                CubemapCamera camera = new CubemapCamera(
                    new Vector3(cUint.Position.X, cUint.Position.Y, cUint.Position.Z)
                    * GLContext.PreviewScale, cUint.Near, cUint.Far);

                var context = new GLContext();
                context.Camera = camera;

                GenerateCubemap(context, cubemapTexture, camera, targetModels, MAX_MIP_LEVEL);

                cubemapTexture.Bind();
                cubemapTexture.GenerateMipmaps();
                cubemapTexture.Unbind();

                //HDR encode and output into the array
                CubemapHDREncodeRT.CreateCubemap(cubemapTexture, texture, layer, MAX_MIP_LEVEL, false, true);

                if (SAVE_TO_DISK)
                {
                    cubemapTexture.SaveDDS(cubeMap.Name + "default.dds");
                }

                layer++;
            }

            cubemapTexture.Dispose();

            //Just generate mips to keep things easier
            texture.Bind();
            texture.GenerateMipmaps();
            texture.Unbind();

            if (SAVE_TO_DISK)
            {
                texture.SaveDDS("Cubemap_Array_HDR.dds");
            }

            if (isWiiU)
            {
                CubeMapTextureArray = texture;
            }
            else
            {
                CubeMapTexture = texture;
            }
        }
Beispiel #5
0
 //------------------------------------------------------------------------------------------------------------------------
 //														RenderSelf
 //------------------------------------------------------------------------------------------------------------------------
 protected virtual void RenderSelf(GLContext glContext)
 {
     //if (visible == false) return;
     //glContext.PushMatrix(matrix);
     //glContext.PopMatrix();
 }
Beispiel #6
0
 public void SetContext(GLContext glContext)
 {
     fGI = new GraphicsInterface(glContext);
     OnSetContext();
 }
Beispiel #7
0
 internal virtual void Unbind(GLContext ctx)
 {
 }
        private unsafe void modelPanel1_PostRender(object sender, GLContext context)
        {
            context.glClear(GLClearMask.DepthBuffer);
            context.glEnable(GLEnableCap.DepthTest);

            if (pnlAssets.SelectedBone != null)
            {
                context.glDisable((uint)GLEnableCap.Lighting);

                //Render rotation orb
                MDL0BoneNode  bone   = pnlAssets.SelectedBone;
                GLDisplayList circle = context.GetRingList();
                GLDisplayList sphere = context.GetCircleList();
                Matrix        m;

                //Prepare camera-facing matrix
                Vector3 center = bone._frameMatrix.GetPoint();
                Vector3 cam    = modelPanel1._camera.GetPoint();
                float   radius = center.TrueDistance(cam) / _orbRadius * 0.1f;

                m = Matrix.TransformMatrix(new Vector3(radius), center.LookatAngles(cam) * Maths._rad2degf, center);
                context.glPushMatrix();
                context.glMultMatrix((float *)&m);

                //Orb
                context.glColor(0.7f, 0.7f, 0.7f, 0.15f);
                sphere.Call();

                context.glDisable((uint)GLEnableCap.DepthTest);

                //Container
                context.glColor(0.4f, 0.4f, 0.4f, 1.0f);
                circle.Call();

                //Circ
                if (_snapCirc)
                {
                    context.glColor(1.0f, 1.0f, 0.0f, 1.0f);
                }
                else
                {
                    context.glColor(1.0f, 0.8f, 0.5f, 1.0f);
                }
                context.glScale(_circOrbScale, _circOrbScale, _circOrbScale);
                circle.Call();

                //Pop
                context.glPopMatrix();

                context.glEnable(GLEnableCap.DepthTest);

                //Enter local space
                m = Matrix.TransformMatrix(new Vector3(radius), bone._frameMatrix.GetAngles(), center);
                context.glPushMatrix();
                context.glMultMatrix((float *)&m);

                //Z
                if (_snapZ)
                {
                    context.glColor(1.0f, 1.0f, 0.0f, 1.0f);
                }
                else
                {
                    context.glColor(0.0f, 0.0f, 1.0f, 1.0f);
                }
                circle.Call();

                context.glRotate(90.0f, 0.0f, 1.0f, 0.0f);

                //X
                if (_snapX)
                {
                    context.glColor(1.0f, 1.0f, 0.0f, 1.0f);
                }
                else
                {
                    context.glColor(1.0f, 0.0f, 0.0f, 1.0f);
                }
                circle.Call();

                context.glRotate(90.0f, 1.0f, 0.0f, 0.0f);

                //Y
                if (_snapY)
                {
                    context.glColor(1.0f, 1.0f, 0.0f, 1.0f);
                }
                else
                {
                    context.glColor(0.0f, 1.0f, 0.0f, 1.0f);
                }
                circle.Call();

                //Pop
                context.glPopMatrix();

                //Clear depth buffer for next operation
                context.glClear(GLClearMask.DepthBuffer);
            }

            //Render invisible depth orbs
            context.glColorMask(false, false, false, false);

            if (_targetModel != null && _targetModel._boneList != null)
            {
                GLDisplayList list = context.GetSphereList();
                foreach (MDL0BoneNode bone in _targetModel._boneList)
                {
                    RenderOrbRecursive(bone, context, list);
                }
            }

            context.glColorMask(true, true, true, true);
        }
Beispiel #9
0
 public GLArea(int[] attributeList, GLArea share)
 {
     DoubleBuffered = false;
     context        = GLContext.CreateContext(attributeList,
                                              share != null ? share.context : null, IntPtr.Zero);
 }
        public static void Initialize(GLContext control)
        {
            if (DefaultShaderProgram != null)
            {
                return;
            }

            if (DefaultShaderProgram == null)
            {
                string vert = @"#version 330
                        layout (location = 0) in vec2 aPos;
                        layout (location = 1) in vec2 aTexCoords;

                        out vec2 TexCoords;

                        void main()
                        {
                            gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0); 
                            TexCoords = aTexCoords;
                        }";
                string frag = @"#version 330 core
                    out vec4 FragColor;
  
                    in vec2 TexCoords;

                    uniform sampler2D scene;
                    uniform sampler2D bloomBlur;
                    uniform float exposure;

                    void main()
                    {             
                        const float gamma = 2.2;
                        vec3 hdrColor = texture(scene, TexCoords).rgb;      
                        vec3 bloomColor = texture(bloomBlur, TexCoords).rgb * 0.7f;
                        hdrColor += bloomColor; // additive blending
                        // tone mapping
                     //   vec3 result = vec3(1.0) - exp(-hdrColor * exposure);
                        FragColor = vec4(hdrColor, 1.0);
                    }";


                DefaultShaderProgram = new ShaderProgram(
                    new FragmentShader(frag), new VertexShader(vert));

                int buffer = GL.GenBuffer();
                vao = new VertexBufferObject(buffer);
                vao.AddAttribute(0, 2, VertexAttribPointerType.Float, false, 16, 0);
                vao.AddAttribute(1, 2, VertexAttribPointerType.Float, false, 16, 8);
                vao.Initialize();

                Vector2[] positions = new Vector2[4]
                {
                    new Vector2(-1.0f, 1.0f),
                    new Vector2(-1.0f, -1.0f),
                    new Vector2(1.0f, 1.0f),
                    new Vector2(1.0f, -1.0f),
                };

                Vector2[] texCoords = new Vector2[4]
                {
                    new Vector2(0.0f, 1.0f),
                    new Vector2(0.0f, 0.0f),
                    new Vector2(1.0f, 1.0f),
                    new Vector2(1.0f, 0.0f),
                };

                List <float> list = new List <float>();
                for (int i = 0; i < 4; i++)
                {
                    list.Add(positions[i].X);
                    list.Add(positions[i].Y);
                    list.Add(texCoords[i].X);
                    list.Add(texCoords[i].Y);
                }

                Length = 4;

                float[] data = list.ToArray();
                GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw);
            }
            else
            {
                vao.Initialize();
                DefaultShaderProgram.Link();
            }
        }
        internal unsafe void DrawPlanes(GLContext context)
        {
            if (!_render)
            {
                return;
            }

            int lev = 0;

            if (_linkLeft._highlight)
            {
                lev++;
            }
            if (_linkRight._highlight)
            {
                lev++;
            }

            if (lev == 0)
            {
                context.glColor(0.0f, 0.9f, 0.9f, 0.8f);
            }
            else if (lev == 1)
            {
                context.glColor(1.0f, 0.5f, 0.5f, 0.8f);
            }
            else
            {
                context.glColor(0.9f, 0.0f, 0.9f, 0.8f);
            }

            context.glBegin(GLPrimitiveType.Quads);

            context.glVertex(_linkLeft._value._x, _linkLeft._value._y, 10.0f);
            context.glVertex(_linkLeft._value._x, _linkLeft._value._y, -10.0f);
            context.glVertex(_linkRight._value._x, _linkRight._value._y, -10.0f);
            context.glVertex(_linkRight._value._x, _linkRight._value._y, 10.0f);

            context.glEnd();

            if (lev == 0)
            {
                context.glColor(0.0f, 0.6f, 0.6f, 0.8f);
            }
            else if (lev == 1)
            {
                context.glColor(0.7f, 0.2f, 0.2f, 0.8f);
            }
            else
            {
                context.glColor(0.6f, 0.0f, 0.6f, 0.8f);
            }

            context.glBegin(GLPrimitiveType.Lines);

            context.glVertex(_linkLeft._value._x, _linkLeft._value._y, 10.0f);
            context.glVertex(_linkRight._value._x, _linkRight._value._y, 10.0f);
            context.glVertex(_linkLeft._value._x, _linkLeft._value._y, -10.0f);
            context.glVertex(_linkRight._value._x, _linkRight._value._y, -10.0f);

            context.glEnd();
        }
Beispiel #12
0
 public GLArea(int[] attributeList)
 {
     DoubleBuffered = false;
     context        = GLContext.CreateContext(attributeList, null, IntPtr.Zero);
 }
 public void Refesh(GLContext context)
 {
 }
 public void Detach(GLContext context)
 {
 }
 public void Attach(GLContext context)
 {
 }
Beispiel #16
0
        internal void Render(GLContext ctx)
        {
            if (!_render)
            {
                return;
            }

            //Set single bind matrix
            if (_singleBind != null)
            {
                ctx.glPushMatrix();
                Matrix m = _singleBind.Matrix;
                ctx.glMultMatrix((float *)&m);
            }

            //Enable arrays
            ctx.glEnableClientState(GLArrayType.VERTEX_ARRAY);

            if (_elemDef.Normals)
            {
                ctx.glEnableClientState(GLArrayType.NORMAL_ARRAY);
            }

            if (_elemDef.Colors[0])
            {
                ctx.glEnableClientState(GLArrayType.COLOR_ARRAY);
            }

            if ((_material != null) && (_material._children.Count > 0))
            {
                ctx.glEnableClientState(GLArrayType.TEXTURE_COORD_ARRAY);
                ctx.glEnable(GLEnableCap.Texture2D);
                foreach (MDL0MaterialRefNode mr in _material.Children)
                {
                    if (mr._texture.Enabled)
                    {
                        mr.Bind(ctx);
                    }
                }
                foreach (Primitive2 prim in _primitives)
                {
                    prim.PreparePointers(_elemDef, ctx);
                    prim.Render(ctx, 0);
                }
                ctx.glDisable((uint)GLEnableCap.Texture2D);
                ctx.glDisableClientState(GLArrayType.TEXTURE_COORD_ARRAY);
            }
            else
            {
                ctx.glDisable((uint)GLEnableCap.Texture2D);
                foreach (Primitive2 prim in _primitives)
                {
                    prim.PreparePointers(_elemDef, ctx);
                    prim.Render(ctx, -1);
                }
            }

            //Disable arrays
            if (_elemDef.Normals)
            {
                ctx.glDisableClientState(GLArrayType.NORMAL_ARRAY);
            }

            if (_elemDef.Colors[0])
            {
                ctx.glDisableClientState(GLArrayType.COLOR_ARRAY);
            }

            ctx.glDisableClientState(GLArrayType.VERTEX_ARRAY);

            //Pop matrix
            if (_singleBind != null)
            {
                ctx.glPopMatrix();
            }
        }
 public TripRepository(GLContext context)
 {
     _context = context;
 }
 private void SetShadowTexture(ShaderProgram shader, GLContext control)
 {
 }
Beispiel #19
0
 public void GenProgram(GLContext ctx)
 {
     _context = ctx;
 }
        public void Draw(GLContext control, GLFrameworkEngine.Pass pass, BfresRender parentRender)
        {
            if (disposed || !IsVisible)
            {
                return;
            }

            GL.Enable(EnableCap.TextureCubeMapSeamless);

            if (pass == GLFrameworkEngine.Pass.OPAQUE && Meshes.Any(x => x.IsSelected))
            {
                GL.Enable(EnableCap.StencilTest);
                GL.Clear(ClearBufferMask.StencilBufferBit);
                GL.ClearStencil(0);
                GL.StencilFunc(StencilFunction.Always, 0x1, 0x1);
                GL.StencilOp(StencilOp.Keep, StencilOp.Replace, StencilOp.Replace);
            }

            //Go through each mesh and map materials using shader programs
            var meshes = RenderLayer.Sort(this);

            foreach (var mesh in meshes)
            {
                if (mesh.Pass != pass || !mesh.IsVisible ||
                    mesh.IsDepthShadow || mesh.IsCubeMap || mesh.UseColorBufferPass)
                {
                    continue;
                }

                //Load the material data
                var material = (FMAT)mesh.Shape.Material;
                mesh.Material = material;
                //Update the parent renderer
                ((BfresMaterialAsset)mesh.MaterialAsset).ParentRenderer = parentRender;

                if (!ModelData.Skeleton.Bones[mesh.BoneIndex].Visible)
                {
                    continue;
                }

                RenderMesh(control, mesh);
            }

            GL.DepthMask(true);
            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.TextureCubeMapSeamless);
            GL.Disable(EnableCap.AlphaTest);
            GL.Disable(EnableCap.Blend);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);

            if (meshes.Any(x => x.UseColorBufferPass))
            {
                ScreenBufferTexture.FilterScreen(control);
            }

            foreach (var mesh in meshes.Where(x => x.UseColorBufferPass))
            {
                if (pass != mesh.Pass || !mesh.IsVisible)
                {
                    continue;
                }

                //Load the material data
                var material = (FMAT)mesh.Shape.Material;
                mesh.Material = material;
                ((BfresMaterialAsset)mesh.MaterialAsset).ParentRenderer = parentRender;

                if (!ModelData.Skeleton.Bones[mesh.BoneIndex].Visible)
                {
                    continue;
                }

                RenderMesh(control, mesh);
            }

            if (Runtime.RenderSettings.WireframeOverlay)
            {
                DrawWireframeOutline(control);
            }

            if (pass == GLFrameworkEngine.Pass.TRANSPARENT)
            {
                DrawSelection(control, parentRender.IsSelected || this.IsSelected);
            }

            GL.DepthMask(true);
            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.TextureCubeMapSeamless);
            GL.Disable(EnableCap.AlphaTest);
            GL.Disable(EnableCap.Blend);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
        }
Beispiel #21
0
        public void Render(GLContext ctx, MDL0MaterialNode node)
        {
            ctx.glEnable(GLEnableCap.FRAGMENT_PROGRAM_ARB);
            uint id;

            ctx.glGenProgramsARB(1, &id);
            if ((programHandle = id) == 0)
            {
                ctx.CheckErrors();
            }
            _context = ctx;
            int version = (int)(new string((sbyte *)ctx.glGetString(0x1F02)))[0];

            if (version < 2)
            {
                MessageBox.Show("You need at least OpenGL 2.0 to render shaders.",
                                "GLSL not supported", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            _renderChange = true;
            if (_renderChange)
            {
                //Test shader
                shader = @"uniform sampler2D samp0, samp1, samp2;
                void main(void) 
                { 
                    gl_FragColor = vec4 (1.0, 0.0, 0.0, 1.0);
                }
                ";
                vs     = @"
                void main(void)
                {
                  gl_Position = ftransform(); // gl_ModelViewProjectionMatrix * gl_Vertex;
                }
                ";
                //CreateGLSLShader(node);
            }

            if (!written)
            {
                Console.WriteLine(shader);
                written = true;
            }

            //Create shader
            fragmentHandle = (uint)_context.glCreateShader(ShaderType.FragmentShader);
            vertexHandle   = (uint)_context.glCreateShader(ShaderType.VertexShader);

            //Create program
            //shaderProgramHandle = _context.glCreateProgram();

            //Set the shader code
            _context.ShaderSource((int)fragmentHandle, shader);
            _context.ShaderSource((int)vertexHandle, vs);
            //_context.glProgramStringARB(AssemblyProgramTargetArb.FragmentProgram, OpenGL.etc.ArbVertexProgram.ProgramFormatAsciiArb, shader.Length, shader);

            //Compile the shader
            _context.glCompileShader(fragmentHandle);
            _context.glCompileShader(vertexHandle);
            //_context.glBindProgramARB(AssemblyProgramTargetArb.FragmentProgram, (int)shaderProgramHandle);

            //Attach the shader to the program
            //_context.glAttachObjectARB(shaderProgramHandle, fragmentShaderHandle);

            //Check to see if the shader compiled correctly
            //_context.GetShaderInfoLog(fragmentObject, out info);
            //_context.GetShader(fragmentObject, ShaderParameter.CompileStatus, out status_code);

            //if (status_code != 1)
            //    throw new ApplicationException(info);

            _context.glAttachShader(programHandle, fragmentHandle);
            _context.glAttachShader(programHandle, vertexHandle);
            _context.glLinkProgram(programHandle);
            _context.glUseProgram(programHandle);
            //_context.glUseProgramObjectARB(shaderProgramHandle);

            ctx.glDisable((uint)GLEnableCap.FRAGMENT_PROGRAM_ARB);
            ctx.glDisable((uint)GLEnableCap.VERTEX_PROGRAM_ARB);

            rendered = true;
        }
Beispiel #22
0
 /// <summary>
 /// Checks if the program needs to be reloaded from a change in shader pass.
 /// </summary>
 public virtual void CheckProgram(GLContext control, BfresMeshAsset mesh, int pass = 0)
 {
 }
 public static GLTexture2D GetColorBuffer(GLContext control)
 {
     return(ScreenBuffer);
 }
Beispiel #24
0
 //------------------------------------------------------------------------------------------------------------------------
 //														RenderSelf()
 //------------------------------------------------------------------------------------------------------------------------
 protected override void RenderSelf(GLContext glContext)
 {
 }
        public static void CreateLightPrepassTexture(GLContext control,
                                                     GLTexture normalsTexture, GLTexture depthTexture, GLTexture output)
        {
            GL.BindTexture(output.Target, 0);

            if (Filter == null)
            {
                Init(control.Width, control.Height);
            }

            Filter.Bind();

            if (Filter.Width != control.Width || Filter.Height != control.Height)
            {
                Filter.Resize(control.Width, control.Height);
            }

            if (output.Width != control.Width || output.Height != control.Height)
            {
                output.Bind();
                if (output is GLTexture2DArray)
                {
                    GL.TexImage3D(output.Target, 0, output.PixelInternalFormat,
                                  control.Width, control.Height, 1, 0, output.PixelFormat, output.PixelType, IntPtr.Zero);
                }
                else
                {
                    GL.TexImage2D(output.Target, 0, output.PixelInternalFormat,
                                  control.Width, control.Height, 0, output.PixelFormat, output.PixelType, IntPtr.Zero);
                }
                output.Unbind();
            }

            GL.Viewport(0, 0, control.Width, control.Height);

            for (int i = 0; i < 1; i++)
            {
                if (output is GLTexture2DArray)
                {
                    GL.FramebufferTextureLayer(FramebufferTarget.Framebuffer,
                                               FramebufferAttachment.ColorAttachment0, output.ID, 0, i);
                }
                else
                {
                    GL.FramebufferTexture(FramebufferTarget.Framebuffer,
                                          FramebufferAttachment.ColorAttachment0, output.ID, 0);
                }
            }


            GL.ClearColor(0, 0, 0, 0);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            SceneLightManager.DrawSceneLights(control.Camera, normalsTexture, depthTexture);
            CausticLightManager.DrawCaustics(control, normalsTexture, depthTexture);

            var errorcheck = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);

            if (errorcheck != FramebufferErrorCode.FramebufferComplete)
            {
                throw new Exception(errorcheck.ToString());
            }

            GL.UseProgram(0);
            Filter.Unbind();
        }
Beispiel #26
0
 //------------------------------------------------------------------------------------------------------------------------
 //														RenderSelf()
 //------------------------------------------------------------------------------------------------------------------------
 override protected void RenderSelf(GLContext glContext)
 {
     //empty
 }
Beispiel #27
0
 internal override void Bind(GLContext ctx)
 {
     _render = true;
 }
Beispiel #28
0
        public static void CreateCubemap(GLContext control, GLTextureCube cubemapInput,
                                         GLTexture cubemapOutput, int layer, int numMips)
        {
            int size = cubemapInput.Width;

            Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(90), 1.0f, 0.1f, 10.0f);

            Matrix4[] captureViews =
            {
                Matrix4.LookAt(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(1.0f,   0.0f,  0.0f), new Vector3(0.0f, -1.0f,  0.0f)),
                Matrix4.LookAt(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(-1.0f,  0.0f,  0.0f), new Vector3(0.0f, -1.0f,  0.0f)),
                Matrix4.LookAt(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f,   1.0f,  0.0f), new Vector3(0.0f,  0.0f,  1.0f)),
                Matrix4.LookAt(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f,  -1.0f,  0.0f), new Vector3(0.0f,  0.0f, -1.0f)),
                Matrix4.LookAt(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f,   0.0f,  1.0f), new Vector3(0.0f, -1.0f,  0.0f)),
                Matrix4.LookAt(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f,   0.0f, -1.0f), new Vector3(0.0f, -1.0f,  0.0f)),
            };

            GL.BindTexture(TextureTarget.TextureCubeMap, 0);

            //Bind the cubemap's texture into a filtered quad.
            //Bind the drawn filter to a cubemap array layer
            Framebuffer frameBuffer = new Framebuffer(FramebufferTarget.Framebuffer, size, size, PixelInternalFormat.Rgba32f);

            frameBuffer.Bind();

            GL.Disable(EnableCap.Blend);

            var cubemapFilter = GlobalShaders.GetShader("CUBEMAP_HDRDECODE");

            cubemapFilter.Enable();

            GL.ActiveTexture(TextureUnit.Texture0 + 1);
            cubemapInput.Bind();
            cubemapFilter.SetInt("cubemapTexture", 1);
            cubemapFilter.SetMatrix4x4("projection", ref projection);
            cubemapFilter.SetFloat("gamma", 2.2f);
            cubemapFilter.SetFloat("range", 1024.0f);
            cubemapFilter.SetFloat("scale", 4.0f);

            GL.Disable(EnableCap.CullFace);
            for (int mip = 0; mip < numMips; mip++)
            {
                int mipWidth  = (int)(size * Math.Pow(0.5, mip));
                int mipHeight = (int)(size * Math.Pow(0.5, mip));

                frameBuffer.Resize(mipWidth, mipHeight);
                GL.Viewport(0, 0, mipWidth, mipHeight);

                cubemapFilter.SetFloat("mipLevel", mip);
                for (int i = 0; i < 6; i++)
                {
                    cubemapFilter.SetInt("faceLevel", i);

                    //attach face to fbo as color attachment 0
                    if (cubemapOutput is GLTextureCubeArray)
                    {
                        GL.FramebufferTextureLayer(FramebufferTarget.Framebuffer,
                                                   FramebufferAttachment.ColorAttachment0, cubemapOutput.ID, mip, (layer * 6) + i);
                    }
                    else
                    {
                        GL.FramebufferTexture2D(FramebufferTarget.Framebuffer,
                                                FramebufferAttachment.ColorAttachment0,
                                                TextureTarget.TextureCubeMapPositiveX + i, cubemapOutput.ID, mip);
                    }

                    cubemapFilter.SetMatrix4x4("view", ref captureViews[i]);

                    GL.ClearColor(0, 0, 0, 1);
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                    RenderTools.DrawCube();
                }
            }

            var errorcheck = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);

            if (errorcheck != FramebufferErrorCode.FramebufferComplete)
            {
                throw new Exception(errorcheck.ToString());
            }

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.Blend);

            frameBuffer.Dispoe();
            frameBuffer.DisposeRenderBuffer();

            GL.UseProgram(0);
        }
Beispiel #29
0
        // Methods handled by this control itself; called by the operating system.
        // In many cases, when one of the following methods is called by the 
        // operating system, the method will call a corrsponding method to invoke
        // event handlers set by the client of this control.

        protected override void OnPaint(PaintEventArgs e)
        {
            // If in designer mode, then just fill the area with the BackColor color.
            if ((DesignMode) || (false == mAttemptedInitialization))
            {
                e.Graphics.Clear(BackColor);

                if (DesignMode)
                {
                    return;
                }
            }

            if (false == mAttemptedInitialization)
            {
                mAttemptedInitialization = true;

                fGLContext = new GLContext(Handle, 32, 24, PFDFlags.DoubleBuffer);
                mGR = new GraphicsInterface(fGLContext);
                fGLContext.MakeCurrentContext();

                // Set some default drawing conditions
                mGR.Buffers.ColorBuffer.Color = new ColorRGBA(BackColor.R / 255.0f, BackColor.G / 255.0f, BackColor.B / 255.0f, 1.0f);

                InvokeOpenGLStarted();

                base.OnPaint(e); // Triggers Paint *event*; thus, our override gets called before the event

                return;
            }

            // Set some default drawing conditions
            mGR.Buffers.ColorBuffer.Color = new ColorRGBA(BackColor.R / 255.0f, BackColor.G / 255.0f, BackColor.B / 255.0f, 1.0f);
            fGLContext.MakeCurrentContext();

            base.OnPaint(e); // Triggers Paint *event*; thus, our override gets called before the event
        }
Beispiel #30
0
 /// <summary>
 /// Returns 'true' if specified key was released during the current frame
 /// </summary>
 /// <param name='key'>
 /// Key number, use Key.KEYNAME or integer value.
 /// </param>
 public static bool GetKeyUp(int key)
 {
     return(GLContext.GetKeyUp(key));
 }
Beispiel #31
0
 public Display(GLCapabilities capabilities) : base(Unwrap((AWTGraphicsConfiguration)GLDrawableFactory.GetFactory().ChooseGraphicsConfiguration(capabilities, null, null)))
 {
     drawable = GLDrawableFactory.GetFactory().GetGLDrawable(this, capabilities, null);
     context  = drawable.CreateContext(null);
 }
Beispiel #32
0
 internal override void Unbind(GLContext ctx)
 {
     //foreach (Primitive prim in _primitives)
     //    prim.Dispose();
 }
Beispiel #33
0
        public override void SetTextureUniforms(GLContext control, ShaderProgram shader, STGenericMaterial mat)
        {
            var bfresMaterial = (FMAT)mat;

            GL.ActiveTexture(TextureUnit.Texture0 + 1);
            GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.ID);

            int id = 1;

            var pixelShader = ShaderModel.GetGX2PixelShader(BinaryIndex);

            foreach (var sampler in pixelShader.Samplers)
            {
                GL.ActiveTexture(TextureUnit.Texture0 + id);

                switch (sampler.Name)
                {
                case "ice_cube": IceCubeTexture.Bind(); break;

                case "ice_toon": IceToonTexture.Bind(); break;

                case "light_pre_pass": LightPPTexture.Bind(); break;

                case "linear_depth": LinearDepthTexture.Bind(); break;

                case "shadow_pre_pass": ShadowTexture.Bind(); break;

                case "projection_map": ProjectionTexture.Bind(); break;

                default:
                    ProjectionTexture.Bind(); break;
                }
                this.SetSampler(shader, (int)sampler.Location, ref id);
            }

            for (int i = 0; i < bfresMaterial.TextureMaps?.Count; i++)
            {
                var name    = mat.TextureMaps[i].Name;
                var sampler = mat.TextureMaps[i].Sampler;
                //Lookup samplers targeted via animations and use that texture instead if possible
                if (bfresMaterial.AnimatedSamplers.ContainsKey(sampler))
                {
                    name = bfresMaterial.AnimatedSamplers[sampler];
                }

                var location = this.GetSamplerLocation(bfresMaterial.Samplers[i]);
                if (location == -1)
                {
                    continue;
                }

                if (name == "ZBtoonEX")
                {
                    GL.ActiveTexture(TextureUnit.Texture0 + id);
                    ToonTexture.Bind();
                    this.SetSampler(shader, (int)location, ref id);
                    continue;
                }

                var binded = BindTexture(shader, GetTextures(), mat.TextureMaps[i], name, id);
                this.SetSampler(shader, (int)location, ref id);
            }

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
Beispiel #34
0
 public UserRepository(GLContext context)
 {
     _context = context;
 }
Beispiel #35
0
        internal void Render(GLContext ctx)
        {
            if (!_visible)
            {
                return;
            }

            //Set single bind matrix
            if (_attachedBone != null)
            {
                ctx.glPushMatrix();

                Matrix m = _attachedBone.FrameMatrix;
                ctx.glMultMatrix((float *)&m);
            }

            //Enable arrays
            ctx.glEnableClientState(GLArrayType.VERTEX_ARRAY);

            if (_elemDef.Normals)
            {
                ctx.glEnableClientState(GLArrayType.NORMAL_ARRAY);
            }

            if (_elemDef.Colors[0])
            {
                ctx.glEnableClientState(GLArrayType.COLOR_ARRAY);
            }

            //Material cannot be null!
            if (_material.Children.Count == 0)
            {
                ctx.glDisable((uint)GLEnableCap.Texture2D);
                foreach (Primitive2 prim in _primitives)
                {
                    prim.PreparePointers(_elemDef, ctx);
                    prim.Render(ctx, -1);
                }
            }
            else
            {
                ctx.glEnableClientState(GLArrayType.TEXTURE_COORD_ARRAY);
                ctx.glEnable(GLEnableCap.Texture2D);
                foreach (MDL0MaterialRefNode mr in _material.Children)
                {
                    //if ((mr._layerId1 == 0) || (!mr._textureReference.Enabled))
                    //    continue;
                    if (!mr._texture.Enabled)
                    {
                        continue;
                    }

                    mr.Bind(ctx);
                    foreach (Primitive2 prim in _primitives)
                    {
                        prim.PreparePointers(_elemDef, ctx);
                        prim.Render(ctx, 0);
                    }
                }
                ctx.glDisable((uint)GLEnableCap.Texture2D);
                ctx.glDisableClientState(GLArrayType.TEXTURE_COORD_ARRAY);
            }

            //Disable arrays
            if (_elemDef.Normals)
            {
                ctx.glDisableClientState(GLArrayType.NORMAL_ARRAY);
            }

            if (_elemDef.Colors[0])
            {
                ctx.glDisableClientState(GLArrayType.COLOR_ARRAY);
            }

            ctx.glDisableClientState(GLArrayType.VERTEX_ARRAY);

            //Pop matrix
            if (_attachedBone != null)
            {
                ctx.glPopMatrix();
            }
        }