Example #1
0
/*!
\brief fills an integer array with tokens extracted from a string
\author Xanathar
\return int the number of number read from the string
\param str the string
\param array the array
\param maxsize the size of array
\param defval -1 -> the default value for uninitialized items
\param base the base for number conversion
\deprecated This is part of the old XSS stuff.
*/
int fillIntArray(char* str, int *array, int maxsize, int defval, int base)
{
	int i=0;
	char tmp[1048];
	char *mem;

	if (strlen(str) > 1024) {
		mem = new char[strlen(str)+5];
	} else mem = tmp;  //xan -> we avoid dyna-alloc for strs < 1K
	strcpy(tmp, str);

	char *s;
	char *delimiter = " ";

	if (base != baseInArray) for (i = 0; i < maxsize; i++) array[i] = defval;

	i = 0;

	s = strtok(tmp,delimiter);

	while ((s!=NULL)&&(i < maxsize)) {
		if (base == baseInArray) {
			array[i] = str2num(s, array[i]);
			i++;
		}
		else {
			array[i++] = str2num(s, base);
		}
		s = strtok(NULL, delimiter);
	}

	if (mem != tmp) safedeletearray(mem);
	return i;
}
Example #2
0
bool 
ShaderD3D11::free()
{
    for(auto it = _parameters.begin(); it != _parameters.end(); it++)
    {
        safedelete((*it));
    }

    _parameters.erase(_parameters.begin(), _parameters.end());
    for (auto it = _techniques.begin(); it != _techniques.end(); it++)
    {
        safedelete((*it));
    }

    for (auto it = _shaderParameterValues.begin(); it != _shaderParameterValues.end(); it++)
    {
        _deviceInterface->shaderValueFactory()->removeShaderParameterValue (*it);
    }

    for (auto it = _constantBuffers.begin(); it != _constantBuffers.end(); it++)
    {
        safedelete (*it);
    }

    _shaderParameterValues.clear();
    _meshParameters.clear();
    _techniqueParameters.clear();
    _parameters.clear();
    _techniques.clear();
    _constantBuffers.clear();

    safedelete (_effect);
    safedeletearray(_compiledBuffer);

    return true;
}
VertexDeclarationD3D11::~VertexDeclarationD3D11()
{
    _declaration = std::vector <Ibl::VertexElement>();
    safedeletearray(_vertexAttributes);
}
Example #4
0
bool 
ShaderD3D11::createEffect ()
{
    try
    {        
        uint32_t hlslFlags = 0;

        {
            hlslFlags = D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY;
        }
    
        ID3D10Blob * shaderCode = 0;
        ID3D10Blob * errors = 0;

        std::vector<D3D10_SHADER_MACRO>       vectorDefines;
        if (_defines.size() > 0)
        {
            for (auto it = _defines.begin(); it != _defines.end(); it++)
            {
                D3D10_SHADER_MACRO macro = {(*it).first.c_str(), (*it).second.c_str()};
                vectorDefines.push_back (macro);
            }
            D3D10_SHADER_MACRO nullMacro = {0, 0};
            vectorDefines.push_back (nullMacro);
            
            _hash.build(shaderStream());
        
            if(FAILED(D3DCompile(shaderStream().c_str(), shaderStream().size(), 0, (const D3D_SHADER_MACRO*)&*vectorDefines.begin(), nullptr, "", "fx_5_0", 
                                  hlslFlags, 0, &shaderCode, &errors)))
            { 
        
                // LOG ("Failed to compile ... " << shaderStream() << "\n");
                LOG ("Failed to compile " << IShader::filePathName());
        
                if(errors) 
                { 
        
                    char* buffer = new char[errors->GetBufferSize()+1];
                    memset(&buffer[0], 0, errors->GetBufferSize()+1);
                    memcpy(&buffer[0], errors->GetBufferPointer(), errors->GetBufferSize());
                    // LOG ("Error Compiling ShaderD3D11" << buffer);
        
                    generateDumpFile(IShader::filePathName(), buffer, shaderStream());
        
                    delete[] (buffer);
                } 
        
                return false;
            } 
        }
        else
        {
            _hash.build(shaderStream());
            if(FAILED(D3DCompile(shaderStream().c_str(), shaderStream().size(), 0, 0, nullptr, "", "fx_5_0", 
                                 D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY | D3DCOMPILE_SKIP_OPTIMIZATION
                                 , 0,  &shaderCode, &errors)))
            { 
                LOG ("Failed to compile " << IShader::filePathName());
        
                // Open file and dump error information.
        
                if(errors) 
                { 
                    char* buffer = new char[errors->GetBufferSize()+1];
                    memset(&buffer[0], 0, errors->GetBufferSize()+1);
                    memcpy(&buffer[0], errors->GetBufferPointer(), errors->GetBufferSize());
                    generateDumpFile(IShader::filePathName(), buffer, shaderStream());
                    LOG ("Error Compiling ShaderD3D11" << buffer);
                    delete[] (buffer);
                } 
                return false;
            }
        }
        
        safedeletearray (_compiledBuffer);
        _compiledBufferSize = shaderCode->GetBufferSize();
        _compiledBuffer = new char[_compiledBufferSize];
        memcpy (_compiledBuffer, shaderCode->GetBufferPointer(), _compiledBufferSize * sizeof(char));
     
        // Create effect 
        ID3DX11Effect* effect = 0;
        if(FAILED(D3DX11CreateEffectFromMemory(_compiledBuffer, _compiledBufferSize, 0, _direct3d, &effect))) 
        { 
            LOG ("FAILED to create effect from memory ... \n");
        } 
        else
        {
            _effect = new EffectD3D11 (effect);
            return true;
        }
    }
    catch(...)
    {
        LOG ("Something bad and unknown happened while creating the shader");
    }
    return false;
}