示例#1
0
文件: Logger.cpp 项目: Junios/Falcor
    void Logger::log(Level L, const std::string& msg, bool forceMsgBox)
    {
#if _LOG_ENABLED
        if(sInit)
        {
            if(L >= sVerbosity)
            {
                std::string s = getLogLevelString(L) + std::string("\t") + msg + "\n";
                fprintf_s(sLogFile, "%s", s.c_str());
                fflush(sLogFile);   // Slows down execution, but ensures that the message will be printed in case of a crash
                if (isDebuggerPresent())
                {
                    printToDebugWindow(s);
                }
            }
        }
#endif

        if(L >= Level::Error)
        {
            if(isDebuggerPresent())
            {
                debugBreak();
            }

            forceMsgBox = sShowErrorBox;
        }

        if (forceMsgBox)
        {
            msgBox(msg);
        }
    }
void TriangleBatch::Stripify( TriangleBatch& pNewBatch )
{
#if GD_PLATFORM == GD_PLATFORM_WIN32
	GD_ASSERT( mIndices );

    PrimitiveGroup* strip;
    UInt16          numGroups;

    SetCacheSize(CACHESIZE_GEFORCE1_2);
    SetStitchStrips(true);
    SetMinStripSize(0);
    SetListsOnly(false);

    // Stripify!
    GenerateStrips( mIndices, mIndicesCount, &strip, &numGroups );

    GD_ASSERT( numGroups == 1 );

    // Copy the result in our triangle batch.
    pNewBatch.Allocate( TriangleStrip, strip->numIndices );
    memcpy( pNewBatch.GetIndices(), strip->indices, strip->numIndices*sizeof(UInt16) ); 

    //GD_DELETE_ARRAY(strip);
#else
	debugBreak();
#endif
}
示例#3
0
文件: os.cpp 项目: Tauwasser/mame
	void yield()
	{
#if BX_PLATFORM_WINDOWS
		::SwitchToThread();
#elif BX_PLATFORM_XBOX360
		::Sleep(0);
#elif BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT
		debugOutput("yield is not implemented"); debugBreak();
#else
		::sched_yield();
#endif // BX_PLATFORM_
	}
示例#4
0
文件: os.cpp 项目: Tauwasser/mame
	void sleep(uint32_t _ms)
	{
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
		::Sleep(_ms);
#elif BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT
		BX_UNUSED(_ms);
		debugOutput("sleep is not implemented"); debugBreak();
#else
		timespec req = {(time_t)_ms/1000, (long)((_ms%1000)*1000000)};
		timespec rem = {0, 0};
		::nanosleep(&req, &rem);
#endif // BX_PLATFORM_
	}
示例#5
0
void avgAssert(bool b, const char * pszFile, int line, const char * pszReason)
{
    if (!b) {
        string sDummy;
        static bool bBreak = getEnv("AVG_BREAK_ON_ASSERT", sDummy);
        if (bBreak) {
            debugBreak();
        } else {
            stringstream ss;
            ss << "Assertion failed in " << pszFile << ": " << line << endl;
            if (pszReason) {
                ss << "Reason: " << pszReason << endl;
            }
            dumpBacktrace();
            throw(Exception(AVG_ERR_ASSERT_FAILED, ss.str()));
        }
    }
}
示例#6
0
文件: os.cpp 项目: Tauwasser/mame
	uint32_t getTid()
	{
#if BX_PLATFORM_WINDOWS
		return ::GetCurrentThreadId();
#elif BX_PLATFORM_LINUX || BX_PLATFORM_RPI || BX_PLATFORM_STEAMLINK
		return (pid_t)::syscall(SYS_gettid);
#elif BX_PLATFORM_IOS || BX_PLATFORM_OSX
		return (mach_port_t)::pthread_mach_thread_np(pthread_self() );
#elif BX_PLATFORM_BSD || BX_PLATFORM_NACL
		// Casting __nc_basic_thread_data*... need better way to do this.
		return *(uint32_t*)::pthread_self();
#elif BX_PLATFORM_HURD
		return (pthread_t)::pthread_self();
#else
//#	pragma message "not implemented."
		debugOutput("getTid is not implemented"); debugBreak();
		return 0;
#endif //
	}
