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) ...@@ -378,11 +378,11 @@ Surface *Display::createWindowSurface(HWND window, EGLConfig config)
return surface; return surface;
} }
EGLContext Display::createContext(EGLConfig configHandle) EGLContext Display::createContext(EGLConfig configHandle, const gl::Context *shareContext)
{ {
const egl::Config *config = mConfigSet.get(configHandle); const egl::Config *config = mConfigSet.get(configHandle);
gl::Context *context = glCreateContext(config); gl::Context *context = glCreateContext(config, shareContext);
mContextSet.insert(context); mContextSet.insert(context);
return context; return context;
......
...@@ -43,7 +43,7 @@ class Display ...@@ -43,7 +43,7 @@ class Display
bool getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value); bool getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value);
egl::Surface *createWindowSurface(HWND window, EGLConfig config); 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 destroySurface(egl::Surface *surface);
void destroyContext(gl::Context *context); void destroyContext(gl::Context *context);
......
...@@ -772,7 +772,7 @@ EGLContext __stdcall eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLConte ...@@ -772,7 +772,7 @@ EGLContext __stdcall eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLConte
return EGL_NO_CONTEXT; return EGL_NO_CONTEXT;
} }
EGLContext context = display->createContext(config); EGLContext context = display->createContext(config, static_cast<gl::Context*>(share_context));
return success(context); return success(context);
} }
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
namespace gl namespace gl
{ {
Context::Context(const egl::Config *config) Context::Context(const egl::Config *config, const gl::Context *shareContext)
: mConfig(config) : mConfig(config)
{ {
setClearColor(0.0f, 0.0f, 0.0f, 0.0f); setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
...@@ -104,8 +104,15 @@ Context::Context(const egl::Config *config) ...@@ -104,8 +104,15 @@ Context::Context(const egl::Config *config)
mState.colorMaskAlpha = true; mState.colorMaskAlpha = true;
mState.depthMask = true; mState.depthMask = true;
// FIXME: Resource managers should get managed with context sharing if (shareContext != NULL)
mResourceManager = new ResourceManager(); {
mResourceManager = shareContext->mResourceManager;
mResourceManager->addRef();
}
else
{
mResourceManager = new ResourceManager();
}
// [OpenGL ES 2.0.24] section 3.7 page 83: // [OpenGL ES 2.0.24] section 3.7 page 83:
// In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional
...@@ -200,8 +207,7 @@ Context::~Context() ...@@ -200,8 +207,7 @@ Context::~Context()
mMaskedClearSavedState->Release(); mMaskedClearSavedState->Release();
} }
// FIXME: Context should not be responsible for resource manager deallocation mResourceManager->release();
delete mResourceManager;
} }
void Context::makeCurrent(egl::Display *display, egl::Surface *surface) void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
...@@ -277,6 +283,12 @@ void Context::markAllStateDirty() ...@@ -277,6 +283,12 @@ void Context::markAllStateDirty()
mScissorStateDirty = true; mScissorStateDirty = true;
mSampleStateDirty = true; mSampleStateDirty = true;
mDitherStateDirty = true; mDitherStateDirty = true;
mFrontFaceDirty = true;
if (mBufferBackEnd != NULL)
{
mBufferBackEnd->invalidate();
}
} }
void Context::setClearColor(float red, float green, float blue, float alpha) void Context::setClearColor(float red, float green, float blue, float alpha)
...@@ -2803,9 +2815,9 @@ const char *Context::getExtensionString() const ...@@ -2803,9 +2815,9 @@ const char *Context::getExtensionString() const
extern "C" 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) void glDestroyContext(gl::Context *context)
......
...@@ -193,7 +193,7 @@ struct State ...@@ -193,7 +193,7 @@ struct State
class Context class Context
{ {
public: public:
Context(const egl::Config *config); Context(const egl::Config *config, const gl::Context *shareContext);
~Context(); ~Context();
...@@ -459,7 +459,7 @@ class Context ...@@ -459,7 +459,7 @@ class Context
extern "C" extern "C"
{ {
// Exported functions for use by EGL // 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 glDestroyContext(gl::Context *context);
void glMakeCurrent(gl::Context *context, egl::Display *display, egl::Surface *surface); void glMakeCurrent(gl::Context *context, egl::Display *display, egl::Surface *surface);
gl::Context *glGetCurrentContext(); gl::Context *glGetCurrentContext();
......
...@@ -19,6 +19,7 @@ namespace gl ...@@ -19,6 +19,7 @@ namespace gl
{ {
ResourceManager::ResourceManager() ResourceManager::ResourceManager()
{ {
mRefCount = 1;
} }
ResourceManager::~ResourceManager() ResourceManager::~ResourceManager()
...@@ -49,6 +50,19 @@ 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 // Returns an unused buffer name
GLuint ResourceManager::createBuffer() GLuint ResourceManager::createBuffer()
{ {
......
...@@ -39,6 +39,9 @@ class ResourceManager ...@@ -39,6 +39,9 @@ class ResourceManager
ResourceManager(); ResourceManager();
~ResourceManager(); ~ResourceManager();
void addRef();
void release();
GLuint createBuffer(); GLuint createBuffer();
GLuint createShader(GLenum type); GLuint createShader(GLenum type);
GLuint createProgram(); GLuint createProgram();
...@@ -66,6 +69,8 @@ class ResourceManager ...@@ -66,6 +69,8 @@ class ResourceManager
private: private:
DISALLOW_COPY_AND_ASSIGN(ResourceManager); DISALLOW_COPY_AND_ASSIGN(ResourceManager);
std::size_t mRefCount;
typedef std::map<GLuint, Buffer*> BufferMap; typedef std::map<GLuint, Buffer*> BufferMap;
BufferMap mBufferMap; BufferMap mBufferMap;
......
...@@ -65,6 +65,8 @@ class BufferBackEnd ...@@ -65,6 +65,8 @@ class BufferBackEnd
virtual GLenum setupIndicesPreDraw(const TranslatedIndexData &indexInfo) = 0; virtual GLenum setupIndicesPreDraw(const TranslatedIndexData &indexInfo) = 0;
virtual GLenum setupAttributesPreDraw(const TranslatedAttribute *attributes) = 0; virtual GLenum setupAttributesPreDraw(const TranslatedAttribute *attributes) = 0;
virtual void invalidate() = 0;
}; };
class TranslatedBuffer class TranslatedBuffer
......
...@@ -471,6 +471,14 @@ GLenum Dx9BackEnd::setupAttributesPreDraw(const TranslatedAttribute *attributes) ...@@ -471,6 +471,14 @@ GLenum Dx9BackEnd::setupAttributesPreDraw(const TranslatedAttribute *attributes)
return GL_NO_ERROR; 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) Dx9BackEnd::Dx9VertexBuffer::Dx9VertexBuffer(IDirect3DDevice9 *device, std::size_t size)
: TranslatedVertexBuffer(size) : TranslatedVertexBuffer(size)
{ {
......
...@@ -35,6 +35,8 @@ class Dx9BackEnd : public BufferBackEnd ...@@ -35,6 +35,8 @@ class Dx9BackEnd : public BufferBackEnd
virtual GLenum setupIndicesPreDraw(const TranslatedIndexData &indexInfo); virtual GLenum setupIndicesPreDraw(const TranslatedIndexData &indexInfo);
virtual GLenum setupAttributesPreDraw(const TranslatedAttribute *attributes); virtual GLenum setupAttributesPreDraw(const TranslatedAttribute *attributes);
void invalidate();
private: private:
IDirect3DDevice9 *mDevice; IDirect3DDevice9 *mDevice;
...@@ -47,10 +49,11 @@ class Dx9BackEnd : public BufferBackEnd ...@@ -47,10 +49,11 @@ class Dx9BackEnd : public BufferBackEnd
{ {
STREAM_FREQUENCY_UNINSTANCED = 0, STREAM_FREQUENCY_UNINSTANCED = 0,
STREAM_FREQUENCY_INDEXED, 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 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