~ubuntu-branches/ubuntu/trusty/psychtoolbox-3/trusty-proposed

« back to all changes in this revision

Viewing changes to Psychtoolbox/PsychOpenGL/moglFDF.m

  • Committer: Package Import Robot
  • Author(s): Yaroslav Halchenko
  • Date: 2013-11-19 23:34:50 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20131119233450-f7nf92vb8qavjmk8
Tags: 3.0.11.20131017.dfsg1-3
Upload to unsable since fresh glew has arrived to sid!

Show diffs side-by-side

added added

removed removed

Lines of Context:
271
271
% Subcommand dispatch:
272
272
 
273
273
% Initialization of a new context: Allocate and setup all ressources:
274
 
if strcmpi(cmd, 'CreateContext') | strcmpi(cmd, 'ReinitContext') %#ok<OR2>
 
274
if strcmpi(cmd, 'CreateContext') || strcmpi(cmd, 'ReinitContext')
275
275
    % Fetch all arguments - They are all required.
276
276
    if nargin < 9
277
277
        error(sprintf('Some mandatory input arguments to "%s" are missing. Please provide them!', cmd)); %#ok<SPERR>
298
298
        % rendertarget size:
299
299
        ctx.parentWin = varargin{1};
300
300
 
301
 
        if ~isscalar(ctx.parentWin) | ~ismember(ctx.parentWin, Screen('Windows')) %#ok<OR2>
 
301
        if ~isscalar(ctx.parentWin) || ~ismember(ctx.parentWin, Screen('Windows'))
302
302
            disp(ctx.parentWin);
303
303
            error('Invalid "window" argument provided to "CreateContext" - No such window (see above)!');
304
304
        end
334
334
    
335
335
    % Get all other arguments and perform parameter type and range checks:
336
336
    ctx.rect = varargin{2};
337
 
    if ~isnumeric(ctx.rect) | length(ctx.rect)~=4 %#ok<OR2>
 
337
    if ~isnumeric(ctx.rect) || length(ctx.rect)~=4
338
338
        disp(ctx.rect);
339
339
        error('Invalid "rect" argument provided to "CreateContext" - Must be a 4 component vector that describes the size and shape of the target rectangle [left top right bottom]');        
340
340
    end
346
346
    end
347
347
    
348
348
    ctx.texCoordMin = varargin{3};
349
 
    if ~isnumeric(ctx.texCoordMin) | length(ctx.texCoordMin)~=2 %#ok<OR2>
 
349
    if ~isnumeric(ctx.texCoordMin) || length(ctx.texCoordMin)~=2
350
350
        disp(ctx.texCoordMin);
351
351
        error('Invalid "texCoordMin" argument provided to "CreateContext" - Must be a 2 component vector of minimal texture coordinates in x- and y- direction!');
352
352
    end
353
353
    
354
354
    ctx.texCoordMax = varargin{4};
355
 
    if ~isnumeric(ctx.texCoordMax) | length(ctx.texCoordMax)~=2 %#ok<OR2>
 
355
    if ~isnumeric(ctx.texCoordMax) || length(ctx.texCoordMax)~=2
356
356
        disp(ctx.texCoordMax);
357
357
        error('Invalid "texCoordMax" argument provided to "CreateContext" - Must be a 2 component vector of maximal texture coordinates in x- and y- direction!');
358
358
    end
359
359
    
360
360
    ctx.texResolution = varargin{5};
361
 
    if ~isnumeric(ctx.texResolution) | length(ctx.texResolution)~=2 %#ok<OR2>
 
361
    if ~isnumeric(ctx.texResolution) || length(ctx.texResolution)~=2
362
362
        disp(ctx.texResolution);
363
363
        error('Invalid "texResolution" argument provided to "CreateContext" - Must be a 2 component vector of integral numbers with processing resolution in x- and y- direction!');
364
364
    end
493
493
            error('In "CreateContext": The PTB imaging pipeline is not active for provided parent window - this will not work! Need at least support for fast offscreen windows.');
494
494
        end
495
495
 
496
 
        if winfo.GLSupportsFBOUpToBpc < 32 | winfo.GLSupportsTexturesUpToBpc < 32 %#ok<OR2>
 
496
        if winfo.GLSupportsFBOUpToBpc < 32 || winfo.GLSupportsTexturesUpToBpc < 32
497
497
            error('In "CreateContext": Your gfx-hardware is not capable of handling textures and buffers with the required precision - this function will not work on your hardware!');
498
498
        end
499
499
 
