Exemplo n.º 1
0
void FBOBlitTest::prepare()
{
    BlitTest::prepare();

    glTexImage2D(GL_TEXTURE_2D, 0, m_format, m_width, m_height, 0, m_format, m_type, NULL);
    ASSERT_GL();

    glGenRenderbuffers(1, &m_depthbuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, m_depthbuffer);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, m_width, m_height);
    ASSERT_GL();

    glGenFramebuffers(1, &m_framebuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0);
    if (m_useDepth)
    {
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                                  GL_RENDERBUFFER, m_depthbuffer);
    }
    ASSERT_GL();

    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    ASSERT(status == GL_FRAMEBUFFER_COMPLETE);

    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);
    glViewport(0, 0, m_width, m_height);
    fillTexture();
    glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glBindRenderbuffer(GL_RENDERBUFFER, 0);
    ASSERT_GL();
}
 void drawTexture(bool asSRGB, GLint x, GLint y, GLsizei width,
         GLsizei height) {
     ASSERT_NO_FATAL_FAILURE(fillTexture(asSRGB));
     glViewport(x, y, width, height);
     ASSERT_EQ(GL_NO_ERROR, glGetError());
     glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
     ASSERT_EQ(GL_NO_ERROR, glGetError());
 }
Exemplo n.º 3
0
/*
	loadTexture - This method loads a texture with a path/file name key into
	the GPU memory. It registers the path/file name in the wchar_t table and
	returns the corresponding index. Once the texture is created, it loads
	it into the map.
*/
unsigned int DirectXTextureManager::loadTexture(wstring key)
{
	LPDIRECT3DTEXTURE9 textureToLoad;
	unsigned int result = fillTexture(key, &textureToLoad);
	if (result == S_OK)
	{
		// PUT OUR LOADED TEXTURE INTO OUR MAP
		textures[key.c_str()] = textureToLoad;

		// NOW PUT THE KEY IN THE wchar_t TABLE
		int indexOfTexture = wstringTable.putWStringInTable(key.c_str());

		// AND RETURN THE TEXTURE'S ID
		return indexOfTexture;
	}
	return -1;
}
Exemplo n.º 4
0
void init(void) {
    // Starting services
    sf2d_init();
    sf2d_set_vblank_wait(0);
    sftd_init();
    srvInit();
    aptInit();
    hidInit();
    audio_init();
    //romfsInit();

    // Configuring the right font to use (8bitoperator), and its proprieties
    font = sftd_load_font_file("font/eightbit.ttf");

    // Configuring graphics in general (images, textures, etc)
    sf2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF));

    /* Load Frisk textures
       Loop over every element in tex_arr_friskWalk and load the PNG buffer. */

    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            tex_arr_friskWalk[i][j] = loadTexture(friskFilenames[i][j]);
        }
    }

    room_init();

    // Reusing 'i' from above.
    // Load room textures.
    for (int i = 0; i < 3; ++i) fillTexture(&rooms[i].bg);

    // TODO: Add actual save loading logic. For now, just assume this room.
    player_pos = rooms[room].exits[0].entrance;

    // Play music
    home = sound_create(BGM);
    if (home != NULL) audio_load_ogg("sound/music/house1.ogg", home);
    else home->status = -1;

    timerStep();
}
Exemplo n.º 5
0
void RenderTexture::setData(uint32* dataRGBA32, unsigned int height, unsigned int width)
{
	Assert(dataRGBA32);
	Assert(height > 0);
	Assert(width > 0);
	if (!mDxTexture)
	{
		// uninitialized buffer
		createTexture(dataRGBA32, height, width);
	}
	else if (mDataWidth == width && mDataHeight == height)
	{
		releaseTexture();
		createTexture(dataRGBA32, height, width);
	}
	else
	{
		fillTexture(dataRGBA32);
	}
}
Exemplo n.º 6
0
void RenderTexture::createTexture(uint32* dataRGBA32, unsigned int height, unsigned int width)
{
	mDataHeight = height;
	mDataWidth = width;

	mData = new uint32[mDataHeight*mDataWidth];
	Memory::Memcopy(mData, dataRGBA32, mDataHeight*mDataWidth*sizeof(uint32));

	D3D11_TEXTURE2D_DESC textureDesc;
	textureDesc.Height = height;
	textureDesc.Width = width;
	textureDesc.MipLevels = 0;
	textureDesc.ArraySize = 1;
	textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	textureDesc.SampleDesc.Count = 1;
	textureDesc.SampleDesc.Quality = 0;
	textureDesc.Usage = D3D11_USAGE_DEFAULT;
	textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
	textureDesc.CPUAccessFlags = 0;
	textureDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;

	DX_GetDevice(dxdev);
	DX_SafeCall(dxdev->CreateTexture2D(&textureDesc, NULL, &mDxTexture));

	DX_GetDeviceContext(dxctx);
	UINT rowPitch = mDataWidth * sizeof(uint32);
	dxctx->UpdateSubresource(mDxTexture, 0, NULL, mData, rowPitch, 0);

	D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;
	shaderResourceViewDesc.Format = textureDesc.Format;
	shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
	shaderResourceViewDesc.Texture2D.MipLevels = UINT(-1);
	DX_SafeCall(dxdev->CreateShaderResourceView(mDxTexture, &shaderResourceViewDesc, &mDxTextureView));

	fillTexture(dataRGBA32);
}
Exemplo n.º 7
0
void QTextureGlyphCache::fillInPendingGlyphs()
{
    if (m_pendingGlyphs.isEmpty())
        return;

    int requiredHeight = m_h;
    int requiredWidth = m_w; // Use a minimum size to avoid a lot of initial reallocations
    {
        QHash<GlyphAndSubPixelPosition, Coord>::iterator iter = m_pendingGlyphs.begin();
        while (iter != m_pendingGlyphs.end()) {
            Coord c = iter.value();
            requiredHeight = qMax(requiredHeight, c.y + c.h);
            requiredWidth = qMax(requiredWidth, c.x + c.w);
            ++iter;
        }
    }

    if (isNull() || requiredHeight > m_h || requiredWidth > m_w) {
        if (isNull())
            createCache(qt_next_power_of_two(requiredWidth), qt_next_power_of_two(requiredHeight));
        else
            resizeCache(qt_next_power_of_two(requiredWidth), qt_next_power_of_two(requiredHeight));
    }

    {
        QHash<GlyphAndSubPixelPosition, Coord>::iterator iter = m_pendingGlyphs.begin();
        while (iter != m_pendingGlyphs.end()) {
            GlyphAndSubPixelPosition key = iter.key();
            fillTexture(iter.value(), key.glyph, key.subPixelPosition);

            ++iter;
        }
    }

    m_pendingGlyphs.clear();
}
Exemplo n.º 8
0
bool DirectXTextureManager::loadTileSetFromTexture(Game *game,
	wstring dir,
	wstring sourceImageFileName,
	int tileWidth,
	int tileHeight)
{
	// CONVERT THE FILE NAME INTO A WINDOW LONG CHAR wchar_t (LPCWSTR)
	wstring sourcePath = dir + sourceImageFileName;

	LPDIRECT3DTEXTURE9 textureToDivide;
	LPDIRECT3DSURFACE9 surfaceToDivide;
	//DXLoad
	//D3DXLoadSurfaceFromMemory()
	unsigned int result = fillTexture(sourcePath, &textureToDivide);
	textureToDivide->GetSurfaceLevel(0, &surfaceToDivide);//~15 seconds
	if (result != S_OK) return false;

	// DETERMINE THE NUMBER OF TILE ROWS AND COLUMNS
	D3DSURFACE_DESC surfaceDesc;
	surfaceToDivide->GetDesc(&surfaceDesc);
	int textureWidth = surfaceDesc.Width;
	int textureHeight = surfaceDesc.Height;
	int columns = textureWidth / tileWidth;
	int rows = textureHeight / tileHeight;
	DirectXGraphics *dxg = (DirectXGraphics*)graphics;

	LPDIRECT3DDEVICE9 graphicsDevice = ((DirectXGraphics*)graphics)->getGraphicsDevice();

	// THE TILE SET IMAGE LOADED SUCCESSFULLY, SO LET'S CUT IT UP
	// MAYBE IF IM FEELING CRAZY LATER ILL MULTI THREAD THIS
	for (int row = 0; row < rows; row++)
	{
		for (int column = 0; column < columns; column++)
		{
			LPDIRECT3DTEXTURE9 extractedTexture;
			LPDIRECT3DSURFACE9 extractedSurface;
			result = graphicsDevice->CreateRenderTarget(tileWidth,
				tileHeight,
				D3DFMT_A8R8G8B8,
				D3DMULTISAMPLE_NONE, 0, false, &extractedSurface, NULL);
			if (result != S_OK) return false;

			RECT sourceRect;
			sourceRect.left = column * tileWidth;
			sourceRect.right = tileWidth + (column * tileWidth) - 1;
			sourceRect.top = row * tileHeight;
			sourceRect.bottom = tileHeight + (row * tileHeight) - 1;

			graphicsDevice->StretchRect(surfaceToDivide, &sourceRect, extractedSurface, NULL, D3DTEXF_NONE);

			// BUILD A UNIQUE FILE NAME FOR THIS TEXTURE
			wstring textureFilename = sourceImageFileName;

			unsigned int id = wstringTable.getNumWStringsInTable();
			wchar_t dot = '.';
			int dotIndex = textureFilename.rfind(dot);
			textureFilename = textureFilename.substr(0, dotIndex);
			wstringstream idWss;
			idWss << id;
			wstring idText;
			idWss >> idText;
			textureFilename = textureFilename + idText + L".png";
			textureFilename = wstring(dir.begin(), dir.end()) + textureFilename;

			//D3DXCreateTextureFromFile()
			//D3DxCreateTexture
			HRESULT result = D3DXCreateTexture(graphicsDevice, tileWidth, tileHeight, 1, D3DPOOL_DEFAULT, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &extractedTexture);
			if (result != S_OK) return false;
			LPDIRECT3DSURFACE9 t;
			extractedTexture->GetSurfaceLevel(0, &t);
			D3DXLoadSurfaceFromSurface(t, NULL, NULL, extractedSurface, NULL, NULL, D3DX_FILTER_NONE, 0);
					

			// ADD IT TO THE STRING TABLE
			wstringTable.putWStringInTable(textureFilename);

			// AND ADD IT TO THE TEXTURES
			textures[textureFilename] = extractedTexture;
			extractedSurface->Release();
			t->Release();
		}
	}
	surfaceToDivide->Release();
	textureToDivide->Release();
	return true;
}
Exemplo n.º 9
0
// Generate the texture for error display
void Error3DViewerWidget::genErrorTextures() 
{
  static const GLint internalformat = GL_R3_G3_B2;
  GLubyte *texture;
  GLint tw,max_n;
  QString tmps;
  int i;

  // Only in error mapping mode and if not disabled
  if (!texture_enabled) 
    return;
  makeCurrent(); // make sure we use the correct GL context
  // Allocate texture names (IDs) if not present
  if (etex_id == NULL) {
    etex_id = (GLuint*) xa_malloc(sizeof(*etex_id)*model->mesh->num_faces);
    etex_sz = (int*) xa_malloc(sizeof(*etex_sz)*model->mesh->num_faces);
    glGenTextures(model->mesh->num_faces,etex_id);
  }
  // Get maximum texture size
  max_n = 0;
  for (i=0; i<model->mesh->num_faces; i++) {
    if (max_n < model->fe[i].sample_freq) max_n = model->fe[i].sample_freq;
  }
  max_n = 1<<ceilLog2(max_n); // round (towards infinity) to power of two
  // Test if OpenGL implementation can deal with maximum texture size
  // Unfortunately GL_PROXY_TEXTURE_2D fails on IRIX 6.2 for some SGI
  // machines, so use older GL_MAX_TEXTURE_SIZE method.
  glGetIntegerv(GL_MAX_TEXTURE_SIZE,&tw);
  checkGLErrors("error texture size check");
  if (tw < max_n) {
    tmps.sprintf("The OpenGL implementation does not support\n"
                 "the required texture size (%ix%i).\n"
                 "Using plain white color",max_n,max_n);
    QMessageBox::critical(this,"OpenGL texture size exceeded",tmps);
    // Displaying another window can change the current GL context 
    makeCurrent();
    for (i=0; i<model->mesh->num_faces; i++) {
      etex_sz[i] = 1; // avoid having divide by zero texture coords
    }
    return;
  }
  // What follows is a potentially slow operation
  QApplication::setOverrideCursor(Qt::waitCursor);
  // Allocate temporary texture storage
  texture = (GLubyte*) xa_malloc(sizeof(*texture)*3*(max_n+2)*(max_n+2));
  glPixelStorei(GL_UNPACK_ALIGNMENT,1); /* pixel rows aligned on bytes only */
  for (i=0; i<model->mesh->num_faces; i++) {
    glBindTexture(GL_TEXTURE_2D,etex_id[i]);
    etex_sz[i] = fillTexture(&(model->fe[i]),texture);
    glTexImage2D(GL_TEXTURE_2D,0,internalformat,etex_sz[i]+2,etex_sz[i]+2,1,
                 GL_RGB,GL_UNSIGNED_BYTE,texture);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
    // Default GL_TEXTURE_MIN_FILTER requires mipmaps!
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  }
  checkGLErrors("error texture generation");
  free(texture);
  QApplication::restoreOverrideCursor();
}
/** Executes test iteration.
 *
 *  @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
 */
