Exemplo n.º 1
0
/**
 * Accept a connection from a client.
 * \param protocol  the protocol to use (such as "tcpip" or "gm")
 * \param hostname  optional hostname of the expected client (may be NULL)
 * \param port  number of the port to accept on
 * \param mtu  maximum transmission unit
 * \param broker  either 1 or 0 to indicate if connection is brokered through
 *                the mothership
 * \return  new CRConnection object, or NULL
 */
CRConnection *
crNetAcceptClient( const char *protocol, const char *hostname,
									 unsigned short port, unsigned int mtu, int broker )
{
	CRConnection *conn;

	CRASSERT( cr_net.initialized );

	conn = (CRConnection *) crCalloc( sizeof( *conn ) );
	if (!conn)
		return NULL;

	/* init the non-zero fields */
	conn->type               = CR_NO_CONNECTION; /* we don't know yet */
	conn->recv_credits       = CR_INITIAL_RECV_CREDITS;
	conn->port               = port;
	conn->mtu                = mtu;
	conn->buffer_size        = mtu;
	conn->broker             = broker;
	conn->endianness         = crDetermineEndianness();
	conn->teac_id            = -1;
	conn->teac_rank          = -1;
	conn->tcscomm_id         = -1;
	conn->tcscomm_rank       = -1;

	/* now, just dispatch to the appropriate protocol's initialization functions. */
	crDebug("In crNetAcceptClient( protocol=\"%s\" port=%d mtu=%d )",
					protocol, (int) port, (int) mtu);

	/* special case */
	if ( !crStrncmp( protocol, "file", crStrlen( "file" ) ) ||
			 !crStrncmp( protocol, "swapfile", crStrlen( "swapfile" ) ) )
	{
		char filename[4096];
    char protocol_only[4096];

		cr_net.use_file++;
		if (!crParseURL(protocol, protocol_only, filename, NULL, 0))
		{
			crError( "Malformed URL: \"%s\"", protocol );
		}
		conn->hostname = crStrdup( filename );

    /* call the protocol-specific init routines */  // ktd (add)
    InitConnection(conn, protocol_only, mtu);       // ktd (add)
	}
	else {
  	/* call the protocol-specific init routines */
	  InitConnection(conn, protocol, mtu);
	}

	crNetAccept( conn, hostname, port );
	return conn;
}
Exemplo n.º 2
0
char *crStrjoin( const char *str1, const char *str2 )
{
	const int len1 = crStrlen(str1), len2 = crStrlen(str2);
	char *s = crAlloc(len1 + len2 + 1);
	if (s)
	{
		crMemcpy( s, str1, len1 );
		crMemcpy( s + len1, str2, len2 );
		s[len1 + len2] = '\0';
	}
	return s;
}
Exemplo n.º 3
0
/* Intersect two strings on a word-by-word basis (separated by spaces).
 * We typically use this to intersect OpenGL extension strings.
 * Example: if s1 = "apple banana plum pear"
 *         and s2 = "plum banana orange"
 *      then return "banana plum" (or "plum banana").
 */