543
543
    % window with a pixel size of 128 bits, aka 32 bpc float.
544
544
    ctx.sampleLinesPerBatch = ceil((round(ctx.maxFGDots / ctx.dotLifetime)) / ctx.samplesPerLine);
545
545
    ctx.sampleLinesTotal = ctx.sampleLinesPerBatch * ctx.dotLifetime;
546
 
    ctx.sampleBuffer = Screen('OpenOffscreenWindow', ctx.parentWin, [0 0 0 0], double([0 0 ctx.samplesPerLine ctx.sampleLinesTotal]), 128);
 
546
    ctx.sampleBuffer = Screen('OpenOffscreenWindow', ctx.parentWin, [0 0 0 0], double([0 0 ctx.samplesPerLine ctx.sampleLinesTotal]), 128, 32);
547
547
    ctx.maxFGDots = ctx.sampleLinesTotal * ctx.samplesPerLine;
548
548
    
549
549
    % Silhouette buffer: Contains the "perspective correct image space"
558
558
    % channel encodes t-coord of 2D texture coordinate, blue encodes
559
559
    % interpolated z-buffer depths.
560
560
    [ctx.silhouetteWidth, ctx.silhouetteHeight] = RectSize(ctx.rect);
561
 
    ctx.silhouetteBuffer = Screen('OpenOffscreenWindow', ctx.parentWin, [0 0 0 0], [0, 0, ctx.silhouetteWidth, ctx.silhouetteHeight], 128);
 
561
    ctx.silhouetteBuffer = Screen('OpenOffscreenWindow', ctx.parentWin, [0 0 0 0], [0, 0, ctx.silhouetteWidth, ctx.silhouetteHeight], 128, 32);
562
562
 
563
563
    % Retrieve OpenGL texture handle for the sihouetteBuffer:
564
564
    ctx.silhouetteTexture = Screen('GetOpenGLTexture', ctx.parentWin, ctx.silhouetteBuffer);
578
578
    % Again a 32bpc float offscreen window FBO, but the resolution is
579
579
    % chosen per user spec to be fine enough in texture coordinate space to
580
580
    % avoid aliasing artifacts as good as possible:
581
 
    ctx.trackingBuffer = Screen('OpenOffscreenWindow', ctx.parentWin, [0 0 0 0], [0, 0, ctx.texResolution(1), ctx.texResolution(2)], 128);
 
581
    ctx.trackingBuffer = Screen('OpenOffscreenWindow', ctx.parentWin, [0 0 0 0], [0, 0, ctx.texResolution(1), ctx.texResolution(2)], 128, 32);
582
582
 
583
583
    % Final buffer with foreground dot positions. This one will get filled
584
584
    % by the createFGDotShader. It will later get either read back to
585
585
    % Matlab on usercode request, or converted to a VBO and then rendered.
586
 
    ctx.FGDotsBuffer = Screen('OpenOffscreenWindow', ctx.parentWin, [0 0 0 0], Screen('Rect', ctx.sampleBuffer), 128);
 
586
    ctx.FGDotsBuffer = Screen('OpenOffscreenWindow', ctx.parentWin, [0 0 0 0], Screen('Rect', ctx.sampleBuffer), 128, 32);
587
587
    
588
588
 
589
589
    % Final buffer with background dot positions. This one will get filled
595
595
    ctx.BGsamplesPerLine = min(ctx.BGsamplesPerLine, round(ctx.maxBGDots / ctx.dotLifetime));
596
596
    ctx.BGsampleLinesPerBatch = ceil((round(ctx.maxBGDots / ctx.dotLifetime)) / ctx.BGsamplesPerLine);
597
597
    ctx.BGsampleLinesTotal = ctx.BGsampleLinesPerBatch * ctx.dotLifetime;
598
 
    ctx.BGDotsBuffer = Screen('OpenOffscreenWindow', ctx.parentWin, [0 0 0 0], double([0 0 ctx.BGsamplesPerLine ctx.BGsampleLinesTotal]), 128);
 
598
    ctx.BGDotsBuffer = Screen('OpenOffscreenWindow', ctx.parentWin, [0 0 0 0], double([0 0 ctx.BGsamplesPerLine ctx.BGsampleLinesTotal]), 128, 32);
599
599
    ctx.maxBGDots = ctx.BGsampleLinesTotal * ctx.BGsamplesPerLine;
600
600
    ctx.BGSampleSet = zeros(ctx.BGsampleLinesTotal, ctx.BGsamplesPerLine, 3);
601
601