tcu::TestNode::IterateResult TextureFilterAnisotropicDrawingTestCase::iterate()
{
	const glw::Functions& gl = m_context.getRenderContext().getFunctions();

	bool result = true;

	GLfloat maxAnisoDegree = 2.0;

	gl.getFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisoDegree);
	GLU_EXPECT_NO_ERROR(gl.getError(), "getFloatv");

	std::vector<GLfloat> anisoVec;
	anisoVec.push_back(1.0f);
	anisoVec.push_back(2.0f);
	if (maxAnisoDegree > 2.0f)
		anisoVec.push_back(maxAnisoDegree);

	for (deUint32 iTarget = 0; iTarget < m_supportedTargets.size(); ++iTarget)
	{
		GLenum target = m_supportedTargets[iTarget];

		for (deUint32 iFormat = 0; iFormat < m_supportedInternalFormats.size(); ++iFormat)
		{
			GLenum format = m_supportedInternalFormats[iFormat];

			// Generate texture
			generateTexture(gl, target);

			// Fill texture with strips pattern
			fillTexture(gl, target, format);

			// Draw scene
			GLuint lastPoints = 0xFFFFFFFF;
			for (deUint32 i = 0; i < anisoVec.size(); ++i)
			{
				GLfloat aniso = anisoVec[i];

				if (result)
					result = result && drawTexture(gl, target, aniso);

				// Verify result
				if (result)
				{
					GLuint currentPoints = verifyScene(gl);

					if (lastPoints <= currentPoints)
					{
						m_testCtx.getLog()
							<< tcu::TestLog::Message
							<< "Anisotropy verification failed (lastPoints <= currentPoints) for "
							<< "anisotropy: " << aniso << ", "
							<< "target: " << glu::getTextureTargetName(target) << ", "
							<< "internalFormat: " << glu::getUncompressedTextureFormatName(format) << ", "
							<< "lastPoints: " << lastPoints << ", "
							<< "currentPoints: " << currentPoints << tcu::TestLog::EndMessage;

						result = false;
						break;
					}

					lastPoints = currentPoints;
				}
			}

			// Release texture
			releaseTexture(gl);

			if (!result)
			{
				// Stop loops
				iTarget = m_supportedTargets.size();
				iFormat = m_supportedInternalFormats.size();
			}
		}
	}

	if (result)
		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
	else
		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
	return STOP;
}
Exemplo n.º 11
0
bool DirectXTextureManager::loadTileSetFromTexture(	Game *game, 
													wstring dir,
													wstring sourceImageFileName,
													int tileWidth,
													int tileHeight,
													int spacing,
													int margin)
{
	// CONVERT THE FILE NAME INTO A WINDOW LONG CHAR wchar_t (LPCWSTR)
	wstring sourcePath = dir + sourceImageFileName;

	LPDIRECT3DTEXTURE9 textureToDivide;
	LPDIRECT3DSURFACE9 surfaceToDivide;

	unsigned int result = fillTexture(sourcePath, &textureToDivide);
	textureToDivide->GetSurfaceLevel(0, &surfaceToDivide);
	if (result != S_OK) return false;

	// DETERMINE THE NUMBER OF TILE ROWS AND COLUMNS
	D3DSURFACE_DESC surfaceDesc;
	surfaceToDivide->GetDesc(&surfaceDesc);
	int textureWidth = surfaceDesc.Width;
	int textureHeight = surfaceDesc.Height;
	int columns = (textureWidth-margin)/(tileWidth+spacing);
	int rows = (textureHeight-margin)/(tileHeight+spacing);
	DirectXGraphics *dxg = (DirectXGraphics*)graphics;

	LPDIRECT3DDEVICE9 graphicsDevice = ((DirectXGraphics*)graphics)->getGraphicsDevice();

	// THE TILE SET IMAGE LOADED SUCCESSFULLY, SO LET'S CUT IT UP
	for (int row = 0; row < rows; row++)
	{
		for (int column = 0; column < columns; column++)
		{
			LPDIRECT3DTEXTURE9 extractedTexture;
			LPDIRECT3DSURFACE9 extractedSurface;
			result = graphicsDevice->CreateRenderTarget(tileWidth,
					tileHeight,
					D3DFMT_A8R8G8B8,
					D3DMULTISAMPLE_NONE, 0, false, &extractedSurface, NULL);
			if (result != S_OK) return false;
	
			RECT sourceRect;
			sourceRect.left = (column * (tileWidth + spacing)) + margin;
			sourceRect.right = tileWidth + (sourceRect.left) - 1;
			sourceRect.top = (row * (tileHeight + spacing)) + margin;
			sourceRect.bottom = tileHeight + (sourceRect.top) - 1;
			
			graphicsDevice->StretchRect(surfaceToDivide, &sourceRect, extractedSurface, NULL, D3DTEXF_NONE);

			// BUILD A UNIQUE FILE NAME FOR THIS TEXTURE
			wstring textureFilename = sourceImageFileName;

			unsigned int id = wstringTable.getNumWStringsInTable();
			wchar_t dot = '.';
			int dotIndex = textureFilename.rfind(dot);
			textureFilename = textureFilename.substr(0, dotIndex);
			wstringstream idWss;
			idWss << id;
			wstring idText;
			idWss >> idText;
			textureFilename = textureFilename + idText + L".png";
			textureFilename = wstring(dir.begin(), dir.end()) + textureFilename;
				
			// LET'S PUT THE SURFACE IN AN IMAGE FILE
			D3DXSaveSurfaceToFileW(textureFilename.c_str(), D3DXIFF_PNG, extractedSurface, NULL, NULL); 
			D3DXIMAGE_INFO info;
			HRESULT result = D3DXGetImageInfoFromFile(textureFilename.c_str(), &info);
			if (result != S_OK) return false;

			// AND THEN LOAD IT BACK IN AS A TEXTURE
			result = D3DXCreateTextureFromFileEx(	graphicsDevice,		// GPU
													textureFilename.c_str(),			// BITMAP FILE PATH/NAME
													tileWidth,			// BITMAP IMAGE WIDTH
													tileHeight,		// BITMAP IMAGE HEIGHT
													1,					// MIP-MAP LEVELS (1 FOR NO CHAIN)
													D3DPOOL_DEFAULT,	// THE TYPE OF SURFACE (STANDARD)
													D3DFMT_UNKNOWN,		// SURFACE FORMAT (DEFAULT)
													D3DPOOL_DEFAULT,	// MEMORY CLASS FOR THE TEXTURE
													D3DX_DEFAULT,		// IMAGE FILTER
													D3DX_DEFAULT,		// MIP FILTER
													NULL,			// COLOR KEY
													&info,				// BITMAP FILE INFO
													NULL,				// COLOR PALETTE
													&extractedTexture );	// THE TEXTURE WE ARE CREATING AND LOADING					
			if (result != S_OK) return false;

			// ADD IT TO THE STRING TABLE
			wstringTable.putWStringInTable(textureFilename);

			// AND ADD IT TO THE TEXTURES
			textures[textureFilename] = extractedTexture;
		}
	}
	return true;
}