1 /****************************************************************************
2 * MeshLab o o *
3 * A versatile mesh processing toolbox o o *
4 * _ O _ *
5 * Copyright(C) 2005 \/)\/ *
6 * Visual Computing Lab /\/| *
7 * ISTI - Italian National Research Council | *
8 * \ *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20 * for more details. *
21 * *
22 ****************************************************************************/
23
24 #include "utils.h"
25 #include <QFile>
26 #include <iostream>
27
28
29
30
resourceContent(const std::string & filename)31 std::string resourceContent( const std::string& filename )
32 {
33 std::string content;
34
35 QFile file( QString::fromStdString(filename) );
36 if( file.open(QIODevice::ReadOnly) )
37 {
38 unsigned char *filemap = file.map( 0, file.size() );
39 content = std::string( (char*)filemap );
40 file.unmap( filemap );
41 file.close();
42 }
43
44 return content;
45 }
46
47
loadShader(GPU::Shader & shader,const std::string & basename,std::string * logs)48 bool loadShader( GPU::Shader& shader,
49 const std::string& basename,
50 std::string *logs )
51 {
52 GPU::Shader::VertPg vpg;
53 GPU::Shader::FragPg fpg;
54
55 return vpg.CompileSrcString( resourceContent(":/shaders/"+basename+".vert").c_str(), logs ) &&
56 fpg.CompileSrcString( resourceContent(":/shaders/"+basename+".frag").c_str(), logs ) &&
57 shader.Attach( vpg ).AttachAndLink( fpg, logs );
58 }
59