29#import "MyOpenGLView.h"
44#define FAR_PLANE (DUST_SCALE * 0.50f)
45#define NEAR_PLANE (DUST_SCALE * 0.25f)
49@interface DustEntity (Private) <OOGraphicsResetClient>
87 vertices[vi + DUST_N_PARTICLES] = vertices[vi];
88 warpinessAttr[vi] = 0.0f;
89 warpinessAttr[vi + DUST_N_PARTICLES] = 1.0f;
94 shaderMode = kShaderModeUnknown;
98 [
self setStatus:STATUS_ACTIVE];
106 options:kOOTextureMinFilterMipMap | kOOTextureMagFilterLinear | kOOTextureAlphaMask
134- (void) setDustColor:(
OOColor *) color
136 if (dust_color) [dust_color release];
137 dust_color = [color retain];
138 [dust_color getRed:&color_fv[0] green:&color_fv[1] blue:&color_fv[2] alpha:&color_fv[3]];
154- (void) updateCameraRelativePosition
156 HPVector c_pos = [PLAYER viewpointPosition];
167 if (
EXPECT_NOT(shaderMode == kShaderModeUnknown)) [
self checkShaderMode];
170 if (shaderMode == kShaderModeOn)
return;
173 Vector
offset = vector_flip(cameraRelativePosition);
178 while (vertices[vi].
x -
offset.x < -half_scale)
180 while (vertices[vi].
x -
offset.x > half_scale)
183 while (vertices[vi].
y -
offset.y < -half_scale)
185 while (vertices[vi].
y -
offset.y > half_scale)
188 while (vertices[vi].z -
offset.z < -half_scale)
190 while (vertices[vi].z -
offset.z > half_scale)
197- (OOShaderProgram *) shader
201 NSString *prefix = [NSString stringWithFormat:
202 @"#define OODUST_SCALE_MAX (float(%g))\n"
203 "#define OODUST_SCALE_FACTOR (float(%g))\n"
204 "#define OODUST_SIZE (float(%g))\n",
205 FAR_PLANE / NEAR_PLANE,
206 1.0f / (FAR_PLANE - NEAR_PLANE),
210 NSDictionary *attributes = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kTangentAttributeIndex]
211 forKey:@"aWarpiness"];
213 shader = [[OOShaderProgram shaderProgramWithVertexShaderName:@"oolite-dust.vertex"
214 fragmentShaderName:@"oolite-dust.fragment"
216 attributeBindings:attributes] retain];
219 OOShaderUniform *uWarp = [[OOShaderUniform alloc] initWithName:@"uWarp"
222 property:@selector(warpVector)
224 OOShaderUniform *uOffsetPlayerPosition = [[OOShaderUniform alloc] initWithName:@"uOffsetPlayerPosition"
227 property:@selector(offsetPlayerPosition)
230 uniforms = [[NSArray alloc] initWithObjects:uWarp, uOffsetPlayerPosition, nil];
232 [uOffsetPlayerPosition release];
238- (Vector) offsetPlayerPosition
241 HPVector c_pos = [PLAYER viewpointPosition];
249 shaderMode = kShaderModeOff;
254 shaderMode = kShaderModeOn;
267- (void) drawImmediate:(
bool)immediate translucent:(
bool)translucent
269 if ([
UNIVERSE breakPatternHide] || !translucent)
return;
272 assert(player !=
nil);
279 if (
EXPECT_NOT(shaderMode == kShaderModeUnknown)) [
self checkShaderMode];
280 BOOL useShader = (shaderMode == kShaderModeOn);
284 GLfloat *fogcolor = [UNIVERSE skyClearColor];
285 float idealDustSize = [[UNIVERSE gameView] viewSize].width / 800.0f;
292 OOGL(glDisableClientState(GL_NORMAL_ARRAY));
297 float dustPointSize = ceil(idealDustSize);
298 if (dustPointSize < 1.0f) dustPointSize = 1.0f;
300 dustIntensity = OOClamp_0_1_f(idealDustSize / dustPointSize);
305 float idealLineSize = idealDustSize * 0.5f;
306 float dustLineSize = ceil(idealLineSize);
307 if (dustLineSize < 1.0f) dustLineSize = 1.0f;
309 dustIntensity = OOClamp_0_1_f(idealLineSize / dustLineSize);
311 if (fogcolor[3] > 0.0)
314 dustIntensity = OOClamp_0_1_f(dustIntensity-(fogcolor[3]*3.0));
318 if (dustIntensity > 0.0)
322 if (player->
isSunlit) color = color_fv;
323 else color =
UNIVERSE->stars_ambient;
324 OOGL(glColor4f(color[0], color[1], color[2], dustIntensity));
329 [[
self shader] apply];
330 [uniforms makeObjectsPerformSelector:@selector(apply)];
335 OOGL(glEnable(GL_FOG));
336 OOGL(glFogi(GL_FOG_MODE, GL_LINEAR));
337 OOGL(glFogfv(GL_FOG_COLOR, fogcolor));
338 OOGL(glHint(GL_FOG_HINT, GL_NICEST));
343 OOGL(glEnable(GL_BLEND));
344 OOGL(glDepthMask(GL_FALSE));
348 OOGL(glDisable(GL_TEXTURE_2D));
352 OOGL(glEnableVertexAttribArrayARB(kTangentAttributeIndex));
353 OOGL(glVertexAttribPointerARB(kTangentAttributeIndex, 1, GL_FLOAT, GL_FALSE, 0, warpinessAttr));
358 Vector warpVector = [
self warpVector];
362 vertices[vi + DUST_N_PARTICLES] = vector_subtract(vertices[vi], warpVector);
366 OOGL(glVertexPointer(3, GL_FLOAT, 0, vertices));
372 OOGL(glDisableVertexAttribArrayARB(kTangentAttributeIndex));
375 OOGL(glEnable(GL_TEXTURE_2D));
386 OOGL(glBlendFunc(GL_SRC_ALPHA, GL_ONE));
388 OOGL(glEnable(GL_POINT_SPRITE_ARB));
390 OOGL(glVertexPointer(3, GL_FLOAT, 0, vertices));
392 OOGL(glDisable(GL_POINT_SPRITE_ARB));
396 OOGL(glDisable(GL_TEXTURE_2D));
397 OOGL(glVertexPointer(3, GL_FLOAT, 0, vertices));
399 OOGL(glEnable(GL_TEXTURE_2D));
407 [OOShaderProgram applyNone];
412 OOGL(glDisable(GL_FOG));
413 OOGL(glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA));
416 OOGL(glDisable(GL_BLEND));
417 OOGL(glDepthMask(GL_TRUE));
420 OOGL(glEnableClientState(GL_NORMAL_ARRAY));
433 shaderMode = kShaderModeUnknown;
444- (NSString *) descriptionForObjDump
447 return [
self descriptionForObjDumpBasic];
#define OO_ENTER_OPENGL()
#define OOVerifyOpenGLState()
BOOL OOCheckOpenGLErrors(NSString *format,...)
void GLScaledLineWidth(GLfloat width)
#define OOSetOpenGLState(STATE)
void GLScaledPointSize(GLfloat size)
#define HYPERSPEED_FACTOR
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)
void registerClient:(id< OOGraphicsResetClient > client)
void unregisterClient:(id< OOGraphicsResetClient > client)
OOGraphicsResetManager * sharedManager()
OOOpenGLExtensionManager * sharedManager()
BOOL haveExtension:(NSString *extension)
id textureWithName:inFolder:options:anisotropy:lodBias:(NSString *name,[inFolder] NSString *directory,[options] OOTextureFlags options,[anisotropy] GLfloat anisotropy,[lodBias] GLfloat lodBias)
void resetGraphicsState()