Example #1
0
Surface Font::Render(const std::string & txt,
                     const Color & color,
                     bool cache)
{
  Surface surface;

  if (cache) {
    txt_iterator p = surface_text_table.find(txt);
    if( p == surface_text_table.end() ){
      if( surface_text_table.size() > 5 ){
        //SDL_FreeSurface( surface_text_table.begin()->second );
        surface_text_table.erase( surface_text_table.begin() );
      }
      surface = CreateSurface(txt, color);
      surface_text_table.insert( txt_sample(txt, surface) );
    } else {
      txt_iterator p2 = surface_text_table.find( txt );
      surface = p2->second;
    }
  } else {
    surface = CreateSurface(txt, color);
  }

  ASSERT( !surface.IsNull() );
  return surface;
}
Slab CreateSlab(GLsizei width, GLsizei height, int numComponents)
{
    Slab slab;
    slab.Ping = CreateSurface(width, height, numComponents);
    slab.Pong = CreateSurface(width, height, numComponents);
    return slab;
}
PPSurface CreatePPSurface(GLsizei width, GLsizei height, int Components)
{
	PPSurface ppsurface;
	ppsurface.Ping = CreateSurface(width, height, Components);
	ppsurface.Pong = CreateSurface(width, height, Components);
	
	return ppsurface;

}
CNullVideoRendererInputPin::CNullVideoRendererInputPin(CBaseRenderer *pRenderer, HRESULT *phr, LPCWSTR Name)
	: CRendererInputPin(pRenderer, phr, Name)
{
	HMODULE		hLib;

	CreateSurface();

	hLib = LoadLibrary (L"dxva2.dll");
	pfDXVA2CreateDirect3DDeviceManager9	= hLib ? (PTR_DXVA2CreateDirect3DDeviceManager9) GetProcAddress (hLib, "DXVA2CreateDirect3DDeviceManager9") : NULL;
	pfDXVA2CreateVideoService			= hLib ? (PTR_DXVA2CreateVideoService)           GetProcAddress (hLib, "DXVA2CreateVideoService") : NULL;


	if (hLib != NULL)
	{
		pfDXVA2CreateDirect3DDeviceManager9 (&m_nResetTocken, &m_pD3DDeviceManager);
	}

	// Initialize Device Manager with DX surface
	if (m_pD3DDev)
	{
		HRESULT hr;
		hr = m_pD3DDeviceManager->ResetDevice (m_pD3DDev, m_nResetTocken);
		hr = m_pD3DDeviceManager->OpenDeviceHandle(&m_hDevice);
	}
}
Example #5
0
void Surface::Set(const void* pixels, unsigned int width, unsigned int height, unsigned char bytes_per_pixel, bool amask0)
{
    FreeSurface(*this);

    switch(bytes_per_pixel)
    {
	case 1:
	    CreateSurface(width, height, 8, false);
	    LoadPalette();
	    Lock();
	    std::memcpy(surface->pixels, pixels, width * height);
	    Unlock();
	    break;

	default:
	{
	    u32 rmask, gmask, bmask, amask;
	    GetRGBAMask(bytes_per_pixel * 8, rmask, gmask, bmask, amask);
	    surface = SDL_CreateRGBSurfaceFrom(const_cast<void *>(pixels), width, height, 8 * bytes_per_pixel, width * bytes_per_pixel,
		rmask, gmask, bmask, (amask0 ? amask : 0));
	}
	break;
    }

    if(!surface)
	Error::Except(__FUNCTION__, SDL_GetError());
}
RageSurface *RageMovieTextureDriver_FFMpeg::AVCodecCreateCompatibleSurface( int iTextureWidth, int iTextureHeight, bool bPreferHighColor, int &iAVTexfmt, MovieDecoderPixelFormatYCbCr &fmtout )
{
	FixLilEndian();

	int iAVTexfmtIndex = FindCompatibleAVFormat( bPreferHighColor );
	if( iAVTexfmtIndex == -1 )
		iAVTexfmtIndex = FindCompatibleAVFormat( !bPreferHighColor );

	if( iAVTexfmtIndex == -1 )
	{
		/* No dice.  Use the first avcodec format of the preferred bit depth,
		 * and let the display system convert. */
		for( iAVTexfmtIndex = 0; AVPixelFormats[iAVTexfmtIndex].bpp; ++iAVTexfmtIndex )
			if( AVPixelFormats[iAVTexfmtIndex].bHighColor == bPreferHighColor )
				break;
		ASSERT( AVPixelFormats[iAVTexfmtIndex].bpp != 0 );
	}
	
	const AVPixelFormat_t *pfd = &AVPixelFormats[iAVTexfmtIndex];
	iAVTexfmt = pfd->pf;
	fmtout = pfd->YUV;

	LOG->Trace( "Texture pixel format: %i %i (%ibpp, %08x %08x %08x %08x)", iAVTexfmt, fmtout,
		pfd->bpp, pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3] );

	if( pfd->YUV == PixelFormatYCbCr_YUYV422 )
		iTextureWidth /= 2;

	return CreateSurface( iTextureWidth, iTextureHeight, pfd->bpp,
		pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3] );
}
Example #7
0
wxIDirectFBSurfacePtr wxIDirectFB::GetPrimarySurface()
{
    DFBSurfaceDescription desc;
    desc.flags = DSDESC_CAPS;
    desc.caps = DSCAPS_PRIMARY;
    return CreateSurface(&desc);
}
Example #8
0
MovieTexture_Null::MovieTexture_Null(RageTextureID ID) : RageMovieTexture(ID)
{
	LOG->Trace("MovieTexture_Null::MovieTexture_Null(ID)");
	texHandle = 0;

	RageTextureID actualID = GetID();

	actualID.iAlphaBits = 0;
	int size = 64;
	m_iSourceWidth = size;
	m_iSourceHeight = size;
	m_iImageWidth = size;
	m_iImageHeight = size;
	m_iTextureWidth = power_of_two(size);
	m_iTextureHeight = m_iTextureWidth;
	m_iFramesWide = 1;
	m_iFramesHigh = 1;

	CreateFrameRects();

	RagePixelFormat pixfmt = RagePixelFormat_RGBA4;
	if( !DISPLAY->SupportsTextureFormat(pixfmt) )
		pixfmt = RagePixelFormat_RGBA8;
	ASSERT( DISPLAY->SupportsTextureFormat(pixfmt) );

	const RageDisplay::RagePixelFormatDesc *pfd = DISPLAY->GetPixelFormatDesc( pixfmt );
	RageSurface *img = CreateSurface( size, size, pfd->bpp,
		pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3] );
	memset( img->pixels, 0, img->pitch*img->h );

	texHandle = DISPLAY->CreateTexture( pixfmt, img, false );

	delete img;
}
Example #9
0
HSURFACE CTextHelper::CreateSurfaceFromString (ILTClient* pClientDE, FONT* pFontDef, int strID, HLTCOLOR foreColor, HLTCOLOR backColor, LTBOOL bCropped, int nExtraX, int nExtraY)
{
	if (!pClientDE) return LTNULL;

	HLTFONT hFont = pClientDE->CreateFont (pFontDef->strFontName, 
										   pFontDef->nWidth,
										   pFontDef->nHeight,
										   pFontDef->bItalic,
										   pFontDef->bUnderline,
										   pFontDef->bBold);
	if (!hFont) return LTNULL;

	HSTRING hString = pClientDE->FormatString (strID);
	if (!hString)
	{
		pClientDE->DeleteFont (hFont);
		return LTNULL;
	}

	HSURFACE hSurface = CreateSurface (pClientDE, hFont, hString, foreColor, backColor, bCropped, nExtraX, nExtraY);

	pClientDE->DeleteFont (hFont);
	pClientDE->FreeString (hString);

	return hSurface;
}
void mitk::ImageToSurfaceFilter::GenerateData()
{
  mitk::Surface *surface = this->GetOutput();
  mitk::Image * image        =  (mitk::Image*)GetInput();
  if(image == NULL || !image->IsInitialized())
    mitkThrow() << "No input image set, please set an valid input image!";

  mitk::Image::RegionType outputRegion = image->GetRequestedRegion();

  int tstart=outputRegion.GetIndex(3);
  int tmax=tstart+outputRegion.GetSize(3); //GetSize()==1 - will aber 0 haben, wenn nicht zeitaufgeloest

  if ((tmax-tstart) > 0)
  {
    ProgressBar::GetInstance()->AddStepsToDo( 4 * (tmax - tstart)  );
  }


  int t;
  for( t=tstart; t < tmax; ++t)
  {
    vtkImageData *vtkimagedata =  image->GetVtkImageData(t);
    CreateSurface(t,vtkimagedata,surface,m_Threshold);
    ProgressBar::GetInstance()->Progress();
  }
}
Example #11
0
//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
    // Create the D3D object.
    if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
        return E_FAIL;

    // Set up the structure used to create the D3DDevice. Since we are now
    // using more complex geometry, we will create a device with a zbuffer.
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp, sizeof( d3dpp ) );
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

    // Create the D3DDevice
    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING | 
									  D3DCREATE_MULTITHREADED | 
									  D3DCREATE_FPU_PRESERVE, 
                                      &d3dpp, &g_pd3dDevice ) ) )
    {
        return E_FAIL;
    }
	if (FAILED(CreateSurface(SCREEN_WIDTH, SCREEN_HEIGHT))) 
		return E_FAIL;
    // Turn on the zbuffer
    g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );

    // Turn on ambient lighting 
    g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0xffffffff );

    return S_OK;
}
Example #12
0
CNullVideoRendererInputPin::CNullVideoRendererInputPin(CBaseRenderer* pRenderer, HRESULT* phr, LPCWSTR Name)
    : CRendererInputPin(pRenderer, phr, Name)
    , m_hDXVA2Lib(nullptr)
    , pfDXVA2CreateDirect3DDeviceManager9(nullptr)
    , pfDXVA2CreateVideoService(nullptr)
    , m_pD3DDev(nullptr)
    , m_pD3DDeviceManager(nullptr)
    , m_nResetToken(0)
    , m_hDevice(INVALID_HANDLE_VALUE)
{
    CreateSurface();

    m_hDXVA2Lib = LoadLibrary(L"dxva2.dll");
    if (m_hDXVA2Lib) {
        pfDXVA2CreateDirect3DDeviceManager9 = reinterpret_cast<PTR_DXVA2CreateDirect3DDeviceManager9>(GetProcAddress(m_hDXVA2Lib, "DXVA2CreateDirect3DDeviceManager9"));
        pfDXVA2CreateVideoService = reinterpret_cast<PTR_DXVA2CreateVideoService>(GetProcAddress(m_hDXVA2Lib, "DXVA2CreateVideoService"));
        pfDXVA2CreateDirect3DDeviceManager9(&m_nResetToken, &m_pD3DDeviceManager);
    }

    // Initialize Device Manager with DX surface
    if (m_pD3DDev) {
        m_pD3DDeviceManager->ResetDevice(m_pD3DDev, m_nResetToken);
        m_pD3DDeviceManager->OpenDeviceHandle(&m_hDevice);
    }
}
Example #13
0
WSERR WSurface::RestoreSurface()
{
	LPDIRECTDRAWSURFACE left_buffer=data->LeftBuffer;
	LPDIRECTDRAWSURFACE right_buffer=data->RightBuffer;

	HRESULT hr=DD_OK;
	bool need_restore=false;

	if (data->screen->IsLost()) {
		hr=data->screen->Restore();
		need_restore=true;
	}
	if (hr==DD_OK && left_buffer->IsLost()) {
		hr=left_buffer->Restore();
		need_restore=true;
	}
	if (hr==DD_OK && right_buffer->IsLost()) {
		hr=right_buffer->Restore();
		need_restore=true;
	}

	if (hr!=DD_OK) {
		WSERR err=CreateSurface();
		if (err!=WS_OK) return err;
		need_restore=false;
	}

	if (need_restore) {
		Refresh();
	}
	return WS_OK;
}
Example #14
0
RageSurface* RageDisplay_D3D::CreateScreenshot()
{
#if defined(XBOX)
	return NULL;
#else
	RageSurface * result = NULL;

	// Get the back buffer.
	IDirect3DSurface9* pSurface;
	if( SUCCEEDED( g_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pSurface ) ) )
	{
		// Get the back buffer description.
		D3DSURFACE_DESC desc;
		pSurface->GetDesc( &desc );

		// Copy the back buffer into a surface of a type we support.
		IDirect3DSurface9* pCopy;
		if( SUCCEEDED( g_pd3dDevice->CreateOffscreenPlainSurface( desc.Width, desc.Height, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pCopy, NULL ) ) )
		{
			if( SUCCEEDED( D3DXLoadSurfaceFromSurface( pCopy, NULL, NULL, pSurface, NULL, NULL, D3DX_FILTER_NONE, 0) ) )
			{
				// Update desc from the copy.
				pCopy->GetDesc( &desc );

				D3DLOCKED_RECT lr;

				{
					RECT rect;
					rect.left = 0;
					rect.top = 0;
					rect.right = desc.Width;
					rect.bottom = desc.Height;

					pCopy->LockRect( &lr, &rect, D3DLOCK_READONLY );
				}

				RageSurface *surface = CreateSurfaceFromPixfmt( FMT_RGBA8, lr.pBits, desc.Width, desc.Height, lr.Pitch);
				ASSERT( surface != NULL );

				// We need to make a copy, since lr.pBits will go away when we call UnlockRect().
				result = 
					CreateSurface( surface->w, surface->h,
						surface->format->BitsPerPixel,
						surface->format->Rmask, surface->format->Gmask,
						surface->format->Bmask, surface->format->Amask );
				RageSurfaceUtils::CopySurface( surface, result );
				delete surface;

				pCopy->UnlockRect();
			}

			pCopy->Release();
		}

		pSurface->Release();
	}

	return result;