char *crStrIntersect( const char *s1, const char *s2 )
{
	int len1, len2;
	int resultLen;
	char *result;
	char **exten1, **exten2;
	int i, j;

	if (!s1 || !s2) {
		/* null strings, no intersection */
		return NULL;
	}

	len1 = crStrlen(s1);
	len2 = crStrlen(s2);

	/* allocate storage for result (a conservative estimate) */
	resultLen = ((len1 > len2) ? len1 : len2) + 2;
	result = (char *) crAlloc(resultLen);
	if (!result)
	{
		return NULL;
	}
	result[0] = 0;

	/* split s1 and s2 at space chars */
	exten1 = crStrSplit(s1, " ");
	exten2 = crStrSplit(s2, " ");

	for (i = 0; exten1[i]; i++)
	{
		for (j = 0; exten2[j]; j++)
		{
			if (crStrcmp(exten1[i], exten2[j]) == 0)
			{
				/* found an intersection, append to result */
				crStrcat(result, exten1[i]);
				crStrcat(result, " ");
				break;
			}
		}
	}

	/* free split strings */
	crFreeStrings( exten1 );
	crFreeStrings( exten2 );

	/*CRASSERT(crStrlen(result) < resultLen);*/

	/* all done! */
	return result;
}
Exemplo n.º 4
0
char *crStrstr( const char *str, const char *pat )
{
	int pat_len = crStrlen( pat );
	const char *end = str + crStrlen(str) - pat_len;
	char first_char = *pat;
	if (!str) return NULL;
	for (; str <= end ; str++)
	{
		if (*str == first_char && !crMemcmp( str, pat, pat_len ))
			return (char *) str;
	}
	return NULL;
}
Exemplo n.º 5
0
GLint renderspuWindowCreateEx( const char *dpyName, GLint visBits, GLint id )
{
    WindowInfo *window;
    VisualInfo *visual;
    GLboolean showIt;

    if (id <= 0)
    {
        id = (GLint)crHashtableAllocKeys(render_spu.windowTable, 1);
        if (id <= 0)
        {
            crWarning("failed to allocate window id");
            return -1;
        }
    }
    else
    {
        if (crHashtableIsKeyUsed(render_spu.windowTable, id))
        {
            crWarning("the specified window key %d is in use", id);
            return -1;
        }
    }


    if (!dpyName || crStrlen(render_spu.display_string) > 0)
        dpyName = render_spu.display_string;

    visual = renderspuFindVisual( dpyName, visBits );
    if (!visual)
    {
        crWarning( "Render SPU: Couldn't create a window, renderspuFindVisual returned NULL" );
        return -1;
    }

    /* Allocate WindowInfo */
    window = (WindowInfo *) crCalloc(sizeof(WindowInfo));
    if (!window)
    {
        crWarning( "Render SPU: Couldn't create a window" );
        return -1;
    }
    
    crHashtableAdd(render_spu.windowTable, id, window);

    showIt = 0;

    /*
    crDebug("Render SPU: Creating window (visBits=0x%x, id=%d)", visBits, window->BltInfo.Base.id);
    */
    /* Have GLX/WGL/AGL create the window */
    if (!renderspuWindowInit( window, visual, showIt, id ))
    {
        crFree(window);
        crWarning( "Render SPU: Couldn't create a window, renderspu_SystemCreateWindow failed" );
        return -1;
    }
    
    return window->BltInfo.Base.id;
}
Exemplo n.º 6
0
static int validate_one_option( const SPUOptions *opt, 
                const char *response,
                const char *min,
                const char *max )
{
    switch (opt->type) {
    case CR_BOOL:
        return validate_int( response, "0", "1" );
    case CR_INT:
        return validate_int( response, min, max );
    case CR_FLOAT:
        return validate_float( response, min, max );
    case CR_ENUM:
        /* Make sure response string is present in the min string.
         * For enums, the min string is a comma-separated list of valid values.
         */
        CRASSERT(opt->numValues == 1); /* an enum limitation for now */
        {
            const char *p = crStrstr(min, response);
            if (!p)
                return 0;  /* invalid value! */
            if (p[-1] != '\'')
                return 0;  /* right substring */
            if (p[crStrlen(response)] != '\'')
                return 0;  /* left substring */
            return 1;
        }
    default:
        return 0;
    }
}
Exemplo n.º 7
0
int crdlm_pointers_TexSubImage3D( struct instanceTexSubImage3D *instance, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels, CRClientState *c )
{
    unsigned int size;
    int is_distrib = ((type == GL_TRUE) || (type == GL_FALSE));

    if (pixels == NULL) {
	size = 0;
    }
    else if (is_distrib) {
	size = crStrlen(pixels) + 1 + (type==GL_TRUE?width*height*3:0);
    }
    else {
	size = crTextureSize(format, type, width, height, depth);
    }

    if (instance && size > 0) {
	if (is_distrib) {
	    crMemcpy(instance->pixels, pixels, size);
	}
	else {
	    crPixelCopy3D(width, height, depth,
		instance->pixels, format, type, NULL,
		pixels, format, type, &c->unpack);
	}
    }

    return size;
}
Exemplo n.º 8
0
static int
ParseVisString( const char *visString )
{
	int mask = 0;
	if (crStrlen(visString) > 0) {
		if (crStrstr(visString, "rgb"))
			mask |= CR_RGB_BIT;
		if (crStrstr(visString, "alpha"))
			mask |= CR_ALPHA_BIT;
		if (crStrstr(visString, "z") || crStrstr(visString, "depth"))
			mask |= CR_DEPTH_BIT;
		if (crStrstr(visString, "stencil"))
			mask |= CR_STENCIL_BIT;
		if (crStrstr(visString, "accum"))
			mask |= CR_ACCUM_BIT;
		if (crStrstr(visString, "stereo"))
			mask |= CR_STEREO_BIT;
		if (crStrstr(visString, "multisample"))
			mask |= CR_MULTISAMPLE_BIT;
		if (crStrstr(visString, "double"))
			mask |= CR_DOUBLE_BIT;
		if (crStrstr(visString, "pbuffer"))
			mask |= CR_PBUFFER_BIT;
	}
	return mask;
}
Exemplo n.º 9
0
void
CRUT_APIENTRY
crutGetMenuXML( CRUTAPI *crut_api )
{
    char response[8096];
    
    if (!crut_api->mothershipConn)
	crError("Checking for Menu XML but no connection!"); 
    
    crMothershipGetParam( crut_api->mothershipConn, "crut_menu_xml", response );
    
    if (crStrlen(response) < MENU_MAX_SIZE)
		crMemcpy(crut_api->menuBuffer, response, crStrlen(response));
    else
		crError("Menu XML is too long for buffer");
}
Exemplo n.º 10
0
/**
 * Search str for pattern.  Pattern may include leading and trailing
 * wildcard (*) characters.
 * \return  pointer to match in s, or NULL.
 */
