Exemplo n.º 1
0
Surface :: Surface(const Config & config, HDC hdc)
:	m_Config(config),
	m_Rect (0, 0, config.GetConfigAttrib(EGL_WIDTH), config.GetConfigAttrib(EGL_HEIGHT)),
	m_Bitmap(reinterpret_cast<HBITMAP>(INVALID_HANDLE_VALUE)),
	m_HDC(reinterpret_cast<HDC>(INVALID_HANDLE_VALUE))
{
	//m_ColorBuffer = new U16[m_Width * m_Height];
	U32 width = GetWidth();
	U32 height = GetHeight();

	m_Pitch = width;

	switch (m_Config.GetDepthStencilFormat()) {
	case DepthStencilFormatDepth16:
		m_DepthStencilBuffer = new U8[width * height * sizeof(U16)];
		break;

	case DepthStencilFormatDepth16Stencil16:
		m_DepthStencilBuffer = new U8[width * height * sizeof(U32)];
		break;

	default:
		m_DepthStencilBuffer = 0;
		assert(false);
		break;
	}

	if (hdc != INVALID_HANDLE_VALUE) {
		m_HDC = CreateCompatibleDC(hdc);
	}

	InfoHeader info(m_Config.GetColorFormat(), width, height);

	m_Bitmap = CreateDIBSection(m_HDC, reinterpret_cast<BITMAPINFO *>(&info), DIB_RGB_COLORS,
		reinterpret_cast<void **>(&m_ColorBuffer), NULL, 0);
}
Exemplo n.º 2
0
Context :: Context(const Config & config) 
	:
	m_Config(config),
	m_DrawSurface(0),
	m_ReadSurface(0),
	m_LastError(GL_NO_ERROR),

	// transformation matrices
	m_ModelViewMatrixStack(16),
	m_CurrentMatrixStack(&m_ModelViewMatrixStack),
	m_MatrixMode(GL_MODELVIEW),
	m_Scissor(0, 0, config.GetConfigAttrib(EGL_WIDTH), config.GetConfigAttrib(EGL_HEIGHT)),
	m_Viewport(0, 0, config.GetConfigAttrib(EGL_WIDTH), config.GetConfigAttrib(EGL_HEIGHT)),
	m_CurrentPaletteMatrix(0),

	// server flags
	m_ClipPlaneEnabled(0),
	m_LightingEnabled(false),
	m_TwoSidedLightning(false),
	m_LightEnabled(0),				// no light on
	m_CullFaceEnabled(false),
	m_DitherEnabled(false),
	m_ReverseFaceOrientation(false),
	m_CullMode(CullModeBack),
	m_ColorMaterialEnabled(false),
	m_NormalizeEnabled(false),
	m_RescaleNormalEnabled(false),
	m_PolygonOffsetFillEnabled(false),
	m_MultiSampleEnabled(false),
	m_SampleAlphaToCoverageEnabled(false),
	m_SampleAlphaToOneEnabled(false),
	m_SampleCoverageEnabled(false),
	m_ScissorTestEnabled(false),
	m_MatrixPaletteEnabled(false),
	m_MatrixModePaletteEnabled(false),
	m_ActiveTexture(0),
	m_ClientActiveTexture(0),

	// point parameters
	m_PointSize(EGL_ONE),
	m_PointSizeMin(EGL_ONE),
	m_PointSizeMax(EGL_ONE),		// what is the correct value?
	m_PointFadeThresholdSize(EGL_ONE),
	m_PointSizeAttenuate(false),

	// fog parameters for setup phase
	m_FogMode(FogModeExp),
	m_FogStart(0),
	m_FogEnd(EGL_ONE),
	m_FogGradient(EGL_ONE),
	m_FogGradientShift(0),
	m_FogDensity(EGL_ONE),

	// client flags
	m_VertexArrayEnabled(false),
	m_NormalArrayEnabled(false),
	m_ColorArrayEnabled(false),
	m_PointSizeArrayEnabled(false),

	// buffers
	m_CurrentArrayBuffer(0),
	m_CurrentElementArrayBuffer(0),

	// general context state
	m_Current(false),
	m_Disposed(false),
	m_ViewportInitialized(false),
	m_DefaultNormal(0, 0, EGL_ONE),
	m_DefaultRGBA(EGL_ONE, EGL_ONE, EGL_ONE, EGL_ONE),

	// pixel store state
	m_PixelStorePackAlignment(4),
	m_PixelStoreUnpackAlignment(4),

	// SGIS_generate_mipmap extension
	m_GenerateMipmaps(false),

	// hints
	m_PerspectiveCorrectionHint(GL_DONT_CARE),
	m_PointSmoothHint(GL_DONT_CARE),
	m_LineSmoothHint(GL_DONT_CARE),
	m_FogHint(GL_DONT_CARE),
	m_GenerateMipmapHint(GL_DONT_CARE)
{
	DepthRangex(VIEWPORT_NEAR, VIEWPORT_FAR);
	ClearDepthx(EGL_ONE);
	ClearStencil(0);

	m_Rasterizer = new Rasterizer(GetRasterizerState());	
	m_Buffers.Allocate();			// default buffer

	m_LightModelAmbient.r = m_LightModelAmbient.g = m_LightModelAmbient.b = F(0.2f);
	m_LightModelAmbient.a = F(1.0);

	m_Lights[0].SetDiffuseColor(FractionalColor(F(1.0), F(1.0), F(1.0), F(1.0)));
	m_Lights[0].SetSpecularColor(FractionalColor(F(1.0), F(1.0), F(1.0), F(1.0)));

	m_PointDistanceAttenuation[0] = EGL_ONE;
	m_PointDistanceAttenuation[1] = 0;
	m_PointDistanceAttenuation[2] = 0;

	size_t defaultTexture = m_Textures.Allocate();

	for (size_t unit = 0; unit < EGL_NUM_TEXTURE_UNITS; ++unit) {
		m_TexCoordArrayEnabled[unit] = false;
		m_Rasterizer->SetTexture(unit, m_Textures.GetObject(defaultTexture));
	}

	memset(&m_ClipPlanes, 0, sizeof(m_ClipPlanes));
}