Added shaders for each material/lighting combination.

This commit is contained in:
leozide 2017-02-28 15:20:34 -08:00
parent fa099a12e2
commit 7e3f572b8e
12 changed files with 319 additions and 167 deletions

View file

@ -468,7 +468,7 @@ void lcCamera::CopyPosition(const lcCamera* camera)
void lcCamera::DrawInterface(lcContext* Context) const void lcCamera::DrawInterface(lcContext* Context) const
{ {
Context->SetProgram(LC_PROGRAM_SIMPLE); Context->SetMaterial(LC_MATERIAL_SIMPLE);
lcMatrix44 ViewWorldMatrix = lcMatrix44AffineInverse(mWorldView); lcMatrix44 ViewWorldMatrix = lcMatrix44AffineInverse(mWorldView);
ViewWorldMatrix.SetTranslation(lcVector3(0, 0, 0)); ViewWorldMatrix.SetTranslation(lcVector3(0, 0, 0));

View file

@ -18,7 +18,7 @@
#define GL_STATIC_DRAW_ARB GL_STATIC_DRAW #define GL_STATIC_DRAW_ARB GL_STATIC_DRAW
#endif #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) static int lcOpaqueRenderMeshCompare(const void* Elem1, const void* Elem2)
{ {
@ -100,8 +100,8 @@ lcContext::lcContext()
mProjectionMatrixDirty = false; mProjectionMatrixDirty = false;
mViewProjectionMatrixDirty = false; mViewProjectionMatrixDirty = false;
mLightingMode = LC_LIGHTING_UNLIT; mLightingMode = LC_NUM_LIGHTING_MODES;
mProgramType = LC_NUM_PROGRAMS; mMaterialType = LC_NUM_MATERIALS;
} }
lcContext::~lcContext() lcContext::~lcContext()
@ -124,9 +124,11 @@ void lcContext::CreateShaderPrograms()
#define LC_PIXEL_OUTPUT "#define gl_FragColor FragColor\nout mediump vec4 gl_FragColor;\n" #define LC_PIXEL_OUTPUT "#define gl_FragColor FragColor\nout mediump vec4 gl_FragColor;\n"
#endif #endif
const char* VertexShaders[LC_NUM_PROGRAMS] = const char* VertexShaders[LC_NUM_LIGHTING_MODES][LC_NUM_MATERIALS] =
{ {
// LC_PROGRAM_SIMPLE // LC_LIGHTING_UNLIT
{
// LC_MATERIAL_SIMPLE
LC_SHADER_VERSION LC_SHADER_VERSION
LC_VERTEX_INPUT "vec3 VertexPosition;\n" LC_VERTEX_INPUT "vec3 VertexPosition;\n"
"uniform mat4 WorldViewProjectionMatrix;\n" "uniform mat4 WorldViewProjectionMatrix;\n"
@ -134,7 +136,7 @@ void lcContext::CreateShaderPrograms()
"{\n" "{\n"
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n" " gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
"}\n", "}\n",
// LC_PROGRAM_TEXTURE // LC_MATERIAL_TEXTURE
LC_SHADER_VERSION LC_SHADER_VERSION
LC_VERTEX_INPUT "vec3 VertexPosition;\n" LC_VERTEX_INPUT "vec3 VertexPosition;\n"
LC_VERTEX_INPUT "vec2 VertexTexCoord;\n" LC_VERTEX_INPUT "vec2 VertexTexCoord;\n"
@ -145,7 +147,7 @@ void lcContext::CreateShaderPrograms()
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n" " gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
" PixelTexCoord = VertexTexCoord;\n" " PixelTexCoord = VertexTexCoord;\n"
"}\n", "}\n",
// LC_PROGRAM_VERTEX_COLOR // LC_MATERIAL_VERTEX_COLOR
LC_SHADER_VERSION LC_SHADER_VERSION
LC_VERTEX_INPUT "vec3 VertexPosition;\n" LC_VERTEX_INPUT "vec3 VertexPosition;\n"
LC_VERTEX_INPUT "vec4 VertexColor;\n" LC_VERTEX_INPUT "vec4 VertexColor;\n"
@ -156,11 +158,89 @@ void lcContext::CreateShaderPrograms()
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n" " gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
" PixelColor = VertexColor;\n" " PixelColor = VertexColor;\n"
"}\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_LIGHTING_UNLIT
{
// LC_MATERIAL_SIMPLE
LC_SHADER_VERSION LC_SHADER_VERSION
LC_PIXEL_OUTPUT LC_PIXEL_OUTPUT
"uniform mediump vec4 Color;\n" "uniform mediump vec4 Color;\n"
@ -168,7 +248,7 @@ void lcContext::CreateShaderPrograms()
"{\n" "{\n"
" gl_FragColor = Color;\n" " gl_FragColor = Color;\n"
"}\n", "}\n",
// LC_PROGRAM_TEXTURE // LC_MATERIAL_TEXTURE
LC_SHADER_VERSION LC_SHADER_VERSION
LC_PIXEL_INPUT "vec2 PixelTexCoord;\n" LC_PIXEL_INPUT "vec2 PixelTexCoord;\n"
LC_PIXEL_OUTPUT LC_PIXEL_OUTPUT
@ -178,7 +258,7 @@ void lcContext::CreateShaderPrograms()
"{\n" "{\n"
" gl_FragColor = texture2D(Texture, PixelTexCoord) * Color;\n" " gl_FragColor = texture2D(Texture, PixelTexCoord) * Color;\n"
"}\n", "}\n",
// LC_PROGRAM_VERTEX_COLOR // LC_MATERIAL_VERTEX_COLOR
LC_SHADER_VERSION LC_SHADER_VERSION
LC_PIXEL_INPUT "vec4 PixelColor;\n" LC_PIXEL_INPUT "vec4 PixelColor;\n"
LC_PIXEL_OUTPUT LC_PIXEL_OUTPUT
@ -186,12 +266,76 @@ void lcContext::CreateShaderPrograms()
"{\n" "{\n"
" gl_FragColor = PixelColor;\n" " gl_FragColor = PixelColor;\n"
"}\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++)
{
for (int MaterialType = 0; MaterialType < LC_NUM_MATERIALS; MaterialType++)
{ {
GLuint VertexShader = glCreateShader(GL_VERTEX_SHADER); GLuint VertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(VertexShader, 1, &VertexShaders[ProgramIdx], NULL); glShaderSource(VertexShader, 1, &VertexShaders[LightingMode][MaterialType], NULL);
glCompileShader(VertexShader); glCompileShader(VertexShader);
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
@ -212,7 +356,7 @@ void lcContext::CreateShaderPrograms()
#endif #endif
GLuint FragmentShader = glCreateShader(GL_FRAGMENT_SHADER); GLuint FragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(FragmentShader, 1, &FragmentShaders[ProgramIdx], NULL); glShaderSource(FragmentShader, 1, &FragmentShaders[LightingMode][MaterialType], NULL);
glCompileShader(FragmentShader); glCompileShader(FragmentShader);
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
@ -238,6 +382,7 @@ void lcContext::CreateShaderPrograms()
glAttachShader(Program, FragmentShader); glAttachShader(Program, FragmentShader);
glBindAttribLocation(Program, LC_ATTRIB_POSITION, "VertexPosition"); glBindAttribLocation(Program, LC_ATTRIB_POSITION, "VertexPosition");
glBindAttribLocation(Program, LC_ATTRIB_NORMAL, "VertexNormal");
glBindAttribLocation(Program, LC_ATTRIB_TEXCOORD, "VertexTexCoord"); glBindAttribLocation(Program, LC_ATTRIB_TEXCOORD, "VertexTexCoord");
glBindAttribLocation(Program, LC_ATTRIB_COLOR, "VertexColor"); glBindAttribLocation(Program, LC_ATTRIB_COLOR, "VertexColor");
@ -263,9 +408,10 @@ void lcContext::CreateShaderPrograms()
Program = 0; Program = 0;
} }
mPrograms[ProgramIdx].Object = Program; mPrograms[LightingMode][MaterialType].Object = Program;
mPrograms[ProgramIdx].MatrixLocation = glGetUniformLocation(Program, "WorldViewProjectionMatrix"); mPrograms[LightingMode][MaterialType].MatrixLocation = glGetUniformLocation(Program, "WorldViewProjectionMatrix");
mPrograms[ProgramIdx].ColorLocation = glGetUniformLocation(Program, "Color"); mPrograms[LightingMode][MaterialType].ColorLocation = glGetUniformLocation(Program, "Color");
}
} }
} }
@ -282,8 +428,9 @@ void lcContext::DestroyResources()
if (!gSupportsShaderObjects) if (!gSupportsShaderObjects)
return; return;
for (int ProgramIdx = 0; ProgramIdx < LC_NUM_PROGRAMS; ProgramIdx++) for (int LightingMode = 0; LightingMode < LC_NUM_LIGHTING_MODES; LightingMode++)
glDeleteProgram(mPrograms[ProgramIdx].Object); for (int MaterialType = 0; MaterialType < LC_NUM_MATERIALS; MaterialType++)
glDeleteProgram(mPrograms[LightingMode][MaterialType].Object);
} }
void lcContext::SetDefaultState() void lcContext::SetDefaultState()
@ -339,7 +486,7 @@ void lcContext::SetDefaultState()
if (gSupportsShaderObjects) if (gSupportsShaderObjects)
{ {
glUseProgram(0); glUseProgram(0);
mProgramType = LC_NUM_PROGRAMS; mMaterialType = LC_NUM_MATERIALS;
} }
else else
{ {
@ -357,15 +504,16 @@ void lcContext::SetLightingMode(lcLightingMode LightingMode)
return; return;
mLightingMode = LightingMode; 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; return;
glUseProgram(mPrograms[ProgramType].Object); glUseProgram(mPrograms[mLightingMode][MaterialType].Object);
mProgramType = ProgramType; mMaterialType = MaterialType;
mColorDirty = true; mColorDirty = true;
mWorldMatrixDirty = true; mWorldMatrixDirty = true;
} }
@ -953,6 +1101,8 @@ void lcContext::FlushState()
{ {
if (gSupportsShaderObjects) if (gSupportsShaderObjects)
{ {
const lcProgram& Program = mPrograms[mLightingMode][mMaterialType];
if (mWorldMatrixDirty || mViewMatrixDirty || mProjectionMatrixDirty) if (mWorldMatrixDirty || mViewMatrixDirty || mProjectionMatrixDirty)
{ {
if (mViewProjectionMatrixDirty) if (mViewProjectionMatrixDirty)
@ -961,15 +1111,15 @@ void lcContext::FlushState()
mViewProjectionMatrixDirty = false; mViewProjectionMatrixDirty = false;
} }
glUniformMatrix4fv(mPrograms[mProgramType].MatrixLocation, 1, false, lcMul(mWorldMatrix, mViewProjectionMatrix)); glUniformMatrix4fv(Program.MatrixLocation, 1, false, lcMul(mWorldMatrix, mViewProjectionMatrix));
mWorldMatrixDirty = false; mWorldMatrixDirty = false;
mViewMatrixDirty = false; mViewMatrixDirty = false;
mProjectionMatrixDirty = 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; mColorDirty = false;
} }
} }
@ -1026,7 +1176,7 @@ void lcContext::DrawMeshSection(lcMesh* Mesh, lcMeshSection* Section)
if (!Texture) if (!Texture)
{ {
SetProgram(LC_PROGRAM_SIMPLE); SetMaterial(LC_MATERIAL_SIMPLE);
SetVertexFormat(VertexBufferOffset, 3, 1, 0, 0); SetVertexFormat(VertexBufferOffset, 3, 1, 0, 0);
if (mTexture) if (mTexture)
@ -1038,7 +1188,7 @@ void lcContext::DrawMeshSection(lcMesh* Mesh, lcMeshSection* Section)
else else
{ {
VertexBufferOffset += Mesh->mNumVertices * sizeof(lcVertex); VertexBufferOffset += Mesh->mNumVertices * sizeof(lcVertex);
SetProgram(LC_PROGRAM_TEXTURE); SetMaterial(LC_MATERIAL_TEXTURE);
SetVertexFormat(VertexBufferOffset, 3, 1, 2, 0); SetVertexFormat(VertexBufferOffset, 3, 1, 2, 0);
if (Texture != mTexture) if (Texture != mTexture)

View file

@ -64,15 +64,16 @@ enum lcLightingMode : int
{ {
LC_LIGHTING_UNLIT, LC_LIGHTING_UNLIT,
LC_LIGHTING_FAKE, LC_LIGHTING_FAKE,
LC_LIGHTING_FULL LC_LIGHTING_FULL,
LC_NUM_LIGHTING_MODES
}; };
enum lcProgramType enum lcMaterialType
{ {
LC_PROGRAM_SIMPLE, LC_MATERIAL_SIMPLE,
LC_PROGRAM_TEXTURE, LC_MATERIAL_TEXTURE,
LC_PROGRAM_VERTEX_COLOR, LC_MATERIAL_VERTEX_COLOR,
LC_NUM_PROGRAMS LC_NUM_MATERIALS
}; };
enum lcProgramAttrib enum lcProgramAttrib
@ -129,7 +130,7 @@ public:
} }
void SetLightingMode(lcLightingMode LightingMode); void SetLightingMode(lcLightingMode LightingMode);
void SetProgram(lcProgramType ProgramType); void SetMaterial(lcMaterialType MaterialType);
void SetViewport(int x, int y, int Width, int Height); void SetViewport(int x, int y, int Width, int Height);
void SetLineWidth(float LineWidth); void SetLineWidth(float LineWidth);
void SetTextureMode(lcTextureMode TextureMode); void SetTextureMode(lcTextureMode TextureMode);
@ -186,7 +187,7 @@ protected:
char* mVertexBufferOffset; char* mVertexBufferOffset;
lcLightingMode mLightingMode; lcLightingMode mLightingMode;
lcProgramType mProgramType; lcMaterialType mMaterialType;
bool mNormalEnabled; bool mNormalEnabled;
bool mTexCoordEnabled; bool mTexCoordEnabled;
bool mColorEnabled; bool mColorEnabled;
@ -210,7 +211,7 @@ protected:
GLuint mFramebufferTexture; GLuint mFramebufferTexture;
GLuint mDepthRenderbufferObject; GLuint mDepthRenderbufferObject;
static lcProgram mPrograms[LC_NUM_PROGRAMS]; static lcProgram mPrograms[LC_NUM_LIGHTING_MODES][LC_NUM_MATERIALS];
Q_DECLARE_TR_FUNCTIONS(lcContext); Q_DECLARE_TR_FUNCTIONS(lcContext);
}; };

