|
|
@ -15,77 +15,86 @@
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
#include "driver_opengl.h"
|
|
|
|
#include "driver_opengl.h"
|
|
|
|
|
|
|
|
#include "driver_opengl_program.h"
|
|
|
|
#include "driver_glsl_shader_generator.h"
|
|
|
|
#include "driver_glsl_shader_generator.h"
|
|
|
|
#include "driver_opengl_vertex_buffer_hard.h"
|
|
|
|
#include "driver_opengl_vertex_buffer_hard.h"
|
|
|
|
#include "nel/3d/dynamic_material.h"
|
|
|
|
#include "nel/3d/dynamic_material.h"
|
|
|
|
#include "nel/3d/usr_shader_manager.h"
|
|
|
|
#include "nel/3d/usr_shader_manager.h"
|
|
|
|
#include "nel/3d/usr_shader_program.h"
|
|
|
|
#include "nel/3d/usr_shader_program.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
|
|
|
|
|
|
|
namespace NL3D {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef NL_STATIC
|
|
|
|
|
|
|
|
namespace NLDRIVERGL3 {
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const uint16 g_VertexFlags[CVertexBuffer::NumValue] =
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CVertexBuffer::PositionFlag,
|
|
|
|
|
|
|
|
CVertexBuffer::WeightFlag,
|
|
|
|
|
|
|
|
CVertexBuffer::NormalFlag,
|
|
|
|
|
|
|
|
CVertexBuffer::PrimaryColorFlag,
|
|
|
|
|
|
|
|
CVertexBuffer::SecondaryColorFlag,
|
|
|
|
|
|
|
|
CVertexBuffer::FogFlag,
|
|
|
|
|
|
|
|
CVertexBuffer::PaletteSkinFlag,
|
|
|
|
|
|
|
|
0,
|
|
|
|
|
|
|
|
CVertexBuffer::TexCoord0Flag,
|
|
|
|
|
|
|
|
CVertexBuffer::TexCoord1Flag,
|
|
|
|
|
|
|
|
CVertexBuffer::TexCoord2Flag,
|
|
|
|
|
|
|
|
CVertexBuffer::TexCoord3Flag,
|
|
|
|
|
|
|
|
CVertexBuffer::TexCoord4Flag,
|
|
|
|
|
|
|
|
CVertexBuffer::TexCoord5Flag,
|
|
|
|
|
|
|
|
CVertexBuffer::TexCoord6Flag,
|
|
|
|
|
|
|
|
CVertexBuffer::TexCoord7Flag
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *g_AttribNames[CVertexBuffer::NumValue] =
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"position",
|
|
|
|
|
|
|
|
"weight",
|
|
|
|
|
|
|
|
"normal",
|
|
|
|
|
|
|
|
"color",
|
|
|
|
|
|
|
|
"color2",
|
|
|
|
|
|
|
|
"fog",
|
|
|
|
|
|
|
|
"paletteSkin",
|
|
|
|
|
|
|
|
"none",
|
|
|
|
|
|
|
|
"texCoord0",
|
|
|
|
|
|
|
|
"texCoord1",
|
|
|
|
|
|
|
|
"texCoord2",
|
|
|
|
|
|
|
|
"texCoord3",
|
|
|
|
|
|
|
|
"texCoord4",
|
|
|
|
|
|
|
|
"texCoord5",
|
|
|
|
|
|
|
|
"texCoord6",
|
|
|
|
|
|
|
|
"texCoord7"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *g_TexelNames[IDRV_MAT_MAXTEXTURES] =
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"texel0",
|
|
|
|
|
|
|
|
"texel1",
|
|
|
|
|
|
|
|
"texel2",
|
|
|
|
|
|
|
|
"texel3"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *g_ConstantNames[4] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const char *constNames[ NL3D::IDRV_MAT_MAXTEXTURES ] =
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"constant0",
|
|
|
|
"constant0",
|
|
|
|
"constant1",
|
|
|
|
"constant1",
|
|
|
|
"constant2",
|
|
|
|
"constant2",
|
|
|
|
"constant3"
|
|
|
|
"constant3"
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint16 vertexFlags[ NL3D::CVertexBuffer::NumValue ] =
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::PositionFlag,
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::WeightFlag,
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::NormalFlag,
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::PrimaryColorFlag,
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::SecondaryColorFlag,
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::FogFlag,
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::PaletteSkinFlag,
|
|
|
|
|
|
|
|
0,
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::TexCoord0Flag,
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::TexCoord1Flag,
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::TexCoord2Flag,
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::TexCoord3Flag,
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::TexCoord4Flag,
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::TexCoord5Flag,
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::TexCoord6Flag,
|
|
|
|
|
|
|
|
NL3D::CVertexBuffer::TexCoord7Flag
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum AttribOffset
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Position,
|
|
|
|
|
|
|
|
Weight,
|
|
|
|
|
|
|
|
Normal,
|
|
|
|
|
|
|
|
PrimaryColor,
|
|
|
|
|
|
|
|
SecondaryColor,
|
|
|
|
|
|
|
|
Fog,
|
|
|
|
|
|
|
|
PaletteSkin,
|
|
|
|
|
|
|
|
Empty,
|
|
|
|
|
|
|
|
TexCoord0,
|
|
|
|
|
|
|
|
TexCoord1,
|
|
|
|
|
|
|
|
TexCoord2,
|
|
|
|
|
|
|
|
TexCoord3,
|
|
|
|
|
|
|
|
TexCoord4,
|
|
|
|
|
|
|
|
TexCoord5,
|
|
|
|
|
|
|
|
TexCoord6,
|
|
|
|
|
|
|
|
TexCoord7,
|
|
|
|
|
|
|
|
NumOffsets
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace NL3D
|
|
|
|
bool CDriverGL3::supportVertexProgram(CVertexProgram::TProfile profile) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool CDriverGL3::supportVertexProgram(CVertexProgram::TProfile profile) const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (profile == IProgram::glsl330v)
|
|
|
|
if (profile == IProgram::glsl330v)
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDriverGL3::compileVertexProgram(CVertexProgram *program)
|
|
|
|
bool CDriverGL3::compileVertexProgram(CVertexProgram *program)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (program->m_DrvInfo != NULL)
|
|
|
|
if (program->m_DrvInfo != NULL)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
@ -140,15 +149,15 @@ namespace NL3D
|
|
|
|
program->buildInfo(src);
|
|
|
|
program->buildInfo(src);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDriverGL3::activeVertexProgram(CVertexProgram *program)
|
|
|
|
bool CDriverGL3::activeVertexProgram(CVertexProgram *program)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return activeVertexProgram(program, false);
|
|
|
|
return activeVertexProgram(program, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDriverGL3::activeVertexProgram(CVertexProgram *program, bool driver)
|
|
|
|
bool CDriverGL3::activeVertexProgram(CVertexProgram *program, bool driver)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (driver) nlassert(m_UserVertexProgram == NULL);
|
|
|
|
if (driver) nlassert(m_UserVertexProgram == NULL);
|
|
|
|
|
|
|
|
|
|
|
|
if (m_DriverVertexProgram == program)
|
|
|
|
if (m_DriverVertexProgram == program)
|
|
|
@ -165,30 +174,37 @@ namespace NL3D
|
|
|
|
IProgramDrvInfos *di = program->m_DrvInfo;
|
|
|
|
IProgramDrvInfos *di = program->m_DrvInfo;
|
|
|
|
CVertexProgramDrvInfosGL3 *drvInfo = dynamic_cast< CVertexProgramDrvInfosGL3* >(di);
|
|
|
|
CVertexProgramDrvInfosGL3 *drvInfo = dynamic_cast< CVertexProgramDrvInfosGL3* >(di);
|
|
|
|
if (drvInfo == NULL)
|
|
|
|
if (drvInfo == NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_UserVertexProgram = NULL;
|
|
|
|
|
|
|
|
m_DriverVertexProgram = NULL;
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
glGetError();
|
|
|
|
glGetError();
|
|
|
|
|
|
|
|
|
|
|
|
nglUseProgramStages(ppoId, GL_VERTEX_SHADER_BIT, drvInfo->getProgramId());
|
|
|
|
nglUseProgramStages(ppoId, GL_VERTEX_SHADER_BIT, drvInfo->getProgramId());
|
|
|
|
GLenum error = glGetError();
|
|
|
|
GLenum error = glGetError();
|
|
|
|
if (error != GL_NO_ERROR)
|
|
|
|
if (error != GL_NO_ERROR)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_UserVertexProgram = NULL;
|
|
|
|
|
|
|
|
m_DriverVertexProgram = NULL;
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!driver) m_UserVertexProgram = program;
|
|
|
|
if (!driver) m_UserVertexProgram = program;
|
|
|
|
m_DriverVertexProgram = program;
|
|
|
|
m_DriverVertexProgram = program;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDriverGL3::supportPixelProgram(IProgram::TProfile profile) const
|
|
|
|
bool CDriverGL3::supportPixelProgram(IProgram::TProfile profile) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (profile == IProgram::glsl330f)
|
|
|
|
if (profile == IProgram::glsl330f)
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDriverGL3::compilePixelProgram(CPixelProgram *program)
|
|
|
|
bool CDriverGL3::compilePixelProgram(CPixelProgram *program)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (program->m_DrvInfo != NULL)
|
|
|
|
if (program->m_DrvInfo != NULL)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
@ -241,15 +257,15 @@ namespace NL3D
|
|
|
|
program->buildInfo(src);
|
|
|
|
program->buildInfo(src);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDriverGL3::activePixelProgram(CPixelProgram *program)
|
|
|
|
bool CDriverGL3::activePixelProgram(CPixelProgram *program)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return activePixelProgram(program, false);
|
|
|
|
return activePixelProgram(program, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDriverGL3::activePixelProgram(CPixelProgram *program, bool driver)
|
|
|
|
bool CDriverGL3::activePixelProgram(CPixelProgram *program, bool driver)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (driver) nlassert(m_UserPixelProgram == NULL);
|
|
|
|
if (driver) nlassert(m_UserPixelProgram == NULL);
|
|
|
|
|
|
|
|
|
|
|
|
if (m_DriverPixelProgram == program)
|
|
|
|
if (m_DriverPixelProgram == program)
|
|
|
@ -264,28 +280,39 @@ namespace NL3D
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (program->m_DrvInfo == NULL)
|
|
|
|
if (program->m_DrvInfo == NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_UserPixelProgram = NULL;
|
|
|
|
|
|
|
|
m_DriverPixelProgram = NULL;
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IProgramDrvInfos *di = program->m_DrvInfo;
|
|
|
|
IProgramDrvInfos *di = program->m_DrvInfo;
|
|
|
|
CPixelProgramDrvInfosGL3 *drvInfo = dynamic_cast< CPixelProgramDrvInfosGL3* >(di);
|
|
|
|
CPixelProgramDrvInfosGL3 *drvInfo = dynamic_cast< CPixelProgramDrvInfosGL3* >(di);
|
|
|
|
if (drvInfo == NULL)
|
|
|
|
if (drvInfo == NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_UserPixelProgram = NULL;
|
|
|
|
|
|
|
|
m_DriverPixelProgram = NULL;
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
glGetError();
|
|
|
|
glGetError();
|
|
|
|
|
|
|
|
|
|
|
|
nglUseProgramStages(ppoId, GL_FRAGMENT_SHADER_BIT, drvInfo->getProgramId());
|
|
|
|
nglUseProgramStages(ppoId, GL_FRAGMENT_SHADER_BIT, drvInfo->getProgramId());
|
|
|
|
GLenum error = glGetError();
|
|
|
|
GLenum error = glGetError();
|
|
|
|
if (error != GL_NO_ERROR)
|
|
|
|
if (error != GL_NO_ERROR)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_UserPixelProgram = NULL;
|
|
|
|
|
|
|
|
m_DriverPixelProgram = NULL;
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!driver) m_UserPixelProgram = program;
|
|
|
|
if (!driver) m_UserPixelProgram = program;
|
|
|
|
m_DriverPixelProgram = program;
|
|
|
|
m_DriverPixelProgram = program;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32 CDriverGL3::getProgramId(TProgram program) const
|
|
|
|
uint32 CDriverGL3::getProgramId(TProgram program) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = 0;
|
|
|
|
uint32 id = 0;
|
|
|
|
|
|
|
|
|
|
|
|
switch(program)
|
|
|
|
switch(program)
|
|
|
@ -315,10 +342,10 @@ namespace NL3D
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return id;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IProgram* CDriverGL3::getProgram(TProgram program) const
|
|
|
|
IProgram* CDriverGL3::getProgram(TProgram program) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
switch(program)
|
|
|
|
switch(program)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case IDriver::VertexProgram:
|
|
|
|
case IDriver::VertexProgram:
|
|
|
@ -330,142 +357,142 @@ namespace NL3D
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CDriverGL3::getUniformLocation(TProgram program, const char *name)
|
|
|
|
int CDriverGL3::getUniformLocation(TProgram program, const char *name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
return nglGetUniformLocation(id, name);
|
|
|
|
return nglGetUniformLocation(id, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform1f(TProgram program, uint index, float f0)
|
|
|
|
void CDriverGL3::setUniform1f(TProgram program, uint index, float f0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform1f(id, index, f0);
|
|
|
|
nglProgramUniform1f(id, index, f0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform2f(TProgram program, uint index, float f0, float f1)
|
|
|
|
void CDriverGL3::setUniform2f(TProgram program, uint index, float f0, float f1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform2f(id, index, f0, f1);
|
|
|
|
nglProgramUniform2f(id, index, f0, f1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform3f(TProgram program, uint index, float f0, float f1, float f2)
|
|
|
|
void CDriverGL3::setUniform3f(TProgram program, uint index, float f0, float f1, float f2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform3f(id, index, f0, f1, f2);
|
|
|
|
nglProgramUniform3f(id, index, f0, f1, f2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform4f(TProgram program, uint index, float f0, float f1, float f2, float f3)
|
|
|
|
void CDriverGL3::setUniform4f(TProgram program, uint index, float f0, float f1, float f2, float f3)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform4f(id, index, f0, f1, f2, f3);
|
|
|
|
nglProgramUniform4f(id, index, f0, f1, f2, f3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform1i(TProgram program, uint index, sint32 i0)
|
|
|
|
void CDriverGL3::setUniform1i(TProgram program, uint index, sint32 i0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform1i(id, index, i0);
|
|
|
|
nglProgramUniform1i(id, index, i0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform2i(TProgram program, uint index, sint32 i0, sint32 i1)
|
|
|
|
void CDriverGL3::setUniform2i(TProgram program, uint index, sint32 i0, sint32 i1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform2i(id, index, i0, i1);
|
|
|
|
nglProgramUniform2i(id, index, i0, i1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform3i(TProgram program, uint index, sint32 i0, sint32 i1, sint32 i2)
|
|
|
|
void CDriverGL3::setUniform3i(TProgram program, uint index, sint32 i0, sint32 i1, sint32 i2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform3i(id, index, i0, i1, i2);
|
|
|
|
nglProgramUniform3i(id, index, i0, i1, i2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform4i(TProgram program, uint index, sint32 i0, sint32 i1, sint32 i2, sint32 i3)
|
|
|
|
void CDriverGL3::setUniform4i(TProgram program, uint index, sint32 i0, sint32 i1, sint32 i2, sint32 i3)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform4i(id, index, i0, i1, i2, i3);
|
|
|
|
nglProgramUniform4i(id, index, i0, i1, i2, i3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform1ui(TProgram program, uint index, uint32 ui0)
|
|
|
|
void CDriverGL3::setUniform1ui(TProgram program, uint index, uint32 ui0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform1ui(id, index, ui0);
|
|
|
|
nglProgramUniform1ui(id, index, ui0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform2ui(TProgram program, uint index, uint32 ui0, uint32 ui1)
|
|
|
|
void CDriverGL3::setUniform2ui(TProgram program, uint index, uint32 ui0, uint32 ui1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform2ui(id, index, ui0, ui1);
|
|
|
|
nglProgramUniform2ui(id, index, ui0, ui1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform3ui(TProgram program, uint index, uint32 ui0, uint32 ui1, uint32 ui2)
|
|
|
|
void CDriverGL3::setUniform3ui(TProgram program, uint index, uint32 ui0, uint32 ui1, uint32 ui2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform3ui(id, index, ui0, ui1, ui2);
|
|
|
|
nglProgramUniform3ui(id, index, ui0, ui1, ui2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform4ui(TProgram program, uint index, uint32 ui0, uint32 ui1, uint32 ui2, uint32 ui3)
|
|
|
|
void CDriverGL3::setUniform4ui(TProgram program, uint index, uint32 ui0, uint32 ui1, uint32 ui2, uint32 ui3)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform4ui(id, index, ui0, ui1, ui2, ui3);
|
|
|
|
nglProgramUniform4ui(id, index, ui0, ui1, ui2, ui3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform3f(TProgram program, uint index, const CVector &v)
|
|
|
|
void CDriverGL3::setUniform3f(TProgram program, uint index, const CVector &v)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform3f(id, index, v.x, v.y, v.z);
|
|
|
|
nglProgramUniform3f(id, index, v.x, v.y, v.z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform4f(TProgram program, uint index, const CVector &v, float f3)
|
|
|
|
void CDriverGL3::setUniform4f(TProgram program, uint index, const CVector &v, float f3)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform4f(id, index, v.x, v.y, v.z, f3);
|
|
|
|
nglProgramUniform4f(id, index, v.x, v.y, v.z, f3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform4f(TProgram program, uint index, const NLMISC::CRGBAF& rgba)
|
|
|
|
void CDriverGL3::setUniform4f(TProgram program, uint index, const NLMISC::CRGBAF& rgba)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform4f(id, index, rgba.R, rgba.G, rgba.B, rgba.A);
|
|
|
|
nglProgramUniform4f(id, index, rgba.R, rgba.G, rgba.B, rgba.A);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform3x3f(TProgram program, uint index, const float *src)
|
|
|
|
void CDriverGL3::setUniform3x3f(TProgram program, uint index, const float *src)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniformMatrix3fv(id, index, 1, false, src);
|
|
|
|
nglProgramUniformMatrix3fv(id, index, 1, false, src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform4x4f(TProgram program, uint index, const CMatrix &m)
|
|
|
|
void CDriverGL3::setUniform4x4f(TProgram program, uint index, const CMatrix &m)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniformMatrix4fv(id, index, 1, false, m.get());
|
|
|
|
nglProgramUniformMatrix4fv(id, index, 1, false, m.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform4x4f(TProgram program, uint index, const float *src)
|
|
|
|
void CDriverGL3::setUniform4x4f(TProgram program, uint index, const float *src)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniformMatrix4fv(id, index, 1, false, src);
|
|
|
|
nglProgramUniformMatrix4fv(id, index, 1, false, src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform4fv(TProgram program, uint index, size_t num, const float *src)
|
|
|
|
void CDriverGL3::setUniform4fv(TProgram program, uint index, size_t num, const float *src)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform4fv(id, index, num, src);
|
|
|
|
nglProgramUniform4fv(id, index, num, src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform4iv(TProgram program, uint index, size_t num, const sint32 *src)
|
|
|
|
void CDriverGL3::setUniform4iv(TProgram program, uint index, size_t num, const sint32 *src)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform4iv(id, index, num, src);
|
|
|
|
nglProgramUniform4iv(id, index, num, src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniform4uiv(TProgram program, uint index, size_t num, const uint32 *src)
|
|
|
|
void CDriverGL3::setUniform4uiv(TProgram program, uint index, size_t num, const uint32 *src)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
nglProgramUniform4uiv(id, index, num, src);
|
|
|
|
nglProgramUniform4uiv(id, index, num, src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniformMatrix(TProgram program, uint index, TMatrix matrix, TTransform transform)
|
|
|
|
void CDriverGL3::setUniformMatrix(TProgram program, uint index, TMatrix matrix, TTransform transform)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
CMatrix mat;
|
|
|
|
CMatrix mat;
|
|
|
|
|
|
|
|
|
|
|
@ -499,17 +526,17 @@ namespace NL3D
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nglProgramUniformMatrix4fv(id, index, 1, false, mat.get());
|
|
|
|
nglProgramUniformMatrix4fv(id, index, 1, false, mat.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setUniformFog(TProgram program, uint index)
|
|
|
|
void CDriverGL3::setUniformFog(TProgram program, uint index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
uint32 id = getProgramId(program);
|
|
|
|
const float *v = _ModelViewMatrix.get();
|
|
|
|
const float *v = _ModelViewMatrix.get();
|
|
|
|
nglProgramUniform4f(id, index, -v[ 2 ], -v[ 6 ], -v[ 10 ], -v[ 4 ]);
|
|
|
|
nglProgramUniform4f(id, index, -v[ 2 ], -v[ 6 ], -v[ 10 ], -v[ 4 ]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::generateShaderDesc(CShaderDesc &desc, CMaterial &mat)
|
|
|
|
void CDriverGL3::generateShaderDesc(CShaderDesc &desc, CMaterial &mat)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
desc.setShaderType(mat.getShader());
|
|
|
|
desc.setShaderType(mat.getShader());
|
|
|
|
desc.setVBFlags(_CurrentVertexBufferHard->VB->getVertexFormat());
|
|
|
|
desc.setVBFlags(_CurrentVertexBufferHard->VB->getVertexFormat());
|
|
|
|
|
|
|
|
|
|
|
@ -522,7 +549,7 @@ namespace NL3D
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool useTextures = false;
|
|
|
|
bool useTextures = false;
|
|
|
|
|
|
|
|
|
|
|
|
int maxTextures = std::min(int(SHADER_MAX_TEXTURES), int(IDRV_MAT_MAXTEXTURES));
|
|
|
|
int maxTextures = std::min(int(IDRV_MAT_MAXTEXTURES), int(IDRV_MAT_MAXTEXTURES));
|
|
|
|
for (int i = 0; i < maxTextures; i++)
|
|
|
|
for (int i = 0; i < maxTextures; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
desc.setTexEnvMode(i, mat.getTexEnvMode(i));
|
|
|
|
desc.setTexEnvMode(i, mat.getTexEnvMode(i));
|
|
|
@ -530,7 +557,7 @@ namespace NL3D
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < maxTextures; i++)
|
|
|
|
for (int i = 0; i < maxTextures; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (desc.hasVBFlags(vertexFlags[ TexCoord0 + i ]))
|
|
|
|
if (desc.hasVBFlags(g_VertexFlags[ TexCoord0 + i ]))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
desc.setUseTexStage(i, true);
|
|
|
|
desc.setUseTexStage(i, true);
|
|
|
|
useTextures = true;
|
|
|
|
useTextures = true;
|
|
|
@ -561,20 +588,24 @@ namespace NL3D
|
|
|
|
desc.setAlphaTestThreshold(mat.getAlphaTestThreshold());
|
|
|
|
desc.setAlphaTestThreshold(mat.getAlphaTestThreshold());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (fogEnabled())
|
|
|
|
if (m_VPBuiltinCurrent.Fog)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
desc.setFog(true);
|
|
|
|
desc.setFog(true);
|
|
|
|
desc.setFogMode(CShaderDesc::Linear);
|
|
|
|
desc.setFogMode(CShaderDesc::Linear);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int maxLights = std::min(int(SHADER_MAX_LIGHTS), int(MaxLight));
|
|
|
|
//bool enableLights = false;
|
|
|
|
bool enableLights = false;
|
|
|
|
for (int i = 0; i < MaxLight; i++)
|
|
|
|
for (int i = 0; i < maxLights; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!_UserLightEnable[ i ])
|
|
|
|
if (!_UserLightEnable[i])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
desc.setLight(i, CShaderDesc::Nolight);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//if (!_UserLightEnable[ i ])
|
|
|
|
|
|
|
|
// continue;
|
|
|
|
|
|
|
|
|
|
|
|
enableLights = true;
|
|
|
|
//enableLights = true;
|
|
|
|
|
|
|
|
|
|
|
|
switch(_LightMode[ i ])
|
|
|
|
switch(_LightMode[ i ])
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -593,18 +624,18 @@ namespace NL3D
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
desc.setLighting(enableLights);
|
|
|
|
desc.setLighting(/*enableLights && mat.isLighted() &&*/ m_VPBuiltinCurrent.Lighting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDriverGL3::setupBuiltinPrograms(CMaterial &mat)
|
|
|
|
bool CDriverGL3::setupBuiltinPrograms(CMaterial &mat)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return setupBuiltinVertexProgram()
|
|
|
|
return setupBuiltinVertexProgram()
|
|
|
|
&& setupBuiltinPixelProgram(mat)
|
|
|
|
&& setupBuiltinPixelProgram(mat)
|
|
|
|
&& setupUniforms();
|
|
|
|
&& setupUniforms();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDriverGL3::setupBuiltinVertexProgram()
|
|
|
|
bool CDriverGL3::setupBuiltinVertexProgram()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (m_UserVertexProgram) return true;
|
|
|
|
if (m_UserVertexProgram) return true;
|
|
|
|
|
|
|
|
|
|
|
|
touchVertexFormatVP(); // TODO
|
|
|
|
touchVertexFormatVP(); // TODO
|
|
|
@ -622,10 +653,10 @@ namespace NL3D
|
|
|
|
// GL3 TODO: Here we set the uniforms of the vertex program!
|
|
|
|
// GL3 TODO: Here we set the uniforms of the vertex program!
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDriverGL3::setupBuiltinPixelProgram(CMaterial &mat)
|
|
|
|
bool CDriverGL3::setupBuiltinPixelProgram(CMaterial &mat)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (m_UserPixelProgram) return true;
|
|
|
|
if (m_UserPixelProgram) return true;
|
|
|
|
|
|
|
|
|
|
|
|
// nlassert(!m_UserVertexProgram); // TEMP
|
|
|
|
// nlassert(!m_UserVertexProgram); // TEMP
|
|
|
@ -749,10 +780,10 @@ namespace NL3D
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDriverGL3::setupDynMatProgram(CMaterial& mat, uint pass)
|
|
|
|
bool CDriverGL3::setupDynMatProgram(CMaterial& mat, uint pass)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
if ((currentProgram.vp != NULL) && (currentProgram.pp != NULL))
|
|
|
|
if ((currentProgram.vp != NULL) && (currentProgram.pp != NULL))
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
@ -838,17 +869,17 @@ namespace NL3D
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDriverGL3::setupUniforms()
|
|
|
|
bool CDriverGL3::setupUniforms()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setupUniforms(IDriver::VertexProgram);
|
|
|
|
setupUniforms(IDriver::VertexProgram);
|
|
|
|
setupUniforms(IDriver::PixelProgram);
|
|
|
|
setupUniforms(IDriver::PixelProgram);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDriverGL3::setupUniforms(TProgram program)
|
|
|
|
void CDriverGL3::setupUniforms(TProgram program)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CMaterial &mat = *_CurrentMaterial;
|
|
|
|
CMaterial &mat = *_CurrentMaterial;
|
|
|
|
IProgram *p = getProgram(program);
|
|
|
|
IProgram *p = getProgram(program);
|
|
|
|
|
|
|
|
|
|
|
@ -942,7 +973,7 @@ namespace NL3D
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int maxLights = std::min(int(MaxLight), int(SHADER_MAX_LIGHTS));
|
|
|
|
int maxLights = std::min(int(MaxLight), int(NL_OPENGL3_MAX_LIGHT));
|
|
|
|
for (int i = 0; i < maxLights; i++)
|
|
|
|
for (int i = 0; i < maxLights; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!_UserLightEnable[ i ])
|
|
|
|
if (!_UserLightEnable[ i ])
|
|
|
@ -1064,10 +1095,10 @@ namespace NL3D
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDriverGL3::initProgramPipeline()
|
|
|
|
bool CDriverGL3::initProgramPipeline()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ppoId = 0;
|
|
|
|
ppoId = 0;
|
|
|
|
|
|
|
|
|
|
|
|
nglGenProgramPipelines(1, &ppoId);
|
|
|
|
nglGenProgramPipelines(1, &ppoId);
|
|
|
@ -1077,7 +1108,12 @@ namespace NL3D
|
|
|
|
nglBindProgramPipeline(ppoId);
|
|
|
|
nglBindProgramPipeline(ppoId);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef NL_STATIC
|
|
|
|
|
|
|
|
} // NLDRIVERGL3
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // NL3D
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* end of file */
|
|
|
|