示例#7
0
void GPUProgram::reload(const std::string& _code) {
    std::string code = _code;

    // If a syntax error occurs while loading the shader we want to break.  
    // However, it makes no sense to break in this loading code when the
    // error is really in the shader code.  To hack this under MSVC we print
    // out the error as if it were a MSVC error so double clicking will take
    // us there, then break in this code.  To reload the shader we jump back
    // to the top of the loading routine and try again.
     
    bool reloadFromFile = (code == "");

    bool ignore = false;

LOADSHADER:

    if (reloadFromFile) {
 
        if (fileExists(filename)) {
            code = readFileAsString(filename);
        } else {
            error("Critical Error", 
                std::string("Cannot locate file \"") + filename + "\" to reload it.", true);
            exit(-1);
        }
    }

    unit = getUnitFromCode(code, extension);

    glPushAttrib(GL_ALL_ATTRIB_BITS);
    glEnable(unit);

    genPrograms(1, &glProgram);
    bindProgram(unit, glProgram);
    // Clear the error flag.
    glGetError();

    loadProgram(code);

    // Check for load errors
    if ((glGetError() == GL_INVALID_OPERATION) && (! ignore)) {

        int                  pos = 0;
        const unsigned char* msg = NULL;
        getProgramError(pos, msg);

        deletePrograms(1, &glProgram);

        int line = 1;
        int col  = 1;

        // Find the line and column position.
        int x = 0;
        for (x = 0, col = 1; x < pos; ++x, ++col) {
            if (code[x] == '\n') {
                ++line;
                col = 1;
            }
        }

        if (col > 1) {
            --col;
        }

        // Count forward to the end of the line
        int endCol = col;
        while ((x < (int)code.size()) && (code[x] != '\n') && (code[x] != '\r')) {
            ++x;
            ++endCol;
        }

        // Extract the line
        std::string codeLine = code.substr(pos - col + 1, endCol - col);

        // Show the line
        std::string text = format("%s (%d:%d) : %s%s%s", filename.c_str(), line, col, msg, NEWLINE, NEWLINE);
        text += codeLine + NEWLINE;
        for (int i = 0; i < col - 1; ++i) {
            text += " ";
        }

        text += "^";

        #ifdef G3D_WIN32
        {
            // Print the error message in MSVC format
            std::string fullFilename = resolveFilename(filename);
            debugPrintf("%s%s(%d) : GPU Program Error : %s%s%s",
                   NEWLINE, fullFilename.c_str(), line, msg, NEWLINE, NEWLINE);
        }
        #endif

        #ifndef _DEBUG
            Log::common()->print("\n******************************\n");
            Log::common()->print(text);
            exit(-1);
        #endif

        const char* choice[] = {"Debug", "Ignore", "Ignore All", "Exit"};

        switch (prompt("Error Loading Program", text.c_str(), choice, 4, true)) {
        case 0:
            // Debug
            {
                ////////////////////////////////////////////////////////////////////////////
                //                                                                        //
                //                              PUSH  F4                                  //
                //                                                                        // 
                //   If your program breaks on this line in debug mode under Windows,     //
                //   go to the MSVC Debug window and click on the error message (or       //
                //   just press F4 be taken to the error line in your shader.             //
                //                                                                        //
                //   When you change it and press continue, G3D will try to reload your   //
                //   shader (if it came from a file).                                     //
                //                                                                        //
                ////////////////////////////////////////////////////////////////////////////
                debugBreak();
                reloadFromFile = true;
                goto LOADSHADER;
                break;
            }

        case 1:
            // Ignore
            break;

        case 2:
            // Ignore all
            ignore = true;
            break;

        case 3:
            // Exit
            exit(-1);
        }
    }
    bindingTable.parse(code);

    glPopAttrib();
}
Resource* DevILImporter::Import( const String& pFilename, const String& /*pParams*/ )
{
    ILuint  imageName;

    // Load the image. DevIL will guess the type of the image file using it's extension and if needed it's header.
    ilGenImages( 1, &imageName );
    ilBindImage( imageName );

    // Load the image.
    if( !ilLoadImage( const_cast<char*>(pFilename.c_str()) ) )
        throw ResourceImportException( ToString(ilGetError()), Here );

    // Get the image params.
    ILint bytesPerPixel   = ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL );
    ILint imgFormat       = ilGetInteger( IL_IMAGE_FORMAT );
    ILint imgWidth        = ilGetInteger( IL_IMAGE_WIDTH );
    ILint imgHeight       = ilGetInteger( IL_IMAGE_HEIGHT );

    // We do not support palettized texture currently, so un-palettize them!
    if( imgFormat == IL_COLOR_INDEX )
    {
        switch( ilGetInteger( IL_PALETTE_TYPE ) )
        {
        case IL_PAL_RGB24:
        case IL_PAL_RGB32:
            imgFormat = IL_RGB;
            break;
        case IL_PAL_BGR24:
        case IL_PAL_BGR32:
            imgFormat = IL_BGR;
            break;
        case IL_PAL_RGBA32:
            imgFormat = IL_RGBA;
            break;
        case IL_PAL_BGRA32:
            imgFormat = IL_BGRA;
            break;
        default:
            debugBreak();
        }

        ilConvertImage( imgFormat, IL_UNSIGNED_BYTE );
        bytesPerPixel = ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL );
        imgFormat     = ilGetInteger( IL_IMAGE_FORMAT );
    }

    // Find what is the gamedesk internal image format that will be used.
    Image::Format gdImgFormat = GetImageFormat( imgFormat, bytesPerPixel );

    Image newImage;
    newImage.Create( imgWidth, imgHeight, gdImgFormat );
    memcpy( newImage.GetData(), ilGetData(), imgWidth*imgHeight*bytesPerPixel );

    Texture* newTexture = NULL;

    // Allocate and create using image.
    if( imgWidth == 1 || imgHeight == 1 )
    {
        Texture1D* tex = Cast<Texture1D>(Texture1D::StaticClass()->AllocateNew( pFilename ));
        tex->Create( newImage );
        newTexture = tex;
    }
    else
    {
        Texture2D* tex = Cast<Texture2D>(Texture2D::StaticClass()->AllocateNew( pFilename ));
        tex->Create( newImage );
        newTexture = tex;
    }

    // The DevIL copy of the image is not needed anymore, so destroy it.
    ilDeleteImages( 1, &imageName );

    return newTexture;
}
示例#9
0
void VertexList::Reorder( TriangleBatch& pUnorderedStrip )
{
#if GD_PLATFORM == GD_PLATFORM_WIN32
    Vector3f*   newPositions    = NULL;
    Vector3f*   newNormals      = NULL;
    Color4f*    newColors       = NULL;
    Vector2f*   newTexCoords    = NULL;
    Vector2f*   newTexCoords_2  = NULL;

    PrimitiveGroup  unorderedPrimitiveGroup;
    PrimitiveGroup* orderedPrimitiveGroup;

    unorderedPrimitiveGroup.type        = pUnorderedStrip.GetBatchType() == TriangleBatch::TriangleStrip? PT_STRIP :
    pUnorderedStrip.GetBatchType() == TriangleBatch::TriangleList ? PT_LIST : PT_FAN;

    unorderedPrimitiveGroup.numIndices  = pUnorderedStrip.GetIndicesCount();
    unorderedPrimitiveGroup.indices     = GD_NEW_ARRAY(UInt16, unorderedPrimitiveGroup.numIndices, this, "Engine::Graphic::VertexList");
    memcpy( unorderedPrimitiveGroup.indices, pUnorderedStrip.GetIndices(), sizeof(UInt16)*unorderedPrimitiveGroup.numIndices );

    // Remap!
    RemapIndices( &unorderedPrimitiveGroup, 1, mVertexCount, &orderedPrimitiveGroup );

    UInt16*     oldIndices = unorderedPrimitiveGroup.indices;
    UInt16*     newIndices = orderedPrimitiveGroup->indices;

    if( mPositions )
        newPositions = GD_NEW_ARRAY(Vector3f, mVertexCount, this, "Engine::Graphic::VertexList::Positions");

    if( mNormals )
        newNormals = GD_NEW_ARRAY(Vector3f, mVertexCount, this, "Engine::Graphic::VertexList::Normals");

    if( mColors )
        newColors = GD_NEW_ARRAY(Color4f, mVertexCount, this, "Engine::Graphic::VertexList::Colors");

    if( mTexCoords )
        newTexCoords = GD_NEW_ARRAY(Vector2f, mVertexCount, this, "Engine::Graphic::VertexList::TexCoords");

    if( mTexCoords_2 )
        newTexCoords_2 = GD_NEW_ARRAY(Vector2f, mVertexCount, this, "Engine::Graphic::VertexList::TexCoords");

    for( UInt32 iIndex = 0; iIndex < orderedPrimitiveGroup->numIndices; iIndex++ )
    {
        // Grab old index.
        UInt16 oldIndex = oldIndices[iIndex];

        // Grab new index.
        UInt16 newIndex = newIndices[iIndex];

        if( mPositions )
            newPositions[newIndex] = mPositions[oldIndex];

        if( mNormals )
            newNormals[newIndex] = mNormals[oldIndex];

        if( mColors )
            newColors[newIndex] = mColors[oldIndex];

        if( mTexCoords )
            newTexCoords[newIndex] = mTexCoords[oldIndex];

        if( mTexCoords_2 )
            newTexCoords_2[newIndex] = mTexCoords_2[oldIndex];
    }

    if( mPositions )
    {
        GD_DELETE_ARRAY(mPositions);
        mPositions = newPositions;
    }

    if( mNormals )
    {
        GD_DELETE_ARRAY(mNormals);
        mNormals = newNormals;
    }

    if( mColors )
    {
        GD_DELETE_ARRAY(mColors);
        mColors = newColors;
    }

    if( mTexCoords )
    {
        GD_DELETE_ARRAY(mTexCoords);
        mTexCoords = newTexCoords;
    }

    if( mTexCoords_2 )
    {
        GD_DELETE_ARRAY(mTexCoords_2);
        mTexCoords_2 = newTexCoords_2;
    }

    // Return the ordered triangle strip.
    memcpy( pUnorderedStrip.GetIndices(), orderedPrimitiveGroup->indices, orderedPrimitiveGroup->numIndices*sizeof(UInt16) );

    //    GD_DELETE(orderedPrimitiveGroup);
#else
	debugBreak();
#endif
}