char *
crStrPatternMatch(const char *s, const char *pattern)
{
	const int patLen = crStrlen(pattern);
	const int leadingWildcard = pattern[0] == '*';
	const int trailingWildcard = pattern[patLen-1] == '*';

	if (!leadingWildcard) {
		if (!trailingWildcard) {
			/* total match */
			return crStrstr(s, pattern);
		}
		else {
			/* match at head */
			char *p = crStrstr(s, pattern);
			if (p == s)
				return p;
			else
				return NULL;
		}
	}
	else {
		if (!trailingWildcard) {
			/* match at tail */
			const char *pPtr = pattern + patLen - 1;
			const char *sPtr = s + crStrlen(s) - 1;
			while (pPtr >= pattern && sPtr >= s) {
				if (*pPtr == *sPtr) {
					pPtr--;
					sPtr--;
				}
				else {
					break;
				}
			}
			if (pPtr == pattern && sPtr >= s)
				return (char *) sPtr;
			else
				return NULL;
		}
		else {
			/* match anywhere */
			return crStrstr(s, pattern);
		}
	}
}
Exemplo n.º 11
0
void PACK_APIENTRY crPackShaderSource(GLuint shader, GLsizei count, const char **string, const GLint *length)
{
    CR_GET_PACKER_CONTEXT(pc);
    unsigned char *data_ptr;
    GLint *pLocalLength;
    int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(shader)+sizeof(count)+sizeof(GLint)+count*sizeof(*pLocalLength);
    GLsizei i;

    if ((0==count) || (!string)) return;

    pLocalLength = crAlloc(count*sizeof(*length));
    if (!pLocalLength) return;

    for (i=0; i<count; ++i)
    {
        pLocalLength[i] = (length && (length[i]>=0)) ? length[i] : crStrlen(string[i])+1;
        packet_length += pLocalLength[i];
    }
    
    if (length)
    {
        packet_length += count*sizeof(*length);
    }

    CR_GET_BUFFERED_POINTER(pc, packet_length);
    WRITE_DATA_AI(int, packet_length);
    WRITE_DATA_AI(GLenum, CR_SHADERSOURCE_EXTEND_OPCODE);
    WRITE_DATA_AI(GLuint, shader);
    WRITE_DATA_AI(GLsizei, count);
    WRITE_DATA_AI(GLint, (GLint)(length ? 1:0));
    crMemcpy(data_ptr, pLocalLength, count*sizeof(*pLocalLength));
    data_ptr += count*sizeof(*pLocalLength);

    if (length)
    {
        crMemcpy(data_ptr, length, count*sizeof(*length));
        data_ptr += count*sizeof(*length);
    }

    for (i=0; i<count; ++i)
    {
        if (string[i])
        {
            crMemcpy(data_ptr, string[i], pLocalLength[i]);
        }
        else
        {
            CRASSERT(pLocalLength[i]==1);
            *data_ptr = 0;
        }
        data_ptr += pLocalLength[i];
    }
    WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
    CR_UNLOCK_PACKER_CONTEXT(pc);

    crFree(pLocalLength);
}
Exemplo n.º 12
0
void crStrncpy( char *dest, const char *src, unsigned int len )
{
	const unsigned int str_len = crStrlen(src);
	if (str_len > len - 1) {
		crMemcpy( dest, src, len );  /* NOTE: not null-terminated! */
	}
	else {
		crMemcpy( dest, src, str_len + 1 );  /* includes null terminator */
	}
}
Exemplo n.º 13
0
char *crStrrchr( const char *str, char c )
{
	const char *temp = str + crStrlen( str );
	for ( ; temp >= str ; temp-- )
	{
		if (*temp == c)
			return (char *) temp;
	}
	return NULL;
}
Exemplo n.º 14
0
static int __numOccurrences( const char *str, const char *substr )
{
	int ret = 0;
	char *temp = (char *) str;
	while ((temp = crStrstr( temp, substr )) != NULL )
	{
		temp += crStrlen(substr);
		ret++;
	}
	return ret;
}
Exemplo n.º 15
0
static void
set_basename(void *foo, const char *response)
{
	int rl = crStrlen(response);
	if (rl)
	{
		saveframe_spu.spec = crAlloc(rl + 7);
		/* This relies on saveframe_spu.format being initialized first! */
		sprintf(saveframe_spu.spec, "%s%%d.%s", response, saveframe_spu.format);
	}
}
Exemplo n.º 16
0
static ContextInfo * renderspuCreateContextInternal(const char *dpyName, GLint visBits, GLint idCtx, ContextInfo * sharedContext)
{
    ContextInfo *context;
    VisualInfo *visual;

    if (idCtx <= 0)
    {
        idCtx = (GLint)crHashtableAllocKeys(render_spu.contextTable, 1);
        if (idCtx <= 0)
        {
            crWarning("failed to allocate context id");
            return NULL;
        }
    }
    else
    {
        if (crHashtableIsKeyUsed(render_spu.contextTable, idCtx))
        {
            crWarning("the specified ctx key %d is in use", idCtx);
            return NULL;
        }
    }


    if (!dpyName || crStrlen(render_spu.display_string)>0)
        dpyName = render_spu.display_string;

    visual = renderspuFindVisual(dpyName, visBits);
    if (!visual)
        return NULL;

    context = (ContextInfo *) crCalloc(sizeof(ContextInfo));
    if (!context)
        return NULL;
    context->BltInfo.Base.id = idCtx;
    context->shared = sharedContext;
    if (!renderspu_SystemCreateContext(visual, context, sharedContext))
        return NULL;

    crHashtableAdd(render_spu.contextTable, idCtx, context);

    context->BltInfo.Base.visualBits = visual->visAttribs;
    /*
    crDebug("Render SPU: CreateContext(%s, 0x%x) returning %d",
                    dpyName, visBits, context->BltInfo.Base.id);
    */

    if (sharedContext)
        ASMAtomicIncU32(&sharedContext->cRefs);
    context->cRefs = 1;

    return context;
}
Exemplo n.º 17
0
GLboolean renderspuWindowInit( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id )
{
    crMemset(window, 0, sizeof (*window));
    RTCritSectInit(&window->CompositorLock);
    window->fCompositorPresentEmpty = GL_FALSE;
    window->pCompositor = NULL;

    window->BltInfo.Base.id = id;

    window->x = render_spu.defaultX;
    window->y = render_spu.defaultY;
    window->BltInfo.width  = render_spu.defaultWidth;
    window->BltInfo.height = render_spu.defaultHeight;

    /* Set window->title, replacing %i with the window ID number */
    {
        const char *s = crStrstr(render_spu.window_title, "%i");
        if (s) {
            int i, j, k;
            window->title = crAlloc(crStrlen(render_spu.window_title) + 10);
            for (i = 0; render_spu.window_title[i] != '%'; i++)
                window->title[i] = render_spu.window_title[i];
            k = sprintf(window->title + i, "%d", window->BltInfo.Base.id);
            CRASSERT(k < 10);
            i++; /* skip the 'i' after the '%' */
            j = i + k;
            for (; (window->title[j] = s[i]) != 0; i++, j++)
                ;
        }
        else {
            window->title = crStrdup(render_spu.window_title);
        }
    }
        
    window->BltInfo.Base.visualBits = visual->visAttribs;
    
    
    /*
    crDebug("Render SPU: Creating window (visBits=0x%x, id=%d)", visBits, window->BltInfo.Base.id);
    */
    /* Have GLX/WGL/AGL create the window */
    if (!renderspu_SystemVBoxCreateWindow( visual, showIt, window ))
    {
        crWarning( "Render SPU: Couldn't create a window, renderspu_SystemCreateWindow failed" );
        return GL_FALSE;
    }
    
    window->visible = !!showIt;

    CRASSERT(window->visual == visual);
    return GL_TRUE;
}
Exemplo n.º 18
0
static GLboolean hasExtension(const char *haystack, const char *needle)
{
	const int needleLen = crStrlen(needle);
	const char *s;

	while (1) {
		s = crStrstr(haystack, needle);
		if (!s)
			return GL_FALSE;
		if (s && (s[needleLen] == ' ' || s[needleLen] == 0))
			return GL_TRUE;
		haystack += needleLen;
	}
}
static const GLubyte *
GetExtensions(void)
{
    static GLboolean fInitialized = GL_FALSE;
    if (!fInitialized)
    {
        GLubyte return_value[10*1000];
        const GLubyte *extensions, *ext;
        GET_THREAD(thread);
        int writeback = 1;

        if (pack_spu.swap)
        {
            crPackGetStringSWAP( GL_EXTENSIONS, return_value, &writeback );
        }
        else
        {
            crPackGetString( GL_EXTENSIONS, return_value, &writeback );
        }
        packspuFlush( (void *) thread );

        CRPACKSPU_WRITEBACK_WAIT(thread, writeback);

        CRASSERT(crStrlen((char *)return_value) < 10*1000);

        /* OK, we got the result from the server.  Now we have to
         * intersect is with the set of extensions that Chromium understands
         * and tack on the Chromium-specific extensions.
         */
        extensions = return_value;
        ext = crStateMergeExtensions(1, &extensions);

#ifdef Linux
        /*@todo
         *That's a hack to allow running Unity, it uses libnux which is calling extension functions
         *without checking if it's being supported/exported.
         *glActiveStencilFaceEXT seems to be actually supported but the extension string isn't exported (for ex. on ATI HD4870),
         *which leads to libglew setting function pointer to NULL and crashing Unity.
         */
        sprintf((char*)gpszExtensions, "%s GL_EXT_stencil_two_side", ext);
#else
        sprintf((char*)gpszExtensions, "%s", ext);
#endif
        fInitialized = GL_TRUE;
    }

    return gpszExtensions;
}
Exemplo n.º 20
0
char *crStrdup( const char *str )
{
	int len;
	char *ret;
	
	/* Allow strdup'ing of NULL strings -- this makes the __fillin functions 
	 * much cleaner. */
	
	if (str == NULL) return NULL;
	
	len = crStrlen(str);
	ret = (char*)crAlloc( len+1 );
	crMemcpy( ret, str, len );
	ret[len] = '\0';
	return ret;
}
Exemplo n.º 21
0
void PACK_APIENTRY crPackBindAttribLocation(GLuint program, GLuint index, const char *name)
{
    CR_GET_PACKER_CONTEXT(pc);
    unsigned char *data_ptr;
    int cbName = crStrlen(name)+1;
    int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(program)+sizeof(index) + cbName*sizeof(*name);

    CR_GET_BUFFERED_POINTER(pc, packet_length);
    WRITE_DATA_AI(int, packet_length);
    WRITE_DATA_AI(GLenum, CR_BINDATTRIBLOCATION_EXTEND_OPCODE);
    WRITE_DATA_AI(GLuint, program);
    WRITE_DATA_AI(GLuint, index);
    crMemcpy(data_ptr, name, cbName*sizeof(*name));
    WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
    CR_UNLOCK_PACKER_CONTEXT(pc);
}
Exemplo n.º 22
0
void PACK_APIENTRY crPackGetUniformLocation(GLuint program, const char * name, GLint * return_value, int * writeback)
{
    CR_GET_PACKER_CONTEXT(pc);
    unsigned char *data_ptr;
    int cbName = crStrlen(name)+1;
    int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(program)+cbName*sizeof(*name)+16;

    CR_GET_BUFFERED_POINTER(pc, packet_length);
    WRITE_DATA_AI(int, packet_length);
    WRITE_DATA_AI(GLenum, CR_GETUNIFORMLOCATION_EXTEND_OPCODE);
    WRITE_DATA_AI(GLuint, program);
    crMemcpy(data_ptr, name, cbName*sizeof(*name));
    data_ptr +=  cbName*sizeof(*name);
    WRITE_NETWORK_POINTER(0, (void *) return_value);
    WRITE_NETWORK_POINTER(8, (void *) writeback);
    WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
    CR_UNLOCK_PACKER_CONTEXT(pc);
}
static GLfloat
GetVersionString(void)
{
    static GLboolean fInitialized = GL_FALSE;
    static GLfloat version = 0.;

    if (!fInitialized)
    {
        GLubyte return_value[100];

        GetString(GL_VERSION, return_value);
        CRASSERT(crStrlen((char *)return_value) < 100);

        version = crStrToFloat((char *) return_value);
        version = crStateComputeVersion(version);

        fInitialized = GL_TRUE;
    }

    return version;
}
Exemplo n.º 24
0
/**
 * Send a mesage to the mothership and get a response.
 * \return 1 if OK, 0 if error
 */
