Oolite
Loading...
Searching...
No Matches
OOPolygonSprite Class Reference

#include <OOPolygonSprite.h>

Inheritance diagram for OOPolygonSprite:
Collaboration diagram for OOPolygonSprite:

Instance Methods

(id) - initWithDataArray:outlineWidth:name:
(void) - drawFilled
(void) - drawOutline
(void) - dealloc [implementation]
(NSString *) - descriptionComponents [implementation]
(void) - drawWithData:count:VBO: [implementation]
(void) - resetGraphicsState [implementation]
(BOOL) - loadPolygons:outlineWidth: [implementation]
(void) - oo_drawHUDBeaconIconAt:size:alpha:z: [implementation]

Private Attributes

GLfloat * _solidData
size_t _solidCount
GLfloat * _outlineData
size_t _outlineCount
NSString * _name

Detailed Description

Definition at line 35 of file OOPolygonSprite.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 158 of file OOPolygonSprite.m.

159{
161
162#ifndef NDEBUG
163 DESTROY(_name);
164#endif
165 free(_solidData);
166 free(_outlineData);
167
168 [super dealloc];
169}
#define DESTROY(x)
void unregisterClient:(id< OOGraphicsResetClient > client)
OOGraphicsResetManager * sharedManager()
GLfloat * _outlineData

References _name, _outlineData, _solidData, dealloc, DESTROY, OOGraphicsResetManager::sharedManager, and OOGraphicsResetManager::unregisterClient:.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Definition at line 172 of file OOPolygonSprite.m.

173{
174 return _name;
175}

References _name, and descriptionComponents.

Referenced by descriptionComponents.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawFilled

- (void) drawFilled

Definition at line 219 of file OOPolygonSprite.m.

220{
221#if !OO_USE_VBO
222 GLuint _solidVBO; // Unusued
223#endif
224
225 [self drawWithData:_solidData
226 count:_solidCount
227 VBO:&_solidVBO];
228}

References drawFilled, and drawWithData:count:VBO:.

Referenced by drawFilled, and OOPolygonSprite(OOHUDBeaconIcon)::oo_drawHUDBeaconIconAt:size:alpha:z:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawOutline

- (void) drawOutline

Definition at line 230 of file OOPolygonSprite.m.

231{
232#if !OO_USE_VBO
233 GLuint _outlineVBO; // Unusued
234#endif
235
236 [self drawWithData:_outlineData
237 count:_outlineCount
238 VBO:&_outlineVBO];
239}

References drawOutline, and drawWithData:count:VBO:.

Referenced by drawOutline, and OOPolygonSprite(OOHUDBeaconIcon)::oo_drawHUDBeaconIconAt:size:alpha:z:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawWithData:count:VBO:

- (void) drawWithData: (GLfloat*) data
count: (size_t) count
VBO: (GLuint*) vbo 
implementation

Definition at line 178 of file OOPolygonSprite.m.

178 :(GLfloat*)data count:(size_t)count VBO:(GLuint*)vbo
179{
180 if (count == 0)
181 return;
182 NSParameterAssert(vbo != NULL && data != NULL);
183
186
187#if OO_USE_VBO
189
190 if (useVBO) {
191 if (*vbo == 0) {
192 OOGL(glGenBuffersARB(1, vbo));
193 if (*vbo != 0) {
194 OOGL(glBindBufferARB(GL_ARRAY_BUFFER, *vbo));
195 OOGL(glBufferDataARB(GL_ARRAY_BUFFER, sizeof(GLfloat) * count * 2, data, GL_STATIC_DRAW));
196 }
197 } else {
198 OOGL(glBindBufferARB(GL_ARRAY_BUFFER, *vbo));
199 }
200 if (*vbo != 0)
201 data = NULL; // Must pass NULL pointer to glVertexPointer to use VBO.
202 }
203#endif
204
205 OOGL(glEnableClientState(GL_VERTEX_ARRAY));
206 OOGL(glVertexPointer(2, GL_FLOAT, 0, data));
207 OOGL(glDrawArrays(GL_TRIANGLES, 0, count));
208 OOGL(glDisableClientState(GL_VERTEX_ARRAY));
209
210#if OO_USE_VBO
211 if (useVBO)
212 OOGL(glBindBufferARB(GL_ARRAY_BUFFER, 0));
213#endif
214
216 OOCheckOpenGLErrors(@"OOPolygonSprite after rendering %@", self);
217}
#define OO_ENTER_OPENGL()
@ OPENGL_STATE_OVERLAY
Definition OOOpenGL.h:124
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:133
BOOL OOCheckOpenGLErrors(NSString *format,...)
Definition OOOpenGL.m:38
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:132
#define OOGL(statement)
Definition OOOpenGL.h:262
unsigned count
OOOpenGLExtensionManager * sharedManager()

