108 if (!m_glmanager || !m_fbmanager)
return false;
110 if (m_pTextureFilterIndex==NULL)
113 m_shaders_array.Init(0, NULL);
127 MODebug2->
Message(
"moShaderManager::Init > Creating basic Render Shader...");
128 m_RenderShader.
Init();
131 "attribute vec4 position;\n"
132 "attribute vec3 colors;\n"
133 "attribute vec2 t_coordedge;\n"
134 "attribute vec2 t_coord;\n"
135 "attribute vec3 normal;\n"
136 "uniform mat4 projmatrix;\n"
137 "varying vec3 colorVarying;\n"
138 "varying vec3 v_normal;\n"
139 "varying vec2 v_texcoord;\n"
140 "varying vec2 v_texcoordedge;\n"
143 " colorVarying = colors;\n"
144 " v_normal = normal;\n"
145 " v_texcoord = t_coord;\n"
146 " v_texcoordedge = t_coordedge;\n"
147 " gl_Position = projmatrix*position;\n"
152 "precision mediump float;"
154 "varying vec3 colorVarying;\n"
155 "uniform sampler2D t_image;\n"
156 "varying vec3 v_normal;\n"
157 "varying vec2 v_texcoord;\n"
158 "varying vec2 v_texcoordedge;\n"
159 "uniform float wseg;\n"
160 "uniform float hseg;\n"
161 "uniform float wireframe_width;"
162 "uniform vec3 a_light;\n"
163 "uniform vec3 color;\n"
164 "uniform float opacity;\n"
167 " vec4 texcolor = texture2D( t_image, v_texcoord );\n"
170 " vec2 vector_to_borderC = vec2( 1.0, 1.0 ) - v_texcoord;\n"
171 " vec2 vector_to_borderB = vec2( 1.0, 0.0 ) - v_texcoord;\n"
172 " vec2 vector_to_borderA = vec2( 0.0, 0.0 ) - v_texcoord;\n"
173 " vec2 vector_to_borderD = vec2( 0.0, 1.0 ) - v_texcoord;\n"
174 " float distance_to_borderX = v_texcoord.x;\n"
175 " float intensity = 0.6+0.4*abs(max( 0.0, dot( v_normal, -1.0*a_light )) );\n"
177 " float dX = floor( v_texcoord.x * wseg );\n"
178 " float dY = floor( v_texcoord.y * hseg );\n"
179 " float distance_to_borderXd = abs( v_texcoord.x - dX / wseg );\n"
180 " float distance_to_borderY = v_texcoord.y;\n"
181 " float distance_to_borderYd = abs( v_texcoord.y - dY / hseg );\n"
182 " float distance_to_borderA = length(vector_to_borderA);\n"
183 " float distance_to_borderB = length(vector_to_borderB);\n"
184 " float distance_to_borderC = length(vector_to_borderC);\n"
185 " float distance_to_borderD = length(vector_to_borderD);\n"
186 " vec4 wirecolor = vec4( 0.0, 1.0, 0.0, 1.0);\n"
187 " vec4 wirecolorA = vec4( 1.0, 0.0, 0.0, 1.0);\n"
188 " vec4 wirecolorB = vec4( 0.0, 1.0, 0.0, 1.0);\n"
189 " vec4 wirecolorC = vec4( 0.0, 0.0, 1.0, 1.0);\n"
190 " vec4 wirecolorD = vec4( 1.0, 1.0, 1.0, 1.0);\n"
191 " if (distance_to_borderA<(wireframe_width*10.0)) texcolor = wirecolorA;\n"
192 " if (distance_to_borderB<(wireframe_width*10.0)) texcolor = wirecolorB;\n"
193 " if (distance_to_borderC<(wireframe_width*10.0)) texcolor = wirecolorC;\n"
194 " if (distance_to_borderD<(wireframe_width*10.0)) texcolor = wirecolorD;\n"
195 " if (distance_to_borderXd<wireframe_width) texcolor = wirecolor;\n"
196 " if (distance_to_borderYd<wireframe_width) texcolor = wirecolor;\n"
197 " if (distance_to_borderXd>(-wireframe_width+1.0/wseg)) texcolor = wirecolor;\n"
198 " if (distance_to_borderYd>(-wireframe_width+1.0/hseg)) texcolor = wirecolor;\n"
200 " vec4 mulcolor = intensity*vec4( 1.0*color.r, 1.0*color.g, 1.0*color.b, 1.0*opacity );\n"
201 " gl_FragColor = vec4( mulcolor.x*texcolor.x, mulcolor.y*texcolor.y, mulcolor.z*texcolor.z, mulcolor.w*texcolor.w );\n"
212 m_RenderShaderTexCoordEdgeIndex = m_RenderShader.
GetAttribID(
moText(
"t_coordedge"));
218 m_RenderShaderProjectionMatrixIndex = m_RenderShader.
GetUniformID(
"projmatrix");
219 m_RenderShaderWireframeWidthIndex = m_RenderShader.
GetUniformID(
moText(
"wireframe_width"));
226 "moShaderManager::Init > m_RenderShader Attrib IDs,"
227 " position:"+
IntToStr(m_RenderShaderPositionIndex)+
""
228 " normal:"+
IntToStr(m_RenderShaderNormalIndex)+
""
229 " color:"+
IntToStr(m_RenderShaderColorIndex)+
""
230 " opacity:"+
IntToStr(m_RenderShaderOpacityIndex)+
""
231 " t_coord:"+
IntToStr(m_RenderShaderTexCoordIndex)+
""
232 " t_coordedge:"+
IntToStr(m_RenderShaderTexCoordEdgeIndex)
237 +
moText(
" projmatrix:")+
IntToStr(m_RenderShaderProjectionMatrixIndex)
238 +
moText(
" wireframe_width:")+
IntToStr(m_RenderShaderWireframeWidthIndex)
248 return (m_glmanager && m_fbmanager);
261 m_pTextureFilterIndex = NULL;
269 if (m_pTextureFilterIndex) {
270 delete m_pTextureFilterIndex;
271 m_pTextureFilterIndex = NULL;
274 m_shaders_array.Finish();
285 for (
MOuint i = 0; i < m_shaders_array.Count(); i++)
287 pshader = m_shaders_array[i];
288 if ((pshader != NULL) && (!stricmp(pshader->
GetName(), p_name)))
return i;
290 if (p_create_shader)
return AddShader(p_name);
303 pshader_glsl->
Init();
306 m_shaders_array.Add(pshader);
307 return m_shaders_array.Count() - 1;
312 moShaderCG* pshader_cg;
313 pshader_cg =
new moShaderCG();
315 pshader_cg->SetName(p_name);
317 m_shaders_array.Add(pshader);
318 return m_shaders_array.Count() - 1;
332 complete_fn += p_filename;
340 moFile cfgFile( complete_fn );
346 +
moText(
" type parameter not founded.")
358 +
moText(
" fragment(pixel) shader parameter not founded.")
363 +
moText(
" vertex shader parameter not founded.")
380 if (!vertexFile.
Exists()) {
393 if (!fragmentFile.
Exists()) {
395 fragment_fn = fragment_fn + config.
Text(fragment_idx);
402 else tex_grid.
Init(&config, grid_idx);
406 vertex_fn, fragment_fn, tex_grid);
435 if (p_idx < (
MOint)m_shaders_array.Count())
437 m_shaders_array.Remove(p_idx);
MOboolean Initialized()
Pregunta si está inicializado.
void SetName(const moText &p_name)
moValueBase & GetSubValue(MOint p_indexsubvalue=0)
void SetGrid(moTexturedGrid p_grid)
moRenderManager * GetRenderMan()
static void Error(moText p_text)
Anuncia un error.
int GetParamIndex(moText p_paramname)
Devuelve el índice correspondiente al parámetro por nombre.
void SetResourceType(moResourceType p_restype)
virtual MOboolean Init(MOint p_size_x, MOint p_size_y, MOint p_num_layers, const MOfloat p_grid_dx[], const MOfloat p_grid_dy[])
virtual MOboolean Finish()
void PrintVertShaderLog()
GLint GetUniformID(const moText &uName)
void SetCompletePath(moText p_completepath)
clase de para manejar textos
virtual void LoadShader(const moText &vert_filename, const moText &frag_filename)=0
moResourceManager * m_pResourceManager
Puntero al administrador de recursos.
Dispositivo de entrada/salida, típicamente, interfaces humanas de IO y datos ( teclado, mouse, tableta, tcp, udp, serial )
MOboolean DeleteShader(MOint p_idx)
virtual MOboolean Init(moParam *p_param, moGLManager *p_glman, moFBManager *p_fbman, moShaderManager *p_shaman, moTextureManager *p_texman, moRenderManager *p_renderman)
moConfig m_Config
Configuración de parámetros del objeto.
int LoadConfig(moText p_filename)
Lee la configuracion de un archivo.
moText GetPath()
Retreive full file name: return "myFileName.txt", extension is included.
virtual void LoadVertShader(const moText &vert_filename)=0
#define MO_PARAM_NOT_FOUND
moShader * GetShader(MOuint p_idx)
void SetLabelName(const moText &p_labelname)
MOboolean IsConfigLoaded()
Indica si ha sido cargado con éxito el archivo de configuración
virtual void CreateShader(const moText &vert_source, const moText &frag_source)
static moDebug * MODebug2
Clase de impresión de errores para depuración
moDataManager * GetDataMan()
moValue & GetValue(MOint i=-1)
moParam & GetParam(MOint p_paramindex=-1)
Devuelve el parámetro por índice.
LIBMOLDEO_API moText0 IntToStr(int a)
MOint GetShaderIndex(moText p_name, MOboolean p_create_shader)
MOint AddShader(MOuint p_type, moText p_name)
void PrintFragShaderLog()
void SetName(const moText &p_name)
virtual void LoadFragShader(const moText &frag_filename)=0
void Message(moText p_text)
Anuncia un mensaje al usuario además de guardarlo en el log de texto.
void SetType(moMoldeoObjectType p_type)
GLint GetAttribID(const moText &aName)
moTextureManager * GetTextureMan()
moText Text(moParamReference p_paramreference)
Acceso rápido a un valor de texto.
almacena la configuración de los parámetros de un objeto en un archivo XML