Create shared contexts.

TRAC #12498 Signed-off-by: Shannon Woods Signed-off-by: Daniel Koch Author: Andrew Lewycky git-svn-id: https://angleproject.googlecode.com/svn/trunk@363 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent bbc57796
......@@ -378,11 +378,11 @@ Surface *Display::createWindowSurface(HWND window, EGLConfig config)
return surface;
}
EGLContext Display::createContext(EGLConfig configHandle)
EGLContext Display::createContext(EGLConfig configHandle, const gl::Context *shareContext)
{
const egl::Config *config = mConfigSet.get(configHandle);
gl::Context *context = glCreateContext(config);
gl::Context *context = glCreateContext(config, shareContext);
mContextSet.insert(context);
return context;
......
......@@ -43,7 +43,7 @@ class Display
bool getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value);
egl::Surface *createWindowSurface(HWND window, EGLConfig config);
EGLContext createContext(EGLConfig configHandle);
EGLContext createContext(EGLConfig configHandle, const gl::Context *shareContext);
void destroySurface(egl::Surface *surface);
void destroyContext(gl::Context *context);
......
......@@ -772,7 +772,7 @@ EGLContext __stdcall eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLConte
return EGL_NO_CONTEXT;
}
EGLContext context = display->createContext(config);
EGLContext context = display->createContext(config, static_cast<gl::Context*>(share_context));
return success(context);
}
......
......@@ -34,7 +34,7 @@
namespace gl
{
Context::Context(const egl::Config *config)
Context::Context(const egl::Config *config, const gl::Context *shareContext)
: mConfig(config)
{
setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
......@@ -104,8 +104,15 @@ Context::Context(const egl::Config *config)
mState.colorMaskAlpha = true;
mState.depthMask = true;
// FIXME: Resource managers should get managed with context sharing
mResourceManager = new ResourceManager();
if (shareContext != NULL)
{
mResourceManager = shareContext->mResourceManager;
mResourceManager->addRef();
}
else
{
mResourceManager = new ResourceManager();
}
// [OpenGL ES 2.0.24] section 3.7 page 83:
// In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional
......@@ -200,8 +207,7 @@ Context::~Context()
mMaskedClearSavedState->Release();
}
// FIXME: Context should not be responsible for resource manager deallocation
delete mResourceManager;
mResourceManager->release();
}
void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
......@@ -277,6 +283,12 @@ void Context::markAllStateDirty()
mScissorStateDirty = true;
mSampleStateDirty = true;
mDitherStateDirty = true;
mFrontFaceDirty = true;
if (mBufferBackEnd != NULL)
{
mBufferBackEnd->invalidate();
}
}
void Context::setClearColor(float red, float green, float blue, float alpha)
......@@ -2803,9 +2815,9 @@ const char *Context::getExtensionString() const
extern "C"
{
gl::Context *glCreateContext(const egl::Config *config)
gl::Context *glCreateContext(const egl::Config *config, const gl::Context *shareContext)
{
return new gl::Context(config);
return new gl::Context(config, shareContext);
}
void glDestroyContext(gl::Context *context)
......
......@@ -193,7 +193,7 @@ struct State
class Context
{
public:
Context(const egl::Config *config);
Context(const egl::Config *config, const gl::Context *shareContext);
~Context();
......@@ -459,7 +459,7 @@ class Context
extern "C"
{
// Exported functions for use by EGL
gl::Context *glCreateContext(const egl::Config *config);
gl::Context *glCreateContext(const egl::Config *config, const gl::Context *shareContext);
void glDestroyContext(gl::Context *context);
void glMakeCurrent(gl::Context *context, egl::Display *display, egl::Surface *surface);
gl::Context *glGetCurrentContext();
......
......@@ -19,6 +19,7 @@ namespace gl
{
ResourceManager::ResourceManager()
{
mRefCount = 1;
}
ResourceManager::~ResourceManager()
......@@ -49,6 +50,19 @@ ResourceManager::~ResourceManager()
}
}
void ResourceManager::addRef()
{
mRefCount++;
}
void ResourceManager::release()
{
if (--mRefCount == 0)
{
delete this;
}
}
// Returns an unused buffer name
GLuint ResourceManager::createBuffer()
{
......
......@@ -39,6 +39,9 @@ class ResourceManager
ResourceManager();
~ResourceManager();
void addRef();
void release();
GLuint createBuffer();
GLuint createShader(GLenum type);
GLuint createProgram();
......@@ -66,6 +69,8 @@ class ResourceManager
private:
DISALLOW_COPY_AND_ASSIGN(ResourceManager);
std::size_t mRefCount;
typedef std::map<GLuint, Buffer*> BufferMap;
BufferMap mBufferMap;
......
......@@ -65,6 +65,8 @@ class BufferBackEnd
virtual GLenum setupIndicesPreDraw(const TranslatedIndexData &indexInfo) = 0;
virtual GLenum setupAttributesPreDraw(const TranslatedAttribute *attributes) = 0;
virtual void invalidate() = 0;
};
class TranslatedBuffer
......
......@@ -471,6 +471,14 @@ GLenum Dx9BackEnd::setupAttributesPreDraw(const TranslatedAttribute *attributes)
return GL_NO_ERROR;
}
void Dx9BackEnd::invalidate()
{
for (int i = 0; i < MAX_VERTEX_ATTRIBS + 1; i++)
{
mStreamFrequency[i] = STREAM_FREQUENCY_DIRTY;
}
}
Dx9BackEnd::Dx9VertexBuffer::Dx9VertexBuffer(IDirect3DDevice9 *device, std::size_t size)
: TranslatedVertexBuffer(size)
{
......
......@@ -35,6 +35,8 @@ class Dx9BackEnd : public BufferBackEnd
virtual GLenum setupIndicesPreDraw(const TranslatedIndexData &indexInfo);
virtual GLenum setupAttributesPreDraw(const TranslatedAttribute *attributes);
void invalidate();
private:
IDirect3DDevice9 *mDevice;
......@@ -47,10 +49,11 @@ class Dx9BackEnd : public BufferBackEnd
{
STREAM_FREQUENCY_UNINSTANCED = 0,
STREAM_FREQUENCY_INDEXED,
STREAM_FREQUENCY_INSTANCED
STREAM_FREQUENCY_INSTANCED,
STREAM_FREQUENCY_DIRTY
};
StreamFrequency mStreamFrequency[MAX_VERTEX_ATTRIBS+1];
StreamFrequency mStreamFrequency[MAX_VERTEX_ATTRIBS+1]; // Stream frequencies as last set.
struct TranslationInfo
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment