/// <summary> /// Create or update resources defined by this IGraphicsState, based on the associated <see cref="ShaderProgram"/>. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for allocating resources. /// </param> /// <param name="shaderProgram"> /// A <see cref="ShaderProgram"/> that will be used in conjunction with this IGraphicsState. /// </param> private void CreateUniformBuffer(GraphicsContext ctx, ShaderProgram shaderProgram) { if (ctx.Extensions.UniformBufferObject_ARB == false) { return; // No uniform buffer support } if (UniformBlockTag == null) { return; // No uniform block support by this class } if (shaderProgram == null) { return; // No uniform buffer support by fixed pipeline } Debug.Assert(_UniformBuffer == null); if (shaderProgram.IsActiveUniformBlock(UniformBlockTag)) { _UniformBuffer = shaderProgram.CreateUniformBlock(UniformBlockTag, UniformBlockHint); _UniformBuffer.Create(ctx); _UniformBuffer.IncRef(); } // Base implementation base.CreateState(ctx, shaderProgram); }
public void Render() { //-- var ubo = new UniformBufferObject(); ubo.Create(); // if (RenderContext.LightObjects.Count >= 2) // { // var lightsData = new GlslLight[2]; // lightsData[0].Position = RenderContext.LightObjects[0].Position; // lightsData[0].Color = new Vector3(0.5f, 0.5f, 0.5f); // lightsData[0].ShadowLayer = RenderContext.LightObjects[0].ShadowTextureIndex; // lightsData[0].DirectionalLight = RenderContext.LightObjects[0].LightType == LightType.Directional ? 1 : 0; // lightsData[0].LightSpaceMatrix = Matrix4.Transpose(RenderContext.LightObjects[0].LightCamera.ViewMatrix * RenderContext.LightObjects[0].LightCamera.ProjectionMatrix); // lightsData[0].Linear = 0.1f; // lightsData[0].Quadric = 0f; // lightsData[1].Position = RenderContext.LightObjects[1].Position; // lightsData[1].Color = new Vector3(0.5f, 0.5f, 0.5f); // lightsData[1].ShadowLayer = RenderContext.LightObjects[1].ShadowTextureIndex; // lightsData[1].DirectionalLight = RenderContext.LightObjects[1].LightType == LightType.Directional ? 1 : 0; // lightsData[1].LightSpaceMatrix = Matrix4.Transpose(RenderContext.LightObjects[1].LightCamera.ViewMatrix * RenderContext.LightObjects[1].LightCamera.ProjectionMatrix); // lightsData[1].Linear = 0.1f; // lightsData[1].Quadric = 0f; // ubo.SetData(BufferData.Create(lightsData)); // ubo.SetBindingPoint(RenderContext.LightBinding); // } if (RenderContext.LightObjects.Count > 0) { var lightDataList = new List <GlslLight>(); foreach (var light in RenderContext.LightObjects) { var lightData = new GlslLight(); lightData.Position = light.Position; lightData.Color = light.Color; lightData.ShadowLayer = light.ShadowTextureIndex; lightData.DirectionalLight = light.LightType == LightType.Directional ? 1 : 0; lightData.LightSpaceMatrix = Matrix4.Transpose(light.LightCamera.ViewMatrix * light.LightCamera.ProjectionMatrix); lightData.Linear = light.Linear; lightData.Quadric = light.Quadric; lightData.FarPlane = light.LightCamera.FarPlane; lightData.Direction = light.Direction.Normalized(); lightDataList.Add(lightData); } ubo.SetData(BufferData.Create(lightDataList.ToArray())); ubo.SetBindingPoint(RenderContext.LightBinding); } //-- GL.Enable(EnableCap.DepthTest); //-- RenderContext.InitRender(); RenderContext.Render(); RenderContext.OnWorldRendered(); //-- // Configure // Render objects // Render Screen Surface //CheckForProgramError(); ubo.Free(); if (FlushRenderBackend == FlushRenderBackend.End) { GL.Finish(); } }