Пример #1
0
    public void Init(MainWindow mainWindow)
    {
        m_program = OpenGLHelper._CompilerShader(vShaderStr, fShaderStr);



        int vtxStride = sizeof(float) * (VERTEX_POS_SIZE + VERTEX_COLOR_SIZE);

        GL.GenBuffers(2, m_vboBuff);
        GL.BindBuffer(BufferTarget.ArrayBuffer, m_vboBuff[0]);
        GL.BufferData(BufferTarget.ArrayBuffer, vtxStride * m_indices.Length, m_vertices, BufferUsageHint.StaticDraw);
        GL.BindBuffer(BufferTarget.ElementArrayBuffer, m_vboBuff[1]);
        GL.BufferData(BufferTarget.ElementArrayBuffer, sizeof(ushort) * m_indices.Length, m_indices, BufferUsageHint.StaticDraw);

        m_vaoId = GL.GenVertexArray();
        GL.BindVertexArray(m_vaoId);

        GL.BindBuffer(BufferTarget.ArrayBuffer, m_vboBuff[0]);
        GL.BindBuffer(BufferTarget.ElementArrayBuffer, m_vboBuff[1]);
        GL.EnableVertexAttribArray(VERTEX_POS_INDX);
        GL.EnableVertexAttribArray(VERTEX_COLOR_INDX);
        int offset = 0;

        GL.VertexAttribPointer(VERTEX_POS_INDX, VERTEX_POS_SIZE, VertexAttribPointerType.Float, false, vtxStride, offset);
        offset += VERTEX_POS_SIZE * sizeof(float);
        GL.VertexAttribPointer(VERTEX_COLOR_INDX, VERTEX_COLOR_SIZE, VertexAttribPointerType.Float, false, vtxStride, offset);

        GL.BindVertexArray(0);
    }
Пример #2
0
    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;
    }
Пример #3
0
    public void Init(MainWindow mainWindow)
    {
        m_program = OpenGLHelper._CompilerShader(vShaderStr, fShaderStr);

        m_textureId = CreateSimpleTexture2D();

        m_screenTexId = CreateScreenSizeTexture2D();

        float[] vVertices = new float[] { -0.5f, 0.5f, 0.0f,  // Position 0
                                          0.0f, 0.0f,         // TexCoord 0
                                          -0.5f, -0.5f, 0.0f, // Position 1
                                          0.0f, 1.0f,         // TexCoord 1
                                          0.5f, -0.5f, 0.0f,  // Position 2
                                          1.0f, 1.0f,         // TexCoord 2
                                          0.5f, 0.5f, 0.0f,   // Position 3
                                          1.0f, 0.0f          // TexCoord 3
        };
        m_ptr = Marshal.AllocHGlobal(sizeof(float) * vVertices.Length);
        Marshal.Copy(vVertices, 0, m_ptr, vVertices.Length);

        int pixelDataSize = mainWindow.Width * mainWindow.Height * 3 * sizeof(byte);

        byte[] pixelData = new byte[pixelDataSize];

        m_pboId = GL.GenBuffer();
        GL.BindBuffer(All.PixelPackBuffer, m_pboId);
        GL.BufferData(All.PixelPackBuffer, pixelData.Length, pixelData, All.DynamicCopy);
        GL.BindBuffer(All.PixelPackBuffer, 0);

        m_width  = mainWindow.Width;
        m_height = mainWindow.Height;
    }
Пример #4
0
    public void Init(MainWindow mainWindow)
    {
        m_mainWindow = mainWindow;

        m_renderPorgram     = OpenGLHelper._CompilerShader(m_vertexShaderSrc, m_pixelShaderSrc);
        m_vertexArrayObject = GL.GenVertexArray();
        GL.BindVertexArray(m_vertexArrayObject);
    }
Пример #5
0
    public void Init(MainWindow mainWindow)
    {
        m_program = OpenGLHelper._CompilerShader(vShaderStr, fShaderStr);

        m_textureId = CreateSimpleTexture2D();

        float[] vVertices = new float[] { -0.5f, 0.5f, 0.0f,  // Position 0
                                          0.0f, 0.0f,         // TexCoord 0
                                          -0.5f, -0.5f, 0.0f, // Position 1
                                          0.0f, 1.0f,         // TexCoord 1
                                          0.5f, -0.5f, 0.0f,  // Position 2
                                          1.0f, 1.0f,         // TexCoord 2
                                          0.5f, 0.5f, 0.0f,   // Position 3
                                          1.0f, 0.0f          // TexCoord 3
        };
        m_ptr = Marshal.AllocHGlobal(sizeof(float) * vVertices.Length);
        Marshal.Copy(vVertices, 0, m_ptr, vVertices.Length);
    }
Пример #6
0
 public void Init(MainWindow mainWindow)
 {
     m_program = OpenGLHelper._CompilerShader(vShaderStr, fShaderStr);
 }
Пример #7
0
    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);
    }