References count, OO_ENTER_OPENGL, OOCheckOpenGLErrors(), OOGL, OOSetOpenGLState, OOVerifyOpenGLState, OPENGL_STATE_OVERLAY, OOOpenGLExtensionManager::sharedManager, and OOOpenGLExtensionManager::vboSupported.

Referenced by drawFilled, and drawOutline.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWithDataArray:outlineWidth:name:

- (id) initWithDataArray: (NSArray*) dataArray
outlineWidth: (GLfloat) outlineWidth
name: (NSString*) name 

Definition at line 131 of file OOPolygonSprite.m.

131 :(NSArray*)dataArray outlineWidth:(GLfloat)outlineWidth name:(NSString*)name
132{
133 if ((self = [super init])) {
134#ifndef NDEBUG
135 _name = [name copy];
136#endif
137
138 if ([dataArray count] == 0) {
139 [self release];
140 return nil;
141 }
142
143 // Normalize data to array-of-arrays form.
144 if (![[dataArray objectAtIndex:0] isKindOfClass:[NSArray class]]) {
145 dataArray = [NSArray arrayWithObject:dataArray];
146 }
147 if (![self loadPolygons:dataArray outlineWidth:outlineWidth]) {
148 [self release];
149 return nil;
150 }
151
153 }
154
155 return self;
156}
return nil
void registerClient:(id< OOGraphicsResetClient > client)

References _name, count, nil, OOGraphicsResetManager::registerClient:, and OOGraphicsResetManager::sharedManager.

Here is the call graph for this function:

◆ loadPolygons:outlineWidth:

- (BOOL) loadPolygons: (NSArray*) dataArray
outlineWidth: (float) outlineWidth 
implementation

Provided by category OOPolygonSprite(Private).

Definition at line 257 of file OOPolygonSprite.m.