#endif
}
Example #15
0
void CChildView::OnSize(UINT nType, int cx, int cy) 
{
	CWnd::OnSize(nType, cx, cy);
    if (m_hWnd && cx && cy) {
        TRACE("OnSize: width == %d, height == %d\n", cx, cy);

		// Initialize screen format
		// First time init with an hwnd
		if (m_eSurf == eNone) {
			CClientDC dc(this);
			int pixels;
			bool bWarnDepth = false;
			bool bWarnDebug = false;

			SetTimer(m_kTimerID, m_kTimerDelay, NULL);
			pixels = dc.GetDeviceCaps(BITSPIXEL) * dc.GetDeviceCaps(PLANES);
			switch (pixels) {
				case 16:
					m_eSurf = IsSSE2() ? e16BitSSE2Intrin :
						IsMMX() ? e16BitMMXIntrin : e16BitGeneric;
					break;
				case 24:
					m_eSurf =  IsSSE2() ? e24BitSSE2Intrin :
						IsMMX() ? e24BitMMXIntrin : e24BitGeneric;
					break;
				case 32:
					m_eSurf =  IsSSE2() ? e32BitSSE2Intrin :
						IsMMX() ? e32BitMMXIntrin : e32BitGeneric;
					break;
				default:
					bWarnDepth = true;
					m_eSurf =  IsSSE2() ? e32BitSSE2Intrin :
						IsMMX() ? e32BitMMXIntrin : e32BitGeneric;
					break;
			}
#ifdef _DEBUG
			bWarnDebug = true;
#endif
			if (bWarnDepth || bWarnDebug) {
				CString fmt;
				if (bWarnDepth) {
					fmt.LoadString(IDS_WARNING_BITDEPTH);
				}
				if (bWarnDepth && bWarnDebug) {
					fmt += "\n";
				}
				if (bWarnDebug) {
					CString temp;
					temp.LoadString(IDS_WARNING_DEBUG);
					fmt += temp;
				}
				::AfxMessageBox(fmt, MB_ICONINFORMATION);
			}

		}

		m_bSizeChanged = true;
		CreateSurface();
    }
}
Example #16
0
BOOL CMovie::OpenMovie(char *fname,int music,BOOL loop)
{
	int			size;
	Chunk		aviFileHead;
	Chunk		aviInfo;
	AVIMAINHEADER aviMainHead;

	WaitThreadEnd();
	stream = readFile->StreamOpenFile(pack_sound,fname,size);
	if((-1)==stream) return FALSE;
	readFile->StreamReadFile(pack_sound,stream,(char *)&aviFileHead,sizeof(Chunk));
	if(MAKEFOURCC('R','I','F','F')!=aviFileHead.ckID){
		readFile->StreamCloseFile(pack_sound,stream);
		stream = -1;
		return FALSE;
	}
	readFile->StreamReadFile(pack_sound,stream,(char *)&aviInfo,sizeof(Chunk));
	readFile->StreamReadFile(pack_sound,stream,(char *)&aviMainHead,sizeof(AVIMAINHEADER));
	readFile->StreamSeekFile(pack_sound,stream,0,FILE_BEGIN);
	fpms = aviMainHead.dwMicroSecPerFrame;

	srcWidth = aviMainHead.dwWidth;
	srcHeight = aviMainHead.dwHeight;

	HDC hDC = ::GetDC(sysInf.hWnd);
	HBRUSH brush = CreateSolidBrush(RGB(0, 0, 8));
	HBRUSH old_brush = (HBRUSH)SelectObject(hDC,brush);
	PatBlt(hDC,0,0,wWidth,wHeight,PATCOPY);
	SelectObject(hDC,old_brush);
	DeleteObject(brush);
	::ReleaseDC(sysInf.hWnd,hDC);

	if(FALSE == CreateSurface() ){
	}
	buffer_size = srcWidth*srcHeight*2;
	readBuf = (LPBYTE)malloc(buffer_size);

	xvidDec.Start_XviD(srcWidth,srcHeight,overlay_forcc[forccNum]);

	read_size = readFile->StreamReadFile(pack_sound,stream,(char *)readBuf,buffer_size);
	frame_cnt = 0;
	old_frame = 0;
	start_time = 0;
	old_time = 0;
	skip_cnt = 0;
	total_skip_cnt = 0;
	bPause = FALSE;
	if(NULL==lpSoundDS)lpSoundDS = new ClSoundDS(sysInf.hWnd,readFile,FALSE);
	bPlay = TRUE;
	bLoop = loop;
	changeExecMode( movie_mode );
	musicNum = music;

	DWORD	dwThreadID;
	hMovieThread = CreateThread(NULL,0,movieThread,this,0,&dwThreadID);
	bExitMovieThread = FALSE;

	return TRUE;
} // CMovie::OpenMovie
Example #17
0
/* bpp: 8, 16, 24, 32 */
void Surface::Set(u16 sw, u16 sh, u8 bpp, bool amask0)
{
    FreeSurface(*this);
    CreateSurface(sw, sh, bpp, amask0);

    if(8 == bpp) LoadPalette();
    SetDefaultColorKey();
}
Example #18
0
void QmitkIsoSurface::CreateConnections()
{
  if ( m_Controls )
  {
    connect( m_Controls->m_ImageSelector, SIGNAL(OnSelectionChanged(const mitk::DataNode*)), this, SLOT(ImageSelected(const mitk::DataNode*)) );
    connect( m_Controls->createSurfacePushButton, SIGNAL(clicked()), this, SLOT(CreateSurface()) );
  }
}
Example #19
0
//---テクスチャーをロードする
int eiTextureCell::Load(int trans /*= 1*/)
{
	int surface_color = TextureSurfaceColor;

	if(!Data.CreateFlag){
		eiDebugWriteFile("(eiTextureCell) Not Created!!\n");
		return 0;
	}

	eiDDSurface TempSurface;

	//---テクスチャーサーフェイスを確保
	if(!CreateSurface()){
		return 0;
	}
	Texture.SetSrcBltColorKey(16,16);
//	eiDebugWriteFile("(eiTextureCell) Texture.Create Succes\n");

	//---エミュレーションでなければテンポラリサーフェイスを作る
	if(!TempSurface.Create(Data.xSize,Data.ySize,
		ESCREATE_TEXTURE | ESCREATE_TEMPTEXTURE | ESCREATE_SYSTEMMEMORY,
		&Texture,TextureSurfaceColor)){
		Texture.Release();
		eiDebugWriteFile("::::::::::::1\n");
		return 0;
	}
//	eiDebugWriteFile("(eiTextureCell) TempSurface.Create Succes\n");

	if(Data.Color <= 8 && TempSurface.Color <= 8){
		//---パレット
		if(CreatePalette()){
			TempSurface.lpSurface->SetPalette(Palette.lpPalette);
			Texture.lpSurface->SetPalette(Palette.lpPalette);
		}
	}

	//---テンポラリサーフェイスへコピーする
	dib.CopyToDDSurface(&TempSurface,0,0,NULL,trans);
//	eiDebugWriteFile("(eiTextureCell) dib.CopyToDDSurface end\n");

	RECT rect = {0,0,Data.xSize,Data.ySize};

	if(!LoadFromSurface(&TempSurface,&rect)){
		eiDebugWriteFile("(eiTextureCell) load fail\n");
	}

	//---いらなくなったのを解放
	TempSurface.Release();

	//---サーフェイスセット
	Data.SurfaceFlag = 1;
	Data.SurfaceNumber = 2;
	pDDSurface = &Texture;

//	eiDebugWriteFile("(eiTextureCell) Create succes\n");

	return 1;
}
Example #20
0
static RageSurface *ReadImage( RageFile &f, int len, int height,
		const RageSurfaceColor localColorMap[MAXCOLORMAPSIZE],
		int interlace, int ignore )
{
	int xpos = 0, ypos = 0, pass = 0;

	/* Initialize the compression routines */
	LWZState state;
	if( !state.Init(f) )
	{
//		RWSetMsg("error reading image");
		return NULL;
	}
	/* If this is an "uninteresting picture" ignore it. */
	if( ignore )
	{
		while( state.ReadByte(f) >= 0 )
			;
		return NULL;
	}

	RageSurface *image = CreateSurface( len, height, 8, 0, 0, 0, 0 );
	memcpy( image->fmt.palette->colors, localColorMap, 256*sizeof(RageSurfaceColor) );

	int v;
	while( (v = state.ReadByte(f)) >= 0 )
	{
		char *data = (char *) image->pixels;
		data[xpos + ypos * image->pitch] = (char) v;

		++xpos;
		if( xpos == len )
		{
			xpos = 0;
			if( interlace )
			{
				int step[] = { 8, 8, 4, 2 };
				ypos += step[pass];

				if( ypos >= height )
				{
					++pass;
					if( pass == 4 )
						return image;
					int start[] = { 0, 4, 2, 1 };
					ypos = start[pass];
				}
			} else {
				++ypos;
			}
		}
		if (ypos >= height)
			break;
	}

	return image;
}
Example #21
0
std::shared_ptr<gsurface_t> MyRenderGL::CacheSurface( const surf_t &s ) {
    GLuint vao;
    GLuint positionBuffer, indexBuffer;

    _CH(glGenVertexArrays( 1, &vao ));
    _CH(glBindVertexArray( vao ));

    _CH(glGenBuffers( 1, &positionBuffer ));
    _CH(glBindBuffer( GL_ARRAY_BUFFER, positionBuffer ));
    _CH(glBufferData( GL_ARRAY_BUFFER, s.m_verts.size() * 8 * sizeof(float),
        (void *)s.m_verts.data(), GL_STATIC_DRAW ));

    _CH(glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float),
        (void *)(0 * sizeof(float ) ) ));
    _CH(glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float),
        (void *)(3 * sizeof(float ) ) ));
    _CH(glVertexAttribPointer( 2, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float),
        (void *)(5 * sizeof(float ) ) ));

    _CH(glEnableVertexAttribArray( 0 ));
    _CH(glEnableVertexAttribArray( 1 ));
    _CH(glEnableVertexAttribArray( 2 ));

    _CH(glGenBuffers( 1, &indexBuffer ));
    _CH(glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBuffer ));
    _CH(glBufferData( GL_ELEMENT_ARRAY_BUFFER, 
                s.m_indices.size() * sizeof(GLushort),
        (void *)s.m_indices.data(), GL_STATIC_DRAW ));

    std::shared_ptr<gsurface_t> cached = CreateSurface();

    cached->m_vao = vao;
    cached->m_numIndices = s.m_indices.size();
    cached->m_indexBuffer = indexBuffer;

    if ( s.m_matName == "white" ) {
        cached->m_material = m_whiteMaterial;
    } else if ( s.m_matName == "sky" ) {
        cached->m_material = m_skyMaterial;
    } else {
        if ( m_materialCache.find( s.m_matName ) != m_materialCache.end() ) {
            cached->m_material = m_materialCache[ s.m_matName ];
        } else {
            std::shared_ptr<material_t> t = new material_t();
            t->m_texture = CreateTexture( s.m_matName );
            t->m_program = m_shaderProgram;
            if ( !t.IsValid() ) {
                msg_failure( "Can't cache material `%s'\n", s.m_matName.c_str() );
                return nullptr;
            }
            m_materialCache[ s.m_matName ] = t;
            cached->m_material = t;
        }
    }
    return cached;
}
Example #22
0
static struct XenosSurface * GetScreenSurface(int w, int h, int fmt) {
    if (screen_texture == NULL) {
        screen_texture = CreateSurface(1024, 1024, fmt);
    }

