Beispiel #1
0
Prism::Text::Text(const Font& aFont)
	: myFont(aFont)
	, myColor(1.f, 1.f, 1.f, 1.f)
{
	//from debugText
	myEffect = Engine::GetInstance()->GetEffectContainer()->GetEffect("Data/Resource/Shader/S_effect_font.fx");
	//myFont = aFont;
	//myCharSize = myFont->GetCharSize();
	//myCharSpacing = 17.f;
	myScale = { 1.f, 1.f };

	D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};

	InitInputLayout(vertexDesc, ARRAYSIZE(vertexDesc), "Text::InputLayout");
	InitVertexBuffer(sizeof(VertexPosUV), D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
	InitIndexBuffer();
	InitSurface("DiffuseTexture", myFont.GetTexture()->GetFileName());
	InitBlendState("Text::BlendState");

	ZeroMemory(myInitData, sizeof(myInitData));

	myVertices.Init(1024);
	myIndices.Init(1024);
}
Beispiel #2
0
	Terrain::Terrain(const std::string& aHeightMapPath, const std::string& aTexturePath
			, const CU::Vector2<float>& aSize, float aHeight, const CU::Matrix44<float>& aOrientation)
		: myHeightMap(HeightMapFactory::Create(aHeightMapPath.c_str()))
		, mySize(aSize)
		, myHeight(aHeight)
		, myOrientation(aOrientation)
		, myVertexFormat(4)
	{
		myFileName = aTexturePath;

		myEffect = Engine::GetInstance()->GetEffectContainer()->GetEffect("Data/Resource/Shader/S_effect_skybox.fx");
		D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
		{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		};



		InitInputLayout(vertexDesc, ARRAYSIZE(vertexDesc), "Terrain::InputLayout");
		InitVertexBuffer(sizeof(VertexPosNormUV), D3D11_USAGE_IMMUTABLE, 0);

		InitIndexBuffer();
		InitSurface("DiffuseTexture", myFileName);
		InitBlendState("Terrain::BlendState");

		ZeroMemory(myInitData, sizeof(myInitData));

		CreateVertices();
	}
