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

« back to all changes in this revision

Viewing changes to Psychtoolbox/PsychGPGPU/testGLInterop.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:
 
1
function testGLInterop
 
2
 
 
3
PsychDefaultSetup(1);
 
4
 
 
5
GPUstart;
 
6
%memcpyCudaOpenGL(6, 1); % Be verbose.
 
7
%memcpyCudaOpenGL(5, 50); % Use 50 slots in LRU cache.
 
8
 
 
9
Screen('Preference','SkipSyncTests', 2);
 
10
PsychImaging('PrepareConfiguration');
 
11
%PsychImaging('AddTask', 'General', 'FloatingPoint32Bit');
 
12
w = PsychImaging('OpenWindow', 0, 0);
 
13
 
 
14
tex = ones(200, 200, 4);
 
15
 
 
16
% Read our beloved bunny image from filesystem:
 
17
bunnyimg = imread([PsychtoolboxRoot 'PsychDemos/konijntjes1024x768.jpg']);
 
18
bunnyimg(:,:,4) = 255;
 
19
 
 
20
% Maketexture in float precision with upright texture orientation:
 
21
bunnytex = Screen('MakeTexture', w, double(bunnyimg(:,:,1:2))/255, [], [], 2, 1);
 
22
 
 
23
bunre = Screen('Rect', bunnytex)
 
24
bunp  = Screen('Pixelsize', bunnytex)
 
25
 
 
26
%bunnytex = Screen('Openoffscreenwindow', w, [1 1 0 0], [0 0 1024 768], 128);
 
27
%DrawFormattedText(bunnytex, 'HELLO WORLD!', 'center', 'center', [255 0 0]);
 
28
 
 
29
t = bunnytex;
 
30
 
 
31
Screen('DrawTexture', w, t);
 
32
 
 
33
if 0
 
34
    T = GPUTypeFromToGL(0, w, 2);
 
35
end
 
36
Screen('Flip', w);
 
37
 
 
38
 
 
39
if 1
 
40
    if 1
 
41
        % Test high-level interface for pure mortals:
 
42
        T = GPUTypeFromToGL(0, bunnytex, [], [], 0);
 
43
    else
 
44
        % Test low-level OpenGL object interface which does without any calls
 
45
        % into Screen() -- Important for interop with non-ptb code and for use
 
46
        % within imaging pipeline, ie., within Screen's execution context, as
 
47
        % Screen is currently non-reentrant.
 
48
        [texstruct.glhandle, texstruct.gltarget] = Screen('GetOpenGLTexture', w, t);
 
49
        [texstruct.width, texstruct.height] = Screen('Windowsize', t);
 
50
        texstruct.bpp = Screen('Pixelsize', t) / 8;
 
51
        texstruct.nrchannels = 4;
 
52
        T = GPUTypeFromToGL(0, texstruct, 1);
 
53
    end
 
54
end
 
55
 
 
56
rect = Screen('Rect', t)
 
57
 
 
58
%T = GPUsingle(rand(1, 1024, 768));
 
59
foo = size(T)
 
60
H = T;
 
61
foo = size(H)
 
62
c = 0;
 
63
t0 = GetSecs;
 
64
while c < 500
 
65
    %T = T .* 0.99;
 
66
    H = T .* (0.5 + 0.5 * sin(GetSecs * 10));
 
67
    if 1
 
68
        t = GPUTypeFromToGL(1, H, 0, t, 0);
 
69
        %ptr = GPUTypeFromToGL(6, t, 0);
 
70
            %GPUTypeFromToGL(3, t, 0);
 
71
            % Screen('Close', t);
 
72
            % t = GPUTypeFromToGL(1, H, 0, [], 1);
 
73
        
 
74
        Screen('DrawTexture', w, t, [], [], [], 0);
 
75
    else
 
76
        GPUTypeFromToGL(1, H, 2, w);
 
77
    end
 
78
    Screen('Flip', w, 0, 2, 2);
 
79
    c = c + 1;
 
80
end
 
81
Screen('DrawingFinished', w, 2, 1);
 
82
fps = c / (GetSecs - t0);
 
83
gbs = fps * 2 * numel(T) * 4 / 1024 / 1024 / 1024;
 
84
fprintf('FPS = %f [%f GB/sec]\n', fps, gbs);
 
85
GPUTypeFromToGL(4);
 
86
sca;
 
87