    screen_texture->width = w;
    screen_texture->height = h;

    return screen_texture;
}
Example #23
0
void VolumeBrush::InitialUpdate()
{
// TESTING!!!!
	if (!vtRemoveFilters.IsInitted())
	{
		vtRemoveFilters.Init(g_pLTServer, "RemoveFilters", LTNULL, 0.0f);
	}
	if (vtRemoveFilters.GetFloat())
	{
		g_pLTServer->CPrint("Removing Filter: %s", g_pLTServer->GetObjectName(m_hObject));
		g_pLTServer->RemoveObject(m_hObject);
		return;
	}
// TESTING!!!!


	// Tell the client about any special fx (fog)...

	CreateSpecialFXMsg();


	// Save volume brush's initial flags...

    m_dwSaveFlags = g_pLTServer->GetObjectFlags(m_hObject);


    uint32 dwUserFlags = g_pLTServer->GetObjectUserFlags(m_hObject);
	dwUserFlags |= USRFLG_IGNORE_PROJECTILES;
	if (!m_bHidden) dwUserFlags |= USRFLG_VISIBLE;

    g_pLTServer->SetObjectUserFlags(m_hObject, dwUserFlags);


	// Create the surface if necessary.  We only need to do updates if we have
	// a surface (in case somebody decides to move the brush, we need to update
	// the surface's position)...

	if (m_bShowSurface)
	{
		CreateSurface();
        SetNextUpdate(UPDATE_DELTA);
	}


	// Normalize friction (1 = normal, 0 = no friction, 2 = double)...

	if (m_fFriction < 0.0) m_fFriction = 0.0f;
	else if (m_fFriction > 1.0) m_fFriction = 1.0f;


	// Normalize viscosity (1 = no movement, 0 = full movement)...

	if (m_fViscosity < 0.0) m_fViscosity = 0.0f;
	else if (m_fViscosity > 1.0) m_fViscosity = 1.0f;
}
Example #24
0
void VolumeBrush::InitialUpdate(int nData)
{
    CServerDE* pServerDE = GetServerDE();
    if (!pServerDE) return;

    // For save game restores, just recreate the surface
    if (nData == INITIALUPDATE_SAVEGAME)
        return;

    if (m_bShowSurface)
    {
        CreateSurface();
    }

    m_hPlayerClass = pServerDE->GetClass("CPlayerObj");

    DDWORD dwUserFlags = m_bHidden ? 0 : USRFLG_VISIBLE;
    dwUserFlags |= USRFLG_SAVEABLE;

    pServerDE->SetObjectUserFlags(m_hObject, dwUserFlags);

    if (m_hSurfaceObj)
    {
        pServerDE->SetObjectUserFlags(m_hSurfaceObj, dwUserFlags);
    }

    // Tell the client about any special fx (fog)...
    HMESSAGEWRITE hMessage = pServerDE->StartSpecialEffectMessage(this);
    pServerDE->WriteToMessageByte(hMessage, SFX_VOLUMEBRUSH_ID);
//pServerDE->WriteToMessageByte(hMessage, DTRUE);
    pServerDE->WriteToMessageByte(hMessage, (DBYTE)m_bFogEnable);
    pServerDE->WriteToMessageFloat(hMessage, m_fFogFarZ);
    pServerDE->WriteToMessageFloat(hMessage, m_fFogNearZ);
    pServerDE->WriteToMessageVector(hMessage, &m_vFogColor);
    pServerDE->EndMessage(hMessage);

    pServerDE->SetNextUpdate(m_hObject, 0.001f);


    // Save volume brush's initial flags...

    m_dwSaveFlags = pServerDE->GetObjectFlags(m_hObject);


    // Normalize viscosity (1 = no movement, 0 = full movement)...

    if (m_fViscosity < 0.0) m_fViscosity = 0.0f;
    else if (m_fViscosity > 1.0) m_fViscosity = 1.0f;

    // Okay, internally we really want it the opposite way (i.e., 1 = full
    // movement, 0 = no movement)...

    m_fViscosity = 1.0f - m_fViscosity;
}
Example #25
0
	CBenchmark()
	{
		for (dword i = 0; i < 4; i++)
			m_PerfData[i] = 0;

		m_SurfID = CreateSurface(300, 200, 256, 256 + 16);
		FillSurface(m_SurfID, 0xFFFFFFFF);
		DrawFrameRect(m_SurfID, 0, 0, 256, 256 + 16, 0xFF808080);
		ShowSurface(m_SurfID);

		KeEnableNotification(Nf_VirtualKey);
		KeEnableNotification(NfKe_TerminateProcess);

		double T = 0.0;
		dword FPS = 0;
		dword T1 = KeGetTime();
		for (;;)
		{
			for (dword i = 0; i < 6; i++)
				DrawIter(T - 4.0 * (5 - i), 0xFFFFFFFF);

			T += 1.0;
			for (dword i = 0; i < 6; i++)
				DrawIter(T - 4.0 * (5 - i), 0x004070FF | (((i + 1) * 0x10) << 24));

			WaitRedraw();
			FPS++;

			dword T2 = KeGetTime();
			if (T2 - T1 >= 1000)
			{
				dword AvgFPS = AddPerfData(FPS);
				T1 = T2;
				FPS = 0;

				ShowStat(AvgFPS);
			}


			CNotification<4> Nf;
			dword NfCount = KeGetNotificationCount();
			for (dword i = 0; i < NfCount; i++)
			{
				Nf.Recv();
				if (Nf.GetID() == Nf_VirtualKey)
				{
					if (Nf.GetByte(0) == VK_Esc)
						return;
				}
				else if (Nf.GetID() == NfKe_TerminateProcess)
					return;
			}
		}
	}
