//----------------------------------------------------------------------------- // Purpose: Renders the connecting lines between the keyframes // Input : pRender - //----------------------------------------------------------------------------- void CMapKeyFrame::Render3D( CRender3D *pRender ) { if ( m_bRebuildPath ) { if (GetAnimator() != NULL) { GetAnimator()->RebuildPath(); } } // only draw if we have a valid connection if ( m_pNextKeyFrame && m_flSpeed > 0 ) { // only draw if we haven't already been drawn this frame if ( GetRenderFrame() != pRender->GetRenderFrame() ) { pRender->PushRenderMode( RENDER_MODE_WIREFRAME ); SetRenderFrame( pRender->GetRenderFrame() ); Vector o1, o2; GetOrigin( o1 ); m_pNextKeyFrame->GetOrigin( o2 ); CMeshBuilder meshBuilder; CMatRenderContextPtr pRenderContext( MaterialSystemInterface() ); IMesh *pMesh = pRenderContext->GetDynamicMesh(); // draw connecting line going from green to red meshBuilder.Begin( pMesh, MATERIAL_LINE_STRIP, MAX_LINE_POINTS ); // start point meshBuilder.Color3f( 0, 1.0f, 0 ); meshBuilder.Position3f( o1[0], o1[1], o1[2] ); meshBuilder.AdvanceVertex(); for ( int i = 0; i < MAX_LINE_POINTS; i++ ) { float red = (float)(i+1) / (float)MAX_LINE_POINTS; meshBuilder.Color3f( red, 1.0f - red, 0 ); meshBuilder.Position3f( m_LinePoints[i][0], m_LinePoints[i][1], m_LinePoints[i][2] ); meshBuilder.AdvanceVertex(); } meshBuilder.End(); pMesh->Draw(); pRender->PopRenderMode(); } } }
void FOculusRiftHMD::D3D11Bridge::BeginRendering(FHMDViewExtension& InRenderContext, const FTexture2DRHIRef& RT) { check(IsInRenderingThread()); SetRenderContext(&InRenderContext); FGameFrame* CurrentFrame = GetRenderFrame(); check(CurrentFrame); FSettings* FrameSettings = CurrentFrame->GetSettings(); check(FrameSettings); const uint32 RTSizeX = RT->GetSizeX(); const uint32 RTSizeY = RT->GetSizeY(); const FVector2D ActualMirrorWindowSize = CurrentFrame->WindowSize; // detect if mirror texture needs to be re-allocated or freed if (Hmd && MirrorTextureRHI && (bNeedReAllocateMirrorTexture || Hmd != RenderContext->Hmd || (FrameSettings->Flags.bMirrorToWindow && ( FrameSettings->MirrorWindowMode != FSettings::eMirrorWindow_Distorted || ActualMirrorWindowSize != FVector2D(MirrorTextureRHI->GetSizeX(), MirrorTextureRHI->GetSizeY()))) || !FrameSettings->Flags.bMirrorToWindow )) { check(MirrorTexture); ovrHmd_DestroyMirrorTexture(Hmd, MirrorTexture); MirrorTexture = nullptr; MirrorTextureRHI = nullptr; bNeedReAllocateMirrorTexture = false; } // need to allocate a mirror texture? if (FrameSettings->Flags.bMirrorToWindow && FrameSettings->MirrorWindowMode == FSettings::eMirrorWindow_Distorted && !MirrorTextureRHI && ActualMirrorWindowSize.X != 0 && ActualMirrorWindowSize.Y != 0) { D3D11_TEXTURE2D_DESC dsDesc; dsDesc.Width = ActualMirrorWindowSize.X; dsDesc.Height = ActualMirrorWindowSize.Y; dsDesc.MipLevels = 1; dsDesc.ArraySize = 1; dsDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; dsDesc.SampleDesc.Count = 1; dsDesc.SampleDesc.Quality = 0; dsDesc.Usage = D3D11_USAGE_DEFAULT; dsDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; dsDesc.CPUAccessFlags = 0; dsDesc.MiscFlags = 0; ID3D11Device* D3DDevice = (ID3D11Device*)RHIGetNativeDevice(); ovrHmd_CreateMirrorTextureD3D11(Hmd, D3DDevice, &dsDesc, &MirrorTexture); if (!MirrorTexture) { UE_LOG(LogHMD, Error, TEXT("Can't create a mirror texture")); return; } UE_LOG(LogHMD, Log, TEXT("Allocated a new mirror texture (size %d x %d)"), ActualMirrorWindowSize.X, ActualMirrorWindowSize.Y); ovrD3D11Texture D3DMirrorTexture; D3DMirrorTexture.Texture = *MirrorTexture; MirrorTextureRHI = D3D11CreateTexture2DAlias( static_cast<FD3D11DynamicRHI*>(GDynamicRHI), D3DMirrorTexture.D3D11.pTexture, D3DMirrorTexture.D3D11.pSRView, dsDesc.Width, dsDesc.Height, 0, dsDesc.MipLevels, /*ActualMSAACount=*/ 1, (EPixelFormat)PF_B8G8R8A8, TexCreate_RenderTargetable); bNeedReAllocateMirrorTexture = false; } }
int Main(int argc, char *argv[]){ LineArg *la = malloc(sizeof(LineArg)); GLuint VBO = 0; GLsizei offsets = 0; SDL_Event event; SDL_Window *screen = NULL; int live = 1; SDL_Init(SDL_INIT_VIDEO); { void **view = MakeWindow(800, 450); #ifdef _WIN32 LoadGLFunctions(); #endif screen = view[0]; } glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glGenBuffers(1, &VBO); assert(VBO!=0); glBindBuffer(GL_ARRAY_BUFFER, VBO); { float zero = 0.0; GLubyte bufferData[] = { 255, '\0', '\0', 255, //Color1 255, '\0', '\0', 255, //Color2 '\0', '\0', '\0', '\0', //X1 '\0', '\0', '\0', '\0', //Y1 '\0', '\0', '\0', '\0', //X2 '\0', '\0', '\0', '\0', //Y2 }; memcpy(bufferData+8, &zero, 4); memcpy(bufferData+12, &zero, 4); memcpy(bufferData+16, &zero, 4); memcpy(bufferData+20, &zero, 4); glBufferData(GL_ARRAY_BUFFER, sizeof(bufferData), bufferData, GL_DYNAMIC_DRAW); } la->Buffer = VBO; glBindBuffer(GL_ARRAY_BUFFER, 0); SetCoordinateData(VBO, 8); glFinish(); InitDrawQueue(); while(live){ ///// // Be a nice program and handle events. // while(SDL_PollEvent(&event)){ switch(event.type){ case (SDL_QUIT): live = 0; break; case (SDL_MOUSEMOTION): QueueUpdateMousePosition(event.motion.x, event.motion.y); break; } } QueueLine(la); QueueFlipScreen(screen); IncEngineFrame(); { int diff = GetEngineFrame()-GetRenderFrame(); assert(diff>=0); if(GetEngineFrame()%32){ sprintf(WindowTitle, "%s%-4i\t - %-8i\t / %-8i", WindowTitleBase, diff, GetRenderFrame(), GetEngineFrame()); } SDL_SetWindowTitle(screen, WindowTitle); while(diff>FrameFloat){ diff = GetEngineFrame()-GetRenderFrame(); SDL_Delay(0x10); } } } glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); CloseDrawQueue(); return EXIT_SUCCESS; }