File: moglGetTexForFBO.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, 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 (51 lines) | stat: -rw-r--r-- 1,239 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
function texid = moglGetTexForFBO(fbo, bufferid)
% texid = moglGetTexForFBO(fbo, bufferid) -- Return texture name of texture which is
% bound to the specified 'fbo' Framebuffer object as color buffer number 'bufferid'.
% bufferid defaults to 1, aka the first attached color buffer.

% History:
% 30.5.2006 Written (MK).
global GL;

% Child protection:
AssertGLSL;

if nargin < 1
    error('moglGetTexForFBO called without fbo argument.');
end;

if fbo == 0
    texid = 0;
    return;
end;

if nargin < 2
    bufferid=1;
end;

if isempty(bufferid)
    bufferid=1;
end;

% Child protection:
if ~glIsFramebufferEXT(fbo)
    error('Invalid fbo identifier passed. This is not a valid FBO.');
end;

boundfbo = glGetIntegerv(GL.FRAMEBUFFER_BINDING_EXT);
if boundfbo~=fbo
    % fbo currently unbound. Bind it:
    glBindFramebufferEXT(GL.FRAMEBUFFER_EXT, fbo);    
end;

% Query its texture attachments and destroy them:
texid = glGetFramebufferAttachmentParameterivEXT(GL.FRAMEBUFFER_EXT, GL.COLOR_ATTACHMENT0_EXT + bufferid - 1, GL.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT);

% Rebind previous fbo, unless we were bound:
if boundfbo~=fbo
    % Reset to last bound FBO:
    glBindFramebufferEXT(GL.FRAMEBUFFER_EXT, boundfbo);
end;

% Done.
return;