⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shadowview.cpp

📁 PDE simulator on GPU.
💻 CPP
字号:
// ShadowView.cpp : implementation of the CShadowView class
//

#include "stdafx.h"
#include "Shadow.h"
#include <math.h>
#include "extgl.h"

#include "MainFrm.h"
#include "ShadowDoc.h"
#include "ShadowView.h"

#include "InitOpenGL.h"
#include "CommonHW.h"

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

/////////////////////////////////////////////////////////////////////////////
// CShadowView

IMPLEMENT_DYNCREATE(CShadowView, CView)

BEGIN_MESSAGE_MAP(CShadowView, CView)
	//{{AFX_MSG_MAP(CShadowView)
	ON_WM_SIZE()
	ON_WM_ERASEBKGND()
	ON_WM_CREATE()
	ON_COMMAND(ID_TESTCOMPUTATIONONGPU, OnTestComputationOnGPU)
	ON_COMMAND(ID_READYBUTTON, OnReadybutton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShadowView construction/destruction

CShadowView::CShadowView()
{
	m_FrameRate = 0.0;

	isReady = false;
}

CShadowView::~CShadowView()
{
	wglMakeCurrent(NULL,NULL);
	wglDeleteContext(m_hRC);  
	delete m_pDC;
}

BOOL CShadowView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	return CView::PreCreateWindow(cs);
}


/////////////////////////////////////////////////////////////////////////////
// CShadowView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CShadowView message handlers
/////////////////////////////////////////////////////////////////////////////
//Methods to OpenGL
void CShadowView::SetupPerspective()
{
	CRect rect;
	GetClientRect(&rect);
	WinWidth  = rect.Width();
	WinHeight = rect.Height();	
	WHRatio = (float)WinWidth/(float)WinHeight;
//	glViewport(0,0,130,130);
	glViewport(0,0,WinWidth,WinHeight);
	if ( 0 >= WinWidth || 0 >= WinHeight )
		return;
}

void CShadowView::InitRenderWin()
{
	glShadeModel( GL_SMOOTH );
	glDepthFunc ( GL_LESS );
	glDisable ( GL_DEPTH_TEST );
	glDisable(GL_CULL_FACE);

	//glClearColor( 0.45, 0.5, 1.0, 1.0);
	glClearColor( 0.0, 0.0, 0.0, 0.0);
	//glClearColor( 1.0, 1.0, 1.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);	
	
	glViewport(0,0,WinWidth,WinHeight);
//	glViewport(0,0,130,130);
    // The viewing settings.
	glMatrixMode ( GL_PROJECTION );
	glLoadIdentity();
 //	gluPerspective( ViewAngle, WHRatio, PerspNear, PerspFar );
//	glOrtho( 0, WinWidth, 0, WinHeight, -1.0, 1.0 );
	gluOrtho2D ( 0.0, 1.0, 0.0, 1.0 );

	glMatrixMode ( GL_MODELVIEW );
	glLoadIdentity();
}

/////////////////////////////////////////////////////////////////////////////
void CShadowView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	SetupPerspective();
	Invalidate(FALSE);
}

////////////////////////////////////////////////////////////////////////
BOOL CShadowView::OnEraseBkgnd(CDC* pDC) 
{
	//return TRUE;				 // tell Windows not to erase the background
	return CView::OnEraseBkgnd(pDC);
}

////////////////////////////////////////////////////////////////////////
int CShadowView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	m_pDC = new CClientDC(this);
	InitializeOpenGL(m_hRC,m_pDC->GetSafeHdc());

	QueryPerformanceFrequency(&timerFrequency);
	QueryPerformanceFrequency( &frequency );
	
	SetupPerspective();

	///////Initialize OpenGL extension
	extgl_Initialize();

	///////
	FindOutResourceLimitOnCurrentHW();
	LoadFragmentProgramFiles();

	return 0;
}

///////////////////////////////////////////////////////////////////////////
void CShadowView::UpdateInformation()
{
	CShadowApp *pApp = (CShadowApp *)AfxGetApp();
	CMainFrame *pFrame = (CMainFrame *)pApp->m_pMainWnd;
	CString tmp;
	tmp.Format("Time=%5.2fms:Rate=%5.4ffps", m_FrameRate*1000, 1.0/m_FrameRate);
	pFrame->m_wndStatusBar.SetPaneText(1,tmp);

	tmp.Format("W=%d,H=%d", WinWidth, WinHeight);
	pFrame->m_wndStatusBar.SetPaneText(2,tmp);

}
//////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////
// CShadowView drawing
void CShadowView::OnDraw(CDC* pDC)
{
	//OpenGL !!!!!!!
	if(isReady)
	{
//		QueryPerformanceCounter(&startTime);
		RenderScene();
//		QueryPerformanceCounter(&endTime);
//		m_FrameRate = 1.0/((float)(endTime.QuadPart - startTime.QuadPart)/(float)timerFrequency.QuadPart);
//		UpdateInformation();
	}
	CView::OnDraw(pDC);	
}

///////////////////////////////////////////////////////////////////
/////  Latest Date: 2004/1/6
/////  Created by : Youquan Liu
///////////////////////////////////////////////////////////////////
#include "CommonHW.h"
#include "TestDenseMatrixVectorMultiply.h"
#include "TestEquationsSolver.h"
#include "TestMatrixMatrixOperations.h"
#include "TestSparseMatrixVector1.h"
#include "TestSparseMatrixVector2.h"
#include "TestSparseMatrixVector3.h"
#include "TestVectorOperations.h"
#include "AnyTestFunctions.h"


/////////////////////////////////////////////////////////////////////////////
BOOL CShadowView::RenderScene()
{
	QueryPerformanceCounter(&startTime);
	//////////////////////////////////
	InitRenderWin();

	///////Performance Test here with CPU and GPU


	glFlush();

	// Now Swap the buffers
	if ( FALSE == SwapBuffers(m_pDC->GetSafeHdc()))
		return FALSE;

	QueryPerformanceCounter(&endTime);
	m_FrameRate = ((float)(endTime.QuadPart - startTime.QuadPart)/(float)timerFrequency.QuadPart);
	UpdateInformation();

	return TRUE;
}
	
///////////////////////////////////////////////////////////////////
void CShadowView::OnTestComputationOnGPU() 
{
	///////Performance Test here with CPU and GPU
	InitRenderWin();
	//1
	//TestclVecOp();
	//2
	TestclVecReduceFP();
	//3
	//TestclInnerProductFP();
	//4
	//TestKrugerSparseMatVec();
	//5
	//TestBrookSparseMatVec();
	//6
	//TestBolzSparseMatVec();
	//7
	//TestclMatMat();
	//8
	//PerformanceIterativeSolverTestOnGPU();
	//9
	//TestMultiMatVec();
	//10
	//TestclMatVec();
	//11
	//PerformanceTestOnGPU();

}

///////////////////////////////////////////////////////////////////
void CShadowView::OnReadybutton() 
{
	
	return;
}

///////////////////////////////////////////////////////////////////
//// Load a image file and use it as an input texture
////
///////////////////////////////////////////////////////////////////


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -