// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
void GfxTexture::SaveTGA( const char* fname )
{
	FILE *file_TGA = fopen( fname, "wb");

	if (file_TGA != NULL)
		{
		int nSize = Width * Height * (IsRGBA ? 4 : 1);
		void *buf_image = malloc( nSize );
		
		if (buf_image != NULL)
			{
			glBindFramebuffer(GL_FRAMEBUFFER,FramebufferId);
			check_gl();
			glReadPixels(0,0,Width,Height,IsRGBA ? GL_RGBA : GL_LUMINANCE, GL_UNSIGNED_BYTE, buf_image);
			check_gl();
			glBindFramebuffer(GL_FRAMEBUFFER,0);

			raspitexutil_brga_to_rgba( (uint8_t*) buf_image, nSize );
			write_tga( file_TGA, Width, Height, (uint8_t*) buf_image, nSize);

			free(buf_image);
			}
		
		fclose( file_TGA );
		}
}
Example #2
0
File: main.c Project: czaber/ogwm
void add(Window w) {
    XWindowAttributes attr;
	int i;
	if (w == root || w == overlay || w == canvas-1)
		return;

	debug("[AddWindow] Adding window 0x%x\n", w);

	if (workspace == NULL) {
		workspace = malloc(sizeof(Client) * MAX_CLIENTS);
		memset(workspace, 0, sizeof(Client) * MAX_CLIENTS);
	}

	for (i=0; i<MAX_CLIENTS && workspace[i].window != 0; i++)
		if (workspace[i].window == 0)
			break;
	
	unsigned int v;
    int target;
	GLuint texture;
	GLXFBConfig fbc = choose_fbconfig();
	Pixmap pixmap = XCompositeNameWindowPixmap(dpy, w);
    debug("Got pixmap 0x%x for 0x%x\n", pixmap, w);
    XGetWindowAttributes(dpy, w, &attr);
    if (attr.depth == 32)
        pixmap_attr[1] = GLX_TEXTURE_FORMAT_RGBA_EXT;
    else
        pixmap_attr[1] = GLX_TEXTURE_FORMAT_RGB_EXT;
	GLXPixmap glxpixmap = glXCreatePixmap(dpy, fbc, pixmap, pixmap_attr);
    debug("Got glxpixmap 0x%x for 0x%x\n", glxpixmap, pixmap);
	check_gl(__LINE__);
	glXQueryDrawable(dpy, glxpixmap, GLX_WIDTH, &v);
	check_gl(__LINE__); debug("GLX is %d width\n", v);
	glXQueryDrawable(dpy, glxpixmap, GLX_HEIGHT, &v);
	check_gl(__LINE__); debug("GLX is %d height\n", v);
    glXQueryDrawableProc(dpy, glxpixmap, GLX_TEXTURE_TARGET_EXT, &target);
	check_gl(__LINE__); debug("GLX is 0x%x\n", target);
	glGenTextures(1, &texture);
	check_gl(__LINE__);
	
	switch (target) {
		case GLX_TEXTURE_2D_EXT:
			warn("GLX_TEXTURE_2D_EXT requested but we don't support that yet\n");
			target = GL_TEXTURE_2D;
			break;
		case GLX_TEXTURE_RECTANGLE_EXT:
			target = GL_TEXTURE_RECTANGLE_ARB;
			break;
		default:
			die(ERR_INVALID_TEXTURE, "Invalid target: 0x%x\n", target);
	}

	info("Window 0x%x has glx = %x, target 0x%x and texture %d\n",
		w, glxpixmap, target, texture);
	workspace[i].window = w;
	workspace[i].glxpixmap = glxpixmap;
	workspace[i].target = target;
	workspace[i].texture = texture;
    XGetWindowAttributes(dpy, w, &(workspace[i].geom));
}
Example #3
0
File: main.c Project: czaber/ogwm
void setup_gl(void) {
	if (direct && !glXIsDirect(dpy, context))
		warn("Server doesn't support direct rendering! Falling back to indirect.\n");
	direct = glXIsDirect(dpy, context); check_gl(__LINE__);
	if (direct) info("Using direct rendering\n");
	else        info("Using indirect rendering\n");

	glEnable(GL_TEXTURE_RECTANGLE_ARB); check_gl(__LINE__);
	
	//glDrawBuffer(GL_BACK); check_gl(__LINE__);

	*(void**) (&glXQueryDrawableProc) = glXGetProcAddress((GLubyte*)"glXQueryDrawable");
	*(void**) (&glXBindTexImageProc) = glXGetProcAddress((GLubyte*)"glXBindTexImageEXT");
	*(void**) (&glXReleaseTexImageProc) = glXGetProcAddress((GLubyte*)"glXReleaseTexImageEXT");
	if (glXQueryDrawableProc == NULL)
        die(1, "No glXQueryDrawableProc\n");
	if (glXBindTexImageProc == NULL)
        die(1, "No glXBindTexImageProc\n");
	if (glXQueryDrawableProc == NULL)
        die(1, "No glXReleaseTexImageProc\n");
	XMapSubwindows(dpy, overlay);

    info("Defined viewport as %d, %d (ratio = %g)\n", width, height, ratio);
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glOrtho(0, width, height, 0, -2, 2);
    glMatrixMode(GL_MODELVIEW);
    //glOrtho(-1.0f, +1.0f, -1.0f*ratio, +1.0f*ratio, 1e-2f, 1e+4f);
    //for_windows(root, &print);
	//for_windows(root, &add);
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
int GfxTexture::GetImageLayer1( int &nSize, void **buf_image, int nLayer )		// memory is allocated
{
	int nReturn = 0;

	nSize = Width * Height * (IsRGBA ? 4 : 1);
	*buf_image = malloc( nSize );
	
	if (buf_image != NULL)
		{
		glBindFramebuffer(GL_FRAMEBUFFER,FramebufferId);
		check_gl();
		glReadPixels(0,0,Width,Height,IsRGBA ? GL_RGBA : GL_LUMINANCE, GL_UNSIGNED_BYTE, *buf_image);
		check_gl();
		glBindFramebuffer(GL_FRAMEBUFFER,0);
		
		// save only one layer -> result is grayscale image - size Width * Height * 1
		//
		if (raspitexutil_get_onelayer( (uint8_t*) *buf_image, nSize, nLayer ))
			{
			nSize = Width * Height * 1;	// for unknown reason must be each grayscale pixel 16bits long
			
			nReturn = 1;
			}
		
		if (nReturn == 0)	// some error -> erase memory
			{
			free(*buf_image);
			}
		}
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
void GfxTexture::SaveTGALayer2( const char* fname, void *buf_image, int nLayer )
{
	FILE *file_TGA = fopen( fname, "wb");

	if (file_TGA != NULL)
		{
		int nSize = Width * Height * (IsRGBA ? 4 : 1);
		
		if (buf_image != NULL)
			{
			glBindFramebuffer(GL_FRAMEBUFFER,FramebufferId);
			check_gl();
			glReadPixels(0,0,Width,Height,IsRGBA ? GL_RGBA : GL_LUMINANCE, GL_UNSIGNED_BYTE, buf_image);
			check_gl();
			glBindFramebuffer(GL_FRAMEBUFFER,0);
			
			// save only one layer -> result is grayscale image - size Width * Height * 1
			//
			if (raspitexutil_get_onelayer( (uint8_t*) buf_image, nSize, nLayer ))
				{
				int nNewSize = Width * Height * 1;
				write_tga_grayscale( file_TGA, Width, Height, (uint8_t*) buf_image, nNewSize );
				}
			}
		
		fclose( file_TGA );
		}
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
void GfxTexture::SetPixels(const void* data)
{
	glBindTexture(GL_TEXTURE_2D, Id);
	check_gl();
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, Width, Height, IsRGBA ? GL_RGBA : GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
	check_gl();
	glBindTexture(GL_TEXTURE_2D, 0);
	check_gl();
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
bool GfxTexture::GenerateFrameBuffer( )
{
	//Create a frame buffer that points to this texture
	glGenFramebuffers(1,&FramebufferId);
	check_gl();
	glBindFramebuffer(GL_FRAMEBUFFER,FramebufferId);
	check_gl();
	glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,Id,0);
	check_gl();
	glBindFramebuffer(GL_FRAMEBUFFER,0);
	check_gl();
	return true;
}
Example #8
0
  GeomProgram::GeomProgram () :
    vertex_shader   ("../Common/Shaders/Geom-Vertex.glsl",   GL_VERTEX_SHADER),
    fragment_shader ("../Common/Shaders/Geom-Fragment.glsl", GL_FRAGMENT_SHADER)
  {
    program.add_shader (vertex_shader);
    program.add_shader (fragment_shader);

    program.fix_attrib ("attrib_position", attrib_position);
    //program.fix_attrib ("attrib_normal",   attrib_normal);
    program.fix_attrib ("attrib_tcoords",  attrib_tcoords);
    program.fix_attrib ("attrib_colour",   attrib_colour);

    program.link ();

    program.use ();

    u32 tex_diffuse = program.link_uniform ("tex_diffuse");
    glUniform1i (tex_diffuse, texunit_diffuse);

    glVertexAttrib4f (attrib_colour, 1.0f, 1.0f, 1.0f, 1.0f);
    check_gl ("glVertexAttrib4f");

    program.done ();

    /*world_to_clip  = program.link_uniform ("world_to_clip");
    world_to_eye   = program.link_uniform ("world_to_eye");
    model_to_world = program.link_uniform ("model_to_world");*/
    model_to_clip  = program.link_uniform ("model_to_clip");
  }
// --------------------------------------------------------------------------------------------------------------------------------------------
//
void* GfxTexture::GetPixels( int &nSize )
{
	nSize = Width*Height*4;

	void *p_return_image = malloc( nSize );
	if (p_return_image != NULL)
		{
		glBindFramebuffer(GL_FRAMEBUFFER,FramebufferId);
		check_gl();
		glReadPixels(0,0,Width,Height,IsRGBA ? GL_RGBA : GL_LUMINANCE, GL_UNSIGNED_BYTE, p_return_image);
		check_gl();
		glBindFramebuffer(GL_FRAMEBUFFER,0);
		}
	
	return p_return_image;
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
bool GfxProgram::Create(GfxShader* vertex_shader, GfxShader* fragment_shader, const char *lpstrLocation )
{
	VertexShader = vertex_shader;
	FragmentShader = fragment_shader;

	m_Id = glCreateProgram();
	glAttachShader(m_Id, VertexShader->GetId());
	glAttachShader(m_Id, FragmentShader->GetId());
	glLinkProgram(m_Id);
	check_gl();
	printf("Created program id %d from vs %d and fs %d\n", m_Id, VertexShader->GetId(), FragmentShader->GetId());

	// Prints the information log for a program object
	char log[1024];
	glGetProgramInfoLog(m_Id,sizeof log,NULL,log);
	printf("%d:program:\n%s\n", m_Id, log);

	m_loc = 0;
	if (lpstrLocation != NULL)
		{
		GetAttribLocation( lpstrLocation );
		}

	return true;
}
// --------------------------------------------------------------------------------------------------------------------------------------------
//
bool GfxTexture::GetPixels( void *ptr_image, int nSize )
{
	bool bReturn =false;

	if (nSize == (Width * Height * (IsRGBA ? 4 : 1)))
		{
		glBindFramebuffer(GL_FRAMEBUFFER,FramebufferId);
		check_gl();
		glReadPixels(0,0,Width,Height,IsRGBA ? GL_RGBA : GL_LUMINANCE, GL_UNSIGNED_BYTE, ptr_image);
		check_gl();
		glBindFramebuffer(GL_FRAMEBUFFER,0);
		
		bReturn = true;
		}
	
	return bReturn;
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
bool GfxTexture::CreateGreyScale(int width, int height, const void* data)
{
	Width = width;
	Height = height;
	glGenTextures(1, &Id);
	check_gl();
	glBindTexture(GL_TEXTURE_2D, Id);
	check_gl();
	glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, Width, Height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
	check_gl();
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (GLfloat)GL_NEAREST);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (GLfloat)GL_NEAREST);
	check_gl();
	glBindTexture(GL_TEXTURE_2D, 0);
	IsRGBA = false;
	return true;
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
void GfxTexture::SavePNG(const char* fname)
{
	int nSize = Width * Height * (IsRGBA ? 4 : 1);
	void* image = malloc( nSize );

	glBindFramebuffer(GL_FRAMEBUFFER,FramebufferId);
	check_gl();
	glReadPixels(0,0,Width,Height,IsRGBA ? GL_RGBA : GL_LUMINANCE, GL_UNSIGNED_BYTE, image);
	check_gl();
	glBindFramebuffer(GL_FRAMEBUFFER,0);

	unsigned error = lodepng::encode(fname, (const unsigned char*)image, Width, Height, IsRGBA ? LCT_RGBA : LCT_GREY);
	if(error) 
		printf("error: %d\n",error);

	free(image);
}
Example #14
0
File: main.c Project: czaber/ogwm
void draw_background() {
	glBegin(GL_QUADS);
		glColor3f(.7, 0., .9);
		glVertex3f( 5.00f, 5.000f, 1.5f);
		glVertex3f( width-5.0f, 5.000f, 1.5f);
		glColor3f(.3, 0., .4);
		glVertex3f( width-5.0f, height-5.0f, 1.5f);
		glVertex3f( 5.00f, height-5.0f, 1.5f);
	glEnd();
	check_gl(__LINE__);
}
Example #15
0
 bool bind (uint target)
 {
   if (glIsBuffer (name))
   {
     glBindBuffer (target, name);
     check_gl ("glBindBuffer");
     return true;
   }
   else
   {
     return false;
   }
 }
Example #16
0
File: main.c Project: czaber/ogwm
GLXWindow create_canvas(void) {
	XSetWindowAttributes sattr;
	GLXWindow c = 0;
	Window w = 0;
	
	GLXFBConfig fbc = choose_fbconfig();
	XVisualInfo* vi = glXGetVisualFromFBConfig(dpy, fbc);
	check_gl(__LINE__);
	fbconfig_attrs(fbc, &width, &height, &top, &bottom);
    sattr.colormap = XCreateColormap(dpy, root, vi->visual, AllocNone);
    ratio = ((GLfloat) width) / ((GLfloat) height);
	w = XCreateWindow(dpy, overlay, 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, CWColormap, &sattr);
	c = glXCreateWindow(dpy, fbc, w, NULL);
	check_gl(__LINE__);
	XFree(vi);
	XSelectInput(dpy, w, ExposureMask);

	context = glXCreateNewContext(dpy, fbc, GLX_RGBA_TYPE, NULL, direct);
	check_gl(__LINE__);
	glXMakeCurrent(dpy, c, context); check_gl(__LINE__);
    info("Canvas is %d x %d (ratio: %g)\n", width, height, ratio);
	return c;
}
Example #17
0
        void
        Axis2D::render(const glm::mat4& mvp)
        {
          axis_shader->bind();

          // Render x axis
          axis_shader->setModelViewProjection(mvp);
          axis_shader->setColour(glm::vec4(1.0, 0.0, 0.0, 1.0));
          axis_shader->setOffset(glm::vec2(0.0, -40.0));
          axis_shader->enableCoords();
          axis_shader->setCoords(xaxis_vertices, 0, 2, 0);

          // Push each element to the vertex shader
          axis_elements.bind();
          glDrawElements(GL_TRIANGLES, axis_elements.size()/sizeof(GLushort), GL_UNSIGNED_SHORT, 0);
          check_gl("Axis X draw elements");

          axis_shader->disableCoords();

          // Render y axis
          axis_shader->bind();
          axis_shader->setModelViewProjection(mvp);
          axis_shader->setColour(glm::vec4(0.0, 1.0, 0.0, 1.0));
          axis_shader->setOffset(glm::vec2(-40.0, 0.0));
          axis_shader->enableCoords();
          axis_shader->setCoords(yaxis_vertices, 0, 2, 0);

          // Push each element to the vertex shader
          axis_elements.bind();
          glDrawElements(GL_TRIANGLES, axis_elements.size()/sizeof(GLushort), GL_UNSIGNED_SHORT, 0);
          check_gl("Axis Y draw elements");

          axis_shader->disableCoords();

          axis_shader->release();
        }
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
int GfxTexture::GetImageLayer2( int &nSize, void *buf_image, int nLayer )	// memory not allocated here - just use it
{
	int nReturn = 0;
	
	if (buf_image != NULL)
		{
		nSize = Width * Height * (IsRGBA ? 4 : 1);
		
		glBindFramebuffer(GL_FRAMEBUFFER,FramebufferId);
		check_gl();
		glReadPixels(0,0,Width,Height,IsRGBA ? GL_RGBA : GL_LUMINANCE, GL_UNSIGNED_BYTE, buf_image);
		check_gl();
		glBindFramebuffer(GL_FRAMEBUFFER,0);
		
		// save only one layer -> result is grayscale image - size Width * Height * 1
		//
		if (raspitexutil_get_onelayer( (uint8_t*) buf_image, nSize, nLayer ))
			{
			nSize = Width * Height * 1;	// for unknown reason must be each grayscale pixel 16bits long
			
			nReturn = 1;
			}
		}
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
bool GfxShader::LoadFragmentShader( const char *lpstrDir, const char* lpstrFilename )
{
	char lpstrFilePath[1024];
	sprintf( lpstrFilePath, "%s/%s", lpstrDir, lpstrFilename );

	fprintf(stderr, "Try to open FragmentShader '%s'\n", lpstrFilePath );

	//cheeky bit of code to read the whole file into memory
	assert(!Src);
	FILE* f = fopen(lpstrFilePath, "rb");
	assert(f);
	fseek(f,0,SEEK_END);
	int sz = ftell(f);
	fseek(f,0,SEEK_SET);
	Src = new GLchar[sz+1];
	fread(Src,1,sz,f);
	Src[sz] = 0; //null terminate it!
	fclose(f);

	//now create and compile the shader
	GlShaderType = GL_FRAGMENT_SHADER;
	Id = glCreateShader(GlShaderType);
	glShaderSource(Id, 1, (const GLchar**)&Src, 0);
	glCompileShader(Id);
	check_gl();

	//compilation check_gl
	GLint compiled;
	glGetShaderiv(Id, GL_COMPILE_STATUS, &compiled);
	if(compiled==0)
	{
		printf("Failed to compile fragment shader %s:\n%s\n", lpstrFilePath, Src);
		printShaderInfoLog(Id);
		glDeleteShader(Id);
		return false;
	}
	else
	{
		//printf("Compiled fragment shader %s:\n%s\n", lpstrFilePath, Src);
	printf("Compiled fragment shader %s:\n", lpstrFilePath );
	}

	return true;
}
Example #20
0
static void Draw(gl_context_t* context) {
    // Clear the color buffer
    // Set background color and clear buffers
    glClearColor(1, 1, 1, 1);
    glClear(GL_COLOR_BUFFER_BIT);
    check_gl();

    image_t* img = bundle_image_named("beer-label-ruination-ipa.jpg");
    DrawBeerLabel(context, img);
    image_free(img);

    // TODO:DOUG Add blur
    DrawToolbarBackground(context);
    DrawGear(context);
    DrawSelectedTap(context);
    DrawRightLabel(context, "54\xc2\xb0" "F");

    gl_context_swap_buffers(context);
}
Example #21
0
File: main.c Project: czaber/ogwm
GLXFBConfig choose_fbconfig() {
	int i, nfbc;
    GLXFBConfig* fbc = glXChooseFBConfig(dpy, screen, fbconfig_attr, &nfbc);
	check_gl(__LINE__);
    if (fbc == NULL)
        die(1, "No valid FBConfigs.\n");
	for (i=0; i<nfbc; i++) {
		int v;
        continue;
		//if (!vi || vi->visualid != vid) continue;
        debug("FBConfig #%d:\n", i);
        glXGetFBConfigAttrib(dpy, fbc[i], GLX_DRAWABLE_TYPE, &v);
        debug("GLX_DRAWABLE_TYPE: ");
        if (v & GLX_WINDOW_BIT)  log("WINDOW ");
        if (v & GLX_PIXMAP_BIT)  log("PIXMAP ");
        if (v & GLX_PBUFFER_BIT) log("PBUFFER ");
        log("\n");
        glXGetFBConfigAttrib(dpy, fbc[i], GLX_BIND_TO_TEXTURE_TARGETS_EXT, &v);
        debug("GLX_BIND_TO_TEXTURE_TARGETS_EXT: ");
        if (v & GLX_TEXTURE_1D_BIT_EXT) log("1D ");
        if (v & GLX_TEXTURE_2D_BIT_EXT) log("2D ");
        if (v & GLX_TEXTURE_RECTANGLE_BIT_EXT) log("RECTANGLE ");
        log("\n");
        glXGetFBConfigAttrib(dpy, fbc[i], GLX_BIND_TO_TEXTURE_RGBA_EXT, &v);
        debug("GLX_BIND_TO_TEXTURE_RGBA_EXT: ");
        if (v) log("yes ");
        else   log("no ");
        log("\n");
        glXGetFBConfigAttrib(dpy, fbc[i], GLX_BIND_TO_TEXTURE_RGB_EXT, &v);
        debug("GLX_BIND_TO_TEXTURE_RGB_EXT: ");
        if (v) log("yes ");
        else   log("no ");
        log("\n");
	}

    i = 0;
	if (i == nfbc)
		die(2, "No FBCofig found!\n"); 

	return fbc[i];
}
Example #22
0
// For debugging
static void DrawRedBoxAroundRect(gl_context_t* context, rect2d_t rect)
{
    float const l = rect_left(rect);
    float const r = rect_right(rect);
    float const t = rect_top(rect);
    float const b = rect_bottom(rect);

    // Draw a yellow 1 pixel box around the entire thing.
    GLfloat boxLines[] = {
        l, b, 0,
        l, t, 0,
        r, t, 0,
        r, b, 0
    };

    // Use the program object
    glUseProgram(context->mainProgram);

    glVertexAttribPointer(context->a_position, 3, GL_FLOAT, GL_FALSE, 0, boxLines);
    glEnableVertexAttribArray(context->a_position);
    glUniform4f(context->u_fragColor, 1,0,0,1);
    glDrawArrays(GL_LINE_LOOP, 0, 4);
    check_gl();
}
Example #23
0
int
main (int argc, char **argv)
{
        GError           *error = NULL;
        static char     **override_autostart_dirs = NULL;
        static char      *opt_session_name = NULL;
        const char       *debug_string = NULL;
        gboolean          gl_failed = FALSE;
        guint             name_owner_id;
        GOptionContext   *options;
        static GOptionEntry entries[] = {
                { "autostart", 'a', 0, G_OPTION_ARG_STRING_ARRAY, &override_autostart_dirs, N_("Override standard autostart directories"), N_("AUTOSTART_DIR") },
                { "session", 0, 0, G_OPTION_ARG_STRING, &opt_session_name, N_("Session to use"), N_("SESSION_NAME") },
                { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debugging code"), NULL },
                { "failsafe", 'f', 0, G_OPTION_ARG_NONE, &failsafe, N_("Do not load user-specified applications"), NULL },
                { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Version of this application"), NULL },
                /* Translators: the 'fail whale' is the black dialog we show when something goes seriously wrong */
                { "whale", 0, 0, G_OPTION_ARG_NONE, &please_fail, N_("Show the fail whale dialog for testing"), NULL },
                { "disable-acceleration-check", 0, 0, G_OPTION_ARG_NONE, &disable_acceleration_check, N_("Disable hardware acceleration check"), NULL },
                { NULL, 0, 0, 0, NULL, NULL, NULL }
        };

        /* Make sure that we have a session bus */
        if (!require_dbus_session (argc, argv, &error)) {
                gsm_util_init_error (TRUE, "%s", error->message);
        }

        /* From 3.14 GDM sets XDG_CURRENT_DESKTOP. For compatibility with
         * older versions of GDM,  other display managers, and startx,
         * set a fallback value if we don't find it set.
         */
        if (g_getenv ("XDG_CURRENT_DESKTOP") == NULL) {
            g_setenv("XDG_CURRENT_DESKTOP", "GNOME", TRUE);
            gsm_util_setenv ("XDG_CURRENT_DESKTOP", "GNOME");
        }

        /* Make sure we initialize gio in a way that does not autostart any daemon */
        initialize_gio ();

        setlocale (LC_ALL, "");
        bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
        textdomain (GETTEXT_PACKAGE);

        debug_string = g_getenv ("GNOME_SESSION_DEBUG");
        if (debug_string != NULL) {
                debug = rpmatch (debug_string) == TRUE || atoi (debug_string) == 1;
        }

        error = NULL;
        options = g_option_context_new (_(" - the GNOME session manager"));
        g_option_context_add_main_entries (options, entries, GETTEXT_PACKAGE);
        g_option_context_parse (options, &argc, &argv, &error);
        if (error != NULL) {
                g_warning ("%s", error->message);
                exit (1);
        }

        g_option_context_free (options);

        /* Rebind stdout/stderr to the journal explicitly, so that
         * journald picks ups the nicer "gnome-session" as the program
         * name instead of whatever shell script GDM happened to use.
         */
#ifdef HAVE_SYSTEMD
        if (!debug) {
                int journalfd;

                journalfd = sd_journal_stream_fd (PACKAGE, LOG_INFO, 0);
                if (journalfd >= 0) {
                        dup2(journalfd, 1);
                        dup2(journalfd, 2);
                }
        }
#endif

        gdm_log_init ();
        gdm_log_set_debug (debug);

        if (disable_acceleration_check) {
                g_debug ("hardware acceleration check is disabled");
        } else {
                /* Check GL, if it doesn't work out then force software fallback */
                if (!check_gl (&error)) {
                        gl_failed = TRUE;

                        g_debug ("hardware acceleration check failed: %s",
                                 error? error->message : "");
                        g_clear_error (&error);
                        if (g_getenv ("LIBGL_ALWAYS_SOFTWARE") == NULL) {
                                g_setenv ("LIBGL_ALWAYS_SOFTWARE", "1", TRUE);
                                if (!check_gl (&error)) {
                                        g_warning ("software acceleration check failed: %s",
                                                   error? error->message : "");
                                        g_clear_error (&error);
                                } else {
                                        gl_failed = FALSE;
                                }
                        }
                }
        }

        if (show_version) {
                g_print ("%s %s\n", argv [0], VERSION);
                exit (0);
        }

        if (gl_failed) {
                gsm_fail_whale_dialog_we_failed (FALSE, TRUE, NULL);
                gsm_main ();
                exit (1);
        }

        if (please_fail) {
                gsm_fail_whale_dialog_we_failed (TRUE, TRUE, NULL);
                gsm_main ();
                exit (1);
        }

        {
                gchar *ibus_path;

                ibus_path = g_find_program_in_path("ibus-daemon");

                if (ibus_path) {
                        const gchar *p;
                        p = g_getenv ("QT_IM_MODULE");
                        if (!p || !*p)
                                p = "ibus";
                        gsm_util_setenv ("QT_IM_MODULE", p);
                        p = g_getenv ("XMODIFIERS");
                        if (!p || !*p)
                                p = "@im=ibus";
                        gsm_util_setenv ("XMODIFIERS", p);
                }

                g_free (ibus_path);
        }

        /* Some third-party programs rely on GNOME_DESKTOP_SESSION_ID to
         * detect if GNOME is running. We keep this for compatibility reasons.
         */
        gsm_util_setenv ("GNOME_DESKTOP_SESSION_ID", "this-is-deprecated");

        /* We want to use the GNOME menus which has the designed categories.
         */
        gsm_util_setenv ("XDG_MENU_PREFIX", "gnome-");

        /* hack to fix keyring until we can reorder things in 3.20
         * https://bugzilla.gnome.org/show_bug.cgi?id=738205
         */
        if (g_strcmp0 (g_getenv ("XDG_SESSION_TYPE"), "wayland") == 0 &&
            g_getenv ("GSM_SKIP_SSH_AGENT_WORKAROUND") == NULL) {
                char *ssh_socket;

                ssh_socket = g_build_filename (g_get_user_runtime_dir (), "keyring", "ssh", NULL);
                gsm_util_setenv ("SSH_AUTH_SOCK", ssh_socket);
                g_free (ssh_socket);
        }

        gsm_util_set_autostart_dirs (override_autostart_dirs);
        session_name = opt_session_name;

        /* Talk to logind before acquiring a name, since it does synchronous
         * calls at initialization time that invoke a main loop and if we
         * already owned a name, then we would service too early during
         * that main loop.
         */
        g_object_unref (gsm_get_system ());

        name_owner_id  = acquire_name ();

        gsm_main ();

        g_clear_object (&manager);
        g_free (gl_renderer);

        g_bus_unown_name (name_owner_id);
        gdm_log_shutdown ();

        return 0;
}
Example #24
0
static void init_cl(void)
{
    cl_int status;
    cl_platform_id platform_id;
    cl_context context;
    cl_program program;

    char *kernel_src = malloc(10240);
    check_nn(kernel_src, "kernel_src");

    status = clGetPlatformIDs(1, &platform_id, &num_platforms);
    SOFT_CHECK_CL(status, "get platform ids");

    fprintf(stderr, "#platforms: %u\n", num_platforms);
    if (num_platforms == 0)
        return;

    static char info[4][128];
    status = clGetPlatformInfo(platform_id, CL_PLATFORM_PROFILE, 128, info[0], NULL);
    SOFT_CHECK_CL(status, "get platform profile");
    status = clGetPlatformInfo(platform_id, CL_PLATFORM_VERSION, 128, info[1], NULL);
    SOFT_CHECK_CL(status, "get platform version");
    status = clGetPlatformInfo(platform_id, CL_PLATFORM_NAME, 128, info[2], NULL);
    SOFT_CHECK_CL(status, "get platform name");
    status = clGetPlatformInfo(platform_id, CL_PLATFORM_VENDOR, 128, info[3], NULL);
    SOFT_CHECK_CL(status, "get platform vendor");

    fprintf(stderr, "profile: %s\n", info[0]);
    fprintf(stderr, "version: %s\n", info[1]);
    fprintf(stderr, "name: %s\n", info[2]);
    fprintf(stderr, "vendor: %s\n", info[3]);

    cl_context_properties *props = getContextProperties(platform_id);
    context = clCreateContextFromType(props, CL_DEVICE_TYPE_GPU, NULL, NULL, &status);
    SOFT_CHECK_CL(status, "create context");

    // create a command queue
    cl_device_id device_id;
    status = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);
    SOFT_CHECK_CL(status, "get device ids");

    queue = clCreateCommandQueue(context, device_id, 0, &status);
    SOFT_CHECK_CL(status, "create command queue");

    // allocate memory objects
    mainOctCL = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, octTreeLength*sizeof(OctTreeNode), mainOctTree, &status);
    SOFT_CHECK_CL(status, "create buffer");

    glGenTextures(1, &texture);
    check_gl();
    glBindTexture(GL_TEXTURE_2D, texture);
    check_gl();

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    check_gl();
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    check_gl();

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
    check_gl();
    glFinish();
    check_gl();

    image = clCreateFromGLTexture(context, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, texture, &status);
    SOFT_CHECK_CL(status, "create image");

    // create the compute program
    FILE *kernel_handle = fopen("ray.cl", "rb");
    check_nn(kernel_handle, "fopen ray.cl");

    size_t n_bytes = fread(kernel_src, 1, 10239, kernel_handle);
    kernel_src[n_bytes] = '\0';
    check_ferror(kernel_handle, "fread");

    program = clCreateProgramWithSource(context, 1, (const char **)&kernel_src, NULL, &status);
    SOFT_CHECK_CL(status, "create program");

    // build the compute program executable
    status = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
    if (status != CL_BUILD_PROGRAM_FAILURE && status != CL_SUCCESS) {
        SOFT_CHECK_CL(status, "build program");
    } else {
        size_t log_size;
        status = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);
        SOFT_CHECK_CL(status, "get program build log size");

        char *log = malloc(log_size);
        check_nn(log, "log");

        status = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, log_size, log, NULL);
        SOFT_CHECK_CL(status, "get program build log");

        fprintf(stderr, "build kernel log:\n%s\n", log);
    }

    // create the compute kernel
    kernel = clCreateKernel(program, "ray_cl", &status);
    SOFT_CHECK_CL(status, "create kernel");

    status = clReleaseProgram(program);
    SOFT_CHECK_CL(status, "release program");

    status = clReleaseContext(context);
    SOFT_CHECK_CL(status, "release context");

    fprintf(stderr, "OpenCL initialization successful\n");
    render_method = TracerCL;
}
Example #25
0
 void
 GLImageShader2D::setTexture(int texunit)
 {
   glUniform1i(uniform_texture, texunit);
   check_gl("Set image texture");
 }
Example #26
0
 void
 GLImageShader2D::setMin(const glm::vec3& min)
 {
   glUniform3fv(uniform_min, 1, glm::value_ptr(min));
   check_gl("Set min range");
 }
Example #27
0
 void
 GLImageShader2D::setMax(const glm::vec3& max)
 {
   glUniform3fv(uniform_max, 1, glm::value_ptr(max));
   check_gl("Set max range");
 }
Example #28
0
 void
 GLImageShader2D::setCorrection(const glm::vec3& corr)
 {
   glUniform3fv(uniform_corr, 1, glm::value_ptr(corr));
   check_gl("Set correction multiplier");
 }
Example #29
0
 void
 GLImageShader2D::setLUT(int texunit)
 {
   glUniform1i(uniform_lut, texunit);
   check_gl("Set LUT texture");
 }
Example #30
0
 void
 GLImageShader2D::setModelViewProjection(const glm::mat4& mvp)
 {
   glUniformMatrix4fv(uniform_mvp, 1, GL_FALSE, glm::value_ptr(mvp));
   check_gl("Set image2d uniform mvp");
 }