View file

@ -2176,7 +2176,7 @@ void lcLibraryMeshData::AddLine(lcMeshDataType MeshDataType, int LineType, lcuin
if (LineType == 4) if (LineType == 4)
TestQuad(QuadIndices, Vertices); 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) if (!WindingCCW)
Normal = -Normal; Normal = -Normal;
@ -2266,7 +2266,7 @@ void lcLibraryMeshData::AddTexturedLine(lcMeshDataType MeshDataType, int LineTyp
if (LineType == 4) if (LineType == 4)
TestQuad(QuadIndices, Vertices); 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) if (!WindingCCW)
Normal = -Normal; Normal = -Normal;
@ -2360,7 +2360,7 @@ void lcLibraryMeshData::AddMeshData(const lcLibraryMeshData& Data, const lcMatri
Index = AddVertex((lcMeshDataType)MeshDataIdx, Position, true); Index = AddVertex((lcMeshDataType)MeshDataIdx, Position, true);
else else
{ {
lcVector3 Normal = lcMul30(DataVertices[SrcVertexIdx].Normal, Transform); lcVector3 Normal = lcNormalize(lcMul30(DataVertices[SrcVertexIdx].Normal, Transform));
Index = AddVertex((lcMeshDataType)MeshDataIdx, Position, Normal, true); 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); Index = AddTexturedVertex((lcMeshDataType)MeshDataIdx, Position, TexCoord, true);
else else
{ {
lcVector3 Normal = lcMul30(DataVertices[SrcVertexIdx].Normal, Transform); lcVector3 Normal = lcNormalize(lcMul30(DataVertices[SrcVertexIdx].Normal, Transform));
Index = AddTexturedVertex((lcMeshDataType)MeshDataIdx, Position, Normal, TexCoord, true); 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); Index = AddTexturedVertex((lcMeshDataType)MeshDataIdx, Position, SrcVertex.TexCoord, true);
else 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); Index = AddTexturedVertex((lcMeshDataType)MeshDataIdx, Position, Normal, SrcVertex.TexCoord, true);
} }
@ -2514,7 +2514,7 @@ void lcLibraryMeshData::AddMeshDataNoDuplicateCheck(const lcLibraryMeshData& Dat
const lcLibraryMeshVertex& SrcVertex = DataVertices[SrcVertexIdx]; const lcLibraryMeshVertex& SrcVertex = DataVertices[SrcVertexIdx];
lcLibraryMeshVertex& DstVertex = Vertices.Add(); lcLibraryMeshVertex& DstVertex = Vertices.Add();
DstVertex.Position = lcMul31(SrcVertex.Position, Transform); DstVertex.Position = lcMul31(SrcVertex.Position, Transform);
DstVertex.Normal = lcMul30(SrcVertex.Normal, Transform); DstVertex.Normal = lcNormalize(lcMul30(SrcVertex.Normal, Transform));
DstVertex.NormalWeight = SrcVertex.NormalWeight; 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); lcDot3(lcVector3(Position.x, Position.y, Position.z), TextureMap->Params[1]) + TextureMap->Params[1].w);
DstVertex.Position = Position; DstVertex.Position = Position;
DstVertex.Normal = lcMul30(SrcVertex.Normal, Transform); DstVertex.Normal = lcNormalize(lcMul30(SrcVertex.Normal, Transform));
DstVertex.NormalWeight = SrcVertex.NormalWeight; DstVertex.NormalWeight = SrcVertex.NormalWeight;
DstVertex.TexCoord = TexCoord; DstVertex.TexCoord = TexCoord;
} }