int crMothershipSendString( CRConnection *conn, char *response_buf, const char *str, ... )
{
	va_list args;
	static char txt[8092];

	va_start(args, str);
	vsprintf( txt, str, args );
	va_end(args);

	crStrcat( txt, "\n" );
	crNetSendExact( conn, txt, crStrlen(txt) );
	if (response_buf)
	{
		return crMothershipReadResponse( conn, response_buf );
	}
	else
	{
		char devnull[1024];
		return crMothershipReadResponse( conn, devnull );
	}
}
Exemplo n.º 25
0
/**
 * Find the index of the given enum value in the SPUOption's list of
 * possible enum values.
 * Return the enum index, or -1 if not found.
 */
int crSPUGetEnumIndex( const SPUOptions *options, const char *optName, const char *value )
{
    const SPUOptions *opt;
    const int valueLen = crStrlen(value);

    /* first, find the right option */
    for (opt = options; opt->option; opt++) {
        if (crStrcmp(opt->option, optName) == 0) {
            char **values;
            int i;

            CRASSERT(opt->type == CR_ENUM);

            /* break into array of strings */
            /* min string should be of form "'enum1', 'enum2', 'enum3', etc" */
            values = crStrSplit(opt->min, ",");

            /* search the array */
            for (i = 0; values[i]; i++) {
                /* find leading quote */
                const char *e = crStrchr(values[i], '\'');
                CRASSERT(e);
                if (e) {
                    /* test for match */
                    if (crStrncmp(value, e + 1, valueLen) == 0 &&   e[valueLen + 1] == '\'') {
                        crFreeStrings(values);
                        return i;
                    }
                }
            }

            /* enum value not found! */
            crFreeStrings(values);
            return -1;
        }
    }

    return -1;
}
Exemplo n.º 26
0
static char *
crSDPErrorString( int err )
{
	static char buf[512], *temp;
	
	sprintf( buf, "err=%d", err );
	
#define X(x)	crStrcpy(buf,x); break
  
	switch ( err )
	{
	case WSAECONNREFUSED:
		X( "connection refused" );
	case WSAECONNRESET:
		X( "connection reset" );
	default:
		FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
					   FORMAT_MESSAGE_FROM_SYSTEM |
					   FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, err,
					   MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
					   (LPTSTR) &temp, 0, NULL );
		if ( temp )
		{
			crStrncpy( buf, temp, sizeof(buf)-1 );
			buf[sizeof(buf)-1] = 0;
		}
	}
  
