示例#1
0
static GLuint
glw_compile_shader(const char *path, int type, glw_root_t *gr)
{
  GLint v, len;
  GLuint s;
  char log[4096];
  buf_t *b;

  if((b = fa_load(path,
                   FA_LOAD_VPATHS(gr->gr_vpaths),
                   FA_LOAD_ERRBUF(log, sizeof(log)),
                   NULL)) == NULL) {
    TRACE(TRACE_ERROR, "glw", "Unable to load shader %s -- %s",
	  path, log);
    return 0;
  }

  b = buf_make_writable(b);
  char *src = buf_str(b);
  s = glCreateShader(type);
  glShaderSource(s, 1, (const char **)&src, NULL);

  glCompileShader(s);
  glGetShaderInfoLog(s, sizeof(log), &len, log);
  glGetShaderiv(s, GL_COMPILE_STATUS, &v);

  buf_release(b);

  if(!v) {
    TRACE(TRACE_ERROR, "GLW", "Unable to compile shader %s", path);
    TRACE(TRACE_ERROR, "GLW", "%s", log);
    return 0;
  }
  return s;
}
示例#2
0
/**
 * Load a view file and do lexographical parsing
 *
 * Returns pointer to last token, or NULL if an error occured.
 * If an error occured 'ei' will be filled with data
 */
token_t *
glw_view_load1(glw_root_t *gr, rstr_t *url, errorinfo_t *ei, token_t *prev,
               int may_unlock)
{
  token_t *last;
  char errbuf[256];

  rstr_t *p = fa_absolute_path(url, prev->file);

  if(may_unlock)
    glw_unlock(gr);

  buf_t *b = fa_load(rstr_get(p),
                     FA_LOAD_VPATHS(gr->gr_vpaths),
                     FA_LOAD_ERRBUF(errbuf, sizeof(errbuf)),
                     NULL);

  if(may_unlock)
    glw_lock(gr);

  if(b == NULL) {
    snprintf(ei->error, sizeof(ei->error), "Unable to open \"%s\" -- %s",
	     rstr_get(p), errbuf);
    snprintf(ei->file,  sizeof(ei->file),  "%s", rstr_get(prev->file));
    ei->line = prev->line;
    rstr_release(p);
    return NULL;
  }

  last = glw_view_lexer(gr, buf_cstr(b), ei, p, prev);
  buf_release(b);
  rstr_release(p);
  return last;
}
示例#3
0
/**
 * Load entire image into memory using fileaccess load method.
 * Faster than open+read+close.
 */
static image_t *
fa_imageloader2(const char *url, const char **vpaths,
		char *errbuf, size_t errlen, int *cache_control,
                cancellable_t *c)
{
  buf_t *buf;

  buf = fa_load(url,
                FA_LOAD_VPATHS(vpaths),
                FA_LOAD_ERRBUF(errbuf, errlen),
                FA_LOAD_CACHE_CONTROL(cache_control),
                FA_LOAD_CANCELLABLE(c),
                FA_LOAD_FLAGS(FA_CONTENT_ON_ERROR),
                NULL);
  if(buf == NULL || buf == NOT_MODIFIED)
    return (image_t *)buf;

  image_t *img = fa_imageloader_buf(buf, errbuf, errlen);
  buf_release(buf);
  return img;
}
示例#4
0
/**
 * Load entire image into memory using fileaccess load method.
 * Faster than open+read+close.
 */
static pixmap_t *
fa_imageloader2(const char *url, const char **vpaths,
		char *errbuf, size_t errlen, int *cache_control,
                cancellable_t *c)
{
  buf_t *buf;
  jpeg_meminfo_t mi;
  pixmap_type_t fmt;
  int width = -1, height = -1, orientation = 0;

  buf = fa_load(url,
                 FA_LOAD_VPATHS(vpaths),
                 FA_LOAD_ERRBUF(errbuf, errlen),
                 FA_LOAD_CACHE_CONTROL(cache_control),
                 FA_LOAD_CANCELLABLE(c),
                 NULL);
  if(buf == NULL || buf == NOT_MODIFIED)
    return (pixmap_t *)buf;

  const uint8_t *p = buf_c8(buf);
  mi.data = p;
  mi.size = buf->b_size;

  if(buf->b_size < 16)
    goto bad;

  /* Probe format */

  if((p[6] == 'J' && p[7] == 'F' && p[8] == 'I' && p[9] == 'F') ||
     (p[6] == 'E' && p[7] == 'x' && p[8] == 'i' && p[9] == 'f')) {
      
    jpeginfo_t ji;
    
    if(jpeg_info(&ji, jpeginfo_mem_reader, &mi, 
		 JPEG_INFO_DIMENSIONS | JPEG_INFO_ORIENTATION,
		 p, buf->b_size, errbuf, errlen)) {
      buf_release(buf);
      return NULL;
    }

    fmt = PIXMAP_JPEG;

    width = ji.ji_width;
    height = ji.ji_height;
    orientation = ji.ji_orientation;

    jpeg_info_clear(&ji);

  } else if(!memcmp(pngsig, p, 8)) {
    fmt = PIXMAP_PNG;
  } else if(!memcmp(gif87sig, p, sizeof(gif87sig)) ||
	    !memcmp(gif89sig, p, sizeof(gif89sig))) {
    fmt = PIXMAP_GIF;
  } else if(!memcmp(svgsig1, p, sizeof(svgsig1)) ||
	    !memcmp(svgsig2, p, sizeof(svgsig2))) {
    fmt = PIXMAP_SVG;
  } else {
  bad:
    snprintf(errbuf, errlen, "Unknown format");
    buf_release(buf);
    return NULL;
  }

  pixmap_t *pm = pixmap_alloc_coded(p, buf->b_size, fmt);
  if(pm != NULL) {
    pm->pm_width = width;
    pm->pm_height = height;
    pm->pm_orientation = orientation;
  } else {
    snprintf(errbuf, errlen, "Out of memory");
  }
  buf_release(buf);
  return pm;
}