public virtual void PrecompileGLCmds(qfiles.dmdl_t model) { model.textureCoordBuf = globalModelTextureCoordBuf.Slice(); model.vertexIndexBuf = globalModelVertexIndexBuf.Slice(); ArrayList tmp = new ArrayList(); var count = 0; Int32[] order = model.glCmds; var orderIndex = 0; while (true) { count = order[orderIndex++]; if (count == 0) { break; } tmp.Add(count); if (count < 0) { count = -count; } else { } do { globalModelTextureCoordBuf.Put(BitConverter.ToSingle(BitConverter.GetBytes(order[orderIndex + 0]))); globalModelTextureCoordBuf.Put(BitConverter.ToSingle(BitConverter.GetBytes(order[orderIndex + 1]))); globalModelVertexIndexBuf.Put(order[orderIndex + 2]); orderIndex += 3; }while (--count != 0); } Int32 size = tmp.Count; model.counts = new Int32[size]; model.indexElements = new Int32Buffer[size]; count = 0; var pos = 0; for (var i = 0; i < model.counts.Length; i++) { count = (( Int32 )tmp[i]); model.counts[i] = count; count = (count < 0) ? -count : count; model.vertexIndexBuf.Position = pos; model.indexElements[i] = model.vertexIndexBuf.Slice(); model.indexElements[i].Limit = count; pos += count; } }
public override void GL_SetDefaultState() { GL.ClearColor(1F, 0F, 0.5F, 0.5F); GL.CullFace(CullFaceMode.Front); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Greater, 0.666F); GL.Disable(EnableCap.DepthTest); GL.Disable(EnableCap.CullFace); GL.Disable(EnableCap.Blend); GL.Color4(1, 1, 1, 1); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GL.ShadeModel(ShadingModel.Flat); GL_TextureMode(gl_texturemode.string_renamed); GL_TextureAlphaMode(gl_texturealphamode.string_renamed); GL_TextureSolidMode(gl_texturesolidmode.string_renamed); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, gl_filter_min); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, gl_filter_max); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.Repeat); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL_TexEnv((int)All.Replace); if (qglPointParameterfEXT) { SingleBuffer att_buffer = Lib.NewSingleBuffer(4); att_buffer.Put(0, gl_particle_att_a.value); att_buffer.Put(1, gl_particle_att_b.value); att_buffer.Put(2, gl_particle_att_c.value); GL.Enable(EnableCap.PointSmooth); GL.PointParameter(PointParameterName.PointSizeMin, gl_particle_min_size.value); GL.PointParameter(PointParameterName.PointSizeMax, gl_particle_max_size.value); GL.PointParameter(PointParameterName.PointDistanceAttenuation, att_buffer.Array); } if (qglColorTableEXT && gl_ext_palettedtexture.value != 0F) { GL.Enable(EnableCap.SharedTexturePaletteExt); GL_SetTexturePalette(d_8to24table); } GL_UpdateSwapInterval(); GL.EnableClientState(ArrayCap.VertexArray); GL.ClientActiveTexture(TextureUnit.Texture0); GL.EnableClientState(ArrayCap.TextureCoordArray); }
public static void AddParticle(Single[] org, Int32 color, Single alpha) { if (r_numparticles >= MAX_PARTICLES) { return; } var i = r_numparticles++; var c = particle_t.colorTable[color]; c |= ( Int32 )(alpha * 255) << 24; particle_t.colorArray.Put(i, c); i *= 3; SingleBuffer vertexBuf = particle_t.vertexArray; vertexBuf.Put(i++, org[0]); vertexBuf.Put(i++, org[1]); vertexBuf.Put(i++, org[2]); }
public virtual void AddParticle(float[] org, int color, float alpha) { if (r_numparticles >= Defines.MAX_PARTICLES) { return; } int i = r_numparticles++; int c = particle_t.colorTable[color]; c |= (int)(alpha * 255) << 24; particle_t.colorArray.Put(i, c); i *= 3; SingleBuffer vertexBuf = particle_t.vertexArray; vertexBuf.Put(i++, org[0]); vertexBuf.Put(i++, org[1]); vertexBuf.Put(i++, org[2]); }
public virtual void GL_LerpVerts(Int32 nverts, Int32[] ov, Int32[] v, Single[] move, Single[] frontv, Single[] backv) { Int32 ovv, vv; SingleBuffer lerp = vertexArrayBuf; if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) { Single[] normal; var j = 0; for (var i = 0; i < nverts; i++) { vv = v[i]; normal = r_avertexnormals[(v[i] >> 24) & 0xFF]; ovv = ov[i]; lerp.Put(j, move[0] + (ovv & 0xFF) * backv[0] + (vv & 0xFF) * frontv[0] + normal[0] * Defines.POWERSUIT_SCALE); lerp.Put(j + 1, move[1] + ((ovv >> 8) & 0xFF) * backv[1] + ((vv >> 8) & 0xFF) * frontv[1] + normal[1] * Defines.POWERSUIT_SCALE); lerp.Put(j + 2, move[2] + ((ovv >> 16) & 0xFF) * backv[2] + ((vv >> 16) & 0xFF) * frontv[2] + normal[2] * Defines.POWERSUIT_SCALE); j += 3; } } else { var j = 0; for (var i = 0; i < nverts; i++) { ovv = ov[i]; vv = v[i]; lerp.Put(j, move[0] + (ovv & 0xFF) * backv[0] + (vv & 0xFF) * frontv[0]); lerp.Put(j + 1, move[1] + ((ovv >> 8) & 0xFF) * backv[1] + ((vv >> 8) & 0xFF) * frontv[1]); lerp.Put(j + 2, move[2] + ((ovv >> 16) & 0xFF) * backv[2] + ((vv >> 16) & 0xFF) * frontv[2]); j += 3; } } }
public static void ConvertOrientation(float[] forward, float[] up, SingleBuffer orientation) { orientation.Put(0, forward[0]); orientation.Put(1, forward[2]); orientation.Put(2, -forward[1]); orientation.Put(3, up[0]); orientation.Put(4, up[2]); orientation.Put(5, -up[1]); }
public virtual void GL_DrawAliasFrameLerp(qfiles.dmdl_t paliashdr, Single backlerp) { Single l; qfiles.daliasframe_t frame, oldframe; Int32[] v, ov; Int32[] order; var orderIndex = 0; Int32 count; Single frontlerp; Single alpha; Single[] move = new Single[] { 0, 0, 0 }; Single[][] vectors = new Single[][] { new Single[] { 0, 0, 0 }, new Single[] { 0, 0, 0 }, new Single[] { 0, 0, 0 } }; Single[] frontv = new Single[] { 0, 0, 0 }; Single[] backv = new Single[] { 0, 0, 0 }; Int32 i; Int32 index_xyz; frame = paliashdr.aliasFrames[currententity.frame]; v = frame.verts; oldframe = paliashdr.aliasFrames[currententity.oldframe]; ov = oldframe.verts; order = paliashdr.glCmds; if ((currententity.flags & Defines.RF_TRANSLUCENT) != 0) { alpha = currententity.alpha; } else { alpha = 1F; } if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) { GL.Disable(EnableCap.Texture2D); } frontlerp = 1F - backlerp; Math3D.VectorSubtract(currententity.oldorigin, currententity.origin, frontv); Math3D.AngleVectors(currententity.angles, vectors[0], vectors[1], vectors[2]); move[0] = Math3D.DotProduct(frontv, vectors[0]); move[1] = -Math3D.DotProduct(frontv, vectors[1]); move[2] = Math3D.DotProduct(frontv, vectors[2]); Math3D.VectorAdd(move, oldframe.translate, move); for (i = 0; i < 3; i++) { move[i] = backlerp * move[i] + frontlerp * frame.translate[i]; frontv[i] = frontlerp * frame.scale[i]; backv[i] = backlerp * oldframe.scale[i]; } if (gl_vertex_arrays.value != 0F) { GL_LerpVerts(paliashdr.num_xyz, ov, v, move, frontv, backv); GL.EnableClientState(ArrayCap.VertexArray); new Pinnable(vertexArrayBuf.Array, (ptr) => { GL.VertexPointer(3, VertexPointerType.Float, 0, ptr); }); if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) { GL.DisableClientState(ArrayCap.ColorArray); GL.Color4(shadelight[0], shadelight[1], shadelight[2], alpha); } else { GL.EnableClientState(ArrayCap.ColorArray); new Pinnable(colorArrayBuf.Array, (ptr) => { GL.ColorPointer(4, ColorPointerType.Float, 0, ptr); }); SingleBuffer color = colorArrayBuf; var j = 0; for (i = 0; i < paliashdr.num_xyz; i++) { l = shadedots[(v[i] >> 24) & 0xFF]; color.Put(j++, l * shadelight[0]); color.Put(j++, l * shadelight[1]); color.Put(j++, l * shadelight[2]); color.Put(j++, alpha); } } //if (qglLockArraysEXT) // gl.GlLockArraysEXT(0, paliashdr.num_xyz); while (true) { count = order[orderIndex++]; if (count == 0) { break; } if (count < 0) { count = -count; GL.Begin(PrimitiveType.TriangleFan); } else { GL.Begin(PrimitiveType.TriangleStrip); } if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) { do { index_xyz = order[orderIndex + 2]; orderIndex += 3; GL.ArrayElement(index_xyz); }while (--count != 0); } else { do { GL.TexCoord2(BitConverter.ToSingle(BitConverter.GetBytes(order[orderIndex + 0])), BitConverter.ToSingle(BitConverter.GetBytes(order[orderIndex + 1]))); index_xyz = order[orderIndex + 2]; orderIndex += 3; GL.ArrayElement(index_xyz); }while (--count != 0); } GL.End(); } // if (qglLockArraysEXT) // gl.GlUnlockArraysEXT(); } else { GL_LerpVerts(paliashdr.num_xyz, ov, v, s_lerped, move, frontv, backv); Single[] tmp; while (true) { count = order[orderIndex++]; if (count == 0) { break; } if (count < 0) { count = -count; GL.Begin(PrimitiveType.TriangleFan); } else { GL.Begin(PrimitiveType.TriangleStrip); } if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE)) != 0) { do { index_xyz = order[orderIndex + 2]; orderIndex += 3; GL.Color4(shadelight[0], shadelight[1], shadelight[2], alpha); tmp = s_lerped[index_xyz]; GL.Vertex3(tmp[0], tmp[1], tmp[2]); }while (--count != 0); } else { do { GL.TexCoord2(BitConverter.ToSingle(BitConverter.GetBytes(order[orderIndex + 0])), BitConverter.ToSingle(BitConverter.GetBytes(order[orderIndex + 1]))); index_xyz = order[orderIndex + 2]; orderIndex += 3; l = shadedots[(v[index_xyz] >> 24) & 0xFF]; GL.Color4(l * shadelight[0], l * shadelight[1], l * shadelight[2], alpha); tmp = s_lerped[index_xyz]; GL.Vertex3(tmp[0], tmp[1], tmp[2]); }while (--count != 0); } GL.End(); } } if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) { GL.Enable(EnableCap.Texture2D); } }
public static void ConvertVector(float[] from, SingleBuffer to) { to.Put(0, from[0]); to.Put(1, from[2]); to.Put(2, -from[1]); }
public static void PlayAllSounds(SingleBuffer listenerOrigin) { SingleBuffer sourceOrigin = sourceOriginBuffer; Channel ch; int sourceId; int state; for (int i = 0; i < numChannels; i++) { ch = channels[i]; if (ch.active) { sourceId = ch.sourceId; switch (ch.type) { case Channel.LISTENER: sourceOrigin.Put(0, listenerOrigin.Get(0)); sourceOrigin.Put(1, listenerOrigin.Get(1)); sourceOrigin.Put(2, listenerOrigin.Get(2)); break; case Channel.DYNAMIC: CL_ents.GetEntitySoundOrigin(ch.entnum, entityOrigin); ConvertVector(entityOrigin, sourceOrigin); break; case Channel.FIXED: ConvertVector(ch.origin, sourceOrigin); break; } if (ch.modified) { if (ch.bufferChanged) { try { AL10.AlSourcei(sourceId, AL10.AL_BUFFER, ch.bufferId); } catch (OpenALException e) { AL10.AlSourceStop(sourceId); AL10.AlSourcei(sourceId, AL10.AL_BUFFER, ch.bufferId); } } if (ch.volumeChanged) { AL10.AlSourcef(sourceId, AL10.AL_GAIN, ch.volume); } AL10.AlSourcef(sourceId, AL10.AL_ROLLOFF_FACTOR, ch.rolloff); AL10.AlSource(sourceId, AL10.AL_POSITION, sourceOrigin); AL10.AlSourcePlay(sourceId); ch.modified = false; } else { state = AL10.AlGetSourcei(sourceId, AL10.AL_SOURCE_STATE); if (state == AL10.AL_PLAYING) { AL10.AlSource(sourceId, AL10.AL_POSITION, sourceOrigin); } else { ch.Clear(); } } ch.autosound = false; } } }
public override void S1(int index, float value) { buffer.Put((index + pos) * STRIDE, value); }
public virtual void GL_DrawAliasFrameLerp(qfiles.dmdl_t paliashdr, Single backlerp) { qfiles.daliasframe_t frame = paliashdr.aliasFrames[currententity.frame]; Int32[] verts = frame.verts; qfiles.daliasframe_t oldframe = paliashdr.aliasFrames[currententity.oldframe]; Int32[] ov = oldframe.verts; Single alpha; Int32 size; if ((currententity.flags & Defines.RF_TRANSLUCENT) != 0) { alpha = currententity.alpha; } else { alpha = 1F; } if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) { GL.Disable(EnableCap.Texture2D); } var frontlerp = 1F - backlerp; Math3D.VectorSubtract(currententity.oldorigin, currententity.origin, frontv); Math3D.AngleVectors(currententity.angles, vectors[0], vectors[1], vectors[2]); move[0] = Math3D.DotProduct(frontv, vectors[0]); move[1] = -Math3D.DotProduct(frontv, vectors[1]); move[2] = Math3D.DotProduct(frontv, vectors[2]); Math3D.VectorAdd(move, oldframe.translate, move); for (var i = 0; i < 3; i++) { move[i] = backlerp * move[i] + frontlerp * frame.translate[i]; frontv[i] = frontlerp * frame.scale[i]; backv[i] = backlerp * oldframe.scale[i]; } GL_LerpVerts(paliashdr.num_xyz, ov, verts, move, frontv, backv); new Pinnable(vertexArrayBuf.Array, (ptr) => { GL.VertexPointer(3, VertexPointerType.Float, 0, ptr); }); if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) { GL.Color4(shadelight[0], shadelight[1], shadelight[2], alpha); } else { GL.EnableClientState(ArrayCap.ColorArray); new Pinnable(colorArrayBuf.Array, (ptr) => { GL.ColorPointer(4, ColorPointerType.Float, 0, ptr); }); SingleBuffer color = colorArrayBuf; Single l; size = paliashdr.num_xyz; var j = 0; for (var i = 0; i < size; i++) { l = shadedots[(verts[i] >> 24) & 0xFF]; color.Put(j, l * shadelight[0]); color.Put(j + 1, l * shadelight[1]); color.Put(j + 2, l * shadelight[2]); color.Put(j + 3, alpha); j += 4; } } GL.ClientActiveTexture(TextureUnit.Texture0); new Pinnable(textureArrayBuf.Array, (ptr) => { GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, ptr); }); var pos = 0; Int32[] counts = paliashdr.counts; Int32Buffer srcIndexBuf = null; SingleBuffer dstTextureCoords = textureArrayBuf; SingleBuffer srcTextureCoords = paliashdr.textureCoordBuf; var dstIndex = 0; var srcIndex = 0; Int32 count; Int32 mode; size = counts.Length; for (var j = 0; j < size; j++) { count = counts[j]; if (count == 0) { break; } srcIndexBuf = paliashdr.indexElements[j]; mode = ( Int32 )PrimitiveType.TriangleStrip; if (count < 0) { mode = ( Int32 )PrimitiveType.TriangleFan; count = -count; } srcIndex = pos << 1; srcIndex--; for (var k = 0; k < count; k++) { dstIndex = srcIndexBuf.Get(k) << 1; dstTextureCoords.Put(dstIndex, srcTextureCoords.Get(++srcIndex)); dstTextureCoords.Put(++dstIndex, srcTextureCoords.Get(++srcIndex)); } new Pinnable(srcIndexBuf.Array, (ptr) => { GL.DrawElements(( PrimitiveType )mode, 1, DrawElementsType.UnsignedInt, ptr); }); pos += count; } if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) { GL.Enable(EnableCap.Texture2D); } GL.DisableClientState(ArrayCap.ColorArray); }