//------------------------------------------------------------------------- // ReleaseFocus // add sound management here //------------------------------------------------------------------------- void CMultiSAP::ReleaseFocus() { CMovie *pmovie = m_movieList.GetSelectedMovie(); if(pmovie && pmovie->m_Fg) { // Tell the resource manager that we are being made active. This // will then cause the sound to switch to THE SELECTED MEDIA SOURCE. // This is especially // important when playing audio only files as there is no other // playback window. IResourceManager* pResourceManager; HRESULT hr = pmovie->m_Fg->QueryInterface(IID_IResourceManager, (void**)&pResourceManager); if(SUCCEEDED(hr)) { IUnknown* pUnknown; hr = pmovie->m_Fg->QueryInterface(IID_IUnknown, (void**)&pUnknown); if(SUCCEEDED(hr)) { pResourceManager->ReleaseFocus(pUnknown); pUnknown->Release(); } pResourceManager->Release(); } } }
/******************************Public*Routine******************************\ * SetFocus * \**************************************************************************/ void CMovie::SetFocus() { if(m_Fg) { // Tell the resource manager that we are being made active. This // will then cause the sound to switch to us. This is especially // important when playing audio only files as there is no other // playback window. IResourceManager* pResourceManager; HRESULT hr = m_Fg->QueryInterface(IID_IResourceManager, (void**)&pResourceManager); if(SUCCEEDED(hr)) { IUnknown* pUnknown; hr = m_Fg->QueryInterface(IID_IUnknown, (void**)&pUnknown); if(SUCCEEDED(hr)) { hr = pResourceManager->SetFocus(pUnknown); pUnknown->Release(); } pResourceManager->Release(); } } }
int loader_thread(void *loader) { ResourceLoader *resourceLoader = (ResourceLoader *) loader; IResourceManager *resourceManager = resourceLoader->getResourceManager(); LoadingJob *curJob; while (true) { // get a new job from the in list. curJob = resourceLoader->getJobIn(); // process the job switch (curJob->type) { case LOAD_JOB_MESH: // load a mesh curJob->data = resourceManager->readMeshData(curJob->ref->fileName, LOAD_NORMAL_VERTEX, 1.0); break; case LOAD_JOB_TEXTURE: // load a texture curJob->data = resourceManager->loadBMPImage(curJob->ref->fileName); break; default: cerr << "Unknown load job\n"; exit(1); break; } // put the finished job in the out list. resourceLoader->addJobOut(curJob); } return 0; }
void DviProtocolUpnp::WriteResource(const Brx& aUriTail, TIpAddress aAdapter, std::vector<char*>& aLanguageList, IResourceWriter& aResourceWriter) { if (aUriTail == kDeviceXmlName) { Brh xml; Brn xmlBuf; AutoMutex _(iLock); const TInt index = FindListenerForInterface(aAdapter); if (index == -1) { return; } if (iDevice.IsRoot()) { const Brx& cachedXml = iAdapters[index]->DeviceXml(); if (cachedXml.Bytes() > 0) { xmlBuf.Set(cachedXml); } } if (xmlBuf.Bytes() == 0) { GetDeviceXml(xml, aAdapter); if (iDevice.IsRoot()) { iAdapters[index]->SetDeviceXml(xml); xmlBuf.Set(iAdapters[index]->DeviceXml()); } else { xmlBuf.Set(xml); } } aResourceWriter.WriteResourceBegin(xmlBuf.Bytes(), kOhNetMimeTypeXml); aResourceWriter.WriteResource(xmlBuf.Ptr(), xmlBuf.Bytes()); aResourceWriter.WriteResourceEnd(); } else { Parser parser(aUriTail); Brn buf = parser.Next('/'); Brn rem = parser.Remaining(); if (buf == DviDevice::kResourceDir) { IResourceManager* resMgr = iDevice.ResourceManager(); if (resMgr != NULL) { resMgr->WriteResource(rem, aAdapter, aLanguageList, aResourceWriter); } } else if (rem == kServiceXmlName) { iLock.Wait(); DviService* service = 0; const TUint count = iDevice.ServiceCount(); for (TUint i=0; i<count; i++) { DviService& s = iDevice.Service(i); if (s.ServiceType().PathUpnp() == buf) { service = &s; break; } } iLock.Signal(); if (service == 0) { THROW(ReaderError); } DviProtocolUpnpServiceXmlWriter::Write(*service, *this, aResourceWriter); } } }
BOOL OnInitDialog (HWND, LPARAM) { _lostPasswordButton.Attach(GetDlgItem(IDC_RETRIEVE)); _signupButton.Attach(GetDlgItem(IDC_SIGNUP)); _userID.Attach(GetDlgItem(IDC_USERID)); _protocols.Attach(GetDlgItem(IDC_PROTOCOL)); // Attach presence image list to protocol combobox. IResourceManager* resMgr = ComponentManager::Get<IResourceManager>(); Assert(resMgr != 0); if(resMgr != 0) { if(HIMAGELIST imageList = resMgr->GetImageList()) _protocols.SetImageList(imageList); } // Can't change the protocol on an existing account. // It is just too messy to deal with at the moment. if(ThisAccount != 0) _protocols.EnableWindow(FALSE); // Populate account list const wchar_t** protocols = 0; if(IAccountManager* mgr = ComponentManager::Get<IAccountManager>()) protocols = mgr->GetProtocols(); for(int i = 0; protocols[i] != 0; i++) { int image = -1; if(resMgr != 0) image = resMgr->GetImageIndex(protocols[i]); COMBOBOXEXITEM item; item.mask = CBEIF_TEXT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE; item.iItem = -1; item.iImage = image; item.iSelectedImage = image; item.pszText = const_cast<wchar_t*>(protocols[i]); _protocols.InsertItem(&item); } // Select first protocol type if creating new protocol. if(ThisAccount == 0 && protocols[0] != 0) _protocols.SetCurSel(0); if(ThisAccount != 0) DoDataExchange(FALSE); UpdateButtons(); return TRUE; }
TextureDescription RenderingEngine::SetPngTexture(const string& filename) { //return _resourceManager->LoadPngImage2(filename); TextureDescription description = _resourceManager->LoadPngImage(filename); GLuint name; glGenTextures(1, &name); description.Name = name; glBindTexture(GL_TEXTURE_2D, name); //_currentTextureID = name; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); GLenum format = 0; switch (description.Format) { case TextureFormatGray: format = GL_LUMINANCE; break; case TextureFormatGrayAlpha: format = GL_LUMINANCE_ALPHA; break; case TextureFormatRgb: format = GL_RGB; break; case TextureFormatRgba: format = GL_RGBA; break; default: break; } GLenum type; switch (description.BitsPerComponent) { case 8: type = GL_UNSIGNED_BYTE; break; case 4: if (GL_RGBA == format) { type = GL_UNSIGNED_SHORT_4_4_4_4; break; } // intentionally fall through default: assert(!"Unsupported format."); } void* data = _resourceManager->GetImageData(); ivec2 size = description.Size; glTexImage2D(GL_TEXTURE_2D, 0, format, size.x, size.y, 0, format, type, data); _resourceManager->UnloadImage(); return description; // TextureDescription description = _resourceManager->LoadPngImage2(filename); // // return description; }
void ApplicationEngine::Initialize(int width, int height) { m_trackballRadius = width / 3; m_screenSize = ivec2(width, height); m_centerPoint = m_screenSize / 2; string path = m_resourceManager->GetResourcePath(); vector<ISurface*> surfaces(SurfaceCount); FLTetrahedronWithBoundsDivisions* FLTWBD = new FLTetrahedronWithBoundsDivisions(2.5, GL_LINES); surfaces[0] = new FLTetrahedronQuaternaryPhaseDiagram(path + "/nimninco.ABCD", 2.5, GL_TRIANGLES); surfaces[1] = FLTWBD; surfaces[2] = new FLText3D("ni", (FLTWBD->topVertex.Position) - (FLTWBD->translateOriginToCenterOfMassVector)); surfaces[3] = new FLText3D("mn", (FLTWBD->rightVertex.Position) - (FLTWBD->translateOriginToCenterOfMassVector)); surfaces[4] = new FLText3D("in", (FLTWBD->leftVertex.Position) - (FLTWBD->translateOriginToCenterOfMassVector)); surfaces[5] = new FLText3D("co", (FLTWBD->frontVertex.Position) - (FLTWBD->translateOriginToCenterOfMassVector)); m_renderingEngine->Initialize(surfaces); for (int i = 0; i < SurfaceCount; i++) delete surfaces[i]; }
void RenderingEngine::UploadImage(const TextureDescription& description, void* data) { GLenum format; switch (description.Format) { case TextureFormatRgb: format = GL_RGB; break; case TextureFormatRgba: format = GL_RGBA; break; } GLenum type = GL_UNSIGNED_BYTE; ivec2 size = description.Size; if (data == 0) { data = m_resourceManager->GetImageData(); glTexImage2D(GL_TEXTURE_2D, 0, format, size.x, size.y, 0, format, type, data); m_resourceManager->UnloadImage(); } else { glTexImage2D(GL_TEXTURE_2D, 0, format, size.x, size.y, 0, format, type, data); } }
GLuint RenderingEngine::CreateTexture(const string& file) { GLuint name; glGenTextures(1, &name); glBindTexture(GL_TEXTURE_2D, name); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); UploadImage(m_resourceManager->LoadImagePot(file)); return name; }
void ApplicationEngine::Initialize(int width, int height) { m_trackballRadius = width / 3; m_buttonSize.y = height / 10; m_buttonSize.x = 4 * m_buttonSize.y / 3; m_screenSize = ivec2(width, height - m_buttonSize.y); m_centerPoint = m_screenSize / 2; vector<ISurface*> surfaces(SurfaceCount); string path = m_resourceManager->GetResourcePath(); surfaces[0] = new ObjSurface(path + "/micronapalmv2.obj"); surfaces[1] = new ObjSurface(path + "/Ninja.obj"); surfaces[2] = new Torus(1.4, 0.3); surfaces[3] = new TrefoilKnot(1.8f); surfaces[4] = new KleinBottle(0.2f); surfaces[5] = new MobiusStrip(1); m_renderingEngine->Initialize(surfaces); for (int i = 0; i < SurfaceCount; i++) delete surfaces[i]; }
TextureDescription RenderingEngine::SetPvrTexture(const string& filename) { TextureDescription description = _resourceManager->LoadPvrImage(filename); GLuint name; glGenTextures(1, &name); description.Name = name; glBindTexture(GL_TEXTURE_2D, name); //_currentTextureID = name; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); unsigned char* data = (unsigned char*) _resourceManager->GetImageData(); int width = description.Size.x; int height = description.Size.y; int bitsPerPixel = 0; GLenum format; bool compressed = true; switch (description.Format) { case TextureFormatPvrtcRgba2: bitsPerPixel = 2; format = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; break; case TextureFormatPvrtcRgb2: bitsPerPixel = 2; format = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; break; case TextureFormatPvrtcRgba4: bitsPerPixel = 4; format = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; break; case TextureFormatPvrtcRgb4: bitsPerPixel = 4; format = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; break; default: compressed = false; break; } if (compressed) { for (int level = 0; level < description.MipCount; ++level) { GLsizei size = max(32, width * height * bitsPerPixel / 8); glCompressedTexImage2D(GL_TEXTURE_2D, level, format, width, height, 0, size, data); data += size; width >>= 1; height >>= 1; } } /*else { //cout << "Format:" << description.Format << endl; GLenum type; switch (description.Format) { case TextureFormatRgba: //cout << "GL_RGBA" << endl; assert(description.BitsPerComponent == 4); format = GL_RGBA; type = GL_UNSIGNED_SHORT_4_4_4_4; bitsPerPixel = 16; break; case TextureFormat565: //cout << "GL_RGB" << endl; format = GL_RGB; type = GL_UNSIGNED_SHORT_5_6_5; bitsPerPixel = 16; break; case TextureFormat5551: //cout << "GL_RGBA2" << endl; format = GL_RGBA; type = GL_UNSIGNED_SHORT_5_5_5_1; bitsPerPixel = 16; break; default: break; } for (int level = 0; level < description.MipCount; ++level) { GLsizei size = width * height * bitsPerPixel / 8; glTexImage2D(GL_TEXTURE_2D, level, format, width, height, 0, format, type, data); data += size; width >>= 1; height >>= 1; } }*/ _resourceManager->UnloadImage(); return description; }
void RenderingEngine::Initialize(const vector<ISurface*>& surfaces) { vector<ISurface*>::const_iterator surface; for (surface = surfaces.begin(); surface != surfaces.end(); ++surface) { // Create the VBO for the vertices. vector<float> vertices; unsigned char vertexFlags = VertexFlagsNormals | VertexFlagsTexCoords; (*surface)->GenerateVertices(vertices, vertexFlags); GLuint vertexBuffer; glGenBuffers(1, &vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(vertices[0]), &vertices[0], GL_STATIC_DRAW); // Create a new VBO for the indices if needed. int indexCount = (*surface)->GetTriangleIndexCount(); GLuint indexBuffer; if (!m_drawables.empty() && indexCount == m_drawables[0].IndexCount) { indexBuffer = m_drawables[0].IndexBuffer; } else { vector<GLushort> indices(indexCount); (*surface)->GenerateTriangleIndices(indices); glGenBuffers(1, &indexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * sizeof(GLushort), &indices[0], GL_STATIC_DRAW); } Drawable drawable = { vertexBuffer, indexBuffer, indexCount}; m_drawables.push_back(drawable); } // Extract width and height from the color buffer. int width, height; glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width); glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height); // Create a depth buffer that has the same size as the color buffer. glGenRenderbuffersOES(1, &m_depthRenderbuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_depthRenderbuffer); glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height); // Create the framebuffer object. GLuint framebuffer; glGenFramebuffersOES(1, &framebuffer); glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, m_colorRenderbuffer); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, m_depthRenderbuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_colorRenderbuffer); void* pixels; ivec2 size; // Load the background texture. glGenTextures(1, &m_backgroundTexture); glBindTexture(GL_TEXTURE_2D, m_backgroundTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); m_resourceManager->LoadPngImage("Background"); pixels = m_resourceManager->GetImageData(); size = m_resourceManager->GetImageSize(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size.x, size.y, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); m_resourceManager->UnloadImage(); // Load the checkboard texture. glGenTextures(1, &m_gridTexture); glBindTexture(GL_TEXTURE_2D, m_gridTexture); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); m_resourceManager->LoadPngImage("Checkerboard"); pixels = m_resourceManager->GetImageData(); size = m_resourceManager->GetImageSize(); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, size.x, size.y, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels); m_resourceManager->UnloadImage(); // Set up various GL state. glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); // Set up the material properties. vec4 specular(0.5f, 0.5f, 0.5f, 1); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular.Pointer()); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50.0f); m_translation = mat4::Translate(0, 0, -7); }
unique_ptr<GameScene> GameScene::LoadFromFile(string const& name, IResourceManager& resourceManager) { unique_ptr<GameScene> scene(new GameScene()); map<string, shared_ptr<Mesh> > meshCache; ScnParser scnParser(name); // FIXME: this creation requests should be routed to global factory finally scnParser.OnStaticObject = [&](StaticObjectDesc const& staticObjectDesc) { auto iter = meshCache.find(staticObjectDesc.fileName); if (iter == meshCache.end()) { string meshFileName = staticObjectDesc.fileName; meshFileName.append(".objm"); meshCache[staticObjectDesc.fileName] = Mesh::CreateFromObj(meshFileName); assert(meshCache[staticObjectDesc.fileName].use_count() == 1); } scene->AddStaticObject(unique_ptr<StaticObject>(new StaticObject(resourceManager.CompileMesh(*meshCache[staticObjectDesc.fileName]), staticObjectDesc.worldMatrix))); }; scnParser.OnCamera = [&](CameraDesc const& cameraDesc) { unique_ptr<QuaternionCamera> camera(new QuaternionCamera()); camera->SetFrustum(cameraDesc.frustum); camera->LookAt(cameraDesc.pos, cameraDesc.at, cameraDesc.up); scene->AddCamera(cameraDesc.tag, move(camera)); if (cameraDesc.bActive) { scene->SetActiveCamera(cameraDesc.tag); } }; scnParser.OnPointLight = [&](PointLightDesc const& pointLightDesc) { unique_ptr<PointLight> light(new PointLight()); light->SetPosition(pointLightDesc.pos); light->SetColor(pointLightDesc.color); light->SetCastShadow(pointLightDesc.bCastShadow); scene->AddPointLight(std::move(light)); }; scnParser.OnSpotLight = [&](SpotLightDesc const& spotLightDesc) { unique_ptr<SpotLight> spotLight(new SpotLight()); spotLight->SetPosition(spotLightDesc.pos); spotLight->SetDirection(spotLightDesc.dir); spotLight->SetColor(spotLightDesc.color); spotLight->SetAngles(spotLightDesc.innerAngle, spotLightDesc.outerAngle); spotLight->SetCastShadow(spotLightDesc.bCastShadow); scene->AddSpotLight(move(spotLight)); }; scnParser.Parse(); scene->Init(resourceManager); return scene; }
void RenderingEngine::Initialize(const vector<ISurface*>& surfaces) { vector<ISurface*>::const_iterator surface; for (surface = surfaces.begin(); surface != surfaces.end(); ++surface) { // Create the VBO for the vertices. vector<float> vertices; (*surface)->GenerateVertices(vertices, VertexFlagsNormals|VertexFlagsTexCoords); GLuint vertexBuffer; glGenBuffers(1, &vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(vertices[0]), &vertices[0], GL_STATIC_DRAW); // Create a new VBO for the indices if needed. int indexCount = (*surface)->GetTriangleIndexCount(); GLuint indexBuffer; if (!m_drawables.empty() && indexCount == m_drawables[0].IndexCount) { indexBuffer = m_drawables[0].IndexBuffer; } else { vector<GLushort> indices(indexCount); (*surface)->GenerateTriangleIndices(indices); glGenBuffers(1, &indexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * sizeof(GLushort), &indices[0], GL_STATIC_DRAW); } int lineIndexCount = (*surface)->GetLineIndexCount(); GLuint lineIndexBuffer; vector<GLushort> lineIndices(lineIndexCount); (*surface)->GenerateLineIndices(lineIndices); glGenBuffers(1, &lineIndexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, lineIndexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, lineIndexCount * sizeof(GLushort), &lineIndices[0], GL_STATIC_DRAW); Drawable drawable = { vertexBuffer, indexBuffer , indexCount}; m_drawables.push_back(drawable); } // Extract width and height. int width, height; glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width); glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height); // Create a depth buffer that has the same size as the color buffer. glGenRenderbuffers(1, &m_depthRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, m_depthRenderbuffer); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height); // Create the framebuffer object. GLuint framebuffer; glGenFramebuffers(1, &framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_colorRenderbuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, m_colorRenderbuffer); // Create the GLSL program. GLuint program = BuildProgram(SimpleVertexShader, SimpleFragmentShader); glUseProgram(program); // Extract the handles to attributes and uniforms. m_attributes.Position = glGetAttribLocation(program, "Position"); m_attributes.Normal = glGetAttribLocation(program, "Normal"); m_attributes.Diffuse = glGetAttribLocation(program, "DiffuseMaterial"); m_attributes.TextureCoord = glGetAttribLocation(program, "TextureCoord"); m_uniforms.Projection = glGetUniformLocation(program, "Projection"); m_uniforms.Modelview = glGetUniformLocation(program, "Modelview"); m_uniforms.NormalMatrix = glGetUniformLocation(program, "NormalMatrix"); m_uniforms.LightPosition = glGetUniformLocation(program, "LightPosition"); m_uniforms.AmbientMaterial = glGetUniformLocation(program, "AmbientMaterial"); m_uniforms.SpecularMaterial = glGetUniformLocation(program, "SpecularMaterial"); m_uniforms.Shininess = glGetUniformLocation(program, "Shininess"); // Set up some default material parameters. glUniform3f(m_uniforms.AmbientMaterial, 0.04f, 0.04f, 0.04f); glUniform3f(m_uniforms.SpecularMaterial, 0.5, 0.5, 0.5); glUniform1f(m_uniforms.Shininess, 50); // Set the active sampler to stage 0. Not really necessary since the uniform // defaults to zero anyway, but good practice. glActiveTexture(GL_TEXTURE0); glUniform1i(m_uniforms.Sampler, 0); // Load the texture. glGenTextures(1,&m_gridTexture); glBindTexture(GL_TEXTURE_2D, m_gridTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); m_resourceManager = CreateResourceManager(); m_resourceManager->LoadPngImage("Grid16.png"); void* pixels = m_resourceManager->GetImageData(); ivec2 size = m_resourceManager->GetImageSize(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.x, size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); m_resourceManager->UnloadImage(); // Initialize various state. glEnableVertexAttribArray(m_attributes.Position); glEnableVertexAttribArray(m_attributes.Normal); glEnableVertexAttribArray(m_attributes.TextureCoord); glEnable(GL_DEPTH_TEST); // Set up transforms. m_translation = mat4::Translate(0, 0, -7); }
// OpenConnection is called by clients to initiate work with the resource manager under a specified transaction // The transaction is passed in as a transaction token, to show how transactions objects can be serialized across // processes bool DTCResourceManager::OpenConnection(byte* transactionToken, ULONG tokenSize) { std::cout << "The resource manager received an OpenConnection request. Enlisting in the transaction..." << std::endl; ITransactionReceiverFactory* pTxReceiverFactory = NULL; HRESULT hr = DtcGetTransactionManager( NULL, // [in] char * pszHost, NULL, // [in] char * pszTmName, IID_ITransactionReceiverFactory, // [in] REFIID riid, 0, // [in] DWORD dwReserved1, 0, // [in] WORD wcbVarLenReserved2, (void *)NULL, // [in] void * pvVarDataReserved2, (void **)&pTxReceiverFactory // [out] void ** ppv ); if (FAILED (hr)) { std::cout << "DtcGetTransactionManager for ITransactionReceiverFactory failed: Error # " << std::hex << hr << std::endl; goto cleanup; } ITransactionReceiver* pTxReceiver = NULL; hr = pTxReceiverFactory->Create(&pTxReceiver); if (FAILED(hr)) { std::cout << "pTxReceiverFactory->Create failed: Error # " << std::hex << hr << std::endl; goto cleanup; } ITransaction* pTx = NULL; hr = pTxReceiver->UnmarshalPropagationToken(tokenSize, transactionToken, &pTx); if (FAILED(hr)) { std::cout << "pTxReceiver->UnmarshalPropagationToken failed: Error # " << std::hex << hr << std::endl; goto cleanup; } XACTUOW uow; LONG isoLevel; hr = _pRMManager->Enlist(pTx, this, &uow, &isoLevel, &_pEnlist); if (FAILED(hr)) { std::cout << "pRMManager->Enlist failed: Error # " << std::hex << hr << std::endl; goto cleanup; } cleanup: if( pTx ) { pTx->Release(); pTx = NULL; } if( pTxReceiver ) { pTxReceiver->Release(); pTxReceiver = NULL; } if( pTxReceiverFactory ) { pTxReceiverFactory->Release(); pTxReceiverFactory = NULL; } if( FAILED(hr) ) { std::cout << "OpenConnection failed" << std::endl; return false; } return true; }