257 :(NSArray*)dataArray outlineWidth:(float)outlineWidth
258{
259 NSParameterAssert(dataArray != nil);
260
261 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
262 GLUtesselator* tesselator = NULL;
263
264 TessPolygonData polygonData;
265 memset(&polygonData, 0, sizeof polygonData);
266 polygonData.OK = YES;
267#ifndef NDEBUG
268 polygonData.name = _name;
269 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"polygon-sprite-dump-svg"])
270 SVGDumpBegin(&polygonData);
271#endif
272
273 // For efficiency, grow to more than big enough for most cases to avoid regrowing.
274 if (!GrowTessPolygonData(&polygonData, 100)) {
275 polygonData.OK = NO;
276 goto END;
277 }
278
279 tesselator = gluNewTess();
280 if (tesselator == NULL) {
281 polygonData.OK = NO;
282 goto END;
283 }
284
285 dataArray = DataArrayToPoints(&polygonData, dataArray);
286
287 /*** Tesselate polygon fill ***/
288 gluTessCallback(tesselator, GLU_TESS_BEGIN_DATA, (TessFuncPtr)TessBeginCallback);
289 gluTessCallback(tesselator, GLU_TESS_VERTEX_DATA, (TessFuncPtr)TessVertexCallback);
290 gluTessCallback(tesselator, GLU_TESS_END_DATA, (TessFuncPtr)TessEndCallback);
291 gluTessCallback(tesselator, GLU_TESS_ERROR_DATA, (TessFuncPtr)ErrorCallback);
292 gluTessCallback(tesselator, GLU_TESS_COMBINE_DATA, (TessFuncPtr)TessCombineCallback);
293
294 gluTessBeginPolygon(tesselator, &polygonData);
295 SVGDumpBeginGroup(&polygonData, @"Fill");
296
297 NSUInteger contourCount = [dataArray count], contourIndex;
298 for (contourIndex = 0; contourIndex < contourCount && polygonData.OK; contourIndex++) {
299 NSArray* contour = [dataArray oo_arrayAtIndex:contourIndex];
300 if (contour == nil) {
301 polygonData.OK = NO;
302 break;
303 }
304
305 SubmitVertices(tesselator, &polygonData, contour);
306 }
307
308 gluTessEndPolygon(tesselator);
309 SVGDumpEndGroup(&polygonData);
310
311 if (polygonData.OK) {
312 _solidCount = polygonData.count;
313
314 if (_solidCount != 0) {
315 _solidData = realloc(polygonData.data, polygonData.count * sizeof(GLfloat) * 2);
316 if (_solidData != NULL)
317 polygonData.data = NULL; // realloc succeded.
318 else {
319 // Unlikely, but legal: realloc failed to shrink buffer.
320 _solidData = polygonData.data;
321 if (_solidData == NULL)
322 polygonData.OK = NO;
323 }
324 } else {
325 // Empty polygon.
326 _solidData = NULL;
327 }
328 }
329 if (!polygonData.OK)
330 goto END;
331
332 /*** Tesselate polygon outline ***/
333 gluDeleteTess(tesselator);
334 tesselator = gluNewTess();
335 if (tesselator == NULL) {
336 polygonData.OK = NO;
337 goto END;
338 }
339
340 polygonData.count = 0;
341 polygonData.capacity = 0;
342 if (!GrowTessPolygonData(&polygonData, 100)) {
343 polygonData.OK = NO;
344 goto END;
345 }
346#ifndef NDEBUG
347 polygonData.generatingOutline = YES;
348#endif
349
350 gluTessCallback(tesselator, GLU_TESS_BEGIN_DATA, (TessFuncPtr)TessBeginCallback);
351 gluTessCallback(tesselator, GLU_TESS_VERTEX_DATA, (TessFuncPtr)TessVertexCallback);
352 gluTessCallback(tesselator, GLU_TESS_END_DATA, (TessFuncPtr)TessEndCallback);
353 gluTessCallback(tesselator, GLU_TESS_ERROR_DATA, (TessFuncPtr)ErrorCallback);
354 gluTessCallback(tesselator, GLU_TESS_COMBINE_DATA, (TessFuncPtr)TessCombineCallback);
355 gluTessProperty(tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE);
356
357 gluTessBeginPolygon(tesselator, &polygonData);
358 SVGDumpBeginGroup(&polygonData, @"Outline");
359
360 outlineWidth *= 0.5f; // Half the width in, half the width out.
361 contourCount = [dataArray count];
362 for (contourIndex = 0; contourIndex < contourCount && polygonData.OK; contourIndex++) {
363 NSArray* contour = [dataArray oo_arrayAtIndex:contourIndex];
364 if (contour == nil) {
365 polygonData.OK = NO;
366 break;
367 }
368
369 SubmitVertices(tesselator, &polygonData, BuildOutlineContour(contour, outlineWidth, NO));
370 SubmitVertices(tesselator, &polygonData, BuildOutlineContour(contour, outlineWidth, YES));
371 }
372
373 gluTessEndPolygon(tesselator);
374 SVGDumpEndGroup(&polygonData);
375
376 if (polygonData.OK) {
377 if (polygonData.count != 0) {
378 _outlineCount = polygonData.count;
379 _outlineData = realloc(polygonData.data, polygonData.count * sizeof(GLfloat) * 2);
380 if (_outlineData != NULL)
381 polygonData.data = NULL; // realloc succeded.
382 else {
383 // Unlikely, but legal: realloc failed to shrink buffer.
384 _outlineData = polygonData.data;
385 if (_outlineData == NULL)
386 polygonData.OK = NO;
387 }
388 } else {
389 // Empty polygon.
390 _outlineCount = 0;
391 _outlineData = NULL;
392 }
393 }
394
395END:
396 SVGDumpEnd(&polygonData);
397 free(polygonData.data);
398 gluDeleteTess(tesselator);
399 [pool release];
400#ifndef NDEBUG
401 DESTROY(polygonData.debugSVG);
402#endif
403 return polygonData.OK;
404}
static void APIENTRY TessVertexCallback(void *vertexData, void *polygonData)
static void APIENTRY TessEndCallback(void *polygonData)
static void APIENTRY TessBeginCallback(GLenum type, void *polygonData)
static void SVGDumpBeginGroup(TessPolygonData *data, NSString *name)
static NSArray * DataArrayToPoints(TessPolygonData *data, NSArray *dataArray)
GLvoid(* TessFuncPtr)()
static void SubmitVertices(GLUtesselator *tesselator, TessPolygonData *polygonData, NSArray *contour)
static void APIENTRY ErrorCallback(GLenum error, void *polygonData)
static void APIENTRY TessCombineCallback(GLdouble coords[3], void *vertexData[4], GLfloat weight[4], void **outData, void *polygonData)
static NSArray * BuildOutlineContour(NSArray *dataArray, GLfloat width, BOOL inner)
static void SVGDumpBegin(TessPolygonData *data)
static void SVGDumpEndGroup(TessPolygonData *data)
static void SVGDumpEnd(TessPolygonData *data)
static BOOL GrowTessPolygonData(TessPolygonData *data, size_t capacityHint)
NSMutableString * debugSVG

