From f10467496391780c1c8240cec3ca471030622999 Mon Sep 17 00:00:00 2001 From: Benlitz Date: Sat, 14 Sep 2013 17:42:46 +0000 Subject: [PATCH] gpu: removed attribute name, everything works using semantic only now. For glsl, semantic is determined from the attribute name which must follow this pattern: in_[Semantic][index], index being optional. Note: this may break most of the projects although I tried to updated every shader accordingly --- demos/tutorial/01_triangle.cpp | 2 +- demos/tutorial/02_cube.cpp | 6 +- demos/tutorial/02_cube.lolfx | 4 +- demos/tutorial/07_input.lolfx | 4 +- demos/tutorial/08_fbo.cpp | 2 +- demos/tutorial/11_fractal.cpp | 4 +- demos/tutorial/11_fractal.lolfx | 10 +-- demos/tutorial/12_texture_to_screen.lolfx | 6 +- demos/tutorial/12_voronoi.lolfx | 6 +- demos/tutorial/12_voronoi_setup.lolfx | 6 +- src/easymesh/easymesh.cpp | 26 +++---- src/easymesh/easymesh.h | 10 +-- src/easymesh/shiny.lolfx | 4 +- src/easymesh/shiny_SK.lolfx | 4 +- src/easymesh/shinydebugUV.lolfx | 4 +- src/easymesh/shinydebuglighting.lolfx | 4 +- src/easymesh/shinydebugnormal.lolfx | 4 +- src/easymesh/shinydebugwireframe.lolfx | 4 +- src/gpu/shader.cpp | 92 +++++++++++++++++++---- src/gpu/testmaterial.lolfx | 4 +- src/gradient.cpp | 4 +- src/gradient.lolfx | 4 +- src/lol/gpu/shader.h | 3 +- src/scene.cpp | 8 +- test/front_camera_sprite.lolfx | 14 ++-- test/shinyfur.lolfx | 4 +- test/shinymvtexture.lolfx | 4 +- 27 files changed, 153 insertions(+), 94 deletions(-) diff --git a/demos/tutorial/01_triangle.cpp b/demos/tutorial/01_triangle.cpp index 3b481f81..8adcf06c 100644 --- a/demos/tutorial/01_triangle.cpp +++ b/demos/tutorial/01_triangle.cpp @@ -38,7 +38,7 @@ public: if (!m_ready) { m_shader = Shader::Create(LOLFX_RESOURCE_NAME(01_triangle)); - m_coord = m_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0); + m_coord = m_shader->GetAttribLocation(VertexUsage::Position, 0); m_vdecl = new VertexDeclaration(VertexStream(VertexUsage::Position)); diff --git a/demos/tutorial/02_cube.cpp b/demos/tutorial/02_cube.cpp index ebe746da..f5656d2e 100644 --- a/demos/tutorial/02_cube.cpp +++ b/demos/tutorial/02_cube.cpp @@ -75,10 +75,8 @@ public: m_shader = Shader::Create(LOLFX_RESOURCE_NAME(02_cube)); m_mvp = m_shader->GetUniformLocation("in_Matrix"); - m_coord = m_shader->GetAttribLocation("in_Vertex", - VertexUsage::Position, 0); - m_color = m_shader->GetAttribLocation("in_Color", - VertexUsage::Color, 0); + m_coord = m_shader->GetAttribLocation(VertexUsage::Position, 0); + m_color = m_shader->GetAttribLocation(VertexUsage::Color, 0); m_vdecl = new VertexDeclaration(VertexStream(VertexUsage::Position, diff --git a/demos/tutorial/02_cube.lolfx b/demos/tutorial/02_cube.lolfx index 8e1ae04f..3b67e812 100644 --- a/demos/tutorial/02_cube.lolfx +++ b/demos/tutorial/02_cube.lolfx @@ -2,14 +2,14 @@ #version 120 -attribute vec3 in_Vertex; +attribute vec3 in_Position; attribute vec3 in_Color; uniform mat4 in_Matrix; varying vec3 pass_Color; void main(void) { - gl_Position = in_Matrix * vec4(in_Vertex, 1.0); + gl_Position = in_Matrix * vec4(in_Position, 1.0); pass_Color = in_Color; } diff --git a/demos/tutorial/07_input.lolfx b/demos/tutorial/07_input.lolfx index 8e1ae04f..3b67e812 100644 --- a/demos/tutorial/07_input.lolfx +++ b/demos/tutorial/07_input.lolfx @@ -2,14 +2,14 @@ #version 120 -attribute vec3 in_Vertex; +attribute vec3 in_Position; attribute vec3 in_Color; uniform mat4 in_Matrix; varying vec3 pass_Color; void main(void) { - gl_Position = in_Matrix * vec4(in_Vertex, 1.0); + gl_Position = in_Matrix * vec4(in_Position, 1.0); pass_Color = in_Color; } diff --git a/demos/tutorial/08_fbo.cpp b/demos/tutorial/08_fbo.cpp index 291021c7..7bd7e72b 100644 --- a/demos/tutorial/08_fbo.cpp +++ b/demos/tutorial/08_fbo.cpp @@ -58,7 +58,7 @@ public: if (!m_ready) { m_shader = Shader::Create(LOLFX_RESOURCE_NAME(08_fbo)); - m_coord = m_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0); + m_coord = m_shader->GetAttribLocation(VertexUsage::Position, 0); m_uni_flag = m_shader->GetUniformLocation("in_Flag"); m_uni_point = m_shader->GetUniformLocation("in_Point"); m_uni_color = m_shader->GetUniformLocation("in_Color"); diff --git a/demos/tutorial/11_fractal.cpp b/demos/tutorial/11_fractal.cpp index 75ce1c2d..0bf6aeb5 100644 --- a/demos/tutorial/11_fractal.cpp +++ b/demos/tutorial/11_fractal.cpp @@ -463,8 +463,8 @@ public: m_shader = Shader::Create(LOLFX_RESOURCE_NAME(11_fractal)); - m_vertexattrib = m_shader->GetAttribLocation("a_Vertex", VertexUsage::Position, 0); - m_texattrib = m_shader->GetAttribLocation("a_TexCoord", VertexUsage::TexCoord, 0); + m_vertexattrib = m_shader->GetAttribLocation(VertexUsage::Position, 0); + m_texattrib = m_shader->GetAttribLocation(VertexUsage::TexCoord, 0); m_texeluni = m_shader->GetUniformLocation("u_TexelSize"); m_screenuni = m_shader->GetUniformLocation("u_ScreenSize"); m_zoomuni = m_shader->GetUniformLocation("u_ZoomSettings"); diff --git a/demos/tutorial/11_fractal.lolfx b/demos/tutorial/11_fractal.lolfx index 803e8021..4e869841 100644 --- a/demos/tutorial/11_fractal.lolfx +++ b/demos/tutorial/11_fractal.lolfx @@ -6,14 +6,14 @@ uniform mat4 u_ZoomSettings; uniform vec4 u_TexelSize; uniform vec4 u_ScreenSize; -attribute vec2 a_TexCoord; -attribute vec2 a_Vertex; +attribute vec2 in_TexCoord; +attribute vec2 in_Position; varying vec4 v_CenterX, v_CenterY, v_IndexX, v_IndexY; void main(void) { - gl_Position = vec4(a_Vertex, 0.0, 1.0); + gl_Position = vec4(in_Position, 0.0, 1.0); /* Center point in [-.5,.5], apply zoom and translation * transformation, and go back to texture coordinates * in [0,1]. That's the ideal point we would like to @@ -33,9 +33,9 @@ void main(void) u_ZoomSettings[1][1], u_ZoomSettings[2][1], u_ZoomSettings[3][1]); - v_CenterX = zoomscale * a_TexCoord.x + zoomtx + v_CenterX = zoomscale * in_TexCoord.x + zoomtx + offsets.xyxy * u_TexelSize.x; - v_CenterY = zoomscale * a_TexCoord.y - zoomty + v_CenterY = zoomscale * in_TexCoord.y - zoomty + offsets.xyyx * u_TexelSize.y; /* Precompute the multiple of one texel where our ideal * point lies. The fragment shader will call floor() on diff --git a/demos/tutorial/12_texture_to_screen.lolfx b/demos/tutorial/12_texture_to_screen.lolfx index 78ca4d6d..fac53a65 100644 --- a/demos/tutorial/12_texture_to_screen.lolfx +++ b/demos/tutorial/12_texture_to_screen.lolfx @@ -2,14 +2,14 @@ #version 120 -attribute vec2 in_position; +attribute vec2 in_Position; varying vec2 pass_position; void main() { - pass_position = in_position; - gl_Position = vec4(in_position, 0.0, 1.0); + pass_position = in_Position; + gl_Position = vec4(in_Position, 0.0, 1.0); } [frag.glsl] diff --git a/demos/tutorial/12_voronoi.lolfx b/demos/tutorial/12_voronoi.lolfx index 8ae45a11..2ff787ae 100644 --- a/demos/tutorial/12_voronoi.lolfx +++ b/demos/tutorial/12_voronoi.lolfx @@ -5,7 +5,7 @@ #version 120 -attribute vec2 in_position; +attribute vec2 in_Position; uniform vec2 in_screen_res; @@ -16,7 +16,7 @@ varying vec2 pass_p[8]; void main() { //JFA ALGO - pass_pos = ((vec2(1.0) + in_position) * 0.5); + pass_pos = ((vec2(1.0) + in_Position) * 0.5); float k = in_step; @@ -30,7 +30,7 @@ void main() pass_p[6] = p2 + vec2( 0, k); pass_p[7] = p2 + vec2( k, k); - gl_Position = vec4(in_position, 0.0, 1.0); + gl_Position = vec4(in_Position, 0.0, 1.0); } [frag.glsl] diff --git a/demos/tutorial/12_voronoi_setup.lolfx b/demos/tutorial/12_voronoi_setup.lolfx index 3712ace8..9d1a114e 100644 --- a/demos/tutorial/12_voronoi_setup.lolfx +++ b/demos/tutorial/12_voronoi_setup.lolfx @@ -5,7 +5,7 @@ #version 120 -attribute vec2 in_position; +attribute vec2 in_Position; uniform vec2 in_screen_res; @@ -13,8 +13,8 @@ varying vec2 pass_position; void main() { - pass_position = ((vec2(1.0) + in_position) * 0.5 * in_screen_res); - gl_Position = vec4(in_position, 0.0, 1.0); + pass_position = ((vec2(1.0) + in_Position) * 0.5 * in_screen_res); + gl_Position = vec4(in_Position, 0.0, 1.0); } [frag.glsl] diff --git a/src/easymesh/easymesh.cpp b/src/easymesh/easymesh.cpp index d4f03def..5821ca16 100644 --- a/src/easymesh/easymesh.cpp +++ b/src/easymesh/easymesh.cpp @@ -61,9 +61,9 @@ void GpuShaderData::AddUniform(const lol::String &new_uniform) } //----------------------------------------------------------------------------- -void GpuShaderData::AddAttribute(const lol::String &new_attribute, VertexUsage usage, int index) +void GpuShaderData::AddAttribute(VertexUsage usage, int index) { - m_shader_attrib.Push(new_attribute, m_shader->GetAttribLocation(new_attribute.C(), usage, index)); + m_shader_attrib.Push(m_shader->GetAttribLocation(usage, index)); } //----------------------------------------------------------------------------- @@ -76,11 +76,11 @@ ShaderUniform const *GpuShaderData::GetUniform(const lol::String &uniform) } //----------------------------------------------------------------------------- -ShaderAttrib const *GpuShaderData::GetAttribute(const lol::String &attribute) +ShaderAttrib const *GpuShaderData::GetAttribute(VertexUsage usage, int index) { for (int i = 0; i < m_shader_attrib.Count(); ++i) - if (m_shader_attrib[i].m1 == attribute) - return &m_shader_attrib[i].m2; + if (m_shader_attrib[i].GetUsage() == usage && m_shader_attrib[i].GetIndex() == index) + return &m_shader_attrib[i]; return nullptr; } @@ -198,10 +198,10 @@ void GpuEasyMeshData::AddGpuData(GpuShaderData* gpudata, EasyMesh* src_mesh) ASSERT(!vflags, "Vertex Usage setup is not implemented for %s, feel free to do so.", VertexUsage::GetNameList(vflags).C()); - if (has_position) gpudata->AddAttribute(gpudata->GetInVertexName(), VertexUsage::Position, 0); - if (has_normal) gpudata->AddAttribute(gpudata->GetInNormalName(), VertexUsage::Normal, 0); - if (has_color) gpudata->AddAttribute(gpudata->GetInColorName(), VertexUsage::Color, 0); - if (has_texcoord) gpudata->AddAttribute(gpudata->GetInTexCoordName(), VertexUsage::TexCoord, 0); + if (has_position) gpudata->AddAttribute(VertexUsage::Position, 0); + if (has_normal) gpudata->AddAttribute(VertexUsage::Normal, 0); + if (has_color) gpudata->AddAttribute(VertexUsage::Color, 0); + if (has_texcoord) gpudata->AddAttribute(VertexUsage::TexCoord, 0); SetupVertexData(gpudata->m_vert_decl_flags, src_mesh); @@ -408,10 +408,10 @@ void GpuEasyMeshData::RenderMeshData(mat4 const &model) int idx = 0; ShaderAttrib Attribs[4] = { lol::ShaderAttrib(), lol::ShaderAttrib(), lol::ShaderAttrib(), lol::ShaderAttrib() }; - if (has_position) Attribs[idx++] = *gpu_sd.GetAttribute(gpu_sd.GetInVertexName()); - if (has_normal) Attribs[idx++] = *gpu_sd.GetAttribute(gpu_sd.GetInNormalName()); - if (has_color) Attribs[idx++] = *gpu_sd.GetAttribute(gpu_sd.GetInColorName()); - if (has_texcoord) Attribs[idx++] = *gpu_sd.GetAttribute(gpu_sd.GetInTexCoordName()); + if (has_position) Attribs[idx++] = *gpu_sd.GetAttribute(VertexUsage::Position, 0); + if (has_normal) Attribs[idx++] = *gpu_sd.GetAttribute(VertexUsage::Normal, 0); + if (has_color) Attribs[idx++] = *gpu_sd.GetAttribute(VertexUsage::Color, 0); + if (has_texcoord) Attribs[idx++] = *gpu_sd.GetAttribute(VertexUsage::TexCoord, 0); vdecl->SetStream(vbo, Attribs[0], Attribs[1], Attribs[2], Attribs[3]); diff --git a/src/easymesh/easymesh.h b/src/easymesh/easymesh.h index 85b1c38a..0c18138e 100644 --- a/src/easymesh/easymesh.h +++ b/src/easymesh/easymesh.h @@ -77,23 +77,19 @@ public: virtual ~GpuShaderData(); //-- void AddUniform(const lol::String &new_uniform); - void AddAttribute(const lol::String &new_attribute, VertexUsage usage, int index); + void AddAttribute(VertexUsage usage, int index); ShaderUniform const *GetUniform(const lol::String &uniform); - ShaderAttrib const *GetAttribute(const lol::String &attribute); + ShaderAttrib const *GetAttribute(VertexUsage usage, int index); //-- virtual void SetupShaderDatas(mat4 const &model) { UNUSED(model); } //-- - virtual lol::String GetInVertexName() { return lol::String("in_Vertex"); } - virtual lol::String GetInNormalName() { return lol::String("in_Normal"); } - virtual lol::String GetInColorName() { return lol::String("in_Color"); } - virtual lol::String GetInTexCoordName() { return lol::String("in_TexCoord"); } protected: uint16_t m_vert_decl_flags; Shader* m_shader; DebugRenderMode m_render_mode; Array m_shader_uniform; - Array m_shader_attrib; + Array m_shader_attrib; }; class DefaultShaderData : public GpuShaderData diff --git a/src/easymesh/shiny.lolfx b/src/easymesh/shiny.lolfx index 5a24d03c..cfa09a75 100644 --- a/src/easymesh/shiny.lolfx +++ b/src/easymesh/shiny.lolfx @@ -2,7 +2,7 @@ [vert.glsl] #version 120 -attribute vec3 in_Vertex; +attribute vec3 in_Position; attribute vec3 in_Normal; attribute vec4 in_Color; @@ -17,7 +17,7 @@ varying vec4 pass_Color; void main(void) { - vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0); + vec4 vertex = in_ModelView * vec4(in_Position, 1.0); vec3 tnorm = normalize(in_NormalMat * in_Normal); pass_Vertex = vertex; diff --git a/src/easymesh/shiny_SK.lolfx b/src/easymesh/shiny_SK.lolfx index 4f651713..a7a66431 100644 --- a/src/easymesh/shiny_SK.lolfx +++ b/src/easymesh/shiny_SK.lolfx @@ -2,7 +2,7 @@ [vert.glsl] #version 120 -attribute vec3 in_Vertex; +attribute vec3 in_Position; attribute vec3 in_Normal; attribute vec4 in_Color; attribute vec2 in_Index; @@ -21,7 +21,7 @@ varying vec4 pass_Color; void main(void) { - vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0); + vec4 vertex = in_ModelView * vec4(in_Position, 1.0); vec3 tnorm = normalize(in_NormalMat * in_Normal); pass_Vertex = vertex; diff --git a/src/easymesh/shinydebugUV.lolfx b/src/easymesh/shinydebugUV.lolfx index 841b53e4..31a9c517 100644 --- a/src/easymesh/shinydebugUV.lolfx +++ b/src/easymesh/shinydebugUV.lolfx @@ -2,7 +2,7 @@ [vert.glsl] #version 120 -attribute vec3 in_Vertex; +attribute vec3 in_Position; attribute vec3 in_Normal; attribute vec4 in_Color; attribute vec2 in_TexCoord; @@ -19,7 +19,7 @@ varying vec2 pass_TexCoord; void main(void) { - vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0); + vec4 vertex = in_ModelView * vec4(in_Position, 1.0); vec3 tnorm = normalize(in_NormalMat * in_Normal); pass_Vertex = vertex; diff --git a/src/easymesh/shinydebuglighting.lolfx b/src/easymesh/shinydebuglighting.lolfx index c434c3b4..3af480d0 100644 --- a/src/easymesh/shinydebuglighting.lolfx +++ b/src/easymesh/shinydebuglighting.lolfx @@ -2,7 +2,7 @@ [vert.glsl] #version 120 -attribute vec3 in_Vertex; +attribute vec3 in_Position; attribute vec3 in_Normal; attribute vec4 in_Color; @@ -17,7 +17,7 @@ varying vec4 pass_Color; void main(void) { - vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0); + vec4 vertex = in_ModelView * vec4(in_Position, 1.0); vec3 tnorm = normalize(in_NormalMat * in_Normal); pass_Vertex = vertex; diff --git a/src/easymesh/shinydebugnormal.lolfx b/src/easymesh/shinydebugnormal.lolfx index fb87d478..ffdb9b26 100644 --- a/src/easymesh/shinydebugnormal.lolfx +++ b/src/easymesh/shinydebugnormal.lolfx @@ -2,7 +2,7 @@ [vert.glsl] #version 120 -attribute vec3 in_Vertex; +attribute vec3 in_Position; attribute vec3 in_Normal; attribute vec4 in_Color; @@ -17,7 +17,7 @@ varying vec4 pass_Color; void main(void) { - vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0); + vec4 vertex = in_ModelView * vec4(in_Position, 1.0); vec3 tnorm = normalize(in_Normal); pass_Vertex = vertex; diff --git a/src/easymesh/shinydebugwireframe.lolfx b/src/easymesh/shinydebugwireframe.lolfx index 001242fb..aadc2b64 100644 --- a/src/easymesh/shinydebugwireframe.lolfx +++ b/src/easymesh/shinydebugwireframe.lolfx @@ -2,7 +2,7 @@ [vert.glsl] #version 120 -attribute vec3 in_Vertex; +attribute vec3 in_Position; attribute vec3 in_Normal; attribute vec4 in_Color; @@ -17,7 +17,7 @@ varying vec4 pass_Color; void main(void) { - vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0); + vec4 vertex = in_ModelView * vec4(in_Position, 1.0); vec3 tnorm = normalize(in_NormalMat * in_Normal); pass_Vertex = vertex; diff --git a/src/gpu/shader.cpp b/src/gpu/shader.cpp index 904c1502..555d7582 100644 --- a/src/gpu/shader.cpp +++ b/src/gpu/shader.cpp @@ -39,6 +39,24 @@ using namespace std; namespace lol { +static const char* attribute_names[] = { + "in_Position", + "in_BlendWeight", + "in_BlendIndices", + "in_Normal", + "in_PointSize", + "in_TexCoord", + "in_TexCoordExt", + "in_Tangent", + "in_Binormal", + "in_TessFactor", + "in_PositionT", + "in_Color", + "in_Fog", + "in_Depth", + "in_Sample" +}; + /* * Shader implementation class */ @@ -61,7 +79,7 @@ private: #elif !defined __CELLOS_LV2__ 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 attrib_locations; + Map attrib_locations; #else CGprogram vert_id, frag_id; #endif @@ -322,12 +340,68 @@ Shader::Shader(char const *vert, char const *frag) { Log::Debug("link log for program: %s", errbuf); } + + GLint validated; glValidateProgram(data->prog_id); + glGetProgramiv(data->prog_id, GL_VALIDATE_STATUS, &validated); + if (validated != GL_TRUE) + { + Log::Error("failed to validate program"); + } + + GLint num_attribs; + glGetProgramiv(data->prog_id, GL_ACTIVE_ATTRIBUTES, &num_attribs); + + GLint max_len; + glGetProgramiv(data->prog_id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_len); + + char* name_buffer = new char[max_len]; + for (int i = 0; i < num_attribs; ++i) + { + int attrib_len; + int attrib_size; + int attrib_type; + glGetActiveAttrib(data->prog_id, i, max_len, &attrib_len, (GLint*)&attrib_size, (GLenum*)&attrib_type, name_buffer); + + String name(name_buffer); + int index = 0; + VertexUsage usage = VertexUsage::Max; + for (int j = 0; j < VertexUsage::Max; ++j) + { + if (name.StartsWith(attribute_names[j])) + { + usage = VertexUsage(j); + char* idx_ptr = name.C() + strlen(attribute_names[j]); + index = strtol(idx_ptr, nullptr, 10); + break; + } + } + + if (usage == VertexUsage::Max || index == LONG_MIN || index == LONG_MAX) + { + Log::Error("unable to parse attribute sementic from name: %s", name_buffer); + } + else + { + GLint location = glGetAttribLocation(data->prog_id, name_buffer); + uint64_t flags = (uint64_t)(uint16_t)usage << 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 (data->attrib_locations.HasKey(flags)) + { + Log::Error("an error occured while parsing attribute sementics"); + } +#endif + data->attrib_locations[flags] = location; + } + } + + delete[] name_buffer; #endif } -ShaderAttrib Shader::GetAttribLocation(char const *attr, - VertexUsage usage, int index) const +ShaderAttrib Shader::GetAttribLocation(VertexUsage usage, int index) const { ShaderAttrib ret; ret.m_flags = (uint64_t)(uint16_t)usage << 16; @@ -336,17 +410,9 @@ ShaderAttrib Shader::GetAttribLocation(char const *attr, #elif !defined __CELLOS_LV2__ GLint l; - if (!data->attrib_locations.TryGetValue(attr, l)) + if (!data->attrib_locations.TryGetValue(ret.m_flags, l)) { - l = glGetAttribLocation(data->prog_id, attr); - if (l < 0) - { - Log::Warn("tried to query invalid attribute: %s\n", attr); - } - else - { - data->attrib_locations[String(attr)] = l; - } + Log::Error("queried attribute is unavailable for this shader"); } ret.m_flags |= (uint64_t)(uint32_t)l << 32; #else diff --git a/src/gpu/testmaterial.lolfx b/src/gpu/testmaterial.lolfx index 4b572ea4..642b0c44 100644 --- a/src/gpu/testmaterial.lolfx +++ b/src/gpu/testmaterial.lolfx @@ -70,10 +70,10 @@ technique Foo #version 120 /* Valid with my GLSL compiler */ -//#pragma lolfx semantic(in_Vertex, POSITION) +//#pragma lolfx semantic(in_Position, POSITION) //#pragma lolfx semantic(in_Normal, NORMAL) //#pragma lolfx semantic(in_Color, COLOR) -attribute vec3 in_Vertex; +attribute vec3 in_Position; attribute vec3 in_Normal; attribute vec4 in_Color; diff --git a/src/gradient.cpp b/src/gradient.cpp index f1d5cab4..1aba8d8d 100644 --- a/src/gradient.cpp +++ b/src/gradient.cpp @@ -88,8 +88,8 @@ void Gradient::TickDraw(float seconds) ShaderUniform uni_mat; ShaderAttrib attr_pos, attr_col; - attr_pos = data->shader->GetAttribLocation("in_Vertex", VertexUsage::Position, 0); - attr_col = data->shader->GetAttribLocation("in_Color", VertexUsage::Color, 0); + attr_pos = data->shader->GetAttribLocation(VertexUsage::Position, 0); + attr_col = data->shader->GetAttribLocation(VertexUsage::Color, 0); data->shader->Bind(); diff --git a/src/gradient.lolfx b/src/gradient.lolfx index a7404328..ca36870d 100644 --- a/src/gradient.lolfx +++ b/src/gradient.lolfx @@ -2,7 +2,7 @@ #version 130 -attribute vec3 in_Vertex; +attribute vec3 in_Position; attribute vec4 in_Color; varying vec4 pass_Color; @@ -13,7 +13,7 @@ uniform mat4 model_matrix; void main() { gl_Position = proj_matrix * view_matrix * model_matrix - * vec4(in_Vertex, 1.0); + * vec4(in_Position, 1.0); pass_Color = in_Color; } diff --git a/src/lol/gpu/shader.h b/src/lol/gpu/shader.h index d66179f2..cb93ea00 100644 --- a/src/lol/gpu/shader.h +++ b/src/lol/gpu/shader.h @@ -157,8 +157,7 @@ public: static Shader *Create(char const *lolfx); static void Destroy(Shader *shader); - ShaderAttrib GetAttribLocation(char const *attr, struct VertexUsage usage, - int index) const; + ShaderAttrib GetAttribLocation(struct VertexUsage usage, int index) const; ShaderUniform GetUniformLocation(char const *uni) const; void SetUniform(ShaderUniform const &uni, int i); diff --git a/src/scene.cpp b/src/scene.cpp index 7222c88f..958ab078 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -202,8 +202,8 @@ void Scene::RenderTiles() // XXX: rename to Blit() ShaderUniform uni_mat, uni_tex, uni_texsize; ShaderAttrib attr_pos, attr_tex; - attr_pos = data->m_tile_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0); - attr_tex = data->m_tile_shader->GetAttribLocation("in_TexCoord", VertexUsage::TexCoord, 0); + attr_pos = data->m_tile_shader->GetAttribLocation(VertexUsage::Position, 0); + attr_tex = data->m_tile_shader->GetAttribLocation(VertexUsage::TexCoord, 0); data->m_tile_shader->Bind(); @@ -307,8 +307,8 @@ void Scene::RenderLines() // XXX: rename to Blit() ShaderUniform uni_mat, uni_tex; ShaderAttrib attr_pos, attr_col; - attr_pos = data->m_line_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0); - attr_col = data->m_line_shader->GetAttribLocation("in_Color", VertexUsage::Color, 0); + attr_pos = data->m_line_shader->GetAttribLocation(VertexUsage::Position, 0); + attr_col = data->m_line_shader->GetAttribLocation(VertexUsage::Color, 0); data->m_line_shader->Bind(); diff --git a/test/front_camera_sprite.lolfx b/test/front_camera_sprite.lolfx index aa8da80f..2278b573 100644 --- a/test/front_camera_sprite.lolfx +++ b/test/front_camera_sprite.lolfx @@ -2,9 +2,9 @@ [vert.glsl] #version 120 -attribute vec3 in_vertex; -attribute vec4 in_color; -attribute vec4 in_texcoord; +attribute vec3 in_Position; +attribute vec4 in_Color; +attribute vec4 in_TexCoord; uniform mat4 in_model_view; uniform mat3 in_normal_mat; @@ -16,9 +16,9 @@ varying vec4 pass_color; void main(void) { - vec4 vertex = in_model_view * vec4(in_vertex - vec3(0.0,0.5,0.0), 1.0); + vec4 vertex = in_model_view * vec4(in_Position - vec3(0.0,0.5,0.0), 1.0); - vec3 v_offset = vec3(1.0 * in_texcoord.z, -1.0 * in_texcoord.w, 0.0); + vec3 v_offset = vec3(1.0 * in_TexCoord.z, -1.0 * in_TexCoord.w, 0.0); float sinX = sin(in_sprite_orientation); float cosX = cos(in_sprite_orientation); @@ -31,8 +31,8 @@ void main(void) vertex.xyz += v_offset; //pass datas - pass_texcoord = in_texcoord; - pass_color = in_color; + pass_texcoord = in_TexCoord; + pass_color = in_Color; gl_Position = in_proj * vertex; } diff --git a/test/shinyfur.lolfx b/test/shinyfur.lolfx index 10f16857..b14f6d05 100644 --- a/test/shinyfur.lolfx +++ b/test/shinyfur.lolfx @@ -2,7 +2,7 @@ [vert.glsl] #version 120 -attribute vec3 in_Vertex; +attribute vec3 in_Position; attribute vec3 in_Normal; attribute vec4 in_Color; @@ -18,7 +18,7 @@ varying vec4 pass_Color; void main(void) { - vec4 vertex = vec4(in_Vertex + (in_Normal * in_Damage), 1.0); + vec4 vertex = vec4(in_Position + (in_Normal * in_Damage), 1.0); float dam_perc = in_Damage / (0.1 * 40); vec3 vGravity = vec3(0.0, -0.981, 0.0) * 2.0; float k = pow(dam_perc, 3); diff --git a/test/shinymvtexture.lolfx b/test/shinymvtexture.lolfx index cac69a52..29773cf9 100644 --- a/test/shinymvtexture.lolfx +++ b/test/shinymvtexture.lolfx @@ -2,7 +2,7 @@ [vert.glsl] #version 120 -attribute vec3 in_Vertex; +attribute vec3 in_Position; attribute vec3 in_Normal; attribute vec4 in_Color; attribute vec2 in_TexCoord; @@ -19,7 +19,7 @@ varying vec2 pass_TexCoord; void main(void) { - vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0); + vec4 vertex = in_ModelView * vec4(in_Position, 1.0); vec3 tnorm = normalize(in_NormalMat * in_Normal); pass_Vertex = vertex;