~unity-team/nux/nux.redirected-views

« back to all changes in this revision

Viewing changes to NuxGraphics/RenderingPipeAsm.cpp

  • Committer: Tarmac
  • Author(s): Jay Taoko
  • Date: 2012-09-18 14:21:37 UTC
  • mfrom: (660.1.2 nux.dash-to-preview)
  • Revision ID: tarmac-20120918142137-uvz785kmnt2s40qy
This branch introduces "Redirected Views" in Nux. Redirected views allows a view to be rendered inside its own texture and that texture is latter composited inside the main rendering.
This branch contains the required changes for redirected views. The opportunty was also taken to fix minor issues and introduce API changes.

== Core of the Redirected View
  Nux/Area.cpp
  Nux/Area.h
  Nux/Layout.cpp
  Nux/Layout.h
  Nux/View.cpp
  Nux/View.h

== Fixed ClientArea to work with RedirectedViews
  Nux/ClientArea.cpp
  Nux/ClientArea.h

== Concrete implementation of a view to replace InputArea in some locations
  Nux/BasicView.cpp
  Nux/BasicView.h

== Nux.h contains the Feature.h file of Nux
  Nux/Nux.h

== API change to frame buffer object architecture
  NuxGraphics/IOpenGLFrameBufferObject.cpp
  NuxGraphics/IOpenGLFrameBufferObject.h

== Added InitSlTexturePremultiplyShader shader
  NuxGraphics/RenderingPipeGLSL.cpp
  NuxGraphics/GraphicsEngine.cpp
  NuxGraphics/GraphicsEngine.h
  NuxGraphics/RenderingPipeAsm.cpp

== Fixed texture inversion
  NuxGraphics/RenderingPipe.cpp. Fixes: https://bugs.launchpad.net/bugs/1049593. Approved by Neil J. Patel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2518
2518
      SetViewport(0, 0, previous_width, previous_height);
2519
2519
    }
2520
2520
  }
 
2521
 
 
2522
  void GraphicsEngine::InitAsmTexturePremultiplyShader()
 
2523
  {
 
2524
    std::string AsmVtx = 
 
2525
      "!!ARBvp1.0                                 \n\
 
2526
      ATTRIB iPos         = vertex.position;      \n\
 
2527
      ATTRIB iColor       = vertex.attrib[3];     \n\
 
2528
      PARAM  mvp[4]       = {state.matrix.mvp};   \n\
 
2529
      OUTPUT oPos         = result.position;      \n\
 
2530
      OUTPUT oColor       = result.color;         \n\
 
2531
      OUTPUT oTexCoord0   = result.texcoord[0];   \n\
 
2532
      # Transform the vertex to clip coordinates. \n\
 
2533
      DP4   oPos.x, mvp[0], iPos;                     \n\
 
2534
      DP4   oPos.y, mvp[1], iPos;                     \n\
 
2535
      DP4   oPos.z, mvp[2], iPos;                     \n\
 
2536
      DP4   oPos.w, mvp[3], iPos;                     \n\
 
2537
      MOV   oColor, iColor;                           \n\
 
2538
      MOV   oTexCoord0, vertex.attrib[8];             \n\
 
2539
      END";
 
2540
 
 
2541
    std::string AsmFrg = 
 
2542
      "!!ARBfp1.0                                       \n\
 
2543
      TEMP tex0;                                        \n\
 
2544
      TEMP temp;                                        \n\
 
2545
      TEX tex0, fragment.texcoord[0], texture[0], 2D;   \n\
 
2546
      MUL temp.rgb, tex0, tex0.aaaa;                    \n\
 
2547
      MOV temp.a, tex0.aaaa;                            \n\
 
2548
      MUL result.color, fragment.color, temp;           \n\
 
2549
      END";
 
2550
 
 
2551
    std::string AsmFrgRect = 
 
2552
      "!!ARBfp1.0                                       \n\
 
2553
      TEMP tex0;                                        \n\
 
2554
      TEMP temp;                                        \n\
 
2555
      TEX tex0, fragment.texcoord[0], texture[0], RECT; \n\
 
2556
      MUL temp.rgb, tex0, tex0.aaaa;                    \n\
 
2557
      MOV temp.a, tex0.aaaa;                            \n\
 
2558
      MUL result.color, fragment.color, temp;           \n\
 
2559
      END";
 
2560
 
 
2561
    m_AsmTexturePremultiplyModColor = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
 
2562
    m_AsmTexturePremultiplyModColor->LoadVertexShader(AsmVtx.c_str());
 
2563
    m_AsmTexturePremultiplyModColor->LoadPixelShader(AsmFrg.c_str());
 
2564
    m_AsmTexturePremultiplyModColor->Link();
 
2565
 
 
2566
    m_AsmTexturePremultiplyRectModColor = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
 
2567
    m_AsmTexturePremultiplyRectModColor->LoadVertexShader(AsmVtx.c_str());
 
2568
    m_AsmTexturePremultiplyRectModColor->LoadPixelShader(AsmFrgRect.c_str());
 
2569
    m_AsmTexturePremultiplyRectModColor->Link();
 
2570
  }
 
