Esempio n. 1
0
texture_2d smooth_filter(const texture_2d& tfm, 
                         const texture_2d& img,
                         int type,
                         float sigma)
{
    texture_2d dst(tfm.clone_format());

    if (type == 3) {
        glsl_program glsl("lic_fs.glsl");
        glsl.use();
        glsl.bind_sampler("tfm", tfm);
        glsl.bind_sampler("img", img);
        glsl.set_uniform_1f("sigma", sigma);
        glsl.set_uniform_2f("img_size", (float)dst.get_width(), (float)dst.get_height());
        glsl.draw(&dst);
    } else {
        glsl_program gauss((type == 1)? "gauss3x3_fs.glsl" : "gauss5x5_fs.glsl");
        gauss.use();
        gauss.bind_sampler("img", img);
        gauss.set_uniform_2f("img_size", (float)dst.get_width(), (float)dst.get_height());
        gauss.draw(&dst);                  
    }
 
    return dst;
}
Esempio n. 2
0
texture_2d orientation_aligned_bilateral_filter(const texture_2d& src,
                                                const texture_2d& tfm, 
                                                int n, 
                                                float sigma_d,     
                                                float sigma_r) 
{
    texture_2d tmp(src.clone_format());
    texture_2d dst(src.clone_format());

    glsl_program glsl("bf_fs.glsl");
    glsl.use();
    glsl.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
    glsl.set_uniform_1f("sigma_d", sigma_d);
    glsl.set_uniform_1f("sigma_r", sigma_r);
    glsl.bind_sampler("tfm", tfm);

    for (int i = 0; i < n; ++i) {
        glsl.bind_sampler("img", (i == 0)? src : dst, GL_LINEAR);
        glsl.set_uniform_1i("pass", 0);
        glsl.draw(&tmp);

        glsl.bind_sampler("img", tmp, GL_LINEAR);
        glsl.set_uniform_1i("pass", 1);
        glsl.draw(&dst);
    }

    return dst;
}
Esempio n. 3
0
texture_2d lab2rgb(const texture_2d& src) {
    glsl_program glsl("lab2rgb_fs.glsl");
    texture_2d dst(src.clone_format());
    
    glsl.use();
    glsl.bind_sampler("img", src);
    glsl.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
    glsl.draw(&dst);
    return dst;
}
Esempio n. 4
0
texture_2d gauss_filter(const texture_2d& src, 
                        float sigma) 
{
    glsl_program glsl("gauss_fs.glsl");
    texture_2d dst(src.clone_format());
    
    glsl.use();
    glsl.bind_sampler("img", src);
    glsl.set_uniform_1f("sigma", sigma);
    glsl.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
    glsl.draw(&dst);
    return dst;
}
Esempio n. 5
0
void GLView::initializeGL() {
    #ifdef HAVE_QUICKTIME
    m_haveQuickTime = quicktime_init();
    if (!m_haveQuickTime) {
        QMessageBox::warning(NULL, "Warning", "<a href='http://www.apple.com/quicktime/download'>QuickTime 7 Pro</a> not found!<br>");
    }
    #endif

    if (!GLEE_VERSION_2_0 ||
		!GLEE_EXT_framebuffer_object ||
		!GLEE_ARB_texture_float ||
		!GLEE_ARB_texture_rectangle ||
		!GLEE_EXT_bgra) {
		QMessageBox::critical(this, "Error", "OpenGL 2.0 Graphics Card with EXT_framebuffer_object, ARB_texture_rectangle, ARB_texture_float and EXT_bgra required");
	}
	
	bool status = true;
    QDir glsl_dir(":/glsl");
    QFileInfoList glsl_list = glsl_dir.entryInfoList();
    for (int i = 0; i < glsl_list.size(); ++i) {
        QFileInfo fi = glsl_list[i];
        std::string fn = fi.fileName().toStdString();
        QFile f(fi.filePath());
        if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
            QMessageBox::critical(NULL, "Error", QString("Can't open %1").arg(fi.filePath()));
			exit(1);
        }

        #ifdef WIN32
            OutputDebugStringA(fn.c_str());
            OutputDebugStringA("\n");
        #else
            fprintf(stderr, "%s\n", fn.c_str());
        #endif

        QByteArray src = f.readAll();
        glsl_program glsl(fn.c_str(), true);
        glsl.attach_shader(GL_FRAGMENT_SHADER, src.constData());
        status &= glsl.link();
    }
    if (!status) {
        QMessageBox::critical(this, "Error", "Compiling/Linking shader failed!");
        qApp->quit();
    }

    glGenFramebuffersEXT(1, &m_fbo);

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
}
Esempio n. 6
0
texture_2d overlay(const texture_2d& edges, 
                   const texture_2d& img)
{
    texture_2d dst(edges.clone_format());

    glsl_program glsl("overlay_fs.glsl");
    glsl.use();
    glsl.bind_sampler("edges", edges);
    glsl.bind_sampler("img", img);
    glsl.set_uniform_2f("img_size", (float)dst.get_width(), (float)dst.get_height());
    glsl.draw(&dst);
 
    return dst;
}
Esempio n. 7
0
texture_2d mix_filter(const texture_2d& edges, 
                      const texture_2d& img, float edge_color[3])
{
    texture_2d dst(edges.clone_format());

    glsl_program glsl("mix_fs.glsl");
    glsl.use();
    glsl.bind_sampler("edges", edges);
    glsl.bind_sampler("img", img);
    glsl.set_uniform_2f("img_size", (float)dst.get_width(), (float)dst.get_height());
    glsl.set_uniform_3f("edge_color", edge_color[0], edge_color[1], edge_color[2]);
    glsl.draw(&dst);
 
    return dst;
}
Esempio n. 8
0
texture_2d lic_filter(const texture_2d& tfm, 
                      const texture_2d& img,
                      float sigma)
{
    texture_2d dst(tfm.clone_format());

    glsl_program glsl("lic_fs.glsl");
    glsl.use();
    glsl.bind_sampler("tfm", tfm);
    glsl.bind_sampler("img", img);
    glsl.set_uniform_1f("sigma", sigma);
    glsl.set_uniform_2f("img_size", (float)dst.get_width(), (float)dst.get_height());
    glsl.draw(&dst);
 
    return dst;
}
void ShaderManager::load(std::string assetId, std::string path) {
	auto it = cache_.find(assetId);
	if(it != cache_.end()) return;

	std::ifstream glsl(path);
	if(!glsl.is_open()) {
		xLOG[Util::LogType::ERROR]("ShaderManager :: load") << "failed to load shader: " << path << "\0";
		throw Util::RunTimeError(xLOG.prev());
	}
	std::string line;
	std::string code;
	while(getline(glsl, line))
		code += line + "\n";
	glsl.close();

	GLenum type;
	if(assetId.find(".vert") != std::string::npos)
		type = GL_VERTEX_SHADER;
	else if(assetId.find(".frag") != std::string::npos)
		type = GL_FRAGMENT_SHADER;
	else {
		xLOG[Util::LogType::SUCCESS]("ShaderManager :: load") << "unable to identify shader type: " << path << "\0";
		throw Util::RunTimeError(xLOG.prev());
	}
	unsigned int id = glCreateShader(type);

	char const *source = code.c_str();
	glShaderSource(id, 1, &source, 0);
	glCompileShader(id);

	int logLength;
	GLint compileStatus;
	glGetShaderiv(id, GL_COMPILE_STATUS, &compileStatus);
	if(!compileStatus) {
		glGetShaderiv(id, GL_INFO_LOG_LENGTH, &logLength);
		char log[logLength];
		glGetShaderInfoLog(id, logLength, 0, &log[0]);
        xLOG[Util::LogType::ERROR]("ShaderManager :: load") << assetId << " : " << std::string(log) << "\0";
		throw Util::RunTimeError(xLOG.prev());
	}

	cache_[assetId] = std::shared_ptr<Shader>(new Shader(type, id, code));
	xLOG[Util::LogType::SUCCESS]("ShaderManager :: load") << "successfully cached and compiled shader: " << path << "\0";
}
Esempio n. 10
0
/** 
 * Lookup for dbClassificationObj in cacheClassificationObj 
 * @note Used in context db->internaCache lookup (if found remove CACHE_INTERNAL_ONLY and set CACHE_BOTH flag)
 * 
 * @param iLookup 
 * @param iHead 
 * 
 * @return 
 * 0 NOT FOUND
 * 1 FOUND
 */
