private void On_ThemeChange(object sender, RoutedEventArgs e) { System.Windows.Controls.MenuItem src = (System.Windows.Controls.MenuItem)e.Source; model.Theme = Theme.GetThemeByName(src.Name); DrawSurface.Focus(); UpdateWindow(); }
private void handleKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.F9) { _points.Clear(); DrawSurface.InvalidateVisual(); parent.CloseDrawWindow(); } }
public void CloseSideColumn() { model.IsSideColumnVisible = false; model.ShowDeleteButton = false; model.EditingEvent = null; UpdateWindow(); DrawSurface.Focus(); }
private void SKElement_MouseMove(object sender, MouseEventArgs e) { var p = e.GetPosition(DrawSurface); if (_painting) { _points.Add(new DrawPoint { X = (float)p.X, Y = (float)p.Y }); DrawSurface.InvalidateVisual(); } }
private void Awake() { resolution = chunkGridResolution * chunksMultiplier * isoMultiplier; Vector3Int center = new Vector3Int(resolution / 2, resolution / 2, resolution / 2); surfaceMap = new SurfaceMap(resolution); SurfaceMap layer1 = new SurfaceMap(resolution); DrawSurface.Sphere(layer1, center, radius, 3, true); DrawSurface.NoiseSettings.lacunarity = 1; DrawSurface.NoiseSettings.persistance = 0; DrawSurface.NoiseSettings.octaves = 1; DrawSurface.NoiseSettings.frequency = 3; DrawSurface.NoiseSettings.gain = 5; DrawSurface.ApplyNoiseToSphere(layer1, center); SurfaceMap.MergeMaterialLayers(surfaceMap, layer1, 1); //SurfaceMap.MergeMaterialLayers(surfaceMap, layer1, 0); //DrawSurface.Cylinder(surfaceMap, new Vector3Int(7, 7, 7), new Vector3Int(13, 13, 10), 6, 2, 0); /*//DrawSurface.Line(layer1, new Vector3Int(1, 0, 0), new Vector3Int(1, 5, 0), 2, 1, false, 0); * * DrawSurface.NoiseSettings.lacunarity = 1; * DrawSurface.NoiseSettings.persistance = 0; * DrawSurface.NoiseSettings.octaves = 1; * DrawSurface.NoiseSettings.frequency = 1; * DrawSurface.NoiseSettings.gain = 20; * DrawSurface.ApplyNoiseToSphere(layer1, center); * SurfaceMap.MergeMaterialLayers(surfaceMap, layer1, 1);*/ voxelMap.size = size; voxelMap.chunkResolution = chunksMultiplier; voxelMap.voxelResolution = chunkGridResolution; voxelMapObject = Instantiate <VoxelMap>(voxelMap, position, rotation); Refresh(); }
private void PrepareStageTexturing(MaterialStage stage, DrawSurface surface, Vertex[] position) { // set privatePolygonOffset if necessary if(stage.PrivatePolygonOffset > 0) { // TODO: Gl.glEnable(Gl.GL_POLYGON_OFFSET_FILL); // TODO: Gl.glPolygonOffset(idE.CvarSystem.GetFloat("r_offsetFactor"), idE.CvarSystem.GetFloat("r_offsetUnits") * stage.PrivatePolygonOffset); } // set the texture matrix if needed if(stage.Texture.HasMatrix == true) { LoadMaterialTextureMatrix(surface.MaterialRegisters, stage.Texture); } // texgens if(stage.Texture.TextureCoordinates == TextureCoordinateGeneration.DiffuseCube) { idConsole.Warning("TODO: TexGen DiffuseCube"); // TODO: Gl.glTexCoordPointer(3, Gl.GL_FLOAT, sizeof( idVertex ), new float[] { position.Normal.X, position.Normal.Y, position.Normal.Z }); } else if((stage.Texture.TextureCoordinates == TextureCoordinateGeneration.SkyboxCube) || (stage.Texture.TextureCoordinates == TextureCoordinateGeneration.WobbleSkyCube)) { idConsole.Warning("TODO: TexGen SkyboxCube | WobbleSky"); // TODO: Gl.glTexCoordPointer(3, Gl.GL_FLOAT, 0, vertexCache.Position( surf->dynamicTexCoords)); } else if(stage.Texture.TextureCoordinates == TextureCoordinateGeneration.Screen) { idConsole.Warning("TODO: TexGen Screen"); /*qglEnable( GL_TEXTURE_GEN_S ); qglEnable( GL_TEXTURE_GEN_T ); qglEnable( GL_TEXTURE_GEN_Q ); float mat[16], plane[4]; myGlMultMatrix( surf->space->modelViewMatrix, backEnd.viewDef->projectionMatrix, mat ); plane[0] = mat[0]; plane[1] = mat[4]; plane[2] = mat[8]; plane[3] = mat[12]; qglTexGenfv( GL_S, GL_OBJECT_PLANE, plane ); plane[0] = mat[1]; plane[1] = mat[5]; plane[2] = mat[9]; plane[3] = mat[13]; qglTexGenfv( GL_T, GL_OBJECT_PLANE, plane ); plane[0] = mat[3]; plane[1] = mat[7]; plane[2] = mat[11]; plane[3] = mat[15]; qglTexGenfv( GL_Q, GL_OBJECT_PLANE, plane );*/ } else if(stage.Texture.TextureCoordinates == TextureCoordinateGeneration.Screen2) { idConsole.Warning("TODO: TexGen Screen2"); /*qglEnable( GL_TEXTURE_GEN_S ); qglEnable( GL_TEXTURE_GEN_T ); qglEnable( GL_TEXTURE_GEN_Q ); float mat[16], plane[4]; myGlMultMatrix( surf->space->modelViewMatrix, backEnd.viewDef->projectionMatrix, mat ); plane[0] = mat[0]; plane[1] = mat[4]; plane[2] = mat[8]; plane[3] = mat[12]; qglTexGenfv( GL_S, GL_OBJECT_PLANE, plane ); plane[0] = mat[1]; plane[1] = mat[5]; plane[2] = mat[9]; plane[3] = mat[13]; qglTexGenfv( GL_T, GL_OBJECT_PLANE, plane ); plane[0] = mat[3]; plane[1] = mat[7]; plane[2] = mat[11]; plane[3] = mat[15]; qglTexGenfv( GL_Q, GL_OBJECT_PLANE, plane );*/ } else if(stage.Texture.TextureCoordinates == TextureCoordinateGeneration.GlassWarp) { idConsole.Warning("TODO: TexGen GlassWarp"); /*if ( tr.backEndRenderer == BE_ARB2) { qglBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, FPROG_GLASSWARP ); qglEnable( GL_FRAGMENT_PROGRAM_ARB ); GL_SelectTexture( 2 ); globalImages->scratchImage->Bind(); GL_SelectTexture( 1 ); globalImages->scratchImage2->Bind(); qglEnable( GL_TEXTURE_GEN_S ); qglEnable( GL_TEXTURE_GEN_T ); qglEnable( GL_TEXTURE_GEN_Q ); float mat[16], plane[4]; myGlMultMatrix( surf->space->modelViewMatrix, backEnd.viewDef->projectionMatrix, mat ); plane[0] = mat[0]; plane[1] = mat[4]; plane[2] = mat[8]; plane[3] = mat[12]; qglTexGenfv( GL_S, GL_OBJECT_PLANE, plane ); plane[0] = mat[1]; plane[1] = mat[5]; plane[2] = mat[9]; plane[3] = mat[13]; qglTexGenfv( GL_T, GL_OBJECT_PLANE, plane ); plane[0] = mat[3]; plane[1] = mat[7]; plane[2] = mat[11]; plane[3] = mat[15]; qglTexGenfv( GL_Q, GL_OBJECT_PLANE, plane ); GL_SelectTexture( 0 ); }*/ } else if(stage.Texture.TextureCoordinates == TextureCoordinateGeneration.ReflectCube) { idConsole.Warning("TODO: TexGen ReflectCube"); /*if ( tr.backEndRenderer == BE_ARB2 ) { // see if there is also a bump map specified const shaderStage_t *bumpStage = surf->material->GetBumpStage(); if ( bumpStage ) { // per-pixel reflection mapping with bump mapping GL_SelectTexture( 1 ); bumpStage->texture.image->Bind(); GL_SelectTexture( 0 ); qglNormalPointer( GL_FLOAT, sizeof( idDrawVert ), ac->normal.ToFloatPtr() ); qglVertexAttribPointerARB( 10, 3, GL_FLOAT, false, sizeof( idDrawVert ), ac->tangents[1].ToFloatPtr() ); qglVertexAttribPointerARB( 9, 3, GL_FLOAT, false, sizeof( idDrawVert ), ac->tangents[0].ToFloatPtr() ); qglEnableVertexAttribArrayARB( 9 ); qglEnableVertexAttribArrayARB( 10 ); qglEnableClientState( GL_NORMAL_ARRAY ); // Program env 5, 6, 7, 8 have been set in RB_SetProgramEnvironmentSpace qglBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, FPROG_BUMPY_ENVIRONMENT ); qglEnable( GL_FRAGMENT_PROGRAM_ARB ); qglBindProgramARB( GL_VERTEX_PROGRAM_ARB, VPROG_BUMPY_ENVIRONMENT ); qglEnable( GL_VERTEX_PROGRAM_ARB ); } else { // per-pixel reflection mapping without a normal map qglNormalPointer( GL_FLOAT, sizeof( idDrawVert ), ac->normal.ToFloatPtr() ); qglEnableClientState( GL_NORMAL_ARRAY ); qglBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, FPROG_ENVIRONMENT ); qglEnable( GL_FRAGMENT_PROGRAM_ARB ); qglBindProgramARB( GL_VERTEX_PROGRAM_ARB, VPROG_ENVIRONMENT ); qglEnable( GL_VERTEX_PROGRAM_ARB ); } } else { qglEnable( GL_TEXTURE_GEN_S ); qglEnable( GL_TEXTURE_GEN_T ); qglEnable( GL_TEXTURE_GEN_R ); qglTexGenf( GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT ); qglTexGenf( GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT ); qglTexGenf( GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT ); qglEnableClientState( GL_NORMAL_ARRAY ); qglNormalPointer( GL_FLOAT, sizeof( idDrawVert ), ac->normal.ToFloatPtr() ); qglMatrixMode( GL_TEXTURE ); float mat[16]; R_TransposeGLMatrix( backEnd.viewDef->worldSpace.modelViewMatrix, mat ); qglLoadMatrixf( mat ); qglMatrixMode( GL_MODELVIEW ); }*/ } }
private void RenderMaterialPasses(DrawSurface surface) { Surface tri = surface.Geometry; idMaterial material = surface.Material; int count; if(material.HasAmbient == false) { // disabled because we don't do lighting right now //TODO: return; } if(material.IsPortalSky == true) { return; } // change the matrix if needed if(surface.Space != _currentSpace) { _effect.View = surface.Space.ModelViewMatrix; _currentSpace = surface.Space; //idConsole.Warning("TODO: RB_SetProgramEnvironmentSpace();"); } // change the scissor if needed if((idE.CvarSystem.GetBool("r_useScissor") == true) && (_currentScissor != surface.ScissorRectangle)) { _currentScissor = surface.ScissorRectangle; _graphicsDevice.ScissorRectangle = new Rectangle( _viewDef.ViewPort.X1 + _currentScissor.X1, _viewDef.ViewPort.Y1 + _currentScissor.Y1, _currentScissor.X2 + 1 - _currentScissor.X1, _currentScissor.Y2 + 1 - _currentScissor.Y1); } // some deforms may disable themselves by setting numIndexes = 0 if(tri.Indexes.Length == 0) { return; } if(tri.AmbientCache == null) { idConsole.WriteLine("RenderShaderPasses: !tri.AmbientCache"); return; } // get the expressions for conditionals / color / texcoords float[] registers = surface.MaterialRegisters; // set face culling appropriately SetCull(material.CullType); // set polygon offset if necessary if(material.TestMaterialFlag(MaterialFlags.PolygonOffset) == true) { idConsole.Warning("TODO: polygon offset fill"); //Gl.glEnable(Gl.GL_POLYGON_OFFSET_FILL); //Gl.glPolygonOffset(idE.CvarSystem.GetFloat("r_offsetFactor"), idE.CvarSystem.GetFloat("r_offsetUnits") * material.PolygonOffset); } if(surface.Space.WeaponDepthHack == true) { idConsole.Warning("TODO: RB_EnterWeaponDepthHack();"); } if(surface.Space.ModelDepthHack != 0.0f) { idConsole.Warning("TODO: RB_EnterModelDepthHack( surf->space->modelDepthHack );"); } foreach(MaterialStage stage in material.Stages) { // check the enable condition if(registers[stage.ConditionRegister] == 0) { continue; } // skip the stages involved in lighting if(stage.Lighting != StageLighting.Ambient) { // disabled because we don't do lighting right now // TODO: continue; } // skip if the stage is ( GL_ZERO, GL_ONE ), which is used for some alpha masks if((stage.DrawStateBits & (MaterialStates.SourceBlendBits | MaterialStates.DestinationBlendBits)) == (MaterialStates.SourceBlendZero | MaterialStates.DestinationBlendOne)) { continue; } // see if we are a new-style stage NewMaterialStage newStage = stage.NewStage; if(newStage.IsEmpty == false) { throw new Exception("THIS MIGHT NOT WORK!!!"); //-------------------------- // // new style stages // //-------------------------- if(idE.CvarSystem.GetBool("r_skipNewAmbient") == true) { continue; } idConsole.Warning("TODO: render"); /*Gl.glColorPointer(4, Gl.GL_UNSIGNED_BYTE, Marshal.SizeOf(typeof(Vertex)), (void*) &ambientCacheData->color); Gl.glVertexAttribPointerARB(9, 3, Gl.GL_FLOAT, false, Marshal.SizeOf(typeof(Vertex)), ambientCacheData->tangents[0].ToFloatPtr()); Gl.glVertexAttribPointerARB(10, 3, Gl.GL_FLOAT, false, Marshal.SizeOf(typeof(Vertex)), ambientCacheData->tangents[1].ToFloatPtr()); Gl.glNormalPointer(Gl.GL_FLOAT, Marshal.SizeOf(typeof(Vertex)), ambientCacheData->normal.ToFloatPtr());*/ //Gl.glEnableClientState(Gl.GL_COLOR_ARRAY); //Gl.glEnableVertexAttribArray(9); //Gl.glEnableVertexAttribArray(10); //Gl.glEnableClientState(Gl.GL_NORMAL_ARRAY); SetState(stage.DrawStateBits); idConsole.Warning("TODO: glBindProgramARB"); /*Gl.glBindProgramARB(Gl.GL_VERTEX_PROGRAM_ARB, newStage.VertexProgram); Gl.glEnable(Gl.GL_VERTEX_PROGRAM_ARB);*/ // megaTextures bind a lot of images and set a lot of parameters // TODO: megatextures /*if ( newStage->megaTexture ) { newStage->megaTexture->SetMappingForSurface( tri ); idVec3 localViewer; R_GlobalPointToLocal( surf->space->modelMatrix, backEnd.viewDef->renderView.vieworg, localViewer ); newStage->megaTexture->BindForViewOrigin( localViewer ); }*/ count = newStage.VertexParameters.Length; for(int i = 0; i < count; i++) { float[] parm = new float[4]; parm[0] = registers[newStage.VertexParameters[i, 0]]; parm[1] = registers[newStage.VertexParameters[i, 1]]; parm[2] = registers[newStage.VertexParameters[i, 2]]; parm[3] = registers[newStage.VertexParameters[i, 3]]; //Gl.glProgramLocalParameter4fvARB(Gl.GL_VERTEX_PROGRAM_ARB, i, parm); } count = newStage.FragmentProgramImages.Length; for(int i = 0; i < count; i++) { if(newStage.FragmentProgramImages[i] != null) { SetTextureUnit(i); newStage.FragmentProgramImages[i].Bind(); } } //Gl.glBindProgramARB(Gl.GL_FRAGMENT_PROGRAM_ARB, newStage.FragmentProgram); //Gl.glEnable(Gl.GL_FRAGMENT_PROGRAM_ARB); // draw it DrawElementsWithCounters(tri); count = newStage.FragmentProgramImages.Length; for(int i = 1; i < count; i++) { if(newStage.FragmentProgramImages[i] != null) { SetTextureUnit(i); idE.ImageManager.BindNullTexture(); } } // TODO: megatexture /*if ( newStage->megaTexture ) { newStage->megaTexture->Unbind(); }*/ SetTextureUnit(0); //Gl.glDisable(Gl.GL_VERTEX_PROGRAM_ARB); //Gl.glDisable(Gl.GL_FRAGMENT_PROGRAM_ARB); // Fixme: Hack to get around an apparent bug in ATI drivers. Should remove as soon as it gets fixed. //Gl.glBindProgramARB(Gl.GL_VERTEX_PROGRAM_ARB, 0); //Gl.glDisableClientState(Gl.GL_COLOR_ARRAY); //Gl.glDisableVertexAttribArrayARB(9); //Gl.glDisableVertexAttribArrayARB(10); //Gl.glDisableClientState(Gl.GL_NORMAL_ARRAY); continue; } else { //-------------------------- // // old style stages // //-------------------------- // set the color float[] color = new float[4]; color[0] = registers[stage.Color.Registers[0]]; color[1] = registers[stage.Color.Registers[1]]; color[2] = registers[stage.Color.Registers[2]]; color[3] = registers[stage.Color.Registers[3]]; // skip the entire stage if an add would be black if(((stage.DrawStateBits & (MaterialStates.SourceBlendBits & MaterialStates.DestinationBlendBits)) == (MaterialStates.SourceBlendOne | MaterialStates.DestinationBlendOne)) && (color[0] <= 0) && (color[1] <= 0) && (color[2] <= 0)) { continue; } // skip the entire stage if a blend would be completely transparent if(((stage.DrawStateBits & (MaterialStates.SourceBlendBits & MaterialStates.DestinationBlendBits)) == (MaterialStates.SourceBlendSourceAlpha | MaterialStates.DestinationBlendOneMinusSourceAlpha)) && (color[3] <= 0)) { continue; } // select the vertex color source if(stage.VertexColor == StageVertexColor.Ignore) { _effect.DiffuseColor = new Vector3(color[0], color[1], color[2]); _effect.Alpha = color[3]; } else { if(stage.VertexColor == StageVertexColor.InverseModulate) { idConsole.Warning("TODO: InverseModulate"); //GL_TextureEnvironment(Gl.GL_COMBINE_ARB); /*GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.CombineRgb, (int) All.Modulate); GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.Source0Rgb, (int) All.Texture); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_SOURCE1_RGB_ARB, Gl.GL_PRIMARY_COLOR_ARB); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_OPERAND0_RGB_ARB, Gl.GL_SRC_COLOR); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_OPERAND1_RGB_ARB, Gl.GL_ONE_MINUS_SRC_COLOR); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_RGB_SCALE_ARB, 1);*/ } // for vertex color and modulated color, we need to enable a second texture stage if(color[0] != 1 || color[1] != 1 || color[2] != 1 || color[3] != 1) { SetTextureUnit(1); idE.ImageManager.WhiteImage.Bind(); idConsole.Warning("TODO: vertex color"); // GL_TextureEnvironment(Gl.GL_COMBINE_ARB); /*Gl.glTexEnvfv(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_COLOR, color); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_COMBINE_RGB_ARB, Gl.GL_MODULATE); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_SOURCE0_RGB_ARB, Gl.GL_PREVIOUS_ARB); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_SOURCE1_RGB_ARB, Gl.GL_CONSTANT_ARB); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_OPERAND0_RGB_ARB, Gl.GL_SRC_COLOR); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_OPERAND1_RGB_ARB, Gl.GL_SRC_COLOR); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_RGB_SCALE_ARB, 1); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_COMBINE_ALPHA_ARB, Gl.GL_MODULATE); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_SOURCE0_ALPHA_ARB, Gl.GL_PREVIOUS_ARB); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_SOURCE1_ALPHA_ARB, Gl.GL_CONSTANT_ARB); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_OPERAND0_ALPHA_ARB, Gl.GL_SRC_ALPHA); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_OPERAND1_ALPHA_ARB, Gl.GL_SRC_ALPHA); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_ALPHA_SCALE, 1); GL_SelectTexture(0);*/ } } // bind the texture BindVariableStageImage(stage.Texture, registers); // set the state SetState(stage.DrawStateBits); PrepareStageTexturing(stage, surface, tri.AmbientCache.Data); // draw it DrawElementsWithCounters(tri); FinishStageTexturing(stage, surface, tri.AmbientCache.Data); if(stage.VertexColor != StageVertexColor.Ignore) { idConsole.Warning("TODO: SVC ignore"); /*GL.DisableClientState(ArrayCap.ColorArray);*/ SetTextureUnit(1); SetTextureEnvironment(Gl.GL_MODULATE); idE.ImageManager.BindNullTexture(); SetTextureUnit(0); SetTextureEnvironment(Gl.GL_MODULATE); } } // reset polygon offset if(material.TestMaterialFlag(MaterialFlags.PolygonOffset) == true) { // TODO: Gl.glDisable(Gl.GL_POLYGON_OFFSET_FILL); } if((surface.Space.WeaponDepthHack == true) || (surface.Space.ModelDepthHack != 0.0f)) { idConsole.Warning("TODO: RB_LeaveDepthHack();"); } } }
/// <summary> /// The triangle functions can check backEnd.currentSpace != surf->space /// to see if they need to perform any new matrix setup. The modelview /// matrix will already have been loaded, and backEnd.currentSpace will /// be updated after the triangle function completes. /// </summary> /// <param name="surfaces"></param> /// <param name="handler"></param> private void RenderDrawSurfaceListWithFunction(DrawSurface[] surfaces, RenderHandler handler) { int count = surfaces.Length; for(int i = 0; i < count; i++) { DrawSurface surface = surfaces[i]; // change the matrix if needed if(surface.Space != _currentSpace) { _effect.View = surface.Space.ModelViewMatrix; } if(surface.Space.WeaponDepthHack == true) { idConsole.Warning("TODO: RB_EnterWeaponDepthHack();"); } if(surface.Space.ModelDepthHack != 0.0f) { idConsole.Warning("TODO: RB_EnterModelDepthHack( drawSurf->space->modelDepthHack );"); } // change the scissor if needed if((idE.CvarSystem.GetBool("r_useScissor") == true) && (_currentScissor != surface.ScissorRectangle)) { _currentScissor = surface.ScissorRectangle; _graphicsDevice.ScissorRectangle = new Rectangle( _viewDef.ViewPort.X1 + _currentScissor.X1, _viewDef.ViewPort.Y1 + _currentScissor.Y1, _currentScissor.X2 + 1 - _currentScissor.X1, _currentScissor.Y2 + 1 - _currentScissor.Y1); } // render it handler(surface); if((surface.Space.WeaponDepthHack == true) || (surface.Space.ModelDepthHack != 0.0f)) { idConsole.Warning("TODO: RB_LeaveDepthHack();"); } _currentSpace = surface.Space; } }
/// <summary> /// Draw non-light dependent passes. /// </summary> /// <param name="surfaces"></param> /// <returns></returns> private int DrawMaterialPasses(DrawSurface[] surfaces) { // only obey skipAmbient if we are rendering a view if((_viewDef.ViewEntities.Count > 0) && (idE.CvarSystem.GetBool("r_skipAmbient") == true)) { return surfaces.Length; } // RB_LogComment( "---------- RB_STD_DrawShaderPasses ----------\n" ); // if we are about to draw the first surface that needs // the rendering in a texture, copy it over if(surfaces[0].Material.Sort >= (float) MaterialSort.PostProcess) { idConsole.Warning("TODO: PostProcess"); /*if ( r_skipPostProcess.GetBool() ) { return 0; } // only dump if in a 3d view if ( backEnd.viewDef->viewEntitys && tr.backEndRenderer == BE_ARB2 ) { globalImages->currentRenderImage->CopyFramebuffer( backEnd.viewDef->viewport.x1, backEnd.viewDef->viewport.y1, backEnd.viewDef->viewport.x2 - backEnd.viewDef->viewport.x1 + 1, backEnd.viewDef->viewport.y2 - backEnd.viewDef->viewport.y1 + 1, true ); } backEnd.currentRenderCopied = true;*/ } SetTextureUnit(1); idE.ImageManager.BindNullTexture(); SetTextureUnit(0); //Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY); SetProgramEnvironment(); // we don't use RB_RenderDrawSurfListWithFunction() // because we want to defer the matrix load because many // surfaces won't draw any ambient passes // TODO: backEnd.currentSpace = NULL; int i; int surfaceCount = surfaces.Length; for(i = 0; i < surfaceCount; i++) { DrawSurface surface = surfaces[i]; // TODO: suppressInSubview /*if ( drawSurfs[i]->material->SuppressInSubview() ) { continue; }*/ // TODO /*if ( backEnd.viewDef->isXraySubview && drawSurfs[i]->space->entityDef ) { if ( drawSurfs[i]->space->entityDef->parms.xrayIndex != 2 ) { continue; } } */ // we need to draw the post process shaders after we have drawn the fog lights if((surface.Material.Sort >= (float) MaterialSort.PostProcess) && (_currentRenderCopied == false)) { break; } RenderMaterialPasses(surface); } SetCull(CullType.TwoSided); // TODO: Gl.glColor3f(1, 1, 1); return i; }
private void FillDepthBufferHandler(DrawSurface drawSurface) { Surface tri = drawSurface.Geometry; idMaterial material = drawSurface.Material; Vector4 color; // update the clip plane if needed // TODO /*if ( backEnd.viewDef->numClipPlanes && surf->space != backEnd.currentSpace ) { GL_SelectTexture( 1 ); idPlane plane; R_GlobalPlaneToLocal( surf->space->modelMatrix, backEnd.viewDef->clipPlanes[0], plane ); plane[3] += 0.5; // the notch is in the middle qglTexGenfv( GL_S, GL_OBJECT_PLANE, plane.ToFloatPtr() ); GL_SelectTexture( 0 ); }*/ if(material.IsDrawn == false) { return; } // some deforms may disable themselves by setting numIndexes = 0 if(tri.Indexes.Length == 0) { return; } // translucent surfaces don't put anything in the depth buffer and don't // test against it, which makes them fail the mirror clip plane operation if(material.Coverage == MaterialCoverage.Translucent) { return; } if(tri.AmbientCache == null) { idConsole.Warning("TODO: RB_T_FillDepthBuffer: !tri->ambientCache"); return; } // get the expressions for conditionals / color / texcoords float[] regs = drawSurface.MaterialRegisters; // if all stages of a material have been conditioned off, don't do anything int stage; MaterialStage materialStage; for(stage = 0; stage < material.Stages.Length; stage++) { materialStage = material.GetStage(stage); // check the stage enable condition if(regs[materialStage.ConditionRegister] != 0) { break; } } if(stage == material.Stages.Length) { return; } // set polygon offset if necessary /*if ( shader->TestMaterialFlag(MF_POLYGONOFFSET) ) { qglEnable( GL_POLYGON_OFFSET_FILL ); qglPolygonOffset( r_offsetFactor.GetFloat(), r_offsetUnits.GetFloat() * shader->GetPolygonOffset() ); }*/ // subviews will just down-modulate the color buffer by overbright if(material.Sort == (float) MaterialSort.Subview) { SetState(MaterialStates.SourceBlendDestinationColor | MaterialStates.DestinationBlendZero | MaterialStates.DepthFunctionLess); idConsole.Warning("TODO: subview color"); /*color[0] = color[1] = color[2] = ( 1.0 / backEnd.overBright ); color[3] = 1;*/ } else { // others just draw black color = new Vector4(0, 0, 0, 1); } /*idDrawVert *ac = (idDrawVert *)vertexCache.Position( tri->ambientCache ); qglVertexPointer( 3, GL_FLOAT, sizeof( idDrawVert ), ac->xyz.ToFloatPtr() ); qglTexCoordPointer( 2, GL_FLOAT, sizeof( idDrawVert ), reinterpret_cast<void *>(&ac->st) );*/ bool drawSolid = false; if(material.Coverage == MaterialCoverage.Opaque) { drawSolid = true; } // we may have multiple alpha tested stages if(material.Coverage == MaterialCoverage.Perforated) { idConsole.Warning("TODO: perforated"); /*// if the only alpha tested stages are condition register omitted, // draw a normal opaque surface bool didDraw = false; qglEnable( GL_ALPHA_TEST ); // perforated surfaces may have multiple alpha tested stages for ( stage = 0; stage < shader->GetNumStages() ; stage++ ) { pStage = shader->GetStage(stage); if ( !pStage->hasAlphaTest ) { continue; } // check the stage enable condition if ( regs[ pStage->conditionRegister ] == 0 ) { continue; } // if we at least tried to draw an alpha tested stage, // we won't draw the opaque surface didDraw = true; // set the alpha modulate color[3] = regs[ pStage->color.registers[3] ]; // skip the entire stage if alpha would be black if ( color[3] <= 0 ) { continue; } qglColor4fv( color ); qglAlphaFunc( GL_GREATER, regs[ pStage->alphaTestRegister ] ); // bind the texture pStage->texture.image->Bind(); // set texture matrix and texGens RB_PrepareStageTexturing( pStage, surf, ac ); // draw it RB_DrawElementsWithCounters( tri ); RB_FinishStageTexturing( pStage, surf, ac ); } qglDisable( GL_ALPHA_TEST ); if ( !didDraw ) { drawSolid = true; }*/ } // draw the entire surface solid if(drawSolid == true) { idConsole.Warning("TODO: qglColor4fv(color);"); idE.ImageManager.WhiteImage.Bind(); // draw it DrawElementsWithCounters(tri); } // reset polygon offset /*if ( shader->TestMaterialFlag(MF_POLYGONOFFSET) ) { qglDisable( GL_POLYGON_OFFSET_FILL ); }*/ // reset blending if(material.Sort == (float) MaterialSort.Subview) { SetState(MaterialStates.DepthFunctionLess); } }
/// <summary> /// If we are rendering a subview with a near clip plane, use a second texture /// to force the alpha test to fail when behind that clip plane. /// </summary> /// <param name="surfaces"></param> private void FillDepthBuffer(DrawSurface[] surfaces) { // if we are just doing 2D rendering, no need to fill the depth buffer if(_viewDef.ViewEntities.Count == 0) { return; } // TODO: RB_LogComment("---------- RB_STD_FillDepthBuffer ----------\n"); // enable the second texture for mirror plane clipping if needed // TODO: plane clipping /*if(backEnd.viewDef->numClipPlanes) { GL_SelectTexture(1); globalImages->alphaNotchImage->Bind(); qglDisableClientState(GL_TEXTURE_COORD_ARRAY); qglEnable(GL_TEXTURE_GEN_S); qglTexCoord2f(1, 0.5); }*/ // the first texture will be used for alpha tested surfaces SetTextureUnit(0); // decal surfaces may enable polygon offset // TODO: qglPolygonOffset(r_offsetFactor.GetFloat(), r_offsetUnits.GetFloat()); SetState(MaterialStates.DepthFunctionLess); // Enable stencil test if we are going to be using it for shadows. // If we didn't do this, it would be legal behavior to get z fighting // from the ambient pass and the light passes. /*qglEnable(GL_STENCIL_TEST); qglStencilFunc(GL_ALWAYS, 1, 255);*/ RenderDrawSurfaceListWithFunction(surfaces, FillDepthBufferHandler); /*if(backEnd.viewDef->numClipPlanes) { GL_SelectTexture(1); globalImages->BindNull(); qglDisable(GL_TEXTURE_GEN_S); GL_SelectTexture(0); }*/ }
private void FinishStageTexturing(MaterialStage stage, DrawSurface surface, Vertex[] position) { // unset privatePolygonOffset if necessary if((stage.PrivatePolygonOffset > 0) && (surface.Material.TestMaterialFlag(MaterialFlags.PolygonOffset) == false)) { // TODO: Gl.glDisable(Gl.GL_POLYGON_OFFSET_FILL); } if((stage.Texture.TextureCoordinates == TextureCoordinateGeneration.DiffuseCube) || (stage.Texture.TextureCoordinates == TextureCoordinateGeneration.SkyboxCube) || (stage.Texture.TextureCoordinates == TextureCoordinateGeneration.WobbleSkyCube)) { idConsole.Warning("TODO: FinishStageTexturing DiffuseCube"); // TODO qglTexCoordPointer( 2, GL_FLOAT, sizeof( idDrawVert ), (void *)&ac->st ); } else if(stage.Texture.TextureCoordinates == TextureCoordinateGeneration.Screen) { idConsole.Warning("TODO: TexCoord Screen"); // TODO: Gl.glDisable(Gl.GL_TEXTURE_GEN_S); // TODO: Gl.glDisable(Gl.GL_TEXTURE_GEN_T); // TODO: Gl.glDisable(Gl.GL_TEXTURE_GEN_Q); } else if(stage.Texture.TextureCoordinates == TextureCoordinateGeneration.Screen2) { idConsole.Warning("TODO: TexCoord Screen2"); // TODO: Gl.glDisable(Gl.GL_TEXTURE_GEN_S); // TODO: Gl.glDisable(Gl.GL_TEXTURE_GEN_T); // TODO: Gl.glDisable(Gl.GL_TEXTURE_GEN_Q); } else if(stage.Texture.TextureCoordinates == TextureCoordinateGeneration.GlassWarp) { idConsole.Warning("TODO: FinishStageTexturing GlassWarp"); /*if ( tr.backEndRenderer == BE_ARB2) { GL_SelectTexture( 2 ); globalImages->BindNull(); GL_SelectTexture( 1 ); if ( pStage->texture.hasMatrix ) { RB_LoadShaderTextureMatrix( surf->shaderRegisters, &pStage->texture ); } qglDisable( GL_TEXTURE_GEN_S ); qglDisable( GL_TEXTURE_GEN_T ); qglDisable( GL_TEXTURE_GEN_Q ); qglDisable( GL_FRAGMENT_PROGRAM_ARB ); globalImages->BindNull(); GL_SelectTexture( 0 ); }*/ } else if(stage.Texture.TextureCoordinates == TextureCoordinateGeneration.ReflectCube) { idConsole.Warning("TODO: FinishStageTexturing ReflectCube"); /*if ( tr.backEndRenderer == BE_ARB2 ) { // see if there is also a bump map specified const shaderStage_t *bumpStage = surf->material->GetBumpStage(); if ( bumpStage ) { // per-pixel reflection mapping with bump mapping GL_SelectTexture( 1 ); globalImages->BindNull(); GL_SelectTexture( 0 ); qglDisableVertexAttribArrayARB( 9 ); qglDisableVertexAttribArrayARB( 10 ); } else { // per-pixel reflection mapping without bump mapping } qglDisableClientState( GL_NORMAL_ARRAY ); qglDisable( GL_FRAGMENT_PROGRAM_ARB ); qglDisable( GL_VERTEX_PROGRAM_ARB ); // Fixme: Hack to get around an apparent bug in ATI drivers. Should remove as soon as it gets fixed. qglBindProgramARB( GL_VERTEX_PROGRAM_ARB, 0 ); } else { qglDisable( GL_TEXTURE_GEN_S ); qglDisable( GL_TEXTURE_GEN_T ); qglDisable( GL_TEXTURE_GEN_R ); qglTexGenf( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); qglTexGenf( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); qglTexGenf( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); qglDisableClientState( GL_NORMAL_ARRAY ); qglMatrixMode( GL_TEXTURE ); qglLoadIdentity(); qglMatrixMode( GL_MODELVIEW ); }*/ } if(stage.Texture.HasMatrix == true) { //Gl.glMatrixMode(Gl.GL_TEXTURE); //Gl.glLoadIdentity(); //Gl.glMatrixMode(Gl.GL_MODELVIEW); } }
protected override void InitializeComponents() { surface = new DrawSurface(); panel.Children.Add(surface); }
protected override void OnViewportWidthChanged(long oldValue, long newValue) { DrawSurface?.InvalidateVisual(); }
private void DrawSurface_MouseEnter(object sender, EventArgs e) { Cursor.Hide(); Globals.TheGame.IsPaused = false; DrawSurface.Select(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { UpdateWindow(); RefreshScreenStopwatch.Start(); Thread backgroundThread = new Thread(() => { while (_renderWindow.IsOpen) { System.Windows.Application.Current?.Dispatcher.Invoke(DispatcherPriority.Loaded, new Action(() => { // Update Year At Mouse model.YearAtMouse = (int)Math.Round( (Mouse.GetPosition().X - _renderWindow.Position.X - model.OffsetX) / (model.IntervalLengthPx * model.Zoom)); bool Update; if (RefreshScreenStopwatch.ElapsedMilliseconds > RefreshRateInSeconds * 1000) { Update = true; RefreshScreenStopwatch.Restart(); } else { Update = IsMouseDown || KeyPressed_W || KeyPressed_A || KeyPressed_S || KeyPressed_D; } // Check if a note needs to be drawn bool DrawNote = false; foreach (EventViewModel n in model.ListOfEvents) { if (n.IsMouseOver(_renderWindow)) { // Update window so the background color changes Update = true; // Check if Note needs to be drawn if (n.Note != null) { DrawNote = true; if (!DisplayEventNoteStopwatch.IsRunning) { DisplayEventNoteStopwatch.Start(); } if (DisplayEventNoteStopwatch.Elapsed.TotalSeconds > model.DisplayNoteDelayInSeconds) { model.EventToDrawNote = n; } } } } if (!DrawNote) { DisplayEventNoteStopwatch.Stop(); DisplayEventNoteStopwatch.Reset(); model.EventToDrawNote = null; } if (Update) { UpdateWindow(); } } )); } }); backgroundThread.Start(); DrawSurface.Focus(); }