SafeShader::SafeShader( ci::DataSourceRef vertexShader, ci::DataSourceRef fragmentShader, ci::DataSourceRef geometryShader, GLint geometryInputType, GLint geometryOutputType, GLint geometryOutputVertices) { try { mObj = shared_ptr<Obj>( new Obj ); mObj->mHandle = glCreateProgram(); if ( vertexShader ) loadShader( vertexShader->getBuffer(), GL_VERTEX_SHADER_ARB ); if( fragmentShader ) loadShader( fragmentShader->getBuffer(), GL_FRAGMENT_SHADER_ARB ); if( geometryShader ) { loadShader( geometryShader->getBuffer(), GL_GEOMETRY_SHADER_EXT ); glProgramParameteriEXT(mObj->mHandle, GL_GEOMETRY_INPUT_TYPE_EXT, geometryInputType); glProgramParameteriEXT(mObj->mHandle, GL_GEOMETRY_OUTPUT_TYPE_EXT, geometryOutputType); glProgramParameteriEXT(mObj->mHandle, GL_GEOMETRY_VERTICES_OUT_EXT, geometryOutputVertices); } link(); } catch( gl::GlslProgCompileExc exc ){ cout << exc.what() << endl; } }
std::map<std::string, std::string> splitShaderSource(ci::DataSourceRef source) { using namespace std; ci::Buffer buffer = source->getBuffer(); string str(static_cast<char*>(buffer.getData()), buffer.getDataSize()); string del("---"); vector<string> splitted; split(str, del, insert_iterator<vector<string> >(splitted, splitted.begin())); \ vector<string>::iterator it = splitted.begin(); ++it; // skip header map<string, string> sources; for(; it != splitted.end(); ++it) { string key(*it); ++it; string value(*it); sources.insert( pair<string, string>(key, value) ); // printf("key '%s' '%s'", key.c_str(), value.c_str()); } return sources; }
void License::setKey( ci::DataSourceRef dataSource ) { Buffer buf = dataSource->getBuffer(); size_t dataSize = buf.getDataSize(); shared_ptr<char> bufString( new char[dataSize+1], checked_array_deleter<char>() ); memcpy( bufString.get(), buf.getData(), buf.getDataSize() ); bufString.get()[dataSize] = 0; string publicKey( bufString.get() ); mPublicKey = publicKey; }
void Shader::loadShader( ci::DataSourceRef shaderSourceRef, GLint shaderType, GLint geometryInputType, GLint geometryOutputType, GLint geometryOutputVertices ) { if( shaderSourceRef ){ mSource[shaderType] = shaderSourceRef; mLastTime[shaderType] = ci::fs::last_write_time( shaderSourceRef->getFilePath() ); GlslProg::loadShader( shaderSourceRef->getBuffer(), shaderType ); if( shaderType == GL_GEOMETRY_SHADER_EXT ){ glProgramParameteriEXT(mObj->mHandle, GL_GEOMETRY_INPUT_TYPE_EXT, geometryInputType); glProgramParameteriEXT(mObj->mHandle, GL_GEOMETRY_OUTPUT_TYPE_EXT, geometryOutputType); glProgramParameteriEXT(mObj->mHandle, GL_GEOMETRY_VERTICES_OUT_EXT, geometryOutputVertices); mGeometryData = GeomData( geometryInputType, geometryOutputType, geometryOutputVertices ); } } }