Commit 57e29494 authored by Frédéric Larue's avatar Frédéric Larue

shaderFromResources() function more flexible in DisplayableInterface.

Gives the possibility to concatenate multiple source files.
parent 7807046d
Pipeline #1818 failed with stages
in 22 seconds
......@@ -39,46 +39,57 @@ private:
GenericUIData *m_Data;
bool m_IsAnimationPaused;
QString concatenateResourcesContent( const QStringList &resourceNames ) const
{
QString res;
for( auto &rscName : resourceNames )
{
QFile rscFile( rscName );
if( !rscFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
qDebug() << "Unable to load resource \"" << rscName << "\".";
res += (char*) rscFile.map( 0, rscFile.size() );
}
return res;
}
protected:
/** Recover the current viewer to which this Displayable is associated. */
inline GLViewer* getViewer() const { return m_Viewer; }
inline bool shaderFromResources( GPU::Shader &shader,
const QString &vshResourceName,
const QString &fshResourceName,
std::string *logs = NULL )
std::string *logs = NULL ) const
{
return shaderFromResources( shader, QStringList(vshResourceName), QStringList(fshResourceName), logs );
}
inline bool shaderFromResources( GPU::Shader &shader,
const QStringList &vshResourceNames,
const QStringList &fshResourceNames,
std::string *logs = NULL ) const
{
QFile vshResource( vshResourceName );
QFile fshResource( fshResourceName );
return vshResource.open( QIODevice::ReadOnly | QIODevice::Text ) &&
fshResource.open( QIODevice::ReadOnly | QIODevice::Text ) &&
GPU::CreateShaderFromSources(
shader,
(char*) vshResource.map( 0, vshResource.size() ),
(char*) fshResource.map( 0, fshResource.size() ),
logs
);
std::string vshSrc = concatenateResourcesContent(vshResourceNames).toStdString();
std::string fshSrc = concatenateResourcesContent(fshResourceNames).toStdString();
return GPU::CreateShaderFromSources( shader, vshSrc, fshSrc, logs );
}
inline bool shaderFromResources( GPU::Shader &shader,
const QString &vshResourceName,
const QString &gshResourceName,
const QString &fshResourceName,
std::string *logs = NULL )
std::string *logs = NULL ) const
{
return shaderFromResources( shader, QStringList(vshResourceName), QStringList(gshResourceName), QStringList(fshResourceName), logs );
}
inline bool shaderFromResources( GPU::Shader &shader,
const QStringList &vshResourceNames,
const QStringList &gshResourceNames,
const QStringList &fshResourceNames,
std::string *logs = NULL ) const
{
QFile vshResource( vshResourceName );
QFile gshResource( gshResourceName );
QFile fshResource( fshResourceName );
return vshResource.open( QIODevice::ReadOnly | QIODevice::Text ) &&
gshResource.open( QIODevice::ReadOnly | QIODevice::Text ) &&
fshResource.open( QIODevice::ReadOnly | QIODevice::Text ) &&
GPU::CreateShaderFromSources(
shader,
(char*) vshResource.map( 0, vshResource.size() ),
(char*) gshResource.map( 0, gshResource.size() ),
(char*) fshResource.map( 0, fshResource.size() ),
logs
);
std::string vshSrc = concatenateResourcesContent(vshResourceNames).toStdString();
std::string gshSrc = concatenateResourcesContent(gshResourceNames).toStdString();
std::string fshSrc = concatenateResourcesContent(fshResourceNames).toStdString();
return GPU::CreateShaderFromSources( shader, vshSrc, gshSrc, fshSrc, logs );
}
public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment