File: SCREENGetOpenGLTexture.c

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (88 lines) | stat: -rw-r--r-- 3,573 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
  Common/Screen/SCREENGetOpenGLTexture.c		
  
  AUTHORS:
  mario.kleiner at tuebingen.mpg.de  mk
  
  PLATFORMS:	All
    

  HISTORY:
  02/07/06  mk		Created.
 
  DESCRIPTION:
  Takes a Psychtoolbox texture handle and returns all information that is needed to
  use or access the corresponding OpenGL texture with an external OpenGL routine,
  e.g., moglcore or other mex-files...
 
 */


#include "Screen.h"

static char useString[] = "[ gltexid gltextarget texcoord_u texcoord_v ] =Screen('GetOpenGLTexture', windowPtr, textureHandle [, x][, y]);";
static char synopsisString[] = 
	"Returns information about the OpenGL texture corresponding to a Psychtoolbox texture. "
	"\"windowPtr\" is the handle of the onscreen window for which texture should be returned. "
        "'textureHandle' is the Psychtoolbox handle for the requested texture. Optionally you can "
        "pass in Psychtoolbox texture coordinates (x,y) and get them mapped to the proper OpenGL "
        "texture coordinates. Return values: 'gltexid' OpenGL texture id for binding the texture. "
        "'gltextarget' type of OpenGL texture target to use. 'texcoord_u' and 'texcoord_v' "
        "OpenGL texture coordinates corresponding to 'x' and 'y'. Immediately after calling this "
        "routine, the proper OpenGL rendering context for the requested texture is activated for use. "
        "Example of usage: glBindTexture(gltextarget, gltexid); // Activate and bind req. texture. "
        "glTexCoord2d(texcoord_u, texcoord_v); // Assign texture pixel (x,y) to next vertex. For more "
        "info, read an OpenGL book. ";

static char seeAlsoString[] = "SetOpenGLTexture";

PsychError SCREENGetOpenGLTexture(void) 
{
    PsychWindowRecordType *windowRecord, *textureRecord;
    double                x,y;
    x=y=-1;
    
    //all subfunctions should have these two lines.  
    PsychPushHelp(useString, synopsisString, seeAlsoString);
    if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);};
    
    PsychErrorExit(PsychCapNumInputArgs(4));     //The maximum number of inputs
    PsychErrorExit(PsychRequireNumInputArgs(2)); //The required number of inputs	
    PsychErrorExit(PsychCapNumOutputArgs(4));    //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);

    // Get the texture record from the texture record argument.
    PsychAllocInWindowRecordArg(2, TRUE, &textureRecord);
    if (!PsychIsTexture(textureRecord)) {
        PsychErrorExitMsg(PsychError_user, "You tried to query texture information on something else than a texture!");
    }
    
    // Query optional x-pos:
    PsychCopyInDoubleArg(3, FALSE, &x);
 
    // Query optional y-pos:
    PsychCopyInDoubleArg(4, FALSE, &y);

    // Return the OpenGL texture handle:
    PsychCopyOutDoubleArg(1, FALSE, (double) textureRecord->textureNumber);
    
    // Return type of texture target:
    PsychCopyOutDoubleArg(2, FALSE, (double) PsychGetTextureTarget(textureRecord));
    
    // If no texcoords provided, we'll let them default to full texture size:
    if (x==-1) x=PsychGetWidthFromRect(textureRecord->rect);
    if (y==-1) y=PsychGetHeightFromRect(textureRecord->rect);

    // Remap texture coordinates:
    PsychMapTexCoord(textureRecord, &x, &y);
        
    // Return mapped texture coordinates:
    PsychCopyOutDoubleArg(3, FALSE, x);
    PsychCopyOutDoubleArg(4, FALSE, y);
    
    // Done.
    return(PsychError_none);
}