Back to index

nux  3.0.0
Public Member Functions | Private Attributes
nux::GLSh_ColorPicker Class Reference

#include <GLSh_ColorPicker.h>

Collaboration diagram for nux::GLSh_ColorPicker:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 GLSh_ColorPicker (color::Channel cc)
 ~GLSh_ColorPicker ()
void SetColor (float R, float G, float B, float A)
void SetScreenPositionOffset (float x, float y)
void Render (int x, int y, int z, int width, int height, int WindowWidth, int WindowHeight)

Private Attributes

float _R
float _G
float _B
float _A
float _ScreenOffsetX
float _ScreenOffsetY
ObjectPtr< IOpenGLPixelShaderGlobalPixelShader
ObjectPtr< IOpenGLShaderProgramsprog
ObjectPtr
< IOpenGLAsmShaderProgram
m_AsmProg
UINT ViewPortX
UINT ViewPortY
UINT ViewPortWidth
UINT ViewPortHeight

Detailed Description

Definition at line 32 of file GLSh_ColorPicker.h.


Constructor & Destructor Documentation

Definition at line 245 of file GLSh_ColorPicker.cpp.

    :   _R(1.0)
    ,   _G(0.0)
    ,   _B(0.0)
    ,   _A(1.0)
    ,   _ScreenOffsetX(0)
    ,   _ScreenOffsetY(0)
  {
    NString FrgShaderCode;

    if (GetGraphicsDisplay()->GetGraphicsEngine()->UsingGLSLCodePath() && (GetGraphicsDisplay()->GetGpuDevice()->GetGPUBrand() != GPU_BRAND_INTEL))
    {
      switch(color_channel)
      {
        case color::RED:
        {
          FrgShaderCode = RedFrgShader;
          break;
        }
        case color::GREEN:
        {
          FrgShaderCode = GreenFrgShader;
          break;
        }
        case color::BLUE:
        {
          FrgShaderCode = BlueFrgShader;
          break;
        }
        case color::HUE:
        {
          FrgShaderCode = HueFrgShader;
          break;
        }
        case color::SATURATION:
        {
          FrgShaderCode = SaturationFrgShader;
          break;
        }
        case color::VALUE:
        {
          FrgShaderCode = ValueFrgShader;
          break;
        }
        default:
        {
          nuxDebugMsg("[GLSh_ColorPicker::GLSh_ColorPicker] Unknown color channel");
          FrgShaderCode = RedFrgShader;
          break;
        }
      }

      GlobalPixelShader = GetGraphicsDisplay()->GetGpuDevice()->CreatePixelShader();
      sprog = GetGraphicsDisplay()->GetGpuDevice()->CreateShaderProgram();

      GlobalPixelShader->SetShaderCode(HSV_To_RGBFrgShader.GetTCharPtr());

      sprog->AddShaderObject(GlobalPixelShader);
      sprog->LoadVertexShader(VtxShader.GetTCharPtr(), NULL);
      sprog->LoadPixelShader(FrgShaderCode.GetTCharPtr(), NULL);
      sprog->Link();
    }
    else
    {
      switch(color_channel)
      {
        case color::RED:
        {
          FrgShaderCode = AsmRedFrgShader;
          break;
        }
        case color::GREEN:
        {
          FrgShaderCode = AsmGreenFrgShader;
          break;
        }
        case color::BLUE:
        {
          FrgShaderCode = AsmBlueFrgShader;
          break;
        }
        case color::HUE:
        {
          FrgShaderCode = AsmHueFrgShader;
          break;
        }
        case color::SATURATION:
        {
          FrgShaderCode = AsmSaturationFrgShader;
          break;
        }
        case color::VALUE:
        {
          FrgShaderCode = AsmValueFrgShader;
          break;
        }
        default:
        {
          nuxDebugMsg("[GLSh_ColorPicker::GLSh_ColorPicker] Unknown color channel");
          FrgShaderCode = RedFrgShader;
          break;
        }
      }

      m_AsmProg = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
      m_AsmProg->LoadVertexShader(AsmVtxShader.GetTCharPtr());
      m_AsmProg->LoadPixelShader(FrgShaderCode.GetTCharPtr());
      m_AsmProg->Link();
    }
  }

Here is the call graph for this function:

Definition at line 356 of file GLSh_ColorPicker.cpp.

  {
    GlobalPixelShader = ObjectPtr<IOpenGLPixelShader> (0);
    sprog.Release();
    m_AsmProg.Release();
  }

Here is the call graph for this function:


Member Function Documentation

void nux::GLSh_ColorPicker::Render ( int  x,
int  y,
int  z,
int  width,
int  height,
int  WindowWidth,
int  WindowHeight 
)

