X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Fdali-toolkit-test-utils%2Ftest-gl-abstraction.h;h=9f458fc06a796a3444cca33671776b579543441a;hp=da945866a58bb29100688db27f7f6eab0be81be7;hb=06ff574795834b3310bd98ac31c8d345ab55d832;hpb=4d4724513d345467aad5d6ff0ff103b191c32a3f diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.h index da94586..9f458fc 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.h @@ -1,8 +1,8 @@ -#ifndef __TEST_GL_ABSTRACTION_H__ -#define __TEST_GL_ABSTRACTION_H__ +#ifndef TEST_GL_ABSTRACTION_H +#define TEST_GL_ABSTRACTION_H /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,13 +25,16 @@ #include #include #include // for strcmp +#include // INTERNAL INCLUDES #include +#include #include #include #include -#include "test-trace-call-stack.h" +#include +#include namespace Dali { @@ -47,7 +50,7 @@ static const char *mStdAttribs[MAX_ATTRIBUTE_CACHE_SIZE] = "aBoneIndices" // ATTRIB_BONE_INDICES }; -class DALI_IMPORT_API TestGlAbstraction: public Dali::Integration::GlAbstraction +class DALI_CORE_API TestGlAbstraction: public Dali::Integration::GlAbstraction { public: TestGlAbstraction(); @@ -57,6 +60,10 @@ public: void PreRender(); void PostRender(); + bool IsSurfacelessContextSupported() const; + + bool TextureRequiresConverting( const GLenum imageGlFormat, const GLenum textureGlFormat, const bool isSubImage ) const; + /* OpenGL ES 2.0 */ inline void ActiveTexture( GLenum textureUnit ) @@ -246,9 +253,9 @@ public: return mCheckFramebufferStatusResult; } - inline GLenum CheckFramebufferColorAttachment() + inline GLuint CheckFramebufferColorAttachmentCount() { - return mFramebufferColorAttached; + return mFramebufferColorAttachmentCount; } inline GLenum CheckFramebufferDepthAttachment() @@ -269,6 +276,15 @@ public: inline void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) { + mLastClearColor.r = red; + mLastClearColor.g = green; + mLastClearColor.b = blue; + mLastClearColor.a = alpha; + } + + inline const Vector4& GetLastClearColor() const + { + return mLastClearColor; } inline void ClearDepthf(GLclampf depth) @@ -277,10 +293,21 @@ public: inline void ClearStencil(GLint s) { + std::stringstream out; + out << s; + + TraceCallStack::NamedParams namedParams; + namedParams["s"] = ToString( s ); + + mStencilFunctionTrace.PushCall( "ClearStencil", out.str(), namedParams ); } inline void ColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) { + mColorMaskParams.red = red; + mColorMaskParams.green = green; + mColorMaskParams.blue = blue; + mColorMaskParams.alpha = alpha; } inline void CompileShader(GLuint shader) @@ -413,6 +440,7 @@ public: paramName<<"texture["<= GL_COLOR_ATTACHMENT0) && (attachment < GL_COLOR_ATTACHMENT0 + Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS)) { - mFramebufferColorAttached = true; + uint8_t mask = 1 << (attachment - GL_COLOR_ATTACHMENT0); + if ((mFrameBufferColorStatus & mask) == 0) + { + mFrameBufferColorStatus |= mask; + ++mFramebufferColorAttachmentCount; + } } } @@ -623,6 +662,7 @@ public: { *(textures+i) = ++mLastAutoTextureIdUsed; } + mNumGeneratedTextures++; } TraceCallStack::NamedParams namedParams; @@ -644,6 +684,15 @@ public: mTextureTrace.PushCall("GenTextures", out.str(), namedParams); } + inline GLuint GetLastGenTextureId() + { + return mLastAutoTextureIdUsed; + } + inline GLuint GetNumGeneratedTextures() + { + return mNumGeneratedTextures; + } + inline void GetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name) { } @@ -919,6 +968,15 @@ public: mScissorParams.y = y; mScissorParams.width = width; mScissorParams.height = height; + + std::stringstream out; + out << x << ", " << y << ", " << width << ", " << height; + TraceCallStack::NamedParams namedParams; + namedParams["x"] = ToString( x ); + namedParams["y"] = ToString( y ); + namedParams["width"] = ToString( width ); + namedParams["height"] = ToString( height ); + mScissorTrace.PushCall( "Scissor", out.str(), namedParams ); } inline void ShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length) @@ -939,10 +997,11 @@ public: inline void GetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, char* source) { const std::string shaderSource = mShaderSources[shader]; - if( static_cast(shaderSource.length()) < bufsize ) + const int shaderSourceLength = static_cast(shaderSource.length()); + if( shaderSourceLength < bufsize ) { - strcpy(source, shaderSource.c_str()); - *length = shaderSource.length(); + strncpy( source, shaderSource.c_str(), shaderSourceLength ); + *length = shaderSourceLength; } else { @@ -959,26 +1018,79 @@ public: inline void StencilFunc(GLenum func, GLint ref, GLuint mask) { + std::stringstream out; + out << func << ", " << ref << ", " << mask; + + TraceCallStack::NamedParams namedParams; + namedParams["func"] = ToString( func ); + namedParams["ref"] = ToString( ref ); + namedParams["mask"] = ToString( mask ); + + mStencilFunctionTrace.PushCall( "StencilFunc", out.str(), namedParams ); } inline void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) { + std::stringstream out; + out << face << ", " << func << ", " << ref << ", " << mask; + + TraceCallStack::NamedParams namedParams; + namedParams["face"] = ToString( face ); + namedParams["func"] = ToString( func ); + namedParams["ref"] = ToString( ref ); + namedParams["mask"] = ToString( mask ); + + mStencilFunctionTrace.PushCall( "StencilFuncSeparate", out.str(), namedParams ); } inline void StencilMask(GLuint mask) { + std::stringstream out; + out << mask; + + TraceCallStack::NamedParams namedParams; + namedParams["mask"] = ToString( mask ); + + mStencilFunctionTrace.PushCall( "StencilMask", out.str(), namedParams ); } inline void StencilMaskSeparate(GLenum face, GLuint mask) { + std::stringstream out; + out << face << ", " << mask; + + TraceCallStack::NamedParams namedParams; + namedParams["face"] = ToString( face ); + namedParams["mask"] = ToString( mask ); + + mStencilFunctionTrace.PushCall( "StencilMaskSeparate", out.str(), namedParams ); } inline void StencilOp(GLenum fail, GLenum zfail, GLenum zpass) { + std::stringstream out; + out << fail << ", " << zfail << ", " << zpass; + + TraceCallStack::NamedParams namedParams; + namedParams["fail"] = ToString( fail ); + namedParams["zfail"] = ToString( zfail ); + namedParams["zpass"] = ToString( zpass ); + + mStencilFunctionTrace.PushCall( "StencilOp", out.str(), namedParams ); } inline void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass) { + std::stringstream out; + out << face << ", " << fail << ", " << zfail << "," << zpass; + + TraceCallStack::NamedParams namedParams; + namedParams["face"] = ToString( face ); + namedParams["fail"] = ToString( fail ); + namedParams["zfail"] = ToString( zfail ); + namedParams["zpass"] = ToString( zpass ); + + mStencilFunctionTrace.PushCall( "StencilOpSeparate", out.str(), namedParams ); } inline void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels) @@ -1062,9 +1174,12 @@ public: mTextureTrace.PushCall("TexSubImage2D", out.str(), namedParams); } - inline void Uniform1f(GLint location, GLfloat x) + inline void Uniform1f(GLint location, GLfloat value ) { - if( ! mProgramUniforms1f.SetUniformValue( mCurrentProgram, location, x ) ) + std::string params = ToString( value ); + AddUniformCallToTraceStack( location, params ); + + if( ! mProgramUniforms1f.SetUniformValue( mCurrentProgram, location, value ) ) { mGetErrorResult = GL_INVALID_OPERATION; } @@ -1072,6 +1187,14 @@ public: inline void Uniform1fv(GLint location, GLsizei count, const GLfloat* v) { + std::string params; + for( int i = 0; i < count; ++i ) + { + params = params + ToString( v[i] ) + ","; + } + + AddUniformCallToTraceStack( location, params ); + for( int i = 0; i < count; ++i ) { if( ! mProgramUniforms1f.SetUniformValue( mCurrentProgram, location, v[i] ) ) @@ -1084,6 +1207,10 @@ public: inline void Uniform1i(GLint location, GLint x) { + std::string params = ToString( x ); + + AddUniformCallToTraceStack( location, params ); + if( ! mProgramUniforms1i.SetUniformValue( mCurrentProgram, location, x ) ) { mGetErrorResult = GL_INVALID_OPERATION; @@ -1092,6 +1219,9 @@ public: inline void Uniform1iv(GLint location, GLsizei count, const GLint* v) { + std::string params = ToString( v ); + AddUniformCallToTraceStack( location, params ); + for( int i = 0; i < count; ++i ) { if( ! mProgramUniforms1i.SetUniformValue( mCurrentProgram, @@ -1106,6 +1236,9 @@ public: inline void Uniform2f(GLint location, GLfloat x, GLfloat y) { + std::string params = ToString( x ) + "," + ToString( y ); + AddUniformCallToTraceStack( location, params ); + if( ! mProgramUniforms2f.SetUniformValue( mCurrentProgram, location, Vector2( x, y ) ) ) @@ -1116,6 +1249,9 @@ public: inline void Uniform2fv(GLint location, GLsizei count, const GLfloat* v) { + std::string params = ToString( v ); + AddUniformCallToTraceStack( location, params ); + for( int i = 0; i < count; ++i ) { if( ! mProgramUniforms2f.SetUniformValue( mCurrentProgram, @@ -1130,14 +1266,21 @@ public: inline void Uniform2i(GLint location, GLint x, GLint y) { + std::string params = ToString( x ) + "," + ToString( y ); + AddUniformCallToTraceStack( location, params ); } inline void Uniform2iv(GLint location, GLsizei count, const GLint* v) { + std::string params = ToString( v ); + AddUniformCallToTraceStack( location, params ); } inline void Uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z) { + std::string params = ToString( x ) + "," + ToString( y ) + "," + ToString( z ); + AddUniformCallToTraceStack( location, params ); + if( ! mProgramUniforms3f.SetUniformValue( mCurrentProgram, location, Vector3( x, y, z ) ) ) @@ -1148,6 +1291,9 @@ public: inline void Uniform3fv(GLint location, GLsizei count, const GLfloat* v) { + std::string params = ToString( v ); + AddUniformCallToTraceStack( location, params ); + for( int i = 0; i < count; ++i ) { if( ! mProgramUniforms3f.SetUniformValue( @@ -1163,14 +1309,21 @@ public: inline void Uniform3i(GLint location, GLint x, GLint y, GLint z) { + std::string params = ToString( x ) + "," + ToString( y ) + "," + ToString( z ); + AddUniformCallToTraceStack( location, params ); } inline void Uniform3iv(GLint location, GLsizei count, const GLint* v) { + std::string params = ToString( v ); + AddUniformCallToTraceStack( location, params ); } inline void Uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { + std::string params = ToString( x ) + "," + ToString( y ) + "," + ToString( z ) + "," + ToString( w ); + AddUniformCallToTraceStack( location, params ); + if( ! mProgramUniforms4f.SetUniformValue( mCurrentProgram, location, Vector4( x, y, z, w ) ) ) @@ -1181,6 +1334,9 @@ public: inline void Uniform4fv(GLint location, GLsizei count, const GLfloat* v) { + std::string params = ToString( v ); + AddUniformCallToTraceStack( location, params ); + for( int i = 0; i < count; ++i ) { if( ! mProgramUniforms4f.SetUniformValue( @@ -1196,18 +1352,27 @@ public: inline void Uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w) { + std::string params = ToString( x ) + "," + ToString( y ) + "," + ToString( z ) + "," + ToString( w ); + AddUniformCallToTraceStack( location, params ); } inline void Uniform4iv(GLint location, GLsizei count, const GLint* v) { + std::string params = ToString( v ); + AddUniformCallToTraceStack( location, params ); } inline void UniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) { + std::string params = ToString( value ); + AddUniformCallToTraceStack( location, params ); } inline void UniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) { + std::string params = ToString( value ); + AddUniformCallToTraceStack( location, params ); + for( int i = 0; i < count; ++i ) { if( ! mProgramUniformsMat3.SetUniformValue( @@ -1223,6 +1388,9 @@ public: inline void UniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) { + std::string params = ToString( value ); + AddUniformCallToTraceStack( location, params ); + for( int i = 0; i < count; ++i ) { if( ! mProgramUniformsMat4.SetUniformValue( @@ -1283,6 +1451,10 @@ public: inline void Viewport(GLint x, GLint y, GLsizei width, GLsizei height) { + std::string commaString(", "); + std::string params( std::to_string(x) + commaString + std::to_string(y) + commaString + std::to_string(width) + commaString + std::to_string(height) ); + + mViewportTrace.PushCall("Viewport", params); } /* OpenGL ES 3.0 */ @@ -1716,6 +1888,31 @@ public: { } +private: + + inline void AddUniformCallToTraceStack( GLint location, std::string& value ) + { + std::string name = ""; + bool matched = false; + + UniformIDMap& map = mUniforms[mCurrentProgram]; + for (UniformIDMap::iterator it=map.begin(); it!=map.end(); ++it) + { + if( it->second == location ) + { + name = it->first; + matched = true; + break; + } + } + + if ( matched ) + { + mSetUniformTrace.PushCall( name, value ); + } + } + + public: // TEST FUNCTIONS inline void SetCompileStatus( GLuint value ) { mCompileStatus = value; } inline void SetLinkStatus( GLuint value ) { mLinkStatus = value; } @@ -1781,6 +1978,26 @@ public: // TEST FUNCTIONS inline void ResetDepthFunctionCallStack() { mDepthFunctionTrace.Reset(); } inline TraceCallStack& GetDepthFunctionTrace() { return mDepthFunctionTrace; } + //Methods for Stencil function verification + inline void EnableStencilFunctionCallTrace(bool enable) { mStencilFunctionTrace.Enable(enable); } + inline void ResetStencilFunctionCallStack() { mStencilFunctionTrace.Reset(); } + inline TraceCallStack& GetStencilFunctionTrace() { return mStencilFunctionTrace; } + + //Methods for Scissor verification + inline void EnableScissorCallTrace(bool enable) { mScissorTrace.Enable(enable); } + inline void ResetScissorCallStack() { mScissorTrace.Reset(); } + inline TraceCallStack& GetScissorTrace() { return mScissorTrace; } + + //Methods for Uniform function verification + inline void EnableSetUniformCallTrace(bool enable) { mSetUniformTrace.Enable(enable); } + inline void ResetSetUniformCallStack() { mSetUniformTrace.Reset(); } + inline TraceCallStack& GetSetUniformTrace() { return mSetUniformTrace; } + + //Methods for Viewport verification + inline void EnableViewportCallTrace(bool enable) { mViewportTrace.Enable(enable); } + inline void ResetViewportCallStack() { mViewportTrace.Reset(); } + inline TraceCallStack& GetViewportTrace() { return mViewportTrace; } + template inline bool GetUniformValue( const char* name, T& value ) const { @@ -1923,10 +2140,22 @@ public: // TEST FUNCTIONS // Methods to check scissor tests inline const ScissorParams& GetScissorParams() const { return mScissorParams; } + struct ColorMaskParams + { + GLboolean red; + GLboolean green; + GLboolean blue; + GLboolean alpha; + + ColorMaskParams() : red( true ), green( true ), blue( true ), alpha( true ) { } + }; + inline bool GetProgramBinaryCalled() const { return mGetProgramBinaryCalled; } inline unsigned int GetClearCountCalled() const { return mClearCount; } + inline const ColorMaskParams& GetColorMaskParams() const { return mColorMaskParams; } + typedef std::vector BufferDataCalls; inline const BufferDataCalls& GetBufferDataCalls() const { return mBufferDataCalls; } inline void ResetBufferDataCalls() { mBufferDataCalls.clear(); } @@ -1955,9 +2184,10 @@ private: GLenum mActiveTextureUnit; GLenum mCheckFramebufferStatusResult; GLint mFramebufferStatus; - GLenum mFramebufferColorAttached; GLenum mFramebufferDepthAttached; GLenum mFramebufferStencilAttached; + GLuint mFramebufferColorAttachmentCount; + GLuint mFrameBufferColorStatus; GLint mNumBinaryFormats; GLint mBinaryFormats; GLint mProgramBinaryLength; @@ -1968,6 +2198,7 @@ private: ShaderSourceMap mShaderSources; GLuint mLastShaderCompiled; GLbitfield mLastClearBitMask; + Vector4 mLastClearColor; unsigned int mClearCount; Vector4 mLastBlendColor; @@ -1978,8 +2209,11 @@ private: GLenum mLastBlendFuncSrcAlpha; GLenum mLastBlendFuncDstAlpha; + GLboolean mLastDepthMask; + // Data for manipulating the IDs returned by GenTextures GLuint mLastAutoTextureIdUsed; + GLuint mNumGeneratedTextures; std::vector mNextTextureIds; std::vector mDeletedTextureIds; std::vector mBoundTextures; @@ -1998,6 +2232,10 @@ private: TraceCallStack mTexParamaterTrace; TraceCallStack mDrawTrace; TraceCallStack mDepthFunctionTrace; + TraceCallStack mStencilFunctionTrace; + TraceCallStack mScissorTrace; + TraceCallStack mSetUniformTrace; + TraceCallStack mViewportTrace; // Shaders & Uniforms GLuint mLastShaderIdUsed; @@ -2041,7 +2279,7 @@ private: T uniformValue; if ( GetUniformValue( program, uniform, uniformValue ) ) { - return value == uniformValue; + return CompareType(value, uniformValue, Math::MACHINE_EPSILON_10); } return false; @@ -2125,6 +2363,7 @@ private: } ScissorParams mScissorParams; + ColorMaskParams mColorMaskParams; }; template <> @@ -2175,6 +2414,4 @@ bool BlendEnabled(const Dali::TraceCallStack& callStack); bool BlendDisabled(const Dali::TraceCallStack& callStack); - - -#endif // __TEST_GL_ES_H__ +#endif // TEST_GL_ABSTRACTION_H