Beispiel #1
0
/*
	This method generates all the shaders
*/
u32 ShaderSource::getShaderIdDirect(const std::string &name)
{
	//infostream<<"getShaderIdDirect(): name=\""<<name<<"\""<<std::endl;

	// Empty name means shader 0
	if(name == ""){
		infostream<<"getShaderIdDirect(): name is empty"<<std::endl;
		return 0;
	}

	/*
		Calling only allowed from main thread
	*/
	if(get_current_thread_id() != m_main_thread){
		errorstream<<"ShaderSource::getShaderIdDirect() "
				"called not from main thread"<<std::endl;
		return 0;
	}

	/*
		See if shader already exists
	*/
	{
		JMutexAutoLock lock(m_shaderinfo_cache_mutex);

		std::map<std::string, u32>::iterator n;
		n = m_name_to_id.find(name);
		if(n != m_name_to_id.end()){
			/*infostream<<"getShaderIdDirect(): \""<<name
					<<"\" found in cache"<<std::endl;*/
			return n->second;
		}
	}

	/*infostream<<"getShaderIdDirect(): \""<<name
			<<"\" NOT found in cache. Creating it."<<std::endl;*/

	ShaderInfo info = generate_shader(name, m_device,
			m_shader_callback, &m_sourcecache);

	/*
		Add shader to caches (add dummy shaders too)
	*/

	JMutexAutoLock lock(m_shaderinfo_cache_mutex);

	u32 id = m_shaderinfo_cache.size();
	m_shaderinfo_cache.push_back(info);
	m_name_to_id[name] = id;

	/*infostream<<"getShaderIdDirect(): "
			<<"Returning id="<<id<<" for name \""<<name<<"\""<<std::endl;*/

	return id;
}
Beispiel #2
0
void
piglit_init(int argc, char **argv)
{
    unsigned i;
    float v[TEST_COLS * 3 ];

    (void) argc;
    (void) argv;

    piglit_require_fragment_program();
    piglit_require_extension("GL_NV_fragment_program_option");
    piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

    reference_prog = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB,
                                            reference_shader_source);

    glClearColor(1.0, 1.0, 1.0, 1.0);

    for (i = 0; i < ARRAY_SIZE(types); i++) {
        generate_shader(types[i]);
        progs[i] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB,
                                          shader_source);
    }


    /* Generate the possible color values.
     */
    for (i = 0; i <= 127; i++) {
        v[i] = ((float) i) / 127.0;
    }

    for (/* empty */; i < ARRAY_SIZE(v); i++) {
        v[i] = 0.5;
    }


    /* Shuffle the values into random order.  Generate the color data
     * used by the tests from the shuffled values.
     */
    shuffle(v, 128);
    for (i = 0; i < TEST_COLS; i++) {
        assert((i * 3) + 2 < ARRAY_SIZE(v));

        colors[i][0] = v[(i * 3) + 0];
        colors[i][1] = v[(i * 3) + 1];
        colors[i][2] = v[(i * 3) + 2];
        colors[i][3] = 1.0;
    }
}
Beispiel #3
0
/*
	This method generates all the shaders
*/
u32 ShaderSource::getShaderIdDirect(const std::string &name,
		const u8 material_type, const u8 drawtype)
{
	//infostream<<"getShaderIdDirect(): name=\""<<name<<"\""<<std::endl;

	// Empty name means shader 0
	if(name == ""){
		infostream<<"getShaderIdDirect(): name is empty"<<std::endl;
		return 0;
	}

	// Check if already have such instance
	for(u32 i=0; i<m_shaderinfo_cache.size(); i++){
		ShaderInfo *info = &m_shaderinfo_cache[i];
		if(info->name == name && info->material_type == material_type &&
			info->drawtype == drawtype)
			return i;
	}

	/*
		Calling only allowed from main thread
	*/
	if (!thr_is_current_thread(m_main_thread)) {
		errorstream<<"ShaderSource::getShaderIdDirect() "
				"called not from main thread"<<std::endl;
		return 0;
	}

	ShaderInfo info = generate_shader(name, material_type, drawtype, m_device,
			m_shader_callback, &m_sourcecache);

	/*
		Add shader to caches (add dummy shaders too)
	*/

	MutexAutoLock lock(m_shaderinfo_cache_mutex);

	u32 id = m_shaderinfo_cache.size();
	m_shaderinfo_cache.push_back(info);

	infostream<<"getShaderIdDirect(): "
			<<"Returning id="<<id<<" for name \""<<name<<"\""<<std::endl;

	return id;
}
Beispiel #4
0
void ShaderSource::rebuildShaders()
{
	JMutexAutoLock lock(m_shaderinfo_cache_mutex);

	/*// Oh well... just clear everything, they'll load sometime.
	m_shaderinfo_cache.clear();
	m_name_to_id.clear();*/

	/*
		FIXME: Old shader materials can't be deleted in Irrlicht,
		or can they?
		(This would be nice to do in the destructor too)
	*/

	// Recreate shaders
	for(u32 i=0; i<m_shaderinfo_cache.size(); i++){
		ShaderInfo *info = &m_shaderinfo_cache[i];
		*info = generate_shader(info->name, m_device,
				m_shader_callback, &m_sourcecache);
	}
}
Beispiel #5
0
void ShaderSource::rebuildShaders()
{
	MutexAutoLock lock(m_shaderinfo_cache_mutex);

	/*// Oh well... just clear everything, they'll load sometime.
	m_shaderinfo_cache.clear();
	m_name_to_id.clear();*/

	/*
		FIXME: Old shader materials can't be deleted in Irrlicht,
		or can they?
		(This would be nice to do in the destructor too)
	*/

	// Recreate shaders
	for (ShaderInfo &i : m_shaderinfo_cache) {
		ShaderInfo *info = &i;
		if (!info->name.empty()) {
			*info = generate_shader(info->name, info->material_type,
					info->drawtype, m_callbacks,
					m_setter_factories, &m_sourcecache);
		}
	}
}