Definition at line 377 of file GLSh_ColorPicker.cpp.

  {
    float fx = x, fy = y;
    float VtxBuffer[] =
    {
      fx,          fy,          0.0f, 1.0f,
      fx,          fy + height, 0.0f, 1.0f,
      fx + width,  fy + height, 0.0f, 1.0f,
      fx + width,  fy,          0.0f, 1.0f,
    };

    if (GetGraphicsDisplay()->GetGraphicsEngine()->UsingGLSLCodePath() && (GetGraphicsDisplay()->GetGpuDevice()->GetGPUBrand() != GPU_BRAND_INTEL))
    {
      CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
      CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
      sprog->Begin();

      int VertexLocation = sprog->GetAttributeLocation("AVertex");

      int VPMatrixLocation = sprog->GetUniformLocationARB("ViewProjectionMatrix");
      Matrix4 MVPMatrix = GetGraphicsDisplay()->GetGraphicsEngine()->GetOpenGLModelViewProjectionMatrix();

      sprog->SetUniformLocMatrix4fv((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m));

      int ColorBase    = sprog->GetUniformLocationARB("Color");
      int RectPosition    = sprog->GetUniformLocationARB("RectPosition");
      int RectDimension   = sprog->GetUniformLocationARB("RectDimension");

      if (ColorBase != -1)
        CHECKGL(glUniform4fARB(ColorBase, _R, _G, _B, _A));

      if (RectPosition != -1)
        CHECKGL(glUniform4fARB(RectPosition, x + _ScreenOffsetX, WindowHeight - y - height - _ScreenOffsetY, z, 0.0f));

      if (RectDimension != -1)
        CHECKGL(glUniform4fARB(RectDimension, width, height, 0.0f, 0.0f));

      CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
      CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 16, VtxBuffer));

      CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));

      CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));

      sprog->End();
    }
#ifndef NUX_OPENGLES_20
    else
    {
      CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
      CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
      m_AsmProg->Begin();

      CHECKGL(glMatrixMode(GL_MODELVIEW));
      CHECKGL(glLoadIdentity());
      CHECKGL(glLoadMatrixf((FLOAT *) GetGraphicsDisplay()->GetGraphicsEngine()->GetOpenGLModelViewMatrix().m));
      CHECKGL(glMatrixMode(GL_PROJECTION));
      CHECKGL(glLoadIdentity());
      CHECKGL(glLoadMatrixf((FLOAT *) GetGraphicsDisplay()->GetGraphicsEngine()->GetOpenGLProjectionMatrix().m));

      int VertexLocation          = VTXATTRIB_POSITION;

      CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, x + _ScreenOffsetX, WindowHeight - y - height - _ScreenOffsetY, z, 0.0f));
      CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 1, width, height, 0.0f, 0.0f));
      CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 2, _R, _G, _B, _A));

      CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
      CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 16, VtxBuffer));

      CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));

      CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));

      m_AsmProg->End();
    }
#endif
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::GLSh_ColorPicker::SetColor ( float  R,
float  G,
float  B,
float  A 
)

Definition at line 363 of file GLSh_ColorPicker.cpp.

  {
    _R = R;
    _G = G;
    _B = B;
    _A = A;
  }

Here is the caller graph for this function:

void nux::GLSh_ColorPicker::SetScreenPositionOffset ( float  x,
float  y 
)

Definition at line 371 of file GLSh_ColorPicker.cpp.

Here is the caller graph for this function:


Member Data Documentation

float nux::GLSh_ColorPicker::_A [private]

Definition at line 44 of file GLSh_ColorPicker.h.

float nux::GLSh_ColorPicker::_B [private]

Definition at line 44 of file GLSh_ColorPicker.h.

float nux::GLSh_ColorPicker::_G [private]

Definition at line 44 of file GLSh_ColorPicker.h.

float nux::GLSh_ColorPicker::_R [private]

Definition at line 44 of file GLSh_ColorPicker.h.

Definition at line 45 of file GLSh_ColorPicker.h.

Definition at line 45 of file GLSh_ColorPicker.h.

Definition at line 47 of file GLSh_ColorPicker.h.

Definition at line 49 of file GLSh_ColorPicker.h.

Definition at line 48 of file GLSh_ColorPicker.h.

Definition at line 54 of file GLSh_ColorPicker.h.

Definition at line 53 of file GLSh_ColorPicker.h.

Definition at line 51 of file GLSh_ColorPicker.h.

Definition at line 52 of file GLSh_ColorPicker.h.


The documentation for this class was generated from the following files: