Back to index

nux  3.0.0
GLSh_Fill.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #include "NuxCore/NuxCore.h"
00024 #include "GLResource.h"
00025 #include "GpuDevice.h"
00026 #include "GLDeviceObjects.h"
00027 #include "GLSh_Fill.h"
00028 #include "GLShaderParameter.h"
00029 #include "GpuDevice.h"
00030 #include "GLTemplatePrimitiveBuffer.h"
00031 #include "NuxCore/Math/Matrix4.h"
00032 
00033 namespace nux
00034 {
00035 
00036   GLSh_Fill::GLSh_Fill()
00037   {
00038 //     Color                 = new GLShaderParameter(0,  "ColorFill",                  eFRAGMENTUNIFORMTYPE, TRUE);
00039 //     ViewProjectionMatrix  = new GLShaderParameter(0,  "ViewProjectionMatrix",       eVERTEXUNIFORMTYPE, TRUE);
00040 //     Scale                 = new GLShaderParameter(0,  "Scale",                      eVERTEXUNIFORMTYPE, TRUE);
00041 //     Offset                = new GLShaderParameter(0,  "Offset",                     eVERTEXUNIFORMTYPE, TRUE);
00042 //
00043 //     vs = GetGpuDevice()->CreateVertexShader();
00044 //     ps = GetGpuDevice()->CreatePixelShader();
00045 //     sprog = GetGpuDevice()->CreateShaderProgram();
00046 //
00047 //     sprog->AddShaderParameter(Color);
00048 //     sprog->AddShaderParameter(ViewProjectionMatrix);
00049 //     sprog->AddShaderParameter(Scale);
00050 //     sprog->AddShaderParameter(Offset);
00051 //
00052 //     NString SourceCode;
00053 //     LoadFileToString(SourceCode, "..//Shaders//Fill.glsl");
00054 //     NString VertexShaderSource;
00055 //     ExtractShaderString3("[Vertex Shader]", SourceCode, VertexShaderSource);
00056 //     NString PixelShaderSource;
00057 //     ExtractShaderString3("[Fragment Shader]", SourceCode, PixelShaderSource);
00058 //
00059 //     vs->SetShaderCode(VertexShaderSource.GetTCharPtr());
00060 //     ps->SetShaderCode(PixelShaderSource.GetTCharPtr());
00061 //     vs->Compile();
00062 //     ps->Compile();
00063 //
00064 //     sprog->AddShaderObject(vs);
00065 //     sprog->AddShaderObject(ps);
00066 //     sprog->Link();
00067 //
00068 //     m_QuadBuffer = new TemplateQuadBuffer(GetGpuDevice());
00069 // //     Vector4 v[] =
00070 // //     {
00071 // //         Vector4(1, 0, 0, 0),
00072 // //         Vector4(1, 0, 0, 0),
00073 // //         Vector4(0, 0, 1, 0),
00074 // //         Vector4(0, 0, 1, 0),
00075 // //     };
00076 // //     m_QuadBuffer->SetPerVertexAttribute(1, 4, v);
00077   }
00078 
00079   GLSh_Fill::~GLSh_Fill()
00080   {
00081     NUX_SAFE_DELETE(m_QuadBuffer);
00082     NUX_SAFE_DELETE(Color);
00083     NUX_SAFE_DELETE(ViewProjectionMatrix);
00084     NUX_SAFE_DELETE(Scale);
00085     NUX_SAFE_DELETE(Offset);
00086   }
00087 
00088   void GLSh_Fill::SetColor(FLOAT R, FLOAT G, FLOAT B, FLOAT A)
00089   {
00090     _R = R;
00091     _G = G;
00092     _B = B;
00093     _A = A;
00094   }
00095 
00096   void GLSh_Fill::SetTransformMatrix(const Matrix4 &TransformMatrix)
00097   {
00098     m_TransformMatrix = TransformMatrix;
00099   }
00100 
00101   void GLSh_Fill::Render(INT x, INT y, INT z, INT width, INT height)
00102   {
00103     return;
00104     CHECKGL(glDisable(GL_CULL_FACE));
00105     sprog->Begin();
00106 
00107     //Matrix4 ProjectionMatrix;
00108     //ProjectionMatrix.Orthographic(0, 640, 480, 0, 0.0, 10000.0);
00109     //ProjectionMatrix.Transpose();
00110     ViewProjectionMatrix->SetUniformMatrix4fv(1, (GLfloat *) m_TransformMatrix.m, GL_FALSE);
00111 
00112     Scale->SetUniform4f(width, height, 1, 1);
00113     Offset->SetUniform4f(x, y, 0, 0);
00114     Color->SetUniform4f(_R, _G, _B, _A);
00115 
00116     INT VertexLocation = sprog->GetAttributeLocation("Vertex");
00117     m_QuadBuffer->BindAttribute(VertexLocation, 0);
00118 
00119 //     INT VertexColorLocation = sprog->GetAttributeLocation("VertexColor");
00120 //     m_QuadBuffer->BindAttribute(VertexColorLocation, 1);
00121 
00122     m_QuadBuffer->Render(1);
00123 
00124     m_QuadBuffer->UnBindAttribute(VertexLocation);
00125 //     m_QuadBuffer->UnBindAttribute(VertexColorLocation);
00126     m_QuadBuffer->UnBind(); // Unbind the vertex and index buffer.
00127 
00128     sprog->End();
00129   }
00130 
00131   void GLSh_Fill::CacheShader()
00132   {
00133 
00134   }
00135 }