#undef X
  
	temp = buf + crStrlen(buf) - 1;
	while ( temp > buf && isspace( *temp ) )
	{
		*temp = '\0';
		temp--;
	}
  
	return buf;
}
static void set_default_visual( RenderSPU *render_spu, const char *response )
{
    if (crStrlen(response) > 0) {
        if (crStrstr(response, "rgb"))
                render_spu->default_visual |= CR_RGB_BIT;
        if (crStrstr(response, "alpha"))
                render_spu->default_visual |= CR_ALPHA_BIT;
        if (crStrstr(response, "z") || crStrstr(response, "depth"))
                render_spu->default_visual |= CR_DEPTH_BIT;
        if (crStrstr(response, "stencil"))
                render_spu->default_visual |= CR_STENCIL_BIT;
        if (crStrstr(response, "accum"))
                render_spu->default_visual |= CR_ACCUM_BIT;
        if (crStrstr(response, "stereo"))
                render_spu->default_visual |= CR_STEREO_BIT;
        if (crStrstr(response, "multisample"))
                render_spu->default_visual |= CR_MULTISAMPLE_BIT;
        if (crStrstr(response, "double"))
                render_spu->default_visual |= CR_DOUBLE_BIT;
        if (crStrstr(response, "pbuffer"))
                render_spu->default_visual |= CR_PBUFFER_BIT;
    }
}
Exemplo n.º 28
0
GLint RENDER_APIENTRY
renderspuCreateContext(const char *dpyName, GLint visBits, GLint shareCtx)
{
	ContextInfo *context, *sharedContext = NULL;
	VisualInfo *visual;

	if (shareCtx > 0) {
		sharedContext
			= (ContextInfo *) crHashtableSearch(render_spu.contextTable, shareCtx);
	}

	if (!dpyName || crStrlen(render_spu.display_string)>0)
		dpyName = render_spu.display_string;

	visual = renderspuFindVisual(dpyName, visBits);
	if (!visual)
		return -1;

	context = (ContextInfo *) crCalloc(sizeof(ContextInfo));
	if (!context)
		return -1;
	context->id = render_spu.context_id;
	context->shared = sharedContext;
	if (!renderspu_SystemCreateContext(visual, context, sharedContext))
		return -1;

	crHashtableAdd(render_spu.contextTable, render_spu.context_id, context);
	render_spu.context_id++;

	/*
	crDebug("Render SPU: CreateContext(%s, 0x%x) returning %d",
					dpyName, visBits, context->id);
	*/

	return context->id;
}
Exemplo n.º 29
0
DECLEXPORT(void) STATE_APIENTRY 
crStateGLSLProgramCacheUniforms(GLuint program, GLsizei maxcbData, GLsizei *cbData, GLvoid *pData)
{
    CRGLSLProgram *pProgram = crStateGetProgramObj(program);
    GLint maxUniformLen, activeUniforms=0, fakeUniformsCount, i, j;
    char *pCurrent = pData;
    GLsizei cbWritten;

    if (!pProgram)
    {
        crWarning("Unknown program %d", program);
        return;
    }

    diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformLen);
    diff_api.GetProgramiv(pProgram->hwid, GL_ACTIVE_UNIFORMS, &activeUniforms);

    *cbData = 0;

    cbWritten = sizeof(GLsizei);
    if (cbWritten>maxcbData)
    {
        crWarning("crStateGLSLProgramCacheUniforms: buffer too small");
        return;
    }
    ((GLsizei*)pCurrent)[0] = activeUniforms;
    fakeUniformsCount = activeUniforms;
    pCurrent += sizeof(GLsizei);

    crDebug("crStateGLSLProgramCacheUniforms: %i active uniforms", activeUniforms);

    if (activeUniforms>0)
    {
        /*+8 to make sure our array uniforms with higher indices and [] will fit in as well*/
        GLchar *name = (GLchar *) crAlloc(maxUniformLen+8);
        GLenum type;
        GLint size;
        GLsizei cbName;
        GLint location;

        if (!name)
        {
            crWarning("crStateGLSLProgramCacheUniforms: no memory");
            return;
        }

        for (i=0; i<activeUniforms; ++i)
        {
            diff_api.GetActiveUniform(pProgram->hwid, i, maxUniformLen, &cbName, &size, &type, name);
            location = diff_api.GetUniformLocation(pProgram->hwid, name);

            if (!crStateGLSLProgramCacheOneUniform(location, cbName, name, &pCurrent, &cbWritten, maxcbData))
                return;

            /* Only one active uniform variable will be reported for a uniform array by glGetActiveUniform,
             * so we insert fake elements for other array elements.
             */
            if (size!=1)
            {
                char *pIndexStr = crStrchr(name, '[');
                GLint firstIndex=1;
                fakeUniformsCount += size;

                crDebug("crStateGLSLProgramCacheUniforms: expanding array uniform, size=%i", size);

                /*For array uniforms it's valid to query location of 1st element as both uniform and uniform[0].
                 *The name returned by glGetActiveUniform is driver dependent,
                 *atleast it's with [0] on win/ati and without [0] on linux/nvidia.
                 */                
                if (!pIndexStr)
                {
                    pIndexStr = name+cbName;
                    firstIndex=0;
                }
                else
                {
                    cbName = pIndexStr-name;
                    if (!crStateGLSLProgramCacheOneUniform(location, cbName, name, &pCurrent, &cbWritten, maxcbData))
                        return;
                }

                for (j=firstIndex; j<size; ++j)
                {
                    sprintf(pIndexStr, "[%i]", j);
                    cbName = crStrlen(name);

                    location = diff_api.GetUniformLocation(pProgram->hwid, name);

                    if (!crStateGLSLProgramCacheOneUniform(location, cbName, name, &pCurrent, &cbWritten, maxcbData))
                        return;
                }
            }
        }

        crFree(name);
    }

    if (fakeUniformsCount!=activeUniforms)
    {
        ((GLsizei*)pData)[0] = fakeUniformsCount;
        crDebug("FakeCount %i", fakeUniformsCount);
    }

    *cbData = cbWritten;

    CRASSERT((pCurrent-((char*)pData))==cbWritten);
}
Exemplo n.º 30
0
/**
 * This function is called by MakeCurrent() and determines whether or
 * not a new rendering context should be bound to Chromium or the native
 * OpenGL.
 * \return  GL_FALSE if native OpenGL should be used, or GL_TRUE if Chromium
 *          should be used.
 */
