我要发帖 回复

中级会员

30

主题

170

积分

0

专家分

:

私信
发表时间 : 2008-6-18 14:02:45 | 浏览 : 2654    评论 : 11
// mfcView.cpp : implementation of the CMFCView class
//

#include "stdafx.h"
#include "vp_mfc.h"
#include "vp_mfcDoc.h"
#include "vp_mfcView.h"


// START: Vega Prime - Includes
// NOTE: Vega Prime includes MUST be placed BEFORE
// the line of code '#define new DEBUG_NEW' because
// of a conflict created by redefining DEBUG_NEW.
#include <vp.h>
#include <vpKernel.h>
#include <vpWindow.h>
#include "vuDistributed.h"
#include "vuAllocTracer.h"
vuAllocTracer tracer(true, true);
// END: Vega Prime - Includes

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif



/////////////////////////////////////////////////////////////////////////////
// CMFCView

IMPLEMENT_DYNCREATE(CMFCView, CView)

BEGIN_MESSAGE_MAP(CMFCView, CView)
        //{{AFX_MSG_MAP(CMFCView)
        ON_WM_CREATE()
        ON_WM_TIMER()
        ON_WM_SIZE()
        //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMFCView construction/destruction

CMFCView::CMFCView()
{
        // TODO: add construction code here

}

CMFCView::~CMFCView()
{
        // START: Vega Prime - Shutdown
    // Notify VP that we want to end frame loop
    vpKernel::instance()->breakFrameLoop();

    // Allow VP to exit from frame loop
    int frameNum = vpKernel::instance()->beginFrame();
    assert(frameNum == 0);

    int result; // vsgu::SUCCESS or vsgu::FAILURE

    result = vpKernel::instance()->unconfigure();
    assert(result == vsgu::SUCCESS);
   
    result = vp::shutdown();
    assert(result == vsgu::SUCCESS);

    // END: Vega Prime - Shutdown
}

BOOL CMFCView::PreCreateWindow(CREATESTRUCT& cs)
{
        // TODO: Modify the Window class or styles here by modifying
        //  the CREATESTRUCT cs

        return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMFCView drawing

void CMFCView::OnDraw(CDC* pDC)
{
        CMFCDoc* pDoc = GetDocument();
        ASSERT_VALID(pDoc);
        // TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CMFCView diagnostics

#ifdef _DEBUG
void CMFCView::AssertValid() const
{
        CView::AssertValid();
}

void CMFCView::Dump(CDumpContext& dc) const
{
        CView::Dump(dc);
}

CMFCDoc* CMFCView::GetDocument() // non-debug version is inline
{
        ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCDoc)));
        return (CMFCDoc*)m_pDocument;
}
#endif //_DEBUG


/////////////////////////////////////////////////////////////////////////////
// CMFCView message handlers

int CMFCView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
        if (CView::OnCreate(lpCreateStruct) == -1)
                return -1;

        // TODO: Add your specialized creation code here
   
