public void Init(MainWindow mainWindow) { m_program = OpenGLHelper._CompilerShader(vShaderStr, fShaderStr); m_meshData = OpenGLHelper.GetCubeMesh(); m_ptr = Marshal.AllocHGlobal(sizeof(float) * m_meshData.m_data.Length); Marshal.Copy(m_meshData.m_data, 0, m_ptr, m_meshData.m_data.Length); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(All.Lequal); GL.Enable(EnableCap.CullFace); OpenGLHelper.ClearGLError(); m_locAmbient = GL.GetUniformLocation(m_program, "ambientColor"); Debug.Log("m_locAmbient" + m_locAmbient); OpenGLHelper.CheckGLError(); m_locDiffuse = GL.GetUniformLocation(m_program, "diffuseColor"); Debug.Log("m_locDiffuse" + m_locDiffuse); m_locSpecular = GL.GetUniformLocation(m_program, "specularColor"); Debug.Log("m_locSpecular" + m_locSpecular); m_locLight = GL.GetUniformLocation(m_program, "vLightPosition"); Debug.Log("m_locLight" + m_locLight); m_locMVP = GL.GetUniformLocation(m_program, "mvpMatrix"); Debug.Log("m_locMVP" + m_locMVP); m_locMV = GL.GetUniformLocation(m_program, "mvMatrix"); Debug.Log("m_locMV" + m_locMV); //m_locNM = GL.GetUniformLocation(m_program, "normalMatrix"); m_width = mainWindow.Width; m_height = mainWindow.Height; }
public void Init(MainWindow mainWindow) { m_prePassProgram = OpenGLHelper._CompilerShader(prePassVShader, prePassFShader); m_lightPassProgram = OpenGLHelper._CompilerShader(lightPassVShader, lightPassFShader); m_meshData = OpenGLHelper.GetCubeMesh(); m_ptrCube = Marshal.AllocHGlobal(sizeof(float) * m_meshData.m_data.Length); Marshal.Copy(m_meshData.m_data, 0, m_ptrCube, m_meshData.m_data.Length); m_width = mainWindow.Width; m_height = mainWindow.Height; float[] quadVertices = new float[] { -1f, 1f, 0.0f, // Position 0 0.0f, 0.0f, // TexCoord 0 -1f, -1f, 0.0f, // Position 1 0.0f, 1.0f, // TexCoord 1 1f, -1f, 0.0f, // Position 2 1.0f, 1.0f, // TexCoord 2 1f, 1f, 0.0f, // Position 3 1.0f, 0.0f // TexCoord 3 }; m_ptrQuad = Marshal.AllocHGlobal(sizeof(float) * quadVertices.Length); Marshal.Copy(quadVertices, 0, m_ptrQuad, quadVertices.Length); m_gbuffer = GL.GenFramebuffer(); GL.BindFramebuffer(All.Framebuffer, m_gbuffer); GL.GenTextures(3, m_gbuffer_tex); GL.BindTexture(All.Texture2D, m_gbuffer_tex[0]); GL.TexStorage2D(All.Texture2D, 1, All.Rgba32f, m_width, m_height); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Nearest); GL.BindTexture(All.Texture2D, m_gbuffer_tex[1]); GL.TexStorage2D(All.Texture2D, 1, All.Rgba32f, m_width, m_height); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Nearest); GL.BindTexture(All.Texture2D, m_gbuffer_tex[2]); GL.TexStorage2D(All.Texture2D, 1, All.DepthComponent32f, m_width, m_height); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget2d.Texture2D, m_gbuffer_tex[0], 0); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment1, TextureTarget2d.Texture2D, m_gbuffer_tex[1], 0); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, TextureTarget2d.Texture2D, m_gbuffer_tex[2], 0); GL.BindFramebuffer(All.Framebuffer, 0); m_locLight = GL.GetUniformLocation(m_prePassProgram, "vLightPosition"); Debug.Log("m_locLight" + m_locLight); m_locMVP = GL.GetUniformLocation(m_prePassProgram, "mvpMatrix"); Debug.Log("m_locMVP" + m_locMVP); m_locMV = GL.GetUniformLocation(m_prePassProgram, "mvMatrix"); Debug.Log("m_locMV" + m_locMV); m_locAmbient = GL.GetUniformLocation(m_lightPassProgram, "ambientColor"); Debug.Log("m_locAmbient" + m_locAmbient); m_locDiffuse = GL.GetUniformLocation(m_lightPassProgram, "diffuseColor"); Debug.Log("m_locDiffuse" + m_locDiffuse); m_locTex0 = GL.GetUniformLocation(m_lightPassProgram, "gbuf_tex0"); Debug.Log("m_locTex0" + m_locTex0); m_locTex1 = GL.GetUniformLocation(m_lightPassProgram, "gbuf_tex1"); Debug.Log("m_locTex1" + m_locTex1); //fs_quad_vao = GL.GenVertexArray(); //GL.BindVertexArray(fs_quad_vao); }