[shaderx6]8.2 3d engine tools with c++cli
-
Upload
- -
Category
Technology
-
view
827 -
download
8
Transcript of [shaderx6]8.2 3d engine tools with c++cli
8.2 3D Engine Tools with C++/CLI
ohyecloudyhttp://ohyecloudy.com
shader studyhttp://cafe.naver.com/shader
2010.12.06
ShaderX6
Introduction
What Is C++/CLI?
General Programming Considerations
MS에서 .NET platform을 밀고 있음.
툴 작성이 더 편리해짐. GUI 쪽이 많이 편함.
Windows Forms
WPF Windows Presentation Foundation
작성했던 C++ 코드를 다 버려야 하나?
C++/CLI C++, .NET framework 징검다리 역할.
Introduction
What Is C++/CLI?
General Programming Considerations
http://en.wikipedia.org/wiki/Common_Language_Infrastructure
C++ /CLI
Compiler
가능한 애플리케이션
3D object visualization tools
Level editors
Conversion tools and plug-ins
어떻게 달라졌나?
heap이 두 종류 pure c++ heap garbage collected heap
pure c++ heap control * ctrl = new button();
garbage collected heap
control ^ ctrl = gcnew button();
어떻게 달라졌나?
소멸자에서 Dispose() 호출
키워드 추가 property, delegate, event
Language Features for Targeting the CLR
http://goo.gl/cPq7b
장점
DLLImport 필요 없다. Win32 바로 호출
C++ 컴파일러 최적화 젂략 여젂히 유효. .NET, C++ 라이브러리를 사용 가능. 다른 .NET 언어에서 사용 가능
C++/CLI로 만든 컴포넌트를
단점
컴파일러가 상대적으로 최근에 만들어짐
몇 가지 제한 DLLMain에서 .NET 코드를 호출하지 못함
managed 와 unmanaged
컨텍스트 스위칭에 비용이 크다.
Introduction
What Is C++/CLI?
General Programming Considerations
Minimize Context Switches
컨텍스트 스위칭 비용 native와 managed code 사이
50~300 cycles
Minimize Context Switches
컨텍스트 스위칭이 빈번 List<Vector3>^ : managed
DrawInstance : native
이런 경우엔 native array를 사용
List<Vector3>^ instancePos = world->GetTreeInstances(); for each (Vector3 pos in instancePos) pRenderer->DrawInstance(pGeo, pos.x, pos.y, pos.z);
Force Time-Critical Functions to Be Native
컴파일러 동작 과정 먼저 C++ 함수를 MSIL로 컴파일
실패하면 native로 컴파일
바로 native로 컴파일 inline, naked, #pragma unmanaged
Double Thunking
managed와 native가 섞인 코드 모듈이
컴파일됐을 때 entry point를 두 개 생성.
두 개 다 검사하는 double thunking 발생.
Exchanging Data
heap이 두 종류 pure c++ heap
garbage collected heap
간단한 타입은 잘 동작
복잡한 타입인 경우 바로 접근은 불가능 arrays, strings
Exchanging Data
// native function call int adaptersCount = pD3D->GetAdapterCount(); this->adaptersTextBox->Text = adaptersCount.ToString();
fwrite( textBox->Text, sizeof(char), textbox->Text->Length, pFile);
컴파일 성공
컴파일 실패
Pointers and Keeping References
가능
ref class WorldEntity // A managed class { ... private: CMesh* m_graphicalRep; // native pointer };
Pointers and Keeping References
Marshal 클래스가 가능하게 해준다.
native VARIANT 구조체를 대신 사용 16 bytes
class CMesh : public CPlacable3D { ... private: WorldEntity^ m_properties // reference managed object };
Introduction
What Is C++/CLI?
General Programming Considerations