private void PrepareState_Stencil(GpuStateStruct *gpuState) { if (!GL.EnableDisable(GL.GL_STENCIL_TEST, gpuState->StencilState.Enabled)) { return; } //Console.Error.WriteLine("aaaaaa!"); //if (state.stencilFuncFunc == 2) { outputDepthAndStencil(); assert(0); } #if false Console.Error.WriteLine( "{0}:{1}:{2} - {3}, {4}, {5}", StencilFunctionTranslate[(int)GpuState->StencilState.Function], GpuState->StencilState.FunctionRef, GpuState->StencilState.FunctionMask, StencilOperationTranslate[(int)GpuState->StencilState.OperationFail], StencilOperationTranslate[(int)GpuState->StencilState.OperationZFail], StencilOperationTranslate[(int)GpuState->StencilState.OperationZPass] ); #endif GL.glStencilFunc( OpenglGpuImplConversionTables.StencilFunctionTranslate[(int)gpuState->StencilState.Function], gpuState->StencilState.FunctionRef, gpuState->StencilState.FunctionMask ); GL.glStencilOp( OpenglGpuImplConversionTables.StencilOperationTranslate[(int)gpuState->StencilState.OperationFail], OpenglGpuImplConversionTables.StencilOperationTranslate[(int)gpuState->StencilState.OperationZFail], OpenglGpuImplConversionTables.StencilOperationTranslate[(int)gpuState->StencilState.OperationZPass] ); }
public override void Transfer(GpuStateStruct *gpuState) { Console.WriteLine("Transfer Not Implemented"); //return; var textureTransferState = gpuState->TextureTransferState; if ( (textureTransferState.DestinationAddress.Address == gpuState->DrawBufferState.Address) && (textureTransferState.DestinationLineWidth == gpuState->DrawBufferState.Width) && (textureTransferState.BytesPerPixel == gpuState->DrawBufferState.BytesPerPixel) ) { //Console.Error.WriteLine("Writting to DrawBuffer"); TransferToFrameBuffer(gpuState); } else { Console.Error.WriteLine("NOT Writting to DrawBuffer"); TransferGeneric(gpuState); /* * base.Transfer(GpuStateStruct); * PrepareWrite(GpuStateStruct); * { * * } * PrepareRead(GpuStateStruct); */ } Console.Error.WriteLine("GpuImpl.Transfer Not Implemented!! : {0}", gpuState->TextureTransferState.ToStringDefault()); }
internal static void PrepareStateMatrix(GpuStateStruct *gpuState, out Matrix4F worldViewProjectionMatrix) { // DRAW BEGIN COMMON { if (gpuState->VertexState.Type.Transform2D) //if (true) { worldViewProjectionMatrix = Matrix4F.Ortho(0, 512, 272, 0, 0, -0xFFFF); //WorldViewProjectionMatrix = Matrix4f.Ortho(0, 480, 272, 0, 0, -0xFFFF); } else { if (float.IsNaN(gpuState->VertexState.WorldMatrix.Values[0])) { //Console.Error.WriteLine("Invalid WorldMatrix"); //Console.Error.WriteLine("Projection:"); //GpuState->VertexState.ProjectionMatrix.Dump(); //Console.Error.WriteLine("View:"); //GpuState->VertexState.ViewMatrix.Dump(); //Console.Error.WriteLine("World:"); //GpuState->VertexState.WorldMatrix.Dump(); } gpuState->VertexState.ViewMatrix.SetLastColumn(); gpuState->VertexState.WorldMatrix.SetLastColumn(); worldViewProjectionMatrix = Matrix4F.Identity .Multiply(gpuState->VertexState.WorldMatrix.Matrix4) .Multiply(gpuState->VertexState.ViewMatrix.Matrix4) .Multiply(gpuState->VertexState.ProjectionMatrix.Matrix4) ; } } }
private void PrepareState_Texture_Common(GpuStateStruct *gpuState) { var textureMappingState = &gpuState->TextureMappingState; //var ClutState = &TextureMappingState->ClutState; var textureState = &textureMappingState->TextureState; if (!GL.EnableDisable(GL.GL_TEXTURE_2D, textureMappingState->Enabled)) { return; } if (VertexType.Transform2D) { PrepareState_Texture_2D(gpuState); } else { PrepareState_Texture_3D(gpuState); } //GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); RenderbufferManager.TextureCacheGetAndBind(gpuState); //CurrentTexture.Save("test.png"); //GL.glTexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvModeTranslate[(int)TextureState->Effect]); }
public override void PrimStart(GlobalGpuState globalGpuState, GpuStateStruct *gpuState, GuPrimitiveType primitiveType) { GpuState = gpuState; _primitiveType = primitiveType; _doPrimStart = true; ResetVertex(); if (_shader != null) { _shader.GetUniform("lopEnabled").Set(gpuState->LogicalOperationState.Enabled); if (gpuState->LogicalOperationState.Enabled) { if (_logicOpsRenderTarget == null) { _logicOpsRenderTarget = GLRenderTarget.Create(512, 272, RenderTargetLayers.Color); } GLRenderTarget.CopyFromTo(GLRenderTarget.Current, _logicOpsRenderTarget); _shader.GetUniform("backtex").Set(GLTextureUnit.CreateAtIndex(1).SetFiltering(GLScaleFilter.Linear) .SetWrap(GLWrap.ClampToEdge).SetTexture(_logicOpsRenderTarget.TextureColor)); _shader.GetUniform("lop").Set((int)gpuState->LogicalOperationState.Operation); //new Bitmap(512, 272).SetChannelsDataInterleaved(LogicOpsRenderTarget.ReadPixels(), BitmapChannelList.RGBA).Save(@"c:\temp\test.png"); } } }
private void PrepareState_Texture_2D(GpuStateStruct *gpuState) { var textureMappingState = &gpuState->TextureMappingState; var mipmap0 = &textureMappingState->TextureState.Mipmap0; if (textureMappingState->Enabled) { _textureMatrix = Matrix4F.Identity .Scale( 1.0f / mipmap0->BufferWidth, 1.0f / mipmap0->TextureHeight, 1.0f ) ; //GL.ActiveTexture(TextureUnit.Texture0); //GL.MatrixMode(MatrixMode.Texture); //GL.LoadIdentity(); // //GL.Scale( // 1.0f / Mipmap0->BufferWidth, // 1.0f / Mipmap0->TextureHeight, // 1.0f //); } }
public override void Finish(GpuStateStruct *GpuState) { //return; /* * if (GpuState->DrawBufferState.LowAddress != 0) * { * //var Address = PspMemory.FrameBufferOffset | GpuState->DrawBufferState.LowAddress; * var Address = GpuState->DrawBufferState.Address; * try * { * Console.WriteLine("{0:X}", Address); * Memory.CheckAndEnforceAddressValid(Address); * GL.ReadPixels(0, 0, 512, 272, PixelFormat.Rgba, PixelType.UnsignedInt8888, new IntPtr(Memory.PspAddressToPointerSafe(Address))); * } * catch (Exception Exception) * { * // 0x04000000 * Console.WriteLine("Address: {0:X}", Address); * Console.WriteLine(Exception); * //throw(Exception); * } * } */ }
private void PrepareStateDraw(GpuStateStruct *gpuState) { GL.glColorMask(true, true, true, true); #if ENABLE_TEXTURES PrepareState_Texture_Common(gpuState); #endif PrepareState_Blend(gpuState); PrepareState_Clip(gpuState); if (gpuState->VertexState.Type.Transform2D) { PrepareState_Colors_2D(gpuState); GL.glDisable(GL.GL_STENCIL_TEST); GL.glDisable(GL.GL_CULL_FACE); GL.DepthRange(0, 1); GL.glDisable(GL.GL_DEPTH_TEST); //GL.glDisable(EnableCap.Lighting); } else { PrepareState_Colors_3D(gpuState); PrepareState_CullFace(gpuState); PrepareState_Lighting(gpuState); PrepareState_Depth(gpuState); PrepareState_DepthTest(gpuState); PrepareState_Stencil(gpuState); } //GL.ShadeModel((GpuState->ShadeModel == ShadingModelEnum.Flat) ? ShadingModel.Flat : ShadingModel.Smooth); PrepareState_AlphaTest(gpuState); }
private void TransferToFrameBuffer(GpuStateStruct *gpuState) { Console.WriteLine("TransferToFrameBuffer Not Implemented"); //var TextureTransferState = GpuState->TextureTransferState; // //var GlPixelFormat = GlPixelFormatList[(int)GpuState->DrawBufferState.Format]; // //GL.PixelZoom(1, -1); //GL.WindowPos2(TextureTransferState.DestinationX, 272 - TextureTransferState.DestinationY); ////GL.PixelZoom(1, -1); ////GL.PixelZoom(1, 1); //GL.PixelStore(PixelStoreParameter.UnpackAlignment, TextureTransferState.BytesPerPixel); //GL.PixelStore(PixelStoreParameter.UnpackRowLength, TextureTransferState.SourceLineWidth); //GL.PixelStore(PixelStoreParameter.UnpackSkipPixels, TextureTransferState.SourceX); //GL.PixelStore(PixelStoreParameter.UnpackSkipRows, TextureTransferState.SourceY); // //{ // GL.DrawPixels( // TextureTransferState.Width, // TextureTransferState.Height, // PixelFormat.Rgba, // GlPixelFormat.OpenglPixelType, // new IntPtr(Memory.PspAddressToPointerSafe( // TextureTransferState.SourceAddress, // TextureTransferState.Width * TextureTransferState.Height * 4 // )) // ); //} // //GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); //GL.PixelStore(PixelStoreParameter.UnpackRowLength, 0); //GL.PixelStore(PixelStoreParameter.UnpackSkipPixels, 0); //GL.PixelStore(PixelStoreParameter.UnpackSkipRows, 0); }
protected override void ModuleInitialize() { GpuStateStructPartition = MemoryManager.GetPartition(MemoryPartitions.Kernel0).Allocate( sizeof(GpuStateStruct), Name: "GpuStateStruct" ); GpuStateStructPointer = (GpuStateStruct *)GpuStateStructPartition.GetLowPointerSafe <GpuStateStruct>(); }
private void PrepareState_CullFace(GpuStateStruct *GpuState) { if (!GlEnableDisable(EnableCap.CullFace, GpuState->BackfaceCullingState.Enabled)) { return; } GL.CullFace((GpuState->BackfaceCullingState.FrontFaceDirection == State.SubStates.FrontFaceDirectionEnum.ClockWise) ? CullFaceMode.Front : CullFaceMode.Back); }
public int _sceGeListEnQueue(uint InstructionAddressStart, uint InstructionAddressStall, int CallbackId, PspGeListArgs* Args, Action<GpuDisplayList> Action) { //Console.WriteLine("aaaaaaaaaaa"); if (GpuStateStructPartition == null) { GpuStateStructPartition = MemoryManager.GetPartition(Managers.HleMemoryManager.Partitions.Kernel0).Allocate( sizeof(GpuStateStruct), Name: "GpuStateStruct" ); GpuStateStructPointer = (GpuStateStruct*)MemoryManager.Memory.PspAddressToPointerSafe(GpuStateStructPartition.Low, Marshal.SizeOf(typeof(GpuStateStruct))); } //Console.WriteLine("_sceGeListEnQueue"); try { var DisplayList = GpuProcessor.DequeueFreeDisplayList(); { DisplayList.InstructionAddressStart = InstructionAddressStart; DisplayList.InstructionAddressCurrent = InstructionAddressStart; DisplayList.InstructionAddressStall = InstructionAddressStall; DisplayList.CallbacksId = -1; DisplayList.Callbacks = default(PspGeCallbackData); if (CallbackId != -1) { try { //DisplayList.Callbacks = Callbacks[CallbackId]; DisplayList.Callbacks = Callbacks[CallbackId]; DisplayList.CallbacksId = CallbackId; } catch { } } DisplayList.GpuStateStructPointer = null; if (Args != null) { DisplayList.GpuStateStructPointer = (GpuStateStruct*)CpuProcessor.Memory.PspAddressToPointerSafe(Args[0].GpuStateStructAddress, Marshal.SizeOf(typeof(GpuStateStruct))); } if (DisplayList.GpuStateStructPointer == null) { DisplayList.GpuStateStructPointer = GpuStateStructPointer; } Action(DisplayList); } return DisplayList.Id; } catch (Exception Exception) { Console.Error.WriteLine(Exception); //return -1; throw(Exception); } }
private void PrepareState_DepthTest(GpuStateStruct *GpuState) { GL.DepthMask(GpuState->DepthTestState.Mask == 0); if (!GlEnableDisable(EnableCap.DepthTest, GpuState->DepthTestState.Enabled)) { return; } //GL.DepthFunc(DepthFunction.Greater); GL.DepthFunc(TestTranslate[(int)GpuState->DepthTestState.Function]); }
private void PrepareState_AlphaTest(GpuStateStruct *GpuState) { if (!GlEnableDisable(EnableCap.AlphaTest, GpuState->AlphaTestState.Enabled)) { return; } GL.AlphaFunc( (AlphaFunction)TestTranslate[(int)GpuState->AlphaTestState.Function], GpuState->AlphaTestState.Value ); }
private void PrepareState_AlphaTest(GpuStateStruct *gpuState) { //if (!GL.EnableDisable(EnableCap.AlphaTest, GpuState->AlphaTestState.Enabled)) //{ // return; //} // //GL.glAlphaFunc( // (AlphaFunction)DepthFunctionTranslate[(int)GpuState->AlphaTestState.Function], // GpuState->AlphaTestState.Value //); }
internal static void PrepareStateClear(GpuStateStruct *gpuState) { bool ccolorMask = false, calphaMask = false; //return; GL.glDisable(GL.GL_BLEND); //GL.glDisable(GL.GL_LIGHTING); GL.glDisable(GL.GL_TEXTURE_2D); //GL.glDisable(GL.GL_ALPHA_TEST); GL.glDisable(GL.GL_DEPTH_TEST); GL.glDisable(GL.GL_STENCIL_TEST); //GL.glDisable(GL.GL_FOG); //GL.glDisable(GL.GL_LOGIC_OP); GL.glDisable(GL.GL_CULL_FACE); GL.glDepthMask(false); if (gpuState->ClearFlags.HasFlag(ClearBufferSet.ColorBuffer)) { ccolorMask = true; } if (GL.EnableDisable(GL.GL_STENCIL_TEST, gpuState->ClearFlags.HasFlag(ClearBufferSet.StencilBuffer))) { calphaMask = true; // Sets to 0x00 the stencil. // @TODO @FIXME! : Color should be extracted from the color! (as alpha component) GL.glStencilFunc(GL.GL_ALWAYS, 0x00, 0xFF); GL.glStencilOp(GL.GL_REPLACE, GL.GL_REPLACE, GL.GL_REPLACE); //Console.Error.WriteLine("Stencil!"); //GL.Enable(EnableCap.DepthTest); } //int i; glGetIntegerv(GL_STENCIL_BITS, &i); writefln("GL_STENCIL_BITS: %d", i); if (gpuState->ClearFlags.HasFlag(ClearBufferSet.DepthBuffer)) { GL.glEnable(GL.GL_DEPTH_TEST); GL.glDepthFunc(GL.GL_ALWAYS); GL.glDepthMask(true); GL.DepthRange(0, 0); //glDepthRange(0.0, 1.0); // Original value } GL.glColorMask(ccolorMask, ccolorMask, ccolorMask, calphaMask); //glClearDepth(0.0); glClear(GL_COLOR_BUFFER_BIT); //if (state.clearFlags & ClearBufferMask.GU_COLOR_BUFFER_BIT) glClear(GL_DEPTH_BUFFER_BIT); //GL.Clear(ClearBufferMask.StencilBufferBit); }
public static void PrepareStateCommon(GpuStateStruct *gpuState, int scaleViewport) { // ReSharper disable once UnusedVariable var viewport = gpuState->Viewport; //ViewportStruct( // Position=Vector3f(X=2048,Y=2048,Z=0.9999847), // Scale=Vector3f(X=480,Y=-272,Z=-32768), // RegionTopLeft=PointS(X=0,Y=0), // RegionBottomRight=PointS(X=479,Y=271) //) //ViewportStruct( // RegionSize=PointS(X=384,Y=240), // Position=Vector3f(X=2048,Y=2048,Z=0), // Scale=Vector3f(X=480,Y=-272,Z=0), // RegionTopLeft=PointS(X=0,Y=0), // RegionBottomRight=PointS(X=383,Y=239) //) //Console.Error.WriteLine(Viewport.ToString()); //GL.Hint(HintTarget.PolygonSmoothHint, HintMode.Fastest); //GL.Hint(HintTarget.LineSmoothHint, HintMode.Fastest); //GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Fastest); //GL.Hint(HintTarget.PointSmoothHint, HintMode.Fastest); /* * int halfHeight = Math.abs(context.viewport_height); * int halfWidth = Math.abs(context.viewport_width); * int viewportX = context.viewport_cx - halfWidth - context.offset_x; * int viewportY = context.viewport_cy - halfHeight - context.offset_y; * int viewportWidth = 2 * halfWidth; * int viewportHeight = 2 * halfHeight; * * // For OpenGL, translate the viewportY from the upper left corner * // to the lower left corner. * viewportY = Screen.height - viewportY - viewportHeight; * * re.setViewport(viewportX, viewportY, viewportWidth, viewportHeight); */ //int ScreenWidth = 480; //int ScreenHeight = 272; // //int ScaledWidth = (int)(((double)ScreenWidth / (double)Viewport.RegionSize.X) * (double)ScreenWidth); //int ScaledHeight = (int)(((double)ScreenHeight / (double)Viewport.RegionSize.Y) * (double)ScreenHeight); // //GL.glViewport( // (int)Viewport.RegionTopLeft.X * ScaleViewport, // (int)Viewport.RegionTopLeft.Y * ScaleViewport, // ScaledWidth * ScaleViewport, // ScaledHeight * ScaleViewport //); }
private void PrepareState_CullFace(GpuStateStruct *gpuState) { if (!GL.EnableDisable(GL.GL_CULL_FACE, gpuState->BackfaceCullingState.Enabled)) { return; } //GL.EnableDisable(EnableCap.CullFace, false); GL.glCullFace((gpuState->BackfaceCullingState.FrontFaceDirection == FrontFaceDirectionEnum.ClockWise) ? GL.GL_FRONT : GL.GL_BACK); }
private void PrepareState_Lighting(GpuStateStruct *GpuState) { //Console.WriteLine(GpuState->LightingState.AmbientModelColor); var LightingState = &GpuState->LightingState; // if (!glEnableDisable(GL_LIGHTING, state.lighting.enabled) && (state.texture.mapMode != TextureMapMode.GU_ENVIRONMENT_MAP)) { if (!GlEnableDisable(EnableCap.Lighting, LightingState->Enabled)) { return; } GL.LightModel( LightModelParameter.LightModelColorControl, (int)((LightingState->LightModel == LightModelEnum.SeparateSpecularColor) ? LightModelColorControl.SeparateSpecularColor : LightModelColorControl.SingleColor) ); GL.LightModel(LightModelParameter.LightModelAmbient, &LightingState->AmbientLightColor.Red); for (int n = 0; n < 4; n++) { var LightState = &(&LightingState->Light0)[n]; LightName LightName = (LightName)(LightName.Light0 + n); if (!GlEnableDisable((EnableCap)(EnableCap.Light0 + n), LightState->Enabled)) { continue; } GL.Light(LightName, LightParameter.Specular, &LightState->SpecularColor.Red); GL.Light(LightName, LightParameter.Ambient, &LightState->AmbientColor.Red); GL.Light(LightName, LightParameter.Diffuse, &LightState->DiffuseColor.Red); LightState->Position.W = 1.0f; GL.Light(LightName, LightParameter.Position, &LightState->Position.X); GL.Light(LightName, LightParameter.ConstantAttenuation, &LightState->Attenuation.Constant); GL.Light(LightName, LightParameter.LinearAttenuation, &LightState->Attenuation.Linear); GL.Light(LightName, LightParameter.QuadraticAttenuation, &LightState->Attenuation.Quadratic); if (LightState->Type == LightTypeEnum.SpotLight) { GL.Light(LightName, LightParameter.SpotDirection, &LightState->SpotDirection.X); GL.Light(LightName, LightParameter.SpotExponent, &LightState->SpotExponent); GL.Light(LightName, LightParameter.SpotCutoff, &LightState->SpotCutoff); } else { GL.Light(LightName, LightParameter.SpotExponent, 0); GL.Light(LightName, LightParameter.SpotCutoff, 180); } } }
private void PrepareState_DepthTest(GpuStateStruct *gpuState) { if (gpuState->DepthTestState.Mask != 0 && gpuState->DepthTestState.Mask != 1) { Console.Error.WriteLine("WARNING! DepthTestState.Mask: {0}", gpuState->DepthTestState.Mask); } GL.glDepthMask(gpuState->DepthTestState.Mask == 0); if (!GL.EnableDisable(GL.GL_DEPTH_TEST, gpuState->DepthTestState.Enabled)) { return; } GL.glDepthFunc( OpenglGpuImplConversionTables.DepthFunctionTranslate[(int)gpuState->DepthTestState.Function]); }
private void PrepareState_Lighting(GpuStateStruct *gpuState) { //var LightingState = &GpuState->LightingState; // //if (!GL.EnableDisable(EnableCap.Lighting, LightingState->Enabled)) //{ // return; //} // //GL.LightModel( // LightModelParameter.LightModelColorControl, // (int)((LightingState->LightModel == LightModelEnum.SeparateSpecularColor) ? LightModelColorControl.SeparateSpecularColor : LightModelColorControl.SingleColor) //); //GL.LightModel(LightModelParameter.LightModelAmbient, &LightingState->AmbientLightColor.Red); // //for (int n = 0; n < 4; n++) //{ // var LightState = &(&LightingState->Light0)[n]; // LightName LightName = (LightName)(LightName.Light0 + n); // // if (!GL.EnableDisable((EnableCap)(EnableCap.Light0 + n), LightState->Enabled)) // { // continue; // } // // GL.Light(LightName, LightParameter.Specular, &LightState->SpecularColor.Red); // GL.Light(LightName, LightParameter.Ambient, &LightState->AmbientColor.Red); // GL.Light(LightName, LightParameter.Diffuse, &LightState->DiffuseColor.Red); // // LightState->Position.W = 1.0f; // GL.Light(LightName, LightParameter.Position, &LightState->Position.X); // // GL.Light(LightName, LightParameter.ConstantAttenuation, &LightState->Attenuation.Constant); // GL.Light(LightName, LightParameter.LinearAttenuation, &LightState->Attenuation.Linear); // GL.Light(LightName, LightParameter.QuadraticAttenuation, &LightState->Attenuation.Quadratic); // // if (LightState->Type == LightTypeEnum.SpotLight) // { // GL.Light(LightName, LightParameter.SpotDirection, &LightState->SpotDirection.X); // GL.Light(LightName, LightParameter.SpotExponent, &LightState->SpotExponent); // GL.Light(LightName, LightParameter.SpotCutoff, &LightState->SpotCutoff); // } // else // { // GL.Light(LightName, LightParameter.SpotExponent, 0); // GL.Light(LightName, LightParameter.SpotCutoff, 180); // } //} }
private void PrepareState_Clip(GpuStateStruct *gpuState) { if (!GL.EnableDisable(GL.GL_SCISSOR_TEST, gpuState->ClipPlaneState.Enabled)) { return; } var scissor = &gpuState->ClipPlaneState.Scissor; GL.glScissor( scissor->Left * ScaleViewport, scissor->Top * ScaleViewport, (scissor->Right - scissor->Left) * ScaleViewport, (scissor->Bottom - scissor->Top) * ScaleViewport ); }
void drawBeginClear(GpuStateStruct *GpuState) { bool ccolorMask = false, calphaMask = false; //return; GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.Lighting); GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.AlphaTest); GL.Disable(EnableCap.DepthTest); GL.Disable(EnableCap.Fog); GL.Disable(EnableCap.ColorLogicOp); GL.Disable(EnableCap.CullFace); GL.DepthMask(false); if (GpuState->ClearFlags.HasFlag(ClearBufferSet.ColorBuffer)) { ccolorMask = true; } if (GlEnableDisable(EnableCap.StencilTest, GpuState->ClearFlags.HasFlag(ClearBufferSet.StencilBuffer))) { calphaMask = true; // Sets to 0x00 the stencil. // @TODO @FIXME! : Color should be extracted from the color! (as alpha component) GL.StencilFunc(StencilFunction.Always, 0, 0xFF); GL.StencilOp(StencilOp.Replace, StencilOp.Replace, StencilOp.Replace); } //int i; glGetIntegerv(GL_STENCIL_BITS, &i); writefln("GL_STENCIL_BITS: %d", i); if (GpuState->ClearFlags.HasFlag(ClearBufferSet.DepthBuffer)) { GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Always); GL.DepthMask(true); GL.DepthRange(0, 0); //glDepthRange(0.0, 1.0); // Original value } GL.ColorMask(ccolorMask, ccolorMask, ccolorMask, calphaMask); //glClearDepth(0.0); glClear(GL_COLOR_BUFFER_BIT); //if (state.clearFlags & ClearBufferMask.GU_COLOR_BUFFER_BIT) glClear(GL_DEPTH_BUFFER_BIT); }
private void PrepareState(GpuStateStruct *GpuState) { GL.ColorMask(true, true, true, true); PrepareState_Texture(GpuState); PrepareState_CullFace(GpuState); PrepareState_Colors(GpuState); PrepareState_Lighting(GpuState); PrepareState_Blend(GpuState); PrepareState_Depth(GpuState); PrepareState_DepthTest(GpuState); PrepareState_Stencil(GpuState); PrepareState_AlphaTest(GpuState); GL.ShadeModel((GpuState->ShadeModel == ShadingModelEnum.Flat) ? ShadingModel.Flat : ShadingModel.Smooth); }
public void BindCurrentDrawBufferTexture(GpuStateStruct *gpuState) { if (_cachedBindAddress != gpuState->DrawBufferState.Address) { GL.glFlush(); GL.glFinish(); _cachedBindAddress = gpuState->DrawBufferState.Address; var key = new DrawBufferKey() { Address = gpuState->DrawBufferState.Address, //Width = (int)GpuState->DrawBufferState.Width, //Height = (int)272, }; CurrentDrawBuffer?.Unbind(); CurrentDrawBuffer = GetOrCreateDrawBufferTexture(key); CurrentDrawBuffer.Bind(); } }
public void StartPrimitive(GpuStateStruct* GpuState, State.GuPrimitiveType PrimitiveType, uint VertexAddress, int VertexCount, ref State.VertexTypeStruct VertexType) { this.GpuState = GpuState; this.VertexType = VertexType; var ViewMatrix = GpuState->VertexState.ViewMatrix.Matrix4; var WorldMatrix = GpuState->VertexState.WorldMatrix.Matrix4; ModelMatrix = Matrix4.Mult(ViewMatrix, WorldMatrix); this.CurrentPrimitiveType = PrimitiveType; WavefrontObjWriter.StartComment("Start: " + this.CurrentPrimitiveType + " : VertexAddress: 0x" + String.Format("{0:X}", VertexAddress) + " : " + VertexCount + " : " + this.VertexType); PrimitiveIndices.Clear(); //throw new NotImplementedException(); /* Console.WriteLine("ViewMatrix (DEMO):"); Console.WriteLine("{0}", Matrix4.Translation(new Vector3(0f, 0f, -3.5f))); Console.WriteLine("ViewMatrix:"); Console.WriteLine("{0}", ViewMatrix); */ }
private void PrepareState_Stencil(GpuStateStruct *GpuState) { if (!GlEnableDisable(EnableCap.StencilTest, GpuState->StencilState.Enabled)) { return; } //if (state.stencilFuncFunc == 2) { outputDepthAndStencil(); assert(0); } GL.StencilFunc( (StencilFunction)TestTranslate[(int)GpuState->StencilState.Function], GpuState->StencilState.FunctionRef, GpuState->StencilState.FunctionMask ); GL.StencilOp( StencilOperationTranslate[(int)GpuState->StencilState.OperationSFail], StencilOperationTranslate[(int)GpuState->StencilState.OperationDpFail], StencilOperationTranslate[(int)GpuState->StencilState.OperationDpPass] ); }
private void PrepareState_Texture_3D(GpuStateStruct *gpuState) { var textureMappingState = &gpuState->TextureMappingState; var textureState = &textureMappingState->TextureState; if (textureMappingState->Enabled) { _textureMatrix = Matrix4F.Identity; switch (textureMappingState->TextureMapMode) { case TextureMapMode.GuTextureCoords: _textureMatrix = _textureMatrix .Translate(textureState->OffsetU, textureState->OffsetV, 0) .Scale(textureState->ScaleU, textureState->ScaleV, 1) ; break; case TextureMapMode.GuTextureMatrix: switch (gpuState->TextureMappingState.TextureProjectionMapMode) { default: Console.Error.WriteLine("NotImplemented: GU_TEXTURE_MATRIX: {0}", gpuState->TextureMappingState.TextureProjectionMapMode); break; } break; case TextureMapMode.GuEnvironmentMap: Console.Error.WriteLine("NotImplemented: GU_ENVIRONMENT_MAP"); break; default: Console.Error.WriteLine("NotImplemented TextureMappingState->TextureMapMode: " + textureMappingState->TextureMapMode); break; } } }
private void PrepareWrite(GpuStateStruct *GpuState) { //Console.WriteLine("PrepareWrite"); try { var GlPixelFormat = GlPixelFormatList[(int)GpuState->DrawBufferState.Format]; int Width = (int)GpuState->DrawBufferState.Width; int Height = 272; int ScanWidth = PixelFormatDecoder.GetPixelsSize(GlPixelFormat.GuPixelFormat, Width); int PixelSize = PixelFormatDecoder.GetPixelsSize(GlPixelFormat.GuPixelFormat, 1); //GpuState->DrawBufferState.Format var Address = (void *)Memory.PspAddressToPointerSafe(GpuState->DrawBufferState.Address); //Console.WriteLine("{0}", GlPixelFormat.GuPixelFormat); //Console.WriteLine("{0:X}", GpuState->DrawBufferState.Address); GL.PixelStore(PixelStoreParameter.PackAlignment, PixelSize); GL.ReadPixels(0, 0, Width, Height, PixelFormat.Rgba, GlPixelFormat.OpenglPixelType, TempBuffer); fixed(void *_TempBufferPtr = &TempBuffer[0]) { var Input = (byte *)_TempBufferPtr; var Output = (byte *)Address; for (int Row = 0; Row < Height; Row++) { var ScanIn = (byte *)&Input[ScanWidth * Row]; var ScanOut = (byte *)&Output[ScanWidth * (Height - Row - 1)]; //Console.WriteLine("{0}:{1},{2},{3}", Row, PixelSize, Width, ScanWidth); PointerUtils.Memcpy(ScanOut, ScanIn, ScanWidth); } } } catch (Exception Exception) { Console.WriteLine(Exception); } }
private void PrepareRead(GpuStateStruct *GpuState) { /* * var Address = GpuState->DrawBufferState.Address; * //Console.WriteLine("PrepareRead: {0:X}", Address); * * try * { * //GL.WindowPos2(0, 272); * //GL.PixelZoom(1, -1); * * GL.DrawPixels(512, 272, PixelFormat.Rgba, PixelType.UnsignedInt8888, new IntPtr(Memory.PspAddressToPointerSafe(Address))); * //GL.DrawPixels(512, 272, PixelFormat.AbgrExt, PixelType.UnsignedInt8888, new IntPtr(Memory.PspAddressToPointerSafe(Address))); * * //GL.WindowPos2(0, 0); * //GL.PixelZoom(1, 1); * } * catch (Exception Exception) * { * Console.WriteLine(Exception); * } */ }
public GLTexture TextureCacheGetAndBind(GpuStateStruct *gpuState) { if (DynarecConfig.EnableRenderTarget) { var textureMappingState = &gpuState->TextureMappingState; var clutState = &textureMappingState->ClutState; var textureState = &textureMappingState->TextureState; var key = new DrawBufferKey() { Address = textureState->Mipmap0.Address, }; if (_drawBufferTextures.ContainsKey(key)) { return(GetOrCreateDrawBufferTexture(key).RenderTarget.TextureColor.Bind()); } } var currentTexture = OpenglGpuImpl.TextureCache.Get(gpuState); currentTexture.Bind(); return(currentTexture.Texture); }
private void PrepareState_Colors(GpuStateStruct *GpuState) { GlEnableDisable(EnableCap.ColorMaterial, VertexType.Color != VertexTypeStruct.ColorEnum.Void); var Color = GpuState->LightingState.AmbientModelColor; GL.Color4(&Color.Red); if (VertexType.Color != VertexTypeStruct.ColorEnum.Void && GpuState->LightingState.Enabled) { ColorMaterialParameter flags = (ColorMaterialParameter)0; /* * glMaterialfv(faces, GL_AMBIENT , [0.0f, 0.0f, 0.0f, 0.0f].ptr); * glMaterialfv(faces, GL_DIFFUSE , [0.0f, 0.0f, 0.0f, 0.0f].ptr); * glMaterialfv(faces, GL_SPECULAR, [0.0f, 0.0f, 0.0f, 0.0f].ptr); */ var MaterialColorComponents = GpuState->LightingState.MaterialColorComponents; if (MaterialColorComponents.HasFlag(LightComponentsSet.Ambient)) { GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Ambient, &GpuState->LightingState.AmbientModelColor.Red); } if (MaterialColorComponents.HasFlag(LightComponentsSet.Diffuse)) { GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Ambient, &GpuState->LightingState.DiffuseModelColor.Red); } if (MaterialColorComponents.HasFlag(LightComponentsSet.Specular)) { GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Ambient, &GpuState->LightingState.SpecularModelColor.Red); } if (MaterialColorComponents.HasFlag(LightComponentsSet.AmbientAndDiffuse)) { flags = ColorMaterialParameter.AmbientAndDiffuse; } else if (MaterialColorComponents.HasFlag(LightComponentsSet.Ambient)) { flags = ColorMaterialParameter.Ambient; } else if (MaterialColorComponents.HasFlag(LightComponentsSet.Diffuse)) { flags = ColorMaterialParameter.Diffuse; } else if (MaterialColorComponents.HasFlag(LightComponentsSet.Specular)) { flags = ColorMaterialParameter.Specular; } else { //throw (new NotImplementedException("Error! : " + MaterialColorComponents)); } //flags = GL_SPECULAR; if (flags != 0) { GL.ColorMaterial(MaterialFace.FrontAndBack, flags); } //glEnable(GL_COLOR_MATERIAL); } GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Emission, &GpuState->LightingState.EmissiveModelColor.Red); }
/// <summary> /// /// </summary> /// <param name="GpuState"></param> public unsafe override void Prim(GpuStateStruct* GpuState, PrimitiveType PrimitiveType, ushort VertexCount) { this.GpuState = GpuState; if (!IsCurrentWindow) { IsCurrentWindow = true; GraphicsContext.MakeCurrent(NativeWindow.WindowInfo); } //Console.WriteLine("--------------------------------------------------------"); VertexType = GpuState->VertexState.Type; VertexReader.SetVertexTypeStruct(VertexType, (byte*)Memory.PspAddressToPointerSafe(GpuState->VertexAddress)); //IndexReader.SetVertexTypeStruct(VertexType, VertexCount, (byte*)Memory.PspAddressToPointerSafe(GpuState->IndexAddress)); int TotalVerticesWithoutMorphing = VertexCount; void* IndexAddress = Memory.PspAddressToPointerSafe(GpuState->IndexAddress); switch (VertexType.Index) { case VertexTypeStruct.IndexEnum.Void: break; case VertexTypeStruct.IndexEnum.Byte: Marshal.Copy(new IntPtr(IndexAddress), IndexListByte, 0, VertexCount); TotalVerticesWithoutMorphing = IndexListByte.Take(VertexCount).Max() + 1; break; case VertexTypeStruct.IndexEnum.Short: Marshal.Copy(new IntPtr(IndexAddress), IndexListShort, 0, VertexCount); TotalVerticesWithoutMorphing = IndexListShort.Take(VertexCount).Max() + 1; break; default: throw (new NotImplementedException()); } //Console.WriteLine(TotalVerticesWithoutMorphing); int MorpingVertexCount = (int)VertexType.MorphingVertexCount + 1; int z = 0; VertexInfo TempVertexInfo; float* Morphs = &GpuState->MorphingState.MorphWeight0; //for (int n = 0; n < MorpingVertexCount; n++) Console.Write("{0}, ", Morphs[n]); Console.WriteLine(""); fixed (VertexInfo* VerticesPtr = Vertices) { for (int n = 0; n < TotalVerticesWithoutMorphing; n++) { //Console.WriteLine(MorpingVertexCount); if (MorpingVertexCount == 1) { VertexReader.ReadVertex(z++, &TempVertexInfo); //Console.WriteLine(TempVertexInfo); VerticesPtr[n] = TempVertexInfo; } else { var ComponentsIn = (float*)&TempVertexInfo; var ComponentsOut = (float*)&VerticesPtr[n]; for (int cc = 0; cc < 20; cc++) ComponentsOut[cc] = 0; for (int m = 0; m < MorpingVertexCount; m++) { VertexReader.ReadVertex(z++, &TempVertexInfo); for (int cc = 0; cc < 20; cc++) ComponentsOut[cc] += ComponentsIn[cc] * Morphs[m]; } } } } //VertexType.Texture == VertexTypeStruct.TextureEnum.Byte //return; //PrepareRead(GpuState); if (GpuState->ClearingMode) { //return; //GL.ClearColor(1, 1, 0, 0); // @TODO: Fake /* */ //PrepareState(GpuState); //return; //Console.WriteLine(VertexCount); drawBeginClear(GpuState); /* GL.ClearColor(0, 0, 0, 1); GL.ClearDepth(0); GL.ClearStencil(0); GL.ClearAccum(0, 0, 0, 0); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit | ClearBufferMask.AccumBufferBit); return; */ } else { PrepareState(GpuState); } // DRAW BEGIN COMMON { if (GpuState->VertexState.Type.Transform2D) { GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0, 512, 272, 0, -0x7FFF, +0x7FFF); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); } else { GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.MultMatrix(GpuState->VertexState.ProjectionMatrix.Values); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.MultMatrix(GpuState->VertexState.ViewMatrix.Values); GL.MultMatrix(GpuState->VertexState.WorldMatrix.Values); if (GpuState->VertexState.WorldMatrix.Values[0] == float.NaN) { throw (new Exception("Invalid WorldMatrix")); } //GpuState->VertexState.ViewMatrix.Dump(); //GpuState->VertexState.WorldMatrix.Dump(); //Console.WriteLine("NO Transform2D"); } } // DRAW ACTUALLY { uint VertexSize = GpuState->VertexState.Type.GetVertexSize(); byte* VertexPtr = (byte*)Memory.PspAddressToPointerSafe(GpuState->VertexAddress); //Console.WriteLine(VertexSize); var BeginMode = default(BeginMode); switch (PrimitiveType) { case PrimitiveType.Lines: BeginMode = BeginMode.Lines; break; case PrimitiveType.LineStrip: BeginMode = BeginMode.LineStrip; break; case PrimitiveType.Triangles: BeginMode = BeginMode.Triangles; break; case PrimitiveType.Points: BeginMode = BeginMode.Points; break; case PrimitiveType.TriangleFan: BeginMode = BeginMode.TriangleFan; break; case PrimitiveType.TriangleStrip: BeginMode = BeginMode.TriangleStrip; break; case PrimitiveType.Sprites: BeginMode = BeginMode.Quads; break; default: throw (new NotImplementedException("Not implemented PrimitiveType:'" + PrimitiveType + "'")); } //Console.WriteLine(BeginMode); GL.Begin(BeginMode); { if (PrimitiveType == PrimitiveType.Sprites) { GL.Disable(EnableCap.CullFace); for (int n = 0; n < VertexCount; n += 2) { VertexInfo VertexInfoTopLeft; VertexInfo VertexInfoTopRight; VertexInfo VertexInfoBottomRight; VertexInfo VertexInfoBottomLeft; ReadVertex(n + 0, &VertexInfoTopLeft); ReadVertex(n + 1, &VertexInfoBottomRight); //if (GpuState->ClearingMode) Console.WriteLine("{0} - {1}", VertexInfoTopLeft, VertexInfoBottomRight); float R = VertexInfoBottomRight.R, G = VertexInfoBottomRight.G, B = VertexInfoBottomRight.B, A = VertexInfoBottomRight.A; float PZ = VertexInfoTopLeft.PZ; float NZ = VertexInfoTopLeft.NZ; VertexInfoTopRight = new VertexInfo() { U = VertexInfoBottomRight.U, V = VertexInfoTopLeft.V, PX = VertexInfoBottomRight.PX, PY = VertexInfoTopLeft.PY, NX = VertexInfoBottomRight.NX, NY = VertexInfoTopLeft.NY, }; VertexInfoBottomLeft = new VertexInfo() { U = VertexInfoTopLeft.U, V = VertexInfoBottomRight.V, PX = VertexInfoTopLeft.PX, PY = VertexInfoBottomRight.PY, NX = VertexInfoTopLeft.NX, NY = VertexInfoBottomRight.NY, }; VertexInfoBottomLeft.R = VertexInfoBottomRight.R = VertexInfoTopRight.R = VertexInfoTopLeft.R = R; VertexInfoBottomLeft.G = VertexInfoBottomRight.G = VertexInfoTopRight.G = VertexInfoTopLeft.G = G; VertexInfoBottomLeft.B = VertexInfoBottomRight.B = VertexInfoTopRight.B = VertexInfoTopLeft.B = B; VertexInfoBottomLeft.A = VertexInfoBottomRight.A = VertexInfoTopRight.A = VertexInfoTopLeft.A = R; VertexInfoBottomLeft.PZ = VertexInfoBottomRight.PZ = VertexInfoTopRight.PZ = VertexInfoTopLeft.PZ = PZ; VertexInfoBottomLeft.NZ = VertexInfoBottomRight.NZ = VertexInfoTopRight.NZ = VertexInfoTopLeft.NZ = NZ; PutVertex(ref VertexInfoTopLeft, ref VertexType); PutVertex(ref VertexInfoTopRight, ref VertexType); PutVertex(ref VertexInfoBottomRight, ref VertexType); PutVertex(ref VertexInfoBottomLeft, ref VertexType); } } else { for (int n = 0; n < VertexCount; n++) { VertexInfo VertexInfo; ReadVertex(n, &VertexInfo); PutVertex(ref VertexInfo, ref VertexType); } } } GL.End(); GL.Flush(); } //Console.WriteLine(VertexCount); //PrepareWrite(GpuState); }
/// <summary> /// /// </summary> /// <param name="GpuState"></param> private unsafe void _Prim(GpuStateStruct* GpuState, GuPrimitiveType PrimitiveType, ushort VertexCount) { //if (PrimitiveType == GuPrimitiveType.TriangleStrip) VertexCount++; //Console.WriteLine("Prim: {0}, {1}", PrimitiveType, VertexCount); this.GpuState = GpuState; //Console.WriteLine("--------------------------------------------------------"); VertexType = GpuState->VertexState.Type; ReadVertexDelegate ReadVertex = ReadVertex_Void; VertexReader.SetVertexTypeStruct( VertexType, (byte*)Memory.PspAddressToPointerSafe(GpuState->GetAddressRelativeToBaseOffset(GpuState->VertexAddress), 0) ); #if DEBUG_VERTEX_TYPE try { if (!File.Exists("VertexType_" + VertexType.Value)) { File.WriteAllBytes( "VertexType_" + VertexType.Value, PointerUtils.PointerToByteArray((byte*)Memory.PspAddressToPointerSafe(GpuState->VertexAddress), 16 * 1024) ); File.WriteAllText( "VertexType_" + VertexType.Value + "_str", VertexCount + "," + PrimitiveType + "\n" + VertexType.ToString() ); OutputVertexInfoStream = File.OpenWrite("VertexType_" + VertexType.Value + "_list"); } } catch { } #endif //IndexReader.SetVertexTypeStruct(VertexType, VertexCount, (byte*)Memory.PspAddressToPointerSafe(GpuState->IndexAddress)); uint TotalVerticesWithoutMorphing = VertexCount; //Console.Error.WriteLine("GpuState->IndexAddress: {0:X}", GpuState->IndexAddress); // Invalid /* if (GpuState->IndexAddress == 0xFFFFFFFF) { //Debug.Fail("Invalid IndexAddress"); throw (new Exception("Invalid IndexAddress == 0xFFFFFFFF")); } */ void* IndexPointer = null; if (VertexType.Index != VertexTypeStruct.IndexEnum.Void) { IndexPointer = Memory.PspAddressToPointerSafe(GpuState->GetAddressRelativeToBaseOffset(GpuState->IndexAddress), 0); } //Console.Error.WriteLine(VertexType.Index); switch (VertexType.Index) { case VertexTypeStruct.IndexEnum.Void: break; case VertexTypeStruct.IndexEnum.Byte: ReadVertex = ReadVertex_Byte; IndexListByte = (byte *)IndexPointer; TotalVerticesWithoutMorphing = 0; for (int n = 0; n < VertexCount; n++) { if (TotalVerticesWithoutMorphing < IndexListByte[n]) TotalVerticesWithoutMorphing = IndexListByte[n]; } break; case VertexTypeStruct.IndexEnum.Short: ReadVertex = ReadVertex_Short; IndexListShort = (ushort*)IndexPointer; TotalVerticesWithoutMorphing = 0; //VertexCount--; for (int n = 0; n < VertexCount; n++) { //Console.Error.WriteLine(IndexListShort[n]); if (TotalVerticesWithoutMorphing < IndexListShort[n]) TotalVerticesWithoutMorphing = IndexListShort[n]; } break; default: throw (new NotImplementedException()); } TotalVerticesWithoutMorphing++; //Console.WriteLine(TotalVerticesWithoutMorphing); int MorpingVertexCount = (int)VertexType.MorphingVertexCount + 1; int z = 0; VertexInfo TempVertexInfo; float* Morphs = &GpuState->MorphingState.MorphWeight0; //for (int n = 0; n < MorpingVertexCount; n++) Console.Write("{0}, ", Morphs[n]); Console.WriteLine(""); //int VertexInfoFloatCount = (sizeof(Color4F) + sizeof(Vector3F) * 3) / sizeof(float); int VertexInfoFloatCount = (sizeof(VertexInfo)) / sizeof(float); fixed (VertexInfo* VerticesPtr = Vertices) { #if true if (MorpingVertexCount == 1) { VertexReader.ReadVertices(0, VerticesPtr, (int)TotalVerticesWithoutMorphing); } else { var ComponentsIn = (float*)&TempVertexInfo; for (int n = 0; n < TotalVerticesWithoutMorphing; n++) { var ComponentsOut = (float*)&VerticesPtr[n]; for (int cc = 0; cc < VertexInfoFloatCount; cc++) ComponentsOut[cc] = 0; for (int m = 0; m < MorpingVertexCount; m++) { VertexReader.ReadVertex(z++, &TempVertexInfo); for (int cc = 0; cc < VertexInfoFloatCount; cc++) ComponentsOut[cc] += ComponentsIn[cc] * Morphs[m]; } VerticesPtr[n].Normal = VerticesPtr[n].Normal.Normalize(); } } #else var ComponentsIn = (float*)&TempVertexInfo; for (int n = 0; n < TotalVerticesWithoutMorphing; n++) { if (MorpingVertexCount == 1) { VertexReader.ReadVertex(z++, &TempVertexInfo); VerticesPtr[n] = TempVertexInfo; //VertexReader.ReadVertices(0, VerticesPtr, TotalVerticesWithoutMorphing); } else { var ComponentsOut = (float*)&VerticesPtr[n]; for (int cc = 0; cc < VertexInfoFloatCount; cc++) ComponentsOut[cc] = 0; for (int m = 0; m < MorpingVertexCount; m++) { VertexReader.ReadVertex(z++, &TempVertexInfo); for (int cc = 0; cc < VertexInfoFloatCount; cc++) ComponentsOut[cc] += ComponentsIn[cc] * Morphs[m]; } } } #endif } //VertexType.Texture == VertexTypeStruct.TextureEnum.Byte //return; //PrepareRead(GpuState); PrepareStateCommon(GpuState); if (GpuState->ClearingMode) { PrepareStateClear(GpuState); } else { PrepareStateDraw(GpuState); } PrepareStateMatrix(GpuState); //GL.Enable(EnableCap.Blend); /* if (CurrentTexture != null) { if (CurrentTexture.TextureHash == 0x2202293873) { Console.Error.WriteLine(CurrentTexture); Console.Error.WriteLine(VertexCount); } } */ _CaptureStartPrimitive(PrimitiveType, GpuState->GetAddressRelativeToBaseOffset(GpuState->VertexAddress), VertexCount, ref VertexType); // DRAW ACTUALLY { //uint VertexSize = GpuState->VertexState.Type.GetVertexSize(); //byte* VertexPtr = (byte*)Memory.PspAddressToPointerSafe(GpuState->VertexAddress); //Console.WriteLine(VertexSize); var BeginMode = default(BeginMode); switch (PrimitiveType) { case GuPrimitiveType.Lines: BeginMode = BeginMode.Lines; break; case GuPrimitiveType.LineStrip: BeginMode = BeginMode.LineStrip; break; case GuPrimitiveType.Triangles: BeginMode = BeginMode.Triangles; break; case GuPrimitiveType.Points: BeginMode = BeginMode.Points; break; case GuPrimitiveType.TriangleFan: BeginMode = BeginMode.TriangleFan; break; case GuPrimitiveType.TriangleStrip: BeginMode = BeginMode.TriangleStrip; break; case GuPrimitiveType.Sprites: BeginMode = BeginMode.Quads; break; default: throw (new NotImplementedException("Not implemented PrimitiveType:'" + PrimitiveType + "'")); } if (PrimitiveType == GuPrimitiveType.Sprites) { GL.Disable(EnableCap.CullFace); } //Console.WriteLine(BeginMode); //lock (GpuLock) { //Console.Error.WriteLine("GL.Begin : Thread : {0}", Thread.CurrentThread.ManagedThreadId); GL.Begin(BeginMode); { if (PrimitiveType == GuPrimitiveType.Sprites) { GL.Disable(EnableCap.CullFace); for (int n = 0; n < VertexCount; n += 2) { VertexInfo V1, V2, V3, V4; ReadVertex(n + 0, &V1); ReadVertex(n + 1, &V3); { //if (GpuState->ClearingMode) Console.WriteLine("{0} - {1}", VertexInfoTopLeft, VertexInfoBottomRight); var Color = V3.Color; var TZ = V1.Texture.Z; var PZ = V1.Position.Z; var NZ = V1.Normal.Z; V2 = new VertexInfo() { Texture = new Vector3F(V3.Texture.X, V1.Texture.Y, TZ), Position = new Vector3F(V3.Position.X, V1.Position.Y, PZ), Normal = new Vector3F(V3.Normal.X, V1.Normal.Y, NZ), }; V4 = new VertexInfo() { Texture = new Vector3F(V1.Texture.X, V3.Texture.Y, TZ), Position = new Vector3(V1.Position.X, V3.Position.Y, PZ), Normal = new Vector3F(V1.Normal.X, V3.Normal.Y, NZ), }; V4.Color = V3.Color = V2.Color = V1.Color = Color; V4.Position.Z = V3.Position.Z = V2.Position.Z = V1.Position.Z = PZ; V4.Normal.Z = V3.Normal.Z = V2.Normal.Z = V1.Normal.Z = NZ; V4.Texture.Z = V3.Texture.Z = V2.Texture.Z = V1.Texture.Z = NZ; } PutVertex(ref V1, ref VertexType); PutVertex(ref V2, ref VertexType); PutVertex(ref V3, ref VertexType); PutVertex(ref V4, ref VertexType); } } else { VertexInfo VertexInfo; //Console.Error.WriteLine("{0} : {1} : {2}", BeginMode, VertexCount, VertexType.Index); for (int n = 0; n < VertexCount; n++) { ReadVertex(n, &VertexInfo); PutVertex(ref VertexInfo, ref VertexType); } } } GL.End(); } } _CaptureEndPrimitive(); //Console.WriteLine(VertexCount); //PrepareWrite(GpuState); #if DEBUG_VERTEX_TYPE if (OutputVertexInfoStream != null) { OutputVertexInfoStream.Close(); OutputVertexInfoStream = null; } #endif }
protected override void ModuleInitialize() { GpuStateStructPartition = MemoryManager.GetPartition(MemoryPartitions.Kernel0).Allocate( sizeof(GpuStateStruct), Name: "GpuStateStruct" ); GpuStateStructPointer = (GpuStateStruct*)GpuStateStructPartition.GetLowPointerSafe<GpuStateStruct>(); }