View file

@ -1144,7 +1144,7 @@ void lcModel::DrawBackground(lcGLWidget* Widget)
ViewWidth, 0.0f, Color2[0], Color2[1], Color2[2], 1.0f 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->SetVertexBufferPointer(Verts);
Context->SetVertexFormat(0, 2, 0, 0, 4); Context->SetVertexFormat(0, 2, 0, 0, 4);
@ -1179,7 +1179,7 @@ void lcModel::DrawBackground(lcGLWidget* Widget)
0.0f, 0.0f, 0.0f, TileHeight 0.0f, 0.0f, 0.0f, TileHeight
}; };
Context->SetProgram(LC_PROGRAM_TEXTURE); Context->SetMaterial(LC_MATERIAL_TEXTURE);
Context->SetVertexBufferPointer(Verts); Context->SetVertexBufferPointer(Verts);
Context->SetVertexFormat(0, 2, 0, 2, 0); Context->SetVertexFormat(0, 2, 0, 2, 0);

View file

@ -334,7 +334,8 @@ void lcPartSelectionListModel::DrawPreview(int InfoIndex)
Context->SetDefaultState(); Context->SetDefaultState();
Context->SetProjectionMatrix(ProjectionMatrix); Context->SetProjectionMatrix(ProjectionMatrix);
Context->SetProgram(LC_PROGRAM_SIMPLE); Context->SetLightingMode(LC_LIGHTING_UNLIT);
Context->SetMaterial(LC_MATERIAL_SIMPLE);
lcPiecesLibrary* Library = lcGetPiecesLibrary(); lcPiecesLibrary* Library = lcGetPiecesLibrary();
PieceInfo* Info = mParts[InfoIndex].first; PieceInfo* Info = mParts[InfoIndex].first;

