コード例 #1
0
void cacheConfigFile(){
	DWORD l_pos; //first we check if HANDLE is valid
	DWORD l_err;
	BOOL l_rc;
	DWORD l_actual_read;
	char* cText;
	//
	char* key;
	char *value, *value2;
	char* line;
	char _line[1024];
	//
	propCache.count=0;
	comPortList.count=0;
	int i;

	for (i=0;i<CACHE_lIST_SIZE;i++){
		memset(propCache.hash[i].key,0,HASH_KEY_SIZE);
		memset(propCache.hash[i].value,0,HASH_VALUE_SIZE);

	}
	for (i=0;i<COM_LIST_SIZE;i++){
		memset((comPortList.list+i),0,sizeof(COMELEMENT));
	}
	trace("Function cacheConfigFile");
	l_pos = SetFilePointer(configFileHandle, 0, 0, FILE_END);
	LPVOID l_file= LocalAlloc(LPTR, l_pos+1);
	cText = (char *)LocalAlloc(LPTR, l_pos+1);
	SetFilePointer(configFileHandle, 0, 0, FILE_BEGIN);
	l_rc = ReadFile(configFileHandle, l_file, l_pos, &l_actual_read, NULL);
	if (l_rc ==0){
		l_err = GetLastError();
		printErrorMsg(_T("Could not read the config file, reason"),l_err,1,1);
		destroyConfig();
		exit(1);
	}
	*((char*)l_file+l_pos)=0;
	//whe are done, close file
	closeConfigFile();
	convertToANSI((TCHAR *)l_file,l_pos+1,cText,l_pos+1);
	LocalFree(l_file);
	//we have converted everything to ansi so!
	line=0;
	while ((line = fetchNextLine(cText,line,l_pos+1)) != NULL){
		//copy line
		strcpy(_line,line);
		if (isCommentOrEmptyLine(_line)){
			continue;
		}
		splitKeyValue(_line,'=',&key,&value);
		if (stricmp(key,PROP_PORTNAME)==0){
			trace("property PROP_PORTNAME found");
			insertOrReplacePropertyByKey(key, value);
			strcpy(_line,line);
			trace(trim(strupr(_line)));
			continue;
		}

	}
}
コード例 #2
0
void reOpenFiles(){
	DWORD l_pos;//first we check if HANDLE is valid
	DWORD l_err;
	l_pos = SetFilePointer(logFileHandle,0,0,FILE_CURRENT);
	if (l_pos ==INVALID_SET_FILE_POINTER) {
		//--attempt reopen faileL 
		closeLogFile();
		logFileHandle = CreateFile(
			logFile/*lpFileName*/,
			FILE_APPEND_DATA/*dwDesiredAccess*/,
			FILE_SHARE_READ/*dwShareMode*/,
			NULL /*lpSecurityAttributes*/,
			OPEN_ALWAYS/*dwCreationDisposition*/,
			FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN/*dwFlagsAndAttributes*/,
			NULL/*hTemplateFile*/);
		if (logFileHandle == INVALID_HANDLE_VALUE){
			printErrorMsg(_T("Could not open or create logfile, reason"),GetLastError(),0,1);
			destroyConfig();
			exit(1);
		}
	}
	//we have a valid handle here for logfile
	trace("");
	trace("Logfile opened");
	l_pos = SetFilePointer(configFileHandle,0,0,FILE_CURRENT);
	if (l_pos ==INVALID_SET_FILE_POINTER) {
		//--attempt reopen faileL 
		closeConfigFile();//do this anyway
		configFileHandle = CreateFile(
			configFile/*lpFileName*/,
			GENERIC_WRITE|GENERIC_READ/*dwDesiredAccess*/,
			FILE_SHARE_READ/*dwShareMode*/,
			NULL /*lpSecurityAttributes*/,
			OPEN_ALWAYS/*dwCreationDisposition*/,
			FILE_ATTRIBUTE_NORMAL/*dwFlagsAndAttributes*/,
			NULL/*hTemplateFile*/);

		if (configFileHandle == INVALID_HANDLE_VALUE){
			trace("ERR:creating or opening the configuration file refused");
			traceErrorMsg(configFile,_tcslen(configFile)*sizeof(TCHAR));
			trace("ERR:...Check disk space or directory/file permissions");
			printErrorMsg(_T("Could not open or create configfile, system error"),GetLastError(),1,1);
			destroyConfig();
			exit(1);
		}
	}
	trace("Configuration file opened.");
	traceErrorMsg(configFile,_tcslen(configFile)*sizeof(TCHAR));
}
コード例 #3
0
ファイル: config.c プロジェクト: TKr/Wive-ng-rt8186
/**
*   Loads the configuration from file, and stores the config in 
*   respective holders...
*/                 
int loadConfig(char *configFile) {
    struct vifconfig  *tmpPtr;
    struct vifconfig  **currPtr = &vifconf;
    char *token;
    
    // Initialize common config
    initCommonConfig();

    // Test config file reader...
    if(!openConfigFile(configFile)) {
        log(LOG_ERR, 0, "Unable to open configfile from %s", configFile);
    }

    // Get first token...
    token = nextConfigToken();
    if(token == NULL) {
        log(LOG_ERR, 0, "Config file was empty.");
    }

    // Loop until all configuration is read.
    while ( token != NULL ) {
        // Check token...
        if(strcmp("phyint", token)==0) {
            // Got a phyint token... Call phyint parser
            IF_DEBUG log(LOG_DEBUG, 0, "Config: Got a phyint token.");
            tmpPtr = parsePhyintToken();
            if(tmpPtr == NULL) {
                // Unparsable token... Exit...
                closeConfigFile();
                log(LOG_WARNING, 0, "Unknown token '%s' in configfile", token);
                return 0;
            } else {

                IF_DEBUG log(LOG_DEBUG, 0, "IF name : %s", tmpPtr->name);
                IF_DEBUG log(LOG_DEBUG, 0, "Next ptr : %x", tmpPtr->next);
                IF_DEBUG log(LOG_DEBUG, 0, "Ratelimit : %d", tmpPtr->ratelimit);
                IF_DEBUG log(LOG_DEBUG, 0, "Threshold : %d", tmpPtr->threshold);
                IF_DEBUG log(LOG_DEBUG, 0, "State : %d", tmpPtr->state);
                IF_DEBUG log(LOG_DEBUG, 0, "Allowednet ptr : %x", tmpPtr->allowednets);

                // Insert config, and move temppointer to next location...
                *currPtr = tmpPtr;
                currPtr = &tmpPtr->next;
            }
        } 
        else if(strcmp("quickleave", token)==0) {
            // Got a quickleave token....
            IF_DEBUG log(LOG_DEBUG, 0, "Config: Quick leave mode enabled.");
            commonConfig.fastUpstreamLeave = 1;
            
            // Read next token...
            token = nextConfigToken();
            continue;
        } else {
            // Unparsable token... Exit...
            closeConfigFile();
            log(LOG_WARNING, 0, "Unknown token '%s' in configfile", token);
            return 0;
        }
        // Get token that was not recognized by phyint parser.
        token = getCurrentConfigToken();
    }

    // Close the configfile...
    closeConfigFile();

    return 1;
}
コード例 #4
0
ファイル: glfeatures.cpp プロジェクト: 702nADOS/speed-dreams
// Save settings to screen.xml
void GfglFeatures::storeSelection(void* hparmConfig) const
{
    // Display what we have selected.
    dumpSelection();

    // Open the config file if not already done.
    void* hparm = hparmConfig ? hparmConfig : openConfigFile();

    // Write new values.
    GfParmSetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_TEXTURECOMPRESSION,
                 isSelected(TextureCompression)
                 ? GFSCR_ATT_TEXTURECOMPRESSION_ENABLED : GFSCR_ATT_TEXTURECOMPRESSION_DISABLED);
    if (getSupported(TextureMaxSize) != InvalidInt)
        GfParmSetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MAXTEXTURESIZE, pszNoUnit,
                     (tdble)getSelected(TextureMaxSize));
    else
        GfParmRemove(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MAXTEXTURESIZE);

    GfParmSetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTITEXTURING,
                 isSelected(MultiTexturing)
                 ? GFSCR_ATT_MULTITEXTURING_ENABLED : GFSCR_ATT_MULTITEXTURING_DISABLED);
    GfParmSetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLING,
                 isSelected(MultiSampling)
                 ? GFSCR_ATT_MULTISAMPLING_ENABLED : GFSCR_ATT_MULTISAMPLING_DISABLED);
    if (getSupported(MultiSamplingSamples) != InvalidInt)
        GfParmSetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES, pszNoUnit,
                     (tdble)getSelected(MultiSamplingSamples));
    else
        GfParmRemove(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES);


    // Force 'best possible' mode for video initialization when anti-aliasing selected
    if (isSelected(MultiSampling))
    {
        // Use the 'in-test' specs if present, and reset the test state
        // (force a new validation).
        if (GfParmExistsSection(hparm, GFSCR_SECT_INTESTPROPS))
        {
            GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_TESTSTATE,
                         GFSCR_VAL_INPROGRESS);
            GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_VINIT,
                         GFSCR_VAL_VINIT_BEST);
        }

        // Otherwise, use the 'validated' specs ... no new validation needed
        // (if we can en/disable multi-sampling, it means that we already checked
        //  that it was possible, and how much).
        else
        {
            GfParmSetStr(hparm, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_VINIT,
                         GFSCR_VAL_VINIT_BEST);
        }
    }

    GfParmSetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_STEREOVISION,
                 isSelected(StereoVision)
                 ? GFSCR_ATT_STEREOVISION_ENABLED : GFSCR_ATT_STEREOVISION_DISABLED);

    GfParmSetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_BUMPMAPPING,
                 isSelected(BumpMapping)
                 ? GFSCR_ATT_BUMPMAPPING_ENABLED : GFSCR_ATT_BUMPMAPPING_DISABLED);

    if (getSupported(AnisotropicFiltering) != InvalidInt)
        GfParmSetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_ANISOTROPICFILTERING, pszNoUnit,
                     (tdble)getSelected(AnisotropicFiltering));
    else
        GfParmRemove(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_ANISOTROPICFILTERING);

    // Write new params to config file.
    GfParmWriteFile(NULL, hparm, "Screen");

    // Close config file if we open it.
    if (!hparmConfig)
        closeConfigFile(hparm);
}
コード例 #5
0
ファイル: glfeatures.cpp プロジェクト: 702nADOS/speed-dreams
// Load the selected OpenGL features from the config file.
void GfglFeatures::loadSelection(void* hparmConfig)
{
    // Open the config file if not already done.
    void* hparm = hparmConfig ? hparmConfig : openConfigFile();

    // Select the OpenGL features according to the user settings (when relevant)
    // or/and to the supported values (by default, select the max supported values).

    // 1) Double-buffer : not user-customizable.
    _mapSelectedBool[DoubleBuffer] = isSupported(DoubleBuffer);

    // 2) Color buffer depth : not user-customizable.
    _mapSelectedInt[ColorDepth] = getSupported(ColorDepth);

    // 3) Alpha-channel depth : not user-customizable.
    _mapSelectedInt[AlphaDepth] = getSupported(AlphaDepth);

    // 4) Max texture size : load from config file.
    _mapSelectedInt[TextureMaxSize] =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MAXTEXTURESIZE,
                          pszNoUnit, (tdble)getSupported(TextureMaxSize));
    if (_mapSelectedInt[TextureMaxSize] > getSupported(TextureMaxSize))
        _mapSelectedInt[TextureMaxSize] = getSupported(TextureMaxSize);

    // 5) Texture compression : load from config file.
    _mapSelectedBool[TextureCompression] =
        isSupported(TextureCompression)
        && std::string(GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_TEXTURECOMPRESSION,
                                    GFSCR_ATT_TEXTURECOMPRESSION_ENABLED))
        == GFSCR_ATT_TEXTURECOMPRESSION_ENABLED;

    // 6) Multi-texturing : load from config file.
    _mapSelectedBool[MultiTexturing] =
        isSupported(MultiTexturing)
        && std::string(GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTITEXTURING,
                                    GFSCR_ATT_MULTITEXTURING_ENABLED))
        == GFSCR_ATT_MULTITEXTURING_ENABLED;
    _mapSelectedInt[MultiTexturingUnits] =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTITEXTURINGUNITS,
                          pszNoUnit, (tdble)getSupported(TextureMaxSize));
    if (_mapSelectedInt[MultiTexturingUnits] > getSupported(MultiTexturingUnits))
        _mapSelectedInt[MultiTexturingUnits] = getSupported(MultiTexturingUnits);

    // 7) Rectangle textures : not user-customizable.
    _mapSelectedBool[TextureRectangle] = isSupported(TextureRectangle);

    // 8) Non-power-of-2 textures : not user-customizable.
    _mapSelectedBool[TextureNonPowerOf2] = isSupported(TextureNonPowerOf2);

    // 9) Multi-sampling : load from config file.
    const std::string strMultiSamp =
        GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLING,
                     GFSCR_ATT_MULTISAMPLING_ENABLED);
    _mapSelectedBool[MultiSampling] =
        isSupported(MultiSampling)
        && std::string(GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLING,
                                    GFSCR_ATT_MULTISAMPLING_ENABLED))
        == GFSCR_ATT_MULTISAMPLING_ENABLED;

    _mapSelectedInt[MultiSamplingSamples] =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES,
                          pszNoUnit, (tdble)8); // Good but reasonable value.
    if (_mapSelectedInt[MultiSamplingSamples] > getSupported(MultiSamplingSamples))
        _mapSelectedInt[MultiSamplingSamples] = getSupported(MultiSamplingSamples);

    // 10) Stereo Vision : load from config file.
    const std::string strStereoVision =
        GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_STEREOVISION,
                     GFSCR_ATT_STEREOVISION_ENABLED);
    _mapSelectedBool[StereoVision] =
        isSupported(StereoVision)
        && std::string(GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_STEREOVISION,
                                    GFSCR_ATT_STEREOVISION_ENABLED))
        == GFSCR_ATT_STEREOVISION_ENABLED;

    // 11) Bump Mapping : load from config file.
    _mapSelectedBool[BumpMapping] =
        isSupported(BumpMapping)
        && std::string(GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_BUMPMAPPING,
                                    GFSCR_ATT_BUMPMAPPING_ENABLED))
        == GFSCR_ATT_BUMPMAPPING_ENABLED;

    // 12) Anisotropic Filtering : load from config file.
    _mapSelectedInt[AnisotropicFiltering] = (int)GfParmGetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_ANISOTROPICFILTERING,
                                            pszNoUnit, (tdble)getSupported(AnisotropicFiltering));
    // Close config file if we open it.
    if (!hparmConfig)
        closeConfigFile(hparm);

    // Display what we have really selected (after checking / fixing to supported values).
    dumpSelection();
}
コード例 #6
0
ファイル: glfeatures.cpp プロジェクト: 702nADOS/speed-dreams
bool GfglFeatures::checkBestSupport(int nWidth, int nHeight, int nDepth,
                                    bool bAlpha, bool bFullScreen, bool bBump, bool bStereo,int nAniFilt, void* hparmConfig)
{
    // Open the config file if not already done.
    void* hparm = hparmConfig ? hparmConfig : openConfigFile();

    // Get the frame buffer specs that are associated with the detected
    // Open GL features in the config file, if any.
    int nDetWidth, nDetHeight, nDetDepth, nDetAni;
    bool bDetFullScreen, bDetAlpha, bDetBump, bDetStereo;
    bool bPrevSupportFound =
        loadSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo,nDetAni, hparm);

    // Compare with the requested frame buffer specs
    // and run a new supported feature detection if any diffference.
    bool bSupportFound = true;
    if (!bPrevSupportFound || nWidth != nDetWidth || nHeight != nDetHeight || nDepth != nDetDepth
            || bAlpha != bDetAlpha || bFullScreen != bDetFullScreen || bStereo != bDetStereo || bBump != bDetBump || nAniFilt!= nDetAni)
    {
        nDetWidth = nWidth;
        nDetHeight = nHeight;
        nDetDepth = nDepth;
        bDetFullScreen = bFullScreen;
        bDetAlpha = bAlpha;
        bDetStereo = bStereo;
        bDetBump = bBump;
        nDetAni = nAniFilt;
        bSupportFound =
            detectBestSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo, nDetAni);

        // Store support data in any case.
        storeSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo,nDetAni, hparm);

        // If frame buffer specs supported, update relevant user settings and restart.
        if (bSupportFound)
        {
            // Write new user settings about the frame buffer specs
            // (the detection process might have down-casted them ...).
            // Note: Sure the specs are in the 'in-test' state here,
            //       otherwise they would not have changed.
            GfParmSetNum(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_WIN_X, pszNoUnit,
                         (tdble)nDetWidth);
            GfParmSetNum(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_WIN_Y, pszNoUnit,
                         (tdble)nDetHeight);
            GfParmSetNum(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_BPP, pszNoUnit,
                         (tdble)nDetDepth);
            GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_ALPHACHANNEL,
                         bDetAlpha ? GFSCR_VAL_YES : GFSCR_VAL_NO);
            GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_FSCR,
                         bDetFullScreen ? GFSCR_VAL_YES : GFSCR_VAL_NO);

            // But make sure they are not validated yet at restart (only next time if OK).
            GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_TESTSTATE,
                         GFSCR_VAL_TODO);

            // Write new params to config file.
            GfParmWriteFile(NULL, hparm, "Screen");

            // Close the config file ...
            closeConfigFile(hparm);

            // ... as we are restarting ...
            GfuiApp().restart();

            // Next time we pass in this function, loadSupport() will give
            // the right values for all features ...
        }
    }

    if (!hparmConfig)
        closeConfigFile(hparm);

    return bSupportFound;
}
コード例 #7
0
ファイル: glfeatures.cpp プロジェクト: 702nADOS/speed-dreams
void GfglFeatures::storeSupport(int nWidth, int nHeight, int nDepth,
                                bool bAlpha, bool bFullScreen, bool bBump, bool bStereo, int nAniFilt, void* hparmConfig)
{
    // Open the config file if not already done.
    void* hparm = hparmConfig ? hparmConfig : openConfigFile();

    // If there's support for nothing, remove all.
    if (_mapSupportedBool.empty() && _mapSupportedInt.empty())
    {
        // Frame buffer specs.
        GfParmRemoveSection(hparm, GFSCR_SECT_GLDETSPECS);

        // Supported values.
        GfParmRemoveSection(hparm, GFSCR_SECT_GLDETFEATURES);
    }

    // If there's support for anything, store it.
    else
    {
        // Write new frame buffer specs for the stored supported features.
        GfParmSetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_WIN_X, pszNoUnit,
                     (tdble)nWidth);
        GfParmSetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_WIN_Y, pszNoUnit,
                     (tdble)nHeight);
        GfParmSetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BPP, pszNoUnit,
                     (tdble)nDepth);
        GfParmSetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ANISOTROPICFILTERING, pszNoUnit,
                     (tdble)nAniFilt);
        GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ALPHACHANNEL,
                     bAlpha ? GFSCR_VAL_YES : GFSCR_VAL_NO);
        GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_FSCR,
                     bFullScreen ? GFSCR_VAL_YES : GFSCR_VAL_NO);
        GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_STEREOVISION,
                     bStereo ? GFSCR_VAL_YES : GFSCR_VAL_NO);
        GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BUMPMAPPING,
                     bBump ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        // Write new values (remove the ones with no value supported).
        // 1) Double-buffer.
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_DOUBLEBUFFER,
                     isSupported(DoubleBuffer) ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        // 2) Color buffer depth.
        if (getSupported(ColorDepth) != InvalidInt)
            GfParmSetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_COLORDEPTH, pszNoUnit,
                         (tdble)getSupported(ColorDepth));
        else
            GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_COLORDEPTH);

        // 3) Alpha-channel depth.
        if (getSupported(AlphaDepth) != InvalidInt)
            GfParmSetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ALPHADEPTH, pszNoUnit,
                         (tdble)getSupported(AlphaDepth));
        else
            GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ALPHADEPTH);

        // 4) Max texture size.
        if (getSupported(TextureMaxSize) != InvalidInt)
            GfParmSetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MAXTEXTURESIZE, pszNoUnit,
                         (tdble)getSupported(TextureMaxSize));
        else
            GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MAXTEXTURESIZE);

        // 5) Texture compression.
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_TEXTURECOMPRESSION,
                     isSupported(TextureCompression) ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        // 6) Multi-texturing.
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTITEXTURING,
                     isSupported(MultiTexturing) ? GFSCR_VAL_YES : GFSCR_VAL_NO);
        if (getSupported(MultiTexturingUnits) != InvalidInt)
            GfParmSetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTITEXTURINGUNITS, pszNoUnit,
                         (tdble)getSupported(MultiTexturingUnits));
        else
            GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTITEXTURINGUNITS);

        // 7) Rectangle textures).
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_RECTANGLETEXTURES,
                     isSupported(TextureRectangle) ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        // 8) Non-power-of-2 textures.
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_NONPOTTEXTURES,
                     isSupported(TextureNonPowerOf2) ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        // 9) Multi-sampling.
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTISAMPLING,
                     isSupported(MultiSampling) ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        if (getSupported(MultiSamplingSamples) != InvalidInt)
            GfParmSetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES, pszNoUnit,
                         (tdble)getSupported(MultiSamplingSamples));
        else
            GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES);

        // 10) Stereo Vision
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_STEREOVISION,
                     isSupported(StereoVision) ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        // 11) Bump Mapping
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_BUMPMAPPING,
                     isSupported(BumpMapping) ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        // 12) Aniso Filtering
        if (getSupported(AnisotropicFiltering) != InvalidInt)
            GfParmSetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ANISOTROPICFILTERING, pszNoUnit,
                         (tdble)getSupported(AnisotropicFiltering));
        else
            GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ANISOTROPICFILTERING);

    }

    // Write new params to config file.
    GfParmWriteFile(NULL, hparm, "Screen");

    // Close config file if we open it.
    if (!hparmConfig)
        closeConfigFile(hparm);

    // Trace resulting best supported features.
    dumpSupport();
}
コード例 #8
0
ファイル: glfeatures.cpp プロジェクト: 702nADOS/speed-dreams
bool GfglFeatures::loadSupport(int &nWidth, int &nHeight, int &nDepth,
                               bool &bAlpha, bool &bFullScreen, bool &bBump, bool &bStereo, int &nAniFilt,void* hparmConfig)
{
    // Clear support data.
    _mapSupportedBool.clear();
    _mapSupportedInt.clear();

    // Open the config file if not already done.
    void* hparm = hparmConfig ? hparmConfig : openConfigFile();

    // Load the frame buffer specs for the stored supported features.
    nWidth =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_WIN_X, pszNoUnit, 0);
    nHeight =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_WIN_Y, pszNoUnit, 0);
    nDepth =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BPP, pszNoUnit, 0);
    nAniFilt =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ANISOTROPICFILTERING, pszNoUnit, 0);
    bAlpha =
        std::string(GfParmGetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ALPHACHANNEL, GFSCR_VAL_NO))
        == GFSCR_VAL_YES;
    bFullScreen =
        std::string(GfParmGetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_FSCR, GFSCR_VAL_NO))
        == GFSCR_VAL_YES;
    bStereo =
        std::string(GfParmGetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_STEREOVISION, GFSCR_VAL_NO))
        == GFSCR_VAL_YES;
    bBump =
        std::string(GfParmGetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BUMPMAPPING, GFSCR_VAL_NO))
        == GFSCR_VAL_YES;

    // Check that we have something supported, and return if not.
    if (nWidth == 0 || nHeight == 0 || nDepth == 0)
    {
        GfLogTrace("No info found about best supported features for these specs ; "
                   "will need a detection pass.\n");

        // Close config file if we open it.
        if (!hparmConfig)
            closeConfigFile(hparm);

        return false;
    }


    // Here, we only update _mapSupportedXXX only if something relevant in the config file
    // If there's nothing or something not expected, it means no support.

    // 1) Double-buffer.
    const std::string strDoubleBuffer =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_DOUBLEBUFFER, "");
    if (strDoubleBuffer == GFSCR_VAL_YES)
        _mapSupportedBool[DoubleBuffer] = true;
    else if (strDoubleBuffer == GFSCR_VAL_NO)
        _mapSupportedBool[DoubleBuffer] = false;

    // 2) Color buffer depth.
    const int nColorDepth =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_COLORDEPTH,
                          pszNoUnit, (tdble)0);
    if (nColorDepth > 0)
        _mapSupportedInt[ColorDepth] = nColorDepth;

    // 3) Alpha-channel depth.
    const int nAlphaDepth =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ALPHADEPTH,
                          pszNoUnit, (tdble)-1);
    if (nAlphaDepth >= 0)
        _mapSupportedInt[AlphaDepth] = nAlphaDepth;

    // 4) Max texture size.
    const int nMaxTexSize =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MAXTEXTURESIZE,
                          pszNoUnit, (tdble)0);
    if (nMaxTexSize > 0)
        _mapSupportedInt[TextureMaxSize] = nMaxTexSize;

    // 5) Texture compression.
    const std::string strTexComp =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_TEXTURECOMPRESSION, "");
    if (strTexComp == GFSCR_VAL_YES)
        _mapSupportedBool[TextureCompression] = true;
    else if (strTexComp == GFSCR_VAL_NO)
        _mapSupportedBool[TextureCompression] = false;

    // 6) Multi-texturing.
    const std::string strMultiTex =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTITEXTURING, "");
    if (strMultiTex == GFSCR_VAL_YES)
        _mapSupportedBool[MultiTexturing] = true;
    else if (strMultiTex == GFSCR_VAL_NO)
        _mapSupportedBool[MultiTexturing] = false;

    const int nMultiTexUnits =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTITEXTURINGUNITS,
                          pszNoUnit, (tdble)0);
    if (nMultiTexUnits > 0)
        _mapSupportedInt[MultiTexturingUnits] = nMultiTexUnits;

    // 7) Rectangle textures).
    const std::string strRectTex =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_RECTANGLETEXTURES, "");
    if (strRectTex == GFSCR_VAL_YES)
        _mapSupportedBool[TextureRectangle] = true;
    else if (strRectTex == GFSCR_VAL_NO)
        _mapSupportedBool[TextureRectangle] = false;

    // 8) Non-power-of-2 textures.
    const std::string strNonPoTTex =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_NONPOTTEXTURES, "");
    if (strNonPoTTex == GFSCR_VAL_YES)
        _mapSupportedBool[TextureNonPowerOf2] = true;
    else if (strNonPoTTex == GFSCR_VAL_NO)
        _mapSupportedBool[TextureNonPowerOf2] = false;

    // 9) Multi-sampling.
    const std::string strMultiSamp =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTISAMPLING, "");
    if (strMultiSamp == GFSCR_VAL_YES)
        _mapSupportedBool[MultiSampling] = true;
    else if (strMultiSamp == GFSCR_VAL_NO)
        _mapSupportedBool[MultiSampling] = false;

    const int nMultiSampSamples =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES,
                          pszNoUnit, (tdble)0);
    if (nMultiSampSamples > 0)
        _mapSupportedInt[MultiSamplingSamples] = nMultiSampSamples;

    // 10) Stereo Vision
    const std::string strStereoVision =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_STEREOVISION, "");
    if (strStereoVision == GFSCR_VAL_YES)
        _mapSupportedBool[StereoVision] = true;
    else if (strStereoVision == GFSCR_VAL_NO)
        _mapSupportedBool[StereoVision] = false;

    // 11) Bump Mapping.
    const std::string strBumpMapping =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_BUMPMAPPING, "");
    if (strTexComp == GFSCR_VAL_YES) //strTexComp ? Bug ?
        _mapSupportedBool[BumpMapping] = true;
    else if (strTexComp == GFSCR_VAL_NO)
        _mapSupportedBool[BumpMapping] = false;

    // 11) Anisotropic Filtering.
    const int nAF =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ANISOTROPICFILTERING,
                          pszNoUnit, (tdble)0);
    if (nMaxTexSize > 0)
        _mapSupportedInt[AnisotropicFiltering] =nAF;


    // Close config file if we open it.
    if (!hparmConfig)
        closeConfigFile(hparm);

    // Trace best supported features.
    dumpSupport();

    return true;
}