2571
 
 
2572
  void GraphicsEngine::QRP_ASM_1TexPremultiply(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color &color)
 
2573
  {
 
2574
    if (device_texture.IsNull())
 
2575
      return;
 
2576
 
 
2577
    NUX_RETURN_IF_FALSE(m_AsmTexturePremultiplyModColor.IsValid());
 
2578
    NUX_RETURN_IF_FALSE(m_AsmTexturePremultiplyRectModColor.IsValid());
 
2579
 
 
2580
    QRP_Compute_Texture_Coord(width, height, device_texture, texxform);
 
2581
    float fx = x, fy = y;
 
2582
    float VtxBuffer[] =
 
2583
    {
 
2584
      fx,          fy,          0.0f, 1.0f, texxform.u0, texxform.v0, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
 
2585
      fx,          fy + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
 
2586
      fx + width,  fy + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
 
2587
      fx + width,  fy,          0.0f, 1.0f, texxform.u1, texxform.v0, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
 
2588
    };
 
2589
 
 
2590
    CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
 
2591
    CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
 
2592
 
 
2593
    ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_AsmTexturePremultiplyModColor;
 
2594
    if (device_texture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
 
2595
    {
 
2596
      shader_program = m_AsmTexturePremultiplyRectModColor;
 
2597
    }
 
2598
    shader_program->Begin();
 
2599
 
 
2600
    SetTexture(GL_TEXTURE0, device_texture);
 
2601
 
 
2602
    CHECKGL(glMatrixMode(GL_MODELVIEW));
 
2603
    CHECKGL(glLoadIdentity());
 
2604
    CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
 
2605
    CHECKGL(glMatrixMode(GL_PROJECTION));
 
2606
    CHECKGL(glLoadIdentity());
 
2607
    CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
 
2608
 
 
2609
 
 
2610
    int VertexLocation          = VTXATTRIB_POSITION;
 
2611
    int TextureCoord0Location   = VTXATTRIB_TEXCOORD0;
 
2612
    int VertexColorLocation     = VTXATTRIB_COLOR;
 
2613
 
 
2614
    CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
 
2615
    CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer));
 
2616
 
 
2617
    if (TextureCoord0Location != -1)
 
2618
    {
 
2619
      CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
 
2620
      CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4));
 
2621
    }
 
2622
 
 
2623
    if (VertexColorLocation != -1)
 
2624
    {
 
2625
      CHECKGL(glEnableVertexAttribArrayARB(VertexColorLocation));
 
2626
      CHECKGL(glVertexAttribPointerARB((GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8));
 
2627
    }
 
2628
 
 
2629
    CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
 
2630
 
 
2631
    CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
 
2632
 
 
2633
    if (TextureCoord0Location != -1)
 
2634
      CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
 
2635
 
 
2636
    if (VertexColorLocation != -1)
 
2637
      CHECKGL(glDisableVertexAttribArrayARB(VertexColorLocation));
 
2638
 
 
2639
    shader_program->End();
 
2640
  }
2521
2641
}
2522
2642
#endif // NUX_OPENGLES_20
2523
2643