diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-17 03:04:33 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-17 03:04:33 +0000 |
commit | c95c38f7b2303467f466d9dd86ffdecf8ee06cff (patch) | |
tree | 4e7bad1ddee2d62b4e00df89c4ac2f841e8c182f /o3d | |
parent | edeebc29ebdda26ea794d25aef9525507a43de29 (diff) | |
download | chromium_src-c95c38f7b2303467f466d9dd86ffdecf8ee06cff.zip chromium_src-c95c38f7b2303467f466d9dd86ffdecf8ee06cff.tar.gz chromium_src-c95c38f7b2303467f466d9dd86ffdecf8ee06cff.tar.bz2 |
Rename all GLES2 classes from ___GL to ___GLES2
Review URL: http://codereview.chromium.org/500086
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34801 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
23 files changed, 761 insertions, 724 deletions
diff --git a/o3d/core/cross/gles2/buffer_gles2.cc b/o3d/core/cross/gles2/buffer_gles2.cc index 05b1276..d8f4bc4 100644 --- a/o3d/core/cross/gles2/buffer_gles2.cc +++ b/o3d/core/cross/gles2/buffer_gles2.cc @@ -30,12 +30,12 @@ */ -// This file contains the implementatinos of VertexBufferGL and -// IndexBufferGL, used to implement O3D using OpenGL. +// This file contains the implementatinos of VertexBufferGLES2 and +// IndexBufferGLES2, used to implement O3D using OpenGLES2. // // To force the vertex and index buffers to be created by Cg Runtime // control, define the compile flag "USE_CG_BUFFERS". This option is off by -// default and buffers are created, locked and managed using the OpenGL +// default and buffers are created, locked and managed using the OpenGLES2 // "ARB_vertex_buffer_object" extension. #include "core/cross/error.h" @@ -68,24 +68,24 @@ GLenum BufferAccessModeToGLenum(Buffer::AccessMode access_mode) { // Vertex Buffers -------------------------------------------------------------- // Initializes the O3D VertexBuffer object but does not allocate an -// OpenGL vertex buffer object yet. -VertexBufferGL::VertexBufferGL(ServiceLocator* service_locator) +// OpenGLES2 vertex buffer object yet. +VertexBufferGLES2::VertexBufferGLES2(ServiceLocator* service_locator) : VertexBuffer(service_locator), - renderer_(static_cast<RendererGL*>( + renderer_(static_cast<RendererGLES2*>( service_locator->GetService<Renderer>())), gl_buffer_(0) { - DLOG(INFO) << "VertexBufferGL Construct"; + DLOG(INFO) << "VertexBufferGLES2 Construct"; } -// Destructor releases the OpenGL VBO. -VertexBufferGL::~VertexBufferGL() { - DLOG(INFO) << "VertexBufferGL Destruct \"" << name() << "\""; +// Destructor releases the OpenGLES2 VBO. +VertexBufferGLES2::~VertexBufferGLES2() { + DLOG(INFO) << "VertexBufferGLES2 Destruct \"" << name() << "\""; ConcreteFree(); } -// Creates a OpenGL vertex buffer of the requested size. -bool VertexBufferGL::ConcreteAllocate(size_t size_in_bytes) { - DLOG(INFO) << "VertexBufferGL Allocate \"" << name() << "\""; +// Creates a OpenGLES2 vertex buffer of the requested size. +bool VertexBufferGLES2::ConcreteAllocate(size_t size_in_bytes) { + DLOG(INFO) << "VertexBufferGLES2 Allocate \"" << name() << "\""; renderer_->MakeCurrentLazy(); ConcreteFree(); // Create a new VBO. @@ -104,7 +104,7 @@ bool VertexBufferGL::ConcreteAllocate(size_t size_in_bytes) { return true; } -void VertexBufferGL::ConcreteFree() { +void VertexBufferGLES2::ConcreteFree() { if (gl_buffer_) { renderer_->MakeCurrentLazy(); glDeleteBuffersARB(1, &gl_buffer_); @@ -113,11 +113,11 @@ void VertexBufferGL::ConcreteFree() { } } -// Calls Lock on the OpenGL buffer to get the address in memory of where the +// Calls Lock on the OpenGLES2 buffer to get the address in memory of where the // buffer data is currently stored. -bool VertexBufferGL::ConcreteLock(Buffer::AccessMode access_mode, - void **buffer_data) { - DLOG(INFO) << "VertexBufferGL Lock \"" << name() << "\""; +bool VertexBufferGLES2::ConcreteLock(Buffer::AccessMode access_mode, + void **buffer_data) { + DLOG(INFO) << "VertexBufferGLES2 Lock \"" << name() << "\""; renderer_->MakeCurrentLazy(); glBindBufferARB(GL_ARRAY_BUFFER_ARB, gl_buffer_); *buffer_data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, @@ -127,7 +127,7 @@ bool VertexBufferGL::ConcreteLock(Buffer::AccessMode access_mode, if (error == GL_OUT_OF_MEMORY) { O3D_ERROR(service_locator()) << "Out of memory for buffer lock."; } else { - O3D_ERROR(service_locator()) << "Unable to lock a GL Array Buffer"; + O3D_ERROR(service_locator()) << "Unable to lock a GLES2 Array Buffer"; } return false; } @@ -135,10 +135,10 @@ bool VertexBufferGL::ConcreteLock(Buffer::AccessMode access_mode, return true; } -// Calls Unlock on the OpenGL buffer to notify that the contents of the buffer -// are now ready for use. -bool VertexBufferGL::ConcreteUnlock() { - DLOG(INFO) << "VertexBufferGL Unlock \"" << name() << "\""; +// Calls Unlock on the OpenGLES2 buffer to notify that the contents of the +// buffer are now ready for use. +bool VertexBufferGLES2::ConcreteUnlock() { + DLOG(INFO) << "VertexBufferGLES2 Unlock \"" << name() << "\""; renderer_->MakeCurrentLazy(); glBindBufferARB(GL_ARRAY_BUFFER_ARB, gl_buffer_); if (!glUnmapBufferARB(GL_ARRAY_BUFFER)) { @@ -148,7 +148,7 @@ bool VertexBufferGL::ConcreteUnlock() { "Buffer was unlocked without first being locked."; } else { O3D_ERROR( - service_locator()) << "Unable to unlock a GL Element Array Buffer"; + service_locator()) << "Unable to unlock a GLES2 Element Array Buffer"; } return false; } @@ -159,26 +159,26 @@ bool VertexBufferGL::ConcreteUnlock() { // Index Buffers --------------------------------------------------------------- -// Initializes the O3D IndexBuffer object but does not create a OpenGL +// Initializes the O3D IndexBuffer object but does not create a OpenGLES2 // buffer yet. -IndexBufferGL::IndexBufferGL(ServiceLocator* service_locator) +IndexBufferGLES2::IndexBufferGLES2(ServiceLocator* service_locator) : IndexBuffer(service_locator), - renderer_(static_cast<RendererGL*>( + renderer_(static_cast<RendererGLES2*>( service_locator->GetService<Renderer>())), gl_buffer_(0) { - DLOG(INFO) << "IndexBufferGL Construct"; + DLOG(INFO) << "IndexBufferGLES2 Construct"; } -// Destructor releases the OpenGL index buffer. -IndexBufferGL::~IndexBufferGL() { - DLOG(INFO) << "IndexBufferGL Destruct \"" << name() << "\""; +// Destructor releases the OpenGLES2 index buffer. +IndexBufferGLES2::~IndexBufferGLES2() { + DLOG(INFO) << "IndexBufferGLES2 Destruct \"" << name() << "\""; ConcreteFree(); } -// Creates a OpenGL index buffer of the requested size. -bool IndexBufferGL::ConcreteAllocate(size_t size_in_bytes) { - DLOG(INFO) << "IndexBufferGL Allocate \"" << name() << "\""; +// Creates a OpenGLES2 index buffer of the requested size. +bool IndexBufferGLES2::ConcreteAllocate(size_t size_in_bytes) { + DLOG(INFO) << "IndexBufferGLES2 Allocate \"" << name() << "\""; renderer_->MakeCurrentLazy(); ConcreteFree(); // Create a new VBO. @@ -195,7 +195,7 @@ bool IndexBufferGL::ConcreteAllocate(size_t size_in_bytes) { return true; } -void IndexBufferGL::ConcreteFree() { +void IndexBufferGLES2::ConcreteFree() { if (gl_buffer_) { renderer_->MakeCurrentLazy(); glDeleteBuffersARB(1, &gl_buffer_); @@ -204,10 +204,10 @@ void IndexBufferGL::ConcreteFree() { } } -// Maps the OpenGL buffer to get the address in memory of the buffer data. -bool IndexBufferGL::ConcreteLock(Buffer::AccessMode access_mode, - void **buffer_data) { - DLOG(INFO) << "IndexBufferGL Lock \"" << name() << "\""; +// Maps the OpenGLES2 buffer to get the address in memory of the buffer data. +bool IndexBufferGLES2::ConcreteLock(Buffer::AccessMode access_mode, + void **buffer_data) { + DLOG(INFO) << "IndexBufferGLES2 Lock \"" << name() << "\""; renderer_->MakeCurrentLazy(); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, gl_buffer_); if (!num_elements()) @@ -220,7 +220,7 @@ bool IndexBufferGL::ConcreteLock(Buffer::AccessMode access_mode, O3D_ERROR(service_locator()) << "Out of memory for buffer lock."; } else { O3D_ERROR( - service_locator()) << "Unable to lock a GL Element Array Buffer"; + service_locator()) << "Unable to lock a GLES2 Element Array Buffer"; } return false; } @@ -228,10 +228,10 @@ bool IndexBufferGL::ConcreteLock(Buffer::AccessMode access_mode, return true; } -// Calls Unlock on the OpenGL buffer to notify that the contents of the buffer -// are now ready for use. -bool IndexBufferGL::ConcreteUnlock() { - DLOG(INFO) << "IndexBufferGL Unlock \"" << name() << "\""; +// Calls Unlock on the OpenGLES2 buffer to notify that the contents of the +// buffer are now ready for use. +bool IndexBufferGLES2::ConcreteUnlock() { + DLOG(INFO) << "IndexBufferGLES2 Unlock \"" << name() << "\""; renderer_->MakeCurrentLazy(); if (!num_elements()) return true; @@ -243,7 +243,7 @@ bool IndexBufferGL::ConcreteUnlock() { "Buffer was unlocked without first being locked."; } else { O3D_ERROR( - service_locator()) << "Unable to unlock a GL Element Array Buffer"; + service_locator()) << "Unable to unlock a GLES2 Element Array Buffer"; } return false; } @@ -251,3 +251,4 @@ bool IndexBufferGL::ConcreteUnlock() { return true; } } // namespace o3d + diff --git a/o3d/core/cross/gles2/buffer_gles2.h b/o3d/core/cross/gles2/buffer_gles2.h index 90a8327..7dda7e1 100644 --- a/o3d/core/cross/gles2/buffer_gles2.h +++ b/o3d/core/cross/gles2/buffer_gles2.h @@ -31,7 +31,7 @@ // This file contains the declaration of the platform specific -// VertexBufferGL and IndexBufferGL objects used by O3D +// VertexBufferGLES2 and IndexBufferGLES2 objects used by O3D #ifndef O3D_CORE_CROSS_GLES2_BUFFER_GLES2_H_ #define O3D_CORE_CROSS_GLES2_BUFFER_GLES2_H_ @@ -41,76 +41,77 @@ namespace o3d { -class RendererGL; +class RendererGLES2; -// VertexBufferGL is a wrapper around an OpenGL Vertex Buffer Object (VBO). -// The buffer starts out empty. Calling Allocate() will reserve video memory -// for the buffer. Buffer contents are are updated by calling Lock() to get a -// pointer to the memory allocated for the buffer, updating that data in place -// and calling Unlock() to notify OpenGL that the edits are done. +// VertexBufferGLES2 is a wrapper around an OpenGLES2 +// Vertex Buffer Object (VBO). The buffer starts out empty. Calling Allocate() +// will reserve video memory for the buffer. Buffer contents are are updated by +// calling Lock() to get a pointer to the memory allocated for the buffer, +// updating that data in place and calling Unlock() to notify OpenGLES2 that the +// edits are done. // // To force the vertex and index buffers to be created by Cg Runtime // control, define the compile flag "USE_CG_BUFFERS". This option is off by -// default and buffers are created, locked and managed using the OpenGL +// default and buffers are created, locked and managed using the OpenGLES2 // "ARB_vertex_buffer_object" extension. -class VertexBufferGL : public VertexBuffer { +class VertexBufferGLES2 : public VertexBuffer { public: - explicit VertexBufferGL(ServiceLocator* service_locator); - ~VertexBufferGL(); + explicit VertexBufferGLES2(ServiceLocator* service_locator); + ~VertexBufferGLES2(); - // Returns the OpenGL vertex buffer Object handle. + // Returns the OpenGLES2 vertex buffer Object handle. GLuint gl_buffer() const { return gl_buffer_; } protected: - // Creates a OpenGL vertex buffer object of the specified size. + // Creates a OpenGLES2 vertex buffer object of the specified size. virtual bool ConcreteAllocate(size_t size_in_bytes); - // Frees the OpenGL vertex buffer object. + // Frees the OpenGLES2 vertex buffer object. virtual void ConcreteFree(); // Returns a pointer to the current contents of the buffer. A matching // call to Unlock is necessary to update the contents of the buffer. virtual bool ConcreteLock(AccessMode access_mode, void** buffer_data); - // Notifies OpenGL that the buffer data has been updated. Unlock is only + // Notifies OpenGLES2 that the buffer data has been updated. Unlock is only // valid if it follows a Lock operation. virtual bool ConcreteUnlock(); private: - RendererGL* renderer_; + RendererGLES2* renderer_; GLuint gl_buffer_; }; -// IndexBufferGL is a wrapper around an OpenGL Index Buffer Object (VBO). -// The buffer starts out empty. A call to Allocate() will create an OpenGL +// IndexBufferGLES2 is a wrapper around an OpenGLES2 Index Buffer Object (VBO). +// The buffer starts out empty. A call to Allocate() will create an OpenGLES2 // index buffer of the requested size. Updates the to the contents of the // buffer are done via the Lock/Unlock calls. -class IndexBufferGL : public IndexBuffer { +class IndexBufferGLES2 : public IndexBuffer { public: - explicit IndexBufferGL(ServiceLocator* service_locator); - ~IndexBufferGL(); + explicit IndexBufferGLES2(ServiceLocator* service_locator); + ~IndexBufferGLES2(); - // Returns the OpenGL vertex buffer Object handle. + // Returns the OpenGLES2 vertex buffer Object handle. GLuint gl_buffer() const { return gl_buffer_; } protected: - // Creates a OpenGL index buffer of the specified size. + // Creates a OpenGLES2 index buffer of the specified size. virtual bool ConcreteAllocate(size_t size_in_bytes); - // Frees the OpenGL vertex buffer object. + // Frees the OpenGLES2 vertex buffer object. virtual void ConcreteFree(); // Returns a pointer to the current contents of the buffer. After calling // Lock, the contents of the buffer can be updated in place. virtual bool ConcreteLock(AccessMode access_mode, void** buffer_data); - // Notifies OpenGL that the buffer data has been updated. Unlock is only + // Notifies OpenGLES2 that the buffer data has been updated. Unlock is only // valid if it follows a Lock operation. virtual bool ConcreteUnlock(); private: - RendererGL* renderer_; + RendererGLES2* renderer_; GLuint gl_buffer_; }; @@ -118,3 +119,4 @@ class IndexBufferGL : public IndexBuffer { #endif // O3D_CORE_CROSS_GLES2_BUFFER_GLES2_H_ + diff --git a/o3d/core/cross/gles2/draw_element_gles2.cc b/o3d/core/cross/gles2/draw_element_gles2.cc index efe3aca..825ebb4 100644 --- a/o3d/core/cross/gles2/draw_element_gles2.cc +++ b/o3d/core/cross/gles2/draw_element_gles2.cc @@ -30,17 +30,17 @@ */ -// This file contains the definition of the DrawElementGL class. +// This file contains the definition of the DrawElementGLES2 class. #include "core/cross/gles2/draw_element_gles2.h" namespace o3d { -DrawElementGL::DrawElementGL(ServiceLocator* service_locator) +DrawElementGLES2::DrawElementGLES2(ServiceLocator* service_locator) : DrawElement(service_locator) { } -DrawElementGL::~DrawElementGL() { +DrawElementGLES2::~DrawElementGLES2() { } } // namespace o3d diff --git a/o3d/core/cross/gles2/draw_element_gles2.h b/o3d/core/cross/gles2/draw_element_gles2.h index a6c769e..ca026d2 100644 --- a/o3d/core/cross/gles2/draw_element_gles2.h +++ b/o3d/core/cross/gles2/draw_element_gles2.h @@ -30,7 +30,7 @@ */ -// This file contains the declaration of the DrawElementGL class. +// This file contains the declaration of the DrawElementGLES2 class. #ifndef O3D_CORE_CROSS_GLES2_DRAW_ELEMENT_GLES2_H_ #define O3D_CORE_CROSS_GLES2_DRAW_ELEMENT_GLES2_H_ @@ -42,16 +42,17 @@ namespace o3d { class Element; -// DrawElementGL is the OpenGL implementation of the DrawElement. It +// DrawElementGLES2 is the OpenGLES2 implementation of the DrawElement. It // provides a place for the renderer to store platform specific cache // information. -class DrawElementGL : public DrawElement { +class DrawElementGLES2 : public DrawElement { public: - explicit DrawElementGL(ServiceLocator* service_locator); - ~DrawElementGL(); + explicit DrawElementGLES2(ServiceLocator* service_locator); + ~DrawElementGLES2(); private: }; } // o3d #endif // O3D_CORE_CROSS_GLES2_DRAW_ELEMENT_GLES2_H_ + diff --git a/o3d/core/cross/gles2/effect_gles2.cc b/o3d/core/cross/gles2/effect_gles2.cc index efff57e..e0dfaca 100644 --- a/o3d/core/cross/gles2/effect_gles2.cc +++ b/o3d/core/cross/gles2/effect_gles2.cc @@ -30,11 +30,11 @@ */ -// This file contains the definition of EffectGL, the OpenGL implementation -// of the abstract O3D class Effect. +// This file contains the definition of EffectGLES2, the OpenGLES2 +// implementation of the abstract O3D class Effect. -// Disable pointer casting warning for openGL calls that require a void* to +// Disable pointer casting warning for OpenGLES2 calls that require a void* to // be cast to a GLuint #if defined(OS_WIN) #pragma warning(disable : 4312) @@ -94,21 +94,21 @@ static const ObjectBase::Class* CgTypeToParamType(CGtype cg_type) { // ----------------------------------------------------------------------------- -EffectGL::EffectGL(ServiceLocator* service_locator, CGcontext cg_context) +EffectGLES2::EffectGLES2(ServiceLocator* service_locator, CGcontext cg_context) : Effect(service_locator), semantic_manager_(service_locator->GetService<SemanticManager>()), - renderer_(static_cast<RendererGL*>( + renderer_(static_cast<RendererGLES2*>( service_locator->GetService<Renderer>())), cg_context_(cg_context), cg_vertex_(NULL), cg_fragment_(NULL) { - DLOG(INFO) << "EffectGL Construct"; + DLOG(INFO) << "EffectGLES2 Construct"; } // Destructor releases vertex and fragment shaders and their correspoding // constants tables. -EffectGL::~EffectGL() { - DLOG(INFO) << "EffectGL Destruct \"" << name() << "\""; +EffectGLES2::~EffectGLES2() { + DLOG(INFO) << "EffectGLES2 Destruct \"" << name() << "\""; if (cg_vertex_) { cgDestroyProgram(cg_vertex_); } @@ -117,7 +117,7 @@ EffectGL::~EffectGL() { } } -// Rewrites vertex program assembly code to match GL semantics for clipping. +// Rewrites vertex program assembly code to match GLES2 semantics for clipping. // This parses the source, breaking it down into pieces: // - declaration ("!!ARBvp1.0") // - comments (that contain the parameter information) @@ -195,8 +195,8 @@ static bool RewriteVertexProgramSource(String *source) { // Initializes the Effect object using the shaders found in an FX formatted // string. -bool EffectGL::LoadFromFXString(const String& effect) { - DLOG(INFO) << "EffectGL LoadFromFXString"; +bool EffectGLES2::LoadFromFXString(const String& effect) { + DLOG(INFO) << "EffectGLES2 LoadFromFXString"; renderer_->MakeCurrentLazy(); set_source(""); @@ -260,17 +260,17 @@ bool EffectGL::LoadFromFXString(const String& effect) { CHECK_GL_ERROR(); // If the program rewrite introduced some syntax or semantic errors, we won't - // know it until we load the program (through a GL error). - // So flush all GL errors first... + // know it until we load the program (through a GLES2 error). + // So flush all GLES2 errors first... do {} while (glGetError() != GL_NO_ERROR); // ... Then load the program ... cgGLLoadProgram(cg_vertex_); - // ... And check for GL errors. + // ... And check for GLES2 errors. if (glGetError() != GL_NO_ERROR) { O3D_ERROR(service_locator()) - << "Effect post-rewrite GL Error: " + << "Effect post-rewrite GLES2 Error: " << glGetString(GL_PROGRAM_ERROR_STRING_ARB) << "\nSource: \n" << vp_assembly; @@ -300,11 +300,11 @@ bool EffectGL::LoadFromFXString(const String& effect) { cgGLLoadProgram(cg_fragment_); - // Also check for GL errors, in case Cg managed to compile, but generated a + // Also check for GLES2 errors, in case Cg managed to compile, but generated a // bad program. if (glGetError() != GL_NO_ERROR) { O3D_ERROR(service_locator()) - << "Effect GL Error: " + << "Effect GLES2 Error: " << glGetString(GL_PROGRAM_ERROR_STRING_ARB); return false; } @@ -324,7 +324,7 @@ bool EffectGL::LoadFromFXString(const String& effect) { // Note that we compile the raw effect, which shouldn't have any // technique/pass, so we don't actually create programs, just parse the // uniforms and state assignments. -void EffectGL::FillSamplerToTextureMap(const String &effect) { +void EffectGLES2::FillSamplerToTextureMap(const String &effect) { CGeffect cg_effect = cgCreateEffect(cg_context_, effect.c_str(), NULL); if (!cg_effect) { DLOG(ERROR) << "Could not compile the effect to find " @@ -360,7 +360,7 @@ void EffectGL::FillSamplerToTextureMap(const String &effect) { } // TODO(o3d): remove this (OLD path for textures). -String EffectGL::GetTextureNameFromSamplerParamName( +String EffectGLES2::GetTextureNameFromSamplerParamName( const String &sampler_name) { std::map<String, String>::iterator it = sampler_to_texture_map_.find(sampler_name); @@ -373,10 +373,10 @@ String EffectGL::GetTextureNameFromSamplerParamName( // Given a CG_SAMPLER parameter, find the corresponding CG_TEXTURE // parameter. From this CG_TEXTURE, find a matching Param by name. -ParamTexture* EffectGL::GetTextureParamFromCgSampler( +ParamTexture* EffectGLES2::GetTextureParamFromCgSampler( CGparameter cg_sampler, const std::vector<ParamObject*> ¶m_objects) { - DLOG(INFO) << "EffectGL GetTextureParamFromCgSampler"; + DLOG(INFO) << "EffectGLES2 GetTextureParamFromCgSampler"; DLOG_ASSERT(cgGetParameterType(cg_sampler) != CG_SAMPLER); String sampler_name = cgGetParameterName(cg_sampler); String param_name = GetTextureNameFromSamplerParamName(sampler_name); @@ -389,7 +389,7 @@ ParamTexture* EffectGL::GetTextureParamFromCgSampler( Param* param = param_objects[i]->GetUntypedParam(param_name); if (param && param->IsA(ParamTexture::GetApparentClass())) { // Success. - DLOG(INFO) << "EffectGL Matched CG_SAMPLER \"" + DLOG(INFO) << "EffectGLES2 Matched CG_SAMPLER \"" << sampler_name << "\" To Param \"" << param_name << "\""; @@ -403,7 +403,7 @@ ParamTexture* EffectGL::GetTextureParamFromCgSampler( return NULL; } -void EffectGL::GetShaderParamInfo( +void EffectGLES2::GetShaderParamInfo( CGprogram program, CGenum name_space, std::map<String, EffectParameterInfo>* info_map) { @@ -480,7 +480,7 @@ void EffectGL::GetShaderParamInfo( } } -void EffectGL::GetParameterInfo(EffectParameterInfoArray* info_array) { +void EffectGLES2::GetParameterInfo(EffectParameterInfoArray* info_array) { DCHECK(info_array); std::map<String, EffectParameterInfo> info_map; renderer_->MakeCurrentLazy(); @@ -503,7 +503,7 @@ void EffectGL::GetParameterInfo(EffectParameterInfoArray* info_array) { base::select2nd<std::map<String, EffectParameterInfo>::value_type>()); } -void EffectGL::GetVaryingVertexShaderParamInfo( +void EffectGLES2::GetVaryingVertexShaderParamInfo( CGprogram program, CGenum name_space, std::vector<EffectStreamInfo>* info_array) { @@ -535,7 +535,7 @@ void EffectGL::GetVaryingVertexShaderParamInfo( } } -void EffectGL::GetStreamInfo( +void EffectGLES2::GetStreamInfo( EffectStreamInfoArray* info_array) { DCHECK(info_array); renderer_->MakeCurrentLazy(); @@ -548,13 +548,14 @@ void EffectGL::GetStreamInfo( // private functions ----------------------------------------------------------- // Loop over all the CG_SAMPLER objects and attach the GLuint handle for the -// GL texture object that we discovered earlier. Then execute the +// GLES2 texture object that we discovered earlier. Then execute the // CGstateassignments in the sampler_state to set up the texture unit. // TODO(o3d): remove this (OLD path for textures). -void EffectGL::SetTexturesFromEffect(ParamCacheGL* param_cache_gl) { - DLOG_FIRST_N(INFO, kNumLoggedEvents) << "EffectGL EnableTexturesFromEffect"; - ParamCacheGL::SamplerParameterMap& map = param_cache_gl->sampler_map(); - ParamCacheGL::SamplerParameterMap::iterator i; +void EffectGLES2::SetTexturesFromEffect(ParamCacheGLES2* param_cache_gl) { + DLOG_FIRST_N(INFO, kNumLoggedEvents) + << "EffectGLES2 EnableTexturesFromEffect"; + ParamCacheGLES2::SamplerParameterMap& map = param_cache_gl->sampler_map(); + ParamCacheGLES2::SamplerParameterMap::iterator i; for (i = map.begin(); i != map.end(); ++i) { CGparameter cg_param = i->first; ParamTexture *param = i->second; @@ -573,12 +574,13 @@ void EffectGL::SetTexturesFromEffect(ParamCacheGL* param_cache_gl) { // Loop through all the uniform CGparameters on the effect and set their // values from their corresponding Params on the various ParamObject (as stored -// in the ParamCacheGL). -void EffectGL::UpdateShaderUniformsFromEffect(ParamCacheGL* param_cache_gl) { +// in the ParamCacheGLES2). +void EffectGLES2::UpdateShaderUniformsFromEffect( + ParamCacheGLES2* param_cache_gl) { DLOG_FIRST_N(INFO, kNumLoggedEvents) - << "EffectGL UpdateShaderUniformsFromEffect"; - ParamCacheGL::UniformParameterMap& map = param_cache_gl->uniform_map(); - ParamCacheGL::UniformParameterMap::iterator i; + << "EffectGLES2 UpdateShaderUniformsFromEffect"; + ParamCacheGLES2::UniformParameterMap& map = param_cache_gl->uniform_map(); + ParamCacheGLES2::UniformParameterMap::iterator i; for (i = map.begin(); i != map.end(); ++i) { CGparameter cg_param = i->first; i->second->SetEffectParam(renderer_, cg_param); @@ -588,10 +590,10 @@ void EffectGL::UpdateShaderUniformsFromEffect(ParamCacheGL* param_cache_gl) { // Loop through all the uniform CGparameters on the effect and reset their // values. For now, this unbinds textures contained in sampler parameters. -void EffectGL::ResetShaderUniforms(ParamCacheGL* param_cache_gl) { - DLOG_FIRST_N(INFO, kNumLoggedEvents) << "EffectGL ResetShaderUniforms"; - ParamCacheGL::UniformParameterMap& map = param_cache_gl->uniform_map(); - ParamCacheGL::UniformParameterMap::iterator i; +void EffectGLES2::ResetShaderUniforms(ParamCacheGLES2* param_cache_gl) { + DLOG_FIRST_N(INFO, kNumLoggedEvents) << "EffectGLES2 ResetShaderUniforms"; + ParamCacheGLES2::UniformParameterMap& map = param_cache_gl->uniform_map(); + ParamCacheGLES2::UniformParameterMap::iterator i; for (i = map.begin(); i != map.end(); ++i) { CGparameter cg_param = i->first; i->second->ResetEffectParam(renderer_, cg_param); @@ -601,8 +603,8 @@ void EffectGL::ResetShaderUniforms(ParamCacheGL* param_cache_gl) { // Updates the values of the vertex and fragment shader parameters using the // current values in the param/cgparam caches. -void EffectGL::PrepareForDraw(ParamCacheGL* param_cache_gl) { - DLOG_FIRST_N(INFO, kNumLoggedEvents) << "EffectGL PrepareForDraw \"" +void EffectGLES2::PrepareForDraw(ParamCacheGLES2* param_cache_gl) { + DLOG_FIRST_N(INFO, kNumLoggedEvents) << "EffectGLES2 PrepareForDraw \"" << name() << "\""; DCHECK(renderer_->IsCurrent()); @@ -623,12 +625,13 @@ void EffectGL::PrepareForDraw(ParamCacheGL* param_cache_gl) { } // Resets the render states back to their default value. -void EffectGL::PostDraw(ParamCacheGL* param_cache_gl) { +void EffectGLES2::PostDraw(ParamCacheGLES2* param_cache_gl) { DLOG_FIRST_N(INFO, kNumLoggedEvents) - << "EffectGL PostDraw \"" << name() << "\""; + << "EffectGLES2 PostDraw \"" << name() << "\""; DCHECK(renderer_->IsCurrent()); ResetShaderUniforms(param_cache_gl); CHECK_GL_ERROR(); } } // namespace o3d + diff --git a/o3d/core/cross/gles2/effect_gles2.h b/o3d/core/cross/gles2/effect_gles2.h index 93bc857..a919fec 100644 --- a/o3d/core/cross/gles2/effect_gles2.h +++ b/o3d/core/cross/gles2/effect_gles2.h @@ -30,12 +30,12 @@ */ -// This file contains the declaration of the EffectGL class. +// This file contains the declaration of the EffectGLES2 class. #ifndef O3D_CORE_CROSS_GLES2_EFFECT_GLES2_H_ #define O3D_CORE_CROSS_GLES2_EFFECT_GLES2_H_ -// Disable compiler warning for openGL calls that require a void* to +// Disable compiler warning for openGLES2 calls that require a void* to // be cast to a GLuint #if defined(OS_WIN) #pragma warning(disable : 4312) @@ -51,36 +51,38 @@ namespace o3d { -class DrawElementGL; -class ParamCacheGL; +class DrawElementGLES2; +class ParamCacheGLES2; class ParamObject; class Param; class ParamTexture; -class RendererGL; +class RendererGLES2; class SemanticManager; // A class to set an effect parameter from an O3D parameter. -class EffectParamHandlerGL : public RefCounted { +class EffectParamHandlerGLES2 : public RefCounted { public: - typedef SmartPointer<EffectParamHandlerGL> Ref; - virtual ~EffectParamHandlerGL() { } + typedef SmartPointer<EffectParamHandlerGLES2> Ref; + virtual ~EffectParamHandlerGLES2() { } - // Sets a GL/Cg Effect Parameter by an O3D Param. - virtual void SetEffectParam(RendererGL* renderer, CGparameter cg_param) = 0; + // Sets a GLES2/Cg Effect Parameter by an O3D Param. + virtual void SetEffectParam( + RendererGLES2* renderer, CGparameter cg_param) = 0; - // Resets a GL/Cg Effect parameter to default (currently only + // Resets a GLES2/Cg Effect parameter to default (currently only // unbinds textures contained in Sampler params). - virtual void ResetEffectParam(RendererGL* renderer, CGparameter cg_param) {} + virtual void ResetEffectParam( + RendererGLES2* renderer, CGparameter cg_param) {} }; -// EffectGL is an implementation of the Effect object for OpenGL. It +// EffectGLES2 is an implementation of the Effect object for OpenGLES2. It // provides the API for setting the vertex and framgent shaders for the // Effect using the Cg Runtime. Currently the two shaders can either be // provided separately as shader code or together in an FX file. -class EffectGL : public Effect { +class EffectGLES2 : public Effect { public: - EffectGL(ServiceLocator* service_locator, CGcontext cg_context); - virtual ~EffectGL(); + EffectGLES2(ServiceLocator* service_locator, CGcontext cg_context); + virtual ~EffectGLES2(); // Reads the vertex and fragment shaders from string in the FX format. // It returns true if the shaders were successfully compiled. @@ -88,10 +90,10 @@ class EffectGL : public Effect { // Binds the shaders to the device and sets up all the shader parameters using // the values from the matching Param's of the param_object. - void PrepareForDraw(ParamCacheGL* param_cache_gl); + void PrepareForDraw(ParamCacheGLES2* param_cache_gl); // Removes any pipeline state-changes installed during a draw. - void PostDraw(ParamCacheGL* param_cache_gl); + void PostDraw(ParamCacheGLES2* param_cache_gl); // Gets info about the parameters this effect needs. // Overriden from Effect. @@ -105,7 +107,7 @@ class EffectGL : public Effect { // Given a CG_SAMPLER parameter, find the corresponding CG_TEXTURE // parameterand from this CG_TEXTURE, find a matching Param by name in a list // of ParamObject. - // TODO: remove this (OLD path for textures). + // TODO(o3d): remove this (OLD path for textures). ParamTexture* GetTextureParamFromCgSampler( CGparameter cg_sampler, const std::vector<ParamObject*> ¶m_objects); @@ -114,11 +116,11 @@ class EffectGL : public Effect { CGprogram cg_fragment_program() { return cg_fragment_; } private: - // Loops through all the parameters in the ShapeDataGL and updates the - // corresponding parameter EffectGL object - void UpdateShaderUniformsFromEffect(ParamCacheGL* param_cache_gl); + // Loops through all the parameters in the ShapeDataGLES2 and updates the + // corresponding parameter EffectGLES2 object + void UpdateShaderUniformsFromEffect(ParamCacheGLES2* param_cache_gl); // Undoes the effect of the above. For now, this unbinds textures. - void ResetShaderUniforms(ParamCacheGL* param_cache_gl); + void ResetShaderUniforms(ParamCacheGLES2* param_cache_gl); void GetShaderParamInfo(CGprogram program, CGenum name_space, std::map<String, EffectParameterInfo>* info_map); @@ -127,21 +129,22 @@ class EffectGL : public Effect { CGenum name_space, std::vector<EffectStreamInfo>* info_array); - // TODO: remove these (OLD path for textures). - void SetTexturesFromEffect(ParamCacheGL* param_cache_gl); + // TODO(o3d): remove these (OLD path for textures). + void SetTexturesFromEffect(ParamCacheGLES2* param_cache_gl); void FillSamplerToTextureMap(const String &effect); String GetTextureNameFromSamplerParamName(const String &sampler_name); SemanticManager* semantic_manager_; - RendererGL* renderer_; + RendererGLES2* renderer_; CGcontext cg_context_; CGprogram cg_vertex_; CGprogram cg_fragment_; - // TODO: remove this (OLD path for textures). + // TODO(o3d): remove this (OLD path for textures). std::map<String, String> sampler_to_texture_map_; }; } // namespace o3d #endif // O3D_CORE_CROSS_GLES2_EFFECT_GLES2_H_ + diff --git a/o3d/core/cross/gles2/param_cache_gles2.cc b/o3d/core/cross/gles2/param_cache_gles2.cc index dc42a45..8d3371a 100644 --- a/o3d/core/cross/gles2/param_cache_gles2.cc +++ b/o3d/core/cross/gles2/param_cache_gles2.cc @@ -30,7 +30,7 @@ */ -// This file contains the definition of the ParamCacheGL class. +// This file contains the definition of the ParamCacheGLES2 class. #include "core/cross/error.h" #include "core/cross/param_array.h" @@ -47,29 +47,29 @@ namespace o3d { typedef std::vector<ParamObject *> ParamObjectList; -ParamCacheGL::ParamCacheGL(SemanticManager* semantic_manager, - Renderer* renderer) +ParamCacheGLES2::ParamCacheGLES2(SemanticManager* semantic_manager, + Renderer* renderer) : semantic_manager_(semantic_manager), renderer_(renderer), last_vertex_program_(0), last_fragment_program_(0) { } -bool ParamCacheGL::ValidateEffect(Effect* effect) { +bool ParamCacheGLES2::ValidateEffect(Effect* effect) { DLOG_ASSERT(effect); - EffectGL* effect_gl = down_cast<EffectGL*>(effect); + EffectGLES2* effect_gl = down_cast<EffectGLES2*>(effect); return (effect_gl->cg_vertex_program() == last_vertex_program_ || effect_gl->cg_fragment_program() == last_fragment_program_); } -void ParamCacheGL::UpdateCache(Effect* effect, - DrawElement* draw_element, - Element* element, - Material* material, - ParamObject* override) { +void ParamCacheGLES2::UpdateCache(Effect* effect, + DrawElement* draw_element, + Element* element, + Material* material, + ParamObject* override) { DLOG_ASSERT(effect); - EffectGL* effect_gl = down_cast<EffectGL*>(effect); + EffectGLES2* effect_gl = down_cast<EffectGLES2*>(effect); ScanCgEffectParameters(effect_gl->cg_vertex_program(), effect_gl->cg_fragment_program(), @@ -83,22 +83,22 @@ void ParamCacheGL::UpdateCache(Effect* effect, } template <typename T> -class TypedEffectParamHandlerGL : public EffectParamHandlerGL { +class TypedEffectParamHandlerGLES2 : public EffectParamHandlerGLES2 { public: - explicit TypedEffectParamHandlerGL(T* param) + explicit TypedEffectParamHandlerGLES2(T* param) : param_(param) { } - virtual void SetEffectParam(RendererGL* renderer, CGparameter cg_param); + virtual void SetEffectParam(RendererGLES2* renderer, CGparameter cg_param); private: T* param_; }; -class EffectParamHandlerGLMatrixRows : public EffectParamHandlerGL { +class EffectParamHandlerGLMatrixRows : public EffectParamHandlerGLES2 { public: explicit EffectParamHandlerGLMatrixRows(ParamMatrix4* param) : param_(param) { } - virtual void SetEffectParam(RendererGL* renderer, CGparameter cg_param) { + virtual void SetEffectParam(RendererGLES2* renderer, CGparameter cg_param) { // set the data as floats in row major order. Matrix4 mat = param_->value(); cgSetMatrixParameterfr(cg_param, &mat[0][0]); @@ -107,12 +107,12 @@ class EffectParamHandlerGLMatrixRows : public EffectParamHandlerGL { ParamMatrix4* param_; }; -class EffectParamHandlerGLMatrixColumns : public EffectParamHandlerGL { +class EffectParamHandlerGLMatrixColumns : public EffectParamHandlerGLES2 { public: explicit EffectParamHandlerGLMatrixColumns(ParamMatrix4* param) : param_(param) { } - virtual void SetEffectParam(RendererGL* renderer, CGparameter cg_param) { + virtual void SetEffectParam(RendererGLES2* renderer, CGparameter cg_param) { // set the data as floats in column major order. Matrix4 mat = param_->value(); cgSetMatrixParameterfc(cg_param, &mat[0][0]); @@ -122,63 +122,63 @@ class EffectParamHandlerGLMatrixColumns : public EffectParamHandlerGL { }; template <> -void TypedEffectParamHandlerGL<ParamFloat>::SetEffectParam( - RendererGL* renderer, +void TypedEffectParamHandlerGLES2<ParamFloat>::SetEffectParam( + RendererGLES2* renderer, CGparameter cg_param) { Float f = param_->value(); cgSetParameter1f(cg_param, f); }; template <> -void TypedEffectParamHandlerGL<ParamFloat2>::SetEffectParam( - RendererGL* renderer, +void TypedEffectParamHandlerGLES2<ParamFloat2>::SetEffectParam( + RendererGLES2* renderer, CGparameter cg_param) { Float2 f = param_->value(); cgSetParameter2fv(cg_param, f.GetFloatArray()); }; template <> -void TypedEffectParamHandlerGL<ParamFloat3>::SetEffectParam( - RendererGL* renderer, +void TypedEffectParamHandlerGLES2<ParamFloat3>::SetEffectParam( + RendererGLES2* renderer, CGparameter cg_param) { Float3 f = param_->value(); cgSetParameter3fv(cg_param, f.GetFloatArray()); }; template <> -void TypedEffectParamHandlerGL<ParamFloat4>::SetEffectParam( - RendererGL* renderer, +void TypedEffectParamHandlerGLES2<ParamFloat4>::SetEffectParam( + RendererGLES2* renderer, CGparameter cg_param) { Float4 f = param_->value(); cgSetParameter4fv(cg_param, f.GetFloatArray()); }; template <> -void TypedEffectParamHandlerGL<ParamInteger>::SetEffectParam( - RendererGL* renderer, +void TypedEffectParamHandlerGLES2<ParamInteger>::SetEffectParam( + RendererGLES2* renderer, CGparameter cg_param) { int i = param_->value(); cgSetParameter1i(cg_param, i); }; template <> -void TypedEffectParamHandlerGL<ParamBoolean>::SetEffectParam( - RendererGL* renderer, +void TypedEffectParamHandlerGLES2<ParamBoolean>::SetEffectParam( + RendererGLES2* renderer, CGparameter cg_param) { int i = param_->value(); cgSetParameter1i(cg_param, i); }; -class EffectParamHandlerForSamplersGL : public EffectParamHandlerGL { +class EffectParamHandlerForSamplersGLES2 : public EffectParamHandlerGLES2 { public: - explicit EffectParamHandlerForSamplersGL(ParamSampler* param) + explicit EffectParamHandlerForSamplersGLES2(ParamSampler* param) : param_(param) { } - virtual void SetEffectParam(RendererGL* renderer, CGparameter cg_param) { - SamplerGL* sampler_gl = down_cast<SamplerGL*>(param_->value()); + virtual void SetEffectParam(RendererGLES2* renderer, CGparameter cg_param) { + SamplerGLES2* sampler_gl = down_cast<SamplerGLES2*>(param_->value()); if (!sampler_gl) { // Use the error sampler. - sampler_gl = down_cast<SamplerGL*>(renderer->error_sampler()); + sampler_gl = down_cast<SamplerGLES2*>(renderer->error_sampler()); // If no error texture is set then generate an error. if (!renderer->error_texture()) { O3D_ERROR(param_->service_locator()) @@ -187,10 +187,10 @@ class EffectParamHandlerForSamplersGL : public EffectParamHandlerGL { } sampler_gl->SetTextureAndStates(cg_param); } - virtual void ResetEffectParam(RendererGL* renderer, CGparameter cg_param) { - SamplerGL* sampler_gl = down_cast<SamplerGL*>(param_->value()); + virtual void ResetEffectParam(RendererGLES2* renderer, CGparameter cg_param) { + SamplerGLES2* sampler_gl = down_cast<SamplerGLES2*>(param_->value()); if (!sampler_gl) { - sampler_gl = down_cast<SamplerGL*>(renderer->error_sampler()); + sampler_gl = down_cast<SamplerGLES2*>(renderer->error_sampler()); } sampler_gl->ResetTexture(cg_param); } @@ -199,12 +199,12 @@ class EffectParamHandlerForSamplersGL : public EffectParamHandlerGL { }; template <typename T> -class EffectParamArrayHandlerGL : public EffectParamHandlerGL { +class EffectParamArrayHandlerGLES2 : public EffectParamHandlerGLES2 { public: - explicit EffectParamArrayHandlerGL(ParamParamArray* param) + explicit EffectParamArrayHandlerGLES2(ParamParamArray* param) : param_(param) { } - virtual void SetEffectParam(RendererGL* renderer, CGparameter cg_param) { + virtual void SetEffectParam(RendererGLES2* renderer, CGparameter cg_param) { ParamArray* param = param_->value(); if (param) { int size = cgGetArraySize(cg_param, 0); @@ -237,12 +237,12 @@ class EffectParamArrayHandlerGL : public EffectParamHandlerGL { }; template <bool column_major> -class EffectParamArrayMatrix4HandlerGL : public EffectParamHandlerGL { +class EffectParamArrayMatrix4HandlerGLES2 : public EffectParamHandlerGLES2 { public: - explicit EffectParamArrayMatrix4HandlerGL(ParamParamArray* param) + explicit EffectParamArrayMatrix4HandlerGLES2(ParamParamArray* param) : param_(param) { } - virtual void SetEffectParam(RendererGL* renderer, CGparameter cg_param) { + virtual void SetEffectParam(RendererGLES2* renderer, CGparameter cg_param) { ParamArray* param = param_->value(); if (param) { int size = cgGetArraySize(cg_param, 0); @@ -274,12 +274,12 @@ class EffectParamArrayMatrix4HandlerGL : public EffectParamHandlerGL { ParamParamArray* param_; }; -class EffectParamArraySamplerHandlerGL : public EffectParamHandlerGL { +class EffectParamArraySamplerHandlerGLES2 : public EffectParamHandlerGLES2 { public: - explicit EffectParamArraySamplerHandlerGL(ParamParamArray* param) + explicit EffectParamArraySamplerHandlerGLES2(ParamParamArray* param) : param_(param) { } - virtual void SetEffectParam(RendererGL* renderer, CGparameter cg_param) { + virtual void SetEffectParam(RendererGLES2* renderer, CGparameter cg_param) { ParamArray* param = param_->value(); if (param) { int size = cgGetArraySize(cg_param, 0); @@ -296,10 +296,11 @@ class EffectParamArraySamplerHandlerGL : public EffectParamHandlerGL { if (untyped_element->IsA(ParamSampler::GetApparentClass())) { CGparameter cg_element = cgGetArrayParameter(cg_param, i); ParamSampler* element = down_cast<ParamSampler*>(untyped_element); - SamplerGL* sampler_gl = down_cast<SamplerGL*>(element->value()); + SamplerGLES2* sampler_gl = + down_cast<SamplerGLES2*>(element->value()); if (!sampler_gl) { // Use the error sampler. - sampler_gl = down_cast<SamplerGL*>(renderer->error_sampler()); + sampler_gl = down_cast<SamplerGLES2*>(renderer->error_sampler()); // If no error texture is set then generate an error. if (!renderer->error_texture()) { O3D_ERROR(param_->service_locator()) @@ -317,7 +318,7 @@ class EffectParamArraySamplerHandlerGL : public EffectParamHandlerGL { } } } - virtual void ResetEffectParam(RendererGL* renderer, CGparameter cg_param) { + virtual void ResetEffectParam(RendererGLES2* renderer, CGparameter cg_param) { ParamArray* param = param_->value(); if (param) { int size = cgGetArraySize(cg_param, 0); @@ -327,9 +328,10 @@ class EffectParamArraySamplerHandlerGL : public EffectParamHandlerGL { if (untyped_element->IsA(ParamSampler::GetApparentClass())) { CGparameter cg_element = cgGetArrayParameter(cg_param, i); ParamSampler* element = down_cast<ParamSampler*>(untyped_element); - SamplerGL* sampler_gl = down_cast<SamplerGL*>(element->value()); + SamplerGLES2* sampler_gl = + down_cast<SamplerGLES2*>(element->value()); if (!sampler_gl) { - sampler_gl = down_cast<SamplerGL*>(renderer->error_sampler()); + sampler_gl = down_cast<SamplerGLES2*>(renderer->error_sampler()); } sampler_gl->ResetTexture(cg_element); } @@ -343,14 +345,14 @@ class EffectParamArraySamplerHandlerGL : public EffectParamHandlerGL { }; template<> -void EffectParamArrayHandlerGL<ParamFloat>::SetElement( +void EffectParamArrayHandlerGLES2<ParamFloat>::SetElement( CGparameter cg_element, ParamFloat* param) { cgSetParameter1f(cg_element, param->value()); } template<> -void EffectParamArrayHandlerGL<ParamFloat2>::SetElement( +void EffectParamArrayHandlerGLES2<ParamFloat2>::SetElement( CGparameter cg_element, ParamFloat2* param) { Float2 f = param->value(); @@ -358,7 +360,7 @@ void EffectParamArrayHandlerGL<ParamFloat2>::SetElement( } template<> -void EffectParamArrayHandlerGL<ParamFloat3>::SetElement( +void EffectParamArrayHandlerGLES2<ParamFloat3>::SetElement( CGparameter cg_element, ParamFloat3* param) { Float3 f = param->value(); @@ -366,7 +368,7 @@ void EffectParamArrayHandlerGL<ParamFloat3>::SetElement( } template<> -void EffectParamArrayHandlerGL<ParamFloat4>::SetElement( +void EffectParamArrayHandlerGLES2<ParamFloat4>::SetElement( CGparameter cg_element, ParamFloat4* param) { Float4 f = param->value(); @@ -374,7 +376,7 @@ void EffectParamArrayHandlerGL<ParamFloat4>::SetElement( } template<> -void EffectParamArrayMatrix4HandlerGL<false>::SetElement( +void EffectParamArrayMatrix4HandlerGLES2<false>::SetElement( CGparameter cg_element, ParamMatrix4* param) { // set the data as floats in row major order. @@ -383,7 +385,7 @@ void EffectParamArrayMatrix4HandlerGL<false>::SetElement( } template<> -void EffectParamArrayMatrix4HandlerGL<true>::SetElement( +void EffectParamArrayMatrix4HandlerGLES2<true>::SetElement( CGparameter cg_element, ParamMatrix4* param) { // set the data as floats in column major order. @@ -392,70 +394,71 @@ void EffectParamArrayMatrix4HandlerGL<true>::SetElement( } template<> -void EffectParamArrayHandlerGL<ParamInteger>::SetElement( +void EffectParamArrayHandlerGLES2<ParamInteger>::SetElement( CGparameter cg_element, ParamInteger* param) { cgSetParameter1i(cg_element, param->value()); } template<> -void EffectParamArrayHandlerGL<ParamBoolean>::SetElement( +void EffectParamArrayHandlerGLES2<ParamBoolean>::SetElement( CGparameter cg_element, ParamBoolean* param) { cgSetParameter1i(cg_element, param->value()); } -static EffectParamHandlerGL::Ref GetHandlerFromParamAndCgType( - EffectGL* effect_gl, +static EffectParamHandlerGLES2::Ref GetHandlerFromParamAndCgType( + EffectGLES2* effect_gl, Param *param, CGtype cg_type) { - EffectParamHandlerGL::Ref handler; + EffectParamHandlerGLES2::Ref handler; if (param->IsA(ParamParamArray::GetApparentClass())) { ParamParamArray* param_param_array = down_cast<ParamParamArray*>(param); switch (cg_type) { case CG_FLOAT: case CG_FLOAT1: - handler = EffectParamHandlerGL::Ref( - new EffectParamArrayHandlerGL<ParamFloat>(param_param_array)); + handler = EffectParamHandlerGLES2::Ref( + new EffectParamArrayHandlerGLES2<ParamFloat>(param_param_array)); break; case CG_FLOAT2: - handler = EffectParamHandlerGL::Ref( - new EffectParamArrayHandlerGL<ParamFloat2>(param_param_array)); + handler = EffectParamHandlerGLES2::Ref( + new EffectParamArrayHandlerGLES2<ParamFloat2>(param_param_array)); break; case CG_FLOAT3: - handler = EffectParamHandlerGL::Ref( - new EffectParamArrayHandlerGL<ParamFloat3>(param_param_array)); + handler = EffectParamHandlerGLES2::Ref( + new EffectParamArrayHandlerGLES2<ParamFloat3>(param_param_array)); break; case CG_FLOAT4: - handler = EffectParamHandlerGL::Ref( - new EffectParamArrayHandlerGL<ParamFloat4>(param_param_array)); + handler = EffectParamHandlerGLES2::Ref( + new EffectParamArrayHandlerGLES2<ParamFloat4>(param_param_array)); break; case CG_FLOAT4x4: if (effect_gl->matrix_load_order() == Effect::COLUMN_MAJOR) { - handler = EffectParamHandlerGL::Ref( - new EffectParamArrayMatrix4HandlerGL<true>(param_param_array)); + handler = EffectParamHandlerGLES2::Ref( + new EffectParamArrayMatrix4HandlerGLES2<true>(param_param_array)); } else { - handler = EffectParamHandlerGL::Ref( - new EffectParamArrayMatrix4HandlerGL<false>(param_param_array)); + handler = EffectParamHandlerGLES2::Ref( + new EffectParamArrayMatrix4HandlerGLES2<false>( + param_param_array)); } break; case CG_INT: case CG_INT1: - handler = EffectParamHandlerGL::Ref( - new EffectParamArrayHandlerGL<ParamInteger>(param_param_array)); + handler = EffectParamHandlerGLES2::Ref( + new EffectParamArrayHandlerGLES2<ParamInteger>(param_param_array)); break; case CG_BOOL: case CG_BOOL1: - handler = EffectParamHandlerGL::Ref( - new EffectParamArrayHandlerGL<ParamBoolean>(param_param_array)); + handler = EffectParamHandlerGLES2::Ref( + new EffectParamArrayHandlerGLES2<ParamBoolean>(param_param_array)); break; case CG_SAMPLER: case CG_SAMPLER1D: case CG_SAMPLER2D: case CG_SAMPLER3D: case CG_SAMPLERCUBE: - handler = EffectParamHandlerGL::Ref( - new EffectParamArraySamplerHandlerGL(param_param_array)); + handler = EffectParamHandlerGLES2::Ref( + new EffectParamArraySamplerHandlerGLES2(param_param_array)); break; default: break; @@ -464,12 +467,12 @@ static EffectParamHandlerGL::Ref GetHandlerFromParamAndCgType( if (cg_type == CG_FLOAT4x4) { if (effect_gl->matrix_load_order() == Effect::COLUMN_MAJOR) { // set the data as floats in column major order. - handler = EffectParamHandlerGL::Ref( + handler = EffectParamHandlerGLES2::Ref( new EffectParamHandlerGLMatrixColumns( down_cast<ParamMatrix4*>(param))); } else { // set the data as floats in row major order. - handler = EffectParamHandlerGL::Ref( + handler = EffectParamHandlerGLES2::Ref( new EffectParamHandlerGLMatrixRows( down_cast<ParamMatrix4*>(param))); } @@ -477,38 +480,38 @@ static EffectParamHandlerGL::Ref GetHandlerFromParamAndCgType( } else if (param->IsA(ParamFloat::GetApparentClass())) { if (cg_type == CG_FLOAT || cg_type == CG_FLOAT1) { - handler = EffectParamHandlerGL::Ref( - new TypedEffectParamHandlerGL<ParamFloat>( + handler = EffectParamHandlerGLES2::Ref( + new TypedEffectParamHandlerGLES2<ParamFloat>( down_cast<ParamFloat*>(param))); } } else if (param->IsA(ParamFloat2::GetApparentClass())) { if (cg_type == CG_FLOAT2) { - handler = EffectParamHandlerGL::Ref( - new TypedEffectParamHandlerGL<ParamFloat2>( + handler = EffectParamHandlerGLES2::Ref( + new TypedEffectParamHandlerGLES2<ParamFloat2>( down_cast<ParamFloat2*>(param))); } } else if (param->IsA(ParamFloat3::GetApparentClass())) { if (cg_type == CG_FLOAT3) { - handler = EffectParamHandlerGL::Ref( - new TypedEffectParamHandlerGL<ParamFloat3>( + handler = EffectParamHandlerGLES2::Ref( + new TypedEffectParamHandlerGLES2<ParamFloat3>( down_cast<ParamFloat3*>(param))); } } else if (param->IsA(ParamFloat4::GetApparentClass())) { if (cg_type == CG_FLOAT4) { - handler = EffectParamHandlerGL::Ref( - new TypedEffectParamHandlerGL<ParamFloat4>( + handler = EffectParamHandlerGLES2::Ref( + new TypedEffectParamHandlerGLES2<ParamFloat4>( down_cast<ParamFloat4*>(param))); } } else if (param->IsA(ParamInteger::GetApparentClass())) { if (cg_type == CG_INT || cg_type == CG_INT1) { - handler = EffectParamHandlerGL::Ref( - new TypedEffectParamHandlerGL<ParamInteger>( + handler = EffectParamHandlerGLES2::Ref( + new TypedEffectParamHandlerGLES2<ParamInteger>( down_cast<ParamInteger*>(param))); } } else if (param->IsA(ParamBoolean::GetApparentClass())) { if (cg_type == CG_BOOL || cg_type == CG_BOOL1) { - handler = EffectParamHandlerGL::Ref( - new TypedEffectParamHandlerGL<ParamBoolean>( + handler = EffectParamHandlerGLES2::Ref( + new TypedEffectParamHandlerGLES2<ParamBoolean>( down_cast<ParamBoolean*>(param))); } } else if (param->IsA(ParamSampler::GetApparentClass())) { @@ -517,8 +520,8 @@ static EffectParamHandlerGL::Ref GetHandlerFromParamAndCgType( cg_type == CG_SAMPLER2D || cg_type == CG_SAMPLER3D || cg_type == CG_SAMPLERCUBE) { - handler = EffectParamHandlerGL::Ref( - new EffectParamHandlerForSamplersGL( + handler = EffectParamHandlerGLES2::Ref( + new EffectParamHandlerForSamplersGLES2( down_cast<ParamSampler*>(param))); } } @@ -529,7 +532,7 @@ static EffectParamHandlerGL::Ref GetHandlerFromParamAndCgType( // program or effect and recording their entries into the varying map. static void ScanVaryingParameters(CGprogram program, CGenum name_space, - ParamCacheGL* param_cache_gl) { + ParamCacheGLES2* param_cache_gl) { CGparameter cg_param = cgGetFirstLeafParameter(program, name_space); for (; cg_param; cg_param = cgGetNextLeafParameter(cg_param)) { if (!cgIsParameterReferenced(cg_param)) @@ -544,7 +547,7 @@ static void ScanVaryingParameters(CGprogram program, param_cache_gl->varying_map().end()) { const char* cg_name = cgGetParameterName(cg_param); param_cache_gl->varying_map().insert(std::make_pair(cg_param, -1)); - DLOG(INFO) << "ElementGL Found CG_VARYING \"" + DLOG(INFO) << "ElementGLES2 Found CG_VARYING \"" << cg_name << " : " << cgGetParameterSemantic(cg_param) << "\""; } @@ -558,9 +561,9 @@ static void ScanUniformParameters(SemanticManager* semantic_manager, Renderer* renderer, CGprogram program, CGenum name_space, - ParamCacheGL* param_cache_gl, + ParamCacheGLES2* param_cache_gl, const ParamObjectList& param_objects, - EffectGL* effect_gl) { + EffectGLES2* effect_gl) { CGparameter cg_param = cgGetFirstParameter(program, name_space); for (; cg_param; cg_param = cgGetNextParameter(cg_param)) { if (!cgIsParameterReferenced(cg_param)) @@ -617,7 +620,7 @@ static void ScanUniformParameters(SemanticManager* semantic_manager, // semantic from the shader source code, so this match is valid. sem_class = semantic_manager->LookupSemantic(cg_semantic); } - EffectParamHandlerGL::Ref handler; + EffectParamHandlerGLES2::Ref handler; // Look through all the param objects to find a matching param. unsigned last = param_objects.size() - 1; for (unsigned int i = 0; i < param_objects.size(); ++i) { @@ -651,14 +654,14 @@ static void ScanUniformParameters(SemanticManager* semantic_manager, if (!handler.IsNull()) { param_cache_gl->uniform_map().insert( std::make_pair(cg_param, handler)); - DLOG(INFO) << "ElementGL Matched CG_PARAMETER \"" + DLOG(INFO) << "ElementGLES2 Matched CG_PARAMETER \"" << cg_name << "\" to Param \"" << param->name() << "\" from \"" << param_object->name() << "\""; break; } else { // We found a param, but it didn't match the type. keep looking. - DLOG(ERROR) << "ElementGL Param \"" + DLOG(ERROR) << "ElementGLES2 Param \"" << param->name() << "\" type \"" << param->GetClassName() << "\" from \"" << param_object->name() @@ -677,10 +680,10 @@ static void ScanUniformParameters(SemanticManager* semantic_manager, static void DoScanCgEffectParameters(SemanticManager* semantic_manager, Renderer* renderer, - ParamCacheGL* param_cache_gl, + ParamCacheGLES2* param_cache_gl, CGprogram cg_vertex, CGprogram cg_fragment, - EffectGL* effect_gl, + EffectGLES2* effect_gl, const ParamObjectList& param_objects) { ScanVaryingParameters(cg_vertex, CG_PROGRAM, param_cache_gl); ScanVaryingParameters(cg_vertex, CG_GLOBAL, param_cache_gl); @@ -719,17 +722,17 @@ static void DoScanCgEffectParameters(SemanticManager* semantic_manager, // using cgGetFirstEffectParameter() / cgGetFirstLeafParameter() / // cgGetNextLeafParameter(). Add the CGparameters found to the parameter // maps on the DrawElement. -void ParamCacheGL::ScanCgEffectParameters(CGprogram cg_vertex, - CGprogram cg_fragment, - ParamObject* draw_element, - ParamObject* element, - Material* material, - ParamObject* override) { - DLOG(INFO) << "DrawElementGL ScanCgEffectParameters"; +void ParamCacheGLES2::ScanCgEffectParameters(CGprogram cg_vertex, + CGprogram cg_fragment, + ParamObject* draw_element, + ParamObject* element, + Material* material, + ParamObject* override) { + DLOG(INFO) << "DrawElementGLES2 ScanCgEffectParameters"; DLOG_ASSERT(material); DLOG_ASSERT(draw_element); DLOG_ASSERT(element); - EffectGL* effect_gl = static_cast<EffectGL*>(material->effect()); + EffectGLES2* effect_gl = static_cast<EffectGLES2*>(material->effect()); DLOG_ASSERT(effect_gl); if (cg_vertex == NULL) { DLOG(ERROR) << "Can't scan an empty Vertex Program for Cg Parameters."; @@ -760,3 +763,4 @@ void ParamCacheGL::ScanCgEffectParameters(CGprogram cg_vertex, } } // namespace o3d + diff --git a/o3d/core/cross/gles2/param_cache_gles2.h b/o3d/core/cross/gles2/param_cache_gles2.h index d8f14c9..2d1d771 100644 --- a/o3d/core/cross/gles2/param_cache_gles2.h +++ b/o3d/core/cross/gles2/param_cache_gles2.h @@ -30,7 +30,7 @@ */ -// This file contains the declaration of the ParamCacheGL class. +// This file contains the declaration of the ParamCacheGLES2 class. #ifndef O3D_CORE_CROSS_GLES2_PARAM_CACHE_GLES2_H_ #define O3D_CORE_CROSS_GLES2_PARAM_CACHE_GLES2_H_ @@ -45,12 +45,12 @@ namespace o3d { class ParamTexture; class SemanticManager; -class ParamCacheGL : public ParamCache { +class ParamCacheGLES2 : public ParamCache { public: - ParamCacheGL(SemanticManager* semantic_manager, Renderer* renderer); + ParamCacheGLES2(SemanticManager* semantic_manager, Renderer* renderer); typedef std::map<CGparameter, int> VaryingParameterMap; - typedef std::map<CGparameter, EffectParamHandlerGL::Ref> UniformParameterMap; + typedef std::map<CGparameter, EffectParamHandlerGLES2::Ref> UniformParameterMap; typedef std::map<CGparameter, ParamTexture*> SamplerParameterMap; // Overridden from ParamCache. @@ -95,9 +95,10 @@ class ParamCacheGL : public ParamCache { // A map of uniform CGparameter to Param objects. UniformParameterMap uniform_map_; // A map of uniform CG_SAMPLER CGparameters to ParamTexture objects. - // TODO: remove this (OLD path for textures). + // TODO(o3d): remove this (OLD path for textures). SamplerParameterMap sampler_map_; }; } // o3d #endif // O3D_CORE_CROSS_GLES2_PARAM_CACHE_GLES2_H_ + diff --git a/o3d/core/cross/gles2/primitive_gles2.cc b/o3d/core/cross/gles2/primitive_gles2.cc index 3770ca2..ec63fdb 100644 --- a/o3d/core/cross/gles2/primitive_gles2.cc +++ b/o3d/core/cross/gles2/primitive_gles2.cc @@ -30,7 +30,7 @@ */ -// This file contains the definition of PrimitiveGL. +// This file contains the definition of PrimitiveGLES2. #include <algorithm> @@ -55,15 +55,15 @@ namespace o3d { // Number of times to log a repeated event before giving up. const int kNumLoggedEvents = 5; -// PrimitiveGL functions ------------------------------------------------------- +// PrimitiveGLES2 functions ---------------------------------------------------- -PrimitiveGL::PrimitiveGL(ServiceLocator* service_locator) +PrimitiveGLES2::PrimitiveGLES2(ServiceLocator* service_locator) : Primitive(service_locator) { - DLOG(INFO) << "PrimitiveGL Construct"; + DLOG(INFO) << "PrimitiveGLES2 Construct"; } -PrimitiveGL::~PrimitiveGL() { - DLOG(INFO) << "PrimitiveGL Destruct"; +PrimitiveGLES2::~PrimitiveGLES2() { + DLOG(INFO) << "PrimitiveGLES2 Destruct"; } // Binds the vertex and index streams required to draw the shape. If the @@ -71,28 +71,29 @@ PrimitiveGL::~PrimitiveGL() { // was called (or it's the first time it's getting called) then it forces // an update of the mapping between the Shape Param's and the shader parameters // and also fills in for any missing streams. -void PrimitiveGL::PlatformSpecificRender(Renderer* renderer, - DrawElement* draw_element, - Material* material, - ParamObject* override, - ParamCache* param_cache) { +void PrimitiveGLES2::PlatformSpecificRender(Renderer* renderer, + DrawElement* draw_element, + Material* material, + ParamObject* override, + ParamCache* param_cache) { DLOG_ASSERT(material); DLOG_ASSERT(draw_element); DLOG_ASSERT(param_cache); - DLOG_FIRST_N(INFO, kNumLoggedEvents) << "PrimitiveGL Draw \"" + DLOG_FIRST_N(INFO, kNumLoggedEvents) << "PrimitiveGLES2 Draw \"" << draw_element->name() << "\""; - DrawElementGL* draw_element_gl = down_cast<DrawElementGL*>(draw_element); - EffectGL* effect_gl = down_cast<EffectGL*>(material->effect()); + DrawElementGLES2* draw_element_gl = + down_cast<DrawElementGLES2*>(draw_element); + EffectGLES2* effect_gl = down_cast<EffectGLES2*>(material->effect()); DLOG_ASSERT(effect_gl); - StreamBankGL* stream_bank_gl = down_cast<StreamBankGL*>(stream_bank()); + StreamBankGLES2* stream_bank_gl = down_cast<StreamBankGLES2*>(stream_bank()); DLOG_ASSERT(stream_bank_gl); - ParamCacheGL* param_cache_gl = down_cast<ParamCacheGL*>(param_cache); - ParamCacheGL::VaryingParameterMap& varying_map = + ParamCacheGLES2* param_cache_gl = down_cast<ParamCacheGLES2*>(param_cache); + ParamCacheGLES2::VaryingParameterMap& varying_map = param_cache_gl->varying_map(); - // If this PrimitiveGL has an effect we haven't seen before (or it's the first - // time through), initalize the parameter lists before drawing with it. + // If this PrimitiveGLES2 has an effect we haven't seen before (or it's the + // first time through), initalize the parameter lists before drawing with it. if (effect_gl->cg_vertex_program() && effect_gl->cg_fragment_program()) { // Set up the current CGeffect. if (!param_cache_gl->ValidateAndCacheParams(effect_gl, @@ -134,7 +135,7 @@ void PrimitiveGL::PlatformSpecificRender(Renderer* renderer, return; } - // TODO: move these checks at 'set' time instead of draw time. + // TODO(o3d): move these checks at 'set' time instead of draw time. bool draw = true; if (number_vertices_ > max_vertices) { @@ -159,7 +160,7 @@ void PrimitiveGL::PlatformSpecificRender(Renderer* renderer, if (indexed()) { // Re-bind the index buffer for this shape - IndexBufferGL *ibuffer = down_cast<IndexBufferGL*>(index_buffer()); + IndexBufferGLES2 *ibuffer = down_cast<IndexBufferGLES2*>(index_buffer()); unsigned int max_indices = ibuffer->num_elements(); @@ -171,7 +172,7 @@ void PrimitiveGL::PlatformSpecificRender(Renderer* renderer, draw = false; } - // TODO: Also check that indices in the index buffer are less than + // TODO(o3d): Also check that indices in the index buffer are less than // max_vertices_. Needs support from the index buffer (scan indices on // Unlock). @@ -247,7 +248,7 @@ void PrimitiveGL::PlatformSpecificRender(Renderer* renderer, effect_gl->PostDraw(param_cache_gl); // Disable the vertex attribute states set earlier. - for (ParamCacheGL::VaryingParameterMap::iterator i = varying_map.begin(); + for (ParamCacheGLES2::VaryingParameterMap::iterator i = varying_map.begin(); i != varying_map.end(); ++i) { cgGLDisableClientState(i->first); @@ -256,3 +257,4 @@ void PrimitiveGL::PlatformSpecificRender(Renderer* renderer, } } // namespace o3d + diff --git a/o3d/core/cross/gles2/primitive_gles2.h b/o3d/core/cross/gles2/primitive_gles2.h index 7dd1c75..2191033 100644 --- a/o3d/core/cross/gles2/primitive_gles2.h +++ b/o3d/core/cross/gles2/primitive_gles2.h @@ -30,7 +30,7 @@ */ -// This file contains the declaration of the PrimitiveGL class. +// This file contains the declaration of the PrimitiveGLES2 class. #ifndef O3D_CORE_CROSS_GLES2_PRIMITIVE_GLES2_H_ #define O3D_CORE_CROSS_GLES2_PRIMITIVE_GLES2_H_ @@ -41,12 +41,12 @@ namespace o3d { -// PrimitiveGL is the OpenGL implementation of the Primitive. It provides the -// necessary interfaces for setting the geometry streams on the Primitive. -class PrimitiveGL : public Primitive { +// PrimitiveGLES2 is the OpenGLES2 implementation of the Primitive. It provides +// the necessary interfaces for setting the geometry streams on the Primitive. +class PrimitiveGLES2 : public Primitive { public: - explicit PrimitiveGL(ServiceLocator* service_locator); - virtual ~PrimitiveGL(); + explicit PrimitiveGLES2(ServiceLocator* service_locator); + virtual ~PrimitiveGLES2(); protected: // Overridden from Primitive. @@ -61,3 +61,4 @@ class PrimitiveGL : public Primitive { } // o3d #endif // O3D_CORE_CROSS_GLES2_PRIMITIVE_GLES2_H_ + diff --git a/o3d/core/cross/gles2/render_surface_gles2.cc b/o3d/core/cross/gles2/render_surface_gles2.cc index b57403f..5263828 100644 --- a/o3d/core/cross/gles2/render_surface_gles2.cc +++ b/o3d/core/cross/gles2/render_surface_gles2.cc @@ -30,8 +30,8 @@ */ -// This file contains the implementation of RenderSurfaceGL and -// RenderDepthStencilSurfaceGL. +// This file contains the implementation of RenderSurfaceGLES2 and +// RenderDepthStencilSurfaceGLES2. #include "core/cross/gles2/render_surface_gles2.h" #include "core/cross/gles2/utils_gles2-inl.h" @@ -39,22 +39,22 @@ namespace o3d { -RenderSurfaceGL::RenderSurfaceGL(ServiceLocator *service_locator, - int width, - int height, - GLenum cube_face, - int mip_level, - Texture *texture) +RenderSurfaceGLES2::RenderSurfaceGLES2(ServiceLocator *service_locator, + int width, + int height, + GLenum cube_face, + int mip_level, + Texture *texture) : RenderSurface(service_locator, width, height, texture), cube_face_(cube_face), mip_level_(mip_level) { DCHECK(texture); } -RenderSurfaceGL::~RenderSurfaceGL() { +RenderSurfaceGLES2::~RenderSurfaceGLES2() { } -Bitmap::Ref RenderSurfaceGL::PlatformSpecificGetBitmap() const { +Bitmap::Ref RenderSurfaceGLES2::PlatformSpecificGetBitmap() const { Renderer* renderer = service_locator()->GetService<Renderer>(); DCHECK(renderer); @@ -79,7 +79,7 @@ Bitmap::Ref RenderSurfaceGL::PlatformSpecificGetBitmap() const { return bitmap; } -RenderDepthStencilSurfaceGL::RenderDepthStencilSurfaceGL( +RenderDepthStencilSurfaceGLES2::RenderDepthStencilSurfaceGLES2( ServiceLocator *service_locator, int width, int height) @@ -114,7 +114,7 @@ RenderDepthStencilSurfaceGL::RenderDepthStencilSurfaceGL( } } -RenderDepthStencilSurfaceGL::~RenderDepthStencilSurfaceGL() { +RenderDepthStencilSurfaceGLES2::~RenderDepthStencilSurfaceGLES2() { if (GLEW_EXT_packed_depth_stencil) { glDeleteRenderbuffersEXT(1, render_buffers_); } else { @@ -123,3 +123,4 @@ RenderDepthStencilSurfaceGL::~RenderDepthStencilSurfaceGL() { } } // end namespace o3d + diff --git a/o3d/core/cross/gles2/render_surface_gles2.h b/o3d/core/cross/gles2/render_surface_gles2.h index c75aa18..820647c 100644 --- a/o3d/core/cross/gles2/render_surface_gles2.h +++ b/o3d/core/cross/gles2/render_surface_gles2.h @@ -30,8 +30,8 @@ */ -// This file contains the declarations for RenderSurfaceGL and -// RenderDepthStencilSurfaceGL. +// This file contains the declarations for RenderSurfaceGLES2 and +// RenderDepthStencilSurfaceGLES2. #ifndef O3D_CORE_CROSS_GLES2_RENDER_SURFACE_GLES2_H_ #define O3D_CORE_CROSS_GLES2_RENDER_SURFACE_GLES2_H_ @@ -42,11 +42,12 @@ namespace o3d { -class RenderSurfaceGL : public RenderSurface { +class RenderSurfaceGLES2 : public RenderSurface { public: - typedef SmartPointer<RenderSurfaceGL> Ref; + typedef SmartPointer<RenderSurfaceGLES2> Ref; - // Constructs a RenderSurfaceGL instance associated with the texture argument. + // Constructs a RenderSurfaceGLES2 instance associated with the texture + // argument. // Parameters: // service_locator: Service locator for the instance. // width: The width of the surface, in pixels. @@ -56,13 +57,13 @@ class RenderSurfaceGL : public RenderSurface { // this argument is irrelevent. // mip_level: The mip-level of the texture to associate with the surface. // texture: The texture to associate with the surface. - RenderSurfaceGL(ServiceLocator *service_locator, - int width, - int height, - GLenum cube_face, - int mip_level, - Texture *texture); - virtual ~RenderSurfaceGL(); + RenderSurfaceGLES2(ServiceLocator *service_locator, + int width, + int height, + GLenum cube_face, + int mip_level, + Texture *texture); + virtual ~RenderSurfaceGLES2(); GLenum cube_face() const { return cube_face_; @@ -79,17 +80,17 @@ class RenderSurfaceGL : public RenderSurface { private: GLenum cube_face_; int mip_level_; - DISALLOW_COPY_AND_ASSIGN(RenderSurfaceGL); + DISALLOW_COPY_AND_ASSIGN(RenderSurfaceGLES2); }; -class RenderDepthStencilSurfaceGL : public RenderDepthStencilSurface { +class RenderDepthStencilSurfaceGLES2 : public RenderDepthStencilSurface { public: - typedef SmartPointer<RenderDepthStencilSurfaceGL> Ref; + typedef SmartPointer<RenderDepthStencilSurfaceGLES2> Ref; - RenderDepthStencilSurfaceGL(ServiceLocator *service_locator, - int width, - int height); - virtual ~RenderDepthStencilSurfaceGL(); + RenderDepthStencilSurfaceGLES2(ServiceLocator *service_locator, + int width, + int height); + virtual ~RenderDepthStencilSurfaceGLES2(); GLuint depth_buffer() const { return render_buffers_[0]; @@ -101,9 +102,10 @@ class RenderDepthStencilSurfaceGL : public RenderDepthStencilSurface { private: // Handles to the depth and stencil render-buffers, respectively. GLuint render_buffers_[2]; - DISALLOW_COPY_AND_ASSIGN(RenderDepthStencilSurfaceGL); + DISALLOW_COPY_AND_ASSIGN(RenderDepthStencilSurfaceGLES2); }; } // namespace o3d #endif // O3D_CORE_CROSS_GLES2_RENDER_SURFACE_GLES2_H_ + diff --git a/o3d/core/cross/gles2/renderer_gles2.cc b/o3d/core/cross/gles2/renderer_gles2.cc index e2f4a04..da5f5e7 100644 --- a/o3d/core/cross/gles2/renderer_gles2.cc +++ b/o3d/core/cross/gles2/renderer_gles2.cc @@ -30,8 +30,8 @@ */ -// This file contains the definition of the RendererGL class that -// implements the abstract Renderer API using OpenGL and the Cg +// This file contains the definition of the RendererGLES2 class that +// implements the abstract Renderer API using OpenGLES2 and the Cg // Runtime. @@ -170,7 +170,7 @@ GLenum ConvertStencilOp(State::StencilOperation stencil_func) { } // Helper routine that will bind the surfaces stored in the RenderSurface and -// RenderDepthStencilSurface arguments to the current OpenGL context. +// RenderDepthStencilSurface arguments to the current OpenGLES2 context. // Returns true upon success. // Note: This routine assumes that a frambuffer object is presently bound // to the context. @@ -199,8 +199,8 @@ bool InstallFramebufferObjects(const RenderSurface* surface, 0); if (surface) { - const RenderSurfaceGL *gl_surface = - down_cast<const RenderSurfaceGL*>(surface); + const RenderSurfaceGLES2 *gl_surface = + down_cast<const RenderSurfaceGLES2*>(surface); Texture *texture = gl_surface->texture(); GLuint handle = static_cast<GLuint>(reinterpret_cast<intptr_t>( texture->GetTextureHandle())); @@ -223,8 +223,8 @@ bool InstallFramebufferObjects(const RenderSurface* surface, if (surface_depth) { // Bind both the depth and stencil attachments. - const RenderDepthStencilSurfaceGL* gl_surface = - down_cast<const RenderDepthStencilSurfaceGL*>(surface_depth); + const RenderDepthStencilSurfaceGLES2* gl_surface = + down_cast<const RenderDepthStencilSurfaceGLES2*>(surface_depth); ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, @@ -258,13 +258,14 @@ const RenderSurfaceBase* GetValidRenderSurface( // This class wraps StateHandler to make it typesafe. template <typename T> -class TypedStateHandler : public RendererGL::StateHandler { +class TypedStateHandler : public RendererGLES2::StateHandler { public: // Override this function to set a specific state. // Parameters: // renderer: The platform specific renderer. // param: A concrete param with state data. - virtual void SetStateFromTypedParam(RendererGL* renderer, T* param) const = 0; + virtual void SetStateFromTypedParam( + RendererGLES2* renderer, T* param) const = 0; // Gets Class of State's Parameter virtual const ObjectBase::Class* GetClass() const { @@ -277,7 +278,7 @@ class TypedStateHandler : public RendererGL::StateHandler { // renderer: The platform specific renderer. // param: A param with state data. virtual void SetState(Renderer* renderer, Param* param) const { - RendererGL *renderer_gl = down_cast<RendererGL *>(renderer); + RendererGLES2 *renderer_gl = down_cast<RendererGLES2 *>(renderer); // This is safe because State guarntees Params match by type. DCHECK(param->IsA(T::GetApparentClass())); SetStateFromTypedParam(renderer_gl, down_cast<T*>(param)); @@ -290,7 +291,7 @@ class TypedStateHandler : public RendererGL::StateHandler { template <GLenum state_constant> class StateEnableHandler : public TypedStateHandler<ParamBoolean> { public: - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamBoolean* param) const { if (param->value()) { ::glEnable(state_constant); @@ -306,7 +307,7 @@ class BoolHandler : public TypedStateHandler<ParamBoolean> { : var_(*var), changed_var_(*changed_var) { } - virtual void SetStateFromTypedParam(RendererGL *renderer, + virtual void SetStateFromTypedParam(RendererGLES2 *renderer, ParamBoolean *param) const { var_ = param->value(); } @@ -317,7 +318,7 @@ class BoolHandler : public TypedStateHandler<ParamBoolean> { class ZWriteEnableHandler : public TypedStateHandler<ParamBoolean> { public: - virtual void SetStateFromTypedParam(RendererGL *renderer, + virtual void SetStateFromTypedParam(RendererGLES2 *renderer, ParamBoolean *param) const { ::glDepthMask(param->value()); } @@ -325,7 +326,7 @@ class ZWriteEnableHandler : public TypedStateHandler<ParamBoolean> { class AlphaReferenceHandler : public TypedStateHandler<ParamFloat> { public: - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamFloat* param) const { float refFloat = param->value(); @@ -343,7 +344,7 @@ class AlphaReferenceHandler : public TypedStateHandler<ParamFloat> { class CullModeHandler : public TypedStateHandler<ParamInteger> { public: - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamInteger* param) const { State::Cull cull = static_cast<State::Cull>(param->value()); switch (cull) { @@ -364,7 +365,7 @@ class CullModeHandler : public TypedStateHandler<ParamInteger> { class PolygonOffset1Handler : public TypedStateHandler<ParamFloat> { public: - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamFloat* param) const { renderer->polygon_offset_factor_ = param->value(); renderer->polygon_offset_changed_ = true; @@ -373,7 +374,7 @@ class PolygonOffset1Handler : public TypedStateHandler<ParamFloat> { class PolygonOffset2Handler : public TypedStateHandler<ParamFloat> { public: - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamFloat* param) const { renderer->polygon_offset_bias_ = param->value(); renderer->polygon_offset_changed_ = true; @@ -382,7 +383,7 @@ class PolygonOffset2Handler : public TypedStateHandler<ParamFloat> { class FillModeHandler : public TypedStateHandler<ParamInteger> { public: - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamInteger* param) const { ::glPolygonMode(GL_FRONT_AND_BACK, ConvertFillMode(static_cast<State::Fill>(param->value()))); @@ -391,7 +392,7 @@ class FillModeHandler : public TypedStateHandler<ParamInteger> { class ZFunctionHandler : public TypedStateHandler<ParamInteger> { public: - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamInteger* param) const { ::glDepthFunc( ConvertCmpFunc(static_cast<State::Comparison>(param->value()))); @@ -403,7 +404,7 @@ class BlendEquationHandler : public TypedStateHandler<ParamInteger> { explicit BlendEquationHandler(GLenum* var) : var_(*var) { } - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamInteger* param) const { renderer->alpha_blend_settings_changed_ = true; var_ = ConvertBlendEquation( @@ -418,7 +419,7 @@ class BlendFunctionHandler : public TypedStateHandler<ParamInteger> { explicit BlendFunctionHandler(GLenum* var) : var_(*var) { } - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamInteger* param) const { renderer->alpha_blend_settings_changed_ = true; var_ = ConvertBlendFunc( @@ -435,7 +436,7 @@ class StencilOperationHandler : public TypedStateHandler<ParamInteger> { : face_(face) , condition_(condition) { } - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamInteger* param) const { renderer->stencil_settings_changed_ = true; renderer->stencil_settings_[face_].op_[condition_] = ConvertStencilOp( @@ -452,7 +453,7 @@ class ComparisonFunctionHandler : public TypedStateHandler<ParamInteger> { : var_(*var), changed_var_(*changed_var) { } - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamInteger* param) const { changed_var_ = true; var_ = ConvertCmpFunc(static_cast<State::Comparison>(param->value())); @@ -464,7 +465,7 @@ class ComparisonFunctionHandler : public TypedStateHandler<ParamInteger> { class StencilRefHandler : public TypedStateHandler<ParamInteger> { public: - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamInteger* param) const { renderer->stencil_settings_changed_ = true; renderer->stencil_ref_ = param->value(); @@ -476,7 +477,7 @@ class StencilMaskHandler : public TypedStateHandler<ParamInteger> { explicit StencilMaskHandler(int mask_index) : mask_index_(mask_index) { } - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamInteger* param) const { renderer->stencil_settings_changed_ = true; renderer->stencil_mask_[mask_index_] = param->value(); @@ -487,7 +488,7 @@ class StencilMaskHandler : public TypedStateHandler<ParamInteger> { class ColorWriteEnableHandler : public TypedStateHandler<ParamInteger> { public: - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamInteger* param) const { int mask = param->value(); ::glColorMask((mask & 0x1) != 0, @@ -500,11 +501,11 @@ class ColorWriteEnableHandler : public TypedStateHandler<ParamInteger> { class PointSpriteEnableHandler : public TypedStateHandler<ParamBoolean> { public: - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamBoolean* param) const { if (param->value()) { ::glEnable(GL_POINT_SPRITE); - // TODO: It's not clear from D3D docs that point sprites affect + // TODO(o3d): It's not clear from D3D docs that point sprites affect // TEXCOORD0, but that's my guess. Check that. ::glActiveTextureARB(GL_TEXTURE0); ::glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); @@ -518,17 +519,17 @@ class PointSpriteEnableHandler : public TypedStateHandler<ParamBoolean> { class PointSizeHandler : public TypedStateHandler<ParamFloat> { public: - virtual void SetStateFromTypedParam(RendererGL* renderer, + virtual void SetStateFromTypedParam(RendererGLES2* renderer, ParamFloat* param) const { ::glPointSize(param->value()); } }; -RendererGL* RendererGL::CreateDefault(ServiceLocator* service_locator) { - return new RendererGL(service_locator); +RendererGLES2* RendererGLES2::CreateDefault(ServiceLocator* service_locator) { + return new RendererGLES2(service_locator); } -RendererGL::RendererGL(ServiceLocator* service_locator) +RendererGLES2::RendererGLES2(ServiceLocator* service_locator) : Renderer(service_locator), semantic_manager_(service_locator), #ifdef OS_WIN @@ -557,7 +558,7 @@ RendererGL::RendererGL(ServiceLocator* service_locator) polygon_offset_changed_(true), polygon_offset_factor_(0.f), polygon_offset_bias_(0.f) { - DLOG(INFO) << "RendererGL Construct"; + DLOG(INFO) << "RendererGLES2 Construct"; // Setup default state values. for (int ii = 0; ii < 2; ++ii) { @@ -653,13 +654,13 @@ RendererGL::RendererGL(ServiceLocator* service_locator) new BlendEquationHandler(&blend_equation_[ALPHA])); } -RendererGL::~RendererGL() { +RendererGLES2::~RendererGLES2() { Destroy(); } // platform neutral initialization code // -Renderer::InitStatus RendererGL::InitCommonGL() { +Renderer::InitStatus RendererGLES2::InitCommonGLES2() { GLenum glew_error = glewInit(); if (glew_error != GLEW_OK) { DLOG(ERROR) << "Unable to initialise GLEW : " @@ -667,29 +668,29 @@ Renderer::InitStatus RendererGL::InitCommonGL() { return INITIALIZATION_ERROR; } - // Check to see that we can use the OpenGL vertex attribute APIs - // TODO: We should return false if this check fails, but because some - // Intel hardware does not support OpenGL 2.0, yet does support all of the + // Check to see that we can use the OpenGLES2 vertex attribute APIs + // TODO(o3d): We should return false if this check fails, but because some + // Intel hardware does not support OpenGLES2 2.0, yet does support all of the // extensions we require, we only log an error. A future CL should change // this check to ensure that all of the extension strings we require are // present. if (!GLEW_VERSION_2_0) { - DLOG(ERROR) << "GL drivers do not have OpenGL 2.0 functionality."; + DLOG(ERROR) << "GLES2 drivers do not have OpenGLES2 2.0 functionality."; } if (!GLEW_ARB_vertex_buffer_object) { - // NOTE: Linux NVidia drivers claim to support OpenGL 2.0 when using + // NOTE: Linux NVidia drivers claim to support OpenGLES2 2.0 when using // indirect rendering (e.g. remote X), but it is actually lying. The // ARB_vertex_buffer_object functions silently no-op (!) when using // indirect rendering, leading to crashes. Fortunately, in that case, the // driver claims to not support ARB_vertex_buffer_object, so fail in that // case. - DLOG(ERROR) << "GL drivers do not support vertex buffer objects."; + DLOG(ERROR) << "GLES2 drivers do not support vertex buffer objects."; return GPU_NOT_UP_TO_SPEC; } if (!GLEW_EXT_framebuffer_object) { - DLOG(ERROR) << "GL drivers do not support framebuffer objects."; + DLOG(ERROR) << "GLES2 drivers do not support framebuffer objects."; return GPU_NOT_UP_TO_SPEC; } @@ -698,7 +699,7 @@ Renderer::InitStatus RendererGL::InitCommonGL() { #ifdef OS_MACOSX // The Radeon X1600 says it supports NPOT, but in most situations it doesn't. if (supports_npot() && - !strcmp("ATI Radeon X1600 OpenGL Engine", + !strcmp("ATI Radeon X1600 OpenGLES2 Engine", reinterpret_cast<const char*>(::glGetString(GL_RENDERER)))) SetSupportsNPOT(false); #endif @@ -721,9 +722,9 @@ Renderer::InitStatus RendererGL::InitCommonGL() { // ignore any "CG ERROR: Invalid context handle." message on this // function - Invalid context handle isn't one of therror states of // cgCreateContext(). - DLOG(INFO) << "OpenGL Vendor: " << ::glGetString(GL_VENDOR); - DLOG(INFO) << "OpenGL Renderer: " << ::glGetString(GL_RENDERER); - DLOG(INFO) << "OpenGL Version: " << ::glGetString(GL_VERSION); + DLOG(INFO) << "OpenGLES2 Vendor: " << ::glGetString(GL_VENDOR); + DLOG(INFO) << "OpenGLES2 Renderer: " << ::glGetString(GL_RENDERER); + DLOG(INFO) << "OpenGLES2 Version: " << ::glGetString(GL_VERSION); DLOG(INFO) << "Cg Version: " << cgGetString(CG_VERSION); cg_vertex_profile_ = cgGLGetLatestProfile(CG_GL_VERTEX); cgGLSetOptimalOptions(cg_vertex_profile_); @@ -733,9 +734,9 @@ Renderer::InitStatus RendererGL::InitCommonGL() { cgGLSetOptimalOptions(cg_fragment_profile_); DLOG(INFO) << "Best Cg fragment profile = " << cgGetProfileString(cg_fragment_profile_); - // Set up all Cg State Assignments for OpenGL. + // Set up all Cg State Assignments for OpenGLES2. cgGLRegisterStates(cg_context_); - DLOG_CG_ERROR("Registering GL StateAssignments"); + DLOG_CG_ERROR("Registering GLES2 StateAssignments"); cgGLSetDebugMode(CG_FALSE); // Enable the profiles we use. cgGLEnableProfile(CG_PROFILE_ARBVP1); @@ -744,8 +745,8 @@ Renderer::InitStatus RendererGL::InitCommonGL() { GLint max_vertex_attribs = 0; ::glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs); DLOG(INFO) << "Max Vertex Attribs = " << max_vertex_attribs; - // Initialize global GL settings. - // Tell GL that texture buffers can be single-byte aligned. + // Initialize global GLES2 settings. + // Tell GLES2 that texture buffers can be single-byte aligned. ::glPixelStorei(GL_PACK_ALIGNMENT, 1); ::glPixelStorei(GL_UNPACK_ALIGNMENT, 1); ::glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); @@ -764,7 +765,7 @@ Renderer::InitStatus RendererGL::InitCommonGL() { } // platform neutral destruction code -void RendererGL::DestroyCommonGL() { +void RendererGLES2::DestroyCommonGLES2() { MakeCurrentLazy(); if (render_surface_framebuffer_) { ::glDeleteFramebuffersEXT(1, &render_surface_framebuffer_); @@ -812,7 +813,7 @@ LRESULT CALLBACK IntermediateWindowProc(HWND window, Renderer::InitStatus GetWindowsPixelFormat(HWND window, Features* features, int* pixel_format) { - // We must initialize a GL context before we can determine the multi-sampling + // We must initialize a GLES2 context before we can determine the multi-sampling // supported on the current hardware, so we create an intermediate window // and context here. HINSTANCE module_handle; @@ -833,7 +834,7 @@ Renderer::InitStatus GetWindowsPixelFormat(HWND window, intermediate_class.hCursor = LoadCursor(NULL, IDC_ARROW); intermediate_class.hbrBackground = NULL; intermediate_class.lpszMenuName = NULL; - intermediate_class.lpszClassName = L"Intermediate GL Window"; + intermediate_class.lpszClassName = L"Intermediate GLES2 Window"; ATOM class_registration = ::RegisterClass(&intermediate_class); if (!class_registration) { @@ -861,7 +862,7 @@ Renderer::InitStatus GetWindowsPixelFormat(HWND window, int format_index = ::ChoosePixelFormat(intermediate_dc, &kPixelFormatDescriptor); if (format_index == 0) { - DLOG(ERROR) << "Unable to get the pixel format for GL context."; + DLOG(ERROR) << "Unable to get the pixel format for GLES2 context."; ::ReleaseDC(intermediate_window, intermediate_dc); ::DestroyWindow(intermediate_window); ::UnregisterClass(reinterpret_cast<wchar_t*>(class_registration), @@ -870,7 +871,7 @@ Renderer::InitStatus GetWindowsPixelFormat(HWND window, } if (!::SetPixelFormat(intermediate_dc, format_index, &kPixelFormatDescriptor)) { - DLOG(ERROR) << "Unable to set the pixel format for GL context."; + DLOG(ERROR) << "Unable to set the pixel format for GLES2 context."; ::ReleaseDC(intermediate_window, intermediate_dc); ::DestroyWindow(intermediate_window); ::UnregisterClass(reinterpret_cast<wchar_t*>(class_registration), @@ -882,8 +883,8 @@ Renderer::InitStatus GetWindowsPixelFormat(HWND window, *pixel_format = format_index; HGLRC gl_context = ::wglCreateContext(intermediate_dc); if (::wglMakeCurrent(intermediate_dc, gl_context)) { - // GL context was successfully created and applied to the window's DC. - // Startup GLEW, the GL extensions wrangler. + // GLES2 context was successfully created and applied to the window's DC. + // Startup GLEW, the GLES2 extensions wrangler. GLenum glew_error = ::glewInit(); if (glew_error == GLEW_OK) { DLOG(INFO) << "Initialized GLEW " << ::glewGetString(GLEW_VERSION); @@ -949,15 +950,15 @@ Renderer::InitStatus GetWindowsPixelFormat(HWND window, } // unnamed namespace -Renderer::InitStatus RendererGL::InitPlatformSpecific( +Renderer::InitStatus RendererGLES2::InitPlatformSpecific( const DisplayWindow& display, bool off_screen) { const DisplayWindowWindows &display_platform = static_cast<const DisplayWindowWindows&>(display); - DLOG(INFO) << "RendererGL Init"; + DLOG(INFO) << "RendererGLES2 Init"; - // TODO: Add support for off-screen rendering using OpenGL. + // TODO(o3d): Add support for off-screen rendering using OpenGLES2. if (off_screen) { return INITIALIZATION_ERROR; } @@ -976,36 +977,36 @@ Renderer::InitStatus RendererGL::InitPlatformSpecific( device_context_ = ::GetDC(window_); if (!::SetPixelFormat(device_context_, pixel_format, &kPixelFormatDescriptor)) { - DLOG(ERROR) << "Unable to set the pixel format for GL context."; + DLOG(ERROR) << "Unable to set the pixel format for GLES2 context."; return INITIALIZATION_ERROR; } gl_context_ = ::wglCreateContext(device_context_); if (MakeCurrent()) { // Ensure that glew has been initialized for the created rendering context. - init_status = InitCommonGL(); + init_status = InitCommonGLES2(); if (init_status != SUCCESS) { - DLOG(ERROR) << "Failed to initialize GL rendering context."; + DLOG(ERROR) << "Failed to initialize GLES2 rendering context."; return init_status; } if (WGLEW_ARB_multisample) { ::glEnable(GL_MULTISAMPLE_ARB); } } else { - DLOG(ERROR) << "Failed to create the GL Context."; + DLOG(ERROR) << "Failed to create the GLES2 Context."; return INITIALIZATION_ERROR; } CHECK_GL_ERROR(); return SUCCESS; } -// Releases the Cg Context and deletes the GL device. -void RendererGL::Destroy() { - DLOG(INFO) << "Destroy RendererGL"; - DestroyCommonGL(); +// Releases the Cg Context and deletes the GLES2 device. +void RendererGLES2::Destroy() { + DLOG(INFO) << "Destroy RendererGLES2"; + DestroyCommonGLES2(); if (device_context_) { CHECK_GL_ERROR(); - // Release the OpenGL rendering context. + // Release the OpenGLES2 rendering context. ::wglMakeCurrent(device_context_, NULL); if (gl_context_) { ::wglDeleteContext(gl_context_); @@ -1023,20 +1024,20 @@ void RendererGL::Destroy() { #ifdef OS_MACOSX -Renderer::InitStatus RendererGL::InitPlatformSpecific( +Renderer::InitStatus RendererGLES2::InitPlatformSpecific( const DisplayWindow& display, bool /*off_screen*/) { const DisplayWindowMac &display_platform = static_cast<const DisplayWindowMac&>(display); - // TODO: Add support for off screen rendering on the Mac. + // TODO(o3d): Add support for off screen rendering on the Mac. mac_agl_context_ = display_platform.agl_context(); mac_cgl_context_ = display_platform.cgl_context(); - return InitCommonGL(); + return InitCommonGLES2(); } -void RendererGL::Destroy() { - DestroyCommonGL(); +void RendererGLES2::Destroy() { + DestroyCommonGLES2(); // We only have to destroy agl contexts, // cgl contexts are not owned by us. if (mac_agl_context_) { @@ -1048,7 +1049,7 @@ void RendererGL::Destroy() { #endif // OS_MACOSX #ifdef OS_LINUX -Renderer::InitStatus RendererGL::InitPlatformSpecific( +Renderer::InitStatus RendererGLES2::InitPlatformSpecific( const DisplayWindow& display_window, bool off_screen) { const DisplayWindowLinux &display_platform = @@ -1073,7 +1074,7 @@ Renderer::InitStatus RendererGL::InitPlatformSpecific( } ::XFree(visual_info_list); if (!context_) { - DLOG(ERROR) << "Couldn't create GL context."; + DLOG(ERROR) << "Couldn't create GLES2 context."; return INITIALIZATION_ERROR; } display_ = display; @@ -1083,11 +1084,11 @@ Renderer::InitStatus RendererGL::InitPlatformSpecific( context_ = 0; display_ = NULL; window_ = 0; - DLOG(ERROR) << "Couldn't create GL context."; + DLOG(ERROR) << "Couldn't create GLES2 context."; return INITIALIZATION_ERROR; } - InitStatus init_status = InitCommonGL(); + InitStatus init_status = InitCommonGLES2(); if (init_status != SUCCESS) { ::glXDestroyContext(display, context_); context_ = 0; @@ -1097,8 +1098,8 @@ Renderer::InitStatus RendererGL::InitPlatformSpecific( return init_status; } -void RendererGL::Destroy() { - DestroyCommonGL(); +void RendererGLES2::Destroy() { + DestroyCommonGLES2(); if (display_) { ::glXMakeCurrent(display_, 0, 0); if (context_) { @@ -1112,7 +1113,7 @@ void RendererGL::Destroy() { #endif -bool RendererGL::MakeCurrent() { +bool RendererGLES2::MakeCurrent() { #ifdef OS_WIN if (!device_context_ || !gl_context_) return false; bool result = ::wglMakeCurrent(device_context_, gl_context_) != 0; @@ -1139,12 +1140,12 @@ bool RendererGL::MakeCurrent() { #endif } -void RendererGL::PlatformSpecificClear(const Float4 &color, - bool color_flag, - float depth, - bool depth_flag, - int stencil, - bool stencil_flag) { +void RendererGLES2::PlatformSpecificClear(const Float4 &color, + bool color_flag, + float depth, + bool depth_flag, + int stencil, + bool stencil_flag) { MakeCurrentLazy(); ::glClearColor(color[0], color[1], color[2], color[3]); ::glClearDepth(depth); @@ -1156,11 +1157,11 @@ void RendererGL::PlatformSpecificClear(const Float4 &color, CHECK_GL_ERROR(); } -// Updates the helper constant used for the D3D -> GL remapping. +// Updates the helper constant used for the D3D -> GLES2 remapping. // See effect_gles2.cc for details. -void RendererGL::UpdateHelperConstant(float width, float height) { +void RendererGLES2::UpdateHelperConstant(float width, float height) { MakeCurrentLazy(); - // If render-targets are active, pass -1 to invert the Y axis. OpenGL uses + // If render-targets are active, pass -1 to invert the Y axis. OpenGLES2 uses // a different viewport orientation than DX. Without the inversion, the // output of render-target rendering will be upside down. if (RenderSurfaceActive()) { @@ -1182,12 +1183,12 @@ void RendererGL::UpdateHelperConstant(float width, float height) { CHECK_GL_ERROR(); } -void RendererGL::SetViewportInPixels(int left, - int top, - int width, - int height, - float min_z, - float max_z) { +void RendererGLES2::SetViewportInPixels(int left, + int top, + int width, + int height, + float min_z, + float max_z) { MakeCurrentLazy(); int vieport_top = RenderSurfaceActive() ? top : display_height() - top - height; @@ -1208,14 +1209,14 @@ void RendererGL::SetViewportInPixels(int left, } // Resizes the viewport. -void RendererGL::Resize(int width, int height) { +void RendererGLES2::Resize(int width, int height) { MakeCurrentLazy(); SetClientSize(width, height); CHECK_GL_ERROR(); } -bool RendererGL::GoFullscreen(const DisplayWindow& display, - int mode_id) { +bool RendererGLES2::GoFullscreen(const DisplayWindow& display, + int mode_id) { #ifdef OS_LINUX // This actually just switches the GLX context to the new window. The real // work is in main_linux.cc. @@ -1231,8 +1232,8 @@ bool RendererGL::GoFullscreen(const DisplayWindow& display, return true; } -bool RendererGL::CancelFullscreen(const DisplayWindow& display, - int width, int height) { +bool RendererGLES2::CancelFullscreen(const DisplayWindow& display, + int width, int height) { #ifdef OS_LINUX // This actually just switches the GLX context to the old window. The real // work is in main_linux.cc. @@ -1248,7 +1249,7 @@ bool RendererGL::CancelFullscreen(const DisplayWindow& display, return true; } -void RendererGL::GetDisplayModes(std::vector<DisplayMode> *modes) { +void RendererGLES2::GetDisplayModes(std::vector<DisplayMode> *modes) { #ifdef OS_MACOSX // Mac is supposed to call a different function in plugin_mac.mm instead. DLOG(FATAL) << "Not supposed to be called"; @@ -1258,7 +1259,7 @@ void RendererGL::GetDisplayModes(std::vector<DisplayMode> *modes) { modes->clear(); } -bool RendererGL::GetDisplayMode(int id, DisplayMode *mode) { +bool RendererGLES2::GetDisplayMode(int id, DisplayMode *mode) { #ifdef OS_MACOSX // Mac is supposed to call a different function in plugin_mac.mm instead. DLOG(FATAL) << "Not supposed to be called"; @@ -1278,8 +1279,8 @@ bool RendererGL::GetDisplayMode(int id, DisplayMode *mode) { #endif } -bool RendererGL::PlatformSpecificStartRendering() { - DLOG_FIRST_N(INFO, 10) << "RendererGL StartRendering"; +bool RendererGLES2::PlatformSpecificStartRendering() { + DLOG_FIRST_N(INFO, 10) << "RendererGLES2 StartRendering"; MakeCurrentLazy(); // Currently always returns true. @@ -1288,11 +1289,11 @@ bool RendererGL::PlatformSpecificStartRendering() { return true; } -// Clears the color, depth and stncil buffers and prepares GL for rendering +// Clears the color, depth and stncil buffers and prepares GLES2 for rendering // the frame. // Returns true on success. -bool RendererGL::PlatformSpecificBeginDraw() { - DLOG_FIRST_N(INFO, 10) << "RendererGL BeginDraw"; +bool RendererGLES2::PlatformSpecificBeginDraw() { + DLOG_FIRST_N(INFO, 10) << "RendererGLES2 BeginDraw"; MakeCurrentLazy(); @@ -1304,10 +1305,10 @@ bool RendererGL::PlatformSpecificBeginDraw() { // Assign the surface arguments to the renderer, and update the stack // of pushed surfaces. -void RendererGL::SetRenderSurfacesPlatformSpecific( +void RendererGLES2::SetRenderSurfacesPlatformSpecific( const RenderSurface* surface, const RenderDepthStencilSurface* surface_depth) { - // TODO: This routine re-uses a single global framebuffer object for + // TODO(o3d): This routine re-uses a single global framebuffer object for // all RenderSurface rendering. Because of the validation checks performed // at attachment-change time, it may be more performant to create a pool // of framebuffer objects with different attachment characterists and @@ -1316,7 +1317,7 @@ void RendererGL::SetRenderSurfacesPlatformSpecific( ::glBindFramebufferEXT(GL_FRAMEBUFFER, render_surface_framebuffer_); if (!InstallFramebufferObjects(surface, surface_depth)) { O3D_ERROR(service_locator()) - << "Failed to bind OpenGL render target objects:" + << "Failed to bind OpenGLES2 render target objects:" << surface->name() <<", "<< surface_depth->name(); } // RenderSurface rendering is performed with an inverted Y, so the front @@ -1325,7 +1326,7 @@ void RendererGL::SetRenderSurfacesPlatformSpecific( glFrontFace(GL_CW); } -void RendererGL::SetBackBufferPlatformSpecific() { +void RendererGLES2::SetBackBufferPlatformSpecific() { MakeCurrentLazy(); // Bind the default context, and restore the default front-face winding. ::glBindFramebufferEXT(GL_FRAMEBUFFER, 0); @@ -1333,21 +1334,21 @@ void RendererGL::SetBackBufferPlatformSpecific() { } // Executes a post rendering step -void RendererGL::PlatformSpecificEndDraw() { - DLOG_FIRST_N(INFO, 10) << "RendererGL EndDraw"; +void RendererGLES2::PlatformSpecificEndDraw() { + DLOG_FIRST_N(INFO, 10) << "RendererGLES2 EndDraw"; DCHECK(IsCurrent()); } // Swaps the buffers. -void RendererGL::PlatformSpecificFinishRendering() { - DLOG_FIRST_N(INFO, 10) << "RendererGL FinishRendering"; +void RendererGLES2::PlatformSpecificFinishRendering() { + DLOG_FIRST_N(INFO, 10) << "RendererGLES2 FinishRendering"; DCHECK(IsCurrent()); ::glFlush(); CHECK_GL_ERROR(); } -void RendererGL::PlatformSpecificPresent() { - DLOG_FIRST_N(INFO, 10) << "RendererGL Present"; +void RendererGLES2::PlatformSpecificPresent() { + DLOG_FIRST_N(INFO, 10) << "RendererGLES2 Present"; DCHECK(IsCurrent()); #ifdef OS_WIN ::SwapBuffers(device_context_); @@ -1364,20 +1365,20 @@ void RendererGL::PlatformSpecificPresent() { #endif } -StreamBank::Ref RendererGL::CreateStreamBank() { - return StreamBank::Ref(new StreamBankGL(service_locator())); +StreamBank::Ref RendererGLES2::CreateStreamBank() { + return StreamBank::Ref(new StreamBankGLES2(service_locator())); } -Primitive::Ref RendererGL::CreatePrimitive() { - return Primitive::Ref(new PrimitiveGL(service_locator())); +Primitive::Ref RendererGLES2::CreatePrimitive() { + return Primitive::Ref(new PrimitiveGLES2(service_locator())); } -DrawElement::Ref RendererGL::CreateDrawElement() { - return DrawElement::Ref(new DrawElementGL(service_locator())); +DrawElement::Ref RendererGLES2::CreateDrawElement() { + return DrawElement::Ref(new DrawElementGLES2(service_locator())); } -void RendererGL::SetStencilStates(GLenum face, - const StencilStates& stencil_state) { +void RendererGLES2::SetStencilStates(GLenum face, + const StencilStates& stencil_state) { DCHECK(IsCurrent()); if (face == GL_FRONT_AND_BACK) { ::glStencilFunc(stencil_state.func_, @@ -1413,7 +1414,7 @@ void RendererGL::SetStencilStates(GLenum face, CHECK_GL_ERROR(); } -void RendererGL::ApplyDirtyStates() { +void RendererGLES2::ApplyDirtyStates() { MakeCurrentLazy(); DCHECK(IsCurrent()); // Set blend settings. @@ -1481,81 +1482,82 @@ void RendererGL::ApplyDirtyStates() { CHECK_GL_ERROR(); } -VertexBuffer::Ref RendererGL::CreateVertexBuffer() { - DLOG(INFO) << "RendererGL CreateVertexBuffer"; +VertexBuffer::Ref RendererGLES2::CreateVertexBuffer() { + DLOG(INFO) << "RendererGLES2 CreateVertexBuffer"; MakeCurrentLazy(); - return VertexBuffer::Ref(new VertexBufferGL(service_locator())); + return VertexBuffer::Ref(new VertexBufferGLES2(service_locator())); } -IndexBuffer::Ref RendererGL::CreateIndexBuffer() { - DLOG(INFO) << "RendererGL CreateIndexBuffer"; +IndexBuffer::Ref RendererGLES2::CreateIndexBuffer() { + DLOG(INFO) << "RendererGLES2 CreateIndexBuffer"; MakeCurrentLazy(); - return IndexBuffer::Ref(new IndexBufferGL(service_locator())); + return IndexBuffer::Ref(new IndexBufferGLES2(service_locator())); } -Effect::Ref RendererGL::CreateEffect() { - DLOG(INFO) << "RendererGL CreateEffect"; +Effect::Ref RendererGLES2::CreateEffect() { + DLOG(INFO) << "RendererGLES2 CreateEffect"; MakeCurrentLazy(); - return Effect::Ref(new EffectGL(service_locator(), cg_context_)); + return Effect::Ref(new EffectGLES2(service_locator(), cg_context_)); } -Sampler::Ref RendererGL::CreateSampler() { - return Sampler::Ref(new SamplerGL(service_locator())); +Sampler::Ref RendererGLES2::CreateSampler() { + return Sampler::Ref(new SamplerGLES2(service_locator())); } -ParamCache* RendererGL::CreatePlatformSpecificParamCache() { - return new ParamCacheGL(semantic_manager_.Get(), this); +ParamCache* RendererGLES2::CreatePlatformSpecificParamCache() { + return new ParamCacheGLES2(semantic_manager_.Get(), this); } -Texture2D::Ref RendererGL::CreatePlatformSpecificTexture2D( +Texture2D::Ref RendererGLES2::CreatePlatformSpecificTexture2D( int width, int height, Texture::Format format, int levels, bool enable_render_surfaces) { - DLOG(INFO) << "RendererGL CreateTexture2D"; + DLOG(INFO) << "RendererGLES2 CreateTexture2D"; MakeCurrentLazy(); - return Texture2D::Ref(Texture2DGL::Create(service_locator(), - format, - levels, - width, - height, - enable_render_surfaces)); + return Texture2D::Ref(Texture2DGLES2::Create(service_locator(), + format, + levels, + width, + height, + enable_render_surfaces)); } -TextureCUBE::Ref RendererGL::CreatePlatformSpecificTextureCUBE( +TextureCUBE::Ref RendererGLES2::CreatePlatformSpecificTextureCUBE( int edge_length, Texture::Format format, int levels, bool enable_render_surfaces) { - DLOG(INFO) << "RendererGL CreateTextureCUBE"; + DLOG(INFO) << "RendererGLES2 CreateTextureCUBE"; MakeCurrentLazy(); - return TextureCUBE::Ref(TextureCUBEGL::Create(service_locator(), - format, - levels, - edge_length, - enable_render_surfaces)); + return TextureCUBE::Ref(TextureCUBEGLES2::Create(service_locator(), + format, + levels, + edge_length, + enable_render_surfaces)); } -RenderDepthStencilSurface::Ref RendererGL::CreateDepthStencilSurface( +RenderDepthStencilSurface::Ref RendererGLES2::CreateDepthStencilSurface( int width, int height) { return RenderDepthStencilSurface::Ref( - new RenderDepthStencilSurfaceGL(service_locator(), - width, - height)); + new RenderDepthStencilSurfaceGLES2(service_locator(), + width, + height)); } -const int* RendererGL::GetRGBAUByteNSwizzleTable() { +const int* RendererGLES2::GetRGBAUByteNSwizzleTable() { static int swizzle_table[] = { 0, 1, 2, 3, }; return swizzle_table; } // This is a factory function for creating Renderer objects. Since -// we're implementing GL, we only ever return a GL renderer. +// we're implementing GLES2, we only ever return a GLES2 renderer. Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) { - return RendererGL::CreateDefault(service_locator); + return RendererGLES2::CreateDefault(service_locator); } } // namespace o3d + diff --git a/o3d/core/cross/gles2/renderer_gles2.h b/o3d/core/cross/gles2/renderer_gles2.h index 43ba395..dcf04fa 100644 --- a/o3d/core/cross/gles2/renderer_gles2.h +++ b/o3d/core/cross/gles2/renderer_gles2.h @@ -30,8 +30,8 @@ */ -// This file contains the definition of the RendererGL class that provides -// low-level access for O3D to graphics hardware using the OpenGL API +// This file contains the definition of the RendererGLES2 class that provides +// low-level access for O3D to graphics hardware using the OpenGLES2 API // and Cg Runtime. #ifndef O3D_CORE_CROSS_GLES2_RENDERER_GLES2_H_ @@ -51,12 +51,13 @@ class Effect; class DrawEffect; class SemanticManager; -// Implements the genereric Renderer interface using OpenGL and the Cg Runtime. -class RendererGL : public Renderer { +// Implements the genereric Renderer interface using OpenGLES2 and the Cg +// Runtime. +class RendererGLES2 : public Renderer { public: // Creates a default Renderer. - static RendererGL* CreateDefault(ServiceLocator* service_locator); - virtual ~RendererGL(); + static RendererGLES2* CreateDefault(ServiceLocator* service_locator); + virtual ~RendererGLES2(); // Initialises the renderer for use, claiming hardware resources. virtual InitStatus InitPlatformSpecific(const DisplayWindow& display, @@ -86,7 +87,7 @@ class RendererGL : public Renderer { // Returns true on success, false on error. virtual bool GetDisplayMode(int id, DisplayMode *mode); - // Resizes the viewport in OpenGL. + // Resizes the viewport in OpenGLES2. virtual void Resize(int width, int height); // Creates a StreamBank, returning a platform specific implementation class. @@ -99,16 +100,16 @@ class RendererGL : public Renderer { // class. virtual DrawElement::Ref CreateDrawElement(); - // Creates and returns a GL specific float buffer. + // Creates and returns a GLES2 specific float buffer. virtual VertexBuffer::Ref CreateVertexBuffer(); - // Creates and returns a GL specific integer buffer. + // Creates and returns a GLES2 specific integer buffer. virtual IndexBuffer::Ref CreateIndexBuffer(); - // Creates and returns a GL specific Effect object. + // Creates and returns a GLES2 specific Effect object. virtual Effect::Ref CreateEffect(); - // Creates and returns a GL specific Sampler object. + // Creates and returns a GLES2 specific Sampler object. virtual Sampler::Ref CreateSampler(); // Creates and returns a platform-specific RenderDepthStencilSurface object @@ -149,7 +150,7 @@ class RendererGL : public Renderer { return true; } #else - Error: must port RendererGL::IsCurrent() to your platform. + Error: must port RendererGLES2::IsCurrent() to your platform. #endif return false; } @@ -164,7 +165,7 @@ class RendererGL : public Renderer { protected: // Keep the constructor protected so only factory methods can create // renderers. - explicit RendererGL(ServiceLocator* service_locator); + explicit RendererGLES2(ServiceLocator* service_locator); // Overridden from Renderer. virtual bool PlatformSpecificBeginDraw(); @@ -227,13 +228,14 @@ class RendererGL : public Renderer { virtual void ApplyDirtyStates(); private: - // Platform-independent GL initialization - InitStatus InitCommonGL(); + // Platform-independent GLES2 initialization + InitStatus InitCommonGLES2(); - // Platform-independent GL destruction - void DestroyCommonGL(); + // Platform-independent GLES2 destruction + void DestroyCommonGLES2(); - // Updates the helper constant used to remap D3D clip coordinates to GL ones. + // Updates the helper constant used to remap D3D clip coordinates to GLES2 + // ones. void UpdateHelperConstant(float width, float height); ServiceDependency<SemanticManager> semantic_manager_; @@ -243,7 +245,7 @@ class RendererGL : public Renderer { #ifdef OS_WIN - // Handle to the GL device. + // Handle to the GLES2 device. HWND window_; HDC device_context_; HGLRC gl_context_; @@ -333,3 +335,4 @@ class RendererGL : public Renderer { } // namespace o3d #endif // O3D_CORE_CROSS_GLES2_RENDERER_GLES2_H_ + diff --git a/o3d/core/cross/gles2/sampler_gles2.cc b/o3d/core/cross/gles2/sampler_gles2.cc index f275254..502389c 100644 --- a/o3d/core/cross/gles2/sampler_gles2.cc +++ b/o3d/core/cross/gles2/sampler_gles2.cc @@ -30,7 +30,7 @@ */ -// This file contains the implementation for SamplerGL. +// This file contains the implementation for SamplerGLES2. #include "core/cross/gles2/gles2_headers.h" #include "core/cross/error.h" @@ -39,13 +39,13 @@ namespace o3d { -SamplerGL::SamplerGL(ServiceLocator* service_locator) +SamplerGLES2::SamplerGLES2(ServiceLocator* service_locator) : Sampler(service_locator), - renderer_(static_cast<RendererGL*>( + renderer_(static_cast<RendererGLES2*>( service_locator->GetService<Renderer>())) { } -SamplerGL::~SamplerGL() { +SamplerGLES2::~SamplerGLES2() { } namespace { @@ -131,7 +131,7 @@ GLenum GLTextureTarget(Texture* texture) { } // namespace -void SamplerGL::SetTextureAndStates(CGparameter cg_param) { +void SamplerGLES2::SetTextureAndStates(CGparameter cg_param) { // Get the texture object associated with this sampler. Texture* texture_object = texture(); @@ -162,7 +162,7 @@ void SamplerGL::SetTextureAndStates(CGparameter cg_param) { return; } - // TODO: this is a slow check and needs to be moved to initialization + // TODO(o3d): this is a slow check and needs to be moved to initialization // time. GLenum target = GLTextureTarget(texture_object); @@ -201,10 +201,10 @@ void SamplerGL::SetTextureAndStates(CGparameter cg_param) { } } -void SamplerGL::ResetTexture(CGparameter cg_param) { +void SamplerGLES2::ResetTexture(CGparameter cg_param) { Texture* the_texture = texture(); if (the_texture) { - // TODO: this is a slow check and needs to be moved to initialization + // TODO(o3d): this is a slow check and needs to be moved to initialization // time. GLenum target = GLTextureTarget(the_texture); if (target) { @@ -215,3 +215,4 @@ void SamplerGL::ResetTexture(CGparameter cg_param) { } } } // namespace o3d + diff --git a/o3d/core/cross/gles2/sampler_gles2.h b/o3d/core/cross/gles2/sampler_gles2.h index 4da4be8..d388473 100644 --- a/o3d/core/cross/gles2/sampler_gles2.h +++ b/o3d/core/cross/gles2/sampler_gles2.h @@ -30,7 +30,7 @@ */ -// This file contains the class declaration for SamplerGL. +// This file contains the class declaration for SamplerGLES2. #ifndef O3D_CORE_CROSS_GLES2_SAMPLER_GLES2_H_ #define O3D_CORE_CROSS_GLES2_SAMPLER_GLES2_H_ @@ -39,27 +39,28 @@ namespace o3d { -class RendererGL; +class RendererGLES2; -// SamplerGL is an implementation of the Sampler object for GL. -class SamplerGL : public Sampler { +// SamplerGLES2 is an implementation of the Sampler object for GLES2. +class SamplerGLES2 : public Sampler { public: - explicit SamplerGL(ServiceLocator* service_locator); - virtual ~SamplerGL(); + explicit SamplerGLES2(ServiceLocator* service_locator); + virtual ~SamplerGLES2(); // Sets the gl texture and sampler states. void SetTextureAndStates(CGparameter cg_param); - // Unbinds the GL texture. + // Unbinds the GLES2 texture. void ResetTexture(CGparameter cg_param); private: - RendererGL* renderer_; + RendererGLES2* renderer_; - DISALLOW_COPY_AND_ASSIGN(SamplerGL); + DISALLOW_COPY_AND_ASSIGN(SamplerGLES2); }; } // namespace o3d #endif // O3D_CORE_CROSS_GLES2_SAMPLER_GLES2_H_ + diff --git a/o3d/core/cross/gles2/stream_bank_gles2.cc b/o3d/core/cross/gles2/stream_bank_gles2.cc index 70f6b2a..8808c6b 100644 --- a/o3d/core/cross/gles2/stream_bank_gles2.cc +++ b/o3d/core/cross/gles2/stream_bank_gles2.cc @@ -30,7 +30,7 @@ */ -// This file contains the definition of StreamBankGL. +// This file contains the definition of StreamBankGLES2. #include <algorithm> @@ -53,7 +53,7 @@ namespace o3d { namespace { -// Converts from a Field datatype to a suitable GL type +// Converts from a Field datatype to a suitable GLES2 type GLenum GLDataType(const Field& field) { if (field.IsA(FloatField::GetApparentClass())) { return GL_FLOAT; @@ -72,26 +72,26 @@ GLenum GLDataType(const Field& field) { // Number of times to log a repeated event before giving up. const int kNumLoggedEvents = 5; -// StreamBankGL functions ------------------------------------------------------ +// StreamBankGLES2 functions --------------------------------------------------- -StreamBankGL::StreamBankGL(ServiceLocator* service_locator) +StreamBankGLES2::StreamBankGLES2(ServiceLocator* service_locator) : StreamBank(service_locator) { - DLOG(INFO) << "StreamBankGL Construct"; + DLOG(INFO) << "StreamBankGLES2 Construct"; } -StreamBankGL::~StreamBankGL() { - DLOG(INFO) << "StreamBankGL Destruct"; +StreamBankGLES2::~StreamBankGLES2() { + DLOG(INFO) << "StreamBankGLES2 Destruct"; } -bool StreamBankGL::CheckForMissingVertexStreams( - ParamCacheGL::VaryingParameterMap& varying_map, +bool StreamBankGLES2::CheckForMissingVertexStreams( + ParamCacheGLES2::VaryingParameterMap& varying_map, Stream::Semantic* missing_semantic, int* missing_semantic_index) { DCHECK(missing_semantic); DCHECK(missing_semantic_index); - DLOG(INFO) << "StreamBankGL InsertMissingVertexStreams"; + DLOG(INFO) << "StreamBankGLES2 InsertMissingVertexStreams"; // Match CG_VARYING parameters to Buffers with the matching semantics. - ParamCacheGL::VaryingParameterMap::iterator i; + ParamCacheGLES2::VaryingParameterMap::iterator i; for (i = varying_map.begin(); i != varying_map.end(); ++i) { CGparameter cg_param = i->first; const char* semantic_string = cgGetParameterSemantic(cg_param); @@ -101,10 +101,10 @@ bool StreamBankGL::CheckForMissingVertexStreams( int stream_index = FindVertexStream(semantic, index); if (stream_index >= 0) { // record the matched stream into the varying parameter map for later - // use by StreamBankGL::Draw(). + // use by StreamBankGLES2::Draw(). i->second = stream_index; DLOG(INFO) - << "StreamBankGL Matched CG_PARAMETER \"" + << "StreamBankGLES2 Matched CG_PARAMETER \"" << cgGetParameterName(cg_param) << " : " << semantic_string << "\" to stream " << stream_index << " \"" @@ -122,24 +122,24 @@ bool StreamBankGL::CheckForMissingVertexStreams( return true; } -bool StreamBankGL::BindStreamsForRendering( - const ParamCacheGL::VaryingParameterMap& varying_map, +bool StreamBankGLES2::BindStreamsForRendering( + const ParamCacheGLES2::VaryingParameterMap& varying_map, unsigned int* max_vertices) { *max_vertices = UINT_MAX; // Loop over varying params setting up the streams. - ParamCacheGL::VaryingParameterMap::const_iterator i; + ParamCacheGLES2::VaryingParameterMap::const_iterator i; for (i = varying_map.begin(); i != varying_map.end(); ++i) { const Stream& stream = vertex_stream_params_.at(i->second)->stream(); const Field& field = stream.field(); GLenum type = GLDataType(field); if (type == GL_INVALID_ENUM) { - // TODO: support other kinds of buffers. + // TODO(o3d): support other kinds of buffers. O3D_ERROR(service_locator()) << "unsupported field of type '" << field.GetClassName() << "' on StreamBank '" << name() << "'"; return false; } - VertexBufferGL *vbuffer = down_cast<VertexBufferGL*>(field.buffer()); + VertexBufferGLES2 *vbuffer = down_cast<VertexBufferGLES2*>(field.buffer()); if (!vbuffer) { O3D_ERROR(service_locator()) << "stream has no buffer in StreamBank '" << name() << "'"; @@ -159,7 +159,7 @@ bool StreamBankGL::BindStreamsForRendering( // In the num_elements = 1 case we want to do the D3D stride = 0 thing. // but see below. if (vbuffer->num_elements() == 1) { - // TODO: passing a stride of 0 has a different meaning in GL + // TODO(o3d): passing a stride of 0 has a different meaning in GLES2 // (compute a stride as if it was packed) than in DX (re-use the vertex // over and over again). The equivalent of the DX behavior is by // disabling the vertex array, and setting a constant value. Currently, @@ -188,7 +188,7 @@ bool StreamBankGL::BindStreamsForRendering( // Searches the array of streams and returns the index of the stream that // matches the semantic and index pair. if no match was found, return "-1" -int StreamBankGL::FindVertexStream(Stream::Semantic semantic, int index) { +int StreamBankGLES2::FindVertexStream(Stream::Semantic semantic, int index) { for (unsigned ii = 0; ii < vertex_stream_params_.size(); ++ii) { const Stream& stream = vertex_stream_params_[ii]->stream(); if (stream.semantic() == semantic && stream.semantic_index() == index) { @@ -199,3 +199,4 @@ int StreamBankGL::FindVertexStream(Stream::Semantic semantic, int index) { } } // namespace o3d + diff --git a/o3d/core/cross/gles2/stream_bank_gles2.h b/o3d/core/cross/gles2/stream_bank_gles2.h index 7fd8702..1e81dc5 100644 --- a/o3d/core/cross/gles2/stream_bank_gles2.h +++ b/o3d/core/cross/gles2/stream_bank_gles2.h @@ -30,7 +30,7 @@ */ -// This file contains the declaration of the StreamBankGL class. +// This file contains the declaration of the StreamBankGLES2 class. #ifndef O3D_CORE_CROSS_GLES2_STREAM_BANK_GLES2_H_ #define O3D_CORE_CROSS_GLES2_STREAM_BANK_GLES2_H_ @@ -41,11 +41,11 @@ namespace o3d { -// StreamBankGL is the OpenGL implementation of the StreamBank. -class StreamBankGL : public StreamBank { +// StreamBankGLES2 is the OpenGLES2 implementation of the StreamBank. +class StreamBankGLES2 : public StreamBank { public: - explicit StreamBankGL(ServiceLocator* service_locator); - virtual ~StreamBankGL(); + explicit StreamBankGLES2(ServiceLocator* service_locator); + virtual ~StreamBankGLES2(); // Sets the streams for rendering. // Parameter: @@ -55,12 +55,12 @@ class StreamBankGL : public StreamBank { // Returns: // true if all streams were bound. bool BindStreamsForRendering( - const ParamCacheGL::VaryingParameterMap& varying_map, + const ParamCacheGLES2::VaryingParameterMap& varying_map, unsigned int* max_vertices); // Checks for all required streams before rendering. bool CheckForMissingVertexStreams( - ParamCacheGL::VaryingParameterMap& varying_map, + ParamCacheGLES2::VaryingParameterMap& varying_map, Stream::Semantic* missing_semantic, int* missing_semantic_index); @@ -70,3 +70,4 @@ class StreamBankGL : public StreamBank { } // o3d #endif // O3D_CORE_CROSS_GLES2_STREAM_BANK_GLES2_H_ + diff --git a/o3d/core/cross/gles2/texture_gles2.cc b/o3d/core/cross/gles2/texture_gles2.cc index 4fd9ae9..f03340e 100644 --- a/o3d/core/cross/gles2/texture_gles2.cc +++ b/o3d/core/cross/gles2/texture_gles2.cc @@ -31,7 +31,7 @@ // Implementations of the abstract Texture2D and TextureCUBE classes using -// the OpenGL graphics API. +// the OpenGLES2 graphics API. #include "core/cross/gles2/gles2_headers.h" #include "core/cross/error.h" @@ -51,9 +51,9 @@ Texture::RGBASwizzleIndices g_gl_abgr32f_swizzle_indices = {0, 1, 2, 3}; } // anonymous namespace. -// Converts an O3D texture format to a GL texture format. +// Converts an O3D texture format to a GLES2 texture format. // Input is 'format'. -// GL has 2 notions of the format: +// GLES2 has 2 notions of the format: // - the internal format which describes how the format should be stored on the // GPU // - the (format, type) pair which describes how the input data to glTexImage2D @@ -97,7 +97,7 @@ static GLenum GLFormatFromO3DFormat(Texture::Format format, *data_type = 0; return 0; } else { - // TODO: we need to convert DXT1 -> RGBA8 but keep around the + // TODO(o3d): we need to convert DXT1 -> RGBA8 but keep around the // pixels so that we can read them back (we won't try to convert back // to DXTC). LOG(ERROR) << "DXT1 compressed textures not supported yet."; @@ -112,7 +112,7 @@ static GLenum GLFormatFromO3DFormat(Texture::Format format, *data_type = 0; return 0; } else { - // TODO: we need to convert DXT3 -> RGBA8 but keep around the + // TODO(o3d): we need to convert DXT3 -> RGBA8 but keep around the // pixels so that we can read them back (we won't try to convert back // to DXTC). LOG(ERROR) << "DXT3 compressed textures not supported yet."; @@ -127,7 +127,7 @@ static GLenum GLFormatFromO3DFormat(Texture::Format format, *data_type = 0; return 0; } else { - // TODO: we need to convert DXT3 -> RGBA8 but keep around the + // TODO(o3d): we need to convert DXT3 -> RGBA8 but keep around the // pixels so that we can read them back (we won't try to convert back // to DXTC). LOG(ERROR) << "DXT5 compressed textures not supported yet."; @@ -146,7 +146,7 @@ static GLenum GLFormatFromO3DFormat(Texture::Format format, return 0; } -// Updates a GL image from a bitmap, rescaling if necessary. +// Updates a GLES2 image from a bitmap, rescaling if necessary. static bool UpdateGLImageFromBitmap(GLenum target, unsigned int level, TextureCUBE::CubeFace face, @@ -190,7 +190,7 @@ static bool UpdateGLImageFromBitmap(GLenum target, return glGetError() == GL_NO_ERROR; } -// Creates the array of GL images for a particular face and upload the pixel +// Creates the array of GLES2 images for a particular face and upload the pixel // data from the bitmap. static bool CreateGLImages(GLenum target, GLenum internal_format, @@ -240,18 +240,19 @@ static bool CreateGLImages(GLenum target, return true; } -// Texture2DGL ----------------------------------------------------------------- - -// Constructs a 2D texture object from an existing OpenGL 2D texture. -// NOTE: the Texture2DGL now owns the GL texture and will destroy it on exit. -Texture2DGL::Texture2DGL(ServiceLocator* service_locator, - GLint texture, - Texture::Format format, - int levels, - int width, - int height, - bool resize_to_pot, - bool enable_render_surfaces) +// Texture2DGLES2 -------------------------------------------------------------- + +// Constructs a 2D texture object from an existing OpenGLES2 2D texture. +// NOTE: the Texture2DGLES2 now owns the GLES2 texture and will destroy it on +// exit. +Texture2DGLES2::Texture2DGLES2(ServiceLocator* service_locator, + GLint texture, + Texture::Format format, + int levels, + int width, + int height, + bool resize_to_pot, + bool enable_render_surfaces) : Texture2D(service_locator, width, height, @@ -259,26 +260,26 @@ Texture2DGL::Texture2DGL(ServiceLocator* service_locator, levels, enable_render_surfaces), resize_to_pot_(resize_to_pot), - renderer_(static_cast<RendererGL*>( + renderer_(static_cast<RendererGLES2*>( service_locator->GetService<Renderer>())), gl_texture_(texture), backing_bitmap_(Bitmap::Ref(new Bitmap(service_locator))), has_levels_(0), locked_levels_(0) { - DLOG(INFO) << "Texture2DGL Construct from GLint"; + DLOG(INFO) << "Texture2DGLES2 Construct from GLint"; DCHECK_NE(format, Texture::UNKNOWN_FORMAT); } // Creates a new texture object from scratch. -Texture2DGL* Texture2DGL::Create(ServiceLocator* service_locator, - Texture::Format format, - int levels, - int width, - int height, - bool enable_render_surfaces) { - DLOG(INFO) << "Texture2DGL Create"; +Texture2DGLES2* Texture2DGLES2::Create(ServiceLocator* service_locator, + Texture::Format format, + int levels, + int width, + int height, + bool enable_render_surfaces) { + DLOG(INFO) << "Texture2DGLES2 Create"; DCHECK_NE(format, Texture::UNKNOWN_FORMAT); - RendererGL *renderer = static_cast<RendererGL *>( + RendererGLES2 *renderer = static_cast<RendererGLES2 *>( service_locator->GetService<Renderer>()); renderer->MakeCurrentLazy(); GLenum gl_internal_format = 0; @@ -287,14 +288,14 @@ Texture2DGL* Texture2DGL::Create(ServiceLocator* service_locator, &gl_internal_format, &gl_data_type); if (gl_internal_format == 0) { - DLOG(ERROR) << "Unsupported format in Texture2DGL::Create."; + DLOG(ERROR) << "Unsupported format in Texture2DGLES2::Create."; return NULL; } bool resize_to_pot = !renderer->supports_npot() && !image::IsPOT(width, height); - // Creates the OpenGL texture object, with all the required mip levels. + // Creates the OpenGLES2 texture object, with all the required mip levels. GLuint gl_texture = 0; glGenTextures(1, &gl_texture); glBindTexture(GL_TEXTURE_2D, gl_texture); @@ -322,17 +323,17 @@ Texture2DGL* Texture2DGL::Create(ServiceLocator* service_locator, DLOG(INFO) << "Created 2D texture (size=" << gl_width << "x" << gl_height << ", GLuint=" << gl_texture << ")"; - Texture2DGL *texture = new Texture2DGL(service_locator, - gl_texture, - format, - levels, - width, - height, - resize_to_pot, - enable_render_surfaces); + Texture2DGLES2 *texture = new Texture2DGLES2(service_locator, + gl_texture, + format, + levels, + width, + height, + resize_to_pot, + enable_render_surfaces); // If the hardware does not support npot textures, allocate a 0-initialized - // mip-chain here for use during Texture2DGL::Lock. + // mip-chain here for use during Texture2DGLES2::Lock. if (resize_to_pot) { texture->backing_bitmap_->Allocate(format, width, height, levels, Bitmap::IMAGE); @@ -342,7 +343,7 @@ Texture2DGL* Texture2DGL::Create(ServiceLocator* service_locator, return texture; } -void Texture2DGL::UpdateBackedMipLevel(unsigned int level) { +void Texture2DGLES2::UpdateBackedMipLevel(unsigned int level) { DCHECK_LT(static_cast<int>(level), levels()); DCHECK(backing_bitmap_->image_data()); DCHECK_EQ(backing_bitmap_->width(), static_cast<unsigned int>(width())); @@ -354,8 +355,8 @@ void Texture2DGL::UpdateBackedMipLevel(unsigned int level) { *backing_bitmap_.Get(), resize_to_pot_); } -Texture2DGL::~Texture2DGL() { - DLOG(INFO) << "Texture2DGL Destruct"; +Texture2DGLES2::~Texture2DGLES2() { + DLOG(INFO) << "Texture2DGLES2 Destruct"; if (gl_texture_) { renderer_->MakeCurrentLazy(); glDeleteTextures(1, &gl_texture_); @@ -364,13 +365,13 @@ Texture2DGL::~Texture2DGL() { CHECK_GL_ERROR(); } -void Texture2DGL::SetRect(int level, - unsigned dst_left, - unsigned dst_top, - unsigned src_width, - unsigned src_height, - const void* src_data, - int src_pitch) { +void Texture2DGLES2::SetRect(int level, + unsigned dst_left, + unsigned dst_top, + unsigned src_width, + unsigned src_height, + const void* src_data, + int src_pitch) { if (level >= levels() || level < 0) { O3D_ERROR(service_locator()) << "Trying to SetRect on non-existent level " << level @@ -452,9 +453,9 @@ void Texture2DGL::SetRect(int level, // Locks the given mipmap level of this texture for loading from main memory, // and returns a pointer to the buffer. -bool Texture2DGL::PlatformSpecificLock( +bool Texture2DGLES2::PlatformSpecificLock( int level, void** data, int* pitch, Texture::AccessMode mode) { - DLOG(INFO) << "Texture2DGL Lock"; + DLOG(INFO) << "Texture2DGLES2 Lock"; DCHECK(data); DCHECK(pitch); DCHECK_GE(level, 0); @@ -492,9 +493,9 @@ bool Texture2DGL::PlatformSpecificLock( } // Unlocks the given mipmap level of this texture, uploading the main memory -// data buffer to GL. -bool Texture2DGL::PlatformSpecificUnlock(int level) { - DLOG(INFO) << "Texture2DGL Unlock"; +// data buffer to GLES2. +bool Texture2DGLES2::PlatformSpecificUnlock(int level) { + DLOG(INFO) << "Texture2DGLES2 Unlock"; DCHECK_GE(level, 0); DCHECK_LT(level, levels()); if (LockedMode(level) != kReadOnly) { @@ -510,7 +511,7 @@ bool Texture2DGL::PlatformSpecificUnlock(int level) { return true; } -RenderSurface::Ref Texture2DGL::PlatformSpecificGetRenderSurface( +RenderSurface::Ref Texture2DGLES2::PlatformSpecificGetRenderSurface( int mip_level) { DCHECK_LT(mip_level, levels()); if (!render_surfaces_enabled()) { @@ -527,7 +528,7 @@ RenderSurface::Ref Texture2DGL::PlatformSpecificGetRenderSurface( return RenderSurface::Ref(NULL); } - return RenderSurface::Ref(new RenderSurfaceGL( + return RenderSurface::Ref(new RenderSurfaceGLES2( service_locator(), width()>> mip_level, height() >> mip_level, @@ -536,30 +537,30 @@ RenderSurface::Ref Texture2DGL::PlatformSpecificGetRenderSurface( this)); } -const Texture::RGBASwizzleIndices& Texture2DGL::GetABGR32FSwizzleIndices() { +const Texture::RGBASwizzleIndices& Texture2DGLES2::GetABGR32FSwizzleIndices() { return g_gl_abgr32f_swizzle_indices; } -// TextureCUBEGL --------------------------------------------------------------- +// TextureCUBEGLES2 ------------------------------------------------------------ -// Creates a texture from a pre-existing GL texture object. -TextureCUBEGL::TextureCUBEGL(ServiceLocator* service_locator, - GLint texture, - Texture::Format format, - int levels, - int edge_length, - bool resize_to_pot, - bool enable_render_surfaces) +// Creates a texture from a pre-existing GLES2 texture object. +TextureCUBEGLES2::TextureCUBEGLES2(ServiceLocator* service_locator, + GLint texture, + Texture::Format format, + int levels, + int edge_length, + bool resize_to_pot, + bool enable_render_surfaces) : TextureCUBE(service_locator, edge_length, format, levels, enable_render_surfaces), resize_to_pot_(resize_to_pot), - renderer_(static_cast<RendererGL*>( + renderer_(static_cast<RendererGLES2*>( service_locator->GetService<Renderer>())), gl_texture_(texture) { - DLOG(INFO) << "TextureCUBEGL Construct"; + DLOG(INFO) << "TextureCUBEGLES2 Construct"; for (int ii = 0; ii < static_cast<int>(NUMBER_OF_FACES); ++ii) { backing_bitmaps_[ii] = Bitmap::Ref(new Bitmap(service_locator)); has_levels_[ii] = 0; @@ -567,8 +568,8 @@ TextureCUBEGL::TextureCUBEGL(ServiceLocator* service_locator, } } -TextureCUBEGL::~TextureCUBEGL() { - DLOG(INFO) << "TextureCUBEGL Destruct"; +TextureCUBEGLES2::~TextureCUBEGLES2() { + DLOG(INFO) << "TextureCUBEGLES2 Destruct"; if (gl_texture_) { renderer_->MakeCurrentLazy(); glDeleteTextures(1, &gl_texture_); @@ -587,14 +588,14 @@ static const int kCubemapFaceList[] = { }; // Create a new Cube texture from scratch. -TextureCUBEGL* TextureCUBEGL::Create(ServiceLocator* service_locator, - Texture::Format format, - int levels, - int edge_length, - bool enable_render_surfaces) { - DLOG(INFO) << "TextureCUBEGL Create"; +TextureCUBEGLES2* TextureCUBEGLES2::Create(ServiceLocator* service_locator, + Texture::Format format, + int levels, + int edge_length, + bool enable_render_surfaces) { + DLOG(INFO) << "TextureCUBEGLES2 Create"; CHECK_GL_ERROR(); - RendererGL *renderer = static_cast<RendererGL *>( + RendererGLES2 *renderer = static_cast<RendererGLES2 *>( service_locator->GetService<Renderer>()); renderer->MakeCurrentLazy(); @@ -608,11 +609,11 @@ TextureCUBEGL* TextureCUBEGL::Create(ServiceLocator* service_locator, &gl_internal_format, &gl_data_type); if (gl_internal_format == 0) { - DLOG(ERROR) << "Unsupported format in TextureCUBEGL::Create."; + DLOG(ERROR) << "Unsupported format in TextureCUBEGLES2::Create."; return NULL; } - // Creates the OpenGL texture object, with all the required mip levels. + // Creates the OpenGLES2 texture object, with all the required mip levels. GLuint gl_texture = 0; glGenTextures(1, &gl_texture); glBindTexture(GL_TEXTURE_CUBE_MAP, gl_texture); @@ -635,15 +636,15 @@ TextureCUBEGL* TextureCUBEGL::Create(ServiceLocator* service_locator, // Create a new texture object, which initializes the base Texture class // from the Bitmap information. - TextureCUBEGL* texture = new TextureCUBEGL(service_locator, - gl_texture, - format, - levels, - edge_length, - resize_to_pot, - enable_render_surfaces); + TextureCUBEGLES2* texture = new TextureCUBEGLES2(service_locator, + gl_texture, + format, + levels, + edge_length, + resize_to_pot, + enable_render_surfaces); // If the hardware does not support npot textures, allocate a 0-initialized - // mip-chain here for use during TextureCUBEGL::Lock. + // mip-chain here for use during TextureCUBEGLES2::Lock. if (resize_to_pot) { for (int face = 0; face < static_cast<int>(NUMBER_OF_FACES); ++face) { texture->backing_bitmaps_[face]->Allocate( @@ -656,8 +657,8 @@ TextureCUBEGL* TextureCUBEGL::Create(ServiceLocator* service_locator, return texture; } -void TextureCUBEGL::UpdateBackedMipLevel(unsigned int level, - TextureCUBE::CubeFace face) { +void TextureCUBEGLES2::UpdateBackedMipLevel(unsigned int level, + TextureCUBE::CubeFace face) { Bitmap* backing_bitmap = backing_bitmaps_[face].Get(); DCHECK_LT(static_cast<int>(level), levels()); DCHECK(backing_bitmap->image_data()); @@ -671,7 +672,7 @@ void TextureCUBEGL::UpdateBackedMipLevel(unsigned int level, resize_to_pot_); } -RenderSurface::Ref TextureCUBEGL::PlatformSpecificGetRenderSurface( +RenderSurface::Ref TextureCUBEGLES2::PlatformSpecificGetRenderSurface( TextureCUBE::CubeFace face, int mip_level) { DCHECK_LT(mip_level, levels()); @@ -689,7 +690,7 @@ RenderSurface::Ref TextureCUBEGL::PlatformSpecificGetRenderSurface( return RenderSurface::Ref(NULL); } - return RenderSurface::Ref(new RenderSurfaceGL( + return RenderSurface::Ref(new RenderSurfaceGLES2( service_locator(), edge_length() >> mip_level, edge_length() >> mip_level, @@ -698,14 +699,14 @@ RenderSurface::Ref TextureCUBEGL::PlatformSpecificGetRenderSurface( this)); } -void TextureCUBEGL::SetRect(TextureCUBE::CubeFace face, - int level, - unsigned dst_left, - unsigned dst_top, - unsigned src_width, - unsigned src_height, - const void* src_data, - int src_pitch) { +void TextureCUBEGLES2::SetRect(TextureCUBE::CubeFace face, + int level, + unsigned dst_left, + unsigned dst_top, + unsigned src_width, + unsigned src_height, + const void* src_data, + int src_pitch) { if (level >= levels() || level < 0) { O3D_ERROR(service_locator()) << "Trying to SetRect non-existent level " << level @@ -790,10 +791,10 @@ void TextureCUBEGL::SetRect(TextureCUBE::CubeFace face, // Locks the given face and mipmap level of this texture for loading from // main memory, and returns a pointer to the buffer. -bool TextureCUBEGL::PlatformSpecificLock( +bool TextureCUBEGLES2::PlatformSpecificLock( CubeFace face, int level, void** data, int* pitch, Texture::AccessMode mode) { - DLOG(INFO) << "TextureCUBEGL Lock"; + DLOG(INFO) << "TextureCUBEGLES2 Lock"; DCHECK_GE(level, 0); DCHECK_LT(level, levels()); renderer_->MakeCurrentLazy(); @@ -817,7 +818,7 @@ bool TextureCUBEGL::PlatformSpecificLock( } GLenum gl_target = kCubemapFaceList[face]; if (mode != kWriteOnly && !HasLevel(face, level)) { - // TODO: add some API so we don't have to copy back the data if we + // TODO(o3d): add some API so we don't have to copy back the data if we // will rewrite it all. DCHECK(!resize_to_pot_); GLenum gl_internal_format = 0; @@ -837,8 +838,8 @@ bool TextureCUBEGL::PlatformSpecificLock( } // Unlocks the given face and mipmap level of this texture. -bool TextureCUBEGL::PlatformSpecificUnlock(CubeFace face, int level) { - DLOG(INFO) << "TextureCUBEGL Unlock"; +bool TextureCUBEGLES2::PlatformSpecificUnlock(CubeFace face, int level) { + DLOG(INFO) << "TextureCUBEGLES2 Unlock"; DCHECK_GE(level, 0); DCHECK_LT(level, levels()); if (LockedMode(face, level) != kReadOnly) { @@ -868,8 +869,10 @@ bool TextureCUBEGL::PlatformSpecificUnlock(CubeFace face, int level) { return false; } -const Texture::RGBASwizzleIndices& TextureCUBEGL::GetABGR32FSwizzleIndices() { +const Texture::RGBASwizzleIndices& + TextureCUBEGLES2::GetABGR32FSwizzleIndices() { return g_gl_abgr32f_swizzle_indices; } } // namespace o3d + diff --git a/o3d/core/cross/gles2/texture_gles2.h b/o3d/core/cross/gles2/texture_gles2.h index b420eca..660bd5a 100644 --- a/o3d/core/cross/gles2/texture_gles2.h +++ b/o3d/core/cross/gles2/texture_gles2.h @@ -30,15 +30,15 @@ */ -// This file contains the declarations for Texture2DGL and TextureCUBEGL. +// This file contains the declarations for Texture2DGLES2 and TextureCUBEGLES2. #ifndef O3D_CORE_CROSS_GLES2_TEXTURE_GLES2_H_ #define O3D_CORE_CROSS_GLES2_TEXTURE_GLES2_H_ // Precompiled header comes before everything else. -// Disable compiler warning for openGL calls that require a void* to -// be cast to a GLuint +// Disable compiler warning for OpenGLES2 calls that require a void* to be cast +// to a GLuint #if defined(OS_WIN) #pragma warning(disable : 4312) #pragma warning(disable : 4311) @@ -50,16 +50,16 @@ namespace o3d { -class RendererGL; +class RendererGLES2; -// Texture2DGL ----------------------------------------------------------------- +// Texture2DGLES2 -------------------------------------------------------------- -// Texture2DGL implements the Texture2D interface with OpenGL. -class Texture2DGL : public Texture2D { +// Texture2DGLES2 implements the Texture2D interface with OpenGLES2. +class Texture2DGLES2 : public Texture2D { public: - typedef SmartPointer<Texture2DGL> Ref; + typedef SmartPointer<Texture2DGLES2> Ref; - virtual ~Texture2DGL(); + virtual ~Texture2DGLES2(); // Overridden from Texture2D virtual void SetRect(int level, @@ -70,23 +70,23 @@ class Texture2DGL : public Texture2D { const void* src_data, int src_pitch); - // Creates a new Texture2DGL with the given specs. If the GL texture + // Creates a new Texture2DGLES2 with the given specs. If the GLES2 texture // creation fails then it returns NULL otherwise it returns a pointer to the // newly created Texture object. // The created texture takes ownership of the bitmap data. - static Texture2DGL* Create(ServiceLocator* service_locator, - Texture::Format format, - int levels, - int width, - int height, - bool enable_render_surfaces); + static Texture2DGLES2* Create(ServiceLocator* service_locator, + Texture::Format format, + int levels, + int width, + int height, + bool enable_render_surfaces); // Returns the implementation-specific texture handle for this texture. void* GetTextureHandle() const { return reinterpret_cast<void*>(gl_texture_); } - // Gets the GL texture handle. + // Gets the GLES2 texture handle. GLuint gl_texture() const { return gl_texture_; } // Gets a RGBASwizzleIndices that contains a mapping from @@ -105,19 +105,19 @@ class Texture2DGL : public Texture2D { virtual RenderSurface::Ref PlatformSpecificGetRenderSurface(int mip_level); private: - // Initializes the Texture2DGL from a preexisting OpenGL texture handle + // Initializes the Texture2DGLES2 from a preexisting OpenGLES2 texture handle // and raw Bitmap data. // The texture takes ownership of the bitmap data. - Texture2DGL(ServiceLocator* service_locator, - GLint texture, - Texture::Format format, - int levels, - int width, - int height, - bool resize_npot, - bool enable_render_surfaces); - - // Updates a mip level, sending it from the backing bitmap to GL, rescaling + Texture2DGLES2(ServiceLocator* service_locator, + GLint texture, + Texture::Format format, + int levels, + int width, + int height, + bool resize_npot, + bool enable_render_surfaces); + + // Updates a mip level, sending it from the backing bitmap to GLES2, rescaling // it if resize_to_pot_ is set. void UpdateBackedMipLevel(unsigned int level); @@ -131,9 +131,9 @@ class Texture2DGL : public Texture2D { // the scenes. bool resize_to_pot_; - RendererGL* renderer_; + RendererGLES2* renderer_; - // The handle of the OpenGL texture object. + // The handle of the OpenGLES2 texture object. GLuint gl_texture_; // A bitmap used to back the NPOT textures on POT-only hardware, and to back @@ -149,20 +149,20 @@ class Texture2DGL : public Texture2D { }; -// TextureCUBEGL --------------------------------------------------------------- +// TextureCUBEGLES2 ------------------------------------------------------------ -// TextureCUBEGL implements the TextureCUBE interface with OpenGL. -class TextureCUBEGL : public TextureCUBE { +// TextureCUBEGLES2 implements the TextureCUBE interface with OpenGLES2. +class TextureCUBEGLES2 : public TextureCUBE { public: - typedef SmartPointer<TextureCUBEGL> Ref; - virtual ~TextureCUBEGL(); + typedef SmartPointer<TextureCUBEGLES2> Ref; + virtual ~TextureCUBEGLES2(); // Create a new Cube texture from scratch. - static TextureCUBEGL* Create(ServiceLocator* service_locator, - Texture::Format format, - int levels, - int edge_length, - bool enable_render_surfaces); + static TextureCUBEGLES2* Create(ServiceLocator* service_locator, + Texture::Format format, + int levels, + int edge_length, + bool enable_render_surfaces); // Overridden from TextureCUBE virtual void SetRect(CubeFace face, @@ -179,7 +179,7 @@ class TextureCUBEGL : public TextureCUBE { return reinterpret_cast<void*>(gl_texture_); } - // Gets the GL texture handle. + // Gets the GLES2 texture handle. GLuint gl_texture() const { return gl_texture_; } // Gets a RGBASwizzleIndices that contains a mapping from @@ -199,16 +199,16 @@ class TextureCUBEGL : public TextureCUBE { virtual RenderSurface::Ref PlatformSpecificGetRenderSurface(CubeFace face, int level); private: - // Creates a texture from a pre-existing GL texture object. - TextureCUBEGL(ServiceLocator* service_locator, - GLint texture, - Texture::Format format, - int levels, - int edge_length, - bool resize_to_pot, - bool enable_render_surfaces); - - // Updates a mip level, sending it from the backing bitmap to GL, rescaling + // Creates a texture from a pre-existing GLES2 texture object. + TextureCUBEGLES2(ServiceLocator* service_locator, + GLint texture, + Texture::Format format, + int levels, + int edge_length, + bool resize_to_pot, + bool enable_render_surfaces); + + // Updates a mip level, sending it from the backing bitmap to GLES2, rescaling // it if resize_to_pot_ is set. void UpdateBackedMipLevel(unsigned int level, CubeFace face); @@ -222,9 +222,9 @@ class TextureCUBEGL : public TextureCUBE { // the scenes. bool resize_to_pot_; - RendererGL* renderer_; + RendererGLES2* renderer_; - // The handle of the OpenGL texture object. + // The handle of the OpenGLES2 texture object. GLuint gl_texture_; // Bitmaps used to back the NPOT textures on POT-only hardware. @@ -241,3 +241,4 @@ class TextureCUBEGL : public TextureCUBE { } // namespace o3d #endif // O3D_CORE_CROSS_GLES2_TEXTURE_GLES2_H_ + diff --git a/o3d/core/cross/gles2/utils_gles2-inl.h b/o3d/core/cross/gles2/utils_gles2-inl.h index f5aea15..e69b552 100644 --- a/o3d/core/cross/gles2/utils_gles2-inl.h +++ b/o3d/core/cross/gles2/utils_gles2-inl.h @@ -37,7 +37,7 @@ namespace o3d { -// Define this to debug GL errors. This has a significant performance hit. +// Define this to debug GLES2 errors. This has a significant performance hit. // #define GL_ERROR_DEBUGGING // convert a byte offset into a Vertex Buffer Object into a GLvoid* for @@ -70,7 +70,7 @@ namespace o3d { #ifdef GL_ERROR_DEBUGGING #define CHECK_GL_ERROR() do { \ GLenum gl_error = glGetError(); \ - LOG_IF(ERROR, gl_error != GL_NO_ERROR) << "GL Error :" << gl_error; \ + LOG_IF(ERROR, gl_error != GL_NO_ERROR) << "GLES2 Error :" << gl_error; \ } while(0) #else // GL_ERROR_DEBUGGING #define CHECK_GL_ERROR() void(0) @@ -79,3 +79,4 @@ namespace o3d { } // namespace o3d #endif // O3D_CORE_CROSS_GLES2_UTILS_GLES2_INL_H_ + diff --git a/o3d/core/cross/gles2/utils_gles2.cc b/o3d/core/cross/gles2/utils_gles2.cc index cec893a..696a067 100644 --- a/o3d/core/cross/gles2/utils_gles2.cc +++ b/o3d/core/cross/gles2/utils_gles2.cc @@ -35,7 +35,7 @@ #include "core/cross/gles2/utils_gles2.h" #include "core/cross/gles2/gles2_headers.h" -// Required OpenGL extensions: +// Required OpenGLES2 extensions: // GL_ARB_vertex_buffer_object // GL_ARB_vertex_program // GL_ARB_texture_compression @@ -141,7 +141,7 @@ SemanticMapElement semantic_map_vp_40[] = { SemanticMapElement("ATTR15", 15), }; -// The map batween OpenGL Vertex Attribute indexes under the VP_40 profile +// The map batween OpenGLES2 Vertex Attribute indexes under the VP_40 profile // to Stream::Semantic identifiers (with index offsets). struct AttrMapElement { AttrMapElement(Stream::Semantic s, int i) : semantic(s), index(i) {} @@ -167,14 +167,14 @@ AttrMapElement attr_map_vp_40[] = { AttrMapElement(Stream::BINORMAL, 0), }; -// TODO: make this choice a runtime decision in RendererGL +// TODO(o3d): make this choice a runtime decision in RendererGLES2 // initialisation. static SemanticMap semantic_map(semantic_map_vp_40, semantic_map_vp_40 + sizeof(semantic_map_vp_40) / sizeof(SemanticMapElement) ); -// Converts a semantic string to an OpenGL vertex attribute number using the +// Converts a semantic string to an OpenGLES2 vertex attribute number using the // standard VP_40 shader semantic mappings. If the semantic is not // recognised, it returns an index of -1. int SemanticNameToGLVertexAttribute(const char* semantic) { @@ -192,11 +192,11 @@ Stream::Semantic GLVertexAttributeToStream(const unsigned int attr, // kMaxAttrIndex is available from: // glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs); // - // TODO: make this a runtime provided value discovered during + // TODO(o3d): make this a runtime provided value discovered during // Renderer creation. const unsigned int kMaxAttrIndex = 15u; if (attr > kMaxAttrIndex) { - //TODO: Figure out how to get errors out of here to the client. + //TODO(o3d): Figure out how to get errors out of here to the client. DLOG(ERROR) << "Invalid vertex attribute index."; *index = 0; return Stream::UNKNOWN_SEMANTIC; @@ -226,3 +226,4 @@ inline void CheckForCgError(const String& logmessage, CGcontext cg_context) { #endif } // namespace o3d + diff --git a/o3d/core/cross/renderer_test.cc b/o3d/core/cross/renderer_test.cc index 50c719a..057e624 100644 --- a/o3d/core/cross/renderer_test.cc +++ b/o3d/core/cross/renderer_test.cc @@ -94,7 +94,7 @@ TEST_F(RendererTest, InitAndDestroyRenderer) { EXPECT_TRUE(gl_renderer->cg_context() != NULL); #elif defined(RENDERER_GLES2) // test that the Cg Context was correctly created - RendererGL* gles2_renderer = down_cast<RendererGL*>(renderer.get()); + RendererGLES2* gles2_renderer = down_cast<RendererGLES2*>(renderer.get()); EXPECT_TRUE(gles2_renderer->cg_context() != NULL); #endif // destroy the renderer @@ -185,3 +185,4 @@ TEST_F(RendererTest, SetViewport) { } } // namespace o3d + |