View file

@ -284,7 +284,7 @@ void lcLight::UpdatePosition(lcStep Step)
void lcLight::DrawInterface(lcContext* Context) const void lcLight::DrawInterface(lcContext* Context) const
{ {
Context->SetProgram(LC_PROGRAM_SIMPLE); Context->SetMaterial(LC_MATERIAL_SIMPLE);
if (IsPointLight()) if (IsPointLight())
DrawPointLight(Context); DrawPointLight(Context);

View file

@ -292,7 +292,7 @@ void MinifigWizard::OnDraw()
Scene.End(); Scene.End();
mContext->SetProgram(LC_PROGRAM_SIMPLE); mContext->SetMaterial(LC_MATERIAL_SIMPLE);
mContext->DrawOpaqueMeshes(Scene.mOpaqueMeshes); mContext->DrawOpaqueMeshes(Scene.mOpaqueMeshes);
mContext->DrawTranslucentMeshes(Scene.mTranslucentMeshes); mContext->DrawTranslucentMeshes(Scene.mTranslucentMeshes);

View file

@ -520,7 +520,7 @@ void lcPiece::DrawInterface(lcContext* Context) const
{ Min[0], Min[1], Min[2] }, { Min[0], Min[1], Min[2] + Edge[2] }, { 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); Context->SetWorldMatrix(mModelWorld);
if (IsFocused(LC_PIECE_SECTION_POSITION)) if (IsFocused(LC_PIECE_SECTION_POSITION))

View file

@ -1313,7 +1313,7 @@ void Project::ExportHTML()
Context->SetDefaultState(); Context->SetDefaultState();
Context->SetProjectionMatrix(ProjectionMatrix); Context->SetProjectionMatrix(ProjectionMatrix);
Context->SetProgram(LC_PROGRAM_SIMPLE); Context->SetMaterial(LC_MATERIAL_SIMPLE);
for (lcPartsList::const_iterator PartIt = PartsList.constBegin(); PartIt != PartsList.constEnd(); PartIt++) for (lcPartsList::const_iterator PartIt = PartsList.constBegin(); PartIt != PartsList.constEnd(); PartIt++)
{ {

View file

@ -569,7 +569,7 @@ void View::OnDraw()
mContext->SetViewMatrix(mCamera->mWorldView); mContext->SetViewMatrix(mCamera->mWorldView);
mContext->SetProjectionMatrix(GetProjectionMatrix()); mContext->SetProjectionMatrix(GetProjectionMatrix());
mContext->SetLightingMode(Preferences.mLightingMode); mContext->SetLightingMode(Preferences.mLightingMode);
mContext->SetProgram(LC_PROGRAM_SIMPLE); mContext->SetMaterial(LC_MATERIAL_SIMPLE);
#ifndef LC_OPENGLES #ifndef LC_OPENGLES
const lcModelProperties& Properties = mModel->GetProperties(); const lcModelProperties& Properties = mModel->GetProperties();
@ -598,7 +598,7 @@ void View::OnDraw()
if (DrawInterface) if (DrawInterface)
{ {
mContext->SetLightingMode(LC_LIGHTING_UNLIT); mContext->SetLightingMode(LC_LIGHTING_UNLIT);
mContext->SetProgram(LC_PROGRAM_SIMPLE); mContext->SetMaterial(LC_MATERIAL_SIMPLE);
mContext->DrawInterfaceObjects(mScene.mInterfaceObjects); mContext->DrawInterfaceObjects(mScene.mInterfaceObjects);
mContext->SetLineWidth(1.0f); mContext->SetLineWidth(1.0f);
@ -627,7 +627,7 @@ void View::OnDraw()
void View::DrawSelectMoveOverlay() void View::DrawSelectMoveOverlay()
{ {
mContext->SetProgram(LC_PROGRAM_SIMPLE); mContext->SetMaterial(LC_MATERIAL_SIMPLE);
mContext->SetViewMatrix(mCamera->mWorldView); mContext->SetViewMatrix(mCamera->mWorldView);
mContext->SetProjectionMatrix(GetProjectionMatrix()); mContext->SetProjectionMatrix(GetProjectionMatrix());
@ -818,7 +818,7 @@ void View::DrawRotateOverlay()
const float OverlayScale = GetOverlayScale(); const float OverlayScale = GetOverlayScale();
const float OverlayRotateRadius = 2.0f; const float OverlayRotateRadius = 2.0f;
mContext->SetProgram(LC_PROGRAM_SIMPLE); mContext->SetMaterial(LC_MATERIAL_SIMPLE);
mContext->SetViewMatrix(mCamera->mWorldView); mContext->SetViewMatrix(mCamera->mWorldView);
mContext->SetProjectionMatrix(GetProjectionMatrix()); mContext->SetProjectionMatrix(GetProjectionMatrix());
@ -1089,7 +1089,7 @@ void View::DrawRotateOverlay()
// Draw text. // Draw text.
lcVector3 ScreenPos = ProjectPoint(OverlayCenter); lcVector3 ScreenPos = ProjectPoint(OverlayCenter);
mContext->SetProgram(LC_PROGRAM_TEXTURE); mContext->SetMaterial(LC_MATERIAL_TEXTURE);
mContext->SetWorldMatrix(lcMatrix44Identity()); mContext->SetWorldMatrix(lcMatrix44Identity());
mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0))); mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0)));
mContext->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f)); mContext->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f));
@ -1118,7 +1118,7 @@ void View::DrawRotateOverlay()
void View::DrawSelectZoomRegionOverlay() void View::DrawSelectZoomRegionOverlay()
{ {
mContext->SetProgram(LC_PROGRAM_SIMPLE); mContext->SetMaterial(LC_MATERIAL_SIMPLE);
mContext->SetWorldMatrix(lcMatrix44Identity()); mContext->SetWorldMatrix(lcMatrix44Identity());
mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0))); mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0)));
mContext->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f)); mContext->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f));
@ -1207,7 +1207,7 @@ void View::DrawRotateViewOverlay()
w = mWidth; w = mWidth;
h = mHeight; h = mHeight;
mContext->SetProgram(LC_PROGRAM_SIMPLE); mContext->SetMaterial(LC_MATERIAL_SIMPLE);
mContext->SetWorldMatrix(lcMatrix44Identity()); mContext->SetWorldMatrix(lcMatrix44Identity());
mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0))); mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0)));
mContext->SetProjectionMatrix(lcMatrix44Ortho(0, w, 0, h, -1, 1)); 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); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
mContext->SetProgram(LC_PROGRAM_TEXTURE); mContext->SetMaterial(LC_MATERIAL_TEXTURE);
mContext->SetColor(lcVector4FromColor(Preferences.mGridStudColor)); mContext->SetColor(lcVector4FromColor(Preferences.mGridStudColor));
mContext->SetVertexFormat(0, 3, 0, 2, 0); mContext->SetVertexFormat(0, 3, 0, 2, 0);
@ -1436,7 +1436,7 @@ void View::DrawGrid()
if (Preferences.mDrawGridLines) if (Preferences.mDrawGridLines)
{ {
mContext->SetLineWidth(1.0f); mContext->SetLineWidth(1.0f);
mContext->SetProgram(LC_PROGRAM_SIMPLE); mContext->SetMaterial(LC_MATERIAL_SIMPLE);
mContext->SetColor(lcVector4FromColor(Preferences.mGridLineColor)); mContext->SetColor(lcVector4FromColor(Preferences.mGridLineColor));
int NumVerts = 2 * (MaxX - MinX + MaxY - MinY + 2); int NumVerts = 2 * (MaxX - MinX + MaxY - MinY + 2);
@ -1475,7 +1475,7 @@ void View::DrawAxes()
lcMatrix44 WorldViewMatrix = mCamera->mWorldView; lcMatrix44 WorldViewMatrix = mCamera->mWorldView;
WorldViewMatrix.SetTranslation(lcVector3(0, 0, 0)); WorldViewMatrix.SetTranslation(lcVector3(0, 0, 0));
mContext->SetProgram(LC_PROGRAM_SIMPLE); mContext->SetMaterial(LC_MATERIAL_SIMPLE);
mContext->SetWorldMatrix(lcMatrix44Identity()); mContext->SetWorldMatrix(lcMatrix44Identity());
mContext->SetViewMatrix(lcMul(WorldViewMatrix, TranslationMatrix)); mContext->SetViewMatrix(lcMul(WorldViewMatrix, TranslationMatrix));
mContext->SetProjectionMatrix(lcMatrix44Ortho(0, mWidth, 0, mHeight, -50, 50)); 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->SetColor(0.0f, 0.0f, 0.8f, 1.0f);
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 24, GL_UNSIGNED_SHORT, (6 + 48) * 2); 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->SetViewMatrix(TranslationMatrix);
mContext->SetTextureMode(LC_TEXTURE_MODULATE); mContext->SetTextureMode(LC_TEXTURE_MODULATE);
gTexFont.MakeCurrent(); gTexFont.MakeCurrent();
@ -1534,7 +1534,7 @@ void View::DrawViewport()
if (gMainWindow->GetActiveView() == this) if (gMainWindow->GetActiveView() == this)
{ {
mContext->SetProgram(LC_PROGRAM_SIMPLE); mContext->SetMaterial(LC_MATERIAL_SIMPLE);
mContext->SetColor(1.0f, 0.0f, 0.0f, 1.0f); 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 }; 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]) if (CameraName[0])
{ {
mContext->SetProgram(LC_PROGRAM_TEXTURE); mContext->SetMaterial(LC_MATERIAL_TEXTURE);
mContext->SetColor(0.0f, 0.0f, 0.0f, 1.0f); mContext->SetColor(0.0f, 0.0f, 0.0f, 1.0f);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);

View file

@ -112,7 +112,7 @@ void lcQPreferencesDialog::accept()
options->Preferences.mGridLineSpacing = gridLineSpacing; options->Preferences.mGridLineSpacing = gridLineSpacing;
options->Preferences.mDrawAxes = ui->axisIcon->isChecked(); 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(); QDialog::accept();
} }