Move duplicated setVertexArrays to RenderContext

pull/3/head
Hleb Valoshka 2019-07-19 00:47:30 +03:00
parent 4d5f2d9c64
commit f8d3815a70
2 changed files with 32 additions and 68 deletions

View File

@ -183,6 +183,37 @@ RenderContext::drawGroup(const Mesh::PrimitiveGroup& group)
}
void
RenderContext::setVertexArrays(const Mesh::VertexDescription& desc,
const void* vertexData)
{
setStandardVertexArrays(desc, vertexData);
setExtendedVertexArrays(desc, vertexData);
// Normally, the shader that will be used depends only on the material.
// But the presence of point size and normals can also affect the
// shader, so force an update of the material if those attributes appear
// or disappear in the new set of vertex arrays.
bool usePointSizeNow = (desc.getAttribute(Mesh::PointSize).format == Mesh::Float1);
bool useNormalsNow = (desc.getAttribute(Mesh::Normal).format == Mesh::Float3);
bool useColorsNow = (desc.getAttribute(Mesh::Color0).format != Mesh::InvalidFormat);
bool useTexCoordsNow = (desc.getAttribute(Mesh::Texture0).format != Mesh::InvalidFormat);
if (usePointSizeNow != usePointSize ||
useNormalsNow != useNormals ||
useColorsNow != useColors ||
useTexCoordsNow != useTexCoords)
{
usePointSize = usePointSizeNow;
useNormals = useNormalsNow;
useColors = useColorsNow;
useTexCoords = useTexCoordsNow;
if (getMaterial() != nullptr)
makeCurrent(*getMaterial());
}
}
void
setStandardVertexArrays(const Mesh::VertexDescription& desc,
const void* vertexData)
@ -602,37 +633,6 @@ GLSL_RenderContext::makeCurrent(const Material& m)
}
void
GLSL_RenderContext::setVertexArrays(const Mesh::VertexDescription& desc,
const void* vertexData)
{
setStandardVertexArrays(desc, vertexData);
setExtendedVertexArrays(desc, vertexData);
// Normally, the shader that will be used depends only on the material.
// But the presence of point size and normals can also affect the
// shader, so force an update of the material if those attributes appear
// or disappear in the new set of vertex arrays.
bool usePointSizeNow = (desc.getAttribute(Mesh::PointSize).format == Mesh::Float1);
bool useNormalsNow = (desc.getAttribute(Mesh::Normal).format == Mesh::Float3);
bool useColorsNow = (desc.getAttribute(Mesh::Color0).format != Mesh::InvalidFormat);
bool useTexCoordsNow = (desc.getAttribute(Mesh::Texture0).format != Mesh::InvalidFormat);
if (usePointSizeNow != usePointSize ||
useNormalsNow != useNormals ||
useColorsNow != useColors ||
useTexCoordsNow != useTexCoords)
{
usePointSize = usePointSizeNow;
useNormals = useNormalsNow;
useColors = useColorsNow;
useTexCoords = useTexCoordsNow;
if (getMaterial() != nullptr)
makeCurrent(*getMaterial());
}
}
void
GLSL_RenderContext::setAtmosphere(const Atmosphere* _atmosphere)
{
@ -768,34 +768,3 @@ GLSLUnlit_RenderContext::makeCurrent(const Material& m)
}
}
}
void
GLSLUnlit_RenderContext::setVertexArrays(const Mesh::VertexDescription& desc,
const void* vertexData)
{
setStandardVertexArrays(desc, vertexData);
setExtendedVertexArrays(desc, vertexData);
// Normally, the shader that will be used depends only on the material.
// But the presence of point size and normals can also affect the
// shader, so force an update of the material if those attributes appear
// or disappear in the new set of vertex arrays.
bool usePointSizeNow = (desc.getAttribute(Mesh::PointSize).format == Mesh::Float1);
bool useNormalsNow = (desc.getAttribute(Mesh::Normal).format == Mesh::Float3);
bool useColorsNow = (desc.getAttribute(Mesh::Color0).format != Mesh::InvalidFormat);
bool useTexCoordsNow = (desc.getAttribute(Mesh::Texture0).format != Mesh::InvalidFormat);
if (usePointSizeNow != usePointSize ||
useNormalsNow != useNormals ||
useColorsNow != useColors ||
useTexCoordsNow != useTexCoords)
{
usePointSize = usePointSizeNow;
useNormals = useNormalsNow;
useColors = useColorsNow;
useTexCoords = useTexCoordsNow;
if (getMaterial() != nullptr)
makeCurrent(*getMaterial());
}
}

View File

@ -28,7 +28,7 @@ class RenderContext
virtual void makeCurrent(const cmod::Material&) = 0;
virtual void setVertexArrays(const cmod::Mesh::VertexDescription& desc,
const void* vertexData) = 0;
const void* vertexData);
virtual void drawGroup(const cmod::Mesh::PrimitiveGroup& group);
const cmod::Material* getMaterial() const;
@ -79,9 +79,6 @@ class GLSL_RenderContext : public RenderContext
~GLSL_RenderContext() override;
void makeCurrent(const cmod::Material&) override;
void setVertexArrays(const cmod::Mesh::VertexDescription& desc,
const void* vertexData) override;
void setLunarLambert(float);
void setAtmosphere(const Atmosphere*);
@ -112,8 +109,6 @@ class GLSLUnlit_RenderContext : public RenderContext
~GLSLUnlit_RenderContext() override;
void makeCurrent(const cmod::Material&) override;
void setVertexArrays(const cmod::Mesh::VertexDescription& desc,
const void* vertexData) override;
private:
void initLightingEnvironment();