GL3: Begin refactoring pixel program

--HG--
branch : opengl3
hg/feature/opengl3
kaetemi 11 years ago
parent 270342a07d
commit a13d39e9f4

@ -827,16 +827,8 @@ namespace NL3D
void CGLSLShaderGenerator::generateSpecular() void CGLSLShaderGenerator::generateSpecular()
{ {
/*s << "vec4 texel;" << std::endl;
ss << "texel.rgb = texel0.rgb * diffuseColor.rgb;" << std::endl;
ss << "texel.a = texel0.a;" << std::endl;
ss << "texel.rgb = texel1.rgb * texel.a + texel.rgb;" << std::endl;
ss << "texel.a = texel1.a;" << std::endl;*/
// FIXME GL3 SPECULAR: VERIFY IF THIS WORKS
ss << "vec3 specop0 = texel0.rgb * diffuse.rgb;" << std::endl; ss << "vec3 specop0 = texel0.rgb * diffuse.rgb;" << std::endl;
ss << "vec4 specop1 = vec4(texel1.rgb * texel0.a + specop0, texel0.a);" << std::endl; ss << "vec4 specop1 = vec4(texel1.rgb * texel0.a + specop0, diffuse.a);" << std::endl;
ss << "fragColor = specop1;" << std::endl; ss << "fragColor = specop1;" << std::endl;
} }

@ -214,7 +214,7 @@ public:
// *************************************************************************** // ***************************************************************************
class CShaderGL3 : public IMaterialDrvInfos class CMaterialDrvInfosGL3 : public IMaterialDrvInfos
{ {
public: public:
GLenum SrcBlend; GLenum SrcBlend;
@ -234,7 +234,10 @@ public:
// The supported Shader type. // The supported Shader type.
CMaterial::TShader SupportedShader; CMaterial::TShader SupportedShader;
CShaderGL3(IDriver *drv, ItMatDrvInfoPtrList it) : IMaterialDrvInfos(drv, it) {} // PP builtin
CPPBuiltin PPBuiltin;
CMaterialDrvInfosGL3(IDriver *drv, ItMatDrvInfoPtrList it) : IMaterialDrvInfos(drv, it) {}
}; };
@ -393,6 +396,8 @@ public:
void touchVertexFormatVP(); void touchVertexFormatVP();
void setTexGenModeVP(uint stage, sint mode); void setTexGenModeVP(uint stage, sint mode);
void generateBuiltinPixelProgram(CMaterial &mat);
virtual void startSpecularBatch(); virtual void startSpecularBatch();
virtual void endSpecularBatch(); virtual void endSpecularBatch();
@ -1345,6 +1350,9 @@ private:
NLMISC::CRefPtr<CGeometryProgram> m_DriverGeometryProgram; NLMISC::CRefPtr<CGeometryProgram> m_DriverGeometryProgram;
NLMISC::CRefPtr<CPixelProgram> m_DriverPixelProgram; NLMISC::CRefPtr<CPixelProgram> m_DriverPixelProgram;
friend class CPPBuiltin;
std::set<CPPBuiltin> m_PPBuiltinCache;
std::set<CVPBuiltin> m_VPBuiltinCache; std::set<CVPBuiltin> m_VPBuiltinCache;
CVPBuiltin m_VPBuiltinCurrent; CVPBuiltin m_VPBuiltinCurrent;
bool m_VPBuiltinTouched; bool m_VPBuiltinTouched;

@ -243,7 +243,7 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
return true; return true;
} }
CShaderGL3* pShader; CMaterialDrvInfosGL3* pShader;
CMaterial::TShader matShader; CMaterial::TShader matShader;
GLenum glenum = GL_ZERO; GLenum glenum = GL_ZERO;
uint32 touched = mat.getTouched(); uint32 touched = mat.getTouched();
@ -260,12 +260,12 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
// insert into driver list. (so it is deleted when driver is deleted). // insert into driver list. (so it is deleted when driver is deleted).
ItMatDrvInfoPtrList it= _MatDrvInfos.insert(_MatDrvInfos.end(), (NL3D::IMaterialDrvInfos*)NULL); ItMatDrvInfoPtrList it= _MatDrvInfos.insert(_MatDrvInfos.end(), (NL3D::IMaterialDrvInfos*)NULL);
// create and set iterator, for future deletion. // create and set iterator, for future deletion.
*it= mat._MatDrvInfo= new CShaderGL3(this, it); *it= mat._MatDrvInfo= new CMaterialDrvInfosGL3(this, it);
// Must create all OpenGL shader states. // Must create all OpenGL shader states.
touched= IDRV_TOUCHED_ALL; touched= IDRV_TOUCHED_ALL;
} }
pShader=static_cast<CShaderGL3*>((IMaterialDrvInfos*)(mat._MatDrvInfo)); pShader=static_cast<CMaterialDrvInfosGL3*>((IMaterialDrvInfos*)(mat._MatDrvInfo));
// 1. Setup modified fields of material. // 1. Setup modified fields of material.
//===================================== //=====================================

