コード例 #1
0
ファイル: State.cpp プロジェクト: philipp-hammerer/angle
void State::detachTexture(const TextureMap &zeroTextures, GLuint texture)
{
    // Textures have a detach method on State rather than a simple
    // removeBinding, because the zero/null texture objects are managed
    // separately, and don't have to go through the Context's maps or
    // the ResourceManager.

    // [OpenGL ES 2.0.24] section 3.8 page 84:
    // If a texture object is deleted, it is as if all texture units which are bound to that texture object are
    // rebound to texture object zero

    for (TextureBindingMap::iterator bindingVec = mSamplerTextures.begin(); bindingVec != mSamplerTextures.end(); bindingVec++)
    {
        GLenum textureType = bindingVec->first;
        TextureBindingVector &textureVector = bindingVec->second;
        for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++)
        {
            BindingPointer<Texture> &binding = textureVector[textureIdx];
            if (binding.id() == texture)
            {
                auto it = zeroTextures.find(textureType);
                ASSERT(it != zeroTextures.end());
                // Zero textures are the "default" textures instead of NULL
                binding.set(it->second.get());
            }
        }
    }

    // [OpenGL ES 2.0.24] section 4.4 page 112:
    // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is
    // as if Texture2DAttachment had been called, with a texture of 0, for each attachment point to which this
    // image was attached in the currently bound framebuffer.

    if (mReadFramebuffer)
    {
        mReadFramebuffer->detachTexture(texture);
    }

    if (mDrawFramebuffer)
    {
        mDrawFramebuffer->detachTexture(texture);
    }
}
コード例 #2
0
void SlotMachine::Update(Canvas *_canvas) {
	Canvas *canvas = _canvas;
	if (state == SlotMachineState::sl_inProcess) {
		// Все ли барабаны остановлены
		bool allStoped = true;

		// Обновляем и проверяем состояние барабанов
		TypeObjectsMap::iterator wit; // Итератор для карты с барабанами

		// Проверяем состояние барабанов
		for (wit = wheelsMap.begin(); wit != wheelsMap.end(); ++wit) {
			if (wit->second->getState() == WheelState::_running) {
				wit->second->Update();
				allStoped = false;
			}
		}

		TypeObjectsMap::iterator bit; // Итератор для карты с кнопками

		// Все барабаны прекратили вращение
		if (allStoped) {
			bit = buttonsMap.find(ObjectRole::_start);
			if (bit != buttonsMap.end()) {
				Object *start = bit->second;
				if (start->getState() == ButtonState::_enabled) {
					// Закончили вращение. Возвращаемся в исходное состояние и проверяем результат
					if (result = CalcResult()) {
						showResultStartTime = currentTime = std::time(nullptr);
						state = SlotMachineState::sl_show_result;
						TextureMap * textureMap = canvas->getTextureMap();
						TextureMap::iterator it;
						resultTexture = nullptr;
						// Обработка результатов костыль
						switch (result) {
							case r_slash:
								it = textureMap->find(TextureRole::_w_slash);
								resultTexture = it->second;
								break;
							case r_center:
								it = textureMap->find(TextureRole::_w_center);
								resultTexture = it->second;
								break;
							case r_backslah:
								it = textureMap->find(TextureRole::_w_backslash);
								resultTexture = it->second;
								break;
						}

						resultTexture->ena = true;
					}
					else {
						state = SlotMachineState::sl_waiting;
						start->Update();
					}
				}
			}

		}
	}
	else if (state == SlotMachineState::sl_show_result) {
		currentTime = std::time(nullptr);
		int elapse = currentTime - showResultStartTime;

		if (elapse < SHOW_RESULT_DURATION) {
			//resultTexture->ena = true;
		}
		else {
			resultTexture->ena = false;
			state = SlotMachineState::sl_waiting;
			TypeObjectsMap::iterator bit;
			bit = buttonsMap.find(ObjectRole::_start);
			bit->second->Update();
		}
	}
}