u_int32_t dbClassificationLookup(dbClassificationObj *iLookup,cacheClassificationObj *iHead)
{
    if( (iLookup == NULL))
    {
        /* XXX */
        FatalError("database [%s()], Called with dbReferenceObj[0x%x] cacheClassificationObj [0x%x] \n",
                   __FUNCTION__,
                   iLookup,
                   iHead);
    }
    
    if(iHead == NULL)
    {
	return 0;
    }
    
    while(iHead != NULL)
    {
	if( (strncasecmp(iLookup->sig_class_name,iHead->obj.sig_class_name,
			 glsl(iLookup->sig_class_name,iHead->obj.sig_class_name)) == 0))
	{
            /* Found */
	    if(  iHead->flag & CACHE_INTERNAL_ONLY)
            {
                iHead->flag ^= (CACHE_INTERNAL_ONLY | CACHE_BOTH);
            }
            else
            {
                iHead->flag ^= CACHE_BOTH;
            }
	    iHead->obj.db_sig_class_id = iLookup->db_sig_class_id;
            return 1;
        }
	
        iHead = iHead->next;
    }
    
    return 0;
}
Esempio n. 11
0
//-------------------------------------------------------------
// GLSupport::gl_init() initialize
//-------------------------------------------------------------
void GLSupport::gl_init()
{
	static int initialized=0;
	if(!initialized){
		const GLubyte *version=glGetString(GL_VERSION);
		const GLubyte *glsl_version=glGetString(GL_SHADING_LANGUAGE_VERSION);
		gl_version=10*(version[0]-'0');
		gl_version+=version[2]-'0';
		ARB_multitexture_supported=extensionSupported("GL_ARB_multitexture");
		ARB_texture_env_combine_supported=extensionSupported("GL_ARB_texture_env_combine");
		ARB_texture_cube_map_supported=extensionSupported("GL_ARB_texture_cube_map");
		ARB_texture_env_dot3_supported=extensionSupported("GL_ARB_texture_env_dot3");
		ARB_shading_language_100_supported=extensionSupported("GL_ARB_shading_language_100");
		ARB_shader_objects_supported=extensionSupported("GL_ARB_shader_objects");
		EXT_framebuffer_object_supported=extensionSupported("GL_EXT_framebuffer_object");
		ARB_geometry_shader4_supported=extensionSupported("GL_ARB_geometry_shader4");
		printf("OGL  version : %s (%d)\n",version,gl_version);
		printf("GLSL version : %s \n",glsl_version);
#ifdef SHOW_ALL_EXTENSIONS
		const GLubyte *exts=glGetString(GL_EXTENSIONS);
        printf("%s\n",exts);
#endif
		initialized=1;
	}

	setContext();

	// make white texture for ogl1.1 specular pass
	//if(gl_version==11){
	//	glGenTextures (1, &white_texture);
	//	glBindTexture (GL_TEXTURE_2D, white_texture);
	//}
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	//glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST );
	//glHint(GL_POINT_SMOOTH_HINT, GL_NICEST );

	//glPolygonOffset(0.1,1);
	//glEnable(GL_POLYGON_OFFSET_FILL);
	int auxbufs=0;

	glGetIntegerv(GL_SAMPLE_BUFFERS_ARB,&auxbufs);

	//glEnable(GL_POLYGON_SMOOTH);
 	//glEnable(GL_NORMALIZE);

   // unsigned char pixels[2*2*4];
    //memset (pixels, 0xff, 2*2*4);
    //glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 2, 2,
     //             0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

	txchnls=1;
	if(multiTextures()){
#ifdef GL_MAX_TEXTURE_UNITS_ARB
		glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB,&txchnls);
#else
#ifdef GL_MAX_ACTIVE_TEXTURES_ARB
		glGetIntegerv(GL_MAX_ACTIVE_TEXTURES_ARB,&txchnls);
#endif
#endif
	    printf("max multi-texture channels = %d\n",txchnls);
	}
	else
		printf(" multi-textures support disabled\n");

	if(glsl()){
		printf("GLSL supported\n");
		if(geometry_shader())
			printf("Geometry shader supported\n");
		else
			printf("Geometry shader NOT supported\n");
		if(renderTextures())
			printf("Render to Texture supported\n");
		else
			printf("Render to Texture NOT supported\n");
	}
	else
		printf("GLSL NOT supported\n");

	set_spectex(1);
}
void GpuProgramManager::reflectPipelineLayout(
    uint32_t p_PoolCount, const Dod::RefArray& p_GpuPrograms,
    Dod::Ref p_PipelineLayoutToInit)
{

  _INTR_ARRAY(BindingDescription) bindingDecs;

  for (uint32_t i = 0u; i < p_GpuPrograms.size(); ++i)
  {
    GpuProgramRef gpuProgramRef = p_GpuPrograms[i];

    spirv_cross::CompilerGLSL glsl(
        GpuProgramManager::_spirvBuffer(gpuProgramRef));
    spirv_cross::ShaderResources resources = glsl.get_shader_resources();

    // Uniform buffers
    for (uint32_t i = 0u; i < resources.uniform_buffers.size(); ++i)
    {
      spirv_cross::Resource& res = resources.uniform_buffers[i];

      if (glsl.get_decoration(res.id, spv::DecorationDescriptorSet) != 0u)
        continue;

      const bool isDynamic = res.name == "PerInstance" ||
                             res.name == "PerMaterial" ||
                             res.name == "PerFrame";

      BindingDescription bd;
      {
        bd.name = res.name.c_str();
        bd.bindingType = isDynamic ? BindingType::kUniformBufferDynamic
                                   : BindingType::kUniformBuffer;
        bd.binding = glsl.get_decoration(res.id, spv::DecorationBinding);
        bd.poolCount = p_PoolCount;
        bd.shaderStage = GpuProgramManager::_descGpuProgramType(gpuProgramRef);
      }

      bindingDecs.push_back(bd);
    }

    // Images
    for (uint32_t i = 0u; i < resources.sampled_images.size(); ++i)
    {
      spirv_cross::Resource& res = resources.sampled_images[i];

      if (glsl.get_decoration(res.id, spv::DecorationDescriptorSet) != 0u)
        continue;

      BindingDescription bd;
      {
        bd.name = res.name.c_str();
        bd.bindingType = BindingType::kImageAndSamplerCombined;
        bd.binding = glsl.get_decoration(res.id, spv::DecorationBinding);
        bd.poolCount = p_PoolCount;
        bd.shaderStage = GpuProgramManager::_descGpuProgramType(gpuProgramRef);
      }

      bindingDecs.push_back(bd);
    }

    // Storage Images
    for (uint32_t i = 0u; i < resources.storage_images.size(); ++i)
    {
      spirv_cross::Resource& res = resources.storage_images[i];

      if (glsl.get_decoration(res.id, spv::DecorationDescriptorSet) != 0u)
        continue;

      BindingDescription bd;
      {
        bd.name = res.name.c_str();
        bd.bindingType = BindingType::kStorageImage;
        bd.binding = glsl.get_decoration(res.id, spv::DecorationBinding);
        bd.poolCount = p_PoolCount;
        bd.shaderStage = GpuProgramManager::_descGpuProgramType(gpuProgramRef);
      }

      bindingDecs.push_back(bd);
    }

    // Storage Buffers
    for (uint32_t i = 0u; i < resources.storage_buffers.size(); ++i)
    {
      spirv_cross::Resource& res = resources.storage_buffers[i];

      if (glsl.get_decoration(res.id, spv::DecorationDescriptorSet) != 0u)
        continue;

      BindingDescription bd;
      {
        bd.name = res.name.c_str();
        bd.bindingType = BindingType::kStorageBuffer;
        bd.binding = glsl.get_decoration(res.id, spv::DecorationBinding);
        bd.poolCount = p_PoolCount;
        bd.shaderStage = GpuProgramManager::_descGpuProgramType(gpuProgramRef);
      }

      bindingDecs.push_back(bd);
    }
  }

  std::sort(bindingDecs.begin(), bindingDecs.end(),
            [](const BindingDescription& p_Left,
               const BindingDescription& p_Right) -> bool {
              return p_Left.binding < p_Right.binding;
            });

  PipelineLayoutManager::_descBindingDescs(p_PipelineLayoutToInit) =
      std::move(bindingDecs);
}