SDL_Texture *TextureFactory::CreateWindowTexture(int width, int height, SDL_Color color, Renderer *renderer)
{
  SDL_Surface *surface = CreateSurface(width, height);
  SDL_Rect rect = { 0, 0, width, height};

  ColorArea(rect, color, surface);

  SDL_Color black = { 0, 0, 0, 255 };
  DrawBox(rect, black, surface);

  return CreateTexture(renderer, surface);
}
Example #27
0
RageSurface* RageDisplay_D3D::CreateScreenshot()
{
#if defined(XBOX)
	return NULL;
#else
	/* Get the back buffer. */
	IDirect3DSurface8* pSurface;
	g_pd3dDevice->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pSurface );

	/* Get the back buffer description. */
	D3DSURFACE_DESC desc;
	pSurface->GetDesc( &desc );

	/* Copy the back buffer into a surface of a type we support. */
	IDirect3DSurface8* pCopy;
	g_pd3dDevice->CreateImageSurface( desc.Width, desc.Height, D3DFMT_A8R8G8B8, &pCopy );

	D3DXLoadSurfaceFromSurface( pCopy, NULL, NULL, pSurface, NULL, NULL, D3DX_DEFAULT, 0 );

	pSurface->Release();

	/* Update desc from the copy. */
	pCopy->GetDesc( &desc );

	D3DLOCKED_RECT lr;

	{
		RECT rect; 
		rect.left = 0;
		rect.top = 0;
		rect.right = desc.Width;
		rect.bottom = desc.Height;
		pCopy->LockRect( &lr, &rect, D3DLOCK_READONLY );
	}

	RageSurface *surface = CreateSurfaceFromPixfmt( FMT_RGBA8, lr.pBits, desc.Width, desc.Height, lr.Pitch);
	ASSERT( surface );

	/* We need to make a copy, since lr.pBits will go away when we call UnlockRect(). */
	RageSurface *SurfaceCopy = 
		CreateSurface( surface->w, surface->h,
			surface->format->BitsPerPixel,
			surface->format->Rmask, surface->format->Gmask,
			surface->format->Bmask, surface->format->Amask );
	RageSurfaceUtils::CopySurface( surface, SurfaceCopy );
	delete surface;

	pCopy->UnlockRect();
	pCopy->Release();

	return SurfaceCopy;
