void PsychGLColor4f(PsychWindowRecordType *windowRecord, float r, float g, float b, float a) { double colors[4]; colors[0] = r; colors[1] = g; colors[2] = b; colors[3] = a; PsychSetArrayColor(windowRecord, 0, 4, colors, NULL); }
PsychError SCREENFrameOval(void) { PsychRectType rect; double numSlices, outerRadius, xScale, yScale, xTranslate, yTranslate, rectY, rectX, penWidth, penHeight, penSize, innerRadius; PsychWindowRecordType *windowRecord; psych_bool isArgThere, isclassic; double *xy, *colors; unsigned char *bytecolors; double* penSizes; int numRects, i, nc, mc, nrsize; GLUquadricObj *diskQuadric; //all sub functions should have these two lines PsychPushHelp(useString, synopsisString,seeAlsoString); if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);} //check for superfluous arguments PsychErrorExit(PsychCapNumInputArgs(6)); //The maximum number of inputs PsychErrorExit(PsychCapNumOutputArgs(0)); //The maximum number of outputs //get the window record from the window record argument and get info from the window record PsychAllocInWindowRecordArg(kPsychUseDefaultArgPosition, TRUE, &windowRecord); // Query, allocate and copy in all vectors... numRects = 4; nrsize = 0; colors = NULL; bytecolors = NULL; mc = nc = 0; // The negative position -3 means: xy coords are expected at position 3, but they are optional. // NULL means - don't want a size's vector. PsychPrepareRenderBatch(windowRecord, -3, &numRects, &xy, 2, &nc, &mc, &colors, &bytecolors, 4, &nrsize, &penSizes, FALSE); isclassic = PsychIsGLClassic(windowRecord); // Only up to one rect provided? if (numRects <= 1) { // Get the oval and draw it: PsychCopyRect(rect, windowRecord->clientrect); isArgThere=PsychCopyInRectArg(kPsychUseDefaultArgPosition, FALSE, rect); if (isArgThere && IsPsychRectEmpty(rect)) return(PsychError_none); numRects = 1; // Get the pen width and height arguments penWidth=1; penHeight=1; PsychCopyInDoubleArg(4, FALSE, &penWidth); PsychCopyInDoubleArg(5, FALSE, &penHeight); penSize = (penWidth > penHeight) ? penWidth : penHeight; } else { // Multiple ovals provided. Set up the first one: PsychCopyRect(rect, &xy[0]); penSize = penSizes[0]; } // Create quadric object: if (isclassic) diskQuadric = gluNewQuadric(); // Draw all ovals (one or multiple): for (i=0; i < numRects;) { // Per oval color provided? If so then set it up. If only one common color // was provided then PsychPrepareRenderBatch() has already set it up. if (nc>1) { // Yes. Set color for this specific item: PsychSetArrayColor(windowRecord, i, mc, colors, bytecolors); } // Per oval penSize provided? If so, set it up. Otherwise keep at default size // common for all ovals, set by code outside loop: if (nrsize > 1) penSize = penSizes[i]; // Compute drawing parameters for ellipse: if (!IsPsychRectEmpty(rect)) { //The glu disk object location and size with a center point and a radius, //whereas FrameOval accepts a bounding rect. Converting from one set of parameters //to the other we should careful what we do for rects size of even number of pixels in length. PsychGetCenterFromRectAbsolute(rect, &xTranslate, &yTranslate); rectY=PsychGetHeightFromRect(rect); rectX=PsychGetWidthFromRect(rect); if(rectX == rectY){ xScale=1; yScale=1; outerRadius=rectX/2; }else if(rectX > rectY){ xScale=1; yScale=rectY/rectX; outerRadius=rectX/2; }else { yScale=1; xScale=rectX/rectY; outerRadius=rectY/2; } numSlices = 3.14159265358979323846 * 2 * outerRadius; innerRadius = outerRadius - penSize; innerRadius = (innerRadius < 0) ? 0 : innerRadius; if (isclassic) { // Draw: Set up position, scale and size via matrix transform: glPushMatrix(); glTranslated(xTranslate, yTranslate, 0); glScaled(xScale, yScale, 1); // Compute disk quadric for given params: This is awfully slow and would // benefit a lot from shader magic on modern GPUs: gluDisk(diskQuadric, innerRadius, outerRadius, (int) numSlices, 1); glPopMatrix(); } else { PsychDrawDisc(windowRecord, (float) xTranslate, (float) yTranslate, (float) innerRadius, (float) outerRadius, (int) numSlices, (float) xScale, (float) yScale, 0, 360); } } // Done with this one. Set up the next one, if any... i++; if (i < numRects) { PsychCopyRect(rect, &xy[i*4]); } // Next oval. } // Release quadric object: if (isclassic) gluDeleteQuadric(diskQuadric); // Mark end of drawing op. This is needed for single buffered drawing: PsychFlushGL(windowRecord); // All Psychfunctions require this. return(PsychError_none); }
PsychError SCREENFillOval(void) { PsychRectType rect; double numSlices, radius, xScale, yScale, xTranslate, yTranslate, rectY, rectX; PsychWindowRecordType *windowRecord; psych_bool isArgThere; double *xy, *colors; unsigned char *bytecolors; int numRects, i, nc, mc, nrsize; GLUquadricObj *diskQuadric; double perfectUpToMaxDiameter; static double perfectUpToMaxDiameterOld = 0; //all sub functions should have these two lines PsychPushHelp(useString, synopsisString,seeAlsoString); if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);} //check for superfluous arguments PsychErrorExit(PsychCapNumInputArgs(4)); //The maximum number of inputs PsychErrorExit(PsychCapNumOutputArgs(0)); //The maximum number of outputs //get the window record from the window record argument and get info from the window record PsychAllocInWindowRecordArg(kPsychUseDefaultArgPosition, TRUE, &windowRecord); perfectUpToMaxDiameter = PsychGetWidthFromRect(windowRecord->clientrect); if (PsychGetHeightFromRect(windowRecord->clientrect) < perfectUpToMaxDiameter) perfectUpToMaxDiameter = PsychGetHeightFromRect(windowRecord->clientrect); PsychCopyInDoubleArg(4, kPsychArgOptional, &perfectUpToMaxDiameter); if ((perfectUpToMaxDiameter != perfectUpToMaxDiameterOld) || (windowRecord->fillOvalDisplayList == 0)) { perfectUpToMaxDiameterOld = perfectUpToMaxDiameter; // Compute number of subdivisions (slices) to provide a perfect oval, i.e., one subdivision for each // distance unit on the circumference of the oval. numSlices=3.14159265358979323846 * perfectUpToMaxDiameter; // Destroy old display list so it gets rebuilt with the new numSlices setting: if (windowRecord->fillOvalDisplayList != 0) { glDeleteLists(windowRecord->fillOvalDisplayList, 1); windowRecord->fillOvalDisplayList = 0; } } // Already cached display list for filled ovals for this windowRecord available? if (windowRecord->fillOvalDisplayList == 0) { // Nope. Create our prototypical filled oval: // Generate a filled disk of that radius and subdivision and store it in a display list: diskQuadric=gluNewQuadric(); windowRecord->fillOvalDisplayList = glGenLists(1); glNewList(windowRecord->fillOvalDisplayList, GL_COMPILE); gluDisk(diskQuadric, 0, 1, (int) numSlices, 1); glEndList(); gluDeleteQuadric(diskQuadric); // Display list ready for use in this and all future drawing calls for this windowRecord. } // Query, allocate and copy in all vectors... numRects = 4; nrsize = 0; colors = NULL; bytecolors = NULL; mc = nc = 0; // The negative position -3 means: xy coords are expected at position 3, but they are optional. // NULL means - don't want a size's vector. PsychPrepareRenderBatch(windowRecord, -3, &numRects, &xy, 2, &nc, &mc, &colors, &bytecolors, 0, &nrsize, NULL); // Only up to one rect provided? if (numRects <= 1) { // Get the oval and draw it: PsychCopyRect(rect, windowRecord->clientrect); isArgThere=PsychCopyInRectArg(kPsychUseDefaultArgPosition, FALSE, rect); if (isArgThere && IsPsychRectEmpty(rect)) return(PsychError_none); numRects = 1; } else { // Multiple ovals provided. Set up the first one: PsychCopyRect(rect, &xy[0]); } // Draw all ovals (one or multiple): for (i=0; i<numRects;) { // Per oval color provided? If so then set it up. If only one common color // was provided then PsychPrepareRenderBatch() has already set it up. if (nc>1) { // Yes. Set color for this specific item: PsychSetArrayColor(windowRecord, i, mc, colors, bytecolors); } // Compute drawing parameters for ellipse: if (!IsPsychRectEmpty(rect)) { //The glu disk object location and size with a center point and a radius, //whereas FillOval accepts a bounding rect. Converting from one set of parameters //to the other we should careful what we do for rects size of even number of pixels in length. PsychGetCenterFromRectAbsolute(rect, &xTranslate, &yTranslate); rectY=PsychGetHeightFromRect(rect); rectX=PsychGetWidthFromRect(rect); if(rectX == rectY){ xScale=1; yScale=1; radius=rectX/2; }else if(rectX > rectY){ xScale=1; yScale=rectY/rectX; radius=rectX/2; }else if(rectY > rectX){ yScale=1; xScale=rectX/rectY; radius=rectY/2; } // Draw: Set up position, scale and size via matrix transform: glPushMatrix(); glTranslated(xTranslate,yTranslate,0); glScaled(xScale * radius, yScale * radius, 1); // Draw cached disk object (stored in display list): glCallList(windowRecord->fillOvalDisplayList); // Done. glPopMatrix(); } // Done with this one. Set up the next one, if any... i++; if (i < numRects) PsychCopyRect(rect, &xy[i*4]); // Next oval. } // Mark end of drawing op. This is needed for single buffered drawing: PsychFlushGL(windowRecord); //All psychfunctions require this. return(PsychError_none); }
PsychError SCREENFrameRect(void) { PsychColorType color; PsychRectType rect; PsychWindowRecordType *windowRecord; int whiteValue; psych_bool isArgThere; double penSize, lf, fudge; GLdouble dVals[4]; double *xy, *colors, *penSizes; unsigned char *bytecolors; int numRects, i, j, nc, mc, nrsize; //all sub functions should have these two lines PsychPushHelp(useString, synopsisString,seeAlsoString); if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);}; //check for superfluous arguments PsychErrorExit(PsychCapNumInputArgs(4)); //The maximum number of inputs PsychErrorExit(PsychCapNumOutputArgs(0)); //The maximum number of outputs // Get tweakable correction factor for framerect: lf = PsychPrefStateGet_FrameRectCorrection(); //get the window record from the window record argument and get info from the window record PsychAllocInWindowRecordArg(1, kPsychArgRequired, &windowRecord); // Query, allocate and copy in all vectors... numRects = 4; nrsize = 0; colors = NULL; bytecolors = NULL; penSizes = NULL; // The negative position -3 means: xy coords are expected at position 3, but they are optional. // NULL means - don't want a size's vector. PsychPrepareRenderBatch(windowRecord, -3, &numRects, &xy, 2, &nc, &mc, &colors, &bytecolors, 4, &nrsize, &penSizes); // Default rect is fullscreen: PsychCopyRect(rect, windowRecord->rect); // Only up to one rect provided? if (numRects <= 1) { // Get the rect and draw it isArgThere=PsychCopyInRectArg(kPsychUseDefaultArgPosition, FALSE, rect); if (isArgThere && IsPsychRectEmpty(rect)) return(PsychError_none); numRects = 1; } // Pen size starts as "undefined", just to make sure it gets initially set: penSize = -DBL_MAX; // Framed rect drawing loop: for (i=0; i<numRects; i++) { // Multiple rects to draw or single iteration to draw provided rect? if (numRects > 1) { // Multi-Rect drawing: Assign next rect from array and setup corresponding // color and penSize... // Assign rect: rect[kPsychLeft] = xy[i*4 + 0]; rect[kPsychTop] = xy[i*4 + 1]; rect[kPsychRight] = xy[i*4 + 2]; rect[kPsychBottom] = xy[i*4 + 3]; // Per rect color provided? if (nc>1) { // Yes. Set color for this specific rect: PsychSetArrayColor(windowRecord, i, mc, colors, bytecolors); } } else { // Only one single rect to draw in this single loop iteration. // The rect is already set up in 'rect', and the drawing color has // been set as well by PsychPrepareRenderBatch(). penSize has been // set by that routine as well in penSizes[0], so we don't have // anything to do here... // NO OP. } j = (nrsize > 1) ? i : 0; if (penSizes[j] != penSize) { penSize = penSizes[j]; if (lf != -1) glLineWidth((GLfloat) penSize); } if (IsPsychRectEmpty(rect)) continue; if (lf == -1) { // New style rendering: More robust against variations in GPU implementations: fudge = penSize; glRectd(rect[kPsychLeft], rect[kPsychTop], rect[kPsychRight], rect[kPsychTop] + fudge); glRectd(rect[kPsychLeft], rect[kPsychBottom], rect[kPsychRight], rect[kPsychBottom] - fudge); glRectd(rect[kPsychLeft], rect[kPsychTop]+fudge, rect[kPsychLeft]+fudge, rect[kPsychBottom]-fudge); glRectd(rect[kPsychRight]-fudge, rect[kPsychTop]+fudge, rect[kPsychRight], rect[kPsychBottom]-fudge); } else { // Old style: Has a couple of problems in corner cases. Left for now as reference... if (penSize > 1) { // Width > 1 fudge = (penSize > 1) ? lf * penSize/2 : 0.0; glBegin(GL_LINES); // Draw 4 separate segments, extend the left and right // vertical segments by half a penWidth. glVertex2d(rect[kPsychLeft], rect[kPsychTop] - fudge); glVertex2d(rect[kPsychLeft], rect[kPsychBottom] + fudge); glVertex2d(rect[kPsychRight], rect[kPsychTop]); glVertex2d(rect[kPsychLeft], rect[kPsychTop]); glVertex2d(rect[kPsychRight], rect[kPsychBottom] + fudge); glVertex2d(rect[kPsychRight], rect[kPsychTop] - fudge); glVertex2d(rect[kPsychRight], rect[kPsychBottom]); glVertex2d(rect[kPsychLeft], rect[kPsychBottom]); glEnd(); } else { // Width <= 1: Simple case... glBegin(GL_LINE_LOOP); glVertex2d(rect[kPsychLeft], rect[kPsychBottom]); glVertex2d(rect[kPsychLeft], rect[kPsychTop]); glVertex2d(rect[kPsychRight], rect[kPsychTop]); glVertex2d(rect[kPsychRight], rect[kPsychBottom]); glEnd(); } } // Next rect... } // Need to reset line width? if (penSize!=1 && lf!=-1) glLineWidth(1); // Mark end of drawing op. This is needed for single buffered drawing: PsychFlushGL(windowRecord); return(PsychError_none); }
// Batch-drawing version of DrawTexture: PsychError SCREENDrawTextures(void) { // If you change useString then also change the corresponding synopsis string in ScreenSynopsis.c 1 2 3 4 5 6 7 8 static char useString[] = "Screen('DrawTextures', windowPointer, texturePointer(s) [, sourceRect(s)] [, destinationRect(s)] [, rotationAngle(s)] [, filterMode(s)] [, globalAlpha(s)] [, modulateColor(s)] [, textureShader] [, specialFlags] [, auxParameters]);"; // 1 2 3 4 5 6 7 8 9 10 11 static char synopsisString[] = "Draw many textures at once, either one texture to many locations or many textures.\n" "This function accepts the same parameters as Screen('DrawTexture'), but it is optimized for drawing many textures. " "You can leave out each argument, a default setting will be used in that case, provide it once to apply it to all " "drawn items, or provide a vector or matrix with a individual setting for each drawn item. If you provide multiple " "settings per argument, then the number must match between all arguments.\n\n" "Examples:\n" "a) One texture drawn to different locations at different orientations: Provide one texture handle for the texturePointer, " "a 4 row by n columns matrix for 'destinationRect' to provide target rectangles for n locations, provide a n component " "vector of 'rotationAngles' for the n different orientations of the n drawn texture patches.\n" "b) n textures drawn to n different locations: Same as a) but provide a n component vector of 'texturePointers' one for " "each texture to be drawn to one of n locations at n angles.\n"; PsychWindowRecordType *source, *target; PsychRectType sourceRect, targetRect, tempRect; PsychColorType color; double *dstRects, *srcRects, *colors, *penSizes, *globalAlphas, *filterModes, *rotationAngles; unsigned char *bytecolors; int numTexs, numdstRects, numsrcRects, i, nc, mc, nrsize, m, n, p, numAngles, numFilterModes, numAlphas, numRef; double* texids; double rotationAngle, globalAlpha, filterMode; double* auxParameters; int numAuxParams, numAuxComponents; psych_bool isclassic; int textureShader, backupShader; int specialFlags = 0; //all subfunctions should have these two lines. PsychPushHelp(useString, synopsisString, seeAlsoString); if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);}; //Get the window structure for the onscreen window. It holds the onscreen GL context which we will need in the //final step when we copy the texture from system RAM onto the screen. PsychErrorExit(PsychCapNumInputArgs(11)); PsychErrorExit(PsychRequireNumInputArgs(2)); PsychErrorExit(PsychCapNumOutputArgs(0)); // The target window is a fixed parameter: PsychAllocInWindowRecordArg(1, kPsychArgRequired, &target); // Classic OpenGL-1/2? isclassic = PsychIsGLClassic(target); // First get all source texture handles: PsychAllocInDoubleMatArg(2, kPsychArgRequired, &m, &n, &p, &texids); if ((p!=1) || (m>1 && n!=1) || (n>1 && m!=1)) PsychErrorExitMsg(PsychError_user, "The second argument must be either a row- or columnvector of valid texture handles."); // This is the number of texture handles: numTexs = m * n; // Only one texture? if (numTexs == 1) { // Yes. Allocate it in the conventional way: PsychAllocInWindowRecordArg(2, kPsychArgRequired, &source); if(source->windowType!=kPsychTexture) { PsychErrorExitMsg(PsychError_user, "The second argument supplied was not a texture handle!"); } } // Query, allocate and copy in all vectors... numdstRects = 4; nrsize = 0; colors = NULL; bytecolors = NULL; penSizes = NULL; // The negative position -4 means: dstRects coords are expected at position 4, but they are optional. // NULL means - don't want a size's vector. PsychPrepareRenderBatch(target, -4, &numdstRects, &dstRects, 8, &nc, &mc, &colors, &bytecolors, 5, &nrsize, &penSizes, FALSE); // At this point, target is set up as target window, i.e. its GL-Context is active, it is set as drawing target, // alpha blending is set up according to Screen('BlendFunction'), and the drawing color is set if it is a singular one. if (nc <= 1) { // Only one - or no - color provided. One or none? if(PsychCopyInColorArg(8, kPsychArgOptional, &color)) { // One global modulate color provided: // Setup global vertex color as modulate color for texture drawing: PsychCoerceColorMode(&color); PsychSetGLColor(&color, target); } else { // No modulateColor provided: Don't use this parameter: nc = 0; } } // Try to get source rects: m=n=p=0; if (PsychAllocInDoubleMatArg(3, kPsychArgOptional, &m, &n, &p, &srcRects)) { if ((p!=1) || (m!=1 && m!=4)) PsychErrorExitMsg(PsychError_user, "The third argument must be either empty, or a single srcRect 4 component row vector, or a 4 row by n column matrix with srcRects for all objects to draw, not a 3D matrix!"); // Ok, its a one row or four row matrix: if (m==4) { // Potentially multiple source rects provided: numsrcRects = n; } else { // Its a one row vector: This is either a single srcRect for all textures, or something invalid: if (n!=4) PsychErrorExitMsg(PsychError_user, "The third argument must be either empty, or a single srcRect 4 component row vector, or a 4 row by n column matrix with srcRects for all objects to draw!"); // Single srcRect provided: numsrcRects = 1; } } else { // No srcRects provided: numsrcRects = 0; } // Optional rotation angles: m=n=p=0; if (PsychAllocInDoubleMatArg(5, kPsychArgOptional, &m, &n, &p, &rotationAngles)) { if ((p!=1) || (m>1 && n!=1) || (n>1 && m!=1)) PsychErrorExitMsg(PsychError_user, "The fifth argument must be either a row- or columnvector of rotation angles."); } numAngles = m * n; // Default to 0 degree rotation -- upright drawing: rotationAngle = (numAngles == 1) ? rotationAngles[0] : 0.0; // Optional filter modes: m=n=p=0; if (PsychAllocInDoubleMatArg(6, kPsychArgOptional, &m, &n, &p, &filterModes)) { if ((p!=1) || (m>1 && n!=1) || (n>1 && m!=1)) PsychErrorExitMsg(PsychError_user, "The sixth argument must be either a row- or columnvector of filterModes."); } numFilterModes = m * n; // Default to bilinear filtering: filterMode = (numFilterModes == 1) ? filterModes[0] : 1; // Optional globalAlphas: m=n=p=0; if (PsychAllocInDoubleMatArg(7, kPsychArgOptional, &m, &n, &p, &globalAlphas)) { if ((p!=1) || (m>1 && n!=1) || (n>1 && m!=1)) PsychErrorExitMsg(PsychError_user, "The seventh argument must be either a row- or columnvector of globalAlpha values."); } numAlphas = m * n; globalAlpha = (numAlphas == 1) ? globalAlphas[0] : 1.0; // Optional auxParameters: auxParameters = NULL; m=n=p=0; if (PsychAllocInDoubleMatArg(11, kPsychArgOptional, &m, &n, &p, &auxParameters)) { if ((p!=1) || (m < 4) || ((m % 4) !=0)|| (n < 1)) PsychErrorExitMsg(PsychError_user, "The 11th argument must be a column vector or matrix of 'auxParameter' values with at least 4 components and component count a multiple of four."); } numAuxParams = n; numAuxComponents = m; // Check for consistency: Each parameter must be either not present, present once, // or present as many times as all other multi-parameters: numRef = (numsrcRects > numdstRects) ? numsrcRects : numdstRects; numRef = (numRef > numTexs) ? numRef : numTexs; numRef = (numRef > nc) ? numRef : nc; numRef = (numRef > numAlphas) ? numRef : numAlphas; numRef = (numRef > numFilterModes) ? numRef : numFilterModes; numRef = (numRef > numAngles) ? numRef : numAngles; numRef = (numRef > numAuxParams) ? numRef : numAuxParams; if (numTexs > 1 && numTexs != numRef) { printf("PTB-ERROR: Number of provided texture handles %i doesn't match number of other primitives %i!\n", numTexs, numRef); PsychErrorExitMsg(PsychError_user, "Inconsistent number of arguments provided to Screen('DrawTextures')."); } if (numsrcRects > 1 && numsrcRects != numRef) { printf("PTB-ERROR: Number of provided source rectangles %i doesn't match number of other primitives %i!\n", numsrcRects, numRef); PsychErrorExitMsg(PsychError_user, "Inconsistent number of arguments provided to Screen('DrawTextures')."); } if (numdstRects > 1 && numdstRects != numRef) { printf("PTB-ERROR: Number of provided destination rectangles %i doesn't match number of other primitives %i!\n", numdstRects, numRef); PsychErrorExitMsg(PsychError_user, "Inconsistent number of arguments provided to Screen('DrawTextures')."); } if (numAngles > 1 && numAngles != numRef) { printf("PTB-ERROR: Number of provided rotation angles %i doesn't match number of other primitives %i!\n", numAngles, numRef); PsychErrorExitMsg(PsychError_user, "Inconsistent number of arguments provided to Screen('DrawTextures')."); } if (numAlphas > 1 && numAlphas != numRef) { printf("PTB-ERROR: Number of provided global alpha values %i doesn't match number of other primitives %i!\n", numAlphas, numRef); PsychErrorExitMsg(PsychError_user, "Inconsistent number of arguments provided to Screen('DrawTextures')."); } if (numFilterModes > 1 && numFilterModes != numRef) { printf("PTB-ERROR: Number of provided filtermode values %i doesn't match number of other primitives %i!\n", numFilterModes, numRef); PsychErrorExitMsg(PsychError_user, "Inconsistent number of arguments provided to Screen('DrawTextures')."); } if (nc > 1 && nc != numRef) { printf("PTB-ERROR: Number of provided modulateColors %i doesn't match number of other primitives %i!\n", nc, numRef); PsychErrorExitMsg(PsychError_user, "Inconsistent number of arguments provided to Screen('DrawTextures')."); } if (numAuxParams > 1 && numAuxParams != numRef) { printf("PTB-ERROR: Number of provided 'auxParameter' column vectors %i doesn't match number of other primitives %i!\n", numAuxParams, numRef); PsychErrorExitMsg(PsychError_user, "Inconsistent number of arguments provided to Screen('DrawTextures')."); } // Assign optional override texture shader, if any provided: textureShader = -1; PsychCopyInIntegerArg(9, kPsychArgOptional, &textureShader); // Assign any other optional special flags: PsychCopyInIntegerArg(10, kPsychArgOptional, &specialFlags); // Ok, everything consistent so far. // Texture blitting loop: for (i=0; i < numRef; i++) { // Draw i'th texture: // Check if more than one texture provided. If not then the one single texture has been // setup already above: if (numTexs > 1) { // More than one texture handle provided: Need to allocate i'th one in: if(!IsWindowIndex((PsychWindowIndexType) texids[i])) { printf("PTB-ERROR: %i th entry in texture handle vector is not a valid handle!\n"); PsychErrorExitMsg(PsychError_user, "Invalid texture handle provided to Screen('DrawTextures')."); } // Get it: FindWindowRecord((PsychWindowIndexType) texids[i], &source); if(source->windowType!=kPsychTexture) { printf("PTB-ERROR: %i th entry in texture handle vector is not a valid handle!\n"); PsychErrorExitMsg(PsychError_user, "The second argument supplied was not a texture handle!"); } // Ok, we have our texture record in source: } // Source rectangle provided? if (numsrcRects > 1) { // Get i'th source rectangle: PsychCopyRect(sourceRect, &(srcRects[i*4])); } else if (numsrcRects == 1) { // Single source rect provided - get it: PsychCopyRect(sourceRect, &(srcRects[0])); } else { // No source rect provided: Take rectangle of current texture as srcRect: PsychCopyRect(sourceRect,source->clientrect); } // Skip this texture if sourceRect is an empty rect: if (IsPsychRectEmpty(sourceRect)) continue; // Destination rectangle provided? if (numdstRects > 1) { // Get i'th destination rectangle: PsychCopyRect(targetRect, &(dstRects[i*4])); } else if (numdstRects == 1) { // Single destination rect provided - get it: PsychCopyRect(targetRect, &(dstRects[0])); } else { // No destination rect provided: Center the current sourceRect in the current // target window and use that as destination: PsychCopyRect(tempRect, target->clientrect); PsychCenterRectInRect(sourceRect, tempRect, targetRect); } // Skip this texture if targetRect is an empty rect: if (IsPsychRectEmpty(targetRect)) continue; if (numAngles > 1) rotationAngle = rotationAngles[i]; if (numFilterModes > 1) filterMode = filterModes[i]; if (numAlphas > 1) globalAlpha = globalAlphas[i]; // Disable alpha if modulateColor active: if (nc > 0) globalAlpha = DBL_MAX; // Pass auxParameters for current primitive in the auxShaderParams field. target->auxShaderParamsCount = numAuxComponents; if (numAuxParams > 0) { if (numAuxParams == 1) { target->auxShaderParams = auxParameters; } else { target->auxShaderParams = &(auxParameters[i * numAuxComponents]); } } else { target->auxShaderParams = NULL; } // Multiple modulateColors provided? if (nc > 1) { if (isclassic) { // Yes. Set it up as current vertex color: We submit to internal currentColor for // shader based color processing and via glColorXXX() for fixed pipe processing: if (mc==3) { if (colors) { // RGB double: glColor3dv(&(colors[i*3])); target->currentColor[0]=colors[i*3 + 0]; target->currentColor[1]=colors[i*3 + 1]; target->currentColor[2]=colors[i*3 + 2]; target->currentColor[3]=1.0; } else { // RGB uint8: glColor3ubv(&(bytecolors[i*3])); target->currentColor[0]=((double) bytecolors[i*3 + 0] / 255.0); target->currentColor[1]=((double) bytecolors[i*3 + 1] / 255.0); target->currentColor[2]=((double) bytecolors[i*3 + 2] / 255.0); target->currentColor[3]=1.0; } } else { if (colors) { // RGBA double: glColor4dv(&(colors[i*4])); target->currentColor[0]=colors[i*4 + 0]; target->currentColor[1]=colors[i*4 + 1]; target->currentColor[2]=colors[i*4 + 2]; target->currentColor[3]=colors[i*4 + 3]; } else { // RGBA uint8: glColor4ubv(&(bytecolors[i*4])); target->currentColor[0]=((double) bytecolors[i*4 + 0] / 255.0); target->currentColor[1]=((double) bytecolors[i*4 + 1] / 255.0); target->currentColor[2]=((double) bytecolors[i*4 + 2] / 255.0); target->currentColor[3]=((double) bytecolors[i*4 + 3] / 255.0); } } } else { PsychSetArrayColor(target, i, mc, colors, bytecolors); } } // Ok, everything assigned. Check parameters: if (filterMode > 5) { PsychErrorExitMsg(PsychError_user, "filterMode needs to be negative for a specific blur level, or at most 5 for other modes."); } // Set rotation mode flag for texture matrix rotation if secialFlags is set accordingly: if (specialFlags & kPsychUseTextureMatrixForRotation) source->specialflags|=kPsychUseTextureMatrixForRotation; if (specialFlags & kPsychDontDoRotation) source->specialflags|=kPsychDontDoRotation; // Perform blit operation for i'th texture, either with or without an override texture shader applied: if (textureShader > -1) { backupShader = source->textureFilterShader; source->textureFilterShader = -1 * textureShader; PsychBlitTextureToDisplay(source, target, sourceRect, targetRect, rotationAngle, (int) filterMode, globalAlpha); source->textureFilterShader = backupShader; } else { PsychBlitTextureToDisplay(source, target, sourceRect, targetRect, rotationAngle, (int) filterMode, globalAlpha); } // Reset rotation mode flag: source->specialflags &= ~(kPsychUseTextureMatrixForRotation | kPsychDontDoRotation); // Next one... } target->auxShaderParams = NULL; target->auxShaderParamsCount = 0; // Mark end of drawing op. This is needed for single buffered drawing: PsychFlushGL(target); return(PsychError_none); }