/* ARGSUSED */ static double OvalToPoint( Tk_Canvas canvas, /* Canvas containing item. */ Tk_Item *itemPtr, /* Item to check against point. */ double *pointPtr) /* Pointer to x and y coordinates. */ { RectOvalItem *ovalPtr = (RectOvalItem *) itemPtr; double width; int filled; Tk_State state = itemPtr->state; if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } width = (double) ovalPtr->outline.width; if (Canvas(canvas)->currentItemPtr == itemPtr) { if (ovalPtr->outline.activeWidth>width) { width = (double) ovalPtr->outline.activeWidth; } } else if (state == TK_STATE_DISABLED) { if (ovalPtr->outline.disabledWidth>0) { width = (double) ovalPtr->outline.disabledWidth; } } filled = ovalPtr->fillGC != None; if (ovalPtr->outline.gc == None) { width = 0.0; filled = 1; } return TkOvalToPoint(ovalPtr->bbox, width, filled, pointPtr); }
/* ARGSUSED */ static int RectToArea( Tk_Canvas canvas, /* Canvas containing item. */ Tk_Item *itemPtr, /* Item to check against rectangle. */ double *areaPtr) /* Pointer to array of four coordinates (x1, * y1, x2, y2) describing rectangular area. */ { RectOvalItem *rectPtr = (RectOvalItem *) itemPtr; double halfWidth; double width; Tk_State state = itemPtr->state; if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } width = rectPtr->outline.width; if (Canvas(canvas)->currentItemPtr == itemPtr) { if (rectPtr->outline.activeWidth > width) { width = rectPtr->outline.activeWidth; } } else if (state == TK_STATE_DISABLED) { if (rectPtr->outline.disabledWidth > 0) { width = rectPtr->outline.disabledWidth; } } halfWidth = width/2.0; if (rectPtr->outline.gc == None) { halfWidth = 0.0; } if ((areaPtr[2] <= (rectPtr->bbox[0] - halfWidth)) || (areaPtr[0] >= (rectPtr->bbox[2] + halfWidth)) || (areaPtr[3] <= (rectPtr->bbox[1] - halfWidth)) || (areaPtr[1] >= (rectPtr->bbox[3] + halfWidth))) { return -1; } if ((rectPtr->fillGC == None) && (rectPtr->outline.gc != None) && (areaPtr[0] >= (rectPtr->bbox[0] + halfWidth)) && (areaPtr[1] >= (rectPtr->bbox[1] + halfWidth)) && (areaPtr[2] <= (rectPtr->bbox[2] - halfWidth)) && (areaPtr[3] <= (rectPtr->bbox[3] - halfWidth))) { return -1; } if ((areaPtr[0] <= (rectPtr->bbox[0] - halfWidth)) && (areaPtr[1] <= (rectPtr->bbox[1] - halfWidth)) && (areaPtr[2] >= (rectPtr->bbox[2] + halfWidth)) && (areaPtr[3] >= (rectPtr->bbox[3] + halfWidth))) { return 1; } return 0; }
void DebugRenderer::renderBlobs(unsigned char* image, Blobber* blobber, int width, int height) { Canvas canvas = Canvas(); canvas.data = image; canvas.width = width; canvas.height = height; for (int i = 0; i < blobber->getColorCount(); i++) { Blobber::Color* color = blobber->getColor(i); if (color == NULL) { continue; } if ( strcmp(color->name, "ball") != 0 && strcmp(color->name, "yellow-goal") != 0 && strcmp(color->name, "blue-goal") != 0 ) { continue; } Blobber::Blob* blob = blobber->getBlobs(color->name); while (blob != NULL) { canvas.drawBoxCentered( (int)blob->centerX, (int)blob->centerY, blob->x2 - blob->x1, blob->y2 - blob->y1, color->color.red, color->color.green, color->color.blue ); blob = blob->next; } } }
FullScreen::FullScreen() { #ifdef WIN32 clan::D3DTarget::set_current(); #else clan::OpenGLTarget::set_current(); #endif DisplayWindowDescription window_description; window_description.set_title("ClanLib FullScreen Example"); window_description.set_size(Size(700, 600), true); window_description.set_allow_resize(true); window = DisplayWindow(window_description); sc.connect(window.sig_window_close(), clan::bind_member(this, &FullScreen::on_window_close)); sc.connect(window.get_keyboard().sig_key_down(), clan::bind_member(this, &FullScreen::on_input_down)); canvas = Canvas(window); spr_logo = Sprite(canvas, "../Basic2D/Resources/logo.png"); spr_background = Sprite(canvas, "../../Display/Path/Resources/lobby_background2.png"); font = clan::Font("tahoma", 24); game_time.reset(); }
static double TextToPoint( Tk_Canvas canvas, /* Canvas containing itemPtr. */ Tk_Item *itemPtr, /* Item to check against point. */ double *pointPtr) /* Pointer to x and y coordinates. */ { TextItem *textPtr; Tk_State state = itemPtr->state; double value, px, py; if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } textPtr = (TextItem *) itemPtr; px = pointPtr[0] - textPtr->drawOrigin[0]; py = pointPtr[1] - textPtr->drawOrigin[1]; value = (double) Tk_DistanceToTextLayout(textPtr->textLayout, (int) (px*textPtr->cosine - py*textPtr->sine), (int) (py*textPtr->cosine + px*textPtr->sine)); if ((state == TK_STATE_HIDDEN) || (textPtr->color == NULL) || (textPtr->text == NULL) || (*textPtr->text == 0)) { value = 1.0e36; } return value; }
void FRCPassPostProcessVisualizeLPV::Process(FRenderingCompositePassContext& Context) { SCOPED_DRAW_EVENT(Context.RHICmdList, VisualizeLPV); const FSceneView& View = Context.View; const FSceneViewFamily& ViewFamily = *(View.Family); // const FSceneRenderTargetItem& DestRenderTarget = PassOutputs[0].RequestSurface(Context); const TRefCountPtr<IPooledRenderTarget> RenderTarget = GetInput(ePId_Input0)->GetOutput()->PooledRenderTarget; const FSceneRenderTargetItem& DestRenderTarget = RenderTarget->GetRenderTargetItem(); // Set the view family's render target/viewport. SetRenderTarget(Context.RHICmdList, DestRenderTarget.TargetableTexture, FTextureRHIRef()); { FRenderTargetTemp TempRenderTarget(View, (const FTexture2DRHIRef&)DestRenderTarget.TargetableTexture); FCanvas Canvas(&TempRenderTarget, NULL, ViewFamily.CurrentRealTime, ViewFamily.CurrentWorldTime, ViewFamily.DeltaWorldTime, View.GetFeatureLevel()); float X = 30; float Y = 28; const float YStep = 14; const float ColumnWidth = 250; Canvas.DrawShadowedString( X, Y += YStep, TEXT("VisualizeLightPropagationVolume"), GetStatsFont(), FLinearColor(0.2f, 0.2f, 1)); Y += YStep; const FLightPropagationVolumeSettings& Dest = View.FinalPostProcessSettings.BlendableManager.GetSingleFinalDataConst<FLightPropagationVolumeSettings>(); #define ENTRY(name)\ Canvas.DrawShadowedString( X, Y += YStep, TEXT(#name) TEXT(":"), GetStatsFont(), FLinearColor(1, 1, 1));\ Canvas.DrawShadowedString( X + ColumnWidth, Y, *FString::Printf(TEXT("%g"), Dest.name), GetStatsFont(), FLinearColor(1, 1, 1)); ENTRY(LPVIntensity) ENTRY(LPVVplInjectionBias) ENTRY(LPVSize) ENTRY(LPVSecondaryOcclusionIntensity) ENTRY(LPVSecondaryBounceIntensity) ENTRY(LPVGeometryVolumeBias) ENTRY(LPVEmissiveInjectionIntensity) ENTRY(LPVDirectionalOcclusionIntensity) ENTRY(LPVDirectionalOcclusionRadius) ENTRY(LPVDiffuseOcclusionExponent) ENTRY(LPVSpecularOcclusionExponent) ENTRY(LPVDiffuseOcclusionIntensity) ENTRY(LPVSpecularOcclusionIntensity) #undef ENTRY Canvas.Flush_RenderThread(Context.RHICmdList); } Context.RHICmdList.CopyToResolveTarget(DestRenderTarget.TargetableTexture, DestRenderTarget.ShaderResourceTexture, false, FResolveParams()); // to satify following passws FRenderingCompositeOutput* Output = GetOutput(ePId_Output0); Output->PooledRenderTarget = RenderTarget; }
void DebugRenderer::renderBrush(unsigned char* image, int x, int y, int radius, bool active, int width, int height) { Canvas canvas = Canvas(); canvas.data = image; canvas.width = width; canvas.height = height; canvas.drawCircle(x, y, radius, active ? 255 : 0, 0, active ? 0 : 255); }
void DebugRenderer::renderFPS(unsigned char* image, int fps, int width, int height) { Canvas canvas = Canvas(); canvas.data = image; canvas.width = width; canvas.height = height; canvas.drawText(20, 20, "FPS: " + Util::toString(fps)); }
bool FullScreen::update() { const float virtual_screen_width = 800.0f; const float virtual_screen_height = 600.0f; game_time.update(); // Check for fullscreen switch if (fullscreen_requested != is_fullscreen) { is_fullscreen = fullscreen_requested; create_window(); } if (window.get_gc() != canvas.get_gc()) { canvas = Canvas(window); // Always get the graphic context, the window may have been recreated } canvas.clear(Colorf(0.0f,0.0f,0.2f)); int font_size = 28; font_size *= canvas.get_width() / virtual_screen_width; font.set_height(font_size); canvas.set_transform(Mat4f::identity()); if (is_fullscreen) { font.draw_text(canvas, 16, font_size, "Full Screen Mode. Press 'F' to switch to resizable window."); } else { font.draw_text(canvas, 16, font_size, "Resizable Window. Press 'F' to switch to full screen mode."); } // Scale the drawing to the screen to a virtual screen size Mat4f matrix = Mat4f::scale( (float) canvas.get_width() / virtual_screen_width, (float) canvas.get_height() /virtual_screen_height, 1.0f); canvas.set_transform(matrix); spr_logo.draw(canvas, virtual_screen_width-spr_logo.get_width(), virtual_screen_height-spr_logo.get_height()); spr_background.set_scale(0.5f, 0.5f); spr_background.draw(canvas, 100, 100); // Show a few alpha-blending moving rectangles that moves in circles float x = cos(sin_count)*120.0f; float y = sin(sin_count)*120.0f; sin_count += 2.0f * game_time.get_time_elapsed(); canvas.fill_rect(Rectf( 320.0f + x -30.0f, 300.0f + y -30.0f, Sizef(60.0f, 60.0f)), Colorf(0.0f, 1.0f, 0.0, 0.5f)); x = cos(sin_count+3.14159f)*120.0f; y = sin(sin_count+3.14159f)*120.0f; canvas.fill_rect(Rectf( 320.0f + x -30.0f, 300 + y -30.0f, Sizef(60.0f, 60.0f)), Colorf(1.0f, 1.0f, 0.0, 0.5f)); window.flip(1); return !quit; }
static void DisplayImage( Tk_Canvas canvas, /* Canvas that contains item. */ Tk_Item *itemPtr, /* Item to be displayed. */ Display *display, /* Display on which to draw item. */ Drawable drawable, /* Pixmap or window in which to draw item. */ int x, int y, int width, int height) /* Describes region of canvas that must be * redisplayed (not used). */ { ImageItem *imgPtr = (ImageItem *) itemPtr; short drawableX, drawableY; Tk_Image image; Tk_State state = itemPtr->state; if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } image = imgPtr->image; if (Canvas(canvas)->currentItemPtr == itemPtr) { if (imgPtr->activeImage != NULL) { image = imgPtr->activeImage; } } else if (state == TK_STATE_DISABLED) { if (imgPtr->disabledImage != NULL) { image = imgPtr->disabledImage; } } if (image == NULL) { return; } /* * Translate the coordinates to those of the image, then redisplay it. */ Tk_CanvasDrawableCoords(canvas, (double) x, (double) y, &drawableX, &drawableY); Tk_RedrawImage(image, x - imgPtr->header.x1, y - imgPtr->header.y1, width, height, drawable, drawableX, drawableY); }
void DebugRenderer::renderBalls(unsigned char* image, Vision* vision, const ObjectList& balls, int width, int height) { Canvas canvas = Canvas(); canvas.data = image; canvas.width = width; canvas.height = height; Object* ball = NULL; char buf[256]; //int correctedX, correctedY; for (ObjectListItc it = balls.begin(); it != balls.end(); it++) { ball = *it; canvas.drawBoxCentered(ball->x, ball->y, ball->width, ball->height); //canvas.drawLine(ball->x - ball->width / 2, ball->y - ball->height / 2, ball->x + ball->width / 2, ball->y + ball->height / 2); //canvas.drawLine(ball->x - ball->width / 2, ball->y + ball->height / 2, ball->x + ball->width / 2, ball->y - ball->height / 2); sprintf(buf, "%.2fm x %.2fm %.1f deg", ball->distanceX, ball->distanceY, Math::radToDeg(ball->angle)); canvas.drawText(ball->x - ball->width / 2 + 2, ball->y - ball->height / 2 - 22, buf); //correctedX = ball->x; //correctedY = ball->y + ball->height / 2; CameraTranslator::CameraPosition undistortedPos = vision->getCameraTranslator()->undistort(ball->x, ball->y + ball->height / 2); //Util::correctCameraPoint(correctedX, correctedY); sprintf(buf, "%d x %d - %d x %d", ball->x, ball->y + ball->height / 2, undistortedPos.x, undistortedPos.y); canvas.drawText(ball->x - ball->width / 2 + 2, ball->y - ball->height / 2 - 12, buf); //int boxArea = ball->width * ball->height; /*if (boxArea == 0) { continue; } int density = ball->area * 100 / boxArea; sprintf(buf, "%d - %d%%", ball->area, density); canvas.drawText(ball->x - ball->width / 2 + 2, ball->y - ball->height / 2 - 9, buf);*/ } // TEMP - draw centerline //canvas.drawLine(canvas.width / 2, 0, canvas.width / 2, canvas.height); //canvas.fillCircleCentered(Config::cameraWidth / 2, Config::cameraHeight / 2, 100, 0, 0, 255); /*Blobber::Blob* blob = blobber->getBlobs("ball"); while (blob != NULL) { image->drawBoxCentered(blob->centerX, blob->centerY, blob->x2 - blob->x1, blob->y2 - blob->y1); blob = blob->next; }*/ }
void DebugRenderer::renderObjectHighlight(unsigned char* image, Object* object, int red, int green, int blue, int width, int height) { Canvas canvas = Canvas(); canvas.data = image; canvas.width = width; canvas.height = height; canvas.drawBoxCentered(object->x, object->y, object->width + 4, object->height + 4, red, green, blue); canvas.drawLine(object->x - object->width / 2, object->y - object->height / 2, object->x + object->width / 2, object->y + object->height / 2, red, green, blue); canvas.drawLine(object->x - object->width / 2, object->y + object->height / 2, object->x + object->width / 2, object->y - object->height / 2, red, green, blue); }
RenderTechnique::PassElm RenderTechnique::addPass( NameID& name, unsigned int texCount, Effect* effect, int width, int height, bool flipH, bool flipV, bool renderToCanvas ) { for( PassElm p = m_passes.FirstPointer(); !p.IsEmpty(); p.Next() ) if( p() && name == p()->name ) return( PassElm() ); if( static_cast<int>(texCount) > Global::use().engine->getTextureUnitsCount() ) return( PassElm() ); Engine::WindowRect wr; Global::use().engine->getWindowRect( wr ); if( width <= 0 ) width = wr.width; if( height <= 0 ) height = wr.height; Pass* p = new Pass( name ); PassElm pass = m_passes.AddPointer( p ); if( pass.IsEmpty() ) { DELETE_OBJECT( p ); return( PassElm() ); } p->inputTextures.Reserve( texCount ); p->inputTexturesMine.Reserve( texCount ); for( unsigned int i = 0; i < p->inputTextures.Size(); i++ ) { p->inputTextures[ i ] = 0; p->inputTexturesMine[ i ] = false; } p->outputMaterial = xnew Material(); p->outputMaterial->setEffect( effect ); p->outputScene = xnew SpriteBatch( 1 ); p->outputScene->setCamera( xnew Camera2D( 0.0f, 0.0f, static_cast<float>(width), static_cast<float>(height), 0.0f ) ); p->outputQuad = xnew SpriteBatch::Sprite(); p->outputQuad->setMaterial( p->outputMaterial ); p->outputQuad->setWidth( static_cast<float>(width) ); p->outputQuad->setHeight( static_cast<float>(height) ); if( flipH ) p->outputQuad->flip( SpriteBatch::Sprite::ftHorizontal ); if( flipV ) p->outputQuad->flip( SpriteBatch::Sprite::ftVertical ); p->outputScene->attach( p->outputQuad ); if( renderToCanvas ) { p->outputCanvas = xnew Canvas( width, height ); p->outputScene->setCanvas( p->outputCanvas ); p->outputCanvas->setClearOnActivate( true ); } return( pass ); }
WindowView_Impl::WindowView_Impl(WindowView *view, const DisplayWindowDescription &desc) : window_view(view), window(desc) { canvas = Canvas(window); slots.connect(window.sig_lost_focus(), clan::bind_member(this, &WindowView_Impl::on_lost_focus)); slots.connect(window.sig_got_focus(), clan::bind_member(this, &WindowView_Impl::on_got_focus)); slots.connect(window.sig_resize(), clan::bind_member(this, &WindowView_Impl::on_resize)); slots.connect(window.sig_paint(), clan::bind_member(this, &WindowView_Impl::on_paint)); slots.connect(window.sig_window_close(), clan::bind_member(this, &WindowView_Impl::on_window_close)); slots.connect(window.get_ic().get_keyboard().sig_key_down(), clan::bind_member(this, &WindowView_Impl::on_key_down)); slots.connect(window.get_ic().get_keyboard().sig_key_up(), clan::bind_member(this, &WindowView_Impl::on_key_up)); slots.connect(window.get_ic().get_mouse().sig_key_down(), clan::bind_member(this, &WindowView_Impl::on_mouse_down)); slots.connect(window.get_ic().get_mouse().sig_key_dblclk(), clan::bind_member(this, &WindowView_Impl::on_mouse_dblclk)); slots.connect(window.get_ic().get_mouse().sig_key_up(), clan::bind_member(this, &WindowView_Impl::on_mouse_up)); slots.connect(window.get_ic().get_mouse().sig_pointer_move(), clan::bind_member(this, &WindowView_Impl::on_mouse_move)); }
void DebugRenderer::renderGoals(unsigned char* image, const ObjectList& goals, int width, int height) { Canvas canvas = Canvas(); canvas.data = image; canvas.width = width; canvas.height = height; Object* goal = NULL; char buf[256]; int r, g, b; for (ObjectListItc it = goals.begin(); it != goals.end(); it++) { goal = *it; if (goal->type == Side::YELLOW) { r = 200; g = 200; b = 0; } else { r = 0; g = 0; b = 200; } canvas.drawBoxCentered(goal->x, goal->y, goal->width, goal->height, r, g, b); //canvas.drawLine(goal->x - goal->width / 2, goal->y - goal->height / 2, goal->x + goal->width / 2, goal->y + goal->height / 2, r, g, b); //canvas.drawLine(goal->x - goal->width / 2, goal->y + goal->height / 2, goal->x + goal->width / 2, goal->y - goal->height / 2, r, g, b); sprintf(buf, "%.2fm %.1f deg", goal->distance, Math::radToDeg(goal->angle)); canvas.drawText(goal->x - goal->width / 2 + 2, goal->y + goal->height / 2 + 2, buf, r, g, b); sprintf(buf, "%d x %d, %d", goal->x, goal->y + goal->height / 2, goal->area); canvas.drawText(goal->x - goal->width / 2 + 2, goal->y + goal->height / 2 + 12, buf, r, g, b); /*int boxArea = goal->width * goal->height; if (boxArea == 0) { continue; } int density = goal->area * 100 / boxArea; sprintf(buf, "%d - %d%%", goal->area, density); canvas.drawText(goal->x - goal->width / 2 + 2, goal->y - goal->height / 2 - 9, buf);*/ } }
HSV::HSV() { clan::OpenGLTarget::set_current(); window = DisplayWindow("ClanLib HSV Sprite", 1024, 768); sc.connect(window.sig_window_close(), clan::bind_member(this, &HSV::on_close)); sc.connect(window.get_keyboard().sig_key_up(), clan::bind_member(this, &HSV::on_input_up)); canvas = Canvas(window); font = clan::Font("Tahoma", 11); sprite_batcher = std::make_shared<HSVSpriteBatch>(canvas); car1 = std::make_shared<HSVSprite>(canvas, sprite_batcher.get(), "Resources/spaceshoot_body_moving1.png"); car2 = std::make_shared<HSVSprite>(canvas, sprite_batcher.get(), "Resources/ferrari_maranello.png"); last_fps_update = System::get_time(); last_time = last_fps_update; }
void DebugRenderer::renderObstructions(unsigned char* image, Obstruction obstruction, int width, int height) { Canvas canvas = Canvas(); canvas.data = image; canvas.width = width; canvas.height = height; if (obstruction == Obstruction::BOTH || obstruction == Obstruction::LEFT) { canvas.fillBox(width / 2 - 20, height - 80, 20, 40, 200, 0, 0); } else { canvas.fillBox(width / 2 - 20, height - 80, 20, 40, 0, 200, 0); } if (obstruction == Obstruction::BOTH || obstruction == Obstruction::RIGHT) { canvas.fillBox(width / 2, height - 80, 20, 40, 200, 0, 0); } else { canvas.fillBox(width / 2, height - 80, 20, 40, 0, 200, 0); } }
void FullScreen::create_window() { DisplayWindowDescription window_description; window_description.set_title("ClanLib FullScreen Example"); window_description.set_size(Size(700, 600), true); if (is_fullscreen) { window_description.set_fullscreen(true); window_description.show_caption(false); } else { window_description.set_allow_resize(true); } window = DisplayWindow(window_description); sc.connect(window.sig_window_close(), clan::bind_member(this, &FullScreen::on_window_close)); sc.connect(window.get_ic().get_keyboard().sig_key_down(), clan::bind_member(this, &FullScreen::on_input_down)); canvas = Canvas(window); }
static int TextToArea( Tk_Canvas canvas, /* Canvas containing itemPtr. */ Tk_Item *itemPtr, /* Item to check against rectangle. */ double *rectPtr) /* Pointer to array of four coordinates * (x1,y1,x2,y2) describing rectangular * area. */ { TextItem *textPtr; Tk_State state = itemPtr->state; if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } textPtr = (TextItem *) itemPtr; return TkIntersectAngledTextLayout(textPtr->textLayout, (int) ((rectPtr[0] + 0.5) - textPtr->drawOrigin[0]), (int) ((rectPtr[1] + 0.5) - textPtr->drawOrigin[1]), (int) (rectPtr[2] - rectPtr[0] + 0.5), (int) (rectPtr[3] - rectPtr[1] + 0.5), textPtr->angle); }
//--------------------------------------------------------------------------- void __fastcall CenterButtonImage(TButton * Button) { UncenterButtonImage(Button); // with themes disabled, the text seems to be drawn over the icon, // so that the padding spaces hide away most of the icon if (UseThemes()) { Button->ImageAlignment = iaCenter; int ImageWidth = Button->Images->Width; std::unique_ptr<TControlCanvas> Canvas(new TControlCanvas()); Canvas->Control = Button; UnicodeString Caption = Button->Caption; UnicodeString Padding; while (Canvas->TextWidth(Padding) < ImageWidth) { Padding += L" "; } Caption = Padding + Caption; Button->Caption = Caption; int CaptionWidth = Canvas->TextWidth(Caption); // The margins seem to extend the area over which the image is centered, // so we have to set it to a double of desired padding. // Note that (CaptionWidth / 2) - (ImageWidth / 2) // is approximatelly same as half of caption width before padding. Button->ImageMargins->Left = - 2 * ((CaptionWidth / 2) - (ImageWidth / 2) + ScaleByTextHeight(Button, 2)); } else { // at least do not draw it so near to the edge Button->ImageMargins->Left = 1; } }
Canvas TopCanvas::Lock() { return Canvas(buffer); }
void FRCPassPostProcessVisualizeShadingModels::Process(FRenderingCompositePassContext& Context) { SCOPED_DRAW_EVENT(Context.RHICmdList, PostProcessVisualizeShadingModels); const FPooledRenderTargetDesc* InputDesc = GetInputDesc(ePId_Input0); const FSceneView& View = Context.View; const FViewInfo& ViewInfo = Context.View; const FSceneViewFamily& ViewFamily = *(View.Family); FIntRect SrcRect = View.ViewRect; FIntRect DestRect = View.ViewRect; FIntPoint SrcSize = InputDesc->Extent; const FSceneRenderTargetItem& DestRenderTarget = PassOutputs[0].RequestSurface(Context); // Set the view family's render target/viewport. SetRenderTarget(Context.RHICmdList, DestRenderTarget.TargetableTexture, FTextureRHIRef()); Context.SetViewportAndCallRHI(DestRect); // set the state Context.RHICmdList.SetBlendState(TStaticBlendState<>::GetRHI()); Context.RHICmdList.SetRasterizerState(TStaticRasterizerState<>::GetRHI()); Context.RHICmdList.SetDepthStencilState(TStaticDepthStencilState<false, CF_Always>::GetRHI()); TShaderMapRef<FPostProcessVS> VertexShader(Context.GetShaderMap()); TShaderMapRef<FPostProcessVisualizeShadingModelsPS> PixelShader(Context.GetShaderMap()); static FGlobalBoundShaderState BoundShaderState; SetGlobalBoundShaderState(Context.RHICmdList, Context.GetFeatureLevel(), BoundShaderState, GFilterVertexDeclaration.VertexDeclarationRHI, *VertexShader, *PixelShader); PixelShader->SetPS(Context, ((FViewInfo&)View).ShadingModelMaskInView); // Draw a quad mapping scene color to the view's render target DrawRectangle( Context.RHICmdList, DestRect.Min.X, DestRect.Min.Y, DestRect.Width(), DestRect.Height(), SrcRect.Min.X, SrcRect.Min.Y, SrcRect.Width(), SrcRect.Height(), DestRect.Size(), SrcSize, *VertexShader, EDRF_UseTriangleOptimization); FRenderTargetTemp TempRenderTarget(View, (const FTexture2DRHIRef&)DestRenderTarget.TargetableTexture); FCanvas Canvas(&TempRenderTarget, NULL, 0, 0, 0, Context.GetFeatureLevel()); float X = 30; float Y = 28; const float YStep = 14; const float ColumnWidth = 250; FString Line; Canvas.DrawShadowedString( X, Y += YStep, TEXT("Visualize ShadingModels (mostly to track down bugs)"), GetStatsFont(), FLinearColor(1, 1, 1)); Y = 160 - YStep - 4; uint32 Value = ((FViewInfo&)View).ShadingModelMaskInView; Line = FString::Printf(TEXT("View.ShadingModelMaskInView = 0x%x"), Value); Canvas.DrawShadowedString( X, Y, *Line, GetStatsFont(), FLinearColor(0.5f, 0.5f, 0.5f)); Y += YStep; UEnum* Enum = FindObject<UEnum>(NULL, TEXT("Engine.EMaterialShadingModel")); check(Enum); Y += 5; for(uint32 i = 0; i < MSM_MAX; ++i) { FString Name = Enum->GetEnumName(i); Line = FString::Printf(TEXT("%d. %s"), i, *Name); bool bThere = (Value & (1 << i)) != 0; Canvas.DrawShadowedString(X + 30, Y, *Line, GetStatsFont(), bThere ? FLinearColor(1, 1, 1) : FLinearColor(0, 0, 0) ); Y += 20; } Line = FString::Printf(TEXT("(On CPU, based on what gets rendered)")); Canvas.DrawShadowedString( X, Y, *Line, GetStatsFont(), FLinearColor(0.5f, 0.5f, 0.5f)); Y += YStep; Canvas.Flush_RenderThread(Context.RHICmdList); Context.RHICmdList.CopyToResolveTarget(DestRenderTarget.TargetableTexture, DestRenderTarget.ShaderResourceTexture, false, FResolveParams()); // AdjustGBufferRefCount(1) call is done in constructor FSceneRenderTargets::Get(Context.RHICmdList).AdjustGBufferRefCount(Context.RHICmdList, -1); }
void FRCPassPostProcessVisualizeBuffer::Process(FRenderingCompositePassContext& Context) { SCOPED_DRAW_EVENT(VisualizeBuffer, DEC_SCENE_ITEMS); const FPooledRenderTargetDesc* InputDesc = GetInputDesc(ePId_Input0); if(!InputDesc) { // input is not hooked up correctly return; } const FSceneView& View = Context.View; const FSceneViewFamily& ViewFamily = *(View.Family); FIntRect SrcRect = View.ViewRect; FIntRect DestRect = View.ViewRect; FIntPoint SrcSize = InputDesc->Extent; const FSceneRenderTargetItem& DestRenderTarget = PassOutputs[0].RequestSurface(Context); // Set the view family's render target/viewport. RHISetRenderTarget(DestRenderTarget.TargetableTexture, FTextureRHIRef()); Context.SetViewportAndCallRHI(DestRect); // set the state RHISetBlendState(TStaticBlendState<>::GetRHI()); RHISetRasterizerState(TStaticRasterizerState<>::GetRHI()); RHISetDepthStencilState(TStaticDepthStencilState<false,CF_Always>::GetRHI()); SetShaderTempl<false>(Context); // Draw a quad mapping scene color to the view's render target DrawRectangle( 0, 0, DestRect.Width(), DestRect.Height(), SrcRect.Min.X, SrcRect.Min.Y, SrcRect.Width(), SrcRect.Height(), DestRect.Size(), SrcSize, EDRF_UseTriangleOptimization); // Now draw the requested tiles into the grid TShaderMapRef<FPostProcessVS> VertexShader(GetGlobalShaderMap()); TShaderMapRef<FPostProcessVisualizeBufferPS<true> > PixelShader(GetGlobalShaderMap()); RHISetBlendState(TStaticBlendState<CW_RGB, BO_Add, BF_SourceAlpha, BF_InverseSourceAlpha>::GetRHI()); static FGlobalBoundShaderState BoundShaderState; SetGlobalBoundShaderState(BoundShaderState, GFilterVertexDeclaration.VertexDeclarationRHI, *VertexShader, *PixelShader); PixelShader->SetPS(Context); // Track the name and position of each tile we draw so we can write text labels over them struct LabelRecord { FString Label; int32 LocationX; int32 LocationY; }; TArray<LabelRecord> Labels; const int32 MaxTilesX = 4; const int32 MaxTilesY = 4; const int32 TileWidth = DestRect.Width() / MaxTilesX; const int32 TileHeight = DestRect.Height() / MaxTilesY; int32 CurrentTileIndex = 0; for (TArray<TileData>::TConstIterator It = Tiles.CreateConstIterator(); It; ++It, ++CurrentTileIndex) { FRenderingCompositeOutputRef Tile = It->Source; if (Tile.IsValid()) { FTextureRHIRef Texture = Tile.GetOutput()->PooledRenderTarget->GetRenderTargetItem().TargetableTexture; int32 TileX = CurrentTileIndex % MaxTilesX; int32 TileY = CurrentTileIndex / MaxTilesX; PixelShader->SetSourceTexture(Texture); DrawRectangle( TileX * TileWidth, TileY * TileHeight, TileWidth, TileHeight, SrcRect.Min.X, SrcRect.Min.Y, SrcRect.Width(), SrcRect.Height(), DestRect.Size(), SrcSize, EDRF_Default); Labels.Add(LabelRecord()); Labels.Last().Label = It->Name; Labels.Last().LocationX = 8 + TileX * TileWidth; Labels.Last().LocationY = (TileY + 1) * TileHeight - 19; } } // Draw tile labels // this is a helper class for FCanvas to be able to get screen size class FRenderTargetTemp : public FRenderTarget { public: const FSceneView& View; const FTexture2DRHIRef Texture; FRenderTargetTemp(const FSceneView& InView, const FTexture2DRHIRef InTexture) : View(InView), Texture(InTexture) { } virtual FIntPoint GetSizeXY() const { return View.ViewRect.Size(); }; virtual const FTexture2DRHIRef& GetRenderTargetTexture() const { return Texture; } } TempRenderTarget(View, (const FTexture2DRHIRef&)DestRenderTarget.TargetableTexture); FCanvas Canvas(&TempRenderTarget, NULL, ViewFamily.CurrentRealTime, ViewFamily.CurrentWorldTime, ViewFamily.DeltaWorldTime); FLinearColor LabelColor(1, 1, 0); for (auto It = Labels.CreateConstIterator(); It; ++It) { Canvas.DrawShadowedString(It->LocationX, It->LocationY, *It->Label, GetStatsFont(), LabelColor); } Canvas.Flush(); RHICopyToResolveTarget(DestRenderTarget.TargetableTexture, DestRenderTarget.ShaderResourceTexture, false, FResolveParams()); }
// The start of the Application int App::start(const std::vector<std::string> &args) { quit = false; clan::SlotContainer cc; DisplayWindowDescription win_desc; win_desc.set_allow_resize(true); win_desc.set_title("Font Example Application"); win_desc.set_size(Size( 1000, 700 ), false); DisplayWindow window(win_desc); cc.connect(window.sig_window_close(), std::function<void()>(this, &App::on_window_close)); cc.connect(window.get_ic().get_keyboard().sig_key_up(), std::function<void(const clan::InputEvent&)>(this, &App::on_input_up)); resources = clan::XMLResourceManager::create(clan::XMLResourceDocument("Resources/resources.xml")); std::string theme; if (FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css")) theme = "../../../Resources/GUIThemeAero"; else if (FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css")) theme = "../../../Resources/GUIThemeBasic"; else throw Exception("No themes found"); gui_manager = GUIWindowManagerTexture(window); GUIManager gui(gui_manager, theme); canvas = Canvas(window); GUITopLevelDescription gui_desc; gui_desc.set_title("Options"); gui_desc.set_position(Rect(10, 10, 250, 400), false); GUIComponent gui_window(&gui, gui_desc, "window"); int offset_x = 10; int offset_y = 8; int width = 200; int height = 20; const int gap = 26; PushButton button_class_system(&gui_window); button_class_system.set_geometry(Rect(offset_x, offset_y, offset_x + width, offset_y + height)); button_class_system.func_clicked() = bind_member(this, &App::on_button_clicked_class_system); button_class_system.set_text("Class: System"); offset_y += gap; PushButton button_class_sprite(&gui_window); button_class_sprite.set_geometry(Rect(offset_x, offset_y, offset_x + width, offset_y + height)); button_class_sprite.func_clicked() = bind_member(this, &App::on_button_clicked_class_sprite); button_class_sprite.set_text("Class: Sprite"); offset_y += gap; PushButton button_typeface_tahoma(&gui_window); button_typeface_tahoma_ptr = &button_typeface_tahoma; button_typeface_tahoma.set_geometry(Rect(offset_x, offset_y, offset_x + width, offset_y + height)); button_typeface_tahoma.func_clicked() = bind_member(this, &App::on_button_clicked_typeface_tahoma); button_typeface_tahoma.set_text("Typeface: Tahoma"); offset_y += gap; PushButton button_typeface_sans(&gui_window); button_typeface_sans_ptr = &button_typeface_sans; button_typeface_sans.set_geometry(Rect(offset_x, offset_y, offset_x + width, offset_y + height)); button_typeface_sans.func_clicked() = bind_member(this, &App::on_button_clicked_typeface_sans); button_typeface_sans.set_text("Typeface: Microsoft Sans Serif"); offset_y += gap; PushButton button_typeface_bitstream(&gui_window); button_typeface_bitstream_ptr = &button_typeface_bitstream; button_typeface_bitstream.set_geometry(Rect(offset_x, offset_y, offset_x + width, offset_y + height)); button_typeface_bitstream.func_clicked() = bind_member(this, &App::on_button_clicked_typeface_bitstream); button_typeface_bitstream.set_text("Typeface: Bitstream Vera Sans"); offset_y += gap; CheckBox checkbox1(&gui_window); checkbox1.set_geometry(Rect(offset_x, offset_y, offset_x + 80, offset_y + height)); checkbox1.func_state_changed() = bind_member(this, &App::on_checkbox_state_underline); checkbox1.set_text("Underline"); CheckBox checkbox2(&gui_window); checkbox2.set_geometry(Rect(offset_x+100, offset_y, offset_x + 180, offset_y + height)); checkbox2.func_state_changed() = bind_member(this, &App::on_checkbox_state_strikeout); checkbox2.set_text("Strikeout"); offset_y += gap; CheckBox checkbox3(&gui_window); checkbox3.set_geometry(Rect(offset_x, offset_y, offset_x + 80, offset_y + height)); checkbox3.func_state_changed() = bind_member(this, &App::on_checkbox_state_italic); checkbox3.set_text("Italic"); CheckBox checkbox4(&gui_window); checkbox4.set_checked(true); checkbox4.set_geometry(Rect(offset_x+100, offset_y, offset_x + 180, offset_y + height)); checkbox4.func_state_changed() = bind_member(this, &App::on_checkbox_state_antialias); checkbox4.set_text("Anti Alias"); offset_y += gap; CheckBox checkbox5(&gui_window); checkbox5.set_checked(true); checkbox5.set_geometry(Rect(offset_x, offset_y, offset_x + 120, offset_y + height)); checkbox5.func_state_changed() = bind_member(this, &App::on_checkbox_state_subpixel); checkbox5.set_text("SubPixel Rendering"); offset_y += gap; PushButton button_weight_light(&gui_window); button_weight_light.set_geometry(Rect(offset_x, offset_y, offset_x + 60, offset_y + height)); button_weight_light.func_clicked() = bind_member(this, &App::on_button_clicked_weight_light); button_weight_light.set_text("Light"); PushButton button_weight_normal(&gui_window); button_weight_normal.set_geometry(Rect(offset_x+70, offset_y, offset_x + 130, offset_y + height)); button_weight_normal.func_clicked() = bind_member(this, &App::on_button_clicked_weight_normal); button_weight_normal.set_text("Normal"); PushButton button_weight_bold(&gui_window); button_weight_bold.set_geometry(Rect(offset_x+140, offset_y, offset_x + 200, offset_y + height)); button_weight_bold.func_clicked() = bind_member(this, &App::on_button_clicked_weight_bold); button_weight_bold.set_text("Bold"); offset_y += gap; PushButton button_size_16(&gui_window); button_size_16.set_geometry(Rect(offset_x, offset_y, offset_x + 60, offset_y + height)); button_size_16.func_clicked() = bind_member(this, &App::on_button_clicked_size_16); button_size_16.set_text("Size 16"); PushButton button_size_32(&gui_window); button_size_32.set_geometry(Rect(offset_x+70, offset_y, offset_x + 130, offset_y + height)); button_size_32.func_clicked() = bind_member(this, &App::on_button_clicked_size_32); button_size_32.set_text("Size 32"); PushButton button_size_64(&gui_window); button_size_64.set_geometry(Rect(offset_x+140, offset_y, offset_x + 200, offset_y + height)); button_size_64.func_clicked() = bind_member(this, &App::on_button_clicked_size_64); button_size_64.set_text("Size 64"); offset_y += gap; font_text = "Ω(The quick brown fox 0123456789)"; LineEdit lineedit1(&gui_window); lineedit_text_ptr = &lineedit1; lineedit1.set_geometry(Rect(offset_x, offset_y, offset_x + width, offset_y + 30)); lineedit1.set_text(font_text); lineedit1.func_after_edit_changed() = bind_member(this, &App::on_lineedit_changed); last_fps = 0.0f; selected_fontclass = font_ttf; font_typeface = "Microsoft Sans Serif"; font_filename = ""; font_desc.set_height(32); font_desc.set_weight(400); select_font(); small_font = clan::Font(canvas, "Tahoma", 16); GameTime game_time; while(!quit) { game_time.update(); render(window, game_time); } return 0; }
Win32_App::Win32_App() { SourceDLLName = "Game.dll"; //GameCode = Win32_LoadGameCode(SourceDLLName); #ifdef _DEBUG // Дебажная консоль FileLogger flogger("debug.log"); log_event("SYSTEM", "Logger initialized"); #endif try { // We support all display targets, in order listed here #ifdef WIN32 D3DTarget::enable(); #endif OpenGLTarget::enable(); } catch (Exception exception) { // Create a console window for text-output if not available ConsoleWindow console("Console", 80, 160); Console::write_line("Exception caught: " + exception.get_message_and_stack_trace()); console.display_close_message(); quit = true; } // TODO: сохранять настройки графики fullscreen = 0; // TODO: Масштабировать окно InitScreenSize = Sizef(1024.0f, 768.0f); ScreenSize = InitScreenSize; DisplayWindowDescription window_description; window_description.set_title("Robot Game"); window_description.set_size(ScreenSize, true); window_description.set_allow_resize(true); //window_description.set_type(WindowType::tool); window = DisplayWindow(window_description); canvas = Canvas(window); // Подключим коллбэки на слоты пользовательского ввода keyboard = window.get_ic().get_keyboard(); sc.connect(window.sig_window_close(), bind_member(this, &Win32_App::Win32_OnWindowClose)); sc.connect(window.get_ic().get_keyboard().sig_key_up(), bind_member(this, &Win32_App::Win32_OnKeyUp)); sc.connect(window.get_ic().get_keyboard().sig_key_down(), bind_member(this, &Win32_App::Win32_OnKeyDown)); sc.connect(window.get_ic().get_mouse().sig_key_down(), bind_member(this, &Win32_App::Win32_OnMouseDown)); // Sound SoundOutput sound_output(48000); /* SoundBuffer sbuffer("cheer1.ogg"); sbuffer.play(); */ // Game memory LPVOID BaseAddress = 0; GameMemory.PermanentStorageSize = Megabytes(256); GameMemory.TransientStorageSize = Megabytes(256); size_t TotalStorageSize = (size_t)(GameMemory.PermanentStorageSize + GameMemory.TransientStorageSize); GameMemory.PermanentStorage = VirtualAlloc(BaseAddress, TotalStorageSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); GameMemory.TransientStorage = ((uint8*)GameMemory.PermanentStorage + GameMemory.PermanentStorageSize); // Game state GameState = (game_state*)GameMemory.PermanentStorage; *GameState = {}; GameState->ScreenSize = ScreenSize; // Resources //OpenGLTarget::set_current(); GameState->game_resources = clan::XMLResourceManager::create(clan::XMLResourceDocument("sprites.xml")); GameState->LoadGameSpriteFromImage = &LoadGameSpriteFromImage; GameState->LoadGameSpriteFromResource = &LoadGameSpriteFromResource; GameState->AddGameSpriteFrameFromImage = &AddGameSpriteFrameFromImage; // Main display buffers //GameState->MainDisplayBuffer = PixelBuffer(1024, 768, TextureFormat::tf_rgba8, GameMemory.TransientStorage); // Win32 Timings CanSleepSafe = (timeBeginPeriod(1) == TIMERR_NOERROR); QueryPerformanceFrequency(&PerfCounterFrequencyQ); PerfCounterFrequency = PerfCounterFrequencyQ.QuadPart; QueryPerformanceCounter(&LastCounter); LastCycleCount = __rdtsc(); game_time.reset(); //console.display_close_message(); //timeEndPeriod(1); }
void FRCPassPostProcessTestImage::Process(FRenderingCompositePassContext& Context) { SCOPED_DRAW_EVENT(Context.RHICmdList, TestImage, DEC_SCENE_ITEMS); const FSceneView& View = Context.View; const FSceneViewFamily& ViewFamily = *(View.Family); FIntRect SrcRect = View.ViewRect; FIntRect DestRect = View.ViewRect; const FSceneRenderTargetItem& DestRenderTarget = PassOutputs[0].RequestSurface(Context); // Set the view family's render target/viewport. SetRenderTarget(Context.RHICmdList, DestRenderTarget.TargetableTexture, FTextureRHIRef()); Context.SetViewportAndCallRHI(DestRect); // set the state Context.RHICmdList.SetBlendState(TStaticBlendState<>::GetRHI()); Context.RHICmdList.SetRasterizerState(TStaticRasterizerState<>::GetRHI()); Context.RHICmdList.SetDepthStencilState(TStaticDepthStencilState<false, CF_Always>::GetRHI()); TShaderMapRef<FPostProcessVS> VertexShader(Context.GetShaderMap()); TShaderMapRef<FPostProcessTestImagePS> PixelShader(Context.GetShaderMap()); static FGlobalBoundShaderState BoundShaderState; SetGlobalBoundShaderState(Context.RHICmdList, Context.GetFeatureLevel(), BoundShaderState, GFilterVertexDeclaration.VertexDeclarationRHI, *VertexShader, *PixelShader); PixelShader->SetPS(Context); // Draw a quad mapping scene color to the view's render target DrawRectangle( Context.RHICmdList, 0, 0, DestRect.Width(), DestRect.Height(), SrcRect.Min.X, SrcRect.Min.Y, SrcRect.Width(), SrcRect.Height(), DestRect.Size(), GSceneRenderTargets.GetBufferSizeXY(), *VertexShader, EDRF_UseTriangleOptimization); { // this is a helper class for FCanvas to be able to get screen size class FRenderTargetTemp : public FRenderTarget { public: const FSceneView& View; const FTexture2DRHIRef Texture; FRenderTargetTemp(const FSceneView& InView, const FTexture2DRHIRef InTexture) : View(InView), Texture(InTexture) { } virtual FIntPoint GetSizeXY() const { return View.ViewRect.Size(); }; virtual const FTexture2DRHIRef& GetRenderTargetTexture() const { return Texture; } } TempRenderTarget(View, (const FTexture2DRHIRef&)DestRenderTarget.TargetableTexture); FCanvas Canvas(&TempRenderTarget, NULL, ViewFamily.CurrentRealTime, ViewFamily.CurrentWorldTime, ViewFamily.DeltaWorldTime, Context.GetFeatureLevel()); float X = 30; float Y = 8; const float YStep = 14; const float ColumnWidth = 250; FString Line; Line = FString::Printf(TEXT("Top bars:")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT(" Moving bars using FrameTime")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT(" Black and white raster, Pixel sized, Watch for Moire pattern")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT(" Black and white raster, 2x2 block sized")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT("Bottom bars:")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT(" 8 bars near white, 4 right bars should appear as one (HDTV)")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT(" 8 bars near black, 4 left bars should appear as one (HDTV)")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT(" Linear Greyscale in sRGB from 0 to 255")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT("Color bars:")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT(" Red, Green, Blue")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT("Outside:")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT(" Moving bars using FrameNumber, Tearing without VSync")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT("Circles:")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT(" Should be round and centered")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT("Border:")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT(" 4 white pixel sized lines (only visible without overscan)")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Canvas.Flush_RenderThread(Context.RHICmdList); } Context.RHICmdList.CopyToResolveTarget(DestRenderTarget.TargetableTexture, DestRenderTarget.ShaderResourceTexture, false, FResolveParams()); }
void FRCPassPostProcessVisualizeHDR::Process(FRenderingCompositePassContext& Context) { SCOPED_DRAW_EVENT(PostProcessVisualizeHDR, DEC_SCENE_ITEMS); const FPooledRenderTargetDesc* InputDesc = GetInputDesc(ePId_Input0); if(!InputDesc) { // input is not hooked up correctly return; } const FSceneView& View = Context.View; const FSceneViewFamily& ViewFamily = *(View.Family); FIntRect SrcRect = View.ViewRect; FIntRect DestRect = View.ViewRect; FIntPoint SrcSize = InputDesc->Extent; const FSceneRenderTargetItem& DestRenderTarget = PassOutputs[0].RequestSurface(Context); // Set the view family's render target/viewport. RHISetRenderTarget(DestRenderTarget.TargetableTexture, FTextureRHIRef()); Context.SetViewportAndCallRHI(DestRect); // set the state RHISetBlendState(TStaticBlendState<>::GetRHI()); RHISetRasterizerState(TStaticRasterizerState<>::GetRHI()); RHISetDepthStencilState(TStaticDepthStencilState<false,CF_Always>::GetRHI()); TShaderMapRef<FPostProcessVS> VertexShader(GetGlobalShaderMap()); TShaderMapRef<FPostProcessVisualizeHDRPS> PixelShader(GetGlobalShaderMap()); static FGlobalBoundShaderState BoundShaderState; SetGlobalBoundShaderState(BoundShaderState, GFilterVertexDeclaration.VertexDeclarationRHI, *VertexShader, *PixelShader); PixelShader->SetPS(Context); // Draw a quad mapping scene color to the view's render target DrawRectangle( DestRect.Min.X, DestRect.Min.Y, DestRect.Width(), DestRect.Height(), SrcRect.Min.X, SrcRect.Min.Y, SrcRect.Width(), SrcRect.Height(), DestRect.Size(), SrcSize, EDRF_UseTriangleOptimization); // this is a helper class for FCanvas to be able to get screen size class FRenderTargetTemp : public FRenderTarget { public: const FSceneView& View; const FTexture2DRHIRef Texture; FRenderTargetTemp(const FSceneView& InView, const FTexture2DRHIRef InTexture) : View(InView), Texture(InTexture) { } virtual FIntPoint GetSizeXY() const { return View.ViewRect.Size(); }; virtual const FTexture2DRHIRef& GetRenderTargetTexture() const { return Texture; } } TempRenderTarget(View, (const FTexture2DRHIRef&)DestRenderTarget.TargetableTexture); FCanvas Canvas(&TempRenderTarget, NULL, ViewFamily.CurrentRealTime, ViewFamily.CurrentWorldTime, ViewFamily.DeltaWorldTime); float X = 30; float Y = 8; const float YStep = 14; const float ColumnWidth = 250; FString Line; Line = FString::Printf(TEXT("HDR Histogram (Logarithmic, max of RGB)")); Canvas.DrawShadowedString( X, Y += YStep, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Y += 160; float MinX = 64 + 10; float MaxY = View.ViewRect.Max.Y - 64; float SizeX = View.ViewRect.Size().X - 64 * 2 - 20; for(uint32 i = 0; i <= 4; ++i) { int XAdd = (int)(i * SizeX / 4); float HistogramPosition = i / 4.0f; float LogValue = FMath::Lerp(View.FinalPostProcessSettings.HistogramLogMin, View.FinalPostProcessSettings.HistogramLogMax, HistogramPosition); Line = FString::Printf(TEXT("%.2g"), LogValue); Canvas.DrawShadowedString( MinX + XAdd - 5, MaxY, *Line, GetStatsFont(), FLinearColor(1, 0.3f, 0.3f)); Line = LogToString(LogValue); Canvas.DrawShadowedString( MinX + XAdd - 5, MaxY + YStep, *Line, GetStatsFont(), FLinearColor(0.3f, 0.3f, 1)); } Y += 3 * YStep; Line = FString::Printf(TEXT("%g%% .. %g%%"), View.FinalPostProcessSettings.AutoExposureLowPercent, View.FinalPostProcessSettings.AutoExposureHighPercent); Canvas.DrawShadowedString( X, Y += YStep, TEXT("EyeAdaptationPercent Low/High:"), GetStatsFont(), FLinearColor(1, 1, 1)); Canvas.DrawShadowedString( X + ColumnWidth, Y, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT("%g .. %g"), View.FinalPostProcessSettings.AutoExposureMinBrightness, View.FinalPostProcessSettings.AutoExposureMaxBrightness); Canvas.DrawShadowedString( X, Y += YStep, TEXT("EyeAdaptationBrightness Min/Max:"), GetStatsFont(), FLinearColor(1, 1, 1)); Canvas.DrawShadowedString( X + ColumnWidth, Y, *Line, GetStatsFont(), FLinearColor(0.3f, 0.3f, 1)); Line = FString::Printf(TEXT("%g / %g"), View.FinalPostProcessSettings.AutoExposureSpeedUp, View.FinalPostProcessSettings.AutoExposureSpeedDown); Canvas.DrawShadowedString( X, Y += YStep, TEXT("EyeAdaptionSpeed Up/Down:"), GetStatsFont(), FLinearColor(1, 1, 1)); Canvas.DrawShadowedString( X + ColumnWidth, Y, *Line, GetStatsFont(), FLinearColor(1, 1, 1)); Line = FString::Printf(TEXT("%g"), View.FinalPostProcessSettings.AutoExposureBias); Canvas.DrawShadowedString( X, Y += YStep, TEXT("Exposure Offset: "), GetStatsFont(), FLinearColor(1, 1, 1)); Canvas.DrawShadowedString( X + ColumnWidth, Y, *Line, GetStatsFont(), FLinearColor(1, 0.3f, 0.3f)); Line = FString::Printf(TEXT("%g .. %g (log2)"), View.FinalPostProcessSettings.HistogramLogMin, View.FinalPostProcessSettings.HistogramLogMax); Canvas.DrawShadowedString( X, Y += YStep, TEXT("HistogramLog Min/Max:"), GetStatsFont(), FLinearColor(1, 1, 1)); Canvas.DrawShadowedString( X + ColumnWidth, Y, *Line, GetStatsFont(), FLinearColor(1, 0.3f, 0.3f)); Line = FString::Printf(TEXT("%s .. %s (Value)"), *LogToString(View.FinalPostProcessSettings.HistogramLogMin), *LogToString(View.FinalPostProcessSettings.HistogramLogMax)); Canvas.DrawShadowedString( X + ColumnWidth, Y+= YStep, *Line, GetStatsFont(), FLinearColor(0.3f, 0.3f, 1)); Canvas.Flush(); RHICopyToResolveTarget(DestRenderTarget.TargetableTexture, DestRenderTarget.ShaderResourceTexture, false, FResolveParams()); }
/* ARGSUSED */ static double RectToPoint( Tk_Canvas canvas, /* Canvas containing item. */ Tk_Item *itemPtr, /* Item to check against point. */ double *pointPtr) /* Pointer to x and y coordinates. */ { RectOvalItem *rectPtr = (RectOvalItem *) itemPtr; double xDiff, yDiff, x1, y1, x2, y2, inc, tmp; double width; Tk_State state = itemPtr->state; if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } width = rectPtr->outline.width; if (Canvas(canvas)->currentItemPtr == itemPtr) { if (rectPtr->outline.activeWidth>width) { width = rectPtr->outline.activeWidth; } } else if (state == TK_STATE_DISABLED) { if (rectPtr->outline.disabledWidth>0) { width = rectPtr->outline.disabledWidth; } } /* * Generate a new larger rectangle that includes the border width, if * there is one. */ x1 = rectPtr->bbox[0]; y1 = rectPtr->bbox[1]; x2 = rectPtr->bbox[2]; y2 = rectPtr->bbox[3]; if (rectPtr->outline.gc != None) { inc = width/2.0; x1 -= inc; y1 -= inc; x2 += inc; y2 += inc; } /* * If the point is inside the rectangle, handle specially: distance is 0 * if rectangle is filled, otherwise compute distance to nearest edge of * rectangle and subtract width of edge. */ if ((pointPtr[0] >= x1) && (pointPtr[0] < x2) && (pointPtr[1] >= y1) && (pointPtr[1] < y2)) { if ((rectPtr->fillGC != None) || (rectPtr->outline.gc == None)) { return 0.0; } xDiff = pointPtr[0] - x1; tmp = x2 - pointPtr[0]; if (tmp < xDiff) { xDiff = tmp; } yDiff = pointPtr[1] - y1; tmp = y2 - pointPtr[1]; if (tmp < yDiff) { yDiff = tmp; } if (yDiff < xDiff) { xDiff = yDiff; } xDiff -= width; if (xDiff < 0.0) { return 0.0; } return xDiff; } /* * Point is outside rectangle. */ if (pointPtr[0] < x1) { xDiff = x1 - pointPtr[0]; } else if (pointPtr[0] > x2) { xDiff = pointPtr[0] - x2; } else { xDiff = 0; } if (pointPtr[1] < y1) { yDiff = y1 - pointPtr[1]; } else if (pointPtr[1] > y2) { yDiff = pointPtr[1] - y2; } else { yDiff = 0; } return hypot(xDiff, yDiff); }
static void DisplayRectOval( Tk_Canvas canvas, /* Canvas that contains item. */ Tk_Item *itemPtr, /* Item to be displayed. */ Display *display, /* Display on which to draw item. */ Drawable drawable, /* Pixmap or window in which to draw item. */ int x, int y, int width, int height) /* Describes region of canvas that must be * redisplayed (not used). */ { RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr; short x1, y1, x2, y2; Pixmap fillStipple; Tk_State state = itemPtr->state; /* * Compute the screen coordinates of the bounding box for the item. Make * sure that the bbox is at least one pixel large, since some X servers * will die if it isn't. */ Tk_CanvasDrawableCoords(canvas, rectOvalPtr->bbox[0],rectOvalPtr->bbox[1], &x1, &y1); Tk_CanvasDrawableCoords(canvas, rectOvalPtr->bbox[2],rectOvalPtr->bbox[3], &x2, &y2); if (x2 <= x1) { x2 = x1+1; } if (y2 <= y1) { y2 = y1+1; } /* * Display filled part first (if wanted), then outline. If we're * stippling, then modify the stipple offset in the GC. Be sure to reset * the offset when done, since the GC is supposed to be read-only. */ if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } fillStipple = rectOvalPtr->fillStipple; if (Canvas(canvas)->currentItemPtr == (Tk_Item *) rectOvalPtr) { if (rectOvalPtr->activeFillStipple != None) { fillStipple = rectOvalPtr->activeFillStipple; } } else if (state == TK_STATE_DISABLED) { if (rectOvalPtr->disabledFillStipple != None) { fillStipple = rectOvalPtr->disabledFillStipple; } } if (rectOvalPtr->fillGC != None) { if (fillStipple != None) { Tk_TSOffset *tsoffset; int w = 0, h = 0; tsoffset = &rectOvalPtr->tsoffset; if (tsoffset) { int flags = tsoffset->flags; if (flags & (TK_OFFSET_CENTER|TK_OFFSET_MIDDLE)) { Tk_SizeOfBitmap(display, fillStipple, &w, &h); if (flags & TK_OFFSET_CENTER) { w /= 2; } else { w = 0; } if (flags & TK_OFFSET_MIDDLE) { h /= 2; } else { h = 0; } } tsoffset->xoffset -= w; tsoffset->yoffset -= h; } Tk_CanvasSetOffset(canvas, rectOvalPtr->fillGC, tsoffset); if (tsoffset) { tsoffset->xoffset += w; tsoffset->yoffset += h; } } if (rectOvalPtr->header.typePtr == &tkRectangleType) { XFillRectangle(display, drawable, rectOvalPtr->fillGC, x1, y1, (unsigned int) (x2-x1), (unsigned int) (y2-y1)); } else { XFillArc(display, drawable, rectOvalPtr->fillGC, x1, y1, (unsigned) (x2-x1), (unsigned) (y2-y1), 0, 360*64); } if (fillStipple != None) { XSetTSOrigin(display, rectOvalPtr->fillGC, 0, 0); } } if (rectOvalPtr->outline.gc != None) { Tk_ChangeOutlineGC(canvas, itemPtr, &(rectOvalPtr->outline)); if (rectOvalPtr->header.typePtr == &tkRectangleType) { XDrawRectangle(display, drawable, rectOvalPtr->outline.gc, x1, y1, (unsigned) (x2-x1), (unsigned) (y2-y1)); } else { XDrawArc(display, drawable, rectOvalPtr->outline.gc, x1, y1, (unsigned) (x2-x1), (unsigned) (y2-y1), 0, 360*64); } Tk_ResetOutlineGC(canvas, itemPtr, &(rectOvalPtr->outline)); } }
/* ARGSUSED */ static void ComputeRectOvalBbox( Tk_Canvas canvas, /* Canvas that contains item. */ RectOvalItem *rectOvalPtr) /* Item whose bbox is to be recomputed. */ { int bloat, tmp; double dtmp, width; Tk_State state = rectOvalPtr->header.state; if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } width = rectOvalPtr->outline.width; if (state == TK_STATE_HIDDEN) { rectOvalPtr->header.x1 = rectOvalPtr->header.y1 = rectOvalPtr->header.x2 = rectOvalPtr->header.y2 = -1; return; } if (Canvas(canvas)->currentItemPtr == (Tk_Item *) rectOvalPtr) { if (rectOvalPtr->outline.activeWidth>width) { width = rectOvalPtr->outline.activeWidth; } } else if (state == TK_STATE_DISABLED) { if (rectOvalPtr->outline.disabledWidth>0) { width = rectOvalPtr->outline.disabledWidth; } } /* * Make sure that the first coordinates are the lowest ones. */ if (rectOvalPtr->bbox[1] > rectOvalPtr->bbox[3]) { double tmpY = rectOvalPtr->bbox[3]; rectOvalPtr->bbox[3] = rectOvalPtr->bbox[1]; rectOvalPtr->bbox[1] = tmpY; } if (rectOvalPtr->bbox[0] > rectOvalPtr->bbox[2]) { double tmpX = rectOvalPtr->bbox[2]; rectOvalPtr->bbox[2] = rectOvalPtr->bbox[0]; rectOvalPtr->bbox[0] = tmpX; } if (rectOvalPtr->outline.gc == None) { /* * The Win32 switch was added for 8.3 to solve a problem with ovals * leaving traces on bottom and right of 1 pixel. This may not be the * correct place to solve it, but it works. */ #ifdef _WIN32 bloat = 1; #else bloat = 0; #endif /* _WIN32 */ } else { #ifdef MAC_OSX_TK /* * Mac OS X CoreGraphics needs correct rounding here otherwise it will * draw outside the bounding box. Probably correct on other platforms * as well? */ bloat = (int) (width+1.5)/2; #else bloat = (int) (width+1)/2; #endif /* MAC_OSX_TK */ } /* * Special note: the rectangle is always drawn at least 1x1 in size, so * round up the upper coordinates to be at least 1 unit greater than the * lower ones. */ tmp = (int) ((rectOvalPtr->bbox[0] >= 0) ? rectOvalPtr->bbox[0] + .5 : rectOvalPtr->bbox[0] - .5); rectOvalPtr->header.x1 = tmp - bloat; tmp = (int) ((rectOvalPtr->bbox[1] >= 0) ? rectOvalPtr->bbox[1] + .5 : rectOvalPtr->bbox[1] - .5); rectOvalPtr->header.y1 = tmp - bloat; dtmp = rectOvalPtr->bbox[2]; if (dtmp < (rectOvalPtr->bbox[0] + 1)) { dtmp = rectOvalPtr->bbox[0] + 1; } tmp = (int) ((dtmp >= 0) ? dtmp + .5 : dtmp - .5); rectOvalPtr->header.x2 = tmp + bloat; dtmp = rectOvalPtr->bbox[3]; if (dtmp < (rectOvalPtr->bbox[1] + 1)) { dtmp = rectOvalPtr->bbox[1] + 1; } tmp = (int) ((dtmp >= 0) ? dtmp + .5 : dtmp - .5); rectOvalPtr->header.y2 = tmp + bloat; }