#endif
}
Example #28
0
//-----------------------------------------------------------------------------
// Name: LoadSpriteImage24(CBITMAP framesofAnim)
// Desc: creates surfaces for all the cells and copies image to surface cx and 
//       cy are absolute quards i.e. (0,0) (1,0)...
//----------------------------------------------------------------------------- 
int CSPRITE::LoadSpriteImage24(char * filename)
{
	DWORD *source_ptr,   // working pointers
		   *dest_ptr;
	int index_y=0, column=0,row=0,cx=0,cy=0;
	CBITMAP bitmap(filename);
	
	bitmap.LoadBitmapFile();
	
	for(int frame=0; frame<= m_iNumberofFrames-1; frame++)
	{

		m_lpddsImage[frame] = CreateSurface(m_iWidth, m_iHeight,TransColor);

		//clear out the ddsd
		memset(&ddsd,0,sizeof(ddsd));
		ddsd.dwSize  = sizeof(ddsd);
	
		if(!Lock(m_lpddsImage[frame]))
			return(0);
			dest_ptr = (DWORD*) ddsd.lpSurface;
		
			cx=column; cy=row;
			//compute x,y
			cx = cx*(m_iWidth+1) + 1;
			cy = cy*(m_iHeight+1) + 1;
		
			// extract bitmap data
			source_ptr = (DWORD*)bitmap.GetImageData() + (cy*bitmap.GetWidth()+cx);

			// iterate thru each scanline and copy bitmap
			for (int index_y=0; index_y < m_iHeight; index_y++)
			{
			    // copy next line of data to destination
				memcpy(dest_ptr, source_ptr,m_iWidth*4);

				// advance pointers
				dest_ptr   += (ddsd.lPitch >> 2);
				source_ptr += bitmap.GetWidth();
			} // end for index_y

		if(!UnLock(m_lpddsImage[frame]))
			return(0);
		column++;
		if(column > m_iCol-1)
		{
			column=0; row++;
		}
	}//End for(int i=0; i<= m_iNumberofFrames; i++)
	
	m_iAttr = SPRITE_ATTR_LOADED;
	return (1);
}
Example #29
0
int eiTextureCell::CreateFromSurface(int sx,int sy,int color,eiDDSurface *pSurface,RECT *pSrcRect)
{
	CreateTexture(sx,sy,color);
	CreateSurface();
	if(Data.Color <= 8){//TextureSurfaceColor/*8*/){
		if(CreatePalette()){
			Texture.lpSurface->SetPalette(Palette.lpPalette);
		}
	}

	return LoadFromSurface(pSurface,pSrcRect);
}
bool RageSurfaceUtils::SaveBMP( RageSurface *surface, RageFile &f )
{
	/* Convert the surface to 24bpp. */
	RageSurface *converted_surface;
	converted_surface = CreateSurface( surface->w, surface->h, 24,
		Swap24LE( 0xFF0000 ), Swap24LE( 0x00FF00 ), Swap24LE( 0x0000FF ), 0 );
	RageSurfaceUtils::CopySurface( surface, converted_surface );

	RString sError;

	int iFilePitch = converted_surface->pitch;
	iFilePitch = (iFilePitch+3) & ~3; // round up a multiple of 4

	int iDataSize = converted_surface->h * iFilePitch;
	const int iHeaderSize = 0x36;

	WriteBytes( f, sError, "BM", 2 );
	write_le32( f, sError, iHeaderSize+iDataSize ); // size (offset 0x2)
	write_le32( f, sError, 0 ); // reserved (offset 0x6)
	write_le32( f, sError, iHeaderSize ); // bitmap offset (offset 0xA)
	write_le32( f, sError, 0x28 ); // header size (offset 0xE)
	write_le32( f, sError, surface->w ); // width (offset 0x14)
	write_le32( f, sError, surface->h ); // height (offset 0x18)
	write_le16( f, sError, 1 ); // planes (offset 0x1A)
	write_le16( f, sError, (uint16_t) converted_surface->fmt.BytesPerPixel*8 ); // bpp (offset 0x1C)
	write_le32( f, sError, 0 ); // compression (offset 0x1E)
	write_le32( f, sError, iDataSize ); // bitmap size (offset 0x22)
	write_le32( f, sError, 0 ); // horiz resolution (offset 0x26)
	write_le32( f, sError, 0 ); // vert resolution (offset 0x2A)
	write_le32( f, sError, 0 ); // colors (offset 0x2E)
	write_le32( f, sError, 0 ); // important colors (offset 0x32)

	for( int y = converted_surface->h-1; y >= 0; --y )
	{
		const uint8_t *pRow = converted_surface->pixels + converted_surface->pitch*y;
		WriteBytes( f, sError, pRow, converted_surface->pitch );

		/* Pad the row to the pitch. */
		uint8_t padding[4] = { 0,0,0,0 };
		WriteBytes( f, sError, padding, iFilePitch-converted_surface->pitch );
	}

	delete converted_surface;

	if( sError.size() != 0 )
		return false;

	if( f.Flush() == -1 )
		return false;

	return true;
}