@ -0,0 +1,114 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2014 by authors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdopengl.h"
#include <sstream>
#include "nel/3d/vertex_program.h"
#include "nel/3d/light.h"
#include "driver_opengl.h"
#include "driver_opengl_program.h"
#include "driver_opengl_vertex_buffer_hard.h"
namespace NL3D {
#ifdef NL_STATIC
namespace NLDRIVERGL3 {
#endif
bool operator<(const CPPBuiltin &left, const CPPBuiltin &right)
{
// Material state
// Driver state
if (left.VertexFormat != right.VertexFormat)
return left.VertexFormat < right.VertexFormat;
if (left.Fog != right.Fog)
return right.Fog;
return false;
}
namespace /* anonymous */ {
void ppGenerate(std::string &result, CPPBuiltin &desc)
{
}
} /* anonymous namespace */
void CDriverGL3::generateBuiltinPixelProgram(CMaterial &mat)
{
CMaterialDrvInfosGL3 *matDrv = static_cast<CMaterialDrvInfosGL3 *>((IMaterialDrvInfos *)(mat._MatDrvInfo));
nlassert(matDrv);
std::set<CPPBuiltin>::iterator it = m_PPBuiltinCache.find(matDrv->PPBuiltin);
if (it != m_PPBuiltinCache.end())
{
matDrv->PPBuiltin.PixelProgram = it->PixelProgram;
return;
}
std::string result;
ppGenerate(result, matDrv->PPBuiltin);
CPixelProgram *program = new CPixelProgram();
IProgram::CSource *src = new IProgram::CSource();
src->Profile = IProgram::glsl330f;
src->DisplayName = "Builtin Pixel Program (" + NLMISC::toString(m_PPBuiltinCache.size()) + ")";
src->setSource(result);
program->addSource(src);
nldebug("GL3: Generate '%s'", src->DisplayName.c_str());
if (!compilePixelProgram(program))
{
delete program;
program = NULL;
}
matDrv->PPBuiltin.PixelProgram = program;
m_PPBuiltinCache.insert(matDrv->PPBuiltin);
}
void CPPBuiltin::checkDriverStateTouched(CDriverGL3 *driver)
{
if (VertexFormat != driver->m_VPBuiltinCurrent.VertexFormat)
{
VertexFormat = driver->m_VPBuiltinCurrent.VertexFormat;
Touched = true;
}
if (Fog != driver->m_VPBuiltinCurrent.Fog)
{
Fog = driver->m_VPBuiltinCurrent.Fog;
Touched = true;
}
}
void CPPBuiltin::checkMaterialStateTouched(CMaterial &mat)
{
}
#ifdef NL_STATIC
} // NLDRIVERGL3
#endif
} // NL3D

@ -25,6 +25,8 @@ namespace NL3D {
namespace NLDRIVERGL3 { namespace NLDRIVERGL3 {
#endif #endif
class CDriverGL3;
static sint TexGenDisabled = -1; static sint TexGenDisabled = -1;
static sint TexGenReflectionMap = 0; // GL_REFLECTION_MAP_ARB static sint TexGenReflectionMap = 0; // GL_REFLECTION_MAP_ARB
static sint TexGenSphereMap = 1; // GL_SPHERE_MAP static sint TexGenSphereMap = 1; // GL_SPHERE_MAP
@ -47,6 +49,22 @@ struct CVPBuiltin
bool operator<(const CVPBuiltin &left, const CVPBuiltin &right); bool operator<(const CVPBuiltin &left, const CVPBuiltin &right);
/// Builtin pixel program description
struct CPPBuiltin
{
uint16 VertexFormat;
bool Fog;
CPixelProgram *PixelProgram;
bool Touched;
void checkDriverStateTouched(CDriverGL3 *driver);
void checkMaterialStateTouched(CMaterial &mat);
};
bool operator<(const CPPBuiltin &left, const CPPBuiltin &right);
enum TAttribOffset enum TAttribOffset
{ {
Position, Position,

@ -54,10 +54,10 @@ bool operator<(const CVPBuiltin &left, const CVPBuiltin &right)
return false; return false;
} }
namespace namespace /* anonymous */ {
void vpLightUniforms(std::stringstream &ss, const CVPBuiltin &desc, int i)
{ {
void vpLightUniforms(std::stringstream &ss, const CVPBuiltin &desc, int i)
{
switch (desc.LightMode[i]) switch (desc.LightMode[i])
{ {
case CLight::DirectionalLight: case CLight::DirectionalLight:
@ -78,10 +78,10 @@ namespace
ss << "uniform float light" << i << "QuadAttn;" << std::endl; ss << "uniform float light" << i << "QuadAttn;" << std::endl;
break; break;
} }
} }
void vpLightFunctions(std::stringstream &ss, const CVPBuiltin &desc, int i) void vpLightFunctions(std::stringstream &ss, const CVPBuiltin &desc, int i)
{ {
switch (desc.LightMode[i]) switch (desc.LightMode[i])
{ {
case CLight::DirectionalLight: case CLight::DirectionalLight:
@ -170,15 +170,10 @@ namespace
ss << std::endl; ss << std::endl;
break; break;
} }
} }
void vsLighting(std::stringstream &ss, const CVPBuiltin &desc, int i)
{
}
void vpGenerate(std::string &result, const CVPBuiltin &desc) void vpGenerate(std::string &result, const CVPBuiltin &desc)
{ {
std::stringstream ss; std::stringstream ss;
ss << "// Builtin Vertex Shader" << std::endl; ss << "// Builtin Vertex Shader" << std::endl;
ss << std::endl; ss << std::endl;
@ -276,9 +271,10 @@ namespace
ss << "}" << std::endl; ss << "}" << std::endl;
result = ss.str(); result = ss.str();
}
} }
} /* anonymous namespace */
void CDriverGL3::generateBuiltinVertexProgram() void CDriverGL3::generateBuiltinVertexProgram()
{ {
std::set<CVPBuiltin>::iterator it = m_VPBuiltinCache.find(m_VPBuiltinCurrent); std::set<CVPBuiltin>::iterator it = m_VPBuiltinCache.find(m_VPBuiltinCurrent);

Loading…
Cancel
Save