@@ -82,6 +82,7 @@ _ReSharper.* | |||
test/benchsuite | |||
test/btphystest | |||
test/meshviewer | |||
test/nacl_phystest | |||
test/testsuite | |||
test/sandbox/sample | |||
test/math/pi | |||
@@ -122,7 +122,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "People", "People", "{5F1AAF | |||
EndProject | |||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Peeweek", "Peeweek", "{E27FDF36-50C4-4ED2-8CF5-A20FED016910}" | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "demo-peeweek", "..\..\people\peeweek\private\demo-peeweek.vcxproj", "{C2E01551-B636-4324-8461-71811DF6FBB5}" | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "demo-peeweek", "..\..\people\peeweek\demo-peeweek.vcxproj", "{C2E01551-B636-4324-8461-71811DF6FBB5}" | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "03_noise", "..\..\demos\tutorial\03_noise.vcxproj", "{B0A53D75-CBB4-4FDF-93AC-2D12A79ADA0E}" | |||
EndProject | |||
@@ -152,11 +152,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "07_input", "..\..\demos\tut | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "06_sprite", "..\..\demos\tutorial\06_sprite.vcxproj", "{E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}" | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "voxel", "..\..\people\benlitz\private\voxel\voxel.vcxproj", "{52493826-AC00-470B-A745-4F602529B3B0}" | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "voxel", "..\..\people\benlitz\voxel\voxel.vcxproj", "{52493826-AC00-470B-A745-4F602529B3B0}" | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Puzzle", "..\..\people\benlitz\private\puzzle\Puzzle.vcxproj", "{9F291982-8C81-4105-BF39-16844648E55F}" | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Puzzle", "..\..\people\benlitz\puzzle\Puzzle.vcxproj", "{9F291982-8C81-4105-BF39-16844648E55F}" | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lolui", "..\..\people\benlitz\private\lolui\lolui.vcxproj", "{950EDCC1-DF6A-4A75-B083-DFE98E7DD34F}" | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lolui", "..\..\people\benlitz\lolui\lolui.vcxproj", "{950EDCC1-DF6A-4A75-B083-DFE98E7DD34F}" | |||
EndProject | |||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SinglShot", "SinglShot", "{50509BA3-D27B-4FAC-9772-9EC76146F709}" | |||
EndProject | |||
@@ -176,6 +176,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Pimp", "Pimp", "{2195FB18-5 | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pimp", "..\..\tools\pimp\pimp.vcxproj", "{FFF58874-D460-41E6-AD65-DBFEC6E47A94}" | |||
EndProject | |||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "squad_shooter", "..\..\people\touky\private\squad_shooter\squad_shooter.vcxproj", "{DB344310-4938-4294-AEE2-18512454585D}" | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|ORBIS = Debug|ORBIS | |||
@@ -557,8 +557,8 @@ AC_CONFIG_FILES( | |||
people/peeweek/Makefile | |||
people/benlitz/Makefile | |||
people/benlitz/test1/Makefile | |||
people/benlitz/private/voxel/Makefile | |||
people/benlitz/private/lolui/Makefile | |||
people/benlitz/voxel/Makefile | |||
people/benlitz/lolui/Makefile | |||
people/touky/Makefile | |||
people/touky/sprite_sorter/Makefile | |||
people/touky/squad_shooter/Makefile | |||
@@ -118,32 +118,28 @@ public: | |||
if (!m_ready) | |||
{ | |||
g_renderer->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | |||
/* Upload vertex data to GPU */ | |||
for (int i = 0; i < m_gears.Count(); i++) | |||
m_gears[i].m1.MeshConvert(); | |||
#if USE_CUSTOM_SHADER | |||
//Custom Shader: Init the shader | |||
m_custom_shader = Shader::Create(LOLFX_RESOURCE_NAME(shiny)); | |||
/* Custom Shader: Init the shader */ | |||
Shader *custom_shader = Shader::Create(LOLFX_RESOURCE_NAME(shiny)); | |||
// any other shader stuf here (Get uniform, mostly, and set texture) | |||
#endif //USE_CUSTOM_SHADER | |||
g_renderer->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | |||
for (int i = 0; i < m_gears.Count(); i++) | |||
{ | |||
#if USE_CUSTOM_SHADER | |||
//Custom shader, Convert by setuping a shaderData with the vertex useage. | |||
//DefaultShaderData is only a basic class, if needed, don't hesitate to create your own | |||
m_gears[i].m1.MeshConvert(new DefaultShaderData( | |||
((1 << VertexUsage::Position) | | |||
(1 << VertexUsage::Normal) | | |||
(1 << VertexUsage::Color)), | |||
m_custom_shader, false)); | |||
#else //USE_CUSTOM_SHADER | |||
m_gears[i].m1.MeshConvert(); | |||
#endif //USE_CUSTOM_SHADER | |||
} | |||
m_gears[i].m1.SetMaterial(custom_shader); | |||
#endif | |||
m_ready = true; | |||
} | |||
for (int i = 0; i < m_gears.Count(); i++) | |||
m_gears[i].m1.Render(m_mat * m_gears[i].m2); | |||
{ | |||
g_scene->AddPrimitive(m_gears[i].m1, m_mat * m_gears[i].m2); | |||
} | |||
} | |||
private: | |||
@@ -137,8 +137,10 @@ static inline int isnan(float f) | |||
/* External declaration for LolFx files. */ | |||
#define LOLFX_RESOURCE_DECLARE(name) \ | |||
extern "C" char const *LOLFX_RESOURCE_NAME(name) | |||
#define LOLFX_RESOURCE_NAME(name) lolfx_resource_##name | |||
extern "C" char const *lolfx_resource_##name | |||
#define LOLFX_RESOURCE_HELPER(name) #name ".lolfx" | |||
#define LOLFX_RESOURCE_NAME(name) \ | |||
LOLFX_RESOURCE_HELPER(name), lolfx_resource_##name | |||
/* If using NaCl or Android, override main() with our version */ | |||
#if defined __native_client__ | |||
@@ -22,6 +22,8 @@ | |||
#include "core.h" | |||
#include "easymesh/easymesh-compiler.h" | |||
LOLFX_RESOURCE_DECLARE(shiny); | |||
namespace lol | |||
{ | |||
@@ -40,7 +42,6 @@ EasyMesh::EasyMesh(const EasyMesh& em) | |||
m_vert = em.m_vert; | |||
m_cursors = em.m_cursors; | |||
m_build_data = nullptr; | |||
m_gpu_data = GpuEasyMeshData(); | |||
if (em.m_build_data) | |||
m_build_data = new EasyMeshBuildData(*em.m_build_data); | |||
if (m_indices.Count() && m_vert.Count() && m_cursors.Count()) | |||
@@ -64,6 +65,49 @@ bool EasyMesh::Compile(char const *command, bool Execute) | |||
return res; | |||
} | |||
void EasyMesh::MeshConvert() | |||
{ | |||
/* Default material */ | |||
Shader *shader = Shader::Create(LOLFX_RESOURCE_NAME(shiny)); | |||
/* Push index buffer to GPU */ | |||
IndexBuffer *ibo = new IndexBuffer(m_indices.Count() * sizeof(uint16_t)); | |||
uint16_t *indices = (uint16_t *)ibo->Lock(0, 0); | |||
for (int i = 0; i < m_indices.Count(); ++i) | |||
indices[i] = m_indices[i]; | |||
ibo->Unlock(); | |||
/* Push vertex buffer to GPU */ | |||
struct Vertex | |||
{ | |||
vec3 pos, normal; | |||
u8vec4 color; | |||
vec4 texcoord; | |||
}; | |||
VertexDeclaration *vdecl = new VertexDeclaration( | |||
VertexStream<vec3, vec3, u8vec4, vec4>(VertexUsage::Position, | |||
VertexUsage::Normal, | |||
VertexUsage::Color, | |||
VertexUsage::TexCoord)); | |||
VertexBuffer *vbo = new VertexBuffer(m_vert.Count() * sizeof(Vertex)); | |||
Vertex *vert = (Vertex *)vbo->Lock(0, 0); | |||
for (int i = 0; i < m_vert.Count(); ++i) | |||
{ | |||
vert[i].pos = m_vert[i].m_coord, | |||
vert[i].normal = m_vert[i].m_normal, | |||
vert[i].color = (u8vec4)(m_vert[i].m_color * 255.f); | |||
vert[i].texcoord = m_vert[i].m_texcoord; | |||
} | |||
vbo->Unlock(); | |||
/* Reference our new data in our submesh */ | |||
m_submeshes.Push(new SubMesh(shader, vdecl)); | |||
m_submeshes.Last()->SetIndexBuffer(ibo); | |||
m_submeshes.Last()->SetVertexBuffer(0, vbo); | |||
} | |||
//----------------------------------------------------------------------------- | |||
#define EZSET(M0) BD()->CmdStack().GetValue(M0); | |||
#define EZDEF_1(T0) T0 m0; EZSET(m0) | |||
@@ -228,51 +272,6 @@ void EasyMesh::CloseBrace() | |||
m_cursors.Pop(); | |||
} | |||
//----------------------------------------------------------------------------- | |||
void EasyMesh::MeshConvert(GpuShaderData* new_gpu_sdata) | |||
{ | |||
delete(m_build_data); | |||
m_build_data = nullptr; | |||
if (new_gpu_sdata) | |||
{ | |||
m_gpu_data.AddGpuData(new_gpu_sdata, this); | |||
for (int i = DebugRenderMode::Default; i < DebugRenderMode::Max; i++) | |||
if (!m_gpu_data.HasData(i)) | |||
m_gpu_data.AddGpuData(new DefaultShaderData(DebugRenderMode(i)), this); | |||
} | |||
m_state = MeshRender::CanRender; | |||
} | |||
//----------------------------------------------------------------------------- | |||
void EasyMesh::MeshConvert(Shader* provided_shader) | |||
{ | |||
if (provided_shader) | |||
{ | |||
GpuShaderData *new_gpu_sdata = new DefaultShaderData(((1 << VertexUsage::Position) | | |||
(1 << VertexUsage::Normal) | | |||
(1 << VertexUsage::Color)), | |||
provided_shader, | |||
false); | |||
m_gpu_data.AddGpuData(new_gpu_sdata, this); | |||
} | |||
else | |||
m_gpu_data.AddGpuData(new DefaultShaderData(DebugRenderMode::Default), this); | |||
for (int i = DebugRenderMode::Default + 1; i < DebugRenderMode::Max; i++) | |||
m_gpu_data.AddGpuData(new DefaultShaderData(DebugRenderMode(i)), this); | |||
m_state = MeshRender::CanRender; | |||
} | |||
//----------------------------------------------------------------------------- | |||
bool EasyMesh::Render(mat4 const &model, int render_mode) | |||
{ | |||
if (m_state == MeshRender::CanRender) | |||
{ | |||
m_gpu_data.RenderMeshData(model, render_mode); | |||
return true; | |||
} | |||
return false; | |||
} | |||
//----------------------------------------------------------------------------- | |||
bool EasyMesh::SetRender(bool should_render) | |||
@@ -48,7 +48,7 @@ LOL_SAFE_ENUM(MeshTransform, | |||
Shear | |||
); | |||
class EasyMesh | |||
class EasyMesh : public Mesh | |||
{ | |||
friend class EasyMeshParser; | |||
friend class GpuEasyMeshData; | |||
@@ -57,13 +57,11 @@ public: | |||
EasyMesh(); | |||
EasyMesh(const EasyMesh& em); | |||
bool Compile(char const *command, bool Execute=true); | |||
void ExecuteCmdStack(bool ExecAllStack=true); | |||
void MeshConvert(GpuShaderData* new_gpu_sdata); | |||
void MeshConvert(Shader* ProvidedShader = nullptr); | |||
bool Render(mat4 const &model, int render_mode=Video::GetDebugRenderMode()); | |||
MeshRender GetMeshState() { return m_state; } | |||
bool SetRender(bool should_render); | |||
bool Compile(char const *command, bool Execute = true); | |||
void ExecuteCmdStack(bool ExecAllStack = true); | |||
void MeshConvert(); | |||
MeshRender GetMeshState() { return m_state; } | |||
bool SetRender(bool should_render); | |||
private: | |||
void UpdateVertexDict(Array< int, int > &vertex_dict); | |||
@@ -73,6 +71,7 @@ private: | |||
//------------------------------------------------------------------------- | |||
private: | |||
void MeshCsg(CSGUsage csg_operation); | |||
public: | |||
/* [cmd:csgu] Performs a Union operation as (mesh0_Outside + mesh1_Outside) */ | |||
void CsgUnion() { MeshCsg(CSGUsage::Union); } | |||
@@ -386,7 +385,6 @@ public: | |||
Array<int, int> m_cursors; | |||
MeshRender m_state; | |||
GpuEasyMeshData m_gpu_data; | |||
public: | |||
inline EasyMeshBuildData* BD() | |||
@@ -120,9 +120,10 @@ DefaultShaderData::DefaultShaderData(uint16_t vert_decl_flags, Shader* shader, b | |||
SetupDefaultData(with_UV); | |||
} | |||
static const String DefaultUniforms[7] = | |||
static const String DefaultUniforms[8] = | |||
{ | |||
String("u_lights"), | |||
String("u_model"), | |||
String("u_modelview"), | |||
String("u_view"), | |||
String("u_inv_view"), | |||
@@ -160,12 +161,13 @@ void DefaultShaderData::SetupShaderDatas(mat4 const &model) | |||
/* FIXME: GetUniform("blabla") is costly */ | |||
for (int i = 0; i < lights.Count(); ++i) | |||
light_data << vec4(lights[i]->GetPosition(), lights[i]->GetType()) << lights[i]->GetColor(); | |||
while (light_data.Count() < 8) | |||
while (light_data.Count() < LOL_MAX_LIGHT_COUNT) | |||
light_data << vec4::zero << vec4::zero; | |||
int i = 0; | |||
m_shader->SetUniform(*GetUniform(DefaultUniforms[i++]), light_data); | |||
m_shader->SetUniform(*GetUniform(DefaultUniforms[i++]), model); | |||
m_shader->SetUniform(*GetUniform(DefaultUniforms[i++]), modelview); | |||
m_shader->SetUniform(*GetUniform(DefaultUniforms[i++]), view); | |||
m_shader->SetUniform(*GetUniform(DefaultUniforms[i++]), inverse(view)); | |||
@@ -8,7 +8,7 @@ attribute vec4 in_Color; | |||
uniform mat4 u_modelview; | |||
uniform mat4 u_view; | |||
uniform mat4 u_proj; | |||
uniform mat4 u_projection; | |||
uniform mat3 u_normalmat; | |||
varying vec4 pass_Vertex; /* View space */ | |||
@@ -24,7 +24,7 @@ void main(void) | |||
pass_TNormal = tnorm; | |||
pass_Color = in_Color; | |||
gl_Position = u_proj * vertex; | |||
gl_Position = u_projection * vertex; | |||
} | |||
[frag.glsl] | |||
@@ -138,7 +138,7 @@ void main(float3 in_Vertex : POSITION, | |||
float3 in_Normal : NORMAL, | |||
float4 in_Color : COLOR, | |||
uniform float4x4 u_modelview, | |||
uniform float4x4 u_proj, | |||
uniform float4x4 u_projection, | |||
uniform float3x3 u_normalmat, | |||
out float4 pass_Vertex : TEXCOORD0, | |||
out float3 pass_TNormal : TEXCOORD1, | |||
@@ -156,7 +156,7 @@ void main(float3 in_Vertex : POSITION, | |||
pass_Color = in_Color; | |||
#endif | |||
out_Position = mul(u_proj, eye); | |||
out_Position = mul(u_projection, eye); | |||
} | |||
[frag.hlsl] | |||
@@ -10,7 +10,7 @@ attribute vec2 in_Weight; | |||
uniform mat4 u_modelview; | |||
uniform mat4 u_view; | |||
uniform mat4 u_proj; | |||
uniform mat4 u_projection; | |||
uniform mat3 u_normalmat; | |||
//10is not a fix idea, should be more. | |||
uniform mat4 in_BoneList[10]; | |||
@@ -28,7 +28,7 @@ void main(void) | |||
pass_TNormal = tnorm; | |||
pass_Color = in_Color; | |||
gl_Position = u_proj * vertex; | |||
gl_Position = u_projection * vertex; | |||
} | |||
[frag.glsl] | |||
@@ -163,7 +163,7 @@ void main(float3 in_Vertex : POSITION, | |||
float3 in_Normal : NORMAL, | |||
float4 in_Color : COLOR, | |||
uniform float4x4 u_modelview, | |||
uniform float4x4 u_proj, | |||
uniform float4x4 u_projection, | |||
uniform float3x3 u_normalmat, | |||
out float4 pass_Vertex : TEXCOORD0, | |||
out float3 pass_TNormal : TEXCOORD1, | |||
@@ -181,7 +181,7 @@ void main(float3 in_Vertex : POSITION, | |||
pass_Color = in_Color; | |||
#endif | |||
out_Position = mul(u_proj, eye); | |||
out_Position = mul(u_projection, eye); | |||
} | |||
[frag.hlsl] | |||
@@ -9,7 +9,7 @@ attribute vec2 in_TexCoord; | |||
uniform mat4 u_modelview; | |||
uniform mat4 u_view; | |||
uniform mat4 u_proj; | |||
uniform mat4 u_projection; | |||
uniform mat3 u_normalmat; | |||
varying vec4 pass_Vertex; /* View space */ | |||
@@ -27,7 +27,7 @@ void main(void) | |||
pass_Color = in_Color; | |||
pass_TexCoord = in_TexCoord; | |||
gl_Position = u_proj * vertex; | |||
gl_Position = u_projection * vertex; | |||
} | |||
[frag.glsl] | |||
@@ -97,7 +97,7 @@ void main(float3 in_Vertex : POSITION, | |||
float3 in_Normal : NORMAL, | |||
float4 in_Color : COLOR, | |||
uniform float4x4 u_modelview, | |||
uniform float4x4 u_proj, | |||
uniform float4x4 u_projection, | |||
uniform float3x3 u_normalmat, | |||
out float4 pass_Vertex : TEXCOORD0, | |||
out float3 pass_TNormal : TEXCOORD1, | |||
@@ -115,7 +115,7 @@ void main(float3 in_Vertex : POSITION, | |||
pass_Color = in_Color; | |||
#endif | |||
out_Position = mul(u_proj, eye); | |||
out_Position = mul(u_projection, eye); | |||
} | |||
[frag.hlsl] | |||
@@ -8,7 +8,7 @@ attribute vec4 in_Color; | |||
uniform mat4 u_modelview; | |||
uniform mat4 u_view; | |||
uniform mat4 u_proj; | |||
uniform mat4 u_projection; | |||
uniform mat3 u_normalmat; | |||
varying vec4 pass_Vertex; /* View space */ | |||
@@ -24,7 +24,7 @@ void main(void) | |||
pass_TNormal = tnorm; | |||
pass_Color = vec4(1.0, 1.0, 1.0, in_Color.w);//; | |||
gl_Position = u_proj * vertex; | |||
gl_Position = u_projection * vertex; | |||
} | |||
[frag.glsl] | |||
@@ -97,7 +97,7 @@ void main(float3 in_Vertex : POSITION, | |||
float3 in_Normal : NORMAL, | |||
float4 in_Color : COLOR, | |||
uniform float4x4 u_modelview, | |||
uniform float4x4 u_proj, | |||
uniform float4x4 u_projection, | |||
uniform float3x3 u_normalmat, | |||
out float4 pass_Vertex : TEXCOORD0, | |||
out float3 pass_TNormal : TEXCOORD1, | |||
@@ -115,7 +115,7 @@ void main(float3 in_Vertex : POSITION, | |||
pass_Color = in_Color; | |||
#endif | |||
out_Position = mul(u_proj, eye); | |||
out_Position = mul(u_projection, eye); | |||
} | |||
[frag.hlsl] | |||
@@ -8,7 +8,7 @@ attribute vec4 in_Color; | |||
uniform mat4 u_modelview; | |||
uniform mat4 u_view; | |||
uniform mat4 u_proj; | |||
uniform mat4 u_projection; | |||
uniform mat3 u_normalmat; | |||
varying vec4 pass_Vertex; /* View space */ | |||
@@ -24,7 +24,7 @@ void main(void) | |||
pass_TNormal = tnorm; | |||
pass_Color = in_Color; | |||
gl_Position = u_proj * vertex; | |||
gl_Position = u_projection * vertex; | |||
} | |||
[frag.glsl] | |||
@@ -59,7 +59,7 @@ void main(float3 in_Vertex : POSITION, | |||
float3 in_Normal : NORMAL, | |||
float4 in_Color : COLOR, | |||
uniform float4x4 u_modelview, | |||
uniform float4x4 u_proj, | |||
uniform float4x4 u_projection, | |||
uniform float3x3 u_normalmat, | |||
out float4 pass_Vertex : TEXCOORD0, | |||
out float3 pass_TNormal : TEXCOORD1, | |||
@@ -77,7 +77,7 @@ void main(float3 in_Vertex : POSITION, | |||
pass_Color = in_Color; | |||
#endif | |||
out_Position = mul(u_proj, eye); | |||
out_Position = mul(u_projection, eye); | |||
} | |||
[frag.hlsl] | |||
@@ -8,7 +8,7 @@ attribute vec4 in_Color; | |||
uniform mat4 u_modelview; | |||
uniform mat4 u_view; | |||
uniform mat4 u_proj; | |||
uniform mat4 u_projection; | |||
uniform mat3 u_normalmat; | |||
varying vec4 pass_Vertex; /* View space */ | |||
@@ -24,7 +24,7 @@ void main(void) | |||
pass_TNormal = tnorm; | |||
pass_Color = in_Color; | |||
gl_Position = u_proj * vertex; | |||
gl_Position = u_projection * vertex; | |||
} | |||
[frag.glsl] | |||
@@ -55,7 +55,7 @@ void main(float3 in_Vertex : POSITION, | |||
float3 in_Normal : NORMAL, | |||
float4 in_Color : COLOR, | |||
uniform float4x4 u_modelview, | |||
uniform float4x4 u_proj, | |||
uniform float4x4 u_projection, | |||
uniform float3x3 u_normalmat, | |||
out float4 pass_Vertex : TEXCOORD0, | |||
out float3 pass_TNormal : TEXCOORD1, | |||
@@ -73,7 +73,7 @@ void main(float3 in_Vertex : POSITION, | |||
pass_Color = in_Color; | |||
#endif | |||
out_Position = mul(u_proj, eye); | |||
out_Position = mul(u_projection, eye); | |||
} | |||
[frag.hlsl] | |||
@@ -8,7 +8,7 @@ attribute vec4 in_Color; | |||
uniform mat4 u_modelview; | |||
uniform mat4 u_view; | |||
uniform mat4 u_proj; | |||
uniform mat4 u_projection; | |||
uniform mat3 u_normalmat; | |||
varying vec4 pass_Vertex; /* View space */ | |||
@@ -24,7 +24,7 @@ void main(void) | |||
pass_TNormal = tnorm; | |||
pass_Color = in_Color; | |||
gl_Position = u_proj * vertex; | |||
gl_Position = u_projection * vertex; | |||
} | |||
[frag.glsl] | |||
@@ -141,7 +141,7 @@ void main(float3 in_Vertex : POSITION, | |||
float3 in_Normal : NORMAL, | |||
float4 in_Color : COLOR, | |||
uniform float4x4 u_modelview, | |||
uniform float4x4 u_proj, | |||
uniform float4x4 u_projection, | |||
uniform float3x3 u_normalmat, | |||
out float4 pass_Vertex : TEXCOORD0, | |||
out float3 pass_TNormal : TEXCOORD1, | |||
@@ -159,7 +159,7 @@ void main(float3 in_Vertex : POSITION, | |||
pass_Color = in_Color; | |||
#endif | |||
out_Position = mul(u_proj, eye); | |||
out_Position = mul(u_projection, eye); | |||
} | |||
[frag.hlsl] | |||
@@ -96,6 +96,11 @@ IndexBuffer::~IndexBuffer() | |||
delete m_data; | |||
} | |||
size_t IndexBuffer::GetSize() | |||
{ | |||
return m_data->m_size; | |||
} | |||
void *IndexBuffer::Lock(size_t offset, size_t size) | |||
{ | |||
if (!m_data->m_size) | |||
@@ -84,6 +84,8 @@ class ShaderData | |||
friend class Shader; | |||
private: | |||
String m_name; | |||
#if defined USE_D3D9 | |||
IDirect3DDevice9 *m_dev; | |||
IDirect3DVertexShader9 *vert_shader; | |||
@@ -98,6 +100,7 @@ private: | |||
GLuint prog_id, vert_id, frag_id; | |||
// Benlitz: using a simple array could be faster since there is never more than a few attribute locations to store | |||
Map<uint64_t, GLint> attrib_locations; | |||
Map<uint64_t, bool> attrib_errors; | |||
#else | |||
CGprogram vert_id, frag_id; | |||
#endif | |||
@@ -121,16 +124,14 @@ int ShaderData::nshaders = 0; | |||
* Public Shader class | |||
*/ | |||
Shader *Shader::Create(char const *lolfx) | |||
Shader *Shader::Create(String const &name, String const &code) | |||
{ | |||
char *src = new char[strlen(lolfx) + 2]; | |||
memcpy(src + 1, lolfx, strlen(lolfx) + 1); | |||
src[0] = '\n'; | |||
String src = String("\n") + code; | |||
/* Parse the crap */ | |||
Array<char const *, char const *> sections; | |||
char *key = nullptr; | |||
for (char *parser = src; *parser; ) | |||
for (char *parser = src.C(); *parser; ) | |||
{ | |||
if (key == nullptr && (parser[0] == '\n' || parser[0] == '\r') | |||
&& parser[1] == '[') | |||
@@ -173,9 +174,11 @@ Shader *Shader::Create(char const *lolfx) | |||
/* FIXME: we don’t know how to handle these yet. */ | |||
if (!vert) | |||
Log::Error("no vertex shader found… sorry, I’m gonna crash now.\n"); | |||
Log::Error("no vertex shader found in %s… sorry, I’m gonna crash now.\n", | |||
name.C()); | |||
if (!frag) | |||
Log::Error("no fragment shader found… sorry, I’m gonna crash now.\n"); | |||
Log::Error("no fragment shader found in %s… sorry, I’m gonna crash now.\n", | |||
name.C()); | |||
uint32_t new_vert_crc = ShaderData::hash(vert); | |||
uint32_t new_frag_crc = ShaderData::hash(frag); | |||
@@ -185,16 +188,14 @@ Shader *Shader::Create(char const *lolfx) | |||
if (ShaderData::shaders[n]->data->vert_crc == new_vert_crc | |||
&& ShaderData::shaders[n]->data->frag_crc == new_frag_crc) | |||
{ | |||
delete[] src; | |||
return ShaderData::shaders[n]; | |||
} | |||
} | |||
Shader *ret = new Shader(vert, frag); | |||
Shader *ret = new Shader(name, vert, frag); | |||
ShaderData::shaders[ShaderData::nshaders] = ret; | |||
ShaderData::nshaders++; | |||
delete[] src; | |||
return ret; | |||
} | |||
@@ -204,9 +205,12 @@ void Shader::Destroy(Shader *shader) | |||
UNUSED(shader); | |||
} | |||
Shader::Shader(char const *vert, char const *frag) | |||
Shader::Shader(String const &name, | |||
char const *vert, char const *frag) | |||
: data(new ShaderData()) | |||
{ | |||
data->m_name = name; | |||
#if defined USE_D3D9 || defined _XBOX | |||
ID3DXBuffer *shader_code, *error_msg; | |||
HRESULT hr; | |||
@@ -243,7 +247,7 @@ Shader::Shader(char const *vert, char const *frag) | |||
&data->vert_table); | |||
if (FAILED(hr)) | |||
{ | |||
Log::Error("failed to compile vertex shader: %s", | |||
Log::Error("failed to compile vertex shader %s: %s\n", name.C(), | |||
error_msg ? error_msg->GetBufferPointer() : "error"); | |||
Log::Error("shader source:\n%s\n", vert); | |||
} | |||
@@ -261,12 +265,13 @@ Shader::Shader(char const *vert, char const *frag) | |||
glGetShaderiv(data->vert_id, GL_COMPILE_STATUS, &status); | |||
if (status != GL_TRUE) | |||
{ | |||
Log::Error("failed to compile vertex shader: %s", errbuf); | |||
Log::Error("failed to compile vertex shader %s: %s\n", | |||
name.C(), errbuf); | |||
Log::Error("shader source:\n%s\n", shader_code.C()); | |||
} | |||
else if (len > 16) | |||
{ | |||
Log::Debug("compile log for vertex shader: %s", errbuf); | |||
Log::Debug("compile log for vertex shader %s: %s\n", name.C(), errbuf); | |||
Log::Debug("shader source:\n%s\n", shader_code.C()); | |||
} | |||
#else | |||
@@ -275,7 +280,7 @@ Shader::Shader(char const *vert, char const *frag) | |||
nullptr, nullptr); | |||
if (data->vert_id == nullptr) | |||
{ | |||
Log::Error("failed to compile vertex shader"); | |||
Log::Error("failed to compile vertex shader %s\n", name.C()); | |||
Log::Error("shader source:\n%s\n", vert); | |||
} | |||
#endif | |||
@@ -288,7 +293,7 @@ Shader::Shader(char const *vert, char const *frag) | |||
&data->frag_table); | |||
if (FAILED(hr)) | |||
{ | |||
Log::Error("failed to compile fragment shader: %s", | |||
Log::Error("failed to compile fragment shader %s: %s\n", name.C(), | |||
error_msg ? error_msg->GetBufferPointer() : "error"); | |||
Log::Error("shader source:\n%s\n", frag); | |||
} | |||
@@ -306,12 +311,14 @@ Shader::Shader(char const *vert, char const *frag) | |||
glGetShaderiv(data->frag_id, GL_COMPILE_STATUS, &status); | |||
if (status != GL_TRUE) | |||
{ | |||
Log::Error("failed to compile fragment shader: %s", errbuf); | |||
Log::Error("failed to compile fragment shader %s: %s\n", | |||
name.C(), errbuf); | |||
Log::Error("shader source:\n%s\n", shader_code.C()); | |||
} | |||
else if (len > 16) | |||
{ | |||
Log::Debug("compile log for fragment shader: %s", errbuf); | |||
Log::Debug("compile log for fragment shader %s: %s\n", | |||
name.C(), errbuf); | |||
Log::Debug("shader source:\n%s\n", shader_code.C()); | |||
} | |||
#else | |||
@@ -320,7 +327,7 @@ Shader::Shader(char const *vert, char const *frag) | |||
nullptr, nullptr); | |||
if (data->frag_id == nullptr) | |||
{ | |||
Log::Error("failed to compile fragment shader"); | |||
Log::Error("failed to compile fragment shader %s\n", name.C()); | |||
Log::Error("shader source:\n%s\n", frag); | |||
} | |||
#endif | |||
@@ -355,11 +362,11 @@ Shader::Shader(char const *vert, char const *frag) | |||
glGetProgramiv(data->prog_id, GL_LINK_STATUS, &status); | |||
if (status != GL_TRUE) | |||
{ | |||
Log::Error("failed to link program: %s", errbuf); | |||
Log::Error("failed to link program %s: %s\n", name.C(), errbuf); | |||
} | |||
else if (len > 16) | |||
{ | |||
Log::Debug("link log for program: %s", errbuf); | |||
Log::Debug("link log for program %s: %s\n", name.C(), errbuf); | |||
} | |||
GLint validated; | |||
@@ -367,7 +374,7 @@ Shader::Shader(char const *vert, char const *frag) | |||
glGetProgramiv(data->prog_id, GL_VALIDATE_STATUS, &validated); | |||
if (validated != GL_TRUE) | |||
{ | |||
Log::Error("failed to validate program"); | |||
Log::Error("failed to validate program %s\n", name.C()); | |||
} | |||
GLint num_attribs; | |||
@@ -413,10 +420,11 @@ Shader::Shader(char const *vert, char const *frag) | |||
uint64_t flags = (uint64_t)(uint16_t)usage.ToScalar() << 16; | |||
flags |= (uint64_t)(uint16_t)index; | |||
// TODO: this is here just in case. Remove this once everything has been correctly tested | |||
#ifdef _DEBUG | |||
#if _DEBUG | |||
if (data->attrib_locations.HasKey(flags)) | |||
{ | |||
Log::Error("an error occured while parsing attribute semantics"); | |||
Log::Error("error while parsing attribute semantics in %s\n", | |||
name.C()); | |||
} | |||
#endif | |||
data->attrib_locations[flags] = location; | |||
@@ -444,11 +452,17 @@ ShaderAttrib Shader::GetAttribLocation(VertexUsage usage, int index) const | |||
ret.m_flags |= (uint64_t)(uint16_t)index; | |||
#if defined USE_D3D9 || defined _XBOX | |||
#elif !defined __CELLOS_LV2__ | |||
GLint l; | |||
GLint l = -1; | |||
if (!data->attrib_locations.TryGetValue(ret.m_flags, l)) | |||
{ | |||
Log::Error("queried attribute is unavailable for this shader"); | |||
/* Only spit an error once, we don’t need to flood the console. */ | |||
if (!data->attrib_errors.HasKey(ret.m_flags)) | |||
{ | |||
Log::Error("attribute %s not found in shader %s\n", | |||
usage.ToString().C(), data->m_name.C()); | |||
data->attrib_errors[ret.m_flags] = true; | |||
} | |||
} | |||
ret.m_flags |= (uint64_t)(uint32_t)l << 32; | |||
#else | |||
@@ -367,7 +367,7 @@ void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attribs[]) | |||
uint32_t reg = attribs[n].m_flags >> 32; | |||
# if !defined __CELLOS_LV2__ | |||
if (reg != 0xffffffff) | |||
if (reg != 0xffffffffu) | |||
glEnableVertexAttribArray((GLint)reg); | |||
# else | |||
switch (usage.ToScalar()) | |||
@@ -56,7 +56,7 @@ bool ZedImageData::Open(char const *path) | |||
if (!lol::String(path).EndsWith(".RSC")) | |||
return false; | |||
//Compacter definition | |||
// Compacter definition | |||
struct CompactSecondary | |||
{ | |||
CompactSecondary(int32_t size) { m_size = size; } | |||
@@ -27,6 +27,8 @@ public: | |||
IndexBuffer(size_t size); | |||
~IndexBuffer(); | |||
size_t GetSize(); | |||
void *Lock(size_t offset, size_t size); | |||
void Unlock(); | |||
@@ -53,6 +53,24 @@ enum class BlendEquation : uint8_t | |||
Max, | |||
}; | |||
/* A safe enum to indicate the blend equation. */ | |||
struct BlendEquation | |||
{ | |||
enum Value | |||
{ | |||
Add, | |||
Subtract, | |||
ReverseSubtract, | |||
Min, | |||
Max, | |||
} | |||
m_value; | |||
inline BlendEquation() : m_value(Add) {} | |||
inline BlendEquation(Value v) : m_value(v) {} | |||
inline operator Value() { return m_value; } | |||
}; | |||
/* A safe enum to indicate the blending factors. */ | |||
enum class BlendFunc : uint8_t | |||
{ | |||
@@ -90,10 +90,10 @@ private: | |||
class ShaderData; | |||
class Shader | |||
class Shader : public Entity | |||
{ | |||
public: | |||
static Shader *Create(char const *lolfx); | |||
static Shader *Create(String const &name, String const &code); | |||
static void Destroy(Shader *shader); | |||
int GetAttribCount() const; | |||
@@ -122,7 +122,7 @@ public: | |||
void Unbind() const; | |||
protected: | |||
Shader(char const *vert, char const *frag); | |||
Shader(String const &name, char const *vert, char const *frag); | |||
~Shader(); | |||
private: | |||
@@ -99,6 +99,7 @@ public: | |||
protected: | |||
//Work stuff | |||
bool AddWork(ThreadJob* job); | |||
//Fetch Results | |||
bool FetchResult(Array<ThreadJob*>& results); | |||
//Base thread work function | |||
@@ -32,24 +32,33 @@ Mesh::~Mesh() | |||
{ | |||
} | |||
void Mesh::Render(mat4 const &model) | |||
void Mesh::Render() | |||
{ | |||
//for (int i = 0; i < m_submeshes.Count(); ++i) | |||
// m_submeshes[i]->Render(model); | |||
for (int i = 0; i < m_submeshes.Count(); ++i) | |||
m_submeshes[i]->Render(); | |||
} | |||
void Mesh::SetMaterial(Shader *shader) | |||
{ | |||
for (int i = 0; i < m_submeshes.Count(); ++i) | |||
m_submeshes[i]->SetShader(shader); | |||
} | |||
/* | |||
* SubMesh class | |||
*/ | |||
SubMesh::SubMesh(lol::VertexDeclaration* vdecl) | |||
: m_mesh_prim(MeshPrimitive::Triangles) | |||
SubMesh::SubMesh(Shader *shader, VertexDeclaration *vdecl) | |||
: m_mesh_prim(MeshPrimitive::Triangles), | |||
m_shader(shader), | |||
m_vdecl(vdecl) | |||
{ | |||
m_vdecl = vdecl; | |||
Ticker::Ref(m_shader); | |||
} | |||
SubMesh::~SubMesh() | |||
{ | |||
Ticker::Unref(m_shader); | |||
// TODO: cleanup | |||
} | |||
@@ -58,6 +67,23 @@ void SubMesh::SetMeshPrimitive(MeshPrimitive mesh_primitive) | |||
m_mesh_prim = mesh_primitive; | |||
} | |||
void SubMesh::SetShader(Shader *shader) | |||
{ | |||
Ticker::Unref(m_shader); | |||
m_shader = shader; | |||
Ticker::Ref(m_shader); | |||
} | |||
Shader *SubMesh::GetShader() | |||
{ | |||
return m_shader; | |||
} | |||
void SubMesh::SetVertexDeclaration(VertexDeclaration *vdecl) | |||
{ | |||
m_vdecl = vdecl; | |||
} | |||
void SubMesh::SetVertexBuffer(int index, VertexBuffer* vbo) | |||
{ | |||
while (index >= m_vbos.Count()) | |||
@@ -66,12 +92,17 @@ void SubMesh::SetVertexBuffer(int index, VertexBuffer* vbo) | |||
m_vbos[index] = vbo; | |||
} | |||
void SubMesh::SetIndexBuffer(IndexBuffer* ibo) | |||
{ | |||
m_ibo = ibo; | |||
} | |||
void SubMesh::AddTexture(const char* name, Texture* texture) | |||
{ | |||
m_textures.Push(String(name), texture); | |||
} | |||
void SubMesh::Render(Shader* shader) | |||
void SubMesh::Render() | |||
{ | |||
int vertex_count = 0; | |||
@@ -81,19 +112,17 @@ void SubMesh::Render(Shader* shader) | |||
if (m_vbos[i] == nullptr) | |||
{ | |||
Log::Error("trying to render a mesh with a null vbo"); | |||
return; | |||
Log::Error("trying to render a mesh with a null VBO\n"); | |||
continue; | |||
} | |||
int indices[VertexUsage::MAX]; | |||
memset(indices, 0, sizeof(int) * VertexUsage::MAX); | |||
int usages[VertexUsage::MAX] = { 0 }; | |||
VertexStreamBase stream = m_vdecl->GetStream(i); | |||
for (int j = 0; j < stream.GetStreamCount(); ++j) | |||
{ | |||
VertexUsage usage = stream.GetUsage(j); | |||
int usage_index = usage.ToScalar(); | |||
attribs[j] = shader->GetAttribLocation(usage, indices[usage_index]++); | |||
attribs[j] = m_shader->GetAttribLocation(usage, usages[usage_index]++); | |||
} | |||
vertex_count = m_vbos[i]->GetSize() / m_vdecl->GetStream(i).GetSize(); | |||
@@ -104,13 +133,16 @@ void SubMesh::Render(Shader* shader) | |||
for (int i = 0; i < m_textures.Count(); ++i) | |||
{ | |||
// TODO: might be good to cache this | |||
ShaderUniform u_tex = shader->GetUniformLocation(m_textures[i].m1.C()); | |||
shader->SetUniform(u_tex, m_textures[i].m2->GetTextureUniform(), i); | |||
ShaderUniform u_tex = m_shader->GetUniformLocation(m_textures[i].m1.C()); | |||
m_shader->SetUniform(u_tex, m_textures[i].m2->GetTextureUniform(), i); | |||
} | |||
m_ibo->Bind(); | |||
m_vdecl->Bind(); | |||
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, vertex_count); | |||
m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0, vertex_count, | |||
0, m_ibo->GetSize() / sizeof(uint16_t)); | |||
m_vdecl->Unbind(); | |||
m_ibo->Unbind(); | |||
} | |||
} /* namespace lol */ | |||
@@ -31,9 +31,12 @@ public: | |||
Mesh(); | |||
~Mesh(); | |||
void Render(mat4 const &model); | |||
/* FIXME: this should eventually take a “material” as argument, which | |||
* may behave differently between submeshes. */ | |||
void SetMaterial(Shader *shader); | |||
void Render(); | |||
private: | |||
public: | |||
Array<class SubMesh *> m_submeshes; | |||
}; | |||
@@ -42,24 +45,31 @@ private: | |||
* - a vertex declaration | |||
* - a list of VBOs | |||
* - a list of textures | |||
* - a shader | |||
*/ | |||
class SubMesh | |||
{ | |||
public: | |||
SubMesh(VertexDeclaration* vdecl); | |||
SubMesh(Shader *shader, VertexDeclaration* vdecl); | |||
~SubMesh(); | |||
void SetMeshPrimitive(MeshPrimitive mesh_primitive); | |||
void SetShader(Shader *shader); | |||
Shader *GetShader(); | |||
void SetVertexDeclaration(VertexDeclaration *vdecl); | |||
void SetVertexBuffer(int index, VertexBuffer* vbo); | |||
void SetIndexBuffer(IndexBuffer* ibo); | |||
void AddTexture(const char* name, Texture* texture); | |||
void Render(Shader* shader); | |||
void Render(); | |||
protected: | |||
VertexDeclaration* m_vdecl; | |||
MeshPrimitive m_mesh_prim; | |||
Shader *m_shader; | |||
VertexDeclaration* m_vdecl; | |||
Array<VertexBuffer *> m_vbos; | |||
IndexBuffer *m_ibo; | |||
Array<String, Texture*> m_textures; | |||
}; | |||
@@ -24,9 +24,8 @@ namespace lol | |||
* Primitive class | |||
*/ | |||
Primitive::Primitive(Mesh *mesh, Shader *shader, mat4 const &matrix) | |||
: m_mesh(mesh), | |||
m_shader(shader), | |||
Primitive::Primitive(SubMesh *submesh, mat4 const &matrix) | |||
: m_submesh(submesh), | |||
m_matrix(matrix) | |||
{ | |||
} | |||
@@ -26,13 +26,11 @@ class Primitive | |||
friend class Scene; | |||
public: | |||
Primitive(Mesh *mesh, Shader *shader, mat4 const &matrix); | |||
Primitive(SubMesh *submesh, mat4 const &matrix); | |||
~Primitive(); | |||
private: | |||
Mesh *m_mesh; | |||
Shader *m_shader; | |||
SubMesh *m_submesh; | |||
mat4 m_matrix; | |||
}; | |||
@@ -177,11 +177,16 @@ void Scene::Reset() | |||
data->m_tile_bufs.Empty(); | |||
data->m_lights.Empty(); | |||
data->m_primitives.Empty(); | |||
} | |||
void Scene::AddPrimitive(Mesh *mesh, Shader *shader, mat4 const &matrix) | |||
void Scene::AddPrimitive(Mesh const &mesh, mat4 const &matrix) | |||
{ | |||
data->m_primitives.Push(Primitive(mesh, shader, matrix)); | |||
for (int i = 0; i < mesh.m_submeshes.Count(); ++i) | |||
{ | |||
data->m_primitives.Push(Primitive(mesh.m_submeshes[i], | |||
matrix)); | |||
} | |||
} | |||
void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale, float angle) | |||
@@ -190,7 +195,7 @@ void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale, float | |||
Tile t; | |||
/* FIXME: this sorting only works for a 45-degree camera */ | |||
t.prio = -pos.y - 2 * 32 * pos.z + ((float)o ? 0 : 32); | |||
t.prio = -pos.y - (int)(2 * 32 * pos.z) + (o ? 0 : 32); | |||
t.tileset = tileset; | |||
t.id = id; | |||
t.pos = pos; | |||
@@ -242,7 +247,7 @@ void Scene::RenderPrimitives() | |||
* primitives found in the scene graph. When we have one. */ | |||
Shader *shader = nullptr; | |||
ShaderUniform u_model, uni_tex, uni_texsize; | |||
ShaderUniform u_model, u_modelview, u_normalmat, uni_tex, uni_texsize; | |||
ShaderAttrib a_pos, a_tex; | |||
for (int i = 0; i < data->m_primitives.Count(); ++i) | |||
@@ -250,25 +255,50 @@ void Scene::RenderPrimitives() | |||
Primitive &p = data->m_primitives[i]; | |||
/* If this primitive uses a new shader, update attributes */ | |||
if (p.m_shader != shader) | |||
if (p.m_submesh->GetShader() != shader) | |||
{ | |||
shader = p.m_shader; | |||
shader = p.m_submesh->GetShader(); | |||
a_pos = shader->GetAttribLocation(VertexUsage::Position, 0); | |||
a_tex = shader->GetAttribLocation(VertexUsage::TexCoord, 0); | |||
shader->Bind(); | |||
/* Per-scene matrices */ | |||
ShaderUniform u_mat; | |||
u_mat = shader->GetUniformLocation("u_projection"); | |||
shader->SetUniform(u_mat, GetCamera()->GetProjection()); | |||
u_mat = shader->GetUniformLocation("u_view"); | |||
shader->SetUniform(u_mat, GetCamera()->GetView()); | |||
u_mat = shader->GetUniformLocation("u_inv_view"); | |||
shader->SetUniform(u_mat, inverse(GetCamera()->GetView())); | |||
/* Per-object matrices, will be set later */ | |||
u_model = shader->GetUniformLocation("u_model"); | |||
u_modelview = shader->GetUniformLocation("u_modelview"); | |||
u_normalmat = shader->GetUniformLocation("u_normalmat"); | |||
/* Per-scene environment */ | |||
Array<Light *> const &lights = GetLights(); | |||
Array<vec4> light_data; | |||
/* FIXME: the 4th component of the position can be used for other things */ | |||
/* FIXME: GetUniform("blabla") is costly */ | |||
for (int i = 0; i < lights.Count(); ++i) | |||
light_data << vec4(lights[i]->GetPosition(), lights[i]->GetType()) << lights[i]->GetColor(); | |||
while (light_data.Count() < LOL_MAX_LIGHT_COUNT) | |||
light_data << vec4::zero << vec4::zero; | |||
ShaderUniform u_lights = shader->GetUniformLocation("u_lights"); | |||
shader->SetUniform(u_lights, light_data); | |||
} | |||
shader->SetUniform(u_model, p.m_matrix); | |||
mat4 modelview = GetCamera()->GetView() * p.m_matrix; | |||
shader->SetUniform(u_modelview, modelview); | |||
shader->SetUniform(u_normalmat, transpose(inverse(mat3(modelview)))); | |||
p.m_submesh->Render(); | |||
} | |||
} | |||
@@ -23,6 +23,8 @@ | |||
#include "camera.h" | |||
#include "mesh/primitive.h" | |||
#define LOL_MAX_LIGHT_COUNT 8 | |||
namespace lol | |||
{ | |||
@@ -49,7 +51,7 @@ public: | |||
void RenderLines(float seconds); | |||
/* New scenegraph */ | |||
void AddPrimitive(Mesh *mesh, Shader *shader, mat4 const &matrix); | |||
void AddPrimitive(Mesh const &mesh, mat4 const &matrix); | |||
/* FIXME: this should be deprecated -- it doesn't really match | |||
* the architecture we want to build */ | |||
@@ -23,6 +23,7 @@ BaseThreadManager::BaseThreadManager(int thread_count) | |||
{ | |||
m_thread_count = thread_count; | |||
} | |||
BaseThreadManager::~BaseThreadManager() | |||
{ | |||
Stop(); | |||
@@ -68,6 +69,7 @@ bool BaseThreadManager::AddWork(ThreadJob* job) | |||
return true; | |||
return false; | |||
} | |||
bool BaseThreadManager::FetchResult(Array<ThreadJob*>& results) | |||
{ | |||
ThreadJob* result; | |||
@@ -824,12 +824,12 @@ public: | |||
//Camera projection | |||
mat4 new_proj = mat_obj_offset * mat_count_offset * mat_align * mat_count_scale * save_proj; | |||
m_camera->SetProjection(new_proj); | |||
m_meshes[i].m1->Render(m_mat); | |||
g_scene->AddPrimitive(*m_meshes[i].m1, m_mat); | |||
g_renderer->Clear(ClearMask::Depth); | |||
} | |||
m_camera->SetProjection(save_proj); | |||
#else | |||
m_meshes[i].m1->Render(m_mat); | |||
g_scene->AddPrimitive(*m_meshes[i].m1, m_mat); | |||
#endif //ALL_FEATURES | |||
} | |||
} | |||
@@ -839,7 +839,7 @@ public: | |||
{ | |||
m_camera->SetProjection(mat_gizmo); | |||
if (m_ssetup->m_show_gizmo) | |||
m_gizmos[GZ_Editor]->Render(m_mat); | |||
g_scene->AddPrimitive(*m_gizmos[GZ_Editor], m_mat); | |||
if (m_ssetup->m_show_lights) | |||
{ | |||
@@ -851,12 +851,12 @@ public: | |||
//dir light | |||
if (ltmp->GetType() == LightType::Directional) | |||
{ | |||
m_gizmos[GZ_LightPos]->Render(m_mat * inverse(local)); | |||
m_gizmos[GZ_LightDir]->Render(inverse(world) * inverse(mat4::lookat(vec3::zero, -ltmp->GetPosition(), vec3::axis_y))); | |||
g_scene->AddPrimitive(*m_gizmos[GZ_LightPos], m_mat * inverse(local)); | |||
g_scene->AddPrimitive(*m_gizmos[GZ_LightDir], inverse(world) * inverse(mat4::lookat(vec3::zero, -ltmp->GetPosition(), vec3::axis_y))); | |||
} | |||
else //point light | |||
{ | |||
m_gizmos[GZ_LightPos]->Render(m_mat * local); | |||
g_scene->AddPrimitive(*m_gizmos[GZ_LightPos], m_mat * local); | |||
} | |||
} | |||
} | |||
@@ -327,18 +327,16 @@ protected: | |||
{ | |||
if (!m_ready) | |||
{ | |||
if (m_custom_shader) | |||
m_mesh.MeshConvert(m_custom_shader); | |||
else | |||
m_mesh.MeshConvert(); | |||
m_mesh.MeshConvert(); | |||
/* FIXME: m_custom_shader is ignored */ | |||
m_ready = true; | |||
} | |||
else if (m_should_render) | |||
{ | |||
if (m_is_character) | |||
m_mesh.Render(m_character->GetTransform()); | |||
g_scene->AddPrimitive(m_mesh, m_character->GetTransform()); | |||
else | |||
m_mesh.Render(m_physics->GetTransform()); | |||
g_scene->AddPrimitive(m_mesh, m_physics->GetTransform()); | |||
} | |||
} | |||
} | |||
@@ -8,7 +8,7 @@ attribute vec4 in_Color; | |||
uniform mat4 u_modelview; | |||
uniform mat4 u_view; | |||
uniform mat4 u_proj; | |||
uniform mat4 u_projection; | |||
uniform mat3 u_normalmat; | |||
uniform float in_Damage; | |||
@@ -29,7 +29,7 @@ void main(void) | |||
pass_TNormal = tnorm; | |||
pass_Color = in_Color; | |||
gl_Position = u_proj * vertex; | |||
gl_Position = u_projection * vertex; | |||
} | |||
[frag.glsl] | |||
@@ -121,7 +121,7 @@ void main(float3 in_Vertex : POSITION, | |||
float3 in_Normal : NORMAL, | |||
float4 in_Color : COLOR, | |||
uniform float4x4 u_modelview, | |||
uniform float4x4 u_proj, | |||
uniform float4x4 u_projection, | |||
uniform float3x3 u_normalmat, | |||
out float4 pass_Vertex : TEXCOORD0, | |||
out float3 pass_TNormal : TEXCOORD1, | |||
@@ -139,7 +139,7 @@ void main(float3 in_Vertex : POSITION, | |||
pass_Color = in_Color; | |||
#endif | |||
out_Position = mul(u_proj, eye); | |||
out_Position = mul(u_projection, eye); | |||
} | |||
[frag.hlsl] | |||
@@ -9,7 +9,7 @@ attribute vec2 in_TexCoord; | |||
uniform mat4 u_modelview; | |||
uniform mat4 u_view; | |||
uniform mat4 u_proj; | |||
uniform mat4 u_projection; | |||
uniform mat3 u_normalmat; | |||
varying vec4 pass_Vertex; /* View space */ | |||
@@ -27,7 +27,7 @@ void main(void) | |||
pass_Color = in_Color; | |||
pass_TexCoord = in_TexCoord; | |||
gl_Position = u_proj * vertex; | |||
gl_Position = u_projection * vertex; | |||
} | |||
[frag.glsl] | |||
@@ -102,7 +102,7 @@ void main(float3 in_Vertex : POSITION, | |||
float3 in_Normal : NORMAL, | |||
float4 in_Color : COLOR, | |||
uniform float4x4 u_modelview, | |||
uniform float4x4 u_proj, | |||
uniform float4x4 u_projection, | |||
uniform float3x3 u_normalmat, | |||
out float4 pass_Vertex : TEXCOORD0, | |||
out float3 pass_TNormal : TEXCOORD1, | |||
@@ -120,7 +120,7 @@ void main(float3 in_Vertex : POSITION, | |||
pass_Color = in_Color; | |||
#endif | |||
out_Position = mul(u_proj, eye); | |||
out_Position = mul(u_projection, eye); | |||
} | |||
[frag.hlsl] | |||