// initialize vega prime
    int result; // vsgu::SUCCESS or vsgu::FAILURE
   
    result = vp::initialize(__argc, __argv);
    assert(result == vsgu::SUCCESS);  

    // initialize addition modules here
    // vpModule::initializeModule(modulename);


    // Set the syncEnable bits *prior* to configure().
    // DR ignores changes to setSyncEnable() after configure().

    // Pre swapbuffers synchronization.  Setting to "true" forces the master
    // and slaves to sync before swapbuffers.  Setting to "false" will result
    // in systems swapping their buffers independently.  
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_PRE_SWAPBUFFERS, true );

    // Post swapbuffers synchronization.  Setting to "true" forces the master
    // and slaves to sync after swapping their buffers.  
    // This typically results in slower framerates, but can ensure all systems
    // have the same amount of draw time.
    // Default is "false."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_POST_SWAPBUFFERS, false );

    // ACF synchronization across DR slaves.  Setting to "true" will send the
    // master's version of an ACF to the slaves (slaves will ignore their local
    // copy).  Setting to "false" will force slaves to use their local copy of
    // the ACF passed into ::define().
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_ACF, true );

    // Time synchronization across DR slaves. Setting to "true" will give every
    // system the same frame time.  Setting to "false" will let each system
    // use its system's clock for time.  
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_TIME, true );

    // Window messages synchronization.  Setting to "true" will send the
    // master's messages to all the slaves.  Setting to "false" will prevent
    // sending the master's window messages to the slaves.  
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_MESSAGES, true );
  
    // Virtual Texture synchronization.  Setting to "true" will force all
    // systems to page virtual texture at the same time.  Setting to "false"
    // will cause systems to page virtual texture independently.  
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_VT, true );

    // Synchronize paging.  Setting to "true" will force all systems to page
    // texture and geometry at the same time.  Setting to "false" will cause
    // systems to page texture and geometry independently.
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_PAGING, true );

    // Synchronize input devices.  Setting to "true" will make each system
    // react as if the master's input device is connected to the slave.  
    // Setting to "false" will not pass input device updates from the master
    // to the slaves.  
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_INPUT, true );

    // Synchronize Level of Detail Stress.  Setting to "true" will ensure all
    // LOD changes are synchronized.  Setting to "false" let each system
    // determine independently when LOD's should change.  
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_LOD_STRESS, true );

    // User defined synchronization.  Setting to "true" will enable user
    // defined synchronization.  Setting to "false" disables all user
    // defined synchronization.  In this example, disabling user defined sync
    // result in different lowest random numbers for each system.
    // Default is "true."
    vuDistributed::setSyncEnable( vuDistributed::SYNC_LABEL_USER, true );

    // START: Vega Prime - Initialization
    //int result; // vsgu::SUCCESS or vsgu::FAILURE
    //
    //result = vp::initialize(__argc, __argv);
    //assert(result == vsgu::SUCCESS);

    // set acf file
    CString acfFile;

    if (__argc <= 1)
        acfFile = "2pipeline.acf";
    else
        acfFile = __argv[1];

    // load acf file
    result = vpKernel::instance()->define(acfFile);
    assert(result == vsgu::SUCCESS);

        
    // configure Vega Prime
    result = vpKernel::instance()->configure();
    assert(result == vsgu::SUCCESS);


    // assuming at least one window in acf
    assert(vpWindow::size() != 0);

    // get the first Vega Prime window
    vpWindow *vpWin = *vpWindow::begin();

    // set this MFC View window as the parent of the Vega Prime window
    vpWin->setParent(m_hWnd);

    // remove the Vega Prime border (use MFC parent window border instead)
    vpWin->setBorderEnable(false);
       

    // let MFC parent window determine our size by filling the MFC parent
    // window frame
    // vpWin->setFullScreenEnable(true);

    // We can force the Vega Prime window open by calling beginFrame/endFrame
    //   NOTE: OnActivateView requires the Vega Prime window open before it is
    //         called.  If it is not open, the Vega Prime window will never
    //         get focus and thus will not handle keyboard input.

    int frameNum = vpKernel::instance()->beginFrame();
    assert(frameNum != 0);

        vuNotify::setLevel( vuNotify::LEVEL_FATAL);

   // uint frameNum;
    if( vuDistributed::getMode() == vuDistributed::MODE_SLAVE )
        {
                uint seed = 13;
        VUNOTIFY_PRINT(( vuNotify::LEVEL_INFO,
                          NULL,
                          "Slave setting seed to = %d\n",
                          seed ) );
                srand(seed);
        }
        else
        {
                uint seed = 5;
        VUNOTIFY_PRINT( ( vuNotify::LEVEL_INFO,
                          NULL,
                          "Master setting seed to = %d\n",
                          seed ) );
        srand(seed);
        }

    result = vpKernel::instance()->endFrame();
    assert(result == vsgu::SUCCESS);



    // setup timer that updates frame

    //   NOTE: Timer messages (WM_TIMER) are low priority messages.  They
    //         are processed after all other messages have been processed.
    //         Updating frames this way makes the application more responsive
    //         at the expense of frame updates.

    // Timeout of -1 means send a WM_TIMER message as soon as the last
    // message was handled.  This will allow the Vega Prime window to update
    // as fast as it can.

    const int TIMER_ID = 1;
    int returnValue = SetTimer(TIMER_ID, 50, NULL);   
    assert(returnValue == TIMER_ID);

    // END: Vega Prime - Initialization


        return 0;
}
// rendering loop
void CMFCView::OnTimer(UINT nIDEvent)
{
        int frameNum = vpKernel::instance()->beginFrame();
    assert(frameNum != 0);
        int myframenum = frameNum;

    // basic sync mechanism.  masters and slaves wait.  no data is exchanged.
    vuDistributed::sync();

    int randomNum = rand();

    VUNOTIFY_PRINT( ( vuNotify::LEVEL_INFO,
                        NULL,
                        "Original Random Number = %d\n",
                        randomNum ));

    int masterData;

    // if master, cache the random number and send it to the slaves.
    if( vuDistributed::getMode() == vuDistributed::MODE_MASTER ) {
        masterData = randomNum;
    }

    // slaves wait for master to receive data.  if master gets here first, it sends data and immediately moves on.
    // if slaves get here first, slaves block waiting for master's data.
    vuDistributed::sync( (char*) &masterData, sizeof(masterData), vuDistributed::SYNC_LABEL_USER, vuDistributed::WAIT_SLAVES );


    VUNOTIFY_PRINT( ( vuNotify::LEVEL_INFO,
                        NULL,
                        "Data sent from master = %d\n",
                        masterData ) );

    int randBuf[64];

    // master and slaves swap data.  notice no wait enum is required.  by definition all dr apps wait until
    // all data has been exchanged.
    vuDistributed::sync( (char*) &randomNum, sizeof(randomNum), (char*) &randBuf, sizeof(int)*vuDistributed::getNumParticipants(),vuDistributed::SYNC_LABEL_USER );

    int lowRand = INT_MAX;
    for( int i = 0; i < vuDistributed::getNumParticipants(); i++ ) {

        if( randBuf < lowRand )
            lowRand = randBuf;
    }

    VUNOTIFY_PRINT( ( vuNotify::LEVEL_INFO,
                        NULL,
                        "Lowest Random Number = %d\n",
                        lowRand ) );


    assert( myframenum == frameNum );        
   
    double time   = vpKernel::instance()->getSimulationTime();        

    static double previousTime = -1;
    static double maxTime = DBL_MIN;
    static double minTime = DBL_MAX;
    static double totalTime = 0;


    VUNOTIFY_PRINT( ( vuNotify::LEVEL_INFO,
                        NULL,
                        "Frame Number = %d, time = %f\n",
                        frameNum,
                        time ) );
   
    if( previousTime != -1 )
        {


        double deltaTime = time - previousTime;

        if( deltaTime > maxTime )
            maxTime = deltaTime;
        if( deltaTime < minTime )
            minTime = deltaTime;

        totalTime += deltaTime;


       VUNOTIFY_PRINT( ( vuNotify::LEVEL_INFO,
                            NULL,
                            "Delta = %.3f sec, Max = %.3f, Min = %.3f, Avg = %.3f\n",
                            deltaTime, maxTime, minTime, totalTime/double(frameNum) ) );
    }
    previousTime = time;

    int result = vpKernel::instance()->endFrame();
    assert(result == vsgu::SUCCESS);
        CView::OnTimer(nIDEvent);
}