References BuildOutlineContour(), TessPolygonData::capacity, TessPolygonData::count, TessPolygonData::data, DataArrayToPoints(), TessPolygonData::debugSVG, DESTROY, ErrorCallback(), TessPolygonData::generatingOutline, GrowTessPolygonData(), TessPolygonData::name, nil, TessPolygonData::OK, SubmitVertices(), SVGDumpBegin(), SVGDumpBeginGroup(), SVGDumpEnd(), SVGDumpEndGroup(), TessBeginCallback(), TessCombineCallback(), TessEndCallback(), and TessVertexCallback().

Here is the call graph for this function:

◆ oo_drawHUDBeaconIconAt:size:alpha:z:

- (void) oo_drawHUDBeaconIconAt: (NSPoint) where
size: (NSSize) size
alpha: (GLfloat) alpha
z: (GLfloat) z 
implementation

Provided by category OOPolygonSprite(OOHUDBeaconIcon).

Definition at line 4105 of file HeadUpDisplay.m.

4105 :(NSPoint)where size:(NSSize)size alpha:(GLfloat)alpha z:(GLfloat)z
4106{
4107 GLfloat x = where.x - size.width;
4108 GLfloat y = where.y - 1.5 * size.height;
4109
4110 GLfloat ox = x - size.width * 0.5;
4111 GLfloat oy = y - size.height * 0.5;
4112 GLfloat width = size.width * (1.0f / 6.0f);
4113 GLfloat height = size.height * (1.0f / 6.0f);
4114
4117 OOGLScaleModelView(make_vector(width, height, 1.0f));
4118 [self drawFilled];
4119 glColor4f(0.0, 0.0, 0.0, 0.5 * alpha);
4120 [self drawOutline];
4122}
void OOGLScaleModelView(Vector scale)
void OOGLPushModelView(void)
void OOGLTranslateModelView(Vector vector)
OOMatrix OOGLPopModelView(void)
float y
float x
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149
voidpf void uLong size
Definition ioapi.h:126

◆ resetGraphicsState

- (void) resetGraphicsState
implementation

Definition at line 241 of file OOPolygonSprite.m.

242{
243#if OO_USE_VBO
245
246 if (_solidVBO != 0)
247 glDeleteBuffersARB(1, &_solidVBO);
248 if (_outlineVBO != 0)
249 glDeleteBuffersARB(1, &_outlineVBO);
250
251 _solidVBO = 0;
252 _outlineVBO = 0;
253#endif
254}

References OO_ENTER_OPENGL, and resetGraphicsState.

Referenced by resetGraphicsState.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _name

- (NSString*) _name
private

◆ _outlineCount

- (size_t) _outlineCount
private

Definition at line 40 of file OOPolygonSprite.h.

◆ _outlineData

- (GLfloat*) _outlineData
private

Definition at line 39 of file OOPolygonSprite.h.

Referenced by dealloc.

◆ _solidCount

- (size_t) _solidCount
private

Definition at line 38 of file OOPolygonSprite.h.

◆ _solidData

- (GLfloat*) _solidData
private

Definition at line 37 of file OOPolygonSprite.h.

Referenced by dealloc.


The documentation for this class was generated from the following files: