Пример #1
0
NE_API void set_camera(int32 handle) {
	Assert(handle >= 0 && handle < 8);
	ortho_camera* camera = ortho_cameras[handle];
	glm::mat4 view = ortho_view(camera->transform.position, camera->transform.rotation.z, camera->zoom);
	glm::mat4 projection = ortho_projection(camera->transform.scale.xy, camera->near_clipping_plane, camera->far_clipping_plane);
	set_view_projection_uniforms(view, projection);
}
Пример #2
0
NE_API void set_camera(ortho_camera* camera) {
	Assert(camera);
	glm::mat4 view = ortho_view(camera->transform.position, camera->transform.rotation.z, camera->zoom);
	glm::mat4 projection = ortho_projection(camera->transform.scale.xy, camera->near_clipping_plane, camera->far_clipping_plane);
	set_view_projection_uniforms(view, projection);
}
Пример #3
0
void EngineGLFW::programmableRendererDrawLists(ImDrawData * draw_data)
{
    GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
    
    glEnable(GL_SCISSOR_TEST);
    
    shader.begin();
    
    float width = ofGetWidth();
    float height = ofGetHeight();
    ofMatrix4x4 ortho_projection(
                                 2.f / width,  0.f,            0.f,  0.f,
                                 0.f,          2.f / -height,  0.f,  0.f,
                                 0.f,          0.f,           -1.f,  0.f,
                                 -1.f,          1.f,            0.f,  1.f
                                 );
    shader.setUniformMatrix4f("ProjMat", ortho_projection, 1);
    
    glBindVertexArray(vaoHandle);
    
    for(int n = 0; n < draw_data->CmdListsCount; n++)
    {
        const ImDrawList * cmd_list = draw_data->CmdLists[n];
        const ImDrawIdx * idx_buffer_offset = 0;
        
        glBindBuffer(GL_ARRAY_BUFFER, vboHandle);
        glBufferData(
                     GL_ARRAY_BUFFER,
                     (GLsizeiptr)cmd_list->VtxBuffer.size() * sizeof(ImDrawVert),
                     (GLvoid *)&cmd_list->VtxBuffer.front(),
                     GL_STREAM_DRAW
                     );
        
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementsHandle);
        glBufferData(
                     GL_ELEMENT_ARRAY_BUFFER,
                     (GLsizeiptr)cmd_list->IdxBuffer.size() * sizeof(ImDrawIdx),
                     (GLvoid *)&cmd_list->IdxBuffer.front(),
                     GL_STREAM_DRAW
                     );
        
        for(const ImDrawCmd * pcmd = cmd_list->CmdBuffer.begin(); pcmd != cmd_list->CmdBuffer.end(); pcmd++)
        {
            if(pcmd->UserCallback)
            {
                pcmd->UserCallback(cmd_list, pcmd);
            } else {
                ofTexture tex;
                tex.texData.textureTarget = GL_TEXTURE_2D;
                tex.setUseExternalTextureID((intptr_t)pcmd->TextureId);
                tex.bind();
                glScissor(
                          (int)pcmd->ClipRect.x,
                          (int)(height - pcmd->ClipRect.w),
                          (int)(pcmd->ClipRect.z - pcmd->ClipRect.x),
                          (int)(pcmd->ClipRect.w - pcmd->ClipRect.y)
                          );
                glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, GL_UNSIGNED_INT, idx_buffer_offset);
                tex.unbind();
            }
            idx_buffer_offset += pcmd->ElemCount;
        }
    }
    
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindVertexArray(0);
    
    shader.end();
    
    last_enable_scissor_test ? glEnable(GL_SCISSOR_TEST) : glDisable(GL_SCISSOR_TEST);
}
Пример #4
0
void ImGuiRenderer::renderDrawList(ImDrawData *draw_data)
{
    // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
    ImGuiIO& io = ImGui::GetIO();
    int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x);
    int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y);
    if (fb_width == 0 || fb_height == 0)
        return;
    draw_data->ScaleClipRects(io.DisplayFramebufferScale);

    // Backup GL state
    GLint last_active_texture; glGetIntegerv(GL_ACTIVE_TEXTURE, &last_active_texture);
    glActiveTexture(GL_TEXTURE0);
    GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
    GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
    GLint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
    GLint last_element_array_buffer; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer);
    GLint last_vertex_array; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
    GLint last_blend_src_rgb; glGetIntegerv(GL_BLEND_SRC_RGB, &last_blend_src_rgb);
    GLint last_blend_dst_rgb; glGetIntegerv(GL_BLEND_DST_RGB, &last_blend_dst_rgb);
    GLint last_blend_src_alpha; glGetIntegerv(GL_BLEND_SRC_ALPHA, &last_blend_src_alpha);
    GLint last_blend_dst_alpha; glGetIntegerv(GL_BLEND_DST_ALPHA, &last_blend_dst_alpha);
    GLint last_blend_equation_rgb; glGetIntegerv(GL_BLEND_EQUATION_RGB, &last_blend_equation_rgb);
    GLint last_blend_equation_alpha; glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &last_blend_equation_alpha);
    GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
    GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box);
    GLboolean last_enable_blend = glIsEnabled(GL_BLEND);
    GLboolean last_enable_cull_face = glIsEnabled(GL_CULL_FACE);
    GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST);
    GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);

    // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
    glEnable(GL_BLEND);
    glBlendEquation(GL_FUNC_ADD);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_CULL_FACE);
    glDisable(GL_DEPTH_TEST);
    glEnable(GL_SCISSOR_TEST);

    // Setup viewport, orthographic projection matrix
    glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
    //const float ortho_projection[4][4] =
    ngl::Mat4 ortho_projection
    (
         2.0f/io.DisplaySize.x, 0.0f,                   0.0f, 0.0f ,
         0.0f,                  2.0f/-io.DisplaySize.y, 0.0f, 0.0f ,
         0.0f,                  0.0f,                  -1.0f, 0.0f ,
        -1.0f,                  1.0f,                   0.0f, 1.0f
    );
    ngl::ShaderLib *shader = ngl::ShaderLib::instance();
    shader->use(ImGUIShader);
    shader->setUniform("Texture",0);
    shader->setUniform("ProjMtx",ortho_projection);
    std::unique_ptr<ngl::AbstractVAO> vao;
    vao=ngl::VAOFactory::createVAO(ngl::simpleIndexVAO,GL_TRIANGLES);

    vao->bind();
    for (int n = 0; n < draw_data->CmdListsCount; n++)
    {
        const ImDrawList* cmd_list = draw_data->CmdLists[n];
        const ImDrawIdx* idx_buffer_offset = nullptr;
        vao->setData(ngl::SimpleIndexVAO::VertexData(
                         cmd_list->VtxBuffer.Size * sizeof(ImDrawVert),
                         cmd_list->VtxBuffer.Data->pos.x,
                         (GLsizeiptr)cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx),(const GLvoid*)cmd_list->IdxBuffer.Data,
                         sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT));
        vao->setVertexAttributePointer(0,2,GL_FLOAT,sizeof(ImDrawVert), 0);
        vao->setVertexAttributePointer(1,2,GL_FLOAT,sizeof(ImDrawVert), 2);
        vao->setVertexAttributePointer(2,4,GL_UNSIGNED_BYTE,sizeof(ImDrawVert), 4,GL_TRUE);

        vao->setNumIndices(cmd_list->IdxBuffer.Size);
        for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
        {
            const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
            if (pcmd->UserCallback)
            {
                pcmd->UserCallback(cmd_list, pcmd);
            }
            else
            {
                glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
                glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
               // glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);
               vao->draw();
            }
            idx_buffer_offset += pcmd->ElemCount;
        }
    }
    vao->unbind();
    // Restore modified GL state
    glUseProgram(last_program);
    glBindTexture(GL_TEXTURE_2D, last_texture);
    glActiveTexture(last_active_texture);
    glBindVertexArray(last_vertex_array);
    glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer);
    glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha);
    glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
    if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
    if (last_enable_cull_face) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
    if (last_enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
    if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
    glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
    glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]);
}
Пример #5
0
NE_API glm::mat4 ortho_view_projection(const vector3f& position, const vector2f& scale, float zoom, float near, float far, float angle) {
	return ortho_view(position, angle, zoom) * ortho_projection(scale, near, far);
}