void CMFCView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
        // TODO: Add your specialized code here and/or call the base class

    CView::OnActivateView(bActivate, pActivateView, pDeactiveView);


    // START: Vega Prime - Set Focus

   
    // NOTE: Make sure base class OnActivateView is called BEFORE we set the
    //       focus.  Otherwise, the MFC Parent window will take the focus
    //       from the Vega Prime window.  The window with the focus receives
    //       keyboard input.

    // if activating this view...
    if(bActivate) {

        // get the first Vega Prime window
        vpWindow *vpWin = *vpWindow::begin();

        // set the focus
        HWND hVPWnd = vpWin->getWindow();
        assert(::IsWindow( hVPWnd ) == TRUE);
        ::SetFocus(hVPWnd);
    }


    // END: Vega Prime - Set Focus
       

}

void CMFCView::OnSize(UINT nType, int cx, int cy)
{
        CView::OnSize(nType, cx, cy);
       
        // TODO: Add your message handler code here
   
   
    // START: Vega Prime - Set Size

    // get the first Vega Prime window
    vpWindow *vpWin = *vpWindow::begin();

    // set size of Vega Prime window
    vpWin->setSize(cx, cy);


    // END: Vega Prime - Set Size
}

最近VR访客

只要做些什么,就会有所不同:)
perfect_ren 评论于2008-6-18 14:11:11
我想把分布式渲染ACF文件加到mfc程序里面来,仿照vp的控制台demo,放进了mfc,执行发现两个通道不同步,高手能告诉我怎么回事么?或者给个简单的demo?我这样放代码是不是不对?另外,我的acf文件vp自己可以分布式渲染成功,但是加到vp自带的demo(只是改一下调用acf名字),程序启动不了,弹出下面的画面
11.JPG
只要做些什么,就会有所不同:)
perfect_ren 评论于2008-6-18 14:19:52
刚接触vp,也是刚接触分布式渲染,一头雾水,很希望大家能多多交流。分布式渲染写代码和单机的区别主要是什么?原理是不是一套代码多台机器运行,只是dr模块负责命令的通讯同步,那么比如原先的setparent(hwnd)这样的语句,就不能findwindow(“名字”)来得到vp窗口句柄了吧?!诸如此类的问题,难道要分情况(pipeline)对待么?要是哪位高手能提供一个简单的demo就好了。期待中......
只要做些什么,就会有所不同:)
perfect_ren 评论于2008-6-18 14:25:04
还有一个问题,总听别人说一个投影仪最好投40度左右的视角,他的意思是说vp窗口水平视角最好设置40度左右么?如果按照分辨率比例设置120或者90度的就变形么?我按照8比3的分辨率(3200x1200)设置水平120竖直45,就一个窗口,也没觉出变形啊?罗罗嗦嗦这么多,也不知道把问题描述清楚没有,还希望大家多多指教,共同进步
只要做些什么,就会有所不同:)
perfect_ren 评论于2008-6-19 10:31:13
沉下去了,自己顶一下:)
只要做些什么,就会有所不同:)
wgluser 评论于2008-6-20 13:16:57
做成个打包的程序吧.
perfect_ren 评论于2008-6-23 23:17:19
算了,用控制台就可以了,有时间再研究放到mfc里面。
只要做些什么,就会有所不同:)
life1981 评论于2008-6-27 20:49:55
好东西
rpzywspchh 评论于2008-7-10 02:05:38
好东西
xujing2010 评论于2008-7-15 21:21:42
正在关注中
tottttottt 评论于2008-7-30 13:10:42

请教分布式问题

你好,楼主,我现在在调试分布式的控制台程序,不知道怎么也不能够在两台电脑上出来,vp可以,但是程序不行,请教你是怎么弄出来的,还需要其他的特殊的控制吗,谢谢,急等。
perfect_ren 评论于2009-5-26 16:41:55
又回到原点了,必须用MFC做分布式渲染,有没有哪位高手有DEMO?
只要做些什么,就会有所不同:)

手机版|VR开发网 统计 津ICP备18009691号
网安备12019202000257

GMT+8, 2021-6-16 06:49 PM

返回顶部