public SplineTubesTess(string shaderPath, TessTubeShadingStyle shadingStyle, TessTubeRenderSetting renderSettings, BufferUsageHint bufferUsageHintType, int bufferMaxElementCount, int[] nodeCount, int vertexRingCount, int vertexRingVertexCount) : base(renderSettings.HasFlag(TessTubeRenderSetting.ShaderBufferTypeIsSSBO) ? ShaderBufferType.SSBO : ShaderBufferType.UBO, bufferUsageHintType, bufferMaxElementCount, nodeCount, 1 + vertexRingCount / 2) { this.shadingStyle = shadingStyle; this.renderSettings = renderSettings; this.vertexRingVertexCount = vertexRingVertexCount; this.vertexRingCount = vertexRingCount; this.maxLayerId = vertexRingCount - 1; if (shadingStyle == TessTubeShadingStyle.HardNormalWF || shadingStyle == TessTubeShadingStyle.BlueWF) renderSettings |= TessTubeRenderSetting.UseGeoShader; if (renderSettings.HasFlag(TessTubeRenderSetting.UseCaps)) cylIB = IndexBuffer.CreateClosedQuadCylinder(vertexRingVertexCount, vertexRingCount); else cylIB = IndexBuffer.CreateQuadCylinder(vertexRingVertexCount, vertexRingCount); var definesStr = shadingStyle.ToDefineString() + renderSettings.ToDefineString(); definesStr += "#define TUBES_BUFFER_SIZE " + this.shaderBuffer.Float4BlockCount.ToString(); definesStr += Environment.NewLine; definesStr += "#define VRING_VERTEX_COUNT " + vertexRingVertexCount.ToString(); definesStr += Environment.NewLine; definesStr += "#define VRING_COUNT " + vertexRingCount.ToString(); definesStr += Environment.NewLine; if (renderSettings.HasFlag(TessTubeRenderSetting.UseGeoShader)) { shader = new Shader( "#version 440", definesStr, shaderPath + ".defs", new Shader.Desc(ShaderType.VertexShader, shaderPath + ".vs"), new Shader.Desc(ShaderType.TessControlShader, shaderPath + ".tc"), new Shader.Desc(ShaderType.TessEvaluationShader, shaderPath + ".te"), new Shader.Desc(ShaderType.GeometryShader, shaderPath + ".gs"), new Shader.Desc(ShaderType.FragmentShader, shaderPath + ".fs")); } else { shader = new Shader( "#version 440", definesStr, shaderPath + ".defs", new Shader.Desc(ShaderType.VertexShader, shaderPath + ".vs"), new Shader.Desc(ShaderType.TessControlShader, shaderPath + ".tc"), new Shader.Desc(ShaderType.TessEvaluationShader, shaderPath + ".te"), new Shader.Desc(ShaderType.FragmentShader, shaderPath + ".fs")); } }
protected override void OnLoad(EventArgs e) { GL.ClearColor(Color4.Brown); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Less); //GL.Enable(EnableCap.CullFace); //GL.CullFace(CullFaceMode.Back); vertexBuffer = new VertexBuffer<Vector3> ( new Vector3(-1f, +1f, +1f), new Vector3(-1f, -1f, +1f), new Vector3(+1f, +1f, +1f), new Vector3(+1f, -1f, +1f), new Vector3(+1f, -1f, -1f), new Vector3(+1f, +1f, -1f), new Vector3(-1f, +1f, -1f), new Vector3(-1f, -1f, -1f) ); //indexBuffer = new IndexBuffer //( // 0, 1, 3, 2, // 2, 3, 4, 5, // 5, 4, 7, 6, // 6, 7, 1, 0, // 0, 2, 5, 6, // 1, 7, 4, 3 //); indexBuffer = IndexBuffer.CreateQuadCylinder(8, 16); string shaderPath = projectPath + "TessTriCube"; string shaderPath2 = projectPath + "TessQuadCube"; string shaderPath3 = projectPath + "TessCyl"; shader = new Shader( new Shader.Desc(ShaderType.VertexShader, shaderPath3 + ".vs"), new Shader.Desc(ShaderType.TessControlShader, shaderPath2 + ".tc"), //new Shader.Desc(ShaderType.TessControlShader, shaderPath + ".tc"), new Shader.Desc(ShaderType.TessEvaluationShader, shaderPath3 + ".te"), //new Shader.Desc(ShaderType.TessEvaluationShader, shaderPath + ".te"), new Shader.Desc(ShaderType.FragmentShader, shaderPath + ".ps")); shader.Bind(); //uniformScale = GL.GetUniformLocation(shaderProgramHandle, "scale"); //uniformMatViewProj = GL.GetUniformLocation(shader.Handle, "viewProjMat"); ubuffer = new ShaderBuffer(ShaderBufferType.UBO, 4, BufferUsageHint.StreamDraw); ubuffer.BindToIndex(0); //ubuffer.BindToProgram(shader.Handle, "shader_data"); shader.BindShaderBuffer(ubuffer, "shader_data"); query = new PerfQuery(); projMat = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI * 0.25f, Width / (float)Height, 1f, 5000f); }