mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Added shaders for each material/lighting combination.
This commit is contained in:
parent
fa099a12e2
commit
7e3f572b8e
12 changed files with 319 additions and 167 deletions
|
@ -468,7 +468,7 @@ void lcCamera::CopyPosition(const lcCamera* camera)
|
|||
|
||||
void lcCamera::DrawInterface(lcContext* Context) const
|
||||
{
|
||||
Context->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
Context->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
|
||||
lcMatrix44 ViewWorldMatrix = lcMatrix44AffineInverse(mWorldView);
|
||||
ViewWorldMatrix.SetTranslation(lcVector3(0, 0, 0));
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#define GL_STATIC_DRAW_ARB GL_STATIC_DRAW
|
||||
#endif
|
||||
|
||||
lcProgram lcContext::mPrograms[LC_NUM_PROGRAMS];
|
||||
lcProgram lcContext::mPrograms[LC_NUM_LIGHTING_MODES][LC_NUM_MATERIALS];
|
||||
|
||||
static int lcOpaqueRenderMeshCompare(const void* Elem1, const void* Elem2)
|
||||
{
|
||||
|
@ -100,8 +100,8 @@ lcContext::lcContext()
|
|||
mProjectionMatrixDirty = false;
|
||||
mViewProjectionMatrixDirty = false;
|
||||
|
||||
mLightingMode = LC_LIGHTING_UNLIT;
|
||||
mProgramType = LC_NUM_PROGRAMS;
|
||||
mLightingMode = LC_NUM_LIGHTING_MODES;
|
||||
mMaterialType = LC_NUM_MATERIALS;
|
||||
}
|
||||
|
||||
lcContext::~lcContext()
|
||||
|
@ -124,148 +124,294 @@ void lcContext::CreateShaderPrograms()
|
|||
#define LC_PIXEL_OUTPUT "#define gl_FragColor FragColor\nout mediump vec4 gl_FragColor;\n"
|
||||
#endif
|
||||
|
||||
const char* VertexShaders[LC_NUM_PROGRAMS] =
|
||||
const char* VertexShaders[LC_NUM_LIGHTING_MODES][LC_NUM_MATERIALS] =
|
||||
{
|
||||
// LC_PROGRAM_SIMPLE
|
||||
LC_SHADER_VERSION
|
||||
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
|
||||
"uniform mat4 WorldViewProjectionMatrix;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
|
||||
"}\n",
|
||||
// LC_PROGRAM_TEXTURE
|
||||
LC_SHADER_VERSION
|
||||
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
|
||||
LC_VERTEX_INPUT "vec2 VertexTexCoord;\n"
|
||||
LC_VERTEX_OUTPUT "vec2 PixelTexCoord;\n"
|
||||
"uniform mat4 WorldViewProjectionMatrix;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
|
||||
" PixelTexCoord = VertexTexCoord;\n"
|
||||
"}\n",
|
||||
// LC_PROGRAM_VERTEX_COLOR
|
||||
LC_SHADER_VERSION
|
||||
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
|
||||
LC_VERTEX_INPUT "vec4 VertexColor;\n"
|
||||
LC_VERTEX_OUTPUT "vec4 PixelColor;\n"
|
||||
"uniform mat4 WorldViewProjectionMatrix;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
|
||||
" PixelColor = VertexColor;\n"
|
||||
"}\n"
|
||||
// LC_LIGHTING_UNLIT
|
||||
{
|
||||
// LC_MATERIAL_SIMPLE
|
||||
LC_SHADER_VERSION
|
||||
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
|
||||
"uniform mat4 WorldViewProjectionMatrix;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
|
||||
"}\n",
|
||||
// LC_MATERIAL_TEXTURE
|
||||
LC_SHADER_VERSION
|
||||
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
|
||||
LC_VERTEX_INPUT "vec2 VertexTexCoord;\n"
|
||||
LC_VERTEX_OUTPUT "vec2 PixelTexCoord;\n"
|
||||
"uniform mat4 WorldViewProjectionMatrix;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
|
||||
" PixelTexCoord = VertexTexCoord;\n"
|
||||
"}\n",
|
||||
// LC_MATERIAL_VERTEX_COLOR
|
||||
LC_SHADER_VERSION
|
||||
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
|
||||
LC_VERTEX_INPUT "vec4 VertexColor;\n"
|
||||
LC_VERTEX_OUTPUT "vec4 PixelColor;\n"
|
||||
"uniform mat4 WorldViewProjectionMatrix;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
|
||||
" PixelColor = VertexColor;\n"
|
||||
"}\n"
|
||||
},
|
||||
// LC_LIGHTING_FAKE
|
||||
{
|
||||
// LC_MATERIAL_SIMPLE
|
||||
LC_SHADER_VERSION
|
||||
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
|
||||
LC_VERTEX_INPUT "vec3 VertexNormal;\n"
|
||||
LC_VERTEX_OUTPUT "vec3 PixelNormal;\n"
|
||||
"uniform mat4 WorldViewProjectionMatrix;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" PixelNormal = VertexNormal;\n"
|
||||
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
|
||||
"}\n",
|
||||
// LC_MATERIAL_TEXTURE
|
||||
LC_SHADER_VERSION
|
||||
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
|
||||
LC_VERTEX_INPUT "vec3 VertexNormal;\n"
|
||||
LC_VERTEX_INPUT "vec2 VertexTexCoord;\n"
|
||||
LC_VERTEX_OUTPUT "vec3 PixelNormal;\n"
|
||||
LC_VERTEX_OUTPUT "vec2 PixelTexCoord;\n"
|
||||
"uniform mat4 WorldViewProjectionMatrix;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" PixelNormal = VertexNormal;\n"
|
||||
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
|
||||
" PixelTexCoord = VertexTexCoord;\n"
|
||||
"}\n",
|
||||
// LC_MATERIAL_VERTEX_COLOR
|
||||
LC_SHADER_VERSION
|
||||
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
|
||||
LC_VERTEX_INPUT "vec3 VertexNormal;\n"
|
||||
LC_VERTEX_INPUT "vec4 VertexColor;\n"
|
||||
LC_VERTEX_OUTPUT "vec3 PixelNormal;\n"
|
||||
LC_VERTEX_OUTPUT "vec4 PixelColor;\n"
|
||||
"uniform mat4 WorldViewProjectionMatrix;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" PixelNormal = VertexNormal;\n"
|
||||
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
|
||||
" PixelColor = VertexColor;\n"
|
||||
"}\n"
|
||||
},
|
||||
// LC_LIGHTING_FULL
|
||||
{
|
||||
// LC_MATERIAL_SIMPLE
|
||||
LC_SHADER_VERSION
|
||||
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
|
||||
"uniform mat4 WorldViewProjectionMatrix;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
|
||||
"}\n",
|
||||
// LC_MATERIAL_TEXTURE
|
||||
LC_SHADER_VERSION
|
||||
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
|
||||
LC_VERTEX_INPUT "vec2 VertexTexCoord;\n"
|
||||
LC_VERTEX_OUTPUT "vec2 PixelTexCoord;\n"
|
||||
"uniform mat4 WorldViewProjectionMatrix;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
|
||||
" PixelTexCoord = VertexTexCoord;\n"
|
||||
"}\n",
|
||||
// LC_MATERIAL_VERTEX_COLOR
|
||||
LC_SHADER_VERSION
|
||||
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
|
||||
LC_VERTEX_INPUT "vec4 VertexColor;\n"
|
||||
LC_VERTEX_OUTPUT "vec4 PixelColor;\n"
|
||||
"uniform mat4 WorldViewProjectionMatrix;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
|
||||
" PixelColor = VertexColor;\n"
|
||||
"}\n"
|
||||
}
|
||||
};
|
||||
|
||||
const char* FragmentShaders[LC_NUM_PROGRAMS] =
|
||||
const char* FragmentShaders[LC_NUM_LIGHTING_MODES][LC_NUM_MATERIALS] =
|
||||
{
|
||||
// LC_PROGRAM_SIMPLE
|
||||
LC_SHADER_VERSION
|
||||
LC_PIXEL_OUTPUT
|
||||
"uniform mediump vec4 Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = Color;\n"
|
||||
"}\n",
|
||||
// LC_PROGRAM_TEXTURE
|
||||
LC_SHADER_VERSION
|
||||
LC_PIXEL_INPUT "vec2 PixelTexCoord;\n"
|
||||
LC_PIXEL_OUTPUT
|
||||
"uniform mediump vec4 Color;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = texture2D(Texture, PixelTexCoord) * Color;\n"
|
||||
"}\n",
|
||||
// LC_PROGRAM_VERTEX_COLOR
|
||||
LC_SHADER_VERSION
|
||||
LC_PIXEL_INPUT "vec4 PixelColor;\n"
|
||||
LC_PIXEL_OUTPUT
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = PixelColor;\n"
|
||||
"}\n"
|
||||
// LC_LIGHTING_UNLIT
|
||||
{
|
||||
// LC_MATERIAL_SIMPLE
|
||||
LC_SHADER_VERSION
|
||||
LC_PIXEL_OUTPUT
|
||||
"uniform mediump vec4 Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = Color;\n"
|
||||
"}\n",
|
||||
// LC_MATERIAL_TEXTURE
|
||||
LC_SHADER_VERSION
|
||||
LC_PIXEL_INPUT "vec2 PixelTexCoord;\n"
|
||||
LC_PIXEL_OUTPUT
|
||||
"uniform mediump vec4 Color;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = texture2D(Texture, PixelTexCoord) * Color;\n"
|
||||
"}\n",
|
||||
// LC_MATERIAL_VERTEX_COLOR
|
||||
LC_SHADER_VERSION
|
||||
LC_PIXEL_INPUT "vec4 PixelColor;\n"
|
||||
LC_PIXEL_OUTPUT
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = PixelColor;\n"
|
||||
"}\n"
|
||||
},
|
||||
// LC_LIGHTING_FAKE
|
||||
{
|
||||
// LC_MATERIAL_SIMPLE
|
||||
LC_SHADER_VERSION
|
||||
LC_PIXEL_INPUT "vec3 PixelNormal;\n"
|
||||
LC_PIXEL_OUTPUT
|
||||
"uniform mediump vec4 Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = vec4(PixelNormal, 1.0);\n"
|
||||
"}\n",
|
||||
// LC_MATERIAL_TEXTURE
|
||||
LC_SHADER_VERSION
|
||||
LC_PIXEL_INPUT "vec3 PixelNormal;\n"
|
||||
LC_PIXEL_INPUT "vec2 PixelTexCoord;\n"
|
||||
LC_PIXEL_OUTPUT
|
||||
"uniform mediump vec4 Color;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = vec4(PixelNormal, 1.0);\n"
|
||||
"}\n",
|
||||
// LC_MATERIAL_VERTEX_COLOR
|
||||
LC_SHADER_VERSION
|
||||
LC_PIXEL_INPUT "vec3 PixelNormal;\n"
|
||||
LC_PIXEL_INPUT "vec4 PixelColor;\n"
|
||||
LC_PIXEL_OUTPUT
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = vec4(PixelNormal, 1.0);\n"
|
||||
"}\n"
|
||||
},
|
||||
// LC_LIGHTING_FULL
|
||||
{
|
||||
// LC_MATERIAL_SIMPLE
|
||||
LC_SHADER_VERSION
|
||||
LC_PIXEL_OUTPUT
|
||||
"uniform mediump vec4 Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = Color;\n"
|
||||
"}\n",
|
||||
// LC_MATERIAL_TEXTURE
|
||||
LC_SHADER_VERSION
|
||||
LC_PIXEL_INPUT "vec2 PixelTexCoord;\n"
|
||||
LC_PIXEL_OUTPUT
|
||||
"uniform mediump vec4 Color;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = texture2D(Texture, PixelTexCoord) * Color;\n"
|
||||
"}\n",
|
||||
// LC_MATERIAL_VERTEX_COLOR
|
||||
LC_SHADER_VERSION
|
||||
LC_PIXEL_INPUT "vec4 PixelColor;\n"
|
||||
LC_PIXEL_OUTPUT
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = PixelColor;\n"
|
||||
"}\n"
|
||||
}
|
||||
};
|
||||
|
||||
for (int ProgramIdx = 0; ProgramIdx < LC_NUM_PROGRAMS; ProgramIdx++)
|
||||
for (int LightingMode = 0; LightingMode < LC_NUM_LIGHTING_MODES; LightingMode++)
|
||||
{
|
||||
GLuint VertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(VertexShader, 1, &VertexShaders[ProgramIdx], NULL);
|
||||
glCompileShader(VertexShader);
|
||||
for (int MaterialType = 0; MaterialType < LC_NUM_MATERIALS; MaterialType++)
|
||||
{
|
||||
GLuint VertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(VertexShader, 1, &VertexShaders[LightingMode][MaterialType], NULL);
|
||||
glCompileShader(VertexShader);
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
GLint VertexShaderCompiled = 0;
|
||||
glGetShaderiv(VertexShader, GL_COMPILE_STATUS, &VertexShaderCompiled);
|
||||
GLint VertexShaderCompiled = 0;
|
||||
glGetShaderiv(VertexShader, GL_COMPILE_STATUS, &VertexShaderCompiled);
|
||||
|
||||
if (VertexShaderCompiled == GL_FALSE)
|
||||
{
|
||||
GLint Length = 0;
|
||||
glGetShaderiv(VertexShader, GL_INFO_LOG_LENGTH, &Length);
|
||||
if (VertexShaderCompiled == GL_FALSE)
|
||||
{
|
||||
GLint Length = 0;
|
||||
glGetShaderiv(VertexShader, GL_INFO_LOG_LENGTH, &Length);
|
||||
|
||||
QByteArray InfoLog;
|
||||
InfoLog.resize(Length);
|
||||
glGetShaderInfoLog(VertexShader, Length, &Length, InfoLog.data());
|
||||
QByteArray InfoLog;
|
||||
InfoLog.resize(Length);
|
||||
glGetShaderInfoLog(VertexShader, Length, &Length, InfoLog.data());
|
||||
|
||||
qDebug() << InfoLog;
|
||||
}
|
||||
qDebug() << InfoLog;
|
||||
}
|
||||
#endif
|
||||
|
||||
GLuint FragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(FragmentShader, 1, &FragmentShaders[ProgramIdx], NULL);
|
||||
glCompileShader(FragmentShader);
|
||||
GLuint FragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(FragmentShader, 1, &FragmentShaders[LightingMode][MaterialType], NULL);
|
||||
glCompileShader(FragmentShader);
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
GLint FragmentShaderCompiled = 0;
|
||||
glGetShaderiv(FragmentShader, GL_COMPILE_STATUS, &FragmentShaderCompiled);
|
||||
GLint FragmentShaderCompiled = 0;
|
||||
glGetShaderiv(FragmentShader, GL_COMPILE_STATUS, &FragmentShaderCompiled);
|
||||
|
||||
if (FragmentShaderCompiled == GL_FALSE)
|
||||
{
|
||||
GLint Length = 0;
|
||||
glGetShaderiv(FragmentShader, GL_INFO_LOG_LENGTH, &Length);
|
||||
if (FragmentShaderCompiled == GL_FALSE)
|
||||
{
|
||||
GLint Length = 0;
|
||||
glGetShaderiv(FragmentShader, GL_INFO_LOG_LENGTH, &Length);
|
||||
|
||||
QByteArray InfoLog;
|
||||
InfoLog.resize(Length);
|
||||
glGetShaderInfoLog(FragmentShader, Length, &Length, InfoLog.data());
|
||||
QByteArray InfoLog;
|
||||
InfoLog.resize(Length);
|
||||
glGetShaderInfoLog(FragmentShader, Length, &Length, InfoLog.data());
|
||||
|
||||
qDebug() << InfoLog;
|
||||
}
|
||||
qDebug() << InfoLog;
|
||||
}
|
||||
#endif
|
||||
|
||||
GLuint Program = glCreateProgram();
|
||||
GLuint Program = glCreateProgram();
|
||||
|
||||
glAttachShader(Program, VertexShader);
|
||||
glAttachShader(Program, FragmentShader);
|
||||
glAttachShader(Program, VertexShader);
|
||||
glAttachShader(Program, FragmentShader);
|
||||
|
||||
glBindAttribLocation(Program, LC_ATTRIB_POSITION, "VertexPosition");
|
||||
glBindAttribLocation(Program, LC_ATTRIB_TEXCOORD, "VertexTexCoord");
|
||||
glBindAttribLocation(Program, LC_ATTRIB_COLOR, "VertexColor");
|
||||
glBindAttribLocation(Program, LC_ATTRIB_POSITION, "VertexPosition");
|
||||
glBindAttribLocation(Program, LC_ATTRIB_NORMAL, "VertexNormal");
|
||||
glBindAttribLocation(Program, LC_ATTRIB_TEXCOORD, "VertexTexCoord");
|
||||
glBindAttribLocation(Program, LC_ATTRIB_COLOR, "VertexColor");
|
||||
|
||||
glLinkProgram(Program);
|
||||
glLinkProgram(Program);
|
||||
|
||||
glDetachShader(Program, VertexShader);
|
||||
glDetachShader(Program, FragmentShader);
|
||||
glDeleteShader(VertexShader);
|
||||
glDeleteShader(FragmentShader);
|
||||
glDetachShader(Program, VertexShader);
|
||||
glDetachShader(Program, FragmentShader);
|
||||
glDeleteShader(VertexShader);
|
||||
glDeleteShader(FragmentShader);
|
||||
|
||||
GLint IsLinked = 0;
|
||||
glGetProgramiv(Program, GL_LINK_STATUS, &IsLinked);
|
||||
if (IsLinked == GL_FALSE)
|
||||
{
|
||||
GLint Length = 0;
|
||||
glGetProgramiv(Program, GL_INFO_LOG_LENGTH, &Length);
|
||||
GLint IsLinked = 0;
|
||||
glGetProgramiv(Program, GL_LINK_STATUS, &IsLinked);
|
||||
if (IsLinked == GL_FALSE)
|
||||
{
|
||||
GLint Length = 0;
|
||||
glGetProgramiv(Program, GL_INFO_LOG_LENGTH, &Length);
|
||||
|
||||
QByteArray InfoLog;
|
||||
InfoLog.resize(Length);
|
||||
glGetProgramInfoLog(Program, Length, &Length, InfoLog.data());
|
||||
|
||||
glDeleteProgram(Program);
|
||||
Program = 0;
|
||||
QByteArray InfoLog;
|
||||
InfoLog.resize(Length);
|
||||
glGetProgramInfoLog(Program, Length, &Length, InfoLog.data());
|
||||
|
||||
glDeleteProgram(Program);
|
||||
Program = 0;
|
||||
}
|
||||
|
||||
mPrograms[LightingMode][MaterialType].Object = Program;
|
||||
mPrograms[LightingMode][MaterialType].MatrixLocation = glGetUniformLocation(Program, "WorldViewProjectionMatrix");
|
||||
mPrograms[LightingMode][MaterialType].ColorLocation = glGetUniformLocation(Program, "Color");
|
||||
}
|
||||
|
||||
mPrograms[ProgramIdx].Object = Program;
|
||||
mPrograms[ProgramIdx].MatrixLocation = glGetUniformLocation(Program, "WorldViewProjectionMatrix");
|
||||
mPrograms[ProgramIdx].ColorLocation = glGetUniformLocation(Program, "Color");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,8 +428,9 @@ void lcContext::DestroyResources()
|
|||
if (!gSupportsShaderObjects)
|
||||
return;
|
||||
|
||||
for (int ProgramIdx = 0; ProgramIdx < LC_NUM_PROGRAMS; ProgramIdx++)
|
||||
glDeleteProgram(mPrograms[ProgramIdx].Object);
|
||||
for (int LightingMode = 0; LightingMode < LC_NUM_LIGHTING_MODES; LightingMode++)
|
||||
for (int MaterialType = 0; MaterialType < LC_NUM_MATERIALS; MaterialType++)
|
||||
glDeleteProgram(mPrograms[LightingMode][MaterialType].Object);
|
||||
}
|
||||
|
||||
void lcContext::SetDefaultState()
|
||||
|
@ -339,7 +486,7 @@ void lcContext::SetDefaultState()
|
|||
if (gSupportsShaderObjects)
|
||||
{
|
||||
glUseProgram(0);
|
||||
mProgramType = LC_NUM_PROGRAMS;
|
||||
mMaterialType = LC_NUM_MATERIALS;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -357,15 +504,16 @@ void lcContext::SetLightingMode(lcLightingMode LightingMode)
|
|||
return;
|
||||
|
||||
mLightingMode = LightingMode;
|
||||
mMaterialType = LC_NUM_MATERIALS;
|
||||
}
|
||||
|
||||
void lcContext::SetProgram(lcProgramType ProgramType)
|
||||
void lcContext::SetMaterial(lcMaterialType MaterialType)
|
||||
{
|
||||
if (!gSupportsShaderObjects || mProgramType == ProgramType)
|
||||
if (!gSupportsShaderObjects || mMaterialType == MaterialType)
|
||||
return;
|
||||
|
||||
glUseProgram(mPrograms[ProgramType].Object);
|
||||
mProgramType = ProgramType;
|
||||
glUseProgram(mPrograms[mLightingMode][MaterialType].Object);
|
||||
mMaterialType = MaterialType;
|
||||
mColorDirty = true;
|
||||
mWorldMatrixDirty = true;
|
||||
}
|
||||
|
@ -953,6 +1101,8 @@ void lcContext::FlushState()
|
|||
{
|
||||
if (gSupportsShaderObjects)
|
||||
{
|
||||
const lcProgram& Program = mPrograms[mLightingMode][mMaterialType];
|
||||
|
||||
if (mWorldMatrixDirty || mViewMatrixDirty || mProjectionMatrixDirty)
|
||||
{
|
||||
if (mViewProjectionMatrixDirty)
|
||||
|
@ -961,15 +1111,15 @@ void lcContext::FlushState()
|
|||
mViewProjectionMatrixDirty = false;
|
||||
}
|
||||
|
||||
glUniformMatrix4fv(mPrograms[mProgramType].MatrixLocation, 1, false, lcMul(mWorldMatrix, mViewProjectionMatrix));
|
||||
glUniformMatrix4fv(Program.MatrixLocation, 1, false, lcMul(mWorldMatrix, mViewProjectionMatrix));
|
||||
mWorldMatrixDirty = false;
|
||||
mViewMatrixDirty = false;
|
||||
mProjectionMatrixDirty = false;
|
||||
}
|
||||
|
||||
if (mColorDirty && mPrograms[mProgramType].ColorLocation != -1)
|
||||
if (mColorDirty && Program.ColorLocation != -1)
|
||||
{
|
||||
glUniform4fv(mPrograms[mProgramType].ColorLocation, 1, mColor);
|
||||
glUniform4fv(Program.ColorLocation, 1, mColor);
|
||||
mColorDirty = false;
|
||||
}
|
||||
}
|
||||
|
@ -1026,7 +1176,7 @@ void lcContext::DrawMeshSection(lcMesh* Mesh, lcMeshSection* Section)
|
|||
|
||||
if (!Texture)
|
||||
{
|
||||
SetProgram(LC_PROGRAM_SIMPLE);
|
||||
SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
SetVertexFormat(VertexBufferOffset, 3, 1, 0, 0);
|
||||
|
||||
if (mTexture)
|
||||
|
@ -1038,7 +1188,7 @@ void lcContext::DrawMeshSection(lcMesh* Mesh, lcMeshSection* Section)
|
|||
else
|
||||
{
|
||||
VertexBufferOffset += Mesh->mNumVertices * sizeof(lcVertex);
|
||||
SetProgram(LC_PROGRAM_TEXTURE);
|
||||
SetMaterial(LC_MATERIAL_TEXTURE);
|
||||
SetVertexFormat(VertexBufferOffset, 3, 1, 2, 0);
|
||||
|
||||
if (Texture != mTexture)
|
||||
|
|
|
@ -64,15 +64,16 @@ enum lcLightingMode : int
|
|||
{
|
||||
LC_LIGHTING_UNLIT,
|
||||
LC_LIGHTING_FAKE,
|
||||
LC_LIGHTING_FULL
|
||||
LC_LIGHTING_FULL,
|
||||
LC_NUM_LIGHTING_MODES
|
||||
};
|
||||
|
||||
enum lcProgramType
|
||||
enum lcMaterialType
|
||||
{
|
||||
LC_PROGRAM_SIMPLE,
|
||||
LC_PROGRAM_TEXTURE,
|
||||
LC_PROGRAM_VERTEX_COLOR,
|
||||
LC_NUM_PROGRAMS
|
||||
LC_MATERIAL_SIMPLE,
|
||||
LC_MATERIAL_TEXTURE,
|
||||
LC_MATERIAL_VERTEX_COLOR,
|
||||
LC_NUM_MATERIALS
|
||||
};
|
||||
|
||||
enum lcProgramAttrib
|
||||
|
@ -129,7 +130,7 @@ public:
|
|||
}
|
||||
|
||||
void SetLightingMode(lcLightingMode LightingMode);
|
||||
void SetProgram(lcProgramType ProgramType);
|
||||
void SetMaterial(lcMaterialType MaterialType);
|
||||
void SetViewport(int x, int y, int Width, int Height);
|
||||
void SetLineWidth(float LineWidth);
|
||||
void SetTextureMode(lcTextureMode TextureMode);
|
||||
|
@ -186,7 +187,7 @@ protected:
|
|||
char* mVertexBufferOffset;
|
||||
|
||||
lcLightingMode mLightingMode;
|
||||
lcProgramType mProgramType;
|
||||
lcMaterialType mMaterialType;
|
||||
bool mNormalEnabled;
|
||||
bool mTexCoordEnabled;
|
||||
bool mColorEnabled;
|
||||
|
@ -210,7 +211,7 @@ protected:
|
|||
GLuint mFramebufferTexture;
|
||||
GLuint mDepthRenderbufferObject;
|
||||
|
||||
static lcProgram mPrograms[LC_NUM_PROGRAMS];
|
||||
static lcProgram mPrograms[LC_NUM_LIGHTING_MODES][LC_NUM_MATERIALS];
|
||||
|
||||
Q_DECLARE_TR_FUNCTIONS(lcContext);
|
||||
};
|
||||
|
|
|
@ -2176,7 +2176,7 @@ void lcLibraryMeshData::AddLine(lcMeshDataType MeshDataType, int LineType, lcuin
|
|||
if (LineType == 4)
|
||||
TestQuad(QuadIndices, Vertices);
|
||||
|
||||
lcVector3 Normal = lcCross(Vertices[1] - Vertices[0], Vertices[2] - Vertices[0]);
|
||||
lcVector3 Normal = lcNormalize(lcCross(Vertices[1] - Vertices[0], Vertices[2] - Vertices[0]));
|
||||
|
||||
if (!WindingCCW)
|
||||
Normal = -Normal;
|
||||
|
@ -2266,7 +2266,7 @@ void lcLibraryMeshData::AddTexturedLine(lcMeshDataType MeshDataType, int LineTyp
|
|||
if (LineType == 4)
|
||||
TestQuad(QuadIndices, Vertices);
|
||||
|
||||
lcVector3 Normal = lcCross(Vertices[1] - Vertices[0], Vertices[2] - Vertices[0]);
|
||||
lcVector3 Normal = lcNormalize(lcCross(Vertices[1] - Vertices[0], Vertices[2] - Vertices[0]));
|
||||
|
||||
if (!WindingCCW)
|
||||
Normal = -Normal;
|
||||
|
@ -2360,7 +2360,7 @@ void lcLibraryMeshData::AddMeshData(const lcLibraryMeshData& Data, const lcMatri
|
|||
Index = AddVertex((lcMeshDataType)MeshDataIdx, Position, true);
|
||||
else
|
||||
{
|
||||
lcVector3 Normal = lcMul30(DataVertices[SrcVertexIdx].Normal, Transform);
|
||||
lcVector3 Normal = lcNormalize(lcMul30(DataVertices[SrcVertexIdx].Normal, Transform));
|
||||
Index = AddVertex((lcMeshDataType)MeshDataIdx, Position, Normal, true);
|
||||
}
|
||||
|
||||
|
@ -2383,7 +2383,7 @@ void lcLibraryMeshData::AddMeshData(const lcLibraryMeshData& Data, const lcMatri
|
|||
Index = AddTexturedVertex((lcMeshDataType)MeshDataIdx, Position, TexCoord, true);
|
||||
else
|
||||
{
|
||||
lcVector3 Normal = lcMul30(DataVertices[SrcVertexIdx].Normal, Transform);
|
||||
lcVector3 Normal = lcNormalize(lcMul30(DataVertices[SrcVertexIdx].Normal, Transform));
|
||||
Index = AddTexturedVertex((lcMeshDataType)MeshDataIdx, Position, Normal, TexCoord, true);
|
||||
}
|
||||
|
||||
|
@ -2409,7 +2409,7 @@ void lcLibraryMeshData::AddMeshData(const lcLibraryMeshData& Data, const lcMatri
|
|||
Index = AddTexturedVertex((lcMeshDataType)MeshDataIdx, Position, SrcVertex.TexCoord, true);
|
||||
else
|
||||
{
|
||||
lcVector3 Normal = lcMul30(DataVertices[SrcVertexIdx].Normal, Transform);
|
||||
lcVector3 Normal = lcNormalize(lcMul30(DataVertices[SrcVertexIdx].Normal, Transform));
|
||||
Index = AddTexturedVertex((lcMeshDataType)MeshDataIdx, Position, Normal, SrcVertex.TexCoord, true);
|
||||
}
|
||||
|
||||
|
@ -2514,7 +2514,7 @@ void lcLibraryMeshData::AddMeshDataNoDuplicateCheck(const lcLibraryMeshData& Dat
|
|||
const lcLibraryMeshVertex& SrcVertex = DataVertices[SrcVertexIdx];
|
||||
lcLibraryMeshVertex& DstVertex = Vertices.Add();
|
||||
DstVertex.Position = lcMul31(SrcVertex.Position, Transform);
|
||||
DstVertex.Normal = lcMul30(SrcVertex.Normal, Transform);
|
||||
DstVertex.Normal = lcNormalize(lcMul30(SrcVertex.Normal, Transform));
|
||||
DstVertex.NormalWeight = SrcVertex.NormalWeight;
|
||||
}
|
||||
}
|
||||
|
@ -2534,7 +2534,7 @@ void lcLibraryMeshData::AddMeshDataNoDuplicateCheck(const lcLibraryMeshData& Dat
|
|||
lcDot3(lcVector3(Position.x, Position.y, Position.z), TextureMap->Params[1]) + TextureMap->Params[1].w);
|
||||
|
||||
DstVertex.Position = Position;
|
||||
DstVertex.Normal = lcMul30(SrcVertex.Normal, Transform);
|
||||
DstVertex.Normal = lcNormalize(lcMul30(SrcVertex.Normal, Transform));
|
||||
DstVertex.NormalWeight = SrcVertex.NormalWeight;
|
||||
DstVertex.TexCoord = TexCoord;
|
||||
}
|
||||
|
|
|
@ -1144,7 +1144,7 @@ void lcModel::DrawBackground(lcGLWidget* Widget)
|
|||
ViewWidth, 0.0f, Color2[0], Color2[1], Color2[2], 1.0f
|
||||
};
|
||||
|
||||
Context->SetProgram(LC_PROGRAM_VERTEX_COLOR);
|
||||
Context->SetMaterial(LC_MATERIAL_VERTEX_COLOR);
|
||||
Context->SetVertexBufferPointer(Verts);
|
||||
Context->SetVertexFormat(0, 2, 0, 0, 4);
|
||||
|
||||
|
@ -1179,7 +1179,7 @@ void lcModel::DrawBackground(lcGLWidget* Widget)
|
|||
0.0f, 0.0f, 0.0f, TileHeight
|
||||
};
|
||||
|
||||
Context->SetProgram(LC_PROGRAM_TEXTURE);
|
||||
Context->SetMaterial(LC_MATERIAL_TEXTURE);
|
||||
Context->SetVertexBufferPointer(Verts);
|
||||
Context->SetVertexFormat(0, 2, 0, 2, 0);
|
||||
|
||||
|
|
|
@ -334,7 +334,8 @@ void lcPartSelectionListModel::DrawPreview(int InfoIndex)
|
|||
|
||||
Context->SetDefaultState();
|
||||
Context->SetProjectionMatrix(ProjectionMatrix);
|
||||
Context->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
Context->SetLightingMode(LC_LIGHTING_UNLIT);
|
||||
Context->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
|
||||
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
||||
PieceInfo* Info = mParts[InfoIndex].first;
|
||||
|
|
|
@ -284,7 +284,7 @@ void lcLight::UpdatePosition(lcStep Step)
|
|||
|
||||
void lcLight::DrawInterface(lcContext* Context) const
|
||||
{
|
||||
Context->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
Context->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
|
||||
if (IsPointLight())
|
||||
DrawPointLight(Context);
|
||||
|
|
|
@ -292,7 +292,7 @@ void MinifigWizard::OnDraw()
|
|||
|
||||
Scene.End();
|
||||
|
||||
mContext->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
mContext->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
mContext->DrawOpaqueMeshes(Scene.mOpaqueMeshes);
|
||||
mContext->DrawTranslucentMeshes(Scene.mTranslucentMeshes);
|
||||
|
||||
|
|
|
@ -520,7 +520,7 @@ void lcPiece::DrawInterface(lcContext* Context) const
|
|||
{ Min[0], Min[1], Min[2] }, { Min[0], Min[1], Min[2] + Edge[2] },
|
||||
};
|
||||
|
||||
Context->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
Context->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
Context->SetWorldMatrix(mModelWorld);
|
||||
|
||||
if (IsFocused(LC_PIECE_SECTION_POSITION))
|
||||
|
|
|
@ -1313,7 +1313,7 @@ void Project::ExportHTML()
|
|||
|
||||
Context->SetDefaultState();
|
||||
Context->SetProjectionMatrix(ProjectionMatrix);
|
||||
Context->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
Context->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
|
||||
for (lcPartsList::const_iterator PartIt = PartsList.constBegin(); PartIt != PartsList.constEnd(); PartIt++)
|
||||
{
|
||||
|
|
|
@ -569,7 +569,7 @@ void View::OnDraw()
|
|||
mContext->SetViewMatrix(mCamera->mWorldView);
|
||||
mContext->SetProjectionMatrix(GetProjectionMatrix());
|
||||
mContext->SetLightingMode(Preferences.mLightingMode);
|
||||
mContext->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
mContext->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
|
||||
#ifndef LC_OPENGLES
|
||||
const lcModelProperties& Properties = mModel->GetProperties();
|
||||
|
@ -598,7 +598,7 @@ void View::OnDraw()
|
|||
if (DrawInterface)
|
||||
{
|
||||
mContext->SetLightingMode(LC_LIGHTING_UNLIT);
|
||||
mContext->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
mContext->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
mContext->DrawInterfaceObjects(mScene.mInterfaceObjects);
|
||||
|
||||
mContext->SetLineWidth(1.0f);
|
||||
|
@ -627,7 +627,7 @@ void View::OnDraw()
|
|||
|
||||
void View::DrawSelectMoveOverlay()
|
||||
{
|
||||
mContext->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
mContext->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
mContext->SetViewMatrix(mCamera->mWorldView);
|
||||
mContext->SetProjectionMatrix(GetProjectionMatrix());
|
||||
|
||||
|
@ -818,7 +818,7 @@ void View::DrawRotateOverlay()
|
|||
const float OverlayScale = GetOverlayScale();
|
||||
const float OverlayRotateRadius = 2.0f;
|
||||
|
||||
mContext->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
mContext->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
mContext->SetViewMatrix(mCamera->mWorldView);
|
||||
mContext->SetProjectionMatrix(GetProjectionMatrix());
|
||||
|
||||
|
@ -1089,7 +1089,7 @@ void View::DrawRotateOverlay()
|
|||
// Draw text.
|
||||
lcVector3 ScreenPos = ProjectPoint(OverlayCenter);
|
||||
|
||||
mContext->SetProgram(LC_PROGRAM_TEXTURE);
|
||||
mContext->SetMaterial(LC_MATERIAL_TEXTURE);
|
||||
mContext->SetWorldMatrix(lcMatrix44Identity());
|
||||
mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0)));
|
||||
mContext->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f));
|
||||
|
@ -1118,7 +1118,7 @@ void View::DrawRotateOverlay()
|
|||
|
||||
void View::DrawSelectZoomRegionOverlay()
|
||||
{
|
||||
mContext->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
mContext->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
mContext->SetWorldMatrix(lcMatrix44Identity());
|
||||
mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0)));
|
||||
mContext->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f));
|
||||
|
@ -1207,7 +1207,7 @@ void View::DrawRotateViewOverlay()
|
|||
w = mWidth;
|
||||
h = mHeight;
|
||||
|
||||
mContext->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
mContext->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
mContext->SetWorldMatrix(lcMatrix44Identity());
|
||||
mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0)));
|
||||
mContext->SetProjectionMatrix(lcMatrix44Ortho(0, w, 0, h, -1, 1));
|
||||
|
@ -1421,7 +1421,7 @@ void View::DrawGrid()
|
|||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
mContext->SetProgram(LC_PROGRAM_TEXTURE);
|
||||
mContext->SetMaterial(LC_MATERIAL_TEXTURE);
|
||||
mContext->SetColor(lcVector4FromColor(Preferences.mGridStudColor));
|
||||
|
||||
mContext->SetVertexFormat(0, 3, 0, 2, 0);
|
||||
|
@ -1436,7 +1436,7 @@ void View::DrawGrid()
|
|||
if (Preferences.mDrawGridLines)
|
||||
{
|
||||
mContext->SetLineWidth(1.0f);
|
||||
mContext->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
mContext->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
mContext->SetColor(lcVector4FromColor(Preferences.mGridLineColor));
|
||||
|
||||
int NumVerts = 2 * (MaxX - MinX + MaxY - MinY + 2);
|
||||
|
@ -1475,7 +1475,7 @@ void View::DrawAxes()
|
|||
lcMatrix44 WorldViewMatrix = mCamera->mWorldView;
|
||||
WorldViewMatrix.SetTranslation(lcVector3(0, 0, 0));
|
||||
|
||||
mContext->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
mContext->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
mContext->SetWorldMatrix(lcMatrix44Identity());
|
||||
mContext->SetViewMatrix(lcMul(WorldViewMatrix, TranslationMatrix));
|
||||
mContext->SetProjectionMatrix(lcMatrix44Ortho(0, mWidth, 0, mHeight, -50, 50));
|
||||
|
@ -1494,7 +1494,7 @@ void View::DrawAxes()
|
|||
mContext->SetColor(0.0f, 0.0f, 0.8f, 1.0f);
|
||||
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 24, GL_UNSIGNED_SHORT, (6 + 48) * 2);
|
||||
|
||||
mContext->SetProgram(LC_PROGRAM_TEXTURE);
|
||||
mContext->SetMaterial(LC_MATERIAL_TEXTURE);
|
||||
mContext->SetViewMatrix(TranslationMatrix);
|
||||
mContext->SetTextureMode(LC_TEXTURE_MODULATE);
|
||||
gTexFont.MakeCurrent();
|
||||
|
@ -1534,7 +1534,7 @@ void View::DrawViewport()
|
|||
|
||||
if (gMainWindow->GetActiveView() == this)
|
||||
{
|
||||
mContext->SetProgram(LC_PROGRAM_SIMPLE);
|
||||
mContext->SetMaterial(LC_MATERIAL_SIMPLE);
|
||||
mContext->SetColor(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
float Verts[8] = { 0.0f, 0.0f, mWidth - 1.0f, 0.0f, mWidth - 1.0f, mHeight - 1.0f, 0.0f, mHeight - 1.0f };
|
||||
|
||||
|
@ -1549,7 +1549,7 @@ void View::DrawViewport()
|
|||
|
||||
if (CameraName[0])
|
||||
{
|
||||
mContext->SetProgram(LC_PROGRAM_TEXTURE);
|
||||
mContext->SetMaterial(LC_MATERIAL_TEXTURE);
|
||||
mContext->SetColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
|
|
@ -112,7 +112,7 @@ void lcQPreferencesDialog::accept()
|
|||
options->Preferences.mGridLineSpacing = gridLineSpacing;
|
||||
|
||||
options->Preferences.mDrawAxes = ui->axisIcon->isChecked();
|
||||
options->Preferences.mLightingMode = ui->enableLighting->isChecked() ? LC_LIGHTING_FULL : LC_LIGHTING_UNLIT;
|
||||
options->Preferences.mLightingMode = ui->enableLighting->isChecked() ? LC_LIGHTING_FAKE : LC_LIGHTING_UNLIT;
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue