コード例 #1
0
ファイル: Shader.cpp プロジェクト: prknndy/french-fry
bool Shader::CreateShader(const char* vertFilename, const char* fragFilename)
{
    LogDebug("Creating Shader:");
    LogDebug(fragFilename);
    
    shaderProgram = glCreateProgram();
    
    GLuint vertexShader = AddProgram(GL_VERTEX_SHADER, vertFilename);
    
    if (vertexShader == INVALID_OGL_VALUE)
    {
        return false;
    }
    
    GLuint fragShader = AddProgram(GL_FRAGMENT_SHADER, fragFilename);
    
    if (fragShader == INVALID_OGL_VALUE)
    {
        glDeleteShader(vertexShader);
        return false;
    }
    
    if (!CompileShader())
    {
        glDeleteShader(vertexShader);
        glDeleteShader(fragShader);
        return false;
    }
    
    glDeleteShader(vertexShader);
    glDeleteShader(fragShader);
    
    return Init();
}
コード例 #2
0
ファイル: program_storage_impl.cpp プロジェクト: BTML/colobot
void CProgramStorageObjectImpl::LoadAllProgramsForLevel(CLevelParserLine* levelSource, const std::string& userSource, bool loadSoluce)
{
    int run = levelSource->GetParam("run")->AsInt(0)-1;
    bool allFilled = true;
    for (int i = 0; i < 10 || allFilled; i++)
    {
        std::string op = "script" + StrUtils::ToString<int>(i+1); // script1..script10
        std::string opReadOnly = "scriptReadOnly" + StrUtils::ToString<int>(i+1); // scriptReadOnly1..scriptReadOnly10
        std::string opRunnable = "scriptRunnable" + StrUtils::ToString<int>(i+1); // scriptRunnable1..scriptRunnable10
        if (levelSource->GetParam(op)->IsDefined())
        {
            std::string filename = levelSource->GetParam(op)->AsPath("ai");
            GetLogger()->Trace("Loading program '%s' from level file\n", filename.c_str());
            Program* program = AddProgram();
            ReadProgram(program, filename);
            program->readOnly = levelSource->GetParam(opReadOnly)->AsBool(true);
            program->runnable = levelSource->GetParam(opRunnable)->AsBool(true);
            program->filename = levelSource->GetParam(op)->AsString();

            if (m_object->Implements(ObjectInterfaceType::Programmable) && i == run)
            {
                dynamic_cast<CProgrammableObject*>(m_object)->RunProgram(program);
            }
        }
        else
        {
            allFilled = false;
        }
    }

    if (loadSoluce && levelSource->GetParam("soluce")->IsDefined())
    {
        std::string filename = levelSource->GetParam("soluce")->AsPath("ai");
        GetLogger()->Trace("Loading program '%s' as soluce file\n", filename.c_str());
        Program* program = AddProgram();
        ReadProgram(program, filename);
        program->readOnly = true;
        program->runnable = false;
        program->filename = levelSource->GetParam("soluce")->AsString();
    }

    if (m_programStorageIndex >= 0)
    {
        GetLogger()->Debug("Loading user programs from '%s%.3d___.txt'\n", userSource.c_str(), m_programStorageIndex);
        for (unsigned int i = 0; i <= 999; i++)
        {
            std::string filename = userSource + StrUtils::Format("%.3d%.3d.txt", m_programStorageIndex, i);
            if (CResourceManager::Exists(filename))
            {
                Program* program = GetOrAddProgram(i);
                if(GetCompile(program)) program = AddProgram(); // If original slot is already used, get a new one
                GetLogger()->Trace("Loading program '%s' from user directory\n", filename.c_str());
                ReadProgram(program, filename);
            }
        }
    }
}
コード例 #3
0
ファイル: program_storage_impl.cpp プロジェクト: BTML/colobot
Program* CProgramStorageObjectImpl::GetOrAddProgram(int index)
{
    if(index < 0)
        return nullptr;

    if(index < static_cast<int>(m_program.size()))
        return m_program[index].get();

    for(int i = m_program.size(); i < index; i++)
    {
        AddProgram();
    }
    return AddProgram();
}
コード例 #4
0
ファイル: Firewall.cpp プロジェクト: lemonxiao0/peerproject
// Takes a path and file name like "C:\Folder\Program.exe" and a name like "My Program"
// Makes sure the program is listed in Windows Firewall and its listing is checked, adding and checking it as necessary
// Returns true if the program is listed and checked, false if we weren't able to do it
// When bRemove is TRUE, it removes the application from the exception list
BOOL CFirewall::SetupProgram( const CString& path, const CString& name, BOOL bRemove )
{
	// Make sure the COM interfaces have been accessed
	//if ( ! FwManager ) return FALSE;

	// If the program isn't on the Windows Firewall exceptions list
	BOOL bListed = FALSE;
	if ( ! IsProgramListed( path, &bListed ) ) return FALSE;
	if ( ! bListed && ! bRemove )
	{
		// Add it to the list with a checked checkbox
		if ( ! AddProgram( path, name ) ) return FALSE;
	}
	else if ( bListed && bRemove )
	{
		if ( ! RemoveProgram( path ) ) return FALSE;
		return TRUE;
	}

	// If the program is on the list, but its checkbox isn't checked
	BOOL bEnabled = FALSE;
	if ( ! IsProgramEnabled( path, &bEnabled ) ) return FALSE;
	if ( ! bEnabled )
	{
		// Check the checkbox
		if ( ! EnableProgram( path ) ) return FALSE;
	}

	// The program is listed and checked
	return TRUE;
}
コード例 #5
0
ファイル: shaderset.cpp プロジェクト: tbutkie/VRSonarCleaner
GLuint* ShaderSet::AddProgramFromExts(const std::vector<std::string>& shaders)
{
    std::vector<std::pair<std::string, GLenum>> typedShaders;
    for (const std::string& shader : shaders)
    {
        size_t extLoc = shader.find_last_of('.');
        if (extLoc == std::string::npos)
        {
            return nullptr;
        }

        GLenum shaderType;

        std::string ext = shader.substr(extLoc + 1);
        if (ext == "vert")
            shaderType = GL_VERTEX_SHADER;
        else if (ext == "frag")
            shaderType = GL_FRAGMENT_SHADER;
        else if (ext == "geom")
            shaderType = GL_GEOMETRY_SHADER;
        else if (ext == "tesc")
            shaderType = GL_TESS_CONTROL_SHADER;
        else if (ext == "tese")
            shaderType = GL_TESS_EVALUATION_SHADER;
        else if (ext == "comp")
            shaderType = GL_COMPUTE_SHADER;
        else
            return nullptr;

        typedShaders.emplace_back(shader, shaderType);
    }

    return AddProgram(typedShaders);
}
コード例 #6
0
ファイル: programsmodel.cpp プロジェクト: eriser/vstboard-1
bool ProgramsModel::GroupFromStream( QDataStream &stream, const QModelIndex &grpIndex)
{
    QString name;
    stream >> name;
    itemFromIndex(grpIndex)->setText(name);

    //send the group data to the host
    int groupId = grpIndex.data(ProgramId).toInt();
    myHost->groupContainer->ProgramFromStream( groupId, stream );
    myHost->mainWindow->mySceneView->viewGroup->ProgramFromStream( groupId, stream );

    //add the programs
    QByteArray programs;
    stream >> programs;
    QDataStream streamProgs( &programs, QIODevice::ReadOnly);
    int i=0;
    while(!streamProgs.atEnd()) {

        QModelIndex prgIndex;
        if(!AddProgram(grpIndex.row(),prgIndex,i))
            return false;

        if( !ProgramFromStream(streamProgs, prgIndex) )
            return false;
        ++i;
    }
    return true;
}
コード例 #7
0
ファイル: program.cpp プロジェクト: holland01/YAQ3R
gProgramHandle_t GStoreProgram( Program* p )
{
	if ( !p )
	{
		return { G_UNSPECIFIED };
	}

	return AddProgram( p );
}
コード例 #8
0
ファイル: shaderset.cpp プロジェクト: tbutkie/VRSonarCleaner
GLuint* ShaderSet::AddProgramFromCombinedFile(const std::string &filename, const std::vector<GLenum> &shaderTypes)
{
    std::vector<std::pair<std::string, GLenum>> typedShaders;

    for (auto type: shaderTypes)
        typedShaders.emplace_back(filename, type);

    return AddProgram(typedShaders);
}
コード例 #9
0
void OCL_Environment::Initialize()
{
	InitOpenCL();

	// Add programs
	AddProgram(
		CreateProgram<VectorAddProgram> (m_context, m_deviceId, "vector_add_kernel.cl")
	);

}
コード例 #10
0
ファイル: program_storage_impl.cpp プロジェクト: BTML/colobot
Program* CProgramStorageObjectImpl::AddProgram()
{
    assert(m_object->Implements(ObjectInterfaceType::Old)); //TODO
    auto program = MakeUnique<Program>();
    program->script = MakeUnique<CScript>(dynamic_cast<COldObject*>(this));

    Program* prog = program.get();
    AddProgram(std::move(program));
    return prog;
}
コード例 #11
0
ファイル: program_storage_impl.cpp プロジェクト: BTML/colobot
Program* CProgramStorageObjectImpl::CloneProgram(Program* program)
{
    Program* newprog = AddProgram();

    // TODO: Is there any reason CScript doesn't have a function to get the program code directly?
    auto edit = MakeUnique<Ui::CEdit>();
    edit->SetMaxChar(Ui::EDITSTUDIOMAX);
    program->script->PutScript(edit.get(), "");
    newprog->script->GetScript(edit.get());

    return newprog;
}
コード例 #12
0
ファイル: FCGLShaderManager.cpp プロジェクト: chenze4949/FC
FCGLShaderProgramRef FCGLShaderManager::ActivateShader( std::string name )
{
	FCGLShaderProgramRefMapByStringIter i = m_programs.find( name );
	
	if(i == m_programs.end())
	{
		AddProgram(name, name);
		i = m_programs.find( name );
	}
	i->second->Use();
	
	return i->second;
}
コード例 #13
0
ファイル: programsmodel.cpp プロジェクト: eriser/vstboard-1
bool ProgramsModel::GroupFromStreamWithPrograms( QDataStream &stream, const QModelIndex &grpIndex)
{
    if(!GroupFromStream(stream,grpIndex))
        return false;

    //add the programs
    QByteArray programs;
    stream >> programs;
    QDataStream streamProgs( &programs, QIODevice::ReadOnly);
    int i=0;
    while(!streamProgs.atEnd()) {

        QModelIndex prgIndex;
        if(!AddProgram(grpIndex.row(),prgIndex,i))
            return false;

        if( !ProgramFromStream(streamProgs, prgIndex) )
            return false;
        ++i;
    }
    return true;
}
コード例 #14
0
ファイル: shader.cpp プロジェクト: BennyQBD/3DEngineCpp
void ShaderData::AddVertexShader(const std::string& text)
{
	AddProgram(text, GL_VERTEX_SHADER);
}
コード例 #15
0
void _AmProgramEntry::Merge(const _AmProgramEntry &o)
{
	for (uint32 k = 0; k < o.programs.size(); k++)
		AddProgram( o.programs[k] );
}
コード例 #16
0
ファイル: shader.cpp プロジェクト: BennyQBD/3DEngineCpp
void ShaderData::AddGeometryShader(const std::string& text)
{
	AddProgram(text, GL_GEOMETRY_SHADER);
}
コード例 #17
0
ファイル: shader.cpp プロジェクト: BennyQBD/3DEngineCpp
void ShaderData::AddFragmentShader(const std::string& text)
{
	AddProgram(text, GL_FRAGMENT_SHADER);
}
コード例 #18
0
bool OGLSpotLight::Init(int windowWidth, int windowHeight)
{
    bool res = gs::Stage::Init(windowWidth, windowHeight);
    if (!res) {
        return false;
    }

    cubePositions.resize(10);

    res &= InitGUI();

    // Init Camera
    camera.SetPosition(glm::vec3(0, 0, 50));
    camera.SetSpeed(15.0f);
    camera.SetupProjection(45.0f, windowWidth / (float)windowHeight);

    // Init light
    InitLight();

    // Init materials
    InitCubePosition();

    // Init program
    res &= AddProgram("mesh.vert", "spotLight.frag");
    auto program = programs[0];

    // Get uniform locations
    res &= AddLightUniform(program.get());
    res &= AddMatricesUniform(program.get());
    res &= program->AddUniform("material.shininess");
    res &= program->AddUniform("samplerDiffuse1");
    program->AddUniform("samplerDiffuse2");
    program->AddUniform("samplerDiffuse3");
    program->AddUniform("samplerSpecular1");
    program->AddUniform("samplerSpecular2");

    glUniform1i(program->GetUniform("samplerDiffuse1"), 0);
    glUniform1i(program->GetUniform("samplerDiffuse2"), 1);
    glUniform1i(program->GetUniform("samplerDiffuse3"), 2);
    glUniform1i(program->GetUniform("samplerSpecular1"), 3);
    glUniform1i(program->GetUniform("samplerSpecular2"), 4);

    // Init geometry
    auto vao = std::make_unique<gs::VertexArray>();
    vao->BindVAO();

    auto vbo = std::make_unique<gs::VertexBuffer>(GL_ARRAY_BUFFER);
    vbo->BindVBO();
    OGLCube cube;
    auto& vertices = cube.GetVertices();
    cube.InitVertices(glm::vec3(0));
    glBufferData(vbo->GetTarget(), sizeof(gs::Vertex) * vertices.size(), vertices.data(), GL_STATIC_DRAW);
    vbos.push_back(std::move(vbo));

    vao->AddAttribute(0, 3, GL_FLOAT, GL_FALSE, sizeof(gs::Vertex), 0);
    vao->AddAttribute(1, 2, GL_FLOAT, GL_FALSE, sizeof(gs::Vertex), (void*)offsetof(gs::Vertex, texCoords));
    vao->AddAttribute(2, 3, GL_FLOAT, GL_FALSE, sizeof(gs::Vertex), (void*)offsetof(gs::Vertex, normal));
    vaos.push_back(std::move(vao));

    auto diffuse = std::make_unique<gs::Texture>(IMAGE_TYPE::GLI);
    diffuse->SetContribution(LIGHT_CONTRIBUTION::DIFFUSE);
    res &= diffuse->LoadTexture("containerDiffuse.dds");
    diffuse->BindTexture(GL_TEXTURE0);
    textures.push_back(std::move(diffuse));

    auto specular = std::make_unique<gs::Texture>(IMAGE_TYPE::GLI);
    specular->SetContribution(LIGHT_CONTRIBUTION::DIFFUSE);
    res &= specular->LoadTexture("containerSpecular.dds");
    specular->BindTexture(GL_TEXTURE3);
    textures.push_back(std::move(specular));

    glEnable(GL_DEPTH_TEST);
    res = true;
    return res;
}