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

« back to all changes in this revision

Viewing changes to PsychSourceGL/Source/Common/Screen/SCREENDrawDots.c

  • 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:
78
78
PsychError SCREENDrawDots(void)  
79
79
{
80
80
        PsychWindowRecordType                   *windowRecord;
81
 
        int                                     whiteValue, m,n,p,mc,nc,pc,idot_type;
 
81
        int                                     m,n,p,mc,nc,idot_type;
82
82
        int                                     i, nrpoints, nrsize;
83
 
        psych_bool                                 isArgThere, usecolorvector, isdoublecolors, isuint8colors;
 
83
        psych_bool                              isArgThere, usecolorvector, isdoublecolors, isuint8colors;
84
84
        double                                                                  *xy, *size, *center, *dot_type, *colors;
 
85
    float                                   *sizef;
85
86
        unsigned char                           *bytecolors;
86
87
        GLfloat                                                                 pointsizerange[2];
87
 
        double                                                                  convfactor;
88
 
    
 
88
    psych_bool                              lenient = FALSE;
 
89
 
89
90
        // All sub functions should have these two lines
90
91
        PsychPushHelp(useString, synopsisString,seeAlsoString);
91
92
        if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);};
103
104
        colors = NULL;
104
105
        bytecolors = NULL;
105
106
 
106
 
        PsychPrepareRenderBatch(windowRecord, 2, &nrpoints, &xy, 4, &nc, &mc, &colors, &bytecolors, 3, &nrsize, &size);
 
107
        PsychPrepareRenderBatch(windowRecord, 2, &nrpoints, &xy, 4, &nc, &mc, &colors, &bytecolors, 3, &nrsize, &size, (GL_FLOAT == PsychGLFloatType(windowRecord)));
107
108
        isdoublecolors = (colors) ? TRUE:FALSE;
108
109
        isuint8colors  = (bytecolors) ? TRUE:FALSE;
109
110
        usecolorvector = (nc>1) ? TRUE:FALSE;
110
 
        
 
111
 
 
112
    // Assign sizef as float-type array of sizes, if float mode active, NULL otherwise:
 
113
    sizef = (GL_FLOAT == PsychGLFloatType(windowRecord)) ? (float*) size : NULL;
 
114
 
111
115
        // Get center argument
112
116
        isArgThere = PsychIsArgPresent(PsychArgIn, 5);
113
117
        if(!isArgThere){
130
134
                idot_type = (int) dot_type[0];
131
135
        }
132
136
        
133
 
        // Child-protection: Alpha blending needs to be enabled for smoothing to work:
134
 
        // Ok, not such a good idea :-( The flag also enables drawing of round dots and
135
 
        // there are applications were we want to set the flag without using alpha blending...
136
 
        // Therefore disabled -> May want to turn this into some kind of warning or hint in the future...
137
 
        if (idot_type>0 && windowRecord->actualEnableBlending!=TRUE) {
138
 
                //PsychErrorExitMsg(PsychError_user, "Point smoothing doesn't work with alpha-blending disabled! See Screen('BlendFunction') on how to enable it.");
139
 
        }
140
 
        
141
137
        // Turn on antialiasing to draw circles 
142
138
        if(idot_type) {
143
139
                glEnable(GL_POINT_SMOOTH);
146
142
                glHint(GL_POINT_SMOOTH_HINT, (idot_type>1) ? GL_NICEST : GL_DONT_CARE);
147
143
        }
148
144
        else {
149
 
                #ifndef GL_ALIASED_POINT_SIZE_RANGE
150
 
                #define GL_ALIASED_POINT_SIZE_RANGE 0x846D
151
 
                #endif
152
 
                
153
145
                glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, (GLfloat*) &pointsizerange);
154
146
        }
155
147
        
 
148
    // Does ES-GPU only support a fixed point diameter of 1 pixel?
 
149
    if ((pointsizerange[1] <= 1) && PsychIsGLES(windowRecord)) {
 
150
        // Yes. Not much point bailing on this, as it should be easily visible
 
151
        // during testing of a studies code on a OpenGL-ES device.
 
152
        lenient = TRUE;
 
153
    }
 
