我的实验有时间问题,我试图实现一个带有闪烁框的SSVEP拼写器。在每一帧中,我实现以下代码来创建具有指定颜色的矩形,并使用to“drawtext”来指示字母的文本。然而,当我这样做时,漏掉的翻转次数非常高(90%以上),当我移除所有文本绘制时,性能是正常的,非常好(约1%)。
我用的是window 7 64位,用的是MATLAB2017B,Psychtoolbox-3,我已经安装了GStreamer。
function all_rects = create_rects(char_struct,window,drawing_colors,drawing_color_index,black,cue,text_texture)
penWidthPixels = 2;
Screen('TextFont', window, 'Courier New');
Screen('TextSize', window, 15);
num_targets = length(char_struct);
all_rects = nan(4,num_targets);
for i=1:num_targets
baseRect = [0 0 char_struct(i).size(1) char_struct(i).size(2)];
all_rects(:,i) = CenterRectOnPointd(baseRect, char_struct(i).x_location, char_struct(i).y_location);
Screen('FillRect',window,reshape(drawing_colors(drawing_color_index(i)+1,:),[1,3]),all_rects(:,i));
if length(char_struct(i).text) > 1 && ~strcmp(char_struct(i).text,'SPACE')
Screen('DrawText',window, char_struct(i).text,char_struct(i).x_location-15, char_struct(i).y_location+3,0, 100)
elseif strcmp(char_struct(i).text,'SPACE')
Screen('DrawText',window,char_struct(i).text,char_struct(i).x_location-40,char_struct(i).y_location+3,0,100);
else
Screen('DrawText',window, char_struct(i).text,char_struct(i).x_location-5, char_struct(i).y_location+3,0, 100);
end
end
Screen('FrameRect', window, black, all_rects,penWidthPixels);
if cue ~=0
Screen('FrameRect', window, [255 0 0], all_rects(:,cue),penWidthPixels);
end
Screen('DrawingFinished', window);
vbl = Screen('Flip', window,vbl + 0.5 * ifi);
正如您所指出的,将文本(文本本身或整个窗口)预先计算为纹理将在表示循环期间节省资源。您可以以与其他Psychtoolbox绘制函数相同的方式在纹理顶部绘制框,只需在翻转屏幕之前将两者叠加:
Screen('DrawTexture', window, text_texture);
Screen('FrameRect', window, black, all_rects, penWidthPixels);
Screen('Flip', window);