예제 #1
0
/*****************************************************************************
*   FUNCTION :  	GetVirtualAddressOfUncachedMemory
*   DESCRIPTION :   Associates virtual addr with physical memory region
*   INPUTS :		Physical adddress of memory region (page aligned)
*					Size of region to be reserved
*					String identifying point of invocation (for error msgs)
*   OUTPUTS :     	Virtual address associated (or NULL, if failure occurs)
*   DESIGN NOTES :  
*   CAUTIONS :
*****************************************************************************/
extern "C"  PBYTE GetVirtualAddressOfUncachedMemory(
	PBYTE physicalAddress,
	DWORD size,
	char* callerID)
{
	PBYTE virtualAddress;

#define here "GetVirtualAddressOfUncachedMemory"

	FUNC(here);
	if ((ULONG)physicalAddress % PAGE_SIZE) 
	{
		ERRMSG2((TEXT(here "%s: Physical Addr (0x%x) Not Page-Aligned\r\n")), callerID, physicalAddress);
	}
	
	virtualAddress = (PBYTE)VirtualAlloc(
		NULL,
		size,
		MEM_RESERVE,
		PAGE_NOACCESS);
	
	if (virtualAddress == NULL) 
	{
		ERRMSG1((TEXT(here "%s: Virtual Alloc Failed\r\n")), callerID);
		return NULL;
	}
	
	if (!VirtualCopy((PVOID) virtualAddress,
		(PVOID) physicalAddress,
		size,
		PAGE_READWRITE | PAGE_NOCACHE))
	{
		ERRMSG1((TEXT(here "%s: Virtual Copy Failed\r\n")), callerID);
		FreeAllocatedVirtualMemory( virtualAddress );
		return NULL;
	}
	return virtualAddress;
}
예제 #2
0
파일: nurbs.c 프로젝트: gsjaardema/CGNS
int
NurbsSurface (Tcl_Interp *interp, int argc, char* argv [])
{
    int result = TCL_OK;
    GLint uOrder = 4;
    GLint vOrder = 4;
    GLenum type = GL_MAP2_VERTEX_3;
    int nCoords = 3;
    FloatArray uKnot = NewFloatArray ();
    FloatArray vKnot = NewFloatArray ();
    FloatArray cPoint = NewFloatArray ();
    GLfloat samplingTolerance = 50.0;
    GLfloat displayMode = GLU_FILL;
    GLfloat culling = GL_FALSE;
    int iarg;
    int dlist = 0;

    for (iarg = 2; iarg < argc; iarg++) {
        int len = (int)strlen (argv [iarg]);
        if (strncmp (argv [iarg], "-uorder", len) == 0) {
            int val;
            iarg++;
            if (iarg >= argc) ERRMSG ("No value given for -uorder");
            if (Tcl_GetInt (interp, argv [iarg], &val) != TCL_OK ||
                    val < 2 || val > 8)
                ERRMSG2 ("\nInvalid value for -uorder:", argv [iarg]);
            uOrder = val;
        }
        else if (strncmp (argv [iarg], "-vorder", len) == 0) {
            int val;
            iarg++;
            if (iarg >= argc) ERRMSG ("No value given for -vorder");
            if (Tcl_GetInt (interp, argv [iarg], &val) != TCL_OK ||
                    val < 2 || val > 8)
                ERRMSG2 ("\nInvalid value for -vorder:", argv [iarg]);
            vOrder = val;
        }
        else if (strncmp (argv [iarg], "-uknots", len) == 0) {
            if (uKnot->count != 0) ERRMSG ("uknot values already given");
            iarg++;
            while (iarg < argc &&
                    !(argv [iarg][0] == '-' && isalpha(argv [iarg][1]))) {
                double val;
                if (Tcl_GetDouble (interp, argv [iarg], &val) != TCL_OK)
                    ERRMSG ("\nError parsing uknot value");
                if (uKnot->count > 0 &&
                        uKnot->value [uKnot->count-1] > val)
                    ERRMSG ("uknot values not in non-descending order");
                AddFloat (uKnot, (GLfloat)val);
                iarg++;
            }
            iarg--;
        }
        else if (strncmp (argv [iarg], "-vknots", len) == 0) {
            if (vKnot->count != 0) ERRMSG ("vknot values already given");
            iarg++;
            while (iarg < argc &&
                    !(argv [iarg][0] == '-' && isalpha(argv [iarg][1]))) {
                double val;
                if (Tcl_GetDouble (interp, argv [iarg], &val) != TCL_OK)
                    ERRMSG ("\nError parsing uknot value");
                if (vKnot->count > 0 &&
                        vKnot->value [vKnot->count-1] > val)
                    ERRMSG ("vknot values not in non-descending order");
                AddFloat (vKnot, (GLfloat)val);
                iarg++;
            }
            iarg--;
        }
        else if (strncmp (argv [iarg], "-controlpoints", len) == 0) {
            if (cPoint->count != 0) ERRMSG ("controlpoint values already given");
            iarg++;
            while (iarg < argc &&
                    !(argv [iarg][0] == '-' && isalpha(argv [iarg][1]))) {
                double val;
                if (Tcl_GetDouble (interp, argv [iarg], &val) != TCL_OK)
                    ERRMSG ("\nError parsing uknot value");
                AddFloat (cPoint, (GLfloat)val);
                iarg++;
            }
            iarg--;
        }
        else if (strncmp (argv [iarg], "-type", len) == 0) {
            iarg++;
            if (iarg >= argc) ERRMSG ("No -type value given");
            if (strcmp (argv [iarg], "map2vertex3") ==0) {
                type = GL_MAP2_VERTEX_3;
                nCoords = 3;
            } else if (strcmp (argv [iarg], "map2vertex4") == 0) {
                type = GL_MAP2_VERTEX_4;
                nCoords = 4;
            } else if (strcmp (argv [iarg], "map2color4") == 0) {
                type = GL_MAP2_COLOR_4;
                nCoords = 4;
            } else if (strcmp (argv [iarg], "map2normal") == 0) {
                type = GL_MAP2_NORMAL;
                nCoords = 3;
            } else if (strcmp (argv [iarg], "map2texturecoord1") == 0) {
                type = GL_MAP2_TEXTURE_COORD_1;
                nCoords = 1;
            } else if (strcmp (argv [iarg], "map2texturecoord2") == 0) {
                type = GL_MAP2_TEXTURE_COORD_2;
                nCoords = 2;
            } else if (strcmp (argv [iarg], "map2texturecoord3") == 0) {
                type = GL_MAP2_TEXTURE_COORD_3;
                nCoords = 3;
            } else if (strcmp (argv [iarg], "map2texturecoord4") == 0) {
                type = GL_MAP2_TEXTURE_COORD_4;
                nCoords = 4;
            } else
                ERRMSG2 ("not a valid type:", argv [iarg]);
        }
        else if (strncmp (argv [iarg], "-samplingtolerance", len) == 0) {
            double val;
            iarg++;
            if (iarg >= argc) ERRMSG ("No -samplingtolerance value given");
            if (Tcl_GetDouble (interp, argv [iarg], &val) != TCL_OK)
                ERRMSG ("\nError parsing sampling tolerance");
            samplingTolerance = (GLfloat)val;
        }
        else if (strncmp (argv [iarg], "-displaymode", len) == 0) {
            iarg++;
            if (iarg >= argc) ERRMSG ("No -displaymode value given");
            if (strcmp (argv [iarg], "fill") == 0) {
                displayMode = GLU_FILL;
            } else if (strcmp (argv [iarg], "outlinepolygon") == 0) {
                displayMode = GLU_OUTLINE_POLYGON;
            } else if (strcmp (argv [iarg], "outlinepatch") == 0) {
                displayMode = GLU_OUTLINE_PATCH;
            } else {
                ERRMSG2 ("not a valid display mode:", argv [iarg]);
            }
        }
        else if (strncmp (argv [iarg], "-culling", len) == 0) {
            int val;
            iarg++;
            if (iarg >= argc) ERRMSG ("No -culling value given");
            if (Tcl_GetBoolean (interp, argv [iarg], &val) != TCL_OK)
                ERRMSG ("\nError parsing culling value");
            culling = (GLfloat)val;
        }
        else {
            ERRMSG2 ("invalid option:", argv [iarg]);
        }
    }

    if (vKnot->count == 0 || uKnot->count == 0 || cPoint->count == 0)
        ERRMSG ("All of -uknot, -vknot and -cpoint options must be specified");

    /* Now try to guess the remaining arguments and call gluNurbsSurface */
    {
        GLint uKnotCount = uKnot->count;
        GLint vKnotCount = vKnot->count;
        GLint vStride = nCoords;
        GLint uStride = nCoords * (vKnotCount - vOrder);
        static GLUnurbsObj* obj = NULL;
        if (uStride * (uKnotCount - uOrder) != cPoint->count) {
            char buf [80];
            sprintf (buf, "%d", uStride * (uKnotCount - uOrder));
            ERRMSG2 ("Incorrect number of controlpoint coordinates. Expected ",
                     buf);
        }
        /* Theoretically, a nurbs object could be allocated for each
        invocation of NurbsSurface and then freed after the creation
         of the display list. However, this produces a segmentation
         violation on AIX OpenGL 1.0. Thus, only one nurbs object is
         ever allocated and never freed.
            */
        if (obj == NULL) obj = gluNewNurbsRenderer();
        dlist = glGenLists (1);
        gluNurbsProperty (obj, GLU_SAMPLING_TOLERANCE, samplingTolerance);
        gluNurbsProperty (obj, GLU_DISPLAY_MODE, displayMode);
        gluNurbsProperty (obj, GLU_CULLING, culling);
        glNewList (dlist, GL_COMPILE);
        gluBeginSurface (obj);
        gluNurbsSurface (obj, uKnotCount, uKnot->value,
                         vKnotCount, vKnot->value,
                         uStride, vStride, cPoint->value,
                         uOrder, vOrder, type);
        gluEndSurface (obj);
        /* This is never used because of a bug in AIX OpenGL 1.0.
        gluDeleteNurbsObj (obj);
            */
        glEndList();
        glFlush();
    }

done:

    DestroyFloatArray (uKnot);
    DestroyFloatArray (vKnot);
    DestroyFloatArray (cPoint);

    if (result == TCL_OK) {
        char tmp[128];
        sprintf (tmp, "%d", dlist);
        Tcl_SetResult(interp, tmp, TCL_VOLATILE);
    }

    return result;
}