154
 
156
155
        // Set size of a single dot:
157
 
        if (size[0] > pointsizerange[1] || size[0] < pointsizerange[0]) {
 
156
        if (!lenient && ((sizef && (sizef[0] > pointsizerange[1] || sizef[0] < pointsizerange[0])) ||
 
157
                     (!sizef && (size[0] > pointsizerange[1] || size[0] < pointsizerange[0])))) {
158
158
                printf("PTB-ERROR: You requested a point size of %f units, which is not in the range (%f to %f) supported by your graphics hardware.\n",
159
 
                           size[0], pointsizerange[0], pointsizerange[1]);
 
159
                           (sizef) ? sizef[0] : size[0], pointsizerange[0], pointsizerange[1]);
160
160
                PsychErrorExitMsg(PsychError_user, "Unsupported point size requested in Screen('DrawDots').");
161
161
        }
162
162
        
163
163
        // Setup initial common point size for all points:
164
 
        glPointSize(size[0]);
 
164
    if (!lenient) glPointSize((sizef) ? sizef[0] : (float) size[0]);
165
165
        
166
166
        // Setup modelview matrix to perform translation by 'center':
167
167
        glMatrixMode(GL_MODELVIEW);
170
170
        glPushMatrix();
171
171
        
172
172
        // Apply a global translation of (center(x,y)) pixels to all following points:
173
 
        glTranslated(center[0], center[1], 0);
 
173
        glTranslatef((float) center[0], (float) center[1], 0);
174
174
        
175
175
        // Render the array of 2D-Points - Efficient version:
176
176
        // This command sequence allows fast processing of whole arrays
179
179
        // optimized in specific OpenGL implementations.
180
180
        
181
181
        // Pass a pointer to the start of the point-coordinate array:
182
 
        glVertexPointer(2, GL_DOUBLE, 0, &xy[0]);
 
182
        glVertexPointer(2, PSYCHGLFLOAT, 0, &xy[0]);
183
183
        
184
184
        // Enable fast rendering of arrays:
185
185
        glEnableClientState(GL_VERTEX_ARRAY);
200
200
                // Point-Sprite extensions, cleverly used display lists or via vertex-shaders...
201
201
                // For now we do it the stupid way:
202
202
                for (i=0; i<nrpoints; i++) {
203
 
                        if (size[i] > pointsizerange[1] || size[i] < pointsizerange[0]) {
 
203
            if (!lenient && ((sizef && (sizef[i] > pointsizerange[1] || sizef[i] < pointsizerange[0])) ||
 
204
                             (!sizef && (size[i] > pointsizerange[1] || size[i] < pointsizerange[0])))) {
204
205
                                printf("PTB-ERROR: You requested a point size of %f units, which is not in the range (%f to %f) supported by your graphics hardware.\n",
205
 
                                           size[i], pointsizerange[0], pointsizerange[1]);
 
206
                                           (sizef) ? sizef[i] : size[i], pointsizerange[0], pointsizerange[1]);
206
207
                                PsychErrorExitMsg(PsychError_user, "Unsupported point size requested in Screen('DrawDots').");
207
208
                        }
208
209
                        
209
210
                        // Setup point size for this point:
210
 
                        glPointSize(size[i]);
 
211
                        if (!lenient) glPointSize((sizef) ? sizef[i] : (float) size[i]);
211
212
                        
212
213
                        // Render point:
213
214
                        glDrawArrays(GL_POINTS, i, 1);
216
217
        
217
218
        // Disable fast rendering of arrays:
218
219
        glDisableClientState(GL_VERTEX_ARRAY);
219
 
        glVertexPointer(2, GL_DOUBLE, 0, NULL);
 
220
        glVertexPointer(2, PSYCHGLFLOAT, 0, NULL);
220
221
        
221
222
        if (usecolorvector) PsychSetupVertexColorArrays(windowRecord, FALSE, 0, NULL, NULL);
222
223
        
235
236
        //All psychfunctions require this.
236
237
        return(PsychError_none);
237
238
}
238