Commit cd42a0b7 authored by James Fulop's avatar James Fulop
Browse files

transparent meshes working

parent 3c8cfc23
Shortcuts reminder
- Ctrl-shift-d for "debug at function" in Visual Studio
TODOs To Make Something
~ OnCollisionExit/Stay, TriggerExit/Stay game code events
- In-game GUI?
- Can't set render mesh back to None
- Copy/paste entity auto rename is messed up, test this more
- Saving entities while having an open sub-directory makes us lose the whole entity directory
Rendering
- split screen
- Cull back-faces optional
- split screen?
- Do box wireframe as just the edges, probably just a series of draw line commands
- Rim highlight for selections, maybe just render it first as a solid color at a higher scale, then draw it normally on top
- Trilighting instead of lambert?
- Enable backface culling. Something wrong with it currently. Everything looks inverted. On boxes only the -X -Y -Z faces are culling correctly. Probably some coordinate system problem?
- Fog
- Might be able to reduce complexity of game/editor render lists by using EXT_window_rectangles or ARB_viewport_array
- Rim highlight for selections, maybe just render it first as a solid color at a higher scale, then draw it normally on top?
- Trilighting?
- Might be able to reduce complexity of game/editor render lists by using EXT_window_rectangles or ARB_viewport_array or FBOs
Shader Workflow
- Don't assert on a uniform that's not found. Do a check before uploading anything to it, print to console if invalid.
- Need a hot reload sort of thing for this. Probably need to move shaders into another file for that
Sound
!- add rotation to listener definition
- add rotation to listener definition
- move bank loading and description loading code to game, maybe store EventDescriptions in some sort of hashmap thing. Platform should just initialize the FmodSystem
Assets
......@@ -27,12 +32,14 @@ Assets
Transforms
- WorldToLocal?
General
Shipping Eror Handling
- Create debug files on crashes, stack dump, error, file name, line number, etc.
- Variadic debug console output
- Error window popup message box, on crash, maybe Breakpad integration sometime...
General
- Do all scene graphy stuff before going to render. just pass it model matrices
- have game "capture" mouse, toggle-able for user to use GUI in menus and stuff
- Variadic debug console output
- Error window popup message box, maybe Breakpad integration sometime...
String
- Compress down different versions of StringsAreEqual
......@@ -44,7 +51,7 @@ Platform
- pause game when window is being dragged or is not focused
- Maybe have RNG be a platform thing? Seems dangerous. Diff behaviour on diff architecture?
- on Windows you want something like CryptGenRandom, check out the wikipedia page https://en.wikipedia.org/wiki/CryptGenRandom
- Record/replay. Can we exclude player entity from it, or a separate camera?
- Record/replay. Can we exclude player entity from it, or a separate camera? Record/replay just game_state?
Input
- Controller
......@@ -54,18 +61,20 @@ Collision
- Capsule
- Ray GJK?
- "is in frustrum" check
- Screen to ray cuts off on the edges. Something wrong with Ray/Triangle
- Some stuff passing through floor
- If a capsule completely encompasses another object, they are not considered collided
Integration "To Research" Notes
- Taylor Series
- Implicit Euler
- Semi-Explicit Euler
- Explicit Euler
- RK4
4coder
- Launch executable from hotkey so I don't have to always run from debugger
- Build options for only doing changed DLL's, or have build run a program that checks for file changes?
NETWORKING
Windows Sockets 2
https://msdn.microsoft.com/en-us/library/windows/desktop/ms740673(v=vs.85).aspx
\ No newline at end of file
Shader Gen
- Dont write pre-processor'd out code into generated shaders
- Scope indentation
\ No newline at end of file
......@@ -656,6 +656,7 @@ MoveDirection += GameState->PlayerCamera->Forward * Input->Controllers[0].MoveFo
{
entity* Bullet = CreateEntity(GameState->EntityMaster, "Bullet");
Bullet->Material.Texture = GameState->TestDxt;
Bullet->Material.RecieveShadows = true;
Bullet->RenderMesh = GameState->RenderAssets.StandardAssets.Cube;
// TODO(james): these should be world space
SetLocalPosition(Bullet, GameState->PlayerCamera->Position);
......@@ -823,6 +824,7 @@ extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender)
EditorState->EditorCamera = FindEntity(GameState->EntityMaster, "/EditorCamera");
PlayerFPSRotation(EditorState->EditorCamera, &EditorList->View, &Input->Controllers[0], 0);
//TODO(james): this sucks
entity* KillZone = FindEntity(GameState->EntityMaster, "/BulletKillZone0");
KillZone->OnTriggerHit = BulletKillZoneTriggerHit;
......@@ -837,6 +839,7 @@ extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender)
KillZone = FindEntity(GameState->EntityMaster, "/BulletKillZone5");
KillZone->OnTriggerHit = BulletKillZoneTriggerHit;
#if !YAMGINE_EDITOR //start playing immediately
GameAndEditorMemory->GameState.GameplayStartTrigger = true;
GameAndEditorMemory->GamePlaying = true;
......@@ -1110,6 +1113,7 @@ if (Input->Controllers[0].Action1.DownThisFrame)
{
ImGui::Checkbox("Draw Broadphase Debug", &GameAndEditorMemory->GameState.DrawBroadphaseViz);
ImGui::Checkbox("Draw Narrowphase Debug", &GameAndEditorMemory->GameState.DrawNarrowphaseViz);
ImGui::Checkbox("Flip Entity Draw Order", &GameAndEditorMemory->EditorState.FlipDrawEntityOrder);
ImGui::SliderFloat("Simulation Speed", &GameAndEditorMemory->GameState.SimulationSpeed, 0, 5);
if (ImGui::Button("Serialize Player"))
{
......
......@@ -48,8 +48,9 @@ struct game_state
texture* TestDxt;
texture* TestTga;
bool DrawBroadphaseViz;
bool DrawNarrowphaseViz;
bool32 DrawBroadphaseViz;
bool32 DrawNarrowphaseViz;
real32 SimulationSpeed;
......@@ -74,6 +75,9 @@ struct editor_state
v3 InitMovementDelta;
bool32 FlipDrawEntityOrder;
entity* Handle;
entity* XAxisHandle;
entity* YAxisHandle;
......
......@@ -157,7 +157,7 @@ void DrawEntity(render_list* RenderList, entity* Entity, entity* Camera)
{
if (Entity->RenderMesh != NULL)
{
DrawMesh(RenderList, Entity, Entity->RenderMesh, Entity->Material, RenderMode_fill, Entity->TransparencyMode);
DrawMesh(RenderList, Entity, Entity->RenderMesh, Entity->Material, RenderMode_fill, Entity->TargetRenderLayer);
}
if (Entity->IsDirectionalLight && Camera != NULL)
......@@ -328,14 +328,14 @@ void DrawEntityHighlight(render_list* RenderList, entity* Entity,
Material.Color = HighlightColor;
DrawMesh(RenderList, &ExtraScaled, Entity->RenderMesh, Material,
RenderMode_wireframe,TransparencyMode_xray);
RenderMode_wireframe,TargetRenderLayer_xray);
}
if (Entity->ColliderType == ColliderType_mesh && Entity->ColliderMesh != NULL)
{
Material.Color = ColliderColor;
DrawMesh(RenderList, &ExtraScaled, Entity->ColliderMesh, Material,
RenderMode_wireframe,TransparencyMode_xray);
RenderMode_wireframe,TargetRenderLayer_xray);
}
else if (Entity->ColliderType == ColliderType_sphere)
{
......@@ -857,17 +857,11 @@ void EntityPropertiesGui(entity* Entity, render_assets* RenderAssets, collision_
ImGui::Checkbox("Is Trigger", &IsTrigger);
Entity->IsTrigger = IsTrigger;
bool UseGravity = (bool)Entity->UseGravity;
CollisionPropertyChanged |= ImGui::Checkbox("Use Gravity", &UseGravity);
Entity->UseGravity = UseGravity;
CollisionPropertyChanged |= ImGui::Checkbox("Use Gravity", &Entity->UseGravity);
bool IsStatic = (bool)Entity->IsStatic;
CollisionPropertyChanged |= ImGui::Checkbox("Is Static", &IsStatic);
Entity->IsStatic = IsStatic;
CollisionPropertyChanged |= ImGui::Checkbox("Is Static", &Entity->IsStatic);
bool LockRotation = (bool)Entity->LockRotation;
ImGui::Checkbox("Lock Rotation", &LockRotation);
Entity->LockRotation = LockRotation;
ImGui::Checkbox("Lock Rotation", &Entity->LockRotation);
ImGui::DragFloat("Coefficient of Restitution", &Entity->CoefficientOfRestitution,
0.01f, 0.0f, 1.0f, "%.6f");
......@@ -929,9 +923,12 @@ void EntityPropertiesGui(entity* Entity, render_assets* RenderAssets, collision_
}
ImGui::ColorEdit4("Render Color", &Entity->Material.Color.E[0]);
bool IsDirectionalLight = Entity->IsDirectionalLight;
ImGui::Checkbox("Is Directional Light", &IsDirectionalLight);
Entity->IsDirectionalLight = IsDirectionalLight;
ImGui::Checkbox("Is Transparent", &Entity->Material.IsTransparent);
ImGui::Checkbox("Cast Shadows", &Entity->Material.CastShadows);
ImGui::Checkbox("Recieve Shadows", &Entity->Material.RecieveShadows);
ImGui::Checkbox("Is Directional Light", &Entity->IsDirectionalLight);
}
void EntityGui(entity* Entity, entity** SelectedEntity, entity** DroppedOnEntity,
......@@ -1334,8 +1331,11 @@ void EditorMode(game_and_editor_memory* Memory, memory_arena* TransientArena,
if (Input->Controllers[0].DeleteKey.DownThisFrame)
{
DeleteEntity(EditorState->SelectedEntity, EditorState->EntityMaster, EditorState->CollisionGroup);
EditorState->SelectedEntity = NULL;
if (EditorState->SelectedEntity)
{
DeleteEntity(EditorState->SelectedEntity, EditorState->EntityMaster, EditorState->CollisionGroup);
EditorState->SelectedEntity = NULL;
}
}
#ifdef ANGLE_AXIS_EDITOR
......@@ -1447,12 +1447,32 @@ void EditorMode(game_and_editor_memory* Memory, memory_arena* TransientArena,
//DrawDirectionalLight(RenderList, GameState->PlayerCamera);
entity* Entity = GameState->EntityMaster->FirstEntity;
do
if (EditorState->FlipDrawEntityOrder)
{
DrawEntity(RenderList, Entity, EditorState->EditorCamera);
Entity = Entity->NextEntity;
} while (Entity != NULL);
entity* LastEntity = GameState->EntityMaster->FirstEntity;
while (LastEntity->NextEntity != NULL)
{
LastEntity= LastEntity->NextEntity;
}
entity* Entity = LastEntity;
do
{
DrawEntity(RenderList, Entity, EditorState->EditorCamera);
Entity= Entity->PrevEntity;
} while (Entity != NULL);
}
else
{
entity* Entity = GameState->EntityMaster->FirstEntity;
do
{
DrawEntity(RenderList, Entity, EditorState->EditorCamera);
Entity= Entity->NextEntity;
} while (Entity != NULL);
}
/*
// math for having all rays move along the same plane down the frustrum
......@@ -1520,9 +1540,9 @@ CreateCoordinateSystemHandle(editor_state* EditorState)
EditorState->YAxisHandle->RenderMesh = EditorState->RenderAssets->StandardAssets.Cube;
EditorState->ZAxisHandle->RenderMesh = EditorState->RenderAssets->StandardAssets.Cube;
EditorState->XAxisHandle->TransparencyMode = TransparencyMode_xray;
EditorState->YAxisHandle->TransparencyMode = TransparencyMode_xray;
EditorState->ZAxisHandle->TransparencyMode = TransparencyMode_xray;
EditorState->XAxisHandle->TargetRenderLayer = TargetRenderLayer_xray;
EditorState->YAxisHandle->TargetRenderLayer = TargetRenderLayer_xray;
EditorState->ZAxisHandle->TargetRenderLayer = TargetRenderLayer_xray;
EditorState->XAxisHandle->IsStatic = true;
EditorState->YAxisHandle->IsStatic = true;
......
......@@ -292,7 +292,13 @@ struct texture
introspect(category:"math") typedef struct material
{
serialize("param") v4 Color;
texture* Texture;
serialize("param") bool32 IsTransparent;
serialize("param") bool32 CastShadows;
serialize("param") bool32 RecieveShadows;
}material;
//six most extreme points on a mesh
......@@ -615,7 +621,8 @@ typedef struct render_list
matrix4 ViewProjection;
render_layer DefaultLayer;
render_layer XrayLayer;
// depth buffer clear
render_layer XrayLayer;//stuff like handles, which are drawn on top of regular geometry
render_layer ScreenUILayer;
Prof_Report* ProfReport;
......
......@@ -1767,6 +1767,7 @@ WinMain(HINSTANCE Instance,
GameList.ScreenUILayer.MaxPushBufferSize = GameScreenUILayerBufferSize;
GameList.ScreenUILayer.PushBufferElementCount = 0;
/*
if not recording, record
if recording, stop and playback
......
......@@ -579,20 +579,48 @@ void DrawCircle(gl_wrapped* gl, gl_basic_context* CircleContext,
//mesh
mesh_shader BuildMeshShaderContext(gl_wrapped* gl, platform_api* API)
{
mesh_shader Result;
mesh_shader Result = {};
Result.Texture_RecieveShadows_Shader = -1;
Result.Texture_Shader = -1;
Result.RecieveShadows_Shader = -1;
Result.VanillaShader = -1;
GenerateShader("../source/code/shaders/mesh.metashader", "#define TEXTURE\n#define RECIEVE_SHADOWS\n#define LIGHTING\n",
"mesh_allOptions",API);
//
//
//
GenerateShader("../source/code/shaders/mesh.metashader", "#define TEXTURE 1\n#define RECIEVE_SHADOWS 1\n",
"mesh_Texture_RecieveShadows",API);
int IgnoredFileSize;
char* Vert = (char*)API->ReadBinaryFile("shaders/generated/mesh_allOptions.vert", &IgnoredFileSize);
char* Frag = (char*)API->ReadBinaryFile("shaders/generated/mesh_allOptions.frag", &IgnoredFileSize);
Result.Texture_RecieveShadows_Lighting_Shader = LoadShaderProgram(gl, Vert, Frag);
char* Vert = (char*)API->ReadBinaryFile("shaders/generated/mesh_Texture_RecieveShadows.vert", &IgnoredFileSize);
char* Frag = (char*)API->ReadBinaryFile("shaders/generated/mesh_Texture_RecieveShadows.frag", &IgnoredFileSize);
Result.Texture_RecieveShadows_Shader = LoadShaderProgram(gl, Vert, Frag);
//
//
//
GenerateShader("../source/code/shaders/mesh.metashader", "#define TEXTURE 1\n#define RECIEVE_SHADOWS 0\n",
"mesh_Texture",API);
Vert = (char*)API->ReadBinaryFile("shaders/generated/mesh_Texture.vert", &IgnoredFileSize);
Frag = (char*)API->ReadBinaryFile("shaders/generated/mesh_Texture.frag", &IgnoredFileSize);
Result.Texture_Shader = LoadShaderProgram(gl, Vert, Frag);
GenerateShader("../source/code/shaders/mesh.metashader", "#define RECIEVE_SHADOWS\n#define LIGHTING\n",
"mesh_allButTexture",API);
Vert = (char*)API->ReadBinaryFile("shaders/generated/mesh_allButTexture.vert", &IgnoredFileSize);
Frag = (char*)API->ReadBinaryFile("shaders/generated/mesh_allButTexture.frag", &IgnoredFileSize);
Result.RecieveShadows_Lighting_Shader = LoadShaderProgram(gl, Vert, Frag);
//
//
//
GenerateShader("../source/code/shaders/mesh.metashader", "#define TEXTURE 0\n#define RECIEVE_SHADOWS 1\n",
"mesh_RecieveShadows",API);
Vert = (char*)API->ReadBinaryFile("shaders/generated/mesh_RecieveShadows.vert", &IgnoredFileSize);
Frag = (char*)API->ReadBinaryFile("shaders/generated/mesh_RecieveShadows.frag", &IgnoredFileSize);
Result.RecieveShadows_Shader = LoadShaderProgram(gl, Vert, Frag);
//
//
//
GenerateShader("../source/code/shaders/mesh.metashader", "#define TEXTURE 0\n#define RECIEVE_SHADOWS 0\n",
"mesh_vanilla",API);
Vert = (char*)API->ReadBinaryFile("shaders/generated/mesh_vanilla.vert", &IgnoredFileSize);
Frag = (char*)API->ReadBinaryFile("shaders/generated/mesh_vanilla.frag", &IgnoredFileSize);
Result.VanillaShader = LoadShaderProgram(gl, Vert, Frag);
return Result;
}
......@@ -680,7 +708,7 @@ void GLDrawMesh(mesh* Mesh)
}
void DrawMesh(gl_wrapped* gl, mesh* Mesh, matrix4 Model, mesh_shader* MeshContext,
material Material, render_mode RenderMode, transparency_mode TransparencyMode,
material Material, render_mode RenderMode,
matrix4 TransposedView, matrix4 TransposedProjection,
matrix4 LightSpaceMatrix, v3 LightDirection, GLint DepthMapTexture)
{
......@@ -689,25 +717,34 @@ void DrawMesh(gl_wrapped* gl, mesh* Mesh, matrix4 Model, mesh_shader* MeshContex
gl->glBindVertexArray(Mesh->VaoHandle);
GLint Shader;
if (Material.Texture != NULL)
Model = Transpose(Model);
//
// Choose Shader
//
GLint Shader = -1;
if (Material.Texture != NULL && Material.RecieveShadows)
{
Shader = MeshContext->Texture_RecieveShadows_Lighting_Shader;
Shader = MeshContext->Texture_RecieveShadows_Shader;
}
else if (Material.Texture != NULL && !Material.RecieveShadows)
{
Shader = MeshContext->Texture_Shader;
}
else if (Material.RecieveShadows)
{
Shader = MeshContext->RecieveShadows_Shader;
}
else
{
Shader = MeshContext->RecieveShadows_Lighting_Shader;
Shader = MeshContext->VanillaShader;
}
gl->glUseProgram(Shader);
gl->glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, DepthMapTexture);
Model = Transpose(Model);
Assert(Shader > -1);
ErrorMessageAssert();
//
// Fill Parameters
//
gl->glUseProgram(Shader);
GLint Result = 0;
//TODO(james): ensures attributes have been enabled
//glGetVertexAttribfv(0, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &Result);//vertices
......@@ -715,6 +752,21 @@ void DrawMesh(gl_wrapped* gl, mesh* Mesh, matrix4 Model, mesh_shader* MeshContex
//glGetVertexAttribfv(2, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &Result);//UVs
if (Material.RecieveShadows)
{
gl->glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, DepthMapTexture);
GLint LightSpaceMatrixLoc = GetUniformLocation(gl, Shader, "LightSpaceMatrix");
if (LightSpaceMatrixLoc > -1)
gl->glUniformMatrix4fv(LightSpaceMatrixLoc, 1, GL_FALSE, &LightSpaceMatrix.E[0]);
GLint ShadowMapTextureLoc = GetUniformLocation(gl, Shader, "ShadowMapTexture");
if (ShadowMapTextureLoc > -1)
gl->glUniform1i(ShadowMapTextureLoc, 0);// Active Texture ID, not the Texture Handle!
}
ErrorMessageAssert();
GLint ModelLoc = GetUniformLocation(gl, Shader, "Model");
if (ModelLoc > -1)
......@@ -740,30 +792,32 @@ void DrawMesh(gl_wrapped* gl, mesh* Mesh, matrix4 Model, mesh_shader* MeshContex
if (LightColorLoc > -1)
gl->glUniform3f(LightColorLoc, 1.0f,1.0f,1.0f);
GLint LightSpaceMatrixLoc = GetUniformLocation(gl, Shader, "LightSpaceMatrix");
if (LightSpaceMatrixLoc > -1)
gl->glUniformMatrix4fv(LightSpaceMatrixLoc, 1, GL_FALSE, &LightSpaceMatrix.E[0]);
GLint ShadowMapTextureLoc = GetUniformLocation(gl, Shader, "ShadowMapTexture");
if (ShadowMapTextureLoc > -1)
gl->glUniform1i(ShadowMapTextureLoc, 0);// Active Texture ID, not the Texture Handle!
/*
GLint ViewDirLoc = GetUniformLocation(gl, MeshContext->Shader, "ViewDir");
if (ViewDirLoc > -1)
gl->glUniform3f(ViewDirLoc, TransposedView.Row2.x, TransposedView.Row2.y, TransposedView.Row2.z);
*/
if (Material.Texture != NULL)
{
gl->glActiveTexture(GL_TEXTURE1);
uint32 DiffuseTextureID;
if (Material.RecieveShadows)
{
gl->glActiveTexture(GL_TEXTURE1);
DiffuseTextureID = 1;
}
else
{
gl->glActiveTexture(GL_TEXTURE0);
DiffuseTextureID = 0;
}
glBindTexture(GL_TEXTURE_2D, Material.Texture->Handle);
GLint TextureLoc = GetUniformLocation(gl, Shader, "Texture");
if (TextureLoc > -1)
gl->glUniform1i(TextureLoc, 1);// Active Texture ID, not the Texture Handle!
{
gl->glUniform1i(TextureLoc, DiffuseTextureID);// Active Texture ID, not the Texture Handle!
}
}
//
// Determine rendering type
//
// TODO(james): maybe render mode switches should be its own render list command?
// We should probably cache the current render state so we don't have to query
// the mode every drawcall
......@@ -781,33 +835,17 @@ void DrawMesh(gl_wrapped* gl, mesh* Mesh, matrix4 Model, mesh_shader* MeshContex
glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
}
switch(TransparencyMode)
if (Material.IsTransparent)
{
case TransparencyMode_opaque:{
//assumes depth test
//glFrontFace(GL_CCW);
//glCullFace(GL_BACK);
//glDisable(GL_CULL_FACE);
GLDrawMesh(Mesh);
}break;
case TransparencyMode_transparent:{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLDrawMesh(Mesh);
glDisable(GL_BLEND);
}break;
case TransparencyMode_xray:{
//glDepthFunc(GL_ALWAYS);
//TODO(james): stencil stuff
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLDrawMesh(Mesh);
glDisable(GL_BLEND);
}break;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLDrawMesh(Mesh);
glDisable(GL_BLEND);
}
else
{
GLDrawMesh(Mesh);
}
//DEFAULTS
//glPolygonMode(GL_FRONT, CurrentPolygonMode);
ErrorMessageAssert();
......@@ -1229,7 +1267,7 @@ RenderLayer(render_layer* Layer, gl_state* State,
{
render_entry_mesh* Entry = MeshEntryPtrs[MeshPtrIndex];
if (Entry->RenderMode == RenderMode_fill &&
Entry->TransparencyMode == TransparencyMode_opaque)
Entry->Material.CastShadows)
{
DrawMeshToDepthmap(gl, Entry->Mesh, Entry->ModelMatrix,
RenderContexts->MeshToDepthmapContext,
......@@ -1262,6 +1300,7 @@ RenderLayer(render_layer* Layer, gl_state* State,
ErrorMessageAssert();
PushBufferLocation = Layer->PushBufferBase;
for(uint32 EntryIndex = 0;
EntryIndex < Layer->PushBufferElementCount;
++EntryIndex)
......@@ -1323,7 +1362,7 @@ RenderLayer(render_layer* Layer, gl_state* State,
//if (Entry->Mesh->HasUVs && Entry->Material.Texture)
{
DrawMesh(gl, Entry->Mesh, Entry->ModelMatrix, &RenderContexts->MeshContext,
Entry->Material, Entry->RenderMode, Entry->TransparencyMode,
Entry->Material, Entry->RenderMode,
View, Projection, LightSpaceMatrix, LightDir, DepthMapTexture);
}
......
......@@ -63,8 +63,12 @@ struct gl_imgui_context
struct mesh_shader
{
GLint Texture_RecieveShadows_Lighting_Shader;
GLint RecieveShadows_Lighting_Shader;
GLint Texture_RecieveShadows_Shader;
GLint Texture_Shader;
GLint RecieveShadows_Shader;
GLint VanillaShader;
};
......
......@@ -230,6 +230,21 @@ AssertToken(tokenizer *Tokenizer, token_type DesiredType)
Assert(RequireToken(Tokenizer, DesiredType));
}
static token
GetRestOfLine(tokenizer* Tokenizer)
{
token Result = {};
Result.Type = Token_Unknown;
Result.Text = Tokenizer->At;
while (*Tokenizer->At != '\n')
{
Tokenizer->At++;
}
Result.TextLength = Tokenizer->At - Result.Text;
return Result;
}
#define MAX_SHADER_SIZE 4096
void GenerateShader(char* FileName, char* Options, char* OutputName, platform_api* PlatformAPI)
......@@ -409,6 +424,22 @@ AssertToken(tokenizer *Tokenizer, token_type DesiredType)
{
AppendString(CurrentShader, "#else\n", MAX_SHADER_SIZE);
}
else if (TokenEquals(NextToken, "elif"))
{
AppendString(CurrentShader, "#elif ", MAX_SHADER_SIZE);
token PoundId = GetToken(&Tokenizer);
AppendString_(CurrentShader, MAX_SHADER_SIZE, PoundId.Text, (uint32)PoundId.TextLength);
AppendString(CurrentShader, "\n", MAX_SHADER_SIZE);
}
else if (TokenEquals(NextToken, "if"))
{
AppendString(CurrentShader, "#if ", MAX_SHADER_SIZE);
token RestOfLine = GetRestOfLine(&Tokenizer);
AppendString_(CurrentShader, MAX_SHADER_SIZE, RestOfLine.Text, (uint32)RestOfLine.TextLength);
AppendString(CurrentShader, "\n", MAX_SHADER_SIZE);
}
else
{
InvalidCodePath;
......@@ -426,28 +457,29 @@ AssertToken(tokenizer *Tokenizer, token_type DesiredType)
token Type = GetToken(&Tokenizer);