Beispiel #3
0
void Prism::Sprite::ResizeTexture(ID3D11Texture2D* aSrcTexture)
{
	myTexture->Release();
	myShaderView->Release();

	D3D11_TEXTURE2D_DESC desc;
	aSrcTexture->GetDesc(&desc);
	desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;

	HRESULT hr = Engine::GetInstance()->GetDevice()->CreateTexture2D(&desc, NULL, &myTexture);
	if (FAILED(hr))
	{
		DL_ASSERT("Failed to CreateTexture2D");
	}
	Engine::GetInstance()->SetDebugName(myTexture, "Sprite::myTexture");

	hr = Engine::GetInstance()->GetDevice()->CreateShaderResourceView(myTexture, NULL, &myShaderView);
	if (FAILED(hr))
	{
		DL_ASSERT("Failed to CopyFromD3DTexture");
	}
	Engine::GetInstance()->SetDebugName(myShaderView, "Sprite::myShaderView");

	CopyFromD3DTexture(aSrcTexture);

	mySurfaces.DeleteAll();
	InitSurface("DiffuseTexture", myShaderView);
}
Beispiel #4
0
Prism::Sprite::Sprite(const std::string& aFileName, const CU::Vector2<float>& aSpriteSize
		, const CU::Vector2<float>& aHotSpot)
	: mySize(aSpriteSize)
	, myHotspot(aHotSpot)
	, myTexture(nullptr)
	, myShaderView(nullptr)
{
	myFileName = aFileName;

	myEffect = Engine::GetInstance()->GetEffectContainer()->GetEffect("Data/Resource/Shader/S_effect_sprite.fx");
	myEffect->AddListener(this);

	D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};

	InitInputLayout(vertexDesc, ARRAYSIZE(vertexDesc), "Sprite::InputLayout");
	InitVertexBuffer(sizeof(VertexPosUV), D3D11_USAGE_IMMUTABLE, 0);
	InitIndexBuffer();
	InitSurface("DiffuseTexture", myFileName);
	InitBlendState("Sprite::BlendState");

	ZeroMemory(myInitData, sizeof(myInitData));

	CreateVertices();
}
bool
SharedDIBSurface::Attach(Handle aHandle, uint32_t aWidth, uint32_t aHeight,
                         bool aTransparent)
{
  nsresult rv = mSharedDIB.Attach(aHandle, aWidth, aHeight, aTransparent);
  if (NS_FAILED(rv) || !mSharedDIB.IsValid())
    return false;

  InitSurface(aWidth, aHeight, aTransparent);
  return true;
}
bool
SharedDIBSurface::Create(HDC adc, uint32_t aWidth, uint32_t aHeight,
                         bool aTransparent)
{
  nsresult rv = mSharedDIB.Create(adc, aWidth, aHeight, aTransparent);
  if (NS_FAILED(rv) || !mSharedDIB.IsValid())
    return false;

  InitSurface(aWidth, aHeight, aTransparent);
  return true;
}
bool NativeEngine::PrepareToRender() {
    do {
        // if we're missing a surface, context, or display, create them
        if (mEglDisplay == EGL_NO_DISPLAY || mEglSurface == EGL_NO_SURFACE || 
                mEglContext == EGL_NO_CONTEXT) {

            // create display if needed
            if (!InitDisplay()) {
                LOGE("NativeEngine: failed to create display.");
                return false;
            }

            // create surface if needed
            if (!InitSurface()) {
                LOGE("NativeEngine: failed to create surface.");
                return false;
            }

            // create context if needed
            if (!InitContext()) {
                LOGE("NativeEngine: failed to create context.");
                return false;
            }

            LOGD("NativeEngine: binding surface and context (display %p, surface %p, context %p)", 
                    mEglDisplay, mEglSurface, mEglContext);

            // bind them
            if (EGL_FALSE == eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
                LOGE("NativeEngine: eglMakeCurrent failed, EGL error %d", eglGetError());
                HandleEglError(eglGetError());
            }

            // configure our global OpenGL settings
            ConfigureOpenGL();
        }

        // now that we're sure we have a context and all, if we don't have the OpenGL 
        // objects ready, create them.
        if (!mHasGLObjects) {
            LOGD("NativeEngine: creating OpenGL objects.");
            if (!InitGLObjects()) {
                LOGE("NativeEngine: unable to initialize OpenGL objects.");
                return false;
            }
        }
    } while(0);

    // ready to render
    return true;
}
Beispiel #8
0
Prism::Sprite::Sprite(ID3D11Texture2D* aTexture, const CU::Vector2<float>& aSpriteSize
	, const CU::Vector2<float>& aHotSpot)
	: mySize(aSpriteSize)
	, myHotspot(aHotSpot)
	, myTexture(nullptr)
	, myShaderView(nullptr)
{
	myFileName = "Inited from ID3D11Texture";

	myEffect = Engine::GetInstance()->GetEffectContainer()->GetEffect("Data/Resource/Shader/S_effect_sprite.fx");
	myEffect->AddListener(this);

	D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};

	D3D11_TEXTURE2D_DESC desc;
	aTexture->GetDesc(&desc);
	desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;

	HRESULT hr = Engine::GetInstance()->GetDevice()->CreateTexture2D(&desc, NULL, &myTexture);
	if (FAILED(hr))
	{
		DL_ASSERT("Failed to CreateTexture2D");
	}
	Engine::GetInstance()->SetDebugName(myTexture, "Sprite::myTexture");

	hr = Engine::GetInstance()->GetDevice()->CreateShaderResourceView(myTexture, NULL, &myShaderView);
	if (FAILED(hr))
	{
		DL_ASSERT("Failed to CopyFromD3DTexture");
	}
	Engine::GetInstance()->SetDebugName(myShaderView, "Sprite::myShaderView");

	
	CopyFromD3DTexture(aTexture);

	InitInputLayout(vertexDesc, ARRAYSIZE(vertexDesc), "Sprite::InputLayout");
	InitVertexBuffer(sizeof(VertexPosUV), D3D11_USAGE_IMMUTABLE, 0);
	InitSurface("DiffuseTexture", myShaderView);
	InitIndexBuffer();
	InitBlendState("Sprite::BlendState");

	ZeroMemory(myInitData, sizeof(myInitData));

	CreateVertices();
}
Beispiel #9
0
void Graphics::CreateTiles(void)
{
	tiles = new SDL_Surface***[tileAmount];
	for (int t=0; t < tileAmount; ++t)
	{
		tiles[t] = new SDL_Surface**[paletteLines];
		for (int p=0; p < paletteLines; ++p)
		{
			tiles[t][p] = new SDL_Surface*[4];
			for (int f=0; f < 4; ++f)
			{
				tiles[t][p][f] = InitSurface(tileData[t][p][f], 8, 8, 16);
			}
		}
	}
}
Beispiel #10
0
void SwapChain::Initialize(void * WindowHandle, rhi::GfxSetting & gfxSetting)
{
	InitSurface(WindowHandle);
	VkPresentModeKHR swapchainPresentMode				= ChoosePresentMode();
	std::pair<VkFormat, VkColorSpaceKHR> chosenFormat	= ChooseFormat(gfxSetting);
	m_SelectedPresentQueueFamilyIndex					= ChooseQueueIndex();
	m_SwapchainExtent = { gfxSetting.Width, gfxSetting.Height };
	VkSurfaceCapabilitiesKHR surfProperties;
	K3D_VK_VERIFY(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(GetPhysicalDevice(), m_Surface, &surfProperties));
	m_SwapchainExtent = surfProperties.currentExtent;
	/*gfxSetting.Width = m_SwapchainExtent.width;
	gfxSetting.Height = m_SwapchainExtent.height;*/
	uint32 desiredNumBuffers = kMath::Clamp(
		gfxSetting.BackBufferCount, 
		surfProperties.minImageCount, 
		surfProperties.maxImageCount);
	m_DesiredBackBufferCount = desiredNumBuffers;
	InitSwapChain(m_DesiredBackBufferCount, chosenFormat, swapchainPresentMode, surfProperties.currentTransform);
	K3D_VK_VERIFY(fpGetSwapchainImagesKHR(GetRawDevice(), m_SwapChain, &m_ReserveBackBufferCount, nullptr));
	m_ColorImages.resize(m_ReserveBackBufferCount);
	K3D_VK_VERIFY(fpGetSwapchainImagesKHR(GetRawDevice(), m_SwapChain, &m_ReserveBackBufferCount, m_ColorImages.data()));
	gfxSetting.BackBufferCount = m_ReserveBackBufferCount;
	VKLOG(Info, "[SwapChain::Initialize] desired imageCount=%d, reserved imageCount = %d.", m_DesiredBackBufferCount, m_ReserveBackBufferCount);
}
Beispiel #11
0
void CBuild::MergeLM()
{
	vecDefl		Layer;
	vecDefl		deflNew;
	vecDefl		SEL;

	Status("Processing...");
	for (u32 light_layer=0; light_layer<pBuild->lights.size(); light_layer++)
	{
		// Select all deflectors, which contain this light-layer
		Layer.clear	();
		b_light*	L_base	= pBuild->lights[light_layer].original;
		for (int it=0; it<(int)g_deflectors.size(); it++)
		{
			if (g_deflectors[it].bMerged)				continue;
			if (0==g_deflectors[it].GetLayer(L_base))	continue;	
			Layer.push_back	(g_deflectors[it]);
		}
		if (Layer.empty())	continue;
		
		// Resort layer


		// Merge this layer
		while (Layer.size()) 
		{
			// Sort layer (by material and distance from "base" deflector)
			Deflector	= Layer[0];
			std::sort	(Layer.begin()+1,Layer.end(),cmp_defl);

			// Select first deflectors which can fit
			int maxarea = lmap_size*lmap_size*6;	// Max up to 6 lm selected
			int curarea = 0;
			for (it=1; it<(int)Layer.size(); it++)
			{
				int		defl_area	= Layer[it]->GetLayer(L_base)->Area();
				if (curarea + defl_area > maxarea) break;
				curarea		+=	defl_area;
				SEL.push_back(Layer[it]);
			}
			if (SEL.empty()) 
			{
				// No deflectors found to merge
				// Simply transfer base deflector to _new list
				deflNew.push_back(Deflector);
				g_deflectors.erase(g_deflectors.begin());
			} else {
				// Transfer rects
				SEL.push_back(Deflector);
				for (int K=0; K<(int)SEL.size(); K++)
				{
					_rect	T; 
					T.a.set	(0,0);
					T.b.set	(SEL[K]->lm.dwWidth+2*BORDER-1, SEL[K]->lm.dwHeight+2*BORDER-1);
					T.iArea = SEL[K]->iArea;
					selected.push_back	(T);
					perturb.push_back	(K);
				}
				
				// Sort by size decreasing and startup
				std::sort			(perturb.begin(),perturb.end(),cmp_rect);
				InitSurface			();
				int id				= perturb[0];
				_rect &First		= selected[id];
				_rect_register		(First,SEL[id],FALSE);
				best.push_back		(First);
				best_seq.push_back	(id);
				brect.set			(First);
				
				// Process 
				collected.reserve	(SEL.size());
				for (int R=1; R<(int)selected.size(); R++) 
				{
					int ID = perturb[R];
					if (_rect_place(selected[ID],SEL[ID])) 
					{
						brect.Merge			(collected.back());
						best.push_back		(collected.back());
						best_seq.push_back	(ID);
					}
					Progress(float(R)/float(selected.size()));
				}
				R_ASSERT	(brect.a.x==0 && brect.a.y==0);
				
				//  Analyze resuls
				clMsg("%3d / %3d - [%d,%d]",best.size(),selected.size(),brect.SizeX(),brect.SizeY());
				CDeflector*	pDEFL = new CDeflector();
				pDEFL->lm.bHasAlpha = FALSE;
				pDEFL->lm.dwWidth   = lmap_size;
				pDEFL->lm.dwHeight  = lmap_size;
				for (K = 0; K<(int)best.size(); K++) 
				{
					int			iRealIndex	= best_seq	[K];
					_rect&		Place		= best		[K];
					_point&		Offset		= Place.a;
					BOOL		bRotated;
					b_texture&	T			= SEL[iRealIndex]->lm;
					int			T_W			= (int)T.dwWidth	+ 2*BORDER;
					int			T_H			= (int)T.dwHeight	+ 2*BORDER;
					if (Place.SizeX() == T_W) {
						R_ASSERT(Place.SizeY() == T_H);
						bRotated = FALSE;
					} else {
						R_ASSERT(Place.SizeX() == T_H);
						R_ASSERT(Place.SizeY() == T_W);
						bRotated = TRUE;
					}
					
					// Merge
					pDEFL->Capture		(SEL[iRealIndex],Offset.x,Offset.y,Place.SizeX(),Place.SizeY(),bRotated);
					
					// Destroy old deflector
					vecDeflIt		OLD = std::find(g_deflectors.begin(),g_deflectors.end(),SEL[iRealIndex]);
					VERIFY			(OLD!=g_deflectors.end());
					g_deflectors.erase(OLD);
					xr_delete		(SEL[iRealIndex]);
				}
				pDEFL->Save			();
				deflNew.push_back	(pDEFL);
				
				// Cleanup
				SEL.clear			();
				collected.clear		();
				selected.clear		();
				perturb.clear		();
				best.clear			();
				best_seq.clear		();
				brect.iArea			= INT_MAX;
			}
			Progress(1.f-float(g_deflectors.size())/float(dwOldCount));
		}
	}
	
	R_ASSERT(g_deflectors.empty());
	g_deflectors = deflNew;
	clMsg	("%d lightmaps builded",g_deflectors.size());
}
Beispiel #12
0
//+------------------------------------------------------------------------
//
//  Member:     COffScreenContext::CreateDDSurface
//
//  Synopsis:   Create a DD surface with the specified dimensions and palette.
//
//-------------------------------------------------------------------------
BOOL COffScreenContext::CreateDDSurface(long width, long height, HPALETTE hpal)
{
	HRESULT hr = InitSurface();
	if(FAILED(hr))
	{
		return FALSE;
	}

	DDPIXELFORMAT* pPF = PixelFormat(_hdcWnd, _cBitsPixel);
	if(!pPF)
	{
		return FALSE;
	}

	DDSURFACEDESC ddsd;

	ddsd.dwSize = sizeof(ddsd);
	ddsd.ddpfPixelFormat = *pPF;
	ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT;
	ddsd.ddsCaps.dwCaps = DDSCAPS_DATAEXCHANGE|DDSCAPS_OWNDC;
	if(_fUse3D)
	{
		ddsd.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
	}
	ddsd.dwWidth = width;
	ddsd.dwHeight = height;
	hr = g_pDirectDraw->CreateSurface(&ddsd, &_pDDSurface, NULL);
	if(FAILED(hr))
	{
		return FALSE;
	}

	// set color table
	if(_cBitsPixel <= 8)
	{
		IDirectDrawPalette*	pDDPal;
		PALETTEENTRY*		pPal;
		PALETTEENTRY		pal256[256];
		long				cEntries;
		DWORD				pcaps;

		if(_cBitsPixel == 8)
		{
			cEntries = GetPaletteEntries(hpal, 0, 256, pal256);
			pPal = pal256;
			pcaps = DDPCAPS_8BIT;
		}
		else if(_cBitsPixel == 4)
		{
			cEntries = 16;
			pPal = g_pal16;
			pcaps = DDPCAPS_4BIT;
		}
		else if(_cBitsPixel == 1)
		{
			cEntries = 2;
			pPal = g_pal2;
			pcaps = DDPCAPS_1BIT;
		}
		else
		{
			Assert(0 && "invalid cBitsPerPixel");
			return FALSE;
		}

		// create and initialize a new DD palette
		hr = g_pDirectDraw->CreatePalette(pcaps|DDPCAPS_INITIALIZE, pPal, &pDDPal, NULL);
		if(SUCCEEDED(hr))
		{
			// attach the DD palette to the DD surface
			hr = _pDDSurface->SetPalette(pDDPal);
			pDDPal->Release();
		}
		if(FAILED(hr))
		{
			return FALSE;
		}
	}

	hr = _pDDSurface->GetDC(&_hdcMem);
	return SUCCEEDED(hr);
}
Beispiel #13
0
void AndroidEGL::ReInit()
{
	InitSurface(false);
}
Beispiel #14
0
void cxAndroid::onAppCmd(int8_t cmd)
{
    switch (cmd) {
        case APP_CMD_INIT_WINDOW:{
            InitSurface();
            break;
        }
        case APP_CMD_TERM_WINDOW:{
            animating = 0;
            DestroySurface();
            break;
        }
        case APP_CMD_INPUT_CHANGED:{
            break;
        }
        case APP_CMD_WINDOW_RESIZED:{
            cxEngine::Instance()->Layout(width, height);
            animating = true;
            break;
        }
        case APP_CMD_WINDOW_REDRAW_NEEDED:{
            break;
        }
        case APP_CMD_CONTENT_RECT_CHANGED:{
            break;
        }
        case APP_CMD_GAINED_FOCUS:{
            break;
        }
        case APP_CMD_LOST_FOCUS:{
            animating = false;
            break;
        }
        case APP_CMD_CONFIG_CHANGED:{
            break;
        }
        case APP_CMD_LOW_MEMORY:{
            cxEngine::Instance()->Warning();
            break;
        }
        case APP_CMD_START:{
            break;
        }
        case APP_CMD_RESUME:{
            cxEngine::Instance()->Resume();
            animating = true;
            break;
        }
        case APP_CMD_SAVE_STATE:{
            break;
        }
        case APP_CMD_PAUSE:{
            animating = false;
            cxEngine::Instance()->Pause();
            break;
        }
        case APP_CMD_STOP:{
            animating = false;
            break;
        }
        case APP_CMD_DESTROY:{
            animating = false;
            destroyReq = true;
            break;
        }
        default:{
            break;
        }
    }
}