static GLboolean
stubCheckUseChromium( WindowInfo *window )
{
	int x, y;
	unsigned int w, h;

	/* If the provided window is CHROMIUM, we're clearly intended
	 * to create a CHROMIUM context.
	 */
	if (window->type == CHROMIUM)
		return GL_TRUE;

	if (stub.ignoreFreeglutMenus) {
		const char *glutMenuTitle = "freeglut menu";
		char title[1000];
		GetWindowTitle(window, title);
		if (crStrcmp(title, glutMenuTitle) == 0) {
			crDebug("GL faker: Ignoring freeglut menu window");
			return GL_FALSE;
		}
	}

	/*  If the user's specified a window count for Chromium, see if
		*  this window satisfies that criterium.
		*/
	stub.matchChromiumWindowCounter++;
	if (stub.matchChromiumWindowCount > 0) {
		if (stub.matchChromiumWindowCounter != stub.matchChromiumWindowCount) {
			crDebug("Using native GL, app window doesn't meet match_window_count");
			return GL_FALSE;
		}
	}

	/* If the user's specified a window list to ignore, see if this
	 * window satisfies that criterium.
	 */
	if (stub.matchChromiumWindowID) {
		GLuint i;

		for (i = 0; i <= stub.numIgnoreWindowID; i++) {
			if (stub.matchChromiumWindowID[i] == stub.matchChromiumWindowCounter) {
				crDebug("Ignore window ID %d, using native GL", stub.matchChromiumWindowID[i]);
				return GL_FALSE;
			}
		}
	}

	/* If the user's specified a minimum window size for Chromium, see if
	 * this window satisfies that criterium. 
	 */
	if (stub.minChromiumWindowWidth > 0 && 
	    stub.minChromiumWindowHeight > 0) {
		stubGetWindowGeometry( window, &x, &y, &w, &h );
		if (w >= stub.minChromiumWindowWidth && 
		    h >= stub.minChromiumWindowHeight) {

			/* Check for maximum sized window now too */
			if (stub.maxChromiumWindowWidth && 
			    stub.maxChromiumWindowHeight) {
				if (w < stub.maxChromiumWindowWidth &&
				    h < stub.maxChromiumWindowHeight)
					return GL_TRUE;
				else 
					return GL_FALSE;
			}

			return GL_TRUE;
		}
		crDebug("Using native GL, app window doesn't meet minimum_window_size");
		return GL_FALSE;
	}
	else if (stub.matchWindowTitle) {
		/* If the user's specified a window title for Chromium, see if this
		 * window satisfies that criterium.
		 */
		GLboolean wildcard = GL_FALSE;
		char title[1000];
		char *titlePattern;
		int len;
		/* check for leading '*' wildcard */
		if (stub.matchWindowTitle[0] == '*') {
			titlePattern = crStrdup( stub.matchWindowTitle + 1 );
			wildcard = GL_TRUE;
		}
		else {
			titlePattern = crStrdup( stub.matchWindowTitle );
		}
		/* check for trailing '*' wildcard */
		len = crStrlen(titlePattern);
		if (len > 0 && titlePattern[len - 1] == '*') {
			titlePattern[len - 1] = '\0'; /* terminate here */
			wildcard = GL_TRUE;
		}

		GetWindowTitle( window, title );
		if (title[0]) {
			if (wildcard) {
				if (crStrstr(title, titlePattern)) {
					crFree(titlePattern);
					return GL_TRUE;
				}
			}
			else if (crStrcmp(title, titlePattern) == 0) {
				crFree(titlePattern);
				return GL_TRUE;
			}
		}
		crFree(titlePattern);
		crDebug("Using native GL, app window title doesn't match match_window_title string (\"%s\" != \"%s\")", title, stub.matchWindowTitle);
		return GL_FALSE;
	}

	/* Window title and size don't matter */
	CRASSERT(stub.minChromiumWindowWidth == 0);
	CRASSERT(stub.minChromiumWindowHeight == 0);
	CRASSERT(stub.matchWindowTitle == NULL);

	/* User hasn't specified a width/height or window title.
	 * We'll use chromium for this window (and context) if no other is.
	 */

	return GL_TRUE;  /* use Chromium! */
}