void Load() { String name = mName; if (name.substr(name.length() - 4, 4) != ".dll") name += ".dll"; WString wname = StringToWString(name); m_hInst = (HINSTANCE)LoadLibraryEx(wname.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH ); if (!m_hInst) { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); fprintf(stderr, "%s\n", (char*)lpMsgBuf); // Free the buffer. LocalFree( lpMsgBuf ); String error = "Load " + name + " failed!"; ENGINE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, error, "DynLib::Load"); } }
void ThreadController::start() { stop(); mThread = CreateThread( NULL, NULL, threadProc, this, CREATE_SUSPENDED, &mThreadID ); if ( !mThread ) ENGINE_EXCEPT_WINAPI( "Could not create thread" ); if ( ResumeThread( mThread ) == (DWORD)-1 ) ENGINE_EXCEPT_WINAPI( "Could not resume thread" ); HANDLE events[2]; events[0] = mRunEvent; events[1] = mThread; DWORD wait = WaitForMultipleObjects( 2, events, FALSE, INFINITE ); switch ( wait ) { case WAIT_OBJECT_0 + 0: // Thread running OK break; case WAIT_OBJECT_0 + 1: ENGINE_EXCEPT( "Thread failed to start" ); break; case WAIT_FAILED: ENGINE_EXCEPT_WINAPI( "Wait for thread start failed" ); break; } }
uint32_t VertexElementUtil::GetElementSize( const VertexElement& element ) { switch(element.Type) { case VEF_Float: return sizeof(float); case VEF_Float2: return sizeof(float)*2; case VEF_Float3: return sizeof(float)*3; case VEF_Float4: return sizeof(float)*4; case VEF_Int: return sizeof(int32_t); case VEF_Int2: return sizeof(int32_t)*2; case VEF_Int3: return sizeof(int32_t)*3; case VEF_Int4: return sizeof(int32_t)*4; case VEF_UInt: return sizeof(uint32_t); case VEF_UInt2: return sizeof(uint32_t)*2; case VEF_UInt3: return sizeof(uint32_t)*3; case VEF_UInt4: return sizeof(uint32_t)*4; case VEF_Bool: return sizeof(bool); case VEF_Bool2: return sizeof(bool)*2; case VEF_Bool3: return sizeof(bool)*3; case VEF_Bool4: return sizeof(bool)*4; default: break; } ENGINE_EXCEPT(Exception::ERR_INVALID_PARAMS, "Invalid type", "VertexElement::GetElementSize"); }
Box::Box( PhysicsScene* scene, const Vector3& size, const Vector3& position, const Quaternion& orientation ): Primitive( scene ) { PxPhysics& physics = mScene->getScene()->getPhysics(); PxTransform transform; transform.p = Math::ogreVec3ToPx( position ); transform.q = Math::ogreQtToPx( orientation ); PxBoxGeometry geometry; geometry.halfExtents = Math::ogreVec3ToPx( size / 2.0f ); mActor = PxCreateStatic( physics, transform, geometry, *scene->getDefaultMaterial() ); if ( !mActor ) ENGINE_EXCEPT( "Could not create physics box actor" ); mScene->getScene()->addActor( *mActor ); mMesh = Procedural::BoxGenerator().setSize( size ).realizeMesh(); auto scm = Locator::getGraphics().getScene(); mNode = scm->getRootSceneNode()->createChildSceneNode(); mItem = Locator::getGraphics().getScene()->createItem( mMesh ); mItem->setQueryFlags( SceneQueryFlag_World ); mItem->setDatablock( "Developer/Floor" ); mItem->setCastShadows( true ); mNode->attachObject( mItem ); mNode->setPosition( position ); mNode->setOrientation( orientation ); }
uint32_t VertexElementUtil::GetElementComponentCount( const VertexElement& element ) { switch(element.Type) { case VEF_Float: case VEF_Int: case VEF_UInt: case VEF_Bool: return 1; case VEF_Float2: case VEF_Int2: case VEF_UInt2: case VEF_Bool2: return 2; case VEF_UInt3: case VEF_Float3: case VEF_Int3: case VEF_Bool3: return 3; case VEF_Float4: case VEF_Int4: case VEF_Bool4: case VEF_UInt4: return 4; } ENGINE_EXCEPT(Exception::ERR_INVALID_PARAMS, "Invalid type", "VertexElement::GetTypeCount"); }
void* OpenGLGraphicsBuffer::Map( uint32_t offset, uint32_t length, BufferAccess options ) { /*GLenum mapFlag; void* pMapBuffer = NULL; switch(options) { case BA_Read_Only: mapFlag = GL_READ_ONLY; break; case BA_Write_Only: mapFlag = GL_WRITE_ONLY; break; case BA_Read_Write: mapFlag = GL_READ_WRITE; break; } glBindBuffer(mTarget, mBufferID); pMapBuffer = glMapBuffer(mTarget, mapFlag); glBindBuffer(mTarget, 0);*/ // Switch to use glMapBufferRange GLbitfield access; void* pMapBuffer = NULL; switch(options) { case BA_Read_Only: access = GL_MAP_READ_BIT; break; case BA_Write_Only: access = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT; break; case BA_Read_Write: access = GL_MAP_READ_BIT | BA_Read_Write; break; } // Map all rest buffer if (length == MAP_ALL_BUFFER) length = mSizeInBytes - offset; if (offset < 0 || offset + length > mSizeInBytes) ENGINE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Out of range!", "GraphicsBuffer::Map"); glBindBuffer(mTarget, mBufferID); pMapBuffer = glMapBufferRange(mTarget, offset, length, access); glBindBuffer(mTarget, 0); OGL_ERROR_CHECK(); return pMapBuffer; }
void PixelFormatUtils::GetNumDepthStencilBits( PixelFormat format, uint32_t& depth, uint32_t& stencil ) { switch (format) { case PF_D16: { depth = 16; stencil = 0; } break; case PF_D24S8: { depth = 24; stencil = 8; } break; case PF_D32F: { depth = 32; stencil = 0; } break; case PF_D32FS8X24: { depth = 32; stencil = 8; } break; default: ENGINE_EXCEPT(Exception::ERR_INVALID_PARAMS, "Invalid depth format!", "PixelFormatUtils::GetNumDepthStencilBits"); } }
SceneObject* SceneNode::GetAttachedObject( const String& name ) { auto found = std::find_if(mAttachedObjects.begin(), mAttachedObjects.end(), [&name](SceneObject* obj){ return obj->GetName() == name; }); if (found == mAttachedObjects.end()) { ENGINE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Attached movable object named " + name + " does not exist.", "SceneNode::GetAttachedObject"); } return *found; }
void SceneNode::AttachObject( SceneObject* obj ) { if (obj->IsAttached()) { ENGINE_EXCEPT(Exception::ERR_INVALID_PARAMS, "Object already attached to a SceneNode", "SceneNode::attachObject"); } mAttachedObjects.push_back(obj); // since we have attach a scene object, bound may invalid. PropagateDirtyUp(NODE_DIRTY_BOUNDS); obj->OnAttach(this); }
D3D11RenderWindow::D3D11RenderWindow( uint32_t width, uint32_t height ) : D3D11FrameBuffer(width, height), SwapChainD3D11(nullptr), FeatureLevelD3D11(D3D_FEATURE_LEVEL_11_0) { const ApplicationSettings& appSettings = Application::msApp->GetAppSettings(); mSyncInterval = appSettings.SyncInterval; assert(DXGI_FORMAT_R8G8B8A8_UNORM == D3D11Mapping::Mapping(appSettings.ColorFormat)); UINT createDeviceFlags = 0; #ifdef _DEBUG createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, }; UINT numFeatureLevels = ARRAYSIZE( featureLevels ); DXGI_SWAP_CHAIN_DESC sd; ZeroMemory( &sd, sizeof( sd ) ); sd.BufferCount = 1; sd.BufferDesc.Width = width; sd.BufferDesc.Height = height; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.SampleDesc.Count = appSettings.SampleCount; sd.SampleDesc.Quality = appSettings.SampleQuality; sd.Windowed = appSettings.Fullscreen ? FALSE : TRUE; sd.OutputWindow = Window::msWindow->GetHwnd();; HRESULT hr = S_OK; hr = D3D11CreateDeviceAndSwapChain( NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &sd, &SwapChainD3D11, &gD3D11Device->DeviceD3D11, &FeatureLevelD3D11, &gD3D11Device->DeviceContextD3D11 ); if( FAILED( hr ) ) { ENGINE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to create d3d11 Device and SwapChain", "D3D11RenderWindow::D3D11RenderWindow"); } }
void D3D11Device::SetSamplerState( ShaderType stage, uint32_t unit, const shared_ptr<SamplerState>& state ) { SamplerSlot samSlot(stage, unit); bool needUpdate = false; if (mCurrentSamplers.find(samSlot) != mCurrentSamplers.end()) { if (mCurrentSamplers[samSlot] != state) { needUpdate = true; mCurrentSamplers[samSlot] = state; } } else { needUpdate = true; mCurrentSamplers[samSlot] = state; } if (needUpdate) { ID3D11SamplerState* samplerStateD3D11 = (static_cast<D3D11SamplerState*>(state.get()))->StateD3D11; switch (stage) { case ST_Vertex: DeviceContextD3D11->VSSetSamplers(unit, 1, &samplerStateD3D11); break; case ST_Geomerty: DeviceContextD3D11->GSSetSamplers(unit, 1, &samplerStateD3D11); break; case ST_Pixel: DeviceContextD3D11->PSSetSamplers(unit, 1, &samplerStateD3D11); break; case ST_Compute: DeviceContextD3D11->CSSetSamplers(unit, 1, &samplerStateD3D11); break; default: ENGINE_EXCEPT(Exception::ERR_INVALID_PARAMS, "Invalid SamplerState", "D3D11RenderDevice::SetSamplerState"); break; } } }
Plane::Plane( PhysicsScene* scene, const Ogre::Plane& plane, const Real width, const Real height, const Vector3& position, const Real u, const Real v ): Primitive( scene ) { PxPhysics& physics = mScene->getScene()->getPhysics(); mActor = PxCreatePlane( physics, PxPlane( Glacier::Math::ogreVec3ToPx( plane.normal ), plane.d ), *mScene->getDefaultMaterial() ); if ( !mActor ) ENGINE_EXCEPT( "Could not create physics plane actor" ); mScene->getScene()->addActor( *mActor ); Ogre::v1::MeshPtr planeMeshV1 = Ogre::v1::MeshManager::getSingleton().createPlane( "", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, width, height, 1, 1, true, 1, u, v, Ogre::Vector3::UNIT_Z, Ogre::v1::HardwareBuffer::HBU_STATIC, Ogre::v1::HardwareBuffer::HBU_STATIC ); mMesh = Ogre::MeshManager::getSingleton().createManual( "", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); mMesh->importV1( planeMeshV1.get(), true, true, true ); // mMesh = Procedural::PlaneGenerator().setEnableNormals( true ).setSize( Vector2( width, height ) ).setNormal( plane.normal ).setNumSegX( 8 ).setNumSegY( 8 ).setUTile( u ).setVTile( v ).realizeMesh(); auto scm = Locator::getGraphics().getScene(); mNode = scm->getRootSceneNode()->createChildSceneNode(); mItem = scm->createItem( mMesh ); mItem->setQueryFlags( SceneQueryFlag_World ); mItem->setDatablock( "GameTextures/TileLargeHexagon" ); mItem->setCastShadows( false ); mNode->attachObject( mItem ); mNode->setPosition( position ); mNode->setOrientation( Quaternion::IDENTITY ); }
FMODAudio::FMODAudio( Engine* engine ): EngineComponent( engine ), mEventSystem( nullptr ), mSystem( nullptr ), mMusic( nullptr ) { FMOD_RESULT hr; resetGroups(); FMOD::Memory_Initialize( NULL, 0, FMODAudio::callbackFMODMemAlloc, FMODAudio::callbackFMODMemRealloc, FMODAudio::callbackFMODMemFree, FMOD_MEMORY_NORMAL ); // Create event system instance hr = FMOD::EventSystem_Create( &mEventSystem ); if ( FMOD_FAILED( hr ) ) ENGINE_EXCEPT_FMOD( hr, "Failed to create FMOD EventSystem" ); // Fetch underlying oldschool system hr = mEventSystem->getSystemObject( &mSystem ); if ( FMOD_FAILED( hr ) ) ENGINE_EXCEPT_FMOD( hr, "Failed to get FMOD System object" ); // Set FMOD log file name FMOD_ADVANCEDSETTINGS advancedSettings = { NULL }; advancedSettings.cbsize = sizeof( FMOD_ADVANCEDSETTINGS ); advancedSettings.debugLogFilename = const_cast<char*>( cFMODLogFile ); mSystem->setAdvancedSettings( &advancedSettings ); // Check version unsigned int version; hr = mSystem->getVersion( &version ); if ( FMOD_FAILED( hr ) ) ENGINE_EXCEPT_FMOD( hr, "Failed to get FMOD System version" ); if ( version != FMOD_VERSION ) ENGINE_EXCEPT( "Bad FMOD runtime version" ); initialize(); }
Node* Bone::CreateChildImpl( const String& name ) { ENGINE_EXCEPT(Exception::ERR_RT_ASSERTION_FAILED, "Shound't call Bone::CreateChildImpl", "Bone::CreateChildImpl"); return nullptr; }
/* Get the mesh information for the given mesh in v2 Ogre3D format. This is a really useful function that can be used by many different systems. e.g. physics mesh, navmesh, occlusion geometry etc... Original Code - Code found on this forum link: http://www.ogre3d.org/wiki/index.php/RetrieveVertexData Most Code courtesy of al2950( thanks m8 :)), but then edited by Jayce Young & Hannah Young at Aurasoft UK (Skyline Game Engine) to work with Items in the scene. */ void getMesh2Information( const Ogre::MeshPtr mesh, size_t &vertex_count, Ogre::Vector3* &vertices, size_t &index_count, Ogre::uint32* &indices, const Ogre::Vector3 &position, const Ogre::Quaternion &orient, const Ogre::Vector3 &scale ) { //First, we compute the total number of vertices and indices and init the buffers. unsigned int numVertices = 0; unsigned int numIndices = 0; Ogre::Mesh::SubMeshVec::const_iterator subMeshIterator = mesh->getSubMeshes().begin(); while ( subMeshIterator != mesh->getSubMeshes().end() ) { Ogre::SubMesh *subMesh = *subMeshIterator; numVertices += subMesh->mVao[0][0]->getVertexBuffers()[0]->getNumElements(); numIndices += subMesh->mVao[0][0]->getIndexBuffer()->getNumElements(); subMeshIterator++; } vertices = new Ogre::Vector3[numVertices]; indices = new Ogre::uint32[numIndices]; vertex_count = numVertices; index_count = numIndices; unsigned int addedVertices = 0; unsigned int addedIndices = 0; unsigned int index_offset = 0; unsigned int subMeshOffset = 0; // Read Submeshes subMeshIterator = mesh->getSubMeshes().begin(); while ( subMeshIterator != mesh->getSubMeshes().end() ) { Ogre::SubMesh *subMesh = *subMeshIterator; Ogre::VertexArrayObjectArray vaos = subMesh->mVao[0]; if ( !vaos.empty() ) { //Get the first LOD level Ogre::VertexArrayObject *vao = vaos[0]; bool indices32 = ( vao->getIndexBuffer()->getIndexType() == Ogre::IndexBufferPacked::IT_32BIT ); const Ogre::VertexBufferPackedVec &vertexBuffers = vao->getVertexBuffers(); Ogre::IndexBufferPacked *indexBuffer = vao->getIndexBuffer(); //request async read from buffer Ogre::VertexArrayObject::ReadRequestsArray requests; requests.push_back( Ogre::VertexArrayObject::ReadRequests( Ogre::VES_POSITION ) ); vao->readRequests( requests ); vao->mapAsyncTickets( requests ); unsigned int subMeshVerticiesNum = requests[0].vertexBuffer->getNumElements(); if ( requests[0].type == Ogre::VET_HALF4 ) { for ( size_t i = 0; i < subMeshVerticiesNum; ++i ) { const Ogre::uint16* pos = reinterpret_cast<const Ogre::uint16*>( requests[0].data ); Ogre::Vector3 vec; vec.x = Ogre::Bitwise::halfToFloat( pos[0] ); vec.y = Ogre::Bitwise::halfToFloat( pos[1] ); vec.z = Ogre::Bitwise::halfToFloat( pos[2] ); requests[0].data += requests[0].vertexBuffer->getBytesPerElement(); vertices[i + subMeshOffset] = ( orient * ( vec * scale ) ) + position; } } else if ( requests[0].type == Ogre::VET_FLOAT3 ) { for ( size_t i = 0; i < subMeshVerticiesNum; ++i ) { const float* pos = reinterpret_cast<const float*>( requests[0].data ); Ogre::Vector3 vec; vec.x = *pos++; vec.y = *pos++; vec.z = *pos++; requests[0].data += requests[0].vertexBuffer->getBytesPerElement(); vertices[i + subMeshOffset] = ( orient * ( vec * scale ) ) + position; } } else { ENGINE_EXCEPT( "Unknown vertex buffer format" ); } subMeshOffset += subMeshVerticiesNum; vao->unmapAsyncTickets( requests ); ////Read index data if ( indexBuffer ) { Ogre::AsyncTicketPtr asyncTicket = indexBuffer->readRequest( 0, indexBuffer->getNumElements() ); unsigned int *pIndices = 0; if ( indices32 ) { pIndices = (unsigned*)( asyncTicket->map() ); } else { unsigned short *pShortIndices = (unsigned short*)( asyncTicket->map() ); pIndices = new unsigned int[indexBuffer->getNumElements()]; for ( size_t k = 0; k < indexBuffer->getNumElements(); k++ ) pIndices[k] = static_cast<unsigned int>( pShortIndices[k] ); } unsigned int bufferIndex = 0; for ( size_t i = addedIndices; i < addedIndices + indexBuffer->getNumElements(); i++ ) { indices[i] = pIndices[bufferIndex] + index_offset; bufferIndex++; } addedIndices += indexBuffer->getNumElements(); if ( !indices32 ) delete[] pIndices; asyncTicket->unmap(); } index_offset += vertexBuffers[0